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
=begin
Termtter plugin.
Mark everytime timeline is updated. inspired by plugin/mark.rb
=end
config.plugins.mark_on_update.set_default( :wrap_color, 'on_red' )
config.plugins.mark_on_update.set_default( :time_format, 'TIMELINE at %R' )
Termtter::Client.register_hook(
:name => :mark_on_update,
:points => [:post_filter],
#!/usr/bin/ruby -wKu
# vim: set fileencoding=utf-8 :
=begin
return the results of both Enumerable#take and Enumerable#drop
=end
module Enumerable
def split_between val
first = true
first_ary = []
require 'socket'
module SocketSpecs
# helper to get the hostname associated to 127.0.0.1
def self.hostname
# Calculate each time, without caching, since the result might
# depend on things like do_not_reverse_lookup mode, which is
# changing from test to test
Socket.getaddrinfo("127.0.0.1", nil)[0][2]
end
@igrep
igrep / object-pattern.rb
Created August 24, 2010 03:41
Wacky Ruby
#!/usr/bin/ruby -wKu
# vim: set fileencoding=utf-8 :
class ObjectPattern
def initialize obj, method=:[]
@delegate_object = obj
@delegate_method = method
end
attr_reader :delegate_object, :delegate_method
def === other
@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