Skip to content

Instantly share code, notes, and snippets.

@jammycakes
jammycakes / bind.js
Last active March 10, 2023 08:54
A replacement for jQuery.on() with a fluent interface
// Usage: bind(event).to(element).for(selector).as(handler)
// e.g. bind("click").to(document.documentElement).for("a").as(e => console.log(e.target.href));
function bind(event) {
return {
to: function(element) {
element = isString(element) ? document.getElementById(element) : element;
return {
as: function(handler) {
@jammycakes
jammycakes / dropall.sql
Created March 26, 2014 15:27
A script to drop all objects from a SQL Server database
declare @name varchar(100)
declare @table varchar(100)
-- Drop all foreign key constraints: this goes through alter table
declare c cursor for
select a.name as [constraint], b.name as [table] from dbo.sysobjects a
inner join dbo.sysobjects b on a.parent_obj = b.id
where a.xtype='F' and b.xtype='U'
open c
@jammycakes
jammycakes / deps.js
Created February 28, 2012 00:59
Node.js script to install dependencies using npm
var child_process = require('child_process');
function install(modules, callback) {
if (modules.length == 0) {
if (callback) callback(null);
return;
}
var module = modules.shift();
child_process.exec(
'npm install ' + module,