Skip to content

Instantly share code, notes, and snippets.

heroku
toolbelt
- install toolbelt -> https://toolbelt.heroku.com/
- login w/ toolbelt
$ heroku login
- add ssh keys
$ heroku keys:add
prepare rails
#!/usr/bin/env ruby
# REQUIREMENTS
# 1. ruby - http://rubyinstaller.org/
# 2. vlc - http://www.videolan.org/vlc/index.html
#
# USAGE
# 1. save this file as `randime.rb` (type: `All Files`)
# 2. beneath `__END__` below, paste in absolute folder paths containing videos you want played
# 3. double click the `randime.rb` icon to play
@bchase
bchase / 2mp3.rb
Last active August 29, 2015 14:24
#!/usr/bin/env ruby
require 'pathname'
input = Pathname.new ARGV[0]
output = input.basename.to_s.chomp(input.extname) + '.mp3'
%x[avconv -i #{input.to_s.inspect} -ab 192k #{output.inspect}]
# before
lyrics.each do |lyric|
rules.each do |rule|
clip = Clip.new \
song_path: song_path,
lyric: lyric,
rule: rule
arr << clip
end
end
@bchase
bchase / new_namespace.rb
Created July 10, 2015 11:44
create a new namespace (module/class) with spec from gem root
#!/usr/bin/env ruby
# ### USAGE ###
#
# $ ./new_namespace foo/bar_baz [class]
#
# defaults to generating a module
#
# expects existing structure to include...
#
@bchase
bchase / tap.rb
Last active August 29, 2015 14:24
require 'pathname'
require 'pry'
class Object
def tap(msg=nil, with:nil, to:nil, &block)
if block_given? # original Object#tap functionality
return super &block
else
if msg || with # msg to self e.g. #mkdir #gsub!
if msg
@bchase
bchase / db.rb
Last active August 29, 2015 14:25
def db
@db ||= SQLite3::Database.new(path.to_s).tap do |db|
db.results_as_hash = true
db.instance_eval do
def tables
rows = execute "SELECT name FROM sqlite_master WHERE type='table';"
rows.map{|r| r['name']}
end
#!/usr/bin/env ruby
require 'ostruct'
require 'pry'
CEDict = Struct.new :trad, :simp, :pinyin, :glosses
JMDict = Struct.new :kanji, :kana, :glosses
module DictResourceable
%i[word pronunciation meanings].each do |msg|
# Organization class that acts AR-like (::create, ::all, ::find_by)
class Organization
attr_reader :name, :api_key, :api_secret, :list
def initialize(name:, api_key:, api_secret:, list: [])
@name, @api_key, @api_secret, @list= name, api_key, api_secret, list
end
def self.create(*args)
new(*args).tap do |org|
all.push org