Skip to content

Instantly share code, notes, and snippets.

View tkfm-yamaguchi's full-sized avatar

Takafumi Yamaguchi tkfm-yamaguchi

View GitHub Profile
@tkfm-yamaguchi
tkfm-yamaguchi / contrast.rb
Last active August 29, 2015 14:15
generates grey-scale based contrasted color
=begin
Generates grey-scale based contrasted color
from rgb hex string.
=end
yellow = "#FFFF99"
red = "#FF6666"
grey = "#777777"
@tkfm-yamaguchi
tkfm-yamaguchi / conv.rb
Created January 22, 2015 00:17
List the codes to stringify prop values for ObjC
require "active_support"
require "active_support/core_ext"
KLASSNAME = "PSDatabasePeak"
props = DATA.readlines.map do |line|
line.split("\s").select(&:present?).last[/^\*?([^;]+);$/,1]
end
# puts %|return [NSString stringWithFormat:@"<#{KLASSNAME} #{props.map{|s| "@#{s}=%@" }.join("\s")}>", #{props.map{|s| "self.#{s}" }.join(",\s")}];|
@tkfm-yamaguchi
tkfm-yamaguchi / tmuxinator-completion.zsh
Last active August 29, 2015 14:12 — forked from ser1zw/_tmuxinator
zsh script for tmuxinator's completion
#compdef tmuxinator mux
# zsh completion for tmuxinator
# Install:
# $ mkdir -p ~/.tmuxinator/completion
# $ cp _tmuxinator ~/.tmuxinator/completion
# $ vi ~/.zshrc # add the following codes
# fpath=($HOME/.tmuxinator/completion ${fpath})
# autoload -U compinit
@tkfm-yamaguchi
tkfm-yamaguchi / coffee_argument_newline.rb
Created December 12, 2014 00:54
use backslash to write argument in newline in CoffeeScript
require "yaml"
require "coffee-script"
YAML.load(DATA.read).values.each do |src|
puts CoffeeScript.compile src
puts "-" * 30
end
=begin
@tkfm-yamaguchi
tkfm-yamaguchi / my_bp.rb
Created December 9, 2014 01:16
super simple debugger on ruby
def my_bp
while true
print "Breakpoint > "
input = (gets || "\n").chomp.strip
break if input.empty? || input =~ /^exit$/
instance_eval("puts #{input}.inspect")
@tkfm-yamaguchi
tkfm-yamaguchi / class_var_and_inheritance.rb
Last active August 29, 2015 14:09
class variable inheritance test for Ruby
class Base
class << self
def set!
@@_var_ = "var!"
end
def get!
@@_var_
end
end
@tkfm-yamaguchi
tkfm-yamaguchi / listen_ext.rb
Last active August 29, 2015 14:09
To avoid raising error when a duplicated physical path for a symlink is detected ( listen gem )
module ListenExt
module Record
module SymlinkDetector
ERROR_MESSAGE = "Failed due to looped symlinks"
def verify_unwatched!(entry)
begin
super(entry)
rescue => e
@tkfm-yamaguchi
tkfm-yamaguchi / demodulize.sh
Created October 8, 2014 06:50
make submodule to a independent repository.
#!/bin/bash
set -eu
# TODO: summary
REPO_PATH=${1:-""} # the first argument should be a directory to demodulize.
@tkfm-yamaguchi
tkfm-yamaguchi / Rakefile
Created September 4, 2014 23:37
tar exclude pattern
# coding: utf-8
desc "all"
task all: %i[clean prepare]
=begin
- ξ(✿>◡❛)ξ tar --exclude 'a/A/a' -zcf test.tgz test
- ξ(✿>◡❛)ξ tar ztf test.tgz
@tkfm-yamaguchi
tkfm-yamaguchi / sum_of_the_file_size.sh
Created August 14, 2014 07:36
One line command: file size summation
find -name '*.json' -exec ls -s {} \; | ruby -e 'p STDIN.readlines.map(&:to_i).reduce(&:+)'