Skip to content

Instantly share code, notes, and snippets.

r, w = IO.pipe
Process.run("less", input: r)
100.times { w.puts "hello" }
w.close
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 ######################################"
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'],
<%
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',
require 'io/console'
height, width = $stdin.winsize
print "\e[2J"
t = 30
loop {
t += 1
print "\e[H"
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('')}" }
require 'epitools'
class Hash
def to_ostructs
deeply_ostructed_hash = map_values do |value|
case value
when Hash
# Rover
# - move
# - turn_left
# - turn_right
class Rover
attr_reader :x, :y, :direction
@epitron
epitron / evalsto100.rb
Last active August 29, 2015 14:20
Take the numbers 1 through 9, in order, and insert +'s and -'s (or nothing) such that the resulting mathematical expression evaluates to 100.
#
# 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|
String.prototype.interp = function() {
var matcher = /#{(.+?)}/g
var replacer = function(_, expr) {
return eval(expr)
}
return this.replace(matcher, replacer)
}
// Example: