Skip to content

Instantly share code, notes, and snippets.

View edankwan's full-sized avatar

Edan Kwan edankwan

View GitHub Profile
@edankwan
edankwan / rAF.js
Created October 22, 2012 17:17 — forked from paulirish/rAF.js
Javascript - requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller
// fixes from Paul Irish and Tino Zijdel
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
@edankwan
edankwan / reset.css
Created October 22, 2012 17:19
CSS: reset.css
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
@edankwan
edankwan / lzw_encoder.js
Created October 24, 2012 21:44 — forked from revolunet/lzw_encoder.js
LZW javascript compress/decompress
// LZW-compress a string
function lzw_encode(s) {
var dict = {};
var data = (s + "").split("");
var out = [];
var currChar;
var phrase = data[0];
var code = 256;
for (var i=1; i<data.length; i++) {
currChar=data[i];
@edankwan
edankwan / build.js
Created October 26, 2012 15:00 — forked from millermedeiros/build.js
sample node.js build script including RequireJS optimizer (r.js) and copy/delete/filter files
// Combine JS and CSS files
// ---
//
// Make sure you install the npm dependencies
// > cd YOUR_PROJECT_FOLDER
// > npm install
//
// Than run:
// > node build
@edankwan
edankwan / Modernizr_preserve-3d_test.js
Last active October 31, 2017 10:12
preserve-3d test for Modernizr based on https://gist.github.com/4123325
(function(Modernizr, win){
Modernizr.addTest('csstransformspreserve3d', function () {
var prop = Modernizr.prefixed('transformStyle');
var val = 'preserve-3d';
var computedStyle;
if(!prop) return false;
prop = prop.replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
@edankwan
edankwan / console.expand.js
Created January 29, 2013 15:38
A function to allow expanding the object/array in console. NOT working on dom elements or functions as I use JSON.stringify.
if (window.console && window.JSON) console.expand = function () {
var i, j;
var output = '';
var str = JSON.stringify(arguments);
var pos = 0;
var len = str.length;
var indent = ' ';
var newLine = '\n';
var char = '';
for (i = 0; i < len; i++) {
/* modernizr-test_position_fixed_ios.js
* Original by Daniel Ott (https://gist.github.com/1333800)
* 3 March 2011
* Updated by Philipp Söhnlein 3 November 2011
* Custom Tests using Modernizr's addTest API
*/
/* iOS
* There may be times when we need a quick way to reference whether iOS is in play or not.
* While a primative means, will be helpful for that.
;(function(Modernizr, window) {
Modernizr.addTest('positionfixed', function () {
var test = document.createElement('div'),
control = test.cloneNode(false),
fake = false,
root = document.body || (function () {
fake = true;
return document.documentElement.appendChild(document.createElement('body'));
}());
@edankwan
edankwan / bookmarklet.txt
Last active December 16, 2015 02:39
A snippet which will show an input prompt that you can inject the library from the cdn to the current website for debugging
javascript:(function(){var a=prompt("Enter the url: ","//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js");if(a.length>0){var b=document.createElement("script"),c=document.getElementsByTagName("script")[0];b.src=a,c.parentNode.insertBefore(b,c)}})();
@edankwan
edankwan / modernizr.customshader.js
Created April 29, 2013 06:21
Custom shader test for Modernizr
(function(){
Modernizr.addTest('customfilter', function () {
var prop = 'filter';
var prefixedProp = ['WebkitFilter', 'MozFilter', 'msFilter', 'OFilter', 'filter'];
var prefixCSS = ['-webkit-filter', '-moz-filter', '-ms-filter', '-o-filter', 'filter'];
var val = 'custom(url(data:text/plain;base64,))';
var computedStyle;
for(var i = 0, len = prefixCSS.length; i < len; i++) {