Skip to content

Instantly share code, notes, and snippets.

View labocho's full-sized avatar

labocho

View GitHub Profile
@labocho
labocho / handlebars_helpers.coffee
Last active July 10, 2021 13:37
Handlebars で使うヘルパー関数集
##############################
# Formatting
##############################
# Date を "2013年8月31日 (土)" の形式に
Handlebars.registerHelper "d", (date) ->
return "" unless date
weekdays = ["日", "月", "火", "水", "木", "金", "土"]
"#{date.getFullYear()}年#{date.getMonth() + 1}月#{date.getDate()}日 (#{weekdays[date.getDay()]})"
@labocho
labocho / csvconv.rb
Last active August 29, 2015 14:03
CSV Converter
#!/usr/bin/env ruby
# Example:
# # UTF-8 CSV to Excel Compatible TSV
# $ csvconv --output-encoding="bom|utf-16le" --output-col-sep="\t" data.csv > data.txt
# # Excel Compatible TSV to UTF-8 CSV
# $ csvconv --input-encoding="bom|utf-16" --input-col-sep="\t" --output-encoding="utf-8" --output-col-sep="," data.txt > data.csv
require "optparse"
require "csv"
@labocho
labocho / backup-twitpic.rb
Created September 5, 2014 02:02
引数で指定したユーザの twitpic のメタデータと画像を ./twitpic に保存
#!/usr/bin/env ruby
gem "rest-client", "~> 1.6.6"
require "rest-client"
require "json"
require "time"
unless username = ARGV.first
STDERR.puts "Usage: backup-twitpic username"
exit 1
end
@labocho
labocho / kobito_export.rb
Created October 3, 2014 07:20
Kobito.db から Kobito 2.0 の同期用 JSON へエクスポート
#!/usr/bin/env ruby
unless ARGV.first
STDERR.puts "Usage #{$0} ~/Library/Kobito/Kobito.db"
exit 1
end
gem "activerecord", "4.1.6"
gem "composite_primary_keys", "7.0.10"
gem "sqlite3", "1.3.9"
@labocho
labocho / foreigner.rb
Created February 26, 2015 10:34
Synvert snippet to keep foreign key name generated by `foreigner` gem for Rails 4.2 app.
# Synvert snippet to keep foreign key name generated by `foreigner` gem for Rails 4.2 app.
# Usage:
# Save to ~/.synvert/lib/rails/foreigner.rb
# $ cd RAILS_ROOT
# $ synvert --run rails/foreigner
require "active_support/inflector"
load "config/initializers/inflections.rb"
module Synvert::Core
@labocho
labocho / modsec_audit2jsonl.rb
Created October 26, 2015 06:02
Convert ModSecurity audit log to JSON Lines
#!/usr/bin/env ruby
# Convert ModSecurity audit log to JSON Lines
#
# Usage:
# modsec_audit2jsonl.rb modsed_audit.log
# Or
# cat modsed_audit.log | modsec_audit2jsonl.rb
require "json"
@labocho
labocho / keepassx-to-1passwords.rb
Created October 27, 2015 05:12
Convert exported XML file from KeepassX that could be imported to 1Password (via CSV comma separated file)
#!/usr/bin/env ruby
# Usage: ruby keepassx-to-1passwords.rb keepassx.xml > 1password.csv
# Inspired by: Convert exported XML file from KeepassX that could be imported to 1Password (via CSV comma separated file)
# https://gist.github.com/arudmin/52aec759a8c5d7543e36#file-keepassx-to-1passwords-py
require "csv"
require "nokogiri"
def each_entry(group, super_group_title = nil, &block)
@labocho
labocho / iterm-new-session
Last active August 1, 2016 17:49
New session (tab) in iTerm with(or without) command and name.
#!/usr/bin/env ruby
# Usage: iterm-new-session [-n NAME] [command]
# command should be quoted (e.g. iterm-new-session 'ls -l')
require "optparse"
require "open3"
require "json"
require "shellwords"
require "tmpdir"
@labocho
labocho / d.rb
Last active June 20, 2016 03:11
Script parses and prints date time as several formats
#!/usr/bin/env ruby
#
# d - Parse and print date time as several formats
#
# Usage:
#
# $ d [DATETIME]
#
# Supported formats:
#
@labocho
labocho / _example
Created December 17, 2015 09:41
thor-zsh_completion example
#compdef example
local state
_example() {
__example
}
__example() {
readonly local DEPTH=2