Skip to content

Instantly share code, notes, and snippets.

View premasagar's full-sized avatar

Prem Rose premasagar

View GitHub Profile
@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;
}
}
});
// 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;
/* 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
@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++){
#!/usr/bin/python
from osgeo import ogr
import sqlite3, sys, time
def parse_pts(f, lyr):
uuid = 0
con = sqlite3.connect(f)
pts = con.execute('select Latitude, Longitude, HorizontalAccuracy, Timestamp from CellLocation;')
@makoto
makoto / gist:963717
Created May 10, 2011 00:29
hack4japan uk

Hack 4 Japan UK Ideathon & Hackathon

Summary

hack4japan is a series of ideathon and hackathon events for Japan Tsunami relief and recovery effort. So far several meetings, ideathons and hackathons were held in March both online in English/Japanese and offline (Kyoto, Okayama, Tokushima, Fukuoka and Fukushima) in Japanese. The detail of the first event is here.

The next meeting will be held in Sendai city (Miyagi), Wakamatsu city (Fukushima),Tokyo in Japanese during 21st and 22nd May, and we will be also hosting a satellite event in London (UK) in English on 22nd May.

anonymous
anonymous / bootstrap.sh
Created June 2, 2011 17:19
Django on Heroku with Celery and Sentry
virtualenv --no-site-packages .
source bin/activate
bin/pip install Django psycopg2 django-sentry
bin/pip freeze > requirements.txt
bin/django-admin.py startproject mysite
cat >.gitignore <<EOF
bin/
include/
lib/
EOF