Skip to content

Instantly share code, notes, and snippets.

View premasagar's full-sized avatar

Prem Rose premasagar

View GitHub Profile
@premasagar
premasagar / strictify.sh
Last active August 29, 2015 14:27
prepend "use strict"
FILE=path/to/file.js && echo '"use strict";\n' | cat - $FILE > /tmp/out && mv /tmp/out $FILE
@premasagar
premasagar / Esc key trapping
Created March 20, 2010 15:13
Trap 'Esc' key
$(document).keydown(function(ev){
if (ev.which === 27){ // ESC key
close();
});
@premasagar
premasagar / git2tar.sh
Created March 29, 2010 15:15
Export an archive of a Git repository as a .tar file
#!/bin/sh
git archive master | tar -x -C ../exportDirectory
cd ../exportDirectory
tar -zcvf projectName.tar.gz projectName
#!/bin/sh
perl Makefile.PL
make
make test
sudo make install
// random number. Default: maximum of 4 digits
function rand(maxDigits){
var m = Math;
return m.floor(
m.random() * m.pow(10, maxDigits || 4)
);
}
@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;
}
}
});
@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
function compile (template) {
function addText (buffer, text, unescaped) {
unescaped = !!unescaped;
buffer.push("\tprint(");
buffer.push(unescaped ? text : "\"" + text
.split("\r").join("\\r")
.split("\n").join("\\n")
.split("\t").join("\\t")
.split("\"").join("\\\"")
+ "\""
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name, ?description, ?depiction, ?thumbnail, ?scientificName
FROM <http://www.bbc.co.uk/nature/species/Black_Grouse.rdf> {
?species a <http://purl.org/ontology/wo/Species>;
rdfs:label ?name;
dcterms:description ?description;
foaf:depiction ?depiction;
@premasagar
premasagar / trim.js
Created June 19, 2010 18:54
Fast, complete JavaScript trim
function trim(str){
return str.replace(/^[\0\t\n\v\f\r\s]+|[\0\t\n\v\f\r\s]+$/g, ''); // match the full set of whitespace characters
}