Skip to content

Instantly share code, notes, and snippets.

View tjstankus's full-sized avatar

TJ Stankus tjstankus

  • Chapel Hill, NC
View GitHub Profile
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
@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)
@tjstankus
tjstankus / LICENSE.md
Created July 30, 2013 18:54 — forked from brandonb927/LICENSE.md
Evernote, Marked
       DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
               Version 2, December 2004

Copyright (C) 2012 Brandon B. brandon@brandonbrown.io

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 / scala.rb
Created May 2, 2012 14:31
Scala homebrew formula
require 'formula'
class ScalaDocs < Formula
homepage 'http://www.scala-lang.org/'
url 'http://www.scala-lang.org/downloads/distrib/files/scala-docs-2.9.2.zip'
md5 '48d9102789bf696d3d8621fb24ed47da'
end
class ScalaCompletion < Formula
homepage 'http://www.scala-lang.org/'
require 'test_helper'
class MyHelperTest < ActionView::TestCase
test "title" do
assert_select_in '<h1>My Awesome App</h1>', 'h1'
end
test "nav" do
html = '<div id="nav"><a href="/">Home</a></div>'
assert_select_in html, 'div' do
require 'rubygems'
require 'prawn'
require 'prawn/measurement_extensions'
require 'prawn/fast_png'
require 'RMagick'
image = Magick::Image.new(300,300) do
self.background_color = 'black'
self.depth = 8 # without this it breaks in Windows
self.format = 'PNG'
def set(value)
if # ...
# code elided for clarity
elsif tag_name == 'input' and type == 'checkbox'
# node.toggle # => JS event not fired
node.click # => JS event fired
end
end
# Hacking VoodooPad to create OpenMeta tags from VoodooPad page tags
#
# How to make this work:
# 1. Download the openmeta command line tool from here:
# http://code.google.com/p/openmeta/downloads/list
# Unzip the executable and install it to /usr/local/bin.
# If you choose a different directory, change the cmd string below.
# 2. Save the below Python code into
# ~/Library/Application Support/VoodooPad/Script Plugins/openmeta_tags.py
# 3. Quit and restart VoodooPad.
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Major.create(:name => 'Daley', :city => cities.first)
require 'faker'
require 'active_support/ordered_hash'
require 'active_support/core_ext/enumerable'
module Enumerable
def group_by_attribute(attr, options={:nils_first => true})
raise "attr parameter must by a symbol" unless attr.is_a?(Symbol)
h = group_by(&attr)
returning h2 = ActiveSupport::OrderedHash.new do
h2[nil] = h.delete(nil) if options[:nils_first] && h.has_key?(nil)
h2.merge!(h)