Skip to content

Instantly share code, notes, and snippets.

def process_file(name, f):
res = []
i = 0
for line in f:
add_emails(name, line, res)
add_emails2(name, line, res)
add_phone_numbers(name, line, res)
return res
# ruby set_heroku_config.rb | bash
vars = []
File.open('prod.config').each do |line|
key, val = line.chomp.split('=')
next unless val
vars << "#{key.sub(/export /, '')}=#{val.gsub(/'/, '')}"
end
;(use 'clojure.contrib.trace)
(defn boundaries
([ranges] (boundaries ranges []))
([ranges acc]
(if (empty? ranges)
(sort-by #(first %) acc)
(let [f (first ranges)]
(boundaries (rest ranges) (conj acc [(first f) :min] [(last f) :max]))))))
/* *** Javascript Library */
/*
---------- base.js -----------
*/
var pageHasLoaded = false;
var $break = new Object();
var $continue = new Object();
var $browser;
@abuggia
abuggia / phash.js
Created April 1, 2011 14:11
Js file from my (very early stage) rails app
$(function() {
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
@abuggia
abuggia / find_overlaps.scala
Created April 1, 2011 13:56
find overlaps of ranges
def find_overlaps(ranges: List[Range]): List[(Range)] = {
val bounds = for (range <- ranges; t <- List((range.head, 'min), (range.last, 'max))) yield t
var counter = 0
var prevMin = 0
var ret: Array[Range] = Array[Range]()
for (
tup <- bounds.sortWith((e1: Tuple2[Int, Symbol], e2: Tuple2[Int, Symbol]) => e1._1 < e2._1)) {
(tup._1, tup._2, counter) match {
@abuggia
abuggia / make_contact_email_spreadsheet.py
Created March 16, 2011 01:34
Create a spreadsheet from the "contact" emails collected on our web site.
import re
import sys
import time
from time import gmtime, strftime
company_re = re.compile("Company: ([^<]+)")
number_of_units_re = re.compile("Number of Units:\s*(\d+)")
# Date: Sun, 15 Mar 2009 21 : 50 :56 -0400
date_re = re.compile(r'Date: [A-Z][a-z]{2}, (\d{1,2}) ([A-Z][a-z]{2}) (\d\d\d\d) (\d\d)\:(\d\d)\:\d\d \-\d{4}')