Skip to content

Instantly share code, notes, and snippets.

@kainage
kainage / tabs2spaces.rb
Last active December 18, 2015 13:59
Tabs to spaces converter for files. Ruby 1.9 or greater.
require 'optparse'
module TabsToSpaces
def self.start(args, options)
@options = options
display_options_and_args(args)
process(args.first)
end
@kainage
kainage / titleizer.rb
Last active December 18, 2015 23:39
Titleize each line in a file
#!/usr/bin/env ruby
require 'active_support'
require 'active_support/inflector'
file = File.open('output.txt', 'w+')
ARGF.readlines.each do |line|
file << line.titleize
end
require 'benchmark'
require 'securerandom'
require 'ostruct'
cids = {}
class Object
def deep_copy
Marshal.load(Marshal.dump(self))
end
@kainage
kainage / clattrs_and_obthods.rb
Created October 16, 2015 22:15
Clattrs & Obthods with Console Support
module MyApp
class Application
console do
Rails::ConsoleMethods.send :include, ConsoleAddons
end
end
end
module ConsoleAddons
def clattrs(model)
# Resolves an arbitrary number of promises in order. Returns the last promise
# unresolved (or an empty promise if there were none) for chainability.
serialResolver = (promises) ->
promise = promises.shift()
switch
# Promise array was empty to begin with.
when promise is undefined
$q.when()
# For the last promise in the array, return it for chainability.
@kainage
kainage / Stock Hunter
Created April 21, 2017 17:52
Get Dat NES Classic Brah
require 'json'
require 'open-uri'
require 'nokogiri'
require 'byebug'
require 'logger'
# OPTIONS #
# In Seconds
INTERVAL = 5