Skip to content

Instantly share code, notes, and snippets.

@codeslinger
codeslinger / gist:1513
Created July 23, 2008 03:42
YAML layout of Twitter API
---
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 July 23, 2008 11:52
Utility to give system info about a Mac
#!/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 July 31, 2008 18:19
Robust script to retrieve SSH public key into authorized_keys for EC2 instances
#!/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"
# vim:set ts=4 sw=4 et ai:
from __future__ import with_statement
"""
:Author: Toby DiPasquale <[email protected]>
:Copyright: Copyright (c) 2008 Toby DiPasquale. Free for use for any purpose
by anyone forever.
Introduction
============
@codeslinger
codeslinger / gist:6389
Created August 20, 2008 15:21
Recursive, iterative and tail-recursive performance test for X86 (with factorial)
/*
* 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 <[email protected]>
*
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
{:one => 1, :two => 2}.map {|k,v| k == :one ? v : nil}.compact
(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:
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
# 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