Skip to content

Instantly share code, notes, and snippets.

View igrep's full-sized avatar
:shipit:
Writing in Haskell, TypeScript, or Power Automate

YAMAMOTO Yuji igrep

:shipit:
Writing in Haskell, TypeScript, or Power Automate
View GitHub Profile
@igrep
igrep / splatter-case-when.rb
Created September 18, 2010 09:40
Try splatter operator for an IO.
#!/usr/bin/env ruby
# vim: set fileencoding=utf-8 :
$VERBOSE = true
##DIDN'T WORK!!##
#see( Japanese ) http://www.ruby-lang.org/ja/man/html/_C0A9B8E6B9BDC2A4.html#case
print 'foo/bar/hoge: '
case gets #no chomp
when *DATA
puts 'former when caluse.'
@igrep
igrep / tsvsnap.R
Created October 11, 2010 17:17
Snapshot your R objects on a TSV.
#!/usr/bin/r
TSVSNAP.FILE = paste("snap/", Sys.Date(),".tsv", sep="")
tsvsnap = function(obj, ...){
UseMethod("tsvsnap")
}
tsvsnap.summary.lm = function(obj) tsvsnap.table( as.table( coefficients( obj ) ) )
tsvsnap.table = function(obj){
cat("", colnames(obj), file=TSVSNAP.FILE, sep="\t", append=TRUE, "\n")
rows = rownames(obj)
row.num = length(rows)
@igrep
igrep / gist:637855
Created October 21, 2010 03:09
dynamically defining each_with_object
module Enumerable
def each_with_object(memo, &block)
each do |element|
block.call(element, memo)
end
memo
end unless public_method_defined? :each_with_object
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'
#!/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 / 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
=begin
`which' command for Ruby libraries.
=end
lib = ARGV.shift
exts = %w/ .rb .so .dll /
puts $LOAD_PATH.map{|path|
#!/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)
@igrep
igrep / commit-msg
Last active September 25, 2015 01:46
branch名にuser storyのidを入れてコミットメッセージにuser storyのURLを自動で貼る ref: http://qiita.com/igrep/items/17df4627192d7d9d3188
#!/bin/sh
story_id=$(git rev-parse --abbrev-ref HEAD | sed -n 's#.*stories/\([0-9]\+\).*#\1#p')
if [ -n "$story_id" ]; then
echo user story: https://www.pivotaltracker.com/story/show/$story_id >> $1
fi