Skip to content

Instantly share code, notes, and snippets.

View igrep's full-sized avatar
:shipit:
Programming in TypeScript, Python, or Haskell.

YAMAMOTO Yuji igrep

:shipit:
Programming in TypeScript, Python, or Haskell.
View GitHub Profile
@igrep
igrep / gist:1028628
Created June 16, 2011 03:37
(UNNAMED) generator expression like Python in Ruby
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
$VERBOSE = true
=begin
Maybe usable as generator expression in Python
requires ruby1.9 or facets ( >= 2.9.1 )
=end
if RUBY_VERSION < '1.9'
require 'rubygems'
@igrep
igrep / gist:1028626
Created June 16, 2011 03:35
(UNNAMED) generator expression like Python in Ruby
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
$VERBOSE = true
=begin
Maybe usable as generator expression in Python
requires ruby1.9 or facets ( >= 2.9.1 )
=end
$KCODE = 'u' if RUBY_VERSION < '1.9'
@igrep
igrep / config.rb
Created April 19, 2011 07:26
My twitter utils
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
module MyTwitterFavUtils
FORMAT = 'tsv'
SEP = "\t"
FILE = 'fav-tweets.' + FORMAT
BACKUP_SUFFIX = '~'
TRUNCATE_LEN = 20
end
@igrep
igrep / result.txt
Created March 7, 2011 03:15
Measure efficiency of several methods of string concatenation.
user system total real
Array#push and join 0.360000 0.040000 0.400000 ( 0.398396)
String#concat 1 0.240000 0.030000 0.270000 ( 0.267289)
String#concat 2 0.260000 0.040000 0.300000 ( 0.297610)
Array#join with a const 0.090000 0.030000 0.120000 ( 0.121947)
String#concat with const 0.100000 0.030000 0.130000 ( 0.134064)
#!/usr/bin/env ruby
# -*-coding:utf-8-*-
$VERBOSE = true
=begin
Project Euler: 2
By considering the terms in the Fibonacci sequence whose values do not exceed four million,
find the sum of the even-valued terms.
=end
fib = Hash.new{|hsh, n| hsh[n] = hsh[n-2] + hsh[n-1] }
@igrep
igrep / choice_on.py
Created January 31, 2011 14:00
Choose an elements from sequence with weight at random.
#!/usr/bin/env python
import random
def choice_by(seq, criteria):
"""
Choose an elements from sequence with weight at random.
"""
#Initial value
itr = iter(seq)
#!/usr/bin/env ruby
# vim: set fileencoding=utf-8 :
$VERBOSE = true
=begin
`which' command for Ruby libraries.
=end
lib = ARGV.shift
exts = %w/ .rb .so .dll /
puts $LOAD_PATH.map{|path|
@igrep
igrep / queue-to_enum.rb
Created December 29, 2010 05:46
Queue#to_enum( wait_thread )
#!/usr/bin/env ruby
# vim: set fileencoding=utf-8 :
$VERBOSE = true
=begin
Queue#to_enum
=end
require 'thread'
class Queue
#!/usr/bin/env ruby
# vim: set fileencoding=utf-8 :
$VERBOSE = true
require 'set'
def dig *args
args.inject{|x, y| 10 * x + y}
end
@igrep
igrep / clipboard-character-counter.rb
Created October 29, 2010 05:49
Simple character counter with Gtk2.
#!/usr/bin/env ruby
# vim: set fileencoding=utf-8 :
$VERBOSE = true
=begin
Count the number of characters in the clipboard.
=end
require 'rubygems'
require 'clipboard'
require 'kconv'