Skip to content

Instantly share code, notes, and snippets.

View premasagar's full-sized avatar

Prem Rose premasagar

View GitHub Profile
@premasagar
premasagar / blur.html
Created July 1, 2011 13:28
SVG blur filter
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>SVG Blur</title>
</head>
<body>
<h1>SVG filters: blurring</h1>
@premasagar
premasagar / jsonpx.html
Created June 29, 2011 17:43
Wrap random content (e.g. HTML source code) in a JSONP-transportable JavaScript string
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>jsonpx-ify</title>
<script src=jquery.js></script>
<script src=jsonpx.js></script>
<style>
label, textarea, input, button {
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh
@premasagar
premasagar / tim-lite-cached-min.js
Created March 18, 2011 05:53
Tim (lite, cached), renamed to timLiteCached, for including in perf tests at http://jsperf.com/dom-vs-innerhtml-based-templating/111
var timLiteCached=function(){function i(b,e){return b.replace(m,function(g,c){for(var j=c.split("."),k=j.length,h=e,f=0;f<k;f++){h=h[j[f]];if(f===k-1)return h}})}var m=RegExp("{{\\s*([a-z0-9_][\\.a-z0-9_]*)\\s*}}","gi"),d={},l=window.JSON;return l?function(b,e){var g=l.stringify(e),c=d[b]&&d[b][g];if(c)return c;d[b]||(d[b]={});return c=d[b][g]=i(b,e)}:i}();
@premasagar
premasagar / tim-lite-min.js
Created March 18, 2011 05:53
Tim (lite), renamed to timLite, for including in perf tests at http://jsperf.com/dom-vs-innerhtml-based-templating/111
var timLite=function(){var e=/{{\s*([a-z0-9_][\\.a-z0-9_]*)\s*}}/gi;return function(f,g){return f.replace(e,function(h,i){for(var c=i.split("."),d=c.length,b=g,a=0;a<d;a++){b=b[c[a]];if(b===void 0)throw"tim: '"+c[a]+"' not found in "+h;if(a===d-1)return b}})}}();
// Use the test to create a simple element positioning function
function positionElemSimple(elem, x, y){
elem.style.cssText = "position:absolute;top:" + y + "px;left:" + x + "px;";
return elem;
}
function positionElem3d(elem, x, y){
var translate3d = "transform:translate3d(" + x + "px," + y + "px,0);";
@premasagar
premasagar / enumerables.js
Created January 17, 2011 17:59
Enumerable arrays and objects - useful methods
var forEach = Array.prototype.forEach ?
function(array, fn, thisp){
return array.forEach(fn, thisp);
} :
function(array, fn, thisp){
var i = 0,
arrayCopy = Object(array),
length = arrayCopy.length;
for (; i < length; i++){
Rules on omitting quotation marks from HTML5 attributes:
http://www.w3.org/TR/html-markup/syntax.html#syntax-attr-unquoted
An unquoted attribute value has the following restrictions:
* must not contain any literal space characters
* must not contain any """, "'", ">", "=", characters
* must not be the empty string
@premasagar
premasagar / numb.js
Created August 29, 2010 09:25
random numbers, ranges, rounding and more
var numb = {
/*
random integer
call it with the length of an array; returns a random
index or, if no argument suppplied, returns 0 or 1
e.g.
randomInt(); // will return 0 or 1
randomInt(3); // will return 0, 1 or 2
@premasagar
premasagar / 7z-ultra.sh
Created August 28, 2010 23:00
7z command line: adds directory "mydirectory" to archive myarchive.7z, using "ultra settings"
#!/bin/sh
# adds directory "mydirectory" to archive myarchive.7z, using "ultra settings"
7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on myarchive.7z mydirectory