Skip to content

Instantly share code, notes, and snippets.

require 'ostruct'
module Dummy
module Share
def self.all
arr = []
20.times do
arr << new_share
end
foo
bar
@bchase
bchase / not_able.rb
Created August 28, 2014 09:57
we do what we must because we can
module NotAble
def not
boolean_bizzaro_world
end
private
def boolean_methods
methods.select { |m| m.to_s.end_with? '?' }
end
@bchase
bchase / beautiful_days
Last active August 29, 2015 14:06
SPYAIR - Beautiful Days
SPYAIR - BEAUTIFUL DAYS
プラスにもっと変えていける
purasu ni motto kaete ikeru
this can be made better
そうやって信じていこう
sou yatte shijite ikou
let's go on beliving that way
(1..10).each do |num|
sleep 0.5
print "\r"
dashes, spaces = '-'*num, ' '*(10-num)
bar = "[#{dashes}#{spaces}]"
print bar
end
#!/usr/bin/env ruby
class Deploy
def self.all(remote='staging')
releases_txt = `heroku releases -r #{remote}`
app_txt, *release_strs = releases_txt.split("\n")
app, remote = app_txt[/===\s+(\S+)/, 1], remote
deploy_strs = release_strs.select {|str| str =~ /^v\d+\s+Deploy/}
@bchase
bchase / not.rb
Last active August 29, 2015 14:17
module Nottable
class Notter < BasicObject
attr_reader :orig
def initialize(orig)
@orig = orig
end
def equal?(other)
! orig.equal? other
end
class MarkdownText < String
def lines
split("\n").map { |l| MarkdownLine.new l }
end
def urls_to_links!
replace lines.map { |line|
line.solo_url? ? line.to_url_link : line
}.join("\n")
end
# first solution
(1..100).map{|n|s="#{'Fizz'if n%3==0}#{'Buzz'if n%5==0}";p s.empty?? n:s}
# second implemenation
(1..100).map{|n|p %W[#{n} Fizz Buzz FizzBuzz][n%15==0?3:n%3==0?1:n%5==0?2:0]}
(1..100).map{|n|p %w[Fizz Buzz FizzBuzz][n%15==0?2:n%3==0?0:n%5==0?1:7]||n}
# combined and shortened
(1..100).map{|n|p "#{n%3==0?n%5==0?'FizzBuzz':'Fizz':n%5==0?'Buzz':n}"}
(1..100).map{|n|p n%3==0?n%5==0?'FizzBuzz':'Fizz':n%5==0?'Buzz':n}
i = 5
x = [:Fizz][i%3] # => :Fizz || nil
# 5%3
# [:Fizz][2] # => nil
str = "%sBuzz" % x # => 'Buzz' || 'FizzBuzz'
# "%sBuzz" % nil # => 'Buzz'
str = [str][i%5] # => ^ above str or nil
# 5%5
# ['Buzz'][0] # => 'Buzz'
#