Skip to content

Instantly share code, notes, and snippets.

@npow
npow / rot13.bash
Created August 24, 2011 19:07 — forked from noqqe/rot13.bash
An implementation of rot13 encryption written in pure bash
#!/bin/bash
# Choose your favorite table
# classic
SIGNS=( a b c d e f g h i j k l m n o p q r s t u v w x y z )
# advanced
#SIGNS=( a b c d f e h g j i l k m n o p q r s t u v w x y z . - ? ! "#" "+" )
@npow
npow / namespace.js
Created June 2, 2012 20:18
Namespace
function namespace(str) {
var L = str.split('.');
function ns(last, L) {
if (!L.length) return;
ns(last[L[0]] = last[L[0]] || {}, L.splice(1))
}
ns(window[L[0]] = window[L[0]] || {}, L.splice(1))
}
namespace("x.y.z");
namespace("x.b.c");
@npow
npow / getter.js
Created June 2, 2012 20:20
Attribute getter
Object.defineProperty(
Object.prototype,
"2",
{
get: function() {
/* some crazy side-effect */
}
}
);
new Float64Array(1)[2]
@npow
npow / gist:2902211
Created June 9, 2012 19:10
NodeJS return image
var http = require('http')
, fs = require('fs');
fs.readFile('image.jpg', function(err, data) {
if (err) throw err; // Fail if the file can't be read.
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'image/jpeg'});
res.end(data); // Send the file data to the browser.
}).listen(8124);
console.log('Server running at http://localhost:8124/');
@npow
npow / dnd.js
Created July 3, 2012 23:36
PhantomJS drag and drop
var page = require('webpage').create();
page.open('http://jsbin.com/ifuma#noedit', function () {
setTimeout(function () {
page.sendEvent("mousedown", 10, 10);
page.sendEvent("mousemove", 200, 200);
page.sendEvent("mouseup", 200, 200);
page.render('ss.png');
phantom.exit();
}, 3000);
});
Sets
i activity
/
free-lunch,
mixed-nuts,
orange-juice,
heavy-ddr-session,
cheese-snacks,
cookies,
mexican-coke,
@npow
npow / casper.js
Created July 6, 2012 19:14
CasperJS Demo
phantom.injectJs(phantom.casperPath + '\\bin\\bootstrap.js');
var casper = require('casper').create();
casper.start('http://localhost:1200/charts/ChartWrapperTest.htm', function() {
// setup options here
this.evaluate(function () {
document.getElementById('chartType').value = 4;
});
});
@npow
npow / curry.js
Created July 12, 2012 01:18
Curry in JavaScript
Function.prototype.curry = function() {
var fn = this;
var args = [].slice.call(arguments, 0);
return function() {
return fn.apply(this, args.concat([].slice.call(arguments, 0)));
};
}
@npow
npow / fallback.js
Created July 12, 2012 01:38
JavaScript fallbacks
'use strict';
// Add ECMA262-5 method binding if not supported natively
//
if (!('bind' in Function.prototype)) {
Function.prototype.bind= function(owner) {
var that= this;
if (arguments.length<=1) {
return function() {
return that.apply(owner, arguments);
@npow
npow / heapsize.js
Created August 9, 2012 02:37
JS Heap Size
#!/usr/bin/env ruby
require 'rubygems'
require 'watir-webdriver'
browser = Watir::Browser.new :chrome, :switches => %w[--enable-memory-info --enable-popup-blocking]
browser.goto 'file:///Users/npow/code/hydrogen/test.html'
browser.execute_script "document.getElementById('usedJSHeapSize').innerHTML = console.memory.usedJSHeapSize;"
hs = browser.div(:id => 'usedJSHeapSize')
puts hs.text