Skip to content

Instantly share code, notes, and snippets.

@rentalcustard
rentalcustard / my_gem.gemspec
Created November 16, 2011 15:09
Hidden load path bug revealed by Bundler 1.1 rc
#...
spec.add_dependency("capistrano", [">= 1.0.0"])
#...
@rentalcustard
rentalcustard / investigations.markdown
Created November 3, 2011 14:25
Checks for specific classes in Ruby and Java projects

My contention is that Ruby developers are more likely to use Object#is_a?, Object#respond_to?, and Class#=== in their code than Java developers are to use "instanceof". Here is some anecdotal evidence supporting this contention. It's not easy to compare the two for a number of different reasons:

  1. Java projects tend to have a lot more code
  2. It's hard to decide which projects are comparable to others
  3. It's hard to search for uses of Class#===, which is most often used in case statements.

Nonetheless, here are some numbers which probably mean nothing.

@rentalcustard
rentalcustard / rant.coffee
Created October 25, 2011 14:54
Why I don't like coffeescript
#Given a function that accepts a callback...
someFunc = (callback) ->
#do stuff
callback(data) if callback
#when calling it...
someFunc (data) ->
#blah
@rentalcustard
rentalcustard / gist:1309020
Created October 24, 2011 13:26
Web development in 2011. Apparently.
//from https://github.com/christkv/node-mongodb-native
var p_client = new Db('integration_tests_20', new Server("127.0.0.1", 27017, {}), {'pk':CustomPKFactory});
p_client.open(function(err, p_client) {
p_client.dropDatabase(function(err, done) {
p_client.createCollection('test_custom_key', function(err, collection) {
collection.insert({'a':1}, function(err, docs) {
collection.find({'_id':new ObjectID("aaaaaaaaaaaa")}, function(err, cursor) {
cursor.toArray(function(err, items) {
test.assertEquals(1, items.length);
@rentalcustard
rentalcustard / gist:1293275
Created October 17, 2011 17:56
Bundler woes
#given this Gemfile...
source :rubygems
gem 'rake'
gem 'sinatra', "1.3.0"
gem 'haml'
gem 'sass'
gem 'coffee-script'
gem 'pg'
mysql> desc card_commissions;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| unique_id | varchar(255) | YES | MUL | NULL | |
| year_month | int(11) | YES | | NULL | |
| value | decimal(8,2) | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
@rentalcustard
rentalcustard / blanks.py
Created October 4, 2011 14:56 — forked from MrPink/blanks.py
Ganglia Python module to graph results from a SQL query
import sys
import _mysql
import time
import re
def blank_logger(name):
db=_mysql.connect(user="user",passwd="password",db="hitstats")
db.query(""" SELECT sum(if(filename='nginx_timeout',totalhits,0)) blanks
FROM `hitstats`.`serverhits` """)
@rentalcustard
rentalcustard / gist:1231967
Created September 21, 2011 13:00
rake stats
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 14551 | 10450 | 113 | 1127 | 9 | 7 |
| Helpers | 2832 | 2108 | 0 | 235 | 0 | 6 |
| Models | 21418 | 16315 | 341 | 1742 | 5 | 7 |
| Libraries | 9900 | 8807 | 41 | 311 | 7 | 26 |
| APIs | 144 | 107 | 7 | 2 | 0 | 51 |
| Functional tests | 40158 | 32061 | 112 | 2808 | 25 | 9 |
| Unit tests | 19807 | 15513 | 113 | 1879 | 16 | 6 |
class Foo
def some_method
puts "In some_method"
def some_other_method
puts "In some other method"
"Foo"
end
"Bar"
end
end
@rentalcustard
rentalcustard / gist:1153676
Created August 18, 2011 08:45
Sofa Control applescript for controlling Showoff presentations in Google Chrome
(*
Copyright 2011, Tom Stuart
Description: Simple pass through of left/right arrows for Showoff
Author: Tom Stuart
Mapping:
* Left/Right: Left/Right arrow keys
*)