This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r, w = IO.pipe | |
Process.run("less", input: r) | |
100.times { w.puts "hello" } | |
w.close |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
desc "Convert your database into seeds!" | |
task :export_seeds => :environment do | |
Rails.application.eager_load! | |
models = ObjectSpace.each_object(Class).select { |c| c < ActiveRecord::Base } | |
ignored_keys = %w[created_at updated_at id] | |
models.each do |model| | |
puts "### #{model}s ######################################" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
HE = [ | |
['a superhumanly strong','an underprivileged','a globe-trotting','an impetuous','a shy','a suave', | |
'a notorious','a one-legged','an all-American','a short-sighted','an otherworldly','a hate-fuelled', | |
'a scrappy','an unconventional','a jaded','a leather-clad','a fiendish','a Nobel prize-winning', | |
'a suicidal','a maverick','a bookish','an old-fashioned','a witless','a lounge-singing','a war-weary', | |
'a scarfaced','a gun-slinging','an obese','a time-tossed','a benighted','an uncontrollable','an immortal', | |
'an oversexed','a world-famous','an ungodly','a fast talking','a deeply religious','a lonely', | |
'a sword-wielding','a genetically engineered'], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
HE = [ | |
['a superhumanly strong','an underprivileged','a globe-trotting','an impetuous','a shy','a suave', | |
'a notorious','a one-legged','an all-American','a short-sighted','an otherworldly','a hate-fuelled', | |
'a scrappy','an unconventional','a jaded','a leather-clad','a fiendish','a Nobel prize-winning', | |
'a suicidal','a maverick','a bookish','an old-fashioned','a witless','a lounge-singing','a war-weary', | |
'a scarfaced','a gun-slinging','an obese','a time-tossed','a benighted','an uncontrollable','an immortal', | |
'an oversexed','a world-famous','an ungodly','a fast talking','a deeply religious','a lonely', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'io/console' | |
height, width = $stdin.winsize | |
print "\e[2J" | |
t = 30 | |
loop { | |
t += 1 | |
print "\e[H" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
width = 50; (1..width).each { |n| a = [" "] * width; dist = width/n.to_f; (1...n).each { |i| a[i*dist] = "/" }; puts "#{n.to_s.rjust(3)} #{a.join('')}" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'epitools' | |
class Hash | |
def to_ostructs | |
deeply_ostructed_hash = map_values do |value| | |
case value | |
when Hash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rover | |
# - move | |
# - turn_left | |
# - turn_right | |
class Rover | |
attr_reader :x, :y, :direction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Recursively yield all possible expressions for the array of numbers | |
# | |
def exprs(nums) | |
n, *rest = nums | |
if rest.empty? | |
yield "#{n}" | |
else | |
exprs(rest) do |expr| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.interp = function() { | |
var matcher = /#{(.+?)}/g | |
var replacer = function(_, expr) { | |
return eval(expr) | |
} | |
return this.replace(matcher, replacer) | |
} | |
// Example: |