Skip to content

Instantly share code, notes, and snippets.

View premasagar's full-sized avatar

Prem Rose premasagar

View GitHub Profile
@remy
remy / details.js
Created April 18, 2010 22:28
Add <details> support - includes stylesheet
/**
* Note that this script is intended to be included at the *end* of the document, before </body>
*/
(function (window, document) {
if ('open' in document.createElement('details')) return;
// made global by myself to be reused elsewhere
var addEvent = (function () {
if (document.addEventListener) {
return function (el, type, fn) {
@premasagar
premasagar / getby.js
Created June 3, 2010 21:18
Pluck an object that contains a key and optional value
// Pluck an object that contains a key and optional value
function getBy(enumerable, findProperty, findValue){
return jQuery.map(enumerable, function(el){
if (typeof el[findProperty] !== 'undefined'){
if (typeof findValue === 'undefined' ||
el[findProperty] === findValue){
return el;
}
}
});
@vicalejuri
vicalejuri / django-crossdomainxhr-middleware.py
Created June 5, 2010 17:47
Middlware to allow's your django server to respond appropriately to cross domain XHR (postMessage html5 API).
import re
from django.utils.text import compress_string
from django.utils.cache import patch_vary_headers
from django import http
try:
import settings
XS_SHARING_ALLOWED_ORIGINS = settings.XS_SHARING_ALLOWED_ORIGINS
// loop through the 'paper' variable from Raphael JS and build up the JSON object describing all images and paths within it.
loadJSON = function(paper, json) {
var set = paper.set();
$.each(json, function(index, node) {
try {
var el = paper[node.type]().attr(node);
set.push(el);
} catch(e) {}
});
return set;
@premasagar
premasagar / pngcrush.sh
Created June 12, 2010 19:04
Highest minification with pngcrush
# single image
pngcrush -rem alla -brute -reduce src.png dest.png
# directory of images
pngcrush -rem alla -brute -reduce -d outputdir ./*.png
module.exports = {a: 'async'}
console.log('in >> '+__filename)
window._gzip = (function()
{
var _matchCount = function(s, word)
{
var n = 0, wordLen = word.length, p = -wordLen;
while((p = s.indexOf(word, p + wordLen)) > -1)
++n;
return n;
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active May 16, 2024 16:51
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
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 https://www.npmjs.org/install.sh | sh
/* A lightweight templating system.
*
* Based on Tim (http://github.com/premasagar/tim) and Mustache
* (http://github.com/janl/mustache.js).
*
* Template supports simple value replacement as well as block
* functions, iterators and conditionals
*
* Template strings can contain either plain tokens `{{token}}`
* which are replaced with their equivilent value in the data
@cowboy
cowboy / HEY-YOU.md
Last active May 16, 2024 13:31
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.