Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
"""
The filename is grandiose. All this does is find the files in the
web/templates/mustache directory, and dump them all into web/static/js/templates.js as
members of the window.templates object.
"""
import os
import re
import json
@adambard
adambard / stupid_tricks.matlab
Created May 3, 2012 23:23
Stupid MATLAB Tricks.
function stupid_tricks
% I made some functional tools for MATLAB.
assert(reduce_(@(x, y) x + y, [1, 2, 3, 4]) == 10)
% They got a little out of hand.
join = @(sep, args) ...
if_(ischar(sep), @() ... % Input check
reduce_(@(x, y) [x sep y], ... % Reduce to string
map_(@num2str, args))); % Convert args to string.
@adambard
adambard / gist:2591653
Created May 4, 2012 03:08
Join in MATLAB, using the functools package.
join = @(sep, lst) ...
functools.if(~ischar(sep), @()[], @() ...
functools.reduce(@(x, y) [x sep y], ...
functools.map(@num2str, lst)));
@adambard
adambard / gist:2591773
Created May 4, 2012 03:28
Recursive anonymous factorial in MATLAB, using functools.
fact = functools.Y(@(self) @(n) ...
functools.if(n < 2,...
@() 1,
@() n * self(n - 1));
@adambard
adambard / smtp-proxy.py
Created May 9, 2012 17:24
Inbox.py example
"""
Proxy smtp to a starttls server with authentication, from a local
connection.
"""
from inbox import Inbox
from smtplib import SMTP
inbox = Inbox()
SMTP_HOST = 'mail.example.com'
@adambard
adambard / gist:2837521
Created May 30, 2012 16:42
Here's your try.
try {
assert(evaluate() == true);
return true;
} catch (AssertionError e){
return false;
}
@adambard
adambard / franslate.coffee
Created August 8, 2012 05:02
Coffeescript backing franslate.me
jQuery ->
class QuestionView extends Backbone.View
el: $('#main')
tmpl: mustache_templates.question
url: ''
events:
"click .answer": "check_answer"
@adambard
adambard / franslate.rb
Created August 8, 2012 05:06
Franslate, the sinatra part
require 'sinatra'
require 'json'
require 'mustache'
## INITIALIZATION ##########################
configure do
LANGS_AVAILABLE = {
'de' => 'languages/de_20k_trans.txt',
'fr' => 'languages/fr_20k_trans.txt',
@adambard
adambard / handle_invalid.clj
Created August 16, 2012 17:59
There is no such thing as lazy I/O
; Throws an error
(with-open [f (RandomAccessFile. "test_file.tmp", "rws")]
(map #(.writeInt f %1) (range 1000)))
; Runs happily
(with-open [f (RandomAccessFile. "test_file.tmp", "rws")]
(dorun (map #(.writeInt f %1) (range 1000))))
@adambard
adambard / app.rb
Created October 15, 2012 01:12
Voicemail-by-email with Twilio
require 'rubygems'
require 'twilio-ruby'
require 'sinatra'
require 'pony'
require 'open-uri'
# Config
MY_NUMBER = "+19995551234"
TO_EMAIL = "voicemail@adambard.com"
SMTP_HOST = "<SMTP hostname here>"