Skip to content

Instantly share code, notes, and snippets.

View larrywright's full-sized avatar

Larry Wright larrywright

View GitHub Profile
#from: http://github.com/jnunemaker/httparty/examples/basic
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
# You can also use post, put, delete in the same fashion
response = HTTParty.get('http://twitter.com/statuses/public_timeline.json')
puts response.body, response.code, response.headers.inspect
#from the Sinatra home page at http://www.sinatrarb.com/
require 'rubygems'
require 'sinatra'
get '/hi' do
"Hello World!"
end
class UserTest < Test::Unit::TestCase
context "A User instance" do
setup do
@user = User.find(:first)
end
should "return its full name" do
assert_equal 'John Doe', @user.full_name
end
class PostTest < Test::Unit::TestCase
fixtures :all
should_belong_to :user
should_have_many :tags, :through => :taggings
should_validate_uniqueness_of :title
should_validate_presence_of :body, :message => /wtf/
should_validate_presence_of :title
should_validate_numericality_of :user_id
require 'rubygems'
require 'mofo'
require 'pp'
File.open('results.txt', 'w+') do |file|
list = hCard.find 'http://maps.google.com/maps?f=q&source=s_q&view=text&hl=en&gl=us&q=daycare+Ottawa+IL&mrt=all&ie=UTF8&attrid=&sa=N&start=0'
list.each do |item|
begin
file.write("#{item.fn}, #{item.adr[1].street_address}, #{item.adr[1].locality}, #{item.adr[1].region}, #{item.tel}, 61350\n")
rescue
namespace :utils do
desc "Populate the database with random data"
task(:generate_data => :environment) do
puts "Deleting all of the existing data"
Campaign.delete_all
client_names = %w{Acme Danger MegaCorp}
scores = %w{High Medium Low}
volumes = (8000..10000).to_a
letter_types = %w{1 2 3}
dates = ((DateTime.now-40.days)..DateTime.now).to_a
@larrywright
larrywright / stats.rb
Created September 15, 2009 21:42 — forked from mojombo/stats.rb
# Run the given block +num+ times and then print out the mean, median, min,
# max, and stddev of the run. For example:
#
# irb> stats(10) { sleep(rand / 100) }
# mean: 5.99ms
# median: 6.76ms
# min: 1.49ms
# max: 9.28ms
# stddev: 2.54ms
def stats(num)
# mongo_template.rb
# remove unneeded defaults
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/javascripts/controls.js"
run "rm public/javascripts/dragdrop.js"
run "rm public/javascripts/effects.js"
run "rm public/javascripts/prototype.js"
<%= content_for :title, @article.title + " -" %>
<% content_for :content do -%>
<%= render :partial => "article" %>
<div id="disqus_thread">
</div>
<script type="text/javascript"
src="http://disqus.com/forums/thecuriousityproject/embed.js">
var disqus_developer = 1;
</script><noscript><a href="http://thecuriousityproject.disqus.com/?url=ref">View
the discussion thread.</a></noscript><a href="http://disqus.com"
def putFile(self,filename):
self.log(self.getLogPrefix() + "Transmitting File: " + filename)
try:
self._sftp.put(filename, confirm)
# fd = open(filename,'r') #XXX: Probably need to figure out what directory to put it in.
# if self._remotedir != None:
# filename = self._remotedir + '/' + filename
# sftpfile=self._sftp.open(filename,"w")
# sftpfile.writelines(fd.readlines())
# sftpfile.close()