This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Fruit { | |
fn eat(&self); | |
} | |
struct Apple { | |
x: int | |
} | |
impl Fruit for Apple { | |
fn eat(&self) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = module.exports = express.createServer(); | |
app.get('/', function(req, res){ | |
process.nextTick(function () { | |
nonexistantFunc(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var sys = require('sys'); | |
process.exceptionCatcher = function (e) { | |
sys.puts('Catcher 1 catches "' + e.message + '"'); | |
sys.puts('Catcher 1 returns'); | |
} |
NewerOlder