Skip to content

Instantly share code, notes, and snippets.

class String
def strimwidth(width)
self.split(//)[0...width].join
end
end
#see also http://www.ruby-lang.org/ja/man/html/Array.html#self.5bstart.2e.2eend.5d
hash = Hash.new {|h, k| h[k] = Hash.new(&h.default_proc) }
#!/usr/bin/env ruby
for n in 1..30
if 0 == n % 15
p "fizzbuzz"
elsif 0 == n % 5
p "buzz"
elsif 0 == n % 3
p "fizz"
else
preexec() {
if [ ${1} ]; then
key=`ruby -rubygems -e 'require "pit";print Pit.get("outputz.com")["key"]'`
curl -s http://outputz.com/api/post -F key=${key} -F uri=http://zsh.localhost/ -F size=${#1} >/dev/null
fi
}
#!/usr/bin/env ruby -Ku
arr = ["abc","foo","def","foo","ghi","foo","jkl","bar","mno","bar","pqr"]
v = ""
i = 0
c = 0
arr.each do |n|
arr.each do |m|
#!/usr/bin/env ruby -Ku
# abcdefghijklmnopqrstuvwxyz
# bcdefghijklmnopqrstuvwxyza
# cdefghijklmnopqrstuvwxyzab
# defghijklmnopqrstuvwxyzabc
# ..........................
# wxyzabcdefghijklmnopqrstuv
# xyzabcdefghijklmnopqrstuvw
# yzabcdefghijklmnopqrstuvwx
@dzfl
dzfl / ruby.rb
Created December 25, 2008 09:45
#!/usr/bin/env ruby -Ku
require 'rubygems'
require 'RMagick'
require 'digest/sha1'
Dir::glob("/home/foo/*.jpg").each do |f|
original = Magick::Image.read(f).first
resized = original.change_geometry("200x200") { |cols, rows| original.thumbnail(cols, rows) }
#!/usr/bin/env ruby
# vim:fileencoding=utf-8
def lenghten(text)
uri = URI(text)
Net::HTTP.start(uri.host, uri.port).head(uri.request_uri)["Location"]
rescue
nil
end
#!/usr/bin/env ruby
# vim:fileencoding=utf-8
require 'socket'
require 'digest/sha1'
def send(msg)
print msg + "\r\n"
javascript:args = '%s'.split(/ /i); if (args.length > 1) { var serv = args[0]; var id = args[1];} else { var serv = 'd'; var id = args[0] } location.href = "http://" + serv + ".hatena.ne.jp/" + id;