Skip to content

Instantly share code, notes, and snippets.

View kminiatures's full-sized avatar

kmini kminiatures

  • tokyo
View GitHub Profile
@kminiatures
kminiatures / bump_version.rb
Created August 24, 2017 03:36
bump version script. 1.2.3 => 1.2.4
#!/usr/bin/env ruby
require 'optparse'
begin
OPTS = {unit: 'patch'}
opt = OptionParser.new
units = %w{major minor patch}
opt.on('-u [UNIT]', '--unit', units) {|v| OPTS[:unit] = v}
opt.parse!(ARGV)
@kminiatures
kminiatures / double_width.rb
Created January 5, 2017 09:48
幅の広い文字がある場合の ljust である ljust_w を String に追加する...
class String
def length_w
alpha = self.scan /[a-zA-Z0-9 ]/
double = self.length - alpha.length
double * 2 + alpha.length
end
def ljust_w(width)
len = width - (self.length_w)
len = 0 if len < 0
require 'fileutils'
class FindHeavyFile
def self.find(depth = 0)
size, file = `du -sh *`.strip.split("\n").max_by do |f|
size,file = f.split "\t"
to_bytes(size)
end.split("\t")
puts "#{' ' * depth}#{size} #{file}"
@kminiatures
kminiatures / emoji-search.html
Last active March 2, 2016 00:56
utf emoji search
<!doctype html>
<html>
<head>
<meta http-equiv='content-type' content='text/html; charset=utf-8'>
<meta name="viewport" content="width=360,initial-scale=1">
<title>emoji</title>
<style type="text/css">
body{
color: #666;
@kminiatures
kminiatures / private.xml
Created June 19, 2015 04:12
Karabiner hjkl Setting for Phots.app
<?xml version="1.0"?>
<root>
<!-- define Photos -->
<appdef>
<appname>PHOTOS</appname>
<equal>com.apple.Photos</equal>
</appdef>
<item>
<name>Use "hjkl" keys as arrow keys if you are not editing text for Photos.</name>
@kminiatures
kminiatures / translate.rb
Created April 10, 2015 03:58
Alfred Microsoft Translator Workflow
#!/usr/bin/env ruby
# -*- coding:utf-8 -*-
require 'net/http'
require 'rexml/document'
require 'json'
class Alfred
def initialize
@items = []
end
@kminiatures
kminiatures / gist:5d21bcc2ab3899a0629a
Last active August 29, 2015 14:17
merged_branch for bash_completion
# bash_completion
merged_branch () {
local branches
local input=$2
branches=`git b --no-color --merged | grep -v master`
# echo $branches
COMPREPLY=($(compgen -W '$branches' -- $input))
}
# Delete Remote(pub) and Local Branch.
@kminiatures
kminiatures / MySQL.rb
Created September 25, 2014 04:55
small mysql exec
class MySQL
def initialize(database)
@database = database.to_s
end
def exec(sql)
if sql =~ /\.sql$/ and File.exists? sql
sql = File.read(sql, encoding: Encoding::UTF_8)
end
@kminiatures
kminiatures / peco-hist
Last active August 29, 2015 14:05
incremental search for history using peco.
function peco-hist() {
time_column=`echo $HISTTIMEFORMAT | awk '{printf("%s",NF)}'`
column=`expr $time_column + 3`
cmd=`history | tac | peco | sed -e 38;5;208m's/^ //' | sed -e 's/ +/ /g' | cut -d " " -f $column-`
history -s "$cmd"
eval $cmd
}
@kminiatures
kminiatures / peco-kill
Created August 22, 2014 03:01
incremental search, the process you want to kill.
function peco-kill(){
proc=`ps aux | peco`
pid=`echo "$proc" | awk '{print $2}'`
echo "kill pid:$pid. [$proc]"
kill $pid
}