Skip to content

Instantly share code, notes, and snippets.

@benw
benw / create_tables.sql
Created February 7, 2016 20:17
Postgres schema for reasonwell.com
\set ON_ERROR_STOP
CREATE TABLE Sites (
id SERIAL PRIMARY KEY,
base_url VARCHAR NOT NULL,
title VARCHAR NOT NULL,
public_read BOOLEAN NOT NULL DEFAULT FALSE,
allow_anyone BOOLEAN NOT NULL DEFAULT FALSE,
allow_unverified BOOLEAN NOT NULL DEFAULT FALSE,
trait Fruit {
fn eat(&self);
}
struct Apple {
x: int
}
impl Fruit for Apple {
fn eat(&self) {
@benw
benw / list.rs
Created May 28, 2013 02:12
In which I learn to use the ref keyword.
enum List {
Nil,
Node(int, ~List)
}
fn walk(l: &List) -> ~str {
match *l {
Node(i, ref rest) => fmt!("%d %s", i, walk(*rest)),
Nil => ~"end"
}
$('button.accept-terms').click(function (e) {
$(e.target).attr('disabled', 'disabled');
$.ajax({
type: 'POST',
url: '/settings',
data: {
_csrf: window._csrf,
accept_terms: true
},
success: function (data, textStatus, jqXHR) {
@benw
benw / load-hbs-partials.js
Created October 3, 2012 00:29
Loads partial handlebars templates from files in a directory
// Helps with this problem:
// http://stackoverflow.com/questions/8059914/express-js-hbs-module-register-partials-from-hbs-file
var hbs = require('hbs');
var fs = require('fs');
var partialsDir = __dirname + '/../views/partials';
var filenames = fs.readdirSync(partialsDir);
@benw
benw / ms.js
Created December 21, 2011 00:57 — forked from rauchg/ms.md
Milliseconds conversion utility.
/**
# ms.js
No more painful `setTimeout(fn, 60 * 4 * 3 * 2 * 1 * Infinity * NaN * '☃')`.
ms('2d') // 172800000
ms('1.5h') // 5400000
ms('1h') // 3600000
ms('1m') // 60000
var express = require('express');
var app = module.exports = express.createServer();
app.get('/', function(req, res){
process.nextTick(function () {
nonexistantFunc();
});
});
var sys = require('sys');
var http = require('http');
var port = 3000;
http.createServer(dispatchRequest).listen(port);
sys.puts('Server running on port ' + port);
// This is the web framework, which wants to send
Throwing from main
uncaughtException catches "thrown by main"
Timeout 1 throws
Catcher 1 catches "thrown by Timeout 1"
Catcher 1 returns
Timeout 2 throws
Catcher 2 catches "thrown by Timeout 2"
Catcher 2 throws
uncaughtException catches "thrown by Catcher 2"
#!/usr/bin/env node
var sys = require('sys');
process.exceptionCatcher = function (e) {
sys.puts('Catcher 1 catches "' + e.message + '"');
sys.puts('Catcher 1 returns');
}