Skip to content

Instantly share code, notes, and snippets.

View kixxauth's full-sized avatar

Kris Walker kixxauth

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / struct.js
Created May 6, 2011 18:11
Data structure for Royal Node
/**
* DAG node
* --------
*/
var tabbar =
[
{ name: "tabname",
title: "Title",
thumbnail: "Icon",
resource_type: "list, movie, image, ...",
@kixxauth
kixxauth / long-polling.html
Created April 11, 2011 01:21
A Node.js http long polling server for HTTP streaming.
<!DOCTYPE html>
<html>
<style type="text/css">
body {
font-size: 18px;
background: #000;
color: #fff;
}
#container {
width: 600px;