Skip to content

Instantly share code, notes, and snippets.

View tjstankus's full-sized avatar

TJ Stankus tjstankus

  • Chapel Hill, NC
View GitHub Profile
@tjstankus
tjstankus / grooveshark.rb
Created November 26, 2014 14:51
Grooveshark example
require 'grooveshark'
client = Grooveshark::Client.new
session = client.session
songs = client.search_songs('Nirvana')
puts "Number of results -- #{songs.size}"
songs.each do |song|
puts song.name
end
url = client.get_song_url(songs.first)
def round_up_quarter(f)
result = (f * 4.0).round / 4.0
result > f ? result : result + 0.25
end
round_up_quarter(2.2) # => 2.25
round_up_quarter(4.6) # => 4.75

Keybase proof

I hereby claim:

  • I am tjstankus on github.
  • I am tjstankus (https://keybase.io/tjstankus) on keybase.
  • I have a public key whose fingerprint is DEFC 99A1 E5B8 378C E73E E143 CC21 2ABD 83B5 AE2B

To claim this, I am signing this object:

namespace :static do
desc 'Create a static html version of the site'
task :build do
# Make static directory
Dir.mkdir "#{RAILS_ROOT}/static" unless File.exists? "#{RAILS_ROOT}/static"
# wget our local rails site.
%x{ wget --recursive --convert-links --html-extension --no-host-directories --directory-prefix=static http://localhost:3000/ }
require 'rubygems'
require 'mp4info'
require 'fileutils'
def padded_track_num(num)
num <= 9 ? "0#{num}" : "#{num}"
end
print "Enter directory: "
dir = gets.chomp
namespace :test do
Rake::TestTask.new(:gems => :environment) do |t|
t.libs << "test"
if ENV['GEM']
t.pattern = "vendor/gems/#{ENV['GEM']}/test/**/*_test.rb"
else
t.pattern = 'vendor/gems/*/**/test/**/*_test.rb'
end
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar
# 14 rue de Plaisance, 75014 Paris, France
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@tjstankus
tjstankus / irb
Created May 27, 2009 05:52 — forked from quirkey/irb
[08:48 AM:gist-99771(master)] $ irb -rubygems -r myapp.rb -r rack/test
>> app = Rack::Test::Session.new(Sinatra::Application)
=> #<Rack::Test::Session:0x17e8820 @headers={}, @app=Sinatra::Application>
>> app.get '/'
=> #<Rack::Response:0x17ad4dc @block=nil, @writer=#<Proc:0x0189f7b4@/opt/local/lib/ruby/gems/1.8/gems/rack-0.9.1/lib/rack/response.rb:24>, header{"Content-Type"=>"text/html", "Content-Length"=>"7"}, body["testing"], length7, status200
>> app.body
NoMethodError: undefined method `body' for #<Rack::Test::Session:0x17e8820>
from (irb):3
module Subclasses
# return a list of the subclasses of a class
def subclasses(direct = false)
classes = []
if direct
ObjectSpace.each_object(Class) do |c|
next unless c.superclass == self
classes << c
end
else
# Slight modifications to code posted by Gregory Brown at http://pastie.org/515450
require 'delegate'
module Decoration
def decorator_for(*types, &block)
types.each do |type|
decorators[type] = Module.new(&block)
end
end