Skip to content

Instantly share code, notes, and snippets.

View labocho's full-sized avatar

labocho

View GitHub Profile
@labocho
labocho / git-log-p.py
Last active August 17, 2016 05:26
Sublime Text 2/3 command to show result of `git log -p` current file
import sublime, sublime_plugin, subprocess
class GitLogPatchCommand(sublime_plugin.TextCommand):
'''
Show result of `git log -p` current file
# Installation
1. Save to Packages/User/git-log-p.py
2. Edit Packages/User/User.sublime-commands
@labocho
labocho / preview.rb
Created February 10, 2016 07:58
Open PDF file with Preview.app at specified page
#!/usr/bin/env ruby
# Usage:
# preview path/to/pdf:123 # to open path/to/pdf in Preview.app and jump to specified page
require "open3"
require "json"
OPEN_PAGE_SCRIPT = <<-JS
function run(argv) {
var options = JSON.parse(argv[0]);
#!/usr/bin/env ruby
# Kobito の JSON-LD を受け取って、#{timestamp}_#{title}.md のファイルを生成する
# Example: cat ~/Dropbox/Kobito/Kobito\ Archive/*.json | jq -c . | kobito-export
require "json"
require "time"
while line = gets
json = JSON.parse(line)
updated_at = Time.parse(json["updated_at"])
#!/usr/bin/env ruby
# List all foreign key constraints for *_id columns.
# Use --only-no-constraint to list *_id has no constraint.
gem "activerecord", ">= 4.2.1"
gem "mysql2"
require "optparse"
require "active_record"
require "mysql2"
@labocho
labocho / convert_test_request_method_invocation.rb
Created November 17, 2016 06:40
Synvert snippet that converts test request method invocation to Rails 5 style.
# synvert --load convert_test_request_method_invocation.rb --run rails/convert_test_request_method_invocation .
# convert `get @foo, @bar, @baz` to `get params: @foo, session: @bar, flash: @baz` etc.
Synvert::Rewriter.new 'rails', 'convert_test_request_method_invocation' do
%w(test/**/*.rb spec/**/*.rb features/**/*.rb).each do |file_pattern|
within_files file_pattern do
%w(get post put patch delete).each do |http_method|
with_node type: 'send', receiver: nil, message: http_method do
case current_node.arguments.size
when 2
replace_with "#{http_method} {{arguments[0]}}, params: {{arguments[1]}}"
@labocho
labocho / split_pref.rb
Created January 20, 2017 05:30
日本の住所を都道府県で分割するやつ
#!/usr/bin/env ruby
# Usage: echo "東京都xxx\n大阪府xxx\n名古屋市" | ./split_pref.rb
PREFECTURES = [
"北海道", "青森県", "岩手県", "宮城県", "秋田県",
"山形県", "福島県", "茨城県", "栃木県", "群馬県",
"埼玉県", "千葉県", "東京都", "神奈川県", "新潟県",
"富山県", "石川県", "福井県", "山梨県", "長野県",
"岐阜県", "静岡県", "愛知県", "三重県", "滋賀県",
"京都府", "大阪府", "兵庫県", "奈良県", "和歌山県",
@labocho
labocho / generator_spec.zsh
Created July 19, 2017 06:47
thor-zsh_completion example
#compdef generator_spec
local state
_generator_spec() {
__generator_spec
}
__generator_spec() {
readonly local DEPTH=2
@labocho
labocho / use_factory_girl_instead_of_machinist.rb
Created July 28, 2017 09:41
Synvert snippet that converts machinist style fixture generation (like `Foo::Bar.make`) to factory_girl's one (like `build(:foo_bar)`) etc.
# synvert --load use_factory_girl_instead_of_machinist.rb --run factory_girl/use_factory_girl_instead_of_machinist .
# convert `Foo::Bar.make` to `build(:foo_bar)` etc.
require "active_support/core_ext/string"
Synvert::Rewriter.new 'factory_girl', 'use_factory_girl_instead_of_machinist' do
%w(test/**/*.rb spec/**/*.rb features/**/*.rb).each do |file_pattern|
within_files file_pattern do
with_node type: 'send', message: "make" do
name = current_node.receiver.to_source.underscore.gsub("/", "_")
@labocho
labocho / vpn.rb
Last active October 18, 2017 08:20
Ruby script to connect/disconnect VPN with service and (optional) configuration name
#!/usr/bin/env ruby
# Thanks to: https://gist.github.com/kawaz/8bd7db8416f90c3cc168f12c8c75b6d3
# Usage: vpn (connect|disconnect) SERVICE_NAME [CONFIGURATION_NAME]
require "json"
SCRIPT = <<-JS
function run(json) {
var argv = JSON.parse(json);
var sysev = Application("System Events");
@labocho
labocho / kobito2html.rb
Last active November 2, 2017 05:48
Export HTML from Kobito.db with tags and dates (like Evernote)
#!/usr/bin/env ruby
# Usage: ./kobito2html.rb Kobito.db ./export
gem "activerecord", "~> 5.1.4"
gem "nokogiri", "~> 1.8.1"
gem "sqlite3", "~> 1.3.13"
require "active_record"
require "nokogiri"
require "sqlite3"