Skip to content

Instantly share code, notes, and snippets.

View ded's full-sized avatar
🏃
always working, sometimes running

Dustin Diaz ded

🏃
always working, sometimes running
View GitHub Profile
@ded
ded / swift-hepers.swift
Last active August 29, 2015 14:23
Swiftys
// custom RegEx Class
// let string: String = "foo bar baz"
// let regex: Regex = "foo"
// regex.match(string) // true
// "foo".match(string) // true
// "foo bar baz" =~ "foo" // true
@ded
ded / app.js
Created May 15, 2013 17:24
get dependency tree
function init(config) {
var util = require('app/util')
, render = require('client/lib/render')
, router = require('client/lib/router')
, controllers = config.controllers
controllers.forEach(function (c) {
require(c)
})
}
@ded
ded / ender.delay.js
Created November 19, 2011 00:37
ender delay()
!function ($) {
$.ender({
delay: function (n) {
var mock = {}
, chain = []
, key
, $el = $(this)
for (key in $el) {
if (isFinite(key)) continue
!function (key) {
@ded
ded / app.js
Created October 21, 2011 23:14
Rails-like routes for Express
var express = require('express')
, app = express.createServer()
require('./config/routes').initialize(app)
!function (name, definition) {
if (typeof define == 'function' && define.amd) define(name, definition)
else if (typeof module != 'undefined') module.exports = definition()
else this[name] = definition()
}('thing', function () {
// codes
return module
})
@ded
ded / cmd
Created September 21, 2011 03:45
ender | backbone
ender build backbone
@ded
ded / parallel.js
Created July 21, 2011 01:10
call multiple async methods in parallel and receive the result in a callback
function parallel() {
var args = Array.apply(null, arguments)
, callback = args.pop()
, returns = []
, len = 0
args.forEach(function (el, i) {
el(function () {
var a = Array.apply(null, arguments)
, e = a.shift()
if (e) return callback(e)
@ded
ded / virtual-hosts-connect.js
Created July 13, 2011 01:08
run multiple hosts (domains) on a single node process
var connect = require('connect')
, app = require('./app')
, app2 = require('./app2')
connect(
connect.vhost('dustindiaz.com', app)
, connect.vhost('foobar.dustindiaz.com', app2)
).listen(3000)
test_script_elem = document.createElement("script"),
explicit_preloading = typeof test_script_elem.preload == "boolean",
real_preloading = explicit_preloading || (test_script_elem.readyState && test_script_elem.readyState == "uninitialized"),
script = document.createElement('script')
if (real_preloading) {
registry_item.elem = script;
if (explicit_preloading) {
@ded
ded / app.html
Created June 29, 2011 04:09
ender CLI example
<script src="ender.min.js"></script>
<script>
$.require('/js/core.min.js', 'core')
$.ready('core', function () {
$(document).ready(function () {
$('<p>hello world</p>').appendTo('body')
.bind('click', function (e) {
$.require('/js/ajax.min.js', function () {