Skip to content

Instantly share code, notes, and snippets.

View ralphholzmann's full-sized avatar

Ralph Holzmann ralphholzmann

  • Fond du Lac, WI
View GitHub Profile
@ralphholzmann
ralphholzmann / oauthPercentDecode
Created May 25, 2011 14:32
encodeURIComponent doesn't follow rfc3986 that oauth requires. This is my fix...
var oauthPercentEncode = (function(){
var escapeChars = "!*'();:@&=+$,/?%#[]",
matchChars = new RegExp( "([\\" + ( escapeChars.split('').join('\\')) + "])", "gi");
return function( p ) {
return p.replace( matchChars, function( char ) {
return '%' + ( "" + char ).charCodeAt(0).toString(16).toUpperCase();
})
}
@ralphholzmann
ralphholzmann / charCounts.js
Created June 16, 2011 03:31
Paste this in the console at ralphholzmann.com to see the char distribution
var obj = {}, ordered = [];
$.get("js/jquery-1.6.1.min.js", function( src ) {
src.replace(/[^\w]|\d/gi, '').split('').forEach(function( c ) {
obj[ c ] ? ++obj[ c ] : ( obj[ c ] = 1 )
});
@ralphholzmann
ralphholzmann / gist:1038554
Created June 21, 2011 18:42 — forked from garann/gist:1038401
Challenge Accepted.
getEl = (function (doc) {
var getElementsByClassName = (function () {
return doc.getElementsByClassName ?
function (selector) {
return doc.getElementsByClassName(selector.split('.').pop());
} : function (selector) {
var parts = selector.split("."),
var db = new mongo.Db('myDB', new mongo.Server("localhost", "27017", {})),
to = "ralph";
db.open( function( err, p_client ) {
// Problem opening the database?
if ( err ) {
console.log( "db.open: " + err );
}
public function __construct( $params = null, $load = true ) {
}
@ralphholzmann
ralphholzmann / 1.js
Created August 1, 2011 14:57
exports.prop vs module.exports for a constructor
// Boo
exports.Person = function( first, last ) {
this.first = first;
this.last = last;
};
// In your app, you'd have to do
var Person = require( "person" ).Person, // woof.
me = new Person( "ralph", "holzmann" );
@ralphholzmann
ralphholzmann / gist:1483260
Created December 15, 2011 22:35
Templated event bindings
// Lets say you're making a plugin with the typical design of
// passing an object literal of options. Here's what you can do.
$.Controller("myPlugin", { // Static properties
// The options you pass get auto extended over these
defaults: {
className: "default-class"
}
success: function(data){
setTimeout(function(){
_.each( data.objects, function( obj ) {
var t = new Todo({
id: data.obj.id,
text: data.obj.text,
done: data.obj.done,
order: data.obj.order
});
var crypto = require('crypto'),
//sha1 = require('./sha1'),
http = require('http'),
https = require('https'),
url = require('url'),
util = require('util'),
querystring = require('querystring'),
_ = require("underscore"),
// OAuth constructor
@ralphholzmann
ralphholzmann / gist:1872549
Created February 21, 2012 00:29 — forked from rmurphey/gist:1329222
New computer setup notes