Skip to content

Instantly share code, notes, and snippets.

View labocho's full-sized avatar

labocho

View GitHub Profile
@labocho
labocho / change_lang_of_epub.rb
Created June 5, 2011 17:40
Change language of EPUB file for looking up dictionary in iBooks
require "rubygems"
require "zipruby" # gem install zipruby
require "rexml/document"
require "fileutils"
class Zip::Archive
def index
i = 0
each do |f|
if yield f
@labocho
labocho / gist:1263962
Created October 5, 2011 08:53
Convert TSV to WikiTable (TextMate Bundle Command)
#!/usr/bin/env ruby
# Convert TSV to WikiTable (TextMate Bundle Command)
#
# Input: Selected Text or Line
# Output: Replace Selected Text
s = STDIN.readlines.map{|line| line.gsub(/\t/, " || ").gsub(/^/, "| ").strip }.join("\n|-\n")
puts "{|class=\"wikitable\"\n#{s}\n|}"
@labocho
labocho / footwork_trainer.rb
Created October 23, 2011 09:49
Footwork Trainer for Fencer
#!/usr/bin/env ruby
# encoding: UTF-8
# Footwork trainer for fencer
# for Mac OS X
class Footwork
attr_accessor :name, :weight, :duration
def initialize(attrs = {})
attrs.each do |k, v|
@labocho
labocho / gist:1373210
Created November 17, 2011 14:05
Time signal (時報) by cron, growlnotify, and ruby
0 * * * * ruby -e 'puts "#{Time.now.hour} o\x27clock"' | /usr/local/bin/growlnotify
@labocho
labocho / README
Created November 27, 2011 16:30
「プログラミング言語 Ruby」の目次 (jpdfbookmarks format)
* O'reilly Japan Ebook Store で販売されている「プログラミング言語 Ruby (http://www.oreilly.co.jp/books/9784873113944/)」の目次です。
* Gist の仕様上 UTF-8 になってるので、Shift JIS に変換してください。
* JPdfBookmarks (http://sourceforge.net/projects/jpdfbookmarks/) で対象の PDF を開き、[Tools]-[Load] から目次ファイルを指定、[File]-[Save] で保存してください。
@labocho
labocho / bench_aws.rb
Created January 30, 2012 18:21
CarrierWave Benchmark (URL generating for AWS private bucket)
$LOAD_PATH << File.expand_path("lib") # carrierwave/lib path
require "carrierwave"
require "benchmark"
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'foo',
:aws_secret_access_key => 'bar',
}
@labocho
labocho / ruby-debug-man.md
Created January 31, 2012 16:53
ruby-debug 0.11 Command Documatation

ruby-debug 0.11 Command Documentation

break

b[reak] file:line [if expr]

b[reak] class(.|#)method [if expr]

@labocho
labocho / clean_html.rb
Created February 28, 2012 13:14
Cleaning HTML by using Chrome via Selenium
#!/usr/bin/env ruby
require "selenium-webdriver"
require "open-uri"
require "uri"
require "tempfile"
url = nil
if STDIN.tty?
url = ARGV.shift
unless url
@labocho
labocho / file0.rb
Created March 23, 2012 04:42
CSV を文字コード変換しつつロード ref: http://qiita.com/items/8559576b71642b79df67
CSV.foreach(filename, encoding: "Shift_JIS:UTF-8") do |row|
# …
end
@labocho
labocho / template.html
Created July 14, 2012 10:51
FC2 blog template for redirecting to other url.
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="content-type" content="text/html; charset=<%template_charset>">
<!--Google等のインデックスよけ-->
<meta name="robots" content="noindex,follow">
<!-- 各記事のページのリダイレクト -->
<!--permanent_area-->
<meta http-equiv="refresh" content="0; url=http://penguinlab.jp/blog/post/<!--topentry--><%topentry_no><!--/topentry-->">