Skip to content

Instantly share code, notes, and snippets.

@brigand
brigand / app.js
Last active October 21, 2024 14:29
React JS Event-Emitter Mixin and Example
var React = require("react"), Dom = React.DOM;
var LogOutButton = require('./src/logout');
var events = require('api/events');
var Main = React.createClass({
// this mixin provides this.emitLogout, and if we set onLogout it'll be called when "logout" is emitted
mixins: [events.mixinFor("logout")],
getInitialState: function(){
return {
@lsegal
lsegal / test-with-q.js
Created March 7, 2014 20:59
Uses promises with the AWS SDK for JavaScript
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
var Q = require('q');
var list = Q.nbind(s3.listBuckets.bind(s3));
list().then(function(data) {
console.log(data);
});
@jonbretman
jonbretman / type.js
Last active January 16, 2024 01:16
Simple type checking in JavaScript.
(function (root) {
var type = function (o) {
// handle null in old IE
if (o === null) {
return 'null';
}
// handle DOM elements
@imankulov
imankulov / db_test.py
Created June 24, 2013 12:44
Performance test for MySQL UPDATE
# -*- coding: utf-8 -*-
"""
Performance test for different types of update
Results sample
-----------------------------------------------
In [1]: import db_test
@mrlannigan
mrlannigan / res.render.js
Created February 27, 2013 21:02
res.render Override Middleware
/**
* Override res.render to do any pre/post processing
*/
app.use(function(req, res, next) {
var render = res.render;
res.render = function(view, options, fn) {
var self = this,
options = options || {},
req = this.req,
app = req.app,
@eligrey
eligrey / outerHTML.js
Created June 24, 2011 02:56
Efficient outerHTML polyfill that doesn't use cloneNode(true)
/*
* outerHTML.js
* Cross-browser full HTMLElement.outerHTML implementation.
*
* 2011-11-14
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
@borismus
borismus / gist:1032746
Created June 18, 2011 02:46
Convert a base64 string into a binary Uint8 Array
var BASE64_MARKER = ';base64,';
function convertDataURIToBinary(dataURI) {
var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
var base64 = dataURI.substring(base64Index);
var raw = window.atob(base64);
var rawLength = raw.length;
var array = new Uint8Array(new ArrayBuffer(rawLength));
for(i = 0; i < rawLength; i++) {