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
#!/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 / 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
# -*-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 / 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)
@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 / 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 / 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 / example.sh
Created June 29, 2011 07:00
Very simple twitter client for CLI (just tweet!)
alias tweet='cat ~/your-token.yaml | tw-post.rb'
@igrep
igrep / twice.sh
Created August 9, 2011 10:55
Sample to show that It's more useful to use +eval+ and +source+ if you want to decide which command to execute in your script
#!/bin/bash
#Execute command twice.
#Sample to show that
# It's more useful to use +eval+ and +source+
# if you want to decide which command to execute in your script
shopt -s expand_aliases # don't work even if expand_aliases is enabled.
# $@ #don't work well: don't expand the alias
@igrep
igrep / autoload-vimplayer.vim
Created November 22, 2011 03:03
Really thin wrapper of MPlayer for Vim editor. ref http://www.mplayerhq.hu/DOCS/tech/slave.txt
"Settings
let g:vimplayer_mplayer_extra_options = []
let s:vimplayer_pipe_mplayer = {}
function! vimplayer#play(...) abort
let vimplayer_filenames = a:000
if !empty(s:vimplayer_pipe_mplayer) "mplayer already playing something
call s:vimplayer_pipe_mplayer.stdin.write("quit\n")