Skip to content

Instantly share code, notes, and snippets.

View n8agrin's full-sized avatar

Nathan Agrin n8agrin

View GitHub Profile
@n8agrin
n8agrin / net_http_digest_auth.rb
Created March 3, 2009 00:29
HTTP Digest Auth for Ruby's net/http
# Support for http digest auth
# Discovered here: http://johan.bingodisk.com/public/code/net_digest_auth.rb
require 'digest/md5'
require 'net/http'
module Net
module HTTPHeader
@@nonce_count = -1
CNONCE = Digest::MD5.new("%x" % (Time.now.to_i + rand(65535))).hexdigest
@n8agrin
n8agrin / Erlang tail recursion example.erl
Created June 13, 2009 15:29
Erlang tail recursion example
len([]) ->
0;
len([F|R]) ->
len(R,1).
len([],A) ->
A;
len([F|R],A) ->
len(R, A+1).
@n8agrin
n8agrin / Fix for distcc distccd macports installer
Created June 13, 2009 15:36
Fix for distccd macports installer
#!/bin/sh
#
# Originally found here: http://jenders.vox.com/library/post/macports-workaround-for-installing-distcc-31-on-an-intel-mac.html
#
makefile=/opt/local/var/macports/sources/rsync.macports.org/release/ports/devel/distcc/work/distcc-3.1/Makefile
if test -e $makefile; then # user has a half completed installation
break
require 'net/https'
require 'uri'
SITE_URI = ''
SITE_CA = ''
USERNAME = ''
PASSWORD = ''
uri = URI.parse(SITE_URI)
http = Net::HTTP.new(uri.host, uri.port)
function pmt(start, rate_as_percentage, num_periods, lifetime) {
var rate_per_period = ((rate_as_percentage/100) / num_periods);
// e.g. num_periods == 12 months, lifetimes = 4 years for 4 years, 12 months per year
var total_periods = num_periods * lifetime;
var p = (start * rate_per_period * Math.pow((1 + rate_per_period), total_periods)) / (Math.pow((1+rate_per_period), total_periods)-1);
console.log(Math.pow((1 + rate_per_period), total_periods));
return p;
}
- simple
- public over private
- personal vanity
- internet is global
- permalinks
- one important item per page
- don't break the browser
- don't wanker in technology
- a medium is not a grande
- break convention for your users
@n8agrin
n8agrin / osx_colors.sh
Created August 16, 2009 00:20
BSD terminal coloring
# Colors
# The available color codes are:
#
# a -- black
# b -- red
# c -- green
# d -- brown
# e -- blue
# f -- magenta
# g -- cyan
>>> t=tornado.template.Template('<html>{{ bar }}</html>')
>>> t.generate()
ERROR:root:<string> code:
1 def _execute():
2 _buffer = []
3 _buffer.append('<html>')
4 _tmp = bar
5 if isinstance(_tmp, str): _buffer.append(_tmp)
6 elif isinstance(_tmp, unicode): _buffer.append(_tmp.encode('utf-8'))
7 else: _buffer.append(str(_tmp))
#!perl -w
### Script for accessing SGD database via www. Produces 2 output files: ###
### 1) sgd.txt contains the gene name for the sequence according to SGD ###
### 2) blast.txt contains the webpage (html) turned into text ###
### Open the file the sequence is in (tab-delimited) ###
open SEQ,"<sequence.txt" || die;
### Put the file into an array ###
@n8agrin
n8agrin / jQuery.eachIn.js
Created January 26, 2010 07:50
safe eachIn method for object iteration in javascrip
jQuery.extend(jQuery, {
"eachIn": function(obj, callback) {
var ensureHas = function(key, val) {
if (obj.hasOwnProperty(key)) {
return callback(key, val);
}
}
return this.each(obj, ensureHas);
}
});