Skip to content

Instantly share code, notes, and snippets.

@chrisberkhout
chrisberkhout / dynamic removal of a dep, based on a condition.rb
Created February 16, 2010 06:49
Babushka: dynamic removal of a dep requirement, based on a condition evaluated after previous requires have been processed
# dynamic removal of a dep requirement,
# based on a condition evaluated after previous requires have been processed
dep 'site' do
requires \
'system',
'account',
'site dir',
'site options'
end
@chrisberkhout
chrisberkhout / data_table.rb
Created April 28, 2011 04:13
Extension to Ruport's Data::Table to do in-memory joins
class Ruport::Data::Table
def left_outer_join(right_table, field)
left_table = self
result = left_table.sub_table { |row| false }
new_col_names = right_table.column_names.reject { |i| i == field.to_s }
result.add_columns new_col_names
@chrisberkhout
chrisberkhout / gist:971942
Created May 14, 2011 05:26
Github's code for generating participation graphs
ParticipationGraph.prototype = {
readData: function () {
var a = this.data.split("\n");
this.allCommits = a[0] ? this.base64BytesToIntArray(a[0]) : "";
this.ownerCommits = a[1] ? this.base64BytesToIntArray(a[1]) : ""
},
// ...
base64ByteToInt: function (a) {
// This is known as modified Base64 for regexps: http://en.wikipedia.org/wiki/Base64#Regular_expressions
var d = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!-";
@chrisberkhout
chrisberkhout / via_mopera.net_apn.sh
Created July 17, 2011 05:28
Google: .com vs .co.jp (in Japan)
chris-berkhouts-macbook-pro-2:~$ ping google.com
PING google.com (74.125.153.147): 56 data bytes
64 bytes from 74.125.153.147: icmp_seq=0 ttl=46 time=136.270 ms
64 bytes from 74.125.153.147: icmp_seq=1 ttl=46 time=135.076 ms
64 bytes from 74.125.153.147: icmp_seq=2 ttl=46 time=135.428 ms
64 bytes from 74.125.153.147: icmp_seq=3 ttl=46 time=134.717 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 134.717/135.373/136.270/0.576 ms
@chrisberkhout
chrisberkhout / generic-relational-query.sql
Created August 12, 2011 01:10
Task: get all pieces of content including a certain list of keywords (e.g. ‘Air’, ‘Earth’, ‘Water’, ...)
SELECT
`contents`.*
FROM
`contents`
INNER JOIN `contents_keywords` `contents_keywords_0`
ON `contents`.`id` = `contents_keywords_0`.`content_id`
INNER JOIN `contents_keywords` `contents_keywords_1`
ON `contents`.`id` = `contents_keywords_1`.`content_id`
INNER JOIN `contents_keywords` `contents_keywords_2`
ON `contents`.`id` = `contents_keywords_2`.`content_id`
@chrisberkhout
chrisberkhout / hack.sh
Created April 14, 2012 00:22 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@chrisberkhout
chrisberkhout / pipes.rb
Last active December 11, 2015 12:19
Start of Pipes, which builds on ChildProcess to make piping between processes in Ruby as easy as in the shell
require "childprocess"
class Pipes
class NullBit
def initialize
@read, @write = IO.pipe
end
#!/bin/bash
function exitIfRunning {
if ps ax | grep -v grep | grep Harvest\.app > /dev/null
then
echo "You must quit Harvest before continuing."
exit 1
fi
}
@chrisberkhout
chrisberkhout / pascals_triangle.rb
Created April 3, 2013 05:20
Generate a row of Pascal's triangle, in Ruby
def pt(row)
return [1] if row == 0
return [1, 1] if row == 1
last = pt(row-1)
[1] + (0..row-2).to_a.map { |i| last[i] + last[i+1] } + [1]
end
@chrisberkhout
chrisberkhout / mirror-apt-opengeo-org.sh
Last active November 21, 2016 17:49
A script to mirror the OpenGeo APT repository on S3 (so you still have packages for your version of the suite when OpenGeo releases a new version). Depends on `wget` and `s3cmd`.
#!/bin/bash
repo_host="apt.opengeo.org"
repo_dir="suite/v3/ubuntu"
repo_release="lucid"
echo -n "===> Please enter a bucket name: "
read -e bucket
echo "===> Confirming you have s3cmd configured..."