Skip to content

Instantly share code, notes, and snippets.

View tgallant's full-sized avatar
🌁
☕️☕️☕️

Tim Gallant tgallant

🌁
☕️☕️☕️
  • San Francisco, CA
View GitHub Profile
@tgallant
tgallant / pm.erl
Last active February 26, 2017 20:42
-module(pm).
-export([perimiter/1,area/1,enclosure/1,linearBits/1,bits/1]).
%% Shape objects:
%%
%% For the sake of brevity, all shape values
%% are expected to be positive integers.
%%
%% {circle, Radius}
%% {rectangle, {Width,Height}}
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
var saveFile = function(url) {
var file = url.split('/').pop();
request(url).pipe(fs.createWriteStream(file));
console.log('Downloading ' + file);
return true;
};
@tgallant
tgallant / main.cf
Created February 3, 2015 04:21
Postfix main.cf
smtpd_banner = $myhostname ESMTP $mail_name (FreeBSD)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
readme_directory = no
smtpd_tls_cert_file=/etc/ssl/certs/dovecot.pem
smtpd_tls_key_file=/etc/ssl/private/dovecot.pem
// sort items array and return the first three items
{{#items.sort(function() { return .5 - Math.random(); }).splice(0,3)}}
@tgallant
tgallant / e7.scm
Created November 5, 2014 06:53
euler7
;; helpers
(define (nth n l)
(if (or (> n (length l)) (< n 0))
(error "Index out of bounds.")
(if (eq? n 0)
(car l)
(nth (- n 1) (cdr l)))))
@tgallant
tgallant / e5.scm
Created November 4, 2014 05:29
euler5
;; helpers
(define (sum l)
(if (null? l)
0
(+ (car l) (sum (cdr l)))))
(define (sqr x)
(* x x))
@tgallant
tgallant / e4.scm
Created November 4, 2014 05:23
euler4
;; e4
(define (e4)
(define (e4-inner x y)
(let ((i (* x y)))
(if (> x 999)
'()
(if (< y 999)
(if (= i (rev i))
(cons i (e4-inner x (+ y 1)))
@tgallant
tgallant / e3.scm
Created November 4, 2014 05:18
euler3
;; e3
(define (e3 n)
(define (e3-inner num div)
(if (> num 1)
(if (= (modulo num div) 0)
(e3-inner (/ num div) (- div 1))
(e3-inner num (+ div 1)))
(+ div 1)))
(e3-inner n 2))
@tgallant
tgallant / e2.scm
Created November 4, 2014 05:14
euler2
;; helpers
(define (sum l)
(if (null? l)
0
(+ (car l) (sum (cdr l)))))
;; e2
(define (fib x)
@tgallant
tgallant / e1.scm
Last active August 29, 2015 14:08
euler1
;; e1
(define (mod-three-or-five? x)
(if (or
(= (modulo x 3) 0)
(= (modulo x 5) 0)) #t #f))
(define (e1 x)
(sum
(filter