Skip to content

Instantly share code, notes, and snippets.

View matthewhudson's full-sized avatar

Matthew Hudson matthewhudson

View GitHub Profile
@matthewhudson
matthewhudson / index.html
Last active December 18, 2015 08:00
Vertical center content with CSS
<div class="container-outer">
<div class="container-middle">
<div class="container-inner">
<p>Hello World!</p>
</div>
</div>
</div>
class GUID
s4: ->
Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1)
create: () ->
"#{@s4()}#{@s4()}-#{@s4()}-#{@s4()}-#{@s4()}-#{@s4()}#{@s4()}#{@s4()}"
guid = new GUID
console.log guid.create()
<style>.wf-loading{visibility:hidden}</style>
<script type="text/javascript">
(function (doc) {
var config = {
kitId: 'abc1def',
scriptTimeout: 3000
};
var getElement = function (tagName) {
@matthewhudson
matthewhudson / namespaced.js
Created August 3, 2013 20:05
Namespaced JS events
var BaseView = Backbone.View.extend({
el: $('body'),
initialize: function() {
// bind to the namespaced (for easier unbinding) event
// in jQuery 1.7+ use .on(...)
$(window).bind("resize.app", _.bind(this.resize, this));
},
@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)
@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 / 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 / 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 / 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 / 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