Skip to content

Instantly share code, notes, and snippets.

View joho's full-sized avatar
At harbour

John Barton joho

At harbour
View GitHub Profile
# this is my least favourite boolean/operator precedence gotcha
# got any of your own to share?
x = true and false # => false
x # => true
y = true && false # => false
y # => false
# can someone please explain this to me?
left = { :a => 'a', :b => 'b' } # => {:a=>"a", :b=>"b"}
right = { :a => 'a', :b => 'b' } # => {:a=>"a", :b=>"b"}
left == right # => true
left.eql? right # => false
left_array = [1, 2]
right_array = [1, 2]
@joho
joho / new_sales_with_growl.rb
Created March 19, 2009 05:49
A little ruby script to give you growl notifications when you get a new sale
require 'rubygems'
require 'open-uri'
require 'json'
USERNAME = "ryan"
API_KEY = "26k6otse2s586e4hcbzjy3quq830t3o4"
SITE = "flashden"
SLEEP_TIME = 60 * 5
api_url = "http://#{SITE}.net/api/edge/#{USERNAME}/#{API_KEY}/recent-sales+vitals.json"
class ActiveSupport::OrderedHash < Hash
def first
[@keys.first, self[@keys.first]]
end
end
@joho
joho / tramtracker.php
Created April 23, 2009 06:15
A sintatra app & php page for proxy scraping tramtracker
<?php
if ($_SERVER['REMOTE_ADDR'] == "127.0.0.1")
{
define ('HOSTNAME', 'http://tramtracker.com/');
$path = $_GET['path'];
$url = HOSTNAME.$path;
$session = curl_init($url);
TEST_INPUT_PATH = '/Users/joho/Desktop/Grand Designs S09E10.avi'
TIMES_TO_TEST = 10
start = Time.now
TIMES_TO_TEST.times do
puts "start"
File.open 'test.avi', 'w' do |out_file|
File.open TEST_INPUT_PATH, 'r' do |in_file|
out_file.write in_file.read
end
@joho
joho / test_array_in_chunks.rb
Created May 20, 2009 03:30
i needed handy little chunks of my array
require 'test/unit'
class Array
def in_chunks_of(size_of_chunks)
if size_of_chunks >= length
[self]
else
[self[0, size_of_chunks]] + self[size_of_chunks, length].in_chunks_of(size_of_chunks)
end
end
@joho
joho / gist:117894
Created May 26, 2009 04:34 — forked from yob/gist:117889
irb(main):005:0> n = "James"
=> "James"
irb(main):006:0> n.strip!
=> nil
irb(main):007:0> n
=> "James"
# that's just plain weird
>> n = "john "
=> "john "
# extracted from marty andrew's presentation on ruby static code analysis
# http://www.slideshare.net/martin_j_andrews/code-quality-analysis
require 'flog'
require 'flay'
require 'roodi'
require 'roodi_task'
require 'metric_fu'
desc "Analyze for code complexity"
@joho
joho / team-projects.html
Created June 30, 2009 07:44
A little jquery script to show off your team's github repos, based heavily on http://github.com/benaskins/benaskins.github.com
<!DOCTYPE>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('.repos').each(function() {
var current_e = this;
$(this).append('<li><a href="http://github.com/' + this.id + '">github.com/' + this.id + '</a></li>' );
$.getJSON('http://github.com/api/v1/json/' + this.id + '?callback=?', function(data) {