Skip to content

Instantly share code, notes, and snippets.

@rono23
rono23 / checkins.rb
Last active May 16, 2021 06:32
Swarm checkins to Google Calendar
## Usage
# gem install oauth2
# ruby checkins.rb
#
## .env
# https://foursquare.com/developers/apps
# ENV["4SQ_CLIENT_ID"] = ""
# ENV["4SQ_CLIENT_SECRET"] = ""
# ENV["4SQ_REDIRECT_URI"] = "http://localhost"
#
@rono23
rono23 / open-gihub
Created December 27, 2017 12:25
Open Github from Terminal
#!/usr/bin/env ruby
# Example:
# git clone [email protected]:github/hub
# cd hub
# open-github #=> https://github.com/github/hub
# open-github issue #=> https://github.com/github/hub/issues
# open-github issue 1 #=> https://github.com/github/hub/issues/1
# open-github pr #=> https://github.com/github/hub/pulls
# open-github pr 53 #=> https://github.com/github/hub/pull/53

Keybase proof

I hereby claim:

  • I am rono23 on github.
  • I am rono23 (https://keybase.io/rono23) on keybase.
  • I have a public key whose fingerprint is F62E 0C85 BDBD E148 795E 1865 018C 5A74 9C66 AA11

To claim this, I am signing this object:

@rono23
rono23 / dl.rb
Created May 30, 2016 00:32 — forked from uu59/dl.rb
#!/usr/bin/env ruby
percent = (ENV["D"] || "50").to_i
content = ARGF.read
if STDOUT.tty?
print content.chars.map{|c| next c unless c.match(/[\x20-\x7f]/); rand(1..100) <= percent ? " " : c}.join
else
print content
end
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html_tag = "<div class='field-with-errors'>#{html_tag}</div>".html_safe
if instance.kind_of?(ActionView::Helpers::Tags::Label)
html_tag
else
method_name = instance.instance_variable_get(:@method_name).to_sym
error_message = instance.object.errors.full_messages_for(method_name).first
html_tag + "<div class='field-with-errors'><p class='error-message'>#{error_message}</p></div>".html_safe
end
@rono23
rono23 / action_view_ext.rb
Created February 28, 2013 06:07
Rails3で、date_select, datatime_selectに年、日などを追加する
module ActionView
module Helpers
class DateTimeSelector
def build_options_with_unit(selected, options = {})
start = options.delete(:start) || 0
stop = options.delete(:end) || 59
step = options.delete(:step) || 1
options.reverse_merge!({:leading_zeros => true, :ampm => false, :use_two_digit_numbers => false})
leading_zeros = options.delete(:leading_zeros)
def eratosthenes(list, primes=[])
primes << list.shift
prime = primes.last
list.reject!{ |n| n % prime == 0 }
if prime ** 2 > list.max
primes += list
else
eratosthenes(list, primes)
end
def fibonacci(num, current, prev, fibo=[])
return fibo if num < 1
fibo << current
fibonacci(num - 1, current + prev, current, fibo)
end
fibonacci(10, 1, 0)
def fibonacci(n)
if n > 2
fibonacci(n - 2) + fibonacci(n - 1)
else
1
end
end
fibonacci(10)
def factorial(n)
return 1 if n < 1
n * factorial(n - 1)
end
factorial(5)