Thursday, September 26, 2013

SVG Transform Translate

Translate

The translation is an elementary displacement transformation.
Syntax:
 translate(tx, ty)
 tx x-coordinate of displacement
 ty y-coordinate of displacement
Here we apply the translate transformation to the screw group's instance, exactly to the local origin of this group.
   <use xlink:href="#screw" transform="translate(100,130)" />

Figure 6-14. Translate the screw
( view this picture as svg )

Easy, isn't it? So you might ask now what the difference of the translate transformation
to the use of the x- and y- attributes is.
Obviously seems
   <use xlink:href="#screw" transform="translate(100,130)" />
to be identical to 
   <use xlink:href="#screw" x="100" y="130" />
Yes, you are right. So why do we need something complex like transforms? 
We will understand that later, when we had a look at the other elementary transforms and need to combine them. 
So please be patient and simply accept the necessity of the translate transformation for now.
But we should also understand the effect of a combination of the x- and y- attributes 
and the translate transformation.
   <use xlink:href="#screw" transform="translate(100,130)" x="130" y="-160" />

Figure 6-15. Translate and x y attributes
( view this picture as svg )

The effect we have now, is that the screw is translated first to the coordinates (100,130) 
and subsequently displaced by (130,-160) to the end location (230,-30). 
To yield the end position of the elements local coordinate system formally we can simply add the coordinates as in
 Xlocal = tx + x
 ylocal = ty + y
In this formulas we can exchange the addends without harm, i.e.
 Xlocal =x +  tx
 ylocal =y +  ty
will give us the same result. But this means we can also exchange the coordinate values to
   <use xlink:href="#screw" transform="translate(130,-160)" x="100" y="130" />

Figure 6-16. Same result with other combination
( view this picture as svg )
As you see we yield the expected end position of (230,-30) here too. 
So we are not surprised to hear that the following elements produce identical output.
   <use xlink:href="#screw" transform="translate(130,-160) translate(100,130)" />
   <use xlink:href="#screw" transform="translate(100,130) translate(130,-160)" />
   <use xlink:href="#screw" transform="translate(230,-30)" />
   <use xlink:href="#screw" x="230" y="-30" />
It is quite simple but also somewhat confusing to use both the x- and y- attributes and the translate transformation. 
So it is best to avoid this generally, 
but there may be situations to use this effect deliberately as a benefit.
Although the sequence of these both displacements is of no importance here,  the SVG specification states:
The transform attribute is applied to an element before processing any other coordinate or length values supplied for that element.
With that we have a predefined sequence of
perform the translate transformation.
apply the x- and y- attributes.
This was also taken into account with the examples above.

Wednesday, September 25, 2013

Java Regular Expression - Matches vs Find

Regular Expression

import java.io.*;

public class Test{
   public static void main(String args[]){
      String Str = new String("Welcome to Tutorialspoint.com");

      System.out.print("Return Value :" );
      System.out.println(Str.matches("(.*)Tutorials(.*)"));

      System.out.print("Return Value :" );
      System.out.println(Str.matches("Tutorials"));

      System.out.print("Return Value :" );
      System.out.println(Str.matches("Welcome(.*)"));
   }
}
This produces the following result:
Return Value :true
Return Value :false
Return Value :true
 

Matches vs Find

 
public static void main(String[] args) throws ParseException {
    Pattern p = Pattern.compile("\\d\\d\\d");
    Matcher m = p.matcher("a123b");
    System.out.println(m.find());
    System.out.println(m.matches());

    p = Pattern.compile("^\\d\\d\\d$");
    m = p.matcher("123");
    System.out.println(m.find());
    System.out.println(m.matches());
}

/* output:
true
false
true
true
*/ 

Tuesday, September 24, 2013

Monday, September 23, 2013

XML XSD Schema


xmlfox is a good free editor that supports XSD. I however like Oxygen XML Editor. It is very cheap for the functionality it provides.

EditiX supports visual editing. See the below picture.

enter image description here

Thursday, September 19, 2013

SPARQL - JavaScript



$.getJSON("http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=select+*+where+%7B%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FRoger_Federer%3E+%3Fp+%3Fo+filter%28lang%28%3Fo%29+%3D+%27en%27%29%7D%0D%0A&debug=on&timeout=&format=application%2Fsparql-results%2Bjson&save=display&fname=",
  {},
  function(data) {
     console.log('data = ', data);
  });

SPARQL FOAF ENDPOINT

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT Distinct ?Name ?Interest
FROM <http://www.yourwebsite/yourfoaf.rdf>
WHERE {
{?me foaf:knows ?friend . ?friend foaf:name ?Name . ?friend foaf:interest ?Interest}
}
Order by ?Name

Wednesday, September 18, 2013

SKOS Ontology with sample SPARQL

SKOS Simple Knowledge Organization System 

