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
;; 0: | |
(-> Math/E Math/toRadians Math/round) | |
;; 1: | |
(-> Math/E Math/log Math/round) | |
;; 2: | |
(-> Math/E Math/sqrt Math/round) | |
;; 3: | |
(-> Math/E Math/round) | |
;; 4: | |
(-> Math/PI Math/ceil Math/round) |
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
ruby -e "Dir.glob('*.yml.example'){|x| system \"cp #{x} #{x.split('.')[0..-2].join('.')}\"}" |
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
# Rails3 way to redirect non-www domain to www domain | |
# Single domain redirect | |
'example.com'.tap do |host| | |
constraints(:host => host) do | |
match '/(*path)', :to => redirect { |params, request| Addressable::URI.escape request.url.sub(host, "www.#{host}") } | |
end | |
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
# blog post: http://blog.slashpoundbang.com/post/12938588984/google-refine-fingerprint-clustering-algorithm-in-ruby | |
# coding: utf-8 | |
require 'unicode_utils/downcase' | |
class String | |
# Normalize spaces and fingerprint. | |
# http://code.google.com/p/google-refine/wiki/ClusteringInDepth | |
# http://code.google.com/p/google-refine/source/browse/trunk/main/src/com/google/refine/clustering/binning/FingerprintKeyer.java | |
def fingerprint |
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
# | |
# = Capistrano database.yml task | |
# | |
# Provides a couple of tasks for creating the database.yml | |
# configuration file dynamically when deploy:setup is run. | |
# | |
# Category:: Capistrano | |
# Package:: Database | |
# Author:: Simone Carletti <weppos@weppos.net> | |
# Copyright:: 2007-2010 The Authors |
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
function sample(list, m) { | |
var n = list.length; | |
if (m > n) return void console && | |
console.log('list length must be > sample'); | |
var sampleList = []; | |
for (var i = n - m; i < n; i++) { | |
var item = list[~~(Math.random() * i)]; | |
if (sampleList.indexOf(item) !== -1) | |
sampleList.push(list[i]); | |
else |
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
// This is *not* valid Go! | |
func Map(f func(A) B, xs []A) []B { | |
ys := make([]B, len(xs)) | |
for i, x := range xs { | |
ys[i] = f(x) | |
} | |
return ys | |
} | |
Map(func(x int) int { return x * x }, []int{1, 2, 3}) |
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
// data comes from here http://stat-computing.org/dataexpo/2009/the-data.html | |
// download 1994.csv.bz2 and unpack by running: cat 1994.csv.bz2 | bzip2 -d > 1994.csv | |
// 1994.csv should be ~5.2 million lines and 500MB | |
// importing all rows into leveldb took ~50 seconds on my machine | |
// there are two main techniques at work here: | |
// 1: never create JS objects, leave the data as binary the entire time (binary-split does this) | |
// 2: group lines into 16 MB batches, to take advantage of leveldbs batch API (byte-stream does this) | |
var level = require('level') |
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
d3.xml("/data/GoldenGate2012Results.xml", function(xml) { | |
var runners = d3.select(xml).selectAll("runner")[0]; | |
var table = d3.select("#presentation").append("table").attr("class","grid"); | |
var thead = table.append("thead"); | |
thead.append("th").text("Gender"); | |
thead.append("th").text("City"); | |
thead.append("th").text("Time"); | |
thead.append("th").text("Pace"); |
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
# Clone rbenv into ~/.rbenv | |
git clone git@github.com:sstephenson/rbenv.git ~/.rbenv | |
# Add rbenv to your PATH | |
# NOTE: rbenv is *NOT* compatible with rvm, so you'll need to | |
# remove rvm from your profile if it's present. (This is because | |
# rvm overrides the `gem` command.) | |
echo 'export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"' >> ~/.bash_profile | |
exec $SHELL |
OlderNewer