Skip to content

Instantly share code, notes, and snippets.

View matthewhudson's full-sized avatar

Matthew Hudson matthewhudson

View GitHub Profile
@matthewhudson
matthewhudson / keybase.md
Created September 18, 2014 01:22
keybase.md

Keybase proof

I hereby claim:

  • I am matthewhudson on github.
  • I am matthewhudson (https://keybase.io/matthewhudson) on keybase.
  • I have a public key whose fingerprint is 7B45 9A21 41FC FCD3 46EF B079 43BE B01D 5135 4390

To claim this, I am signing this object:

@matthewhudson
matthewhudson / jquery.backgroundParallax.coffee
Created June 13, 2014 20:02
Nifty background parallax effect (requires underscore.js)
# Note that when compiling with coffeescript, the plugin is wrapped in another
# anonymous function. We do not need to pass in undefined as well, since
# coffeescript uses (void 0) instead.
do ($ = jQuery, window, document) ->
# window and document are passed through as local variable rather than global
# as this (slightly) quickens the resolution process and can be more efficiently
# minified (especially when both are regularly referenced in your plugin).
# Create the defaults once
@matthewhudson
matthewhudson / cipher.coffee
Created March 20, 2014 19:26
CoffeeScript Nodejs Cipher
crypto = require 'crypto'
key = 'monkeybutt'
cipher = crypto.createCipher 'aes128', key
decipher = crypto.createDecipher 'aes128', key
encrypt = (plaintext) ->
encrypted = cipher.update plaintext, 'utf8', 'base64'
encrypted += cipher.final 'base64'
@matthewhudson
matthewhudson / gist:8486693
Created January 18, 2014 05:46
Parrish's Law
During discussions of syncing, the chance that someone will mention #git approach 1
@matthewhudson
matthewhudson / parse-bitcoin-url.coffee
Created December 17, 2013 03:55
Parse a Bitcoin URL in CoffeeScript
# Parse bitcoin URL query keys.
parseBitcoinURL = (url) ->
r = /^bitcoin:([a-zA-Z0-9]{27,34})(?:\?(.*))?$/
match = r.exec(url)
return null unless match
parsed = url: url
if match[2]
queries = match[2].split("&")
i = 0
@matthewhudson
matthewhudson / parse-bitcoin-url.js
Last active March 20, 2018 11:45
Parse Bitcoin URL in JavaScript
/* Parse bitcoin URL query keys. */
function parseBitcoinURL(url) {
var r = /^bitcoin:([a-zA-Z0-9]{27,34})(?:\?(.*))?$/;
var match = r.exec(url);
if (!match) return null;
var parsed = { url: url }
if (match[2]) {
var queries = match[2].split('&');
@matthewhudson
matthewhudson / simple-memory-caching.coffee
Created November 19, 2013 16:25
Simple in-memory caching. Defaults to 2s
# Simple in-memory caching. Defaults to 2s
# http://jsperf.com/date-now-vs-new-date-gettime/4
store = {}
cache = {}
cache.set = (key, value, milliseconds) ->
if not store[key]?
store[key] = value
@matthewhudson
matthewhudson / pong.coffee
Created November 17, 2013 23:39
Sends anything from request back as JSON
# Sends anything from request back as JSON
exports.pong = (req, res) ->
# Create ping-pong response from received data
data =
pongQuery: req.query
pongBody: req.body
pongParams: req.params
pongCookies: req.cookies
id: req.params.id
controller: req.params.controller
@matthewhudson
matthewhudson / clone.coffee
Created September 16, 2013 02:01
Simple clone() implemented in coffee
clone = (obj) ->
return obj if not obj? or typeof (obj) isnt "object"
tmp = obj.constructor()
for key of obj
tmp[key] = clone(obj[key])
tmp
@matthewhudson
matthewhudson / app.js
Created August 23, 2013 15:44
BackboneJS: Automatically extend event from a base view
var ParentView = Backbone.View.extend({
'events': {
'click .parent-something': "onParentSomethingClick"
}
});
var ChildView = ParentView.extend({
'events': _.extend({
'click .something': 'onSomethingClick',
}, ParentView.prototype.events)