Skip to content

Instantly share code, notes, and snippets.

View simonwoo's full-sized avatar
💭
I may be slow to respond.

Chong WU simonwoo

💭
I may be slow to respond.
View GitHub Profile
@simonwoo
simonwoo / move path
Created July 16, 2014 10:10
change the position of a path without changing its transform attribute
$(document).ready(function(){
//create a paper
var paper = Raphael("paper", 500,500);
//create a line
var path = paper.path("M100,100L200,200").attr({fill: "orange"});
//the identity matrix
var m = Raphael.matrix(1,0,0,1,0,0);
m.scale(2,1,100,100);
var pathString = Raphael.mapPath(path2.attr("path"),m);
@simonwoo
simonwoo / raphael_export
Created July 23, 2014 13:35
export raphaeljs svg as an image
/*
* js files to be used
* <script src="http://canvg.googlecode.com/svn/trunk/rgbcolor.js"></script>
* <script src="http://canvg.googlecode.com/svn/trunk/StackBlur.js"></script>
* <script src="http://canvg.googlecode.com/svn/trunk/canvg.js"></script>
* <script src="canvas2image.js"></script>
* <script src="raphael.export.js"></script>
*/
//Convert DOM RaphaelJS element SVG to correct XML (fix images export)
// loop through the 'paper' variable from Raphael JS and build up the JSON object describing all images and paths within it.
buildJSON = function(paper) {
var svgdata = [];
svgdata.push({
width: 390,
height: 400
});
$.each(paper,
@simonwoo
simonwoo / element position
Created August 6, 2014 08:25
Get an Element's Position Using JavaScript
function getPosition(element) {
var xPosition = 0;
var yPosition = 0;
while(element) {
xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
element = element.offsetParent;
}
return { x: xPosition, y: yPosition };
@simonwoo
simonwoo / the difference between pageX,pageY,ScreenX,ScreenY,ClientX,ClientY
Last active February 15, 2022 19:06
the difference between pageX,pageY,ScreenX,ScreenY,ClientX,ClientY
In JavaScript:
pageX, pageY, screenX, screenY, clientX and clientY returns a number which indicates the number of physical pixels a point is from the reference point. The event point is where the user clicked, the reference point is a point in the upper left. These properties return the horizontal and vertical distance from that reference point.
pageX and pageY:
Relative the to the top left of the fully rendered content area in the browser. This reference point is below the url bar and back button in the upper left. This point could be anywhere in the browser window and can actually change location if there are embedded scrollable pages embedded within pages and the user moves a scrollbar.
screenX and screenY:
Relative to the top left of the physical screen/monitor, this reference point only moves if you increase or decrease the number of monitors or the monitor resolution.
@simonwoo
simonwoo / mouse event
Created August 21, 2014 09:19
mousedown,mouseover,mouseup
$('#element').mousedown(function(e) {
// You can record the starting position with
var start_x = e.pageX;
var start_y = e.pageY;
$().mousemove(function(e) {
// And you can get the distance moved by
var offset_x = e.pageX - start_x;
var offset_y = e.pageY - start_y;
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
document.addEventListener("deviceready", onDeviceReady, false);
} else {
onDeviceReady(); //this is the browser
}
@simonwoo
simonwoo / TestCassandra.java
Created March 6, 2015 09:55
a simple demo to test cassandra
package com.restlet.testcassandra;
import com.datastax.driver.core.*;
/*
* an simple exemple to use java drive to manipuler the cassandra
* */
public class TestCassandra {
private Cluster cluster; //add a contact point
private Session session; //manage the connections
@simonwoo
simonwoo / migration.java
Created March 10, 2015 16:31
automatic migration for cassandra
package com.apispark.db;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Iterator;
import java.io.File;
@simonwoo
simonwoo / some paths of java.md
Last active August 29, 2015 14:19
java path buildpath classpath
  • The build path is used for building your application. It contains all of your source files and all Java libraries that are required to compile the application.

  • The classpath is used for executing the application. This includes all java classes and libraries that are needed to run the java application. A Classpath is mandatory, the default path is . which is used if the java virtual machine can't find a user defined path. (CLASSPATH environment variable, -cp flag or Class-Path: attribute in a jar manifest)

  • The classpath is the classic way to tell the Java compiler and the Java runtime where to find compiled classes. It is typically a sequence of JAR file names and directory names. The classpath used by the compiler and the runtime system don't have to be the same, but they typically "should be*, especially for a small project.

  • Buildpath is not classic Java terminology. It is the term for the richer way that a typical IDE specifies the relationship between the "modules" or "projects" that make up an