Skip to content

Instantly share code, notes, and snippets.

View matthewhudson's full-sized avatar

Matthew Hudson matthewhudson

View GitHub Profile
@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));
},
<style>.wf-loading{visibility:hidden}</style>
<script type="text/javascript">
(function (doc) {
var config = {
kitId: 'abc1def',
scriptTimeout: 3000
};
var getElement = function (tagName) {
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()
@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>
/* iPad in portrait & landscape */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* STYLES GO HERE */
}
/* iPad in landscape */
@media only screen
and (min-device-width : 768px)
@matthewhudson
matthewhudson / static-server.coffee
Last active December 15, 2015 08:19 — forked from ryanflorence/static_server.js
Run a static server from any directory.
http = require 'http'
url = require 'url'
path = require 'path'
fs = require 'fs'
port = process.argv[2] or 8888
headers =
'Content-Type': 'text/plain'
http.createServer( (request, response) ->
uri = url.parse(request.url).pathname
@matthewhudson
matthewhudson / README.markdown
Last active September 25, 2016 16:59
README Template

Description

Project Name is a...

For example ...

example code
fs = require 'fs'
{exec, spawn} = require 'child_process'
{series} = require 'async'
sh = (command) -> (k) ->
console.log "Executing #{command}"
exec command, (err, sout, serr) ->
console.log err if err
console.log sout if sout
console.log serr if serr
@matthewhudson
matthewhudson / text.js
Created March 12, 2013 20:18
Gently move <h1> downward on load.
<script type="text/javascript">
try{
Typekit.load({
active: function() {
$("h1").transition({ y: '33%' });
}
});
}
catch(e){}
@matthewhudson
matthewhudson / division-test.coffee
Created March 10, 2013 23:15
VowsJS + CoffeeScript
vows = require 'vows'
assert = require 'assert'
vows
.describe('Division by zero')
.addBatch
'when dividing a number by zero':
topic: -> 42/ 0
'we get Infinity': (topic) ->