Skip to content

Instantly share code, notes, and snippets.

View kixxauth's full-sized avatar

Kris Walker kixxauth

View GitHub Profile
@kixxauth
kixxauth / namespaced-events.coffee
Created May 30, 2011 13:59
Namespaced and "stateful" event emitter.
###
# Kris Walker <kixxauth@gmail.com>
# Copyright 2011 Licensed under the MIT License http://opensource.org/licenses/mit-license.php
#
# Namespaced and Stateful events
# * Event names are namespaced
# * Event name specificity is separated by a dot "."
# * Event names get more specific from left to right.
#
@kixxauth
kixxauth / node-static-hang.coffee
Created June 25, 2011 22:58
Hanging responses from Node-static
# This is a factory function which creates a middleware handler
# for serving static files.
#
# We have to use staticServer.serveFile() instead of .serve() because
# we are dynamically rewriting the file path based on the name of the
# application asking for the file.
resourceHandler = (opts) ->
staticServer = new static.Server(STATIC_PATH)
@kixxauth
kixxauth / test_request.js
Created June 26, 2011 11:57
Make a request to an http server
// Call this script with a http URL as the single argument:
// node test_request.js http://www.google.com
var http = require('http');
var url = require('url');
parsed = url.parse(process.argv[2]);
var opts = {
port: 80,
@kixxauth
kixxauth / base.html
Created June 27, 2011 16:13
Conditional HTML root tag based on browser
<!doctype html>
{# <!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ --> #}
<!--[if lt IE 7 ]> <html class="no-js ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]> <html class="no-js ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]> <html class="no-js ie8" lang="en"> <![endif]-->
<!--[if IE 9 ]> <html class="no-js ie9" lang="en"> <![endif]-->
<!--[if !(IE)]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<style>/* This works just as well in a stylesheet, of course */
@kixxauth
kixxauth / better-javascript.js
Created March 31, 2012 17:41
JavaScript Objects and Promises
//
// Typical Prototype composure in JS; This is the classical way of creating and
// using objects in JS.
//
// "Super" or "Parent" object prototype
function Cat(color) {
this.color = color;
this.saying = 'meowwww';
}
@kixxauth
kixxauth / sane-modal.html
Created October 1, 2012 14:42
Sane Modal Dialog
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sane Modal</title>
<meta name="viewport" content="width=device-width">
</head><body>
<!-- All "normal" content goes in the base layer -->
<div id="base-layer">
@kixxauth
kixxauth / broken.html
Created October 11, 2012 10:18
Good Modal Dialogs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sane Modal</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="positioned.css">
</head><body>
<div id="base-layer">
@kixxauth
kixxauth / backbone-one.js
Created November 19, 2012 16:56
Backbone.js Single Event Listener Registration
Backbone.Events.one = function (events, callback, context) {
var self = this;
function wrapper() {
self.off(events, wrapper, context);
callback.apply(this, arguments);
}
this.on(events, wrapper, context);
};
@kixxauth
kixxauth / conditional.html
Created November 29, 2012 13:52
Development Mode in Web Browsers
<script>
// Conditionally load Google Analytics
if (!PAGE.inDevmode) {
var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
}
@kixxauth
kixxauth / index.html
Created January 12, 2013 18:07
Avoid parsing JavaScript on older devices. From https://m.lanyrd.com/
<head>
<script>
(function() {
var d = document,
w = window,
de = d.documentElement,
os = w.applicationCache && w.JSON && w.localStorage,
om = window.operamini,
pe = 'pointerEvents' in de.style && !window.opera, // Opera gives false positive
bs = 'backgroundSize' in de.style && !om; // Opera Mini gives false positive