Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'erb'
require 'rubygems'
require 'hpricot'
require 'open-uri'
base_dir = '/home/avillenw/nwprogressive.org/portal/scripts/'
input_url = 'http://nwprogressive.tumblr.com/api/read'
output_file = File.open(base_dir + '/tumblr_sidebar.html', 'w')
require 'rubygems'
if RUBY_VERSION >= "1.9.0"
require 'csv'
else
require 'fastercsv'
CSV = FasterCSV
end
# Write out dummy data file
@peterc
peterc / on_update.task.rb
Created May 17, 2009 23:55
Rake task to automatically run something (i.e. specs) when code files are changed
# Rake task to automatically run something (i.e. specs) when code files are changed
# By Peter Çoopér
#
# Motivation: I couldn't get autotest to run on my Sinatra project for some reason but realized
# it didn't require overengineering. Just detect when a file is changed and then re-run the specs!
#
# Examples:
# # rake on_update "rake"
# # rake on_update "spec spec/user_spec.rb"
#
@peterc
peterc / 0what.md
Created August 25, 2009 01:58 — forked from defunkt/0what.md

Poor Man's Deploy

  • Start a Sinatra server on port 4000
  • GET / to that server triggers a git pull and mod_rails restart
  • Hit port 4000 locally after pushing

Why?

@peterc
peterc / newgit
Created September 30, 2009 15:35
Create and sync a new git repository on Dreamhost
# Create a new git repository on Dreamhost
# Function tweaked from that found at http://craigjolicoeur.com/blog/hosting-git-repositories-on-dreamhost
#
# Just add the code below to your .bashrc.
# Usage:
# newgit some-repo.git
#
# Then locally:
#
# git push --all ssh://$MACHINE/home/$USER/git/my-new-repos.git
$ gem push pkg/choice-0.1.4.gem
Pushing gem to Gemcutter...
You do not have permission to push to this gem.
$ gem migrate choice
Starting migration of choice from RubyForge...
A migration token has been created.
Uploading the migration token to choice.rubyforge.org. Please enter your RubyForge login:
Login: defunkt
Password:
# A horribly scrappy "just for fun" entry into Satish Talim's latest Ruby
# challenge. Didn't want to use any libraries, etc, just bashed at it true 1980s style!
# It makes the assumption, as was raised in several comments, that the first time in
# the array is the first of the "block" of times..
def average_time_of_day(times)
pr = nil
times.map! do |t|
h,m = t.scan(/\d+/).map(&:to_i)
h += 12 if t =~ /pm/ || (pr && h < pr)
*** LOCAL GEMS ***
actionmailer (2.2.2, 1.3.6)
actionpack (2.2.2, 1.13.6)
actionwebservice (1.2.6)
activerecord (2.2.2, 1.15.6)
activeresource (2.2.2)
activesupport (2.2.2, 1.4.4)
acts_as_ferret (0.4.3)
# RUBY MAZE CHALLENGE
# By Peter Cooper
#
# = INTRODUCTION
#
# Mazes are known to have challenged humans from as far back as the 5th century
# BC. There are many types of maze, but typically you need to find your way
# from a start point to an end point.
#
# In this Ruby challenge, you will need to develop a class that can be used to|
# Peter Cooper's initial Maze solution
class Maze
START_CHARACTER = 'A'
END_CHARACTER = 'B'
WALL_CHARACTER = '#'
def initialize(maze)
# Get the height and width of the maze
@maze_width = maze[/^.*?\n/].length - 1