Skip to content

Instantly share code, notes, and snippets.

View jwerle's full-sized avatar
🔨
Working on @socketsupply/socket

Joseph Werle jwerle

🔨
Working on @socketsupply/socket
View GitHub Profile
@jwerle
jwerle / gfsn.js
Created November 27, 2012 20:53
Get Satisfaction quick implementation
/*
* The Daily Voice
* Copyright 2012 Daily Voice (www.DailyVoice.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@jwerle
jwerle / foo.new.js
Created January 5, 2013 21:48
.new method like Ruby for Javascript
/**
* With some magic getters/setters you can achieve similar syntax like Ruby
**/
function foo() { console.log('im foo') }
foo.__defineGetter__('new', function(){ return new foo })
f = foo.new
// >> im foo
void console.log((new foo) instanceof foo)
// >> im foo
@jwerle
jwerle / basic-simulation-node-module.js
Last active December 14, 2015 07:39
Basic simulation of a Node module
function Module(scope, global){
this.scope = scope;
this.exports = {};
this.global = global || window || this;
}
function ModuleError(message) {
Error.call(this);
Error.captureStackTrace(this, ModuleError);
this.name = 'ModuleError';
@jwerle
jwerle / overload-emit.js
Created May 14, 2013 20:36
overload .emit()
var http, server, emit
http = require('http')
server = http.createServer(function () { console.log('ok') })
emit = emit = server.emit
server.emit = function () {
// log it out
console.log('[server]:', arguments[0])
// apply old emit
emit.apply(this, arguments);
};
var mongoose = require('mongoose'),
Config = mongoose.model('Config')
exports.create = function(req, res) {
var conf = new Config(req.body);
console.log(conf)
conf.save(function(err) {
@jwerle
jwerle / ready.js
Last active December 18, 2015 16:59
ready function
var app = {}
!function (app) {
// boolean to indicate whether
// the `app` is ready
var isReady = false;
// the ready stack to house
// all of the callbacks pushed
// to it
var app = {}
!function (app) {
// container to push booleans
// for each event to indicate whether
// the `app` is ready
var isReady = [];
// the ready stack to house
// all of the callbacks pushed
@jwerle
jwerle / gist:5978791
Created July 11, 2013 20:11
match div ids with filter
[].filter.call(document.querySelectorAll('div'), function (div) { return (/^foo_*/).test(div.id); })
@jwerle
jwerle / stop-animation-frame.js
Last active December 19, 2015 21:49
stop animation frame
function stopAnimations () {
// Get the Body Element
var body = document.body
body.addEventListener('webkitAnimationStart', stopAnimation, false);
body.addEventListener('webkitAnimationIteration', stopAnimation, false);
body.addEventListener('animationstart', stopAnimation, false);
body.addEventListener('animationiteration', stopAnimation, false);
function stopAnimation (e) {
var target = e.target;
@jwerle
jwerle / log.c
Last active December 24, 2015 00:49
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int
main (void) {
double v, r;
v = 1000.0;
r = log10(v);
printf("%f\n", r);