Skip to content

Instantly share code, notes, and snippets.

View gist:469245
module Kernel
def installed?(cmd)
FileTest.executable?(`which #{cmd}`.strip)
end
end
View twitter_bot.rb
#!/usr/bin/env ruby
$: << File.expand_path('~/src/net-irc/lib')
require 'net/irc'
class Bot < Net::IRC::Client
include Net::IRC::Constants
def on_rpl_welcome(m)
View remtter.rb
#!/usr/bin/env ruby
# !!!!! OAuth !!!!!
require "rubygems"
require "logger"
require "net/http"
require "json"
class Remtter
View sokuho.rb
#! /usr/bin/ruby -Ku
require 'net/http'
require 'rubygems'
require 'nokogiri'
require 'meow'
TOPURL = 'http://baseball.yahoo.co.jp/npb/schedule/'
View index_holded_list.rb
class IndexHoldedList < ::Hash
def [](n)
raise ArgumentError unless Integer === n
self.fetch(n)
end
def []=(n, value)
raise ArgumentError unless Integer === n
self.store(n, value)
end
View MyVector.scala
class MyVector(val x: Double, val y: Double) {
override def toString: String = {
"MyVector(" + x + ", " + y + ")"
}
def length: Double = {
Math.sqrt(x * x + y * y)
}
def direction: Double = {
View gist:753162
#!/usr/bin/env ruby
tracks = [] << %w(鮮やか 殺人) << %w(テレキャスター 真実) <<
%w(Sadistic Summer) << %w(ターボチャージャー ON) << %w(Acoustic) <<
%w(O F T) << %w(CRAZY 感情 STYLE) << %w(トルネード G) << %w(傍観) <<
%w(TK in the 夕景) << %w(想像 Security) << %w(感覚 UFO) <<
%w( 気配 アルペジオ) << %w(ラスト ダンス レボリューション) <<
%w(Sergio Echigo) << %w(nakano kill you) << %w(COOL J) << %w(DISCO FLIGHT) <<
%w(knife vacation) << %w(am 3:45) << %w(赤い 誘惑) << %w(1/f 誘惑) <<
%w(i not crazy am you are) << %w(夕景 記憶) << %w(Telecastic fake show) <<
View collatz.rb
#!/usr/bin/env ruby
def collatz(n)
n == 0 || n == 1 ? n : n.even? ? collatz n / 2 : collatz n * 3 + 1
end
1.upto(3 * 2 ** 52).all? {|i| collatz(i) == 1 } # -> true
@aereal
aereal / gist:798444
Created Jan 27, 2011
FileUtils::DryRun.copy_entry (in Ruby 1.9.2) makes changes.
View gist:798444
#!/usr/bin/env ruby
require 'fileutils'
# ./src/README
# ./dst/
FileUtils::DryRun.copy_entry 'src/', 'dst/'
# ./src/README
@aereal
aereal / gist:857556
Created Mar 6, 2011
Collect statistics of F-numbers from my photos.
View gist:857556
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
f_numbers = Dir.glob("**/*.jpg").map {|jpg|
`jhead #{jpg}`.gsub(%r{Aperture\s*:\s*(?:f/(\d+(?:\.\d+)?))}) { $1 }
}.compact.map {|f| f.to_f }
f_numbers.group_by {|f| f_numbers.count(f) }.each do |freq, f|
puts "#{freq}: #{f.uniq.join(",")}"
end