Skip to content

Instantly share code, notes, and snippets.

View hayes's full-sized avatar

Michael Hayes hayes

View GitHub Profile
@hayes
hayes / compound-socket.js
Last active December 10, 2015 18:18
a quick way to get access to compound routing/controllers through socket.io
var sio = require('socket.io');
var fn = function () {};
var http = require('http');
module.exports = function (compound) {
var app = compound.app;
var server = http.createServer(app);
compound.server = server;
var io = compound.io = sio.listen(server);
@hayes
hayes / application.js
Last active December 10, 2015 20:38
basic controller inheritance
var Controller = require('base_controller');
var Application = module.exports = Controller.extend(function Application(init) {
init.before(function protectFromForgeryHook(ctl) {
ctl.protectFromForgery('13cf581adb4cd3c1cccce3604a6c044215f21679');
});
});
var Application = require('./application')
, User = compound.models.User;
var UserController = module.exports = function UserController(init) {
Application.call(this, init);
init.before(loadUser, {
only: ['show', 'edit', 'update', 'destroy']
});
};
@hayes
hayes / gist:5724622
Last active December 18, 2015 04:19
lat+lon to image with marker
<html>
<head>
</head>
<body>
lat:<input type="text" name="lat" value="45.52578"><br>
lon:<input type="text" name="lon" value="-122.683672"><br>
<img src="">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
@hayes
hayes / to_byte.js
Last active December 19, 2015 21:49
convert a string to a byte array
function to_bytes(str) {
var arr = []
, byte_count
, padding
, binary
, prefix
, bytes
, code
for(var i = 0, len = str.length; i < len; ++i) {
@hayes
hayes / request.js
Last active December 25, 2015 15:29
simple request function
function request(method, path, body, headers, ready) {
var xhr = new XMLHttpRequest
, zone
if(typeof headers === 'function') {
ready = headers
headers = {}
} else if(typeof body === 'function') {
ready = body
body = null
@hayes
hayes / commit-msg
Last active December 25, 2015 15:39
add branch name to commit if not on master
#!/bin/sh
#
# Simply prepends the branch name to every commit message
branch=$(git rev-parse --abbrev-ref HEAD)
if [ $branch != 'master' ] && [ $branch != 'HEAD' ]; then
echo "[$branch] `cat $1`" > $1
fi
@hayes
hayes / altr.patch
Created January 27, 2014 17:56
altr diff
diff --git a/lib/filters/add.js b/lib/filters/add.js
index 44d3f99..2c22e8a 100644
--- a/lib/filters/add.js
+++ b/lib/filters/add.js
@@ -1,12 +1,21 @@
var through = require('through')
-module.exports = function(num) {
- console.log(num)
- num = +num
{
"_id": "altr",
"_rev": "13-51f35b7d481978efdd85d1e3737f4d0f",
"name": "altr",
"description": "README.md",
"dist-tags": {
"latest": "0.0.6"
},
"versions": {
"0.0.0": {
var cls = require('continuation-local-storage')
, concat = require('concat-stream')
, http = require('http')
var foo = cls.createNamespace('foo')
http.createServer(foo.bind(function(req, res) {
req.pipe(concat(done))
function done() {