Skip to content

Instantly share code, notes, and snippets.

@revdan
revdan / beer_song.rb
Last active August 29, 2015 14:14
exercism.io BeerSong
class BeerSong
attr_reader :number
def verse(number)
@number = number
take_it_away_guys!
end
def verses(first, last)
first.downto(last).map { |x| verse x }.join("\n") << "\n"
@revdan
revdan / bill_splitter.rb
Created January 31, 2015 13:29
Bill Splitter
class BillSplitter
attr_reader :total, :people, :tip
def initialize(options={})
@total = options.fetch(:total).to_f
@people = options.fetch(:people, 2)
@tip = options.fetch(:tip, 10)
end
def calculate
@revdan
revdan / HTML5VideoCustomPlaybackRateBookmarklet.md
Last active August 29, 2015 14:14
HTML5 Video Custom Playback Rate Bookmarklet

YouTube now defaults to an HTML5 player in modern browsers. While you can choose some varying playback rates from within their interface, this bookmarklet allows you to enter a decimal amount between 0.3 - 3.0 (or slightly wider if you don't mind losing audio).

Add this to the url of your bookmark: javascript: (function(){document.getElementsByTagName('video')[0].playbackRate=prompt('Playback Rate:');})();

Try it with 0.5 on this video for a drunk DHH 🍻

Also works beautifully with @vzaar, and probably many other HTML5 players.

class Wildcards < Struct.new(:hash, :definitions)
def replace(a = hash, b = definitions)
a.merge(b) do |_, left, right|
if left.is_a? Hash
compare(left, right)
else
left == '*' ? right : left
end
end
end
class BookOrderer
attr_accessor :copies, :price
DEFAULT_PRICE = 99.freeze
def initialize(args={})
@copies = args[:copies].to_i
@price = (args[:price].to_i.zero?) ? DEFAULT_PRICE : args[:price].to_i
end
@revdan
revdan / uss-tokens-java.java
Created January 8, 2014 11:22
vzaar user-signed security examples
// This example requires the apache commons-codec library
// (http://commmons.apache.org/codec)
import org.apache.commons.codec.digest.DigestUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class VzaarUssTokens {