Select the first 3 concepts that have a skos:altLabel
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?concept  ?label
WHERE { ?concept skos:altLabel ?label . } LIMIT 3
Select the first 3 concepts that have a skos:altLabel, as RDF
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
CONSTRUCT   { ?concept skos:altLabel ?label  }
WHERE { ?concept skos:altLabel ?label . } LIMIT 3
Construct an RDF graph of terms with narrower terms but no broader terms, including a narrower terms plus the LCC number. Negation is in a state of flux (see http://www.w3.org/2009/sparql/wiki/Feature:Negation).
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX terms: <http://purl.org/dc/terms/>
CONSTRUCT   { 
    ?concept skos:narrower ?child .
    ?concept terms:LCC ?lcc.
}  WHERE { 
    ?concept skos:narrower ?child . 
    ?concept terms:LCC ?lcc.
    OPTIONAL { ?concept skos:broader ?parent }
    FILTER (!bound(?parent))
} LIMIT 3
Construct an RDF graph of terms with no broader terms in science:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX terms: <http://purl.org/dc/terms/>
CONSTRUCT   { 
    ?concept terms:LCC ?lcc.
}  WHERE {  
    ?concept terms:LCC ?lcc.
    ?concept terms:created ?date
    OPTIONAL { ?concept skos:broader ?broader }
    FILTER (!bound(?broader))
    FILTER regex(?lcc, "^QA")
} LIMIT 50
Get all of the information about a concept. Check both ends of the relation, in case there are no inverseOf-def defined. In this case narrower is matched by broader, but that’s not the case for all RDF vocabularies. The many PREFIX clauses are here so that we get sane/readable prefixes in the output, but they’re unnecessary when generating RDF for machine consumption.
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX terms: <http://purl.org/dc/terms/>
CONSTRUCT   { 
    ?first ?relationOne <http://lcsubjects.org/subjects/sh2002000569#concept> .
    <http://lcsubjects.org/subjects/sh2002000569#concept> ?relationTwo ?second .
}  WHERE {  
    ?first ?relationOne <http://lcsubjects.org/subjects/sh2002000569#concept> .
   <http://lcsubjects.org/subjects/sh2002000569#concept> ?relationTwo ?second .   
} 
This example shows how a SPARQL endpoint might be used to get the data for AJAXy autocomplete functionality. In this example, the letters “Comp” have been typed. The str(…) is required to strip the language tags and the “i” indicates that case-insensitive matching should be done.
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT 
    ?label 
WHERE {  
   {  ?concept  skos:altLabel ?label . } UNION {  ?concept  skos:prefLabel ?label . }
   FILTER regex(str(?label), "^Comp", "i") .
} LIMIT 10

Flex Hints

List Object Properties
for(var id:String in object) {
var value:Object = object[id];
trace(id + " = " + value);
}

Application-sandbox content ERROR

Solution 1
work on the web and as an app. (apps don't need to allowDomain b/c they can download everything by default and that is why it fails.)
try {Security.allowDomain("*");}catch (e) { };


Solution 2
Or try to load your SWF temporarily into a ByteArray and then load it with your SWFLoader.
Don't forget to set allowLoadBytesCodeExecution to true since your SWF has as code inside.
Of course be sure that your loaded swf is secure enough for your application since it will have access at all your property.
private function loadSwfApplication():void {
  // load the file with URLLoader into a bytearray
  var loader:URLLoader=new URLLoader();

  // binary format since it a SWF
  loader.dataFormat=URLLoaderDataFormat.BINARY;
  loader.addEventListener(Event.COMPLETE, onSWFLoaded);

  //load the file
  loader.load(new URLRequest("path/to/the/application.swf"));
}
private function onSWFLoaded(e:Event):void {
 // remove the event
 var loader:URLLoader=URLLoader(e.target);
 loader.removeEventListener(Event.COMPLETE, onSWFLoaded);

 // add an Application context and allow bytecode execution 
 var context:LoaderContext=new LoaderContext();
 context.allowLoadBytesCodeExecution=true;

 // set the new context on SWFLoader
 sfwLoader.loaderContext = context;

 sfwLoader.addEventListener(Event.COMPLETE, loadComplete);

 // load the data from the bytearray
 sfwLoader.load(loader.data);
}

// your load complete function
private function loadComplete(completeEvent:Event):void {
 var swfApplication:* = completeEvent.target.content;
 swfApplication.init();  // this is a Function that I made it in the Root 
                         // class of swfApplication
}

Monday, September 16, 2013

Flex - GraphAPI Facebook

http://code.google.com/p/facebook-actionscript-api

Graph Explorer:
https://developers.facebook.com/tools/explorer/

- Get list friends:
'me/friends?fields=work'

https://graph.facebook.com/FriendID?fields=current_location

Friday, September 13, 2013

Thursday, September 12, 2013

Extract Images from Power Point

Solution 1
  • Save as HTML

Solution 2

  • Save the Powerpoint presentation as a XPS Document.
  • Rename the saved document, replace the .xps extension with a .zip extension (as XPS documents are actually ZIP files containing a bunch of other files).
  • Extract the ZIP file with your favorite ZIP extractor and check in the Resources\Images folder. 

Tuesday, September 10, 2013

Cisco VPN - The VPN client agent was unable to create the interprocess communication depot


 Solution

  1. Click theStartbutton.
  2. Click onControl Panel.
  3. Click onView Network Status and Tasks
  4. Click onChange adapter settings
  5. Right-click the shared connection and choose Properties
  6. Click the Sharing tab
  7. Clear theAllow other network users to connect through this computer's Internet connectioncheckbox
  8. Click OK
  9. Reinstall Cisco anyconnect ...
Source:

Friday, September 6, 2013

How to Delete a Windows Service in Windows 7, Vista or XP

If you are a fan of tweaking your system and disabling services, you might find that over time your Windows Services list becomes huge and unwieldy with a large number of services in the list that will never be enabled.

Instead of just disabling a service, you can alternatively completely delete the service. This technique can be especially helpful if you’ve installed some piece of software that doesn’t uninstall correctly, and leaves an item in the service list.
Important Note: Once you delete a service, it’s gone, and it’s going to be a pain to add it back. Use with caution.
Deleting a Service
The first thing you’ll need to do is identify the name of the service, so open up Services through the start menu or control panel, and then find the service in the list that you want to delete.
image
You’ll want to open up the properties by double-clicking on the service name, and then highlight the “Service name” value and copy it to the clipboard. This is what we’ll need to disable it.
You’ll need to open up a command prompt, and if you are using Windows 7 or Vista you’ll need to right-click the command prompt and choose Run as Administrator. We’ll use the sc command to actually do the work.
The syntax used to delete a service is this:
sc delete ServiceName
If your service name has spaces in it, you’ll need to wrap the service name in quotes, like this:
sc delete “Adobe LM Service”
Note that I’m not recommending deleting this particular service, it’s just an example.
Now if you use the F5 key to refresh your Services list, you’ll see that the service is gone.
I’ve found that using this technique (carefully) can make your Services list a lot more useful, since you don’t have to weed through dozens of items you will never have enabled.
Note: You should think long and hard before deleting a service, because it’s very difficult to get them back once they are gone.
Source:

Thursday, September 5, 2013

Java Increase Memeory for Tomcat

On windows: (catalina.bat)
set CATALINA_OPTS/JAVA_OPTS "-Djava.awt.headless=true -Dfile.encoding=UTF-8 
-server -Xms1536m -Xmx1536m
-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 

-XX:MaxPermSize=256m -XX:+DisableExplicitGC"

On linux: create setenv.sh in tomcat/bin folder with the following content
export CATALINA_OPTS/JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 
-server -Xms1536m -Xmx1536m
-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"

Wednesday, September 4, 2013

SVG - viewBox

ViewBox value will be set relevant with the x,y coodirnator.
If x,y ~ 1-10 -> viewBox width,height: 10,10 ....

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="300px" height="200px" version="1.1"
     viewBox="0 0 1500 1000" preserveAspectRatio="none"
     xmlns="http://www.w3.org/2000/svg">
  <desc>Example ViewBox - uses the viewBox 
   attribute to automatically create an initial user coordinate
   system which causes the graphic to scale to fit into the
   viewport no matter what size the viewport is.</desc>
  <!-- This rectangle goes from (0,0) to (1500,1000) in user space.
       Because of the viewBox attribute above,
       the rectangle will end up filling the entire area
       reserved for the SVG content. -->
  <rect x="0" y="0" width="1500" height="1000" 
        fill="yellow" stroke="blue" stroke-width="12"  />
  <!-- A large, red triangle -->
  <path fill="red"  d="M 750,100 L 250,900 L 1250,900 z"/>
  <!-- A text string that spans most of the viewport -->
  <text x="100" y="600" font-size="200" font-family="Verdana" >
    Stretch to fit
  </text>
</svg>

Example ViewBox
Rendered into
viewport with
width=300px,
height=200px
     Rendered into
viewport with
width=150px,
height=200px
Example ViewBox - stretch to fit 300 by 200     Example ViewBox - stretch to fit 150 by 200

http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute

Java - Invalid byte 2 of 2-byte UTF-8 sequence

ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
Use UTF-8:
ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));

Likewise don't use ByteArrayOutputStream.toString(), which again uses the platform default encoding. Indeed, you don't need to convert the output to a string at all:

ByteArrayOutputStream os = new ByteArrayOutputStream();
marshaller.marshal(c, os);
byte[] xml = os.toByteArray();
jc = JAXBContext.newInstance(Candidate.class);
Unmarshaller jaxb = jc.createUnmarshaller();
ByteArrayInputStream is = new ByteArrayInputStream(xml);

Java - Format Number

public class DecimalFormatExample {  
 
    public static void main(String args[])  {
     
        //formatting numbers upto 2 decimal places in Java
        DecimalFormat df = new DecimalFormat("#,###,##0.00");
        System.out.println(df.format(364565.14));
        System.out.println(df.format(364565.1454));
     
        //formatting numbers upto 3 decimal places in Java
        df = new DecimalFormat("#,###,##0.000");
        System.out.println(df.format(364565.14));
        System.out.println(df.format(364565.1454));
    }
     
}

Output:
364,565.14
364,565.15
364,565.140
364,565.145