Skip to content

Instantly share code, notes, and snippets.

View ralphholzmann's full-sized avatar

Ralph Holzmann ralphholzmann

View GitHub Profile
@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"
}
@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" );
public function __construct( $params = null, $load = true ) {
}
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 );
}
@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("."),
@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 / 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();
})
}
DropboxClient.prototype.putFile = function(file, path, optargs, cb) {
if (typeof optargs == 'function') cb = optargs, optargs = {};
var boundary = 'sAxIqse3tPlHqUIUI9ofVlHvtdt3tpaG',
content_type = 'multipart/form-data; boundary=' + boundary,
self = this;
require('fs').readFile(file, function (err, data) {
if (err) return cb(err);
// Build request body.
path = escapePath(path);
/**
* Yepnope JS
*
* Version 0.2.6pre
*
* by Alex Sexton - AlexSexton@gmail.com
*
* Tri-Licensed WTFPL, BSD, & MIT
*/
(function(window, doc, undef) {
@ralphholzmann
ralphholzmann / iframe-facebook.js
Created November 13, 2010 19:44
Modernizr tests to detect if you're in an iframe or facebook iframe
Modernizr
.addTest('iframe', function() {
return window.top.location != window.location;
})
.addTest('facebook', function() {
return !! ~ location.href.indexOf( 'fb_sig_in_iframe=1' );
});