Skip to content

Instantly share code, notes, and snippets.

View brianleroux's full-sized avatar
💚
You are now aware that you are breathing

Brian LeRoux brianleroux

💚
You are now aware that you are breathing
View GitHub Profile
@isaacs
isaacs / comma-first-var.js
Created April 6, 2010 19:24
A better coding convention for lists and object literals in JavaScript
// See comments below.
// This code sample and justification brought to you by
// Isaac Z. Schlueter, aka isaacs
// standard style
var a = "ape",
b = "bat",
c = "cat",
d = "dog",
@alunny
alunny / client-side-xauth.js
Created June 21, 2010 22:39
accessing twitter xAuth through client-side JS
/*****
To authorize on Twitter API through xAuth, you need HMAC-SHA1
I'm using the following lib for that:
http://jssha.sourceforge.net
Make sure you have sha.js included!
<script src="http://jssha.sourceforge.net/sha.js"></script>
Also, you need to email api@twitter.com to get xAuth access
I cannot do that for you - see http://dev.twitter.com/pages/xauth
// by way of http://dmitry.baranovskiy.com/post/typeof-and-friends
function is(o, type) {
type = String(type).toLowerCase();
return (type == "null" && o === null) ||
(type == typeof o) ||
(type == "object" && o === Object(o)) ||
(type == "array" && Array.isArray && Array.isArray(o)) ||
Object.prototype.toString.call(o).slice(8, -1).toLowerCase() == type;
}
Object.defineProperty(Object.prototype, "extend", {value: function (obj) {
obj.__proto__ = this;
return obj;
}});
Object.defineProperty(Object.prototype, "new", {value: function () {
var obj = Object.create(this);
if (obj.initialize) obj.initialize.apply(obj, arguments);
return obj;
}});
@davejohnson
davejohnson / Android-plugin-java-example
Created September 3, 2010 22:21
phonegap-android-plugin-java-example
package com.example;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
function Cache() { }
Cache.prototype.getCachedPathForURI = function(uri, success, fail) {
return PhoneGap.execAsync(function(args) {
success(uri, args.file);
}, function(args) {
fail(uri, args.message);
}, 'com.example.URLCache', 'getCachedPathForURI', [uri, 'FOO']);
};

Module Constructor

This is a proposal for the inclusion of an additional primordial variable to all ECMAScript contexts.

  • There MUST be a primordial function Module(text, fileName, lineNo)
    • text MUST be parsed the body of a strict-mode Function
    • Module MAY throw a SyntaxError
    • fileName is an optional name for the text, for debuggers
  • lineNo defaults to 1, is coerced to Number internally, and represents the line
@shripadk
shripadk / gist:652819
Created October 29, 2010 03:10
Express authentication using Redis for session store and Couchdb for database (in coffeescript!)
###
Module dependencies
###
require.paths.unshift "#{__dirname}/lib/support/express-csrf/"
require.paths.unshift "#{__dirname}/lib/support/node_hash/lib/"
express = require 'express'
app = module.exports = express.createServer()
RedisStore = require 'connect-redis'
@3rd-Eden
3rd-Eden / server.js
Created December 12, 2010 22:36
Running HTTPS and HTTP over the same route using the EventEmitter
// Include required modules
var crypto = require( "crypto" )
, http = require( "http" )
, fs = require( "fs" );
// Build our default app, just like would normally do
var app = http.createServer(function (req, res) {
res.writeHead(200, { "Content-Type": "text/plain" } );
res.end( "Double http server, over http and https\n" );
});
@aaronrussell
aaronrussell / jquery.mobile.event.js
Created December 16, 2010 13:36
Slightly modified version of jQuery Mobile's event handlers so can be used standalone without the rest of the framework
/*
* jQuery Mobile Framework : events
* Copyright (c) jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*/
(function($, undefined ) {
$.extend( $.support, {
orientation: "orientation" in window,