Skip to content

Instantly share code, notes, and snippets.

Avatar

Toby DiPasquale codeslinger

View GitHub Profile
@codeslinger
codeslinger / gist:1513
Created Jul 23, 2008
YAML layout of Twitter API
View gist:1513
---
host: twitter.com
scheme: http
auth: httpbasic
version: 2008-07-07T00:00:00-0800
parameters:
id:
type: id
required: False
id_num:
@codeslinger
codeslinger / gist:1689
Created Jul 23, 2008
Utility to give system info about a Mac
View gist:1689
#!/usr/bin/env python
#
# Little command-line utility for telling you stuff about your Mac without
# having to click around all over the place. Originally found here and
# then cleaned up significantly: http://gist.github.com/1617
#
import sys
import commands
import plistlib
@codeslinger
codeslinger / gist:3494
Created Jul 31, 2008
Robust script to retrieve SSH public key into authorized_keys for EC2 instances
View gist:3494
#!/bin/bash
# vim:set ts=4 sw=4 et ai:
# Retrieve the SSH public key and install it for subsequent login attempts.
AUTHORIZED_KEYS=/root/.ssh/authorized_keys
TMP_KEY=/tmp/openssh_id.pub
CURL=/usr/bin/curl
CURLOPTS="--retry 3 --retry-delay 2 --silent --fail -o $TMP_KEY"
View gist:3792
# vim:set ts=4 sw=4 et ai:
from __future__ import with_statement
"""
:Author: Toby DiPasquale <toby@cbcg.net>
:Copyright: Copyright (c) 2008 Toby DiPasquale. Free for use for any purpose
by anyone forever.
Introduction
============
@codeslinger
codeslinger / gist:6389
Created Aug 20, 2008
Recursive, iterative and tail-recursive performance test for X86 (with factorial)
View gist:6389
/*
* Test for recursive, tail-recursive and iterative functions
* solving the same problem (factorial) to test execution speed
* on an X86 processor.
*
* Found:
* http://mpathirage.com/recursion-non-recursion-and-tail-recursion-test/
*
* Cleaned up by Toby DiPasquale <toby@cbcg.net>
*
View gist:10103
if ENV['BENCHMARK_TESTS'] && ENV['BENCHMARK_TESTS'] == 'on'
class Test::Unit::TestCase
# Replaces the regular Test::Unit::TestCase#run method with one that
# does benchmarking of each test method in a test case
def run result
yield(STARTED, name)
@_result = result
begin
setup
View gist:127508
{:one => 1, :two => 2}.map {|k,v| k == :one ? v : nil}.compact
View gist:259202
(in /Users/toby/code/friendly)
All dependencies seem to be installed.
/opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/json-1.1.3/lib/json/common.rb:60: warning: already initialized constant State
.................................................................................FFFFFFF.........................................................................................................................................
1)
NoMethodError in 'Friendly::DataStore retrieving all based on a query gets the data from the dataset for the klass and makes it an arary'
undefined method `map' for nil:NilClass
/Users/toby/code/friendly/spec/../lib/friendly/data_store.rb:20:in `all'
./spec/unit/data_store_spec.rb:29:
View hash_filter.rb
require 'yaml'
class Hash
def filter(*keys)
self.inject({}) {|h,(k,v)| h[k] = v if keys.include?(k); h}
end
end
test_hash = {'one' => 1, 'two' => 2, 'three' => 3}
puts test_hash.to_yaml
View gist:280998
# Power law (log tail) distribution
# Copyright(C) 2010 Salvatore Sanfilippo
# this code is under the public domain
# min and max are both inclusive
# n is the distribution power: the higher, the more biased
def powerlaw(min,max,n)
max += 1
pl = ((max**(n+1) - min**(n+1))*rand() + min**(n+1))**(1.0/(n+1))
max-1-pl.to_i
You can’t perform that action at this time.