Skip to content

Instantly share code, notes, and snippets.

View pissang's full-sized avatar

Yi Shen pissang

View GitHub Profile
@Yaffle
Yaffle / convertPointFromPageToNode.js
Last active April 30, 2024 03:50
function to get the MouseEvent coordinates for an element that has CSS3 Transforms
/*jslint plusplus: true, vars: true, indent: 2 */
/*
convertPointFromPageToNode(element, event.pageX, event.pageY) -> {x, y}
returns coordinate in element's local coordinate system (works properly with css transforms without perspective projection)
convertPointFromNodeToPage(element, offsetX, offsetY) -> {x, y}
returns coordinate in window's coordinate system (works properly with css transforms without perspective projection)
*/
@claus
claus / gist:1396250
Created November 26, 2011 20:22
Resolution independent rendering of Bezier curves in WebGL
<!doctype html>
<html>
<head>
<title>Resolution independent rendering of Bezier curves in WebGL</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="glMatrix-0.9.6.min.js"></script>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec2 aBezierCoord;
@paullewis
paullewis / gist:1981455
Created March 5, 2012 22:03
Quicksort in JavaScript
/**
* An implementation for Quicksort. Doesn't
* perform as well as the native Array.sort
* and also runs the risk of a stack overflow
*
* Tests with:
*
* var array = [];
* for(var i = 0; i < 20; i++) {
* array.push(Math.round(Math.random() * 100));
@mshafrir
mshafrir / states_hash.json
Created May 9, 2012 17:05
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@cowboy
cowboy / stringify.js
Created September 19, 2012 13:45
JavaScript: like JSON.stringify but handles functions, good for creating arbitrary .js objects?
var stringify = function(obj, prop) {
var placeholder = '____PLACEHOLDER____';
var fns = [];
var json = JSON.stringify(obj, function(key, value) {
if (typeof value === 'function') {
fns.push(value);
return placeholder;
}
return value;
}, 2);
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active May 17, 2024 02:53
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@leeoniya
leeoniya / stable-sort-test.js
Created June 19, 2013 18:09
test if js engine's Array#sort implementation is stable
// test if js engine's Array#sort implementation is stable
var str = "abcdefghijklmnopqrstuvwxyz";
str.split("").sort(function(a,b) {
return ~~(str.indexOf(b)/2.3) - ~~(str.indexOf(a)/2.3);
}).join("") == "xyzvwtursopqmnklhijfgdeabc";
@transitive-bullshit
transitive-bullshit / billboard_sao.frag
Created September 30, 2013 21:08
WebGL GLSL SAO (Scalable Ambient Obscurance) fragment shader. SAO is a more efficient method for computing SSAO (Screen-Space Ambient Occlusion). Converts the g-buffer to an occlusion buffer which estimates local ambient occlusion at each fragment in screen-space. For details on the technique itself, see: McGuire et al [12] http://graphics.cs.wi…
// total number of samples at each fragment
#define NUM_SAMPLES {{ numSamples }}
#define NUM_SPIRAL_TURNS {{ numSpiralTurns }}
#define USE_ACTUAL_NORMALS {{ useActualNormals }}
#define VARIATION {{ variation }}
uniform sampler2D sGBuffer;
@timo22345
timo22345 / flatten.js
Last active March 13, 2024 17:06
Flatten.js, general SVG flattener. Flattens transformations of SVG shapes and paths. All shapes and path commands are supported.
<!doctype html>
<html>
<title>Flatten.js, General SVG Flattener</title>
<head>
<script>
/*
Random path and shape generator, flattener test base: https://jsfiddle.net/fjm9423q/embedded/result/
Basic usage example: https://jsfiddle.net/nrjvmqur/embedded/result/
@mbostock
mbostock / .block
Last active March 31, 2021 08:11
Poisson-Disc II
license: gpl-3.0