Skip to content

Instantly share code, notes, and snippets.

View tkm-kj's full-sized avatar

Takumi Kaji tkm-kj

  • Freelance
  • Tokyo
View GitHub Profile
@tkm-kj
tkm-kj / increment_number.go
Last active October 13, 2020 09:38
時間に応じて特定の数を大きくする(ゆっくり負荷をかけていきたい時に便利)
package main
import (
"log"
"time"
)
func main() {
startTime := time.Now()
@tkm-kj
tkm-kj / handle_error.go
Last active October 13, 2020 09:19
errors.Wrap のstacktraceの出方とエラー判定の方法
package main
import (
"fmt"
"log"
"github.com/pkg/errors"
)
var (
@tkm-kj
tkm-kj / concurrency_sandbox.go
Last active September 9, 2020 07:27
golangで並行処理のお勉強
package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/pkg/errors"
)
@tkm-kj
tkm-kj / main.rb
Created July 5, 2020 10:53
じゃんけんの雛形
p1_name = gets.to_s.chomp
p2_name = gets.to_s.chomp
p1 = Player.new(p1_name)
p2 = Player.new(p2_name)
puts Game.new(p1, p2).start
@tkm-kj
tkm-kj / pre-commit
Created February 25, 2017 05:30
git commit完了前に実行されるスクリプト
#!/bin/sh
exec ruby -S -x $0 "$@"
#! ruby
class PreCommitExecutor
COMMANDS = ['bundle exec rspec', 'bundle exec rubocop']
def run
status = COMMANDS.map {|cmd| system(cmd) }.all?
@tkm-kj
tkm-kj / grep_menuitem.vim
Last active April 12, 2016 22:38 — forked from masaakif/grep_menuitem.vim
nerdtree plugin to integrate nerdtree with :grep : Forked from http://gist.github.com/205807
"shove this in ~/.vim/nerdtree_plugin/grep_menuitem.vim
"
"A really rough integration of :grep with nerdtree. Adds a 'g' menu item that
"prompts the user for a search pattern to use with :grep. :grep is run on the
"selected dir (using the parent if a file is selected)
"
" Originally written by scrooloose
" (http://gist.github.com/205807)
" Forked by masaakif
" (http://gist.github.com/205807)
def make_tournament(players)
seeds = (2 ** Math.log2(players.size).ceil) - players.size
players.map.with_index {|player, i| i < seeds ? [player, player] : player }.flatten
end
def janken(player1, player2)
p1 = player1; p2 = player2
p1 = player1 * 10
p2 = player2 * 10
min = [p1.size, p2.size].min
@tkm-kj
tkm-kj / day1.rb
Created March 24, 2016 07:18
どう書く合宿版1日目
require 'pry'
class Tournament
def initialize(data)
@members = data[1..-2].split(")(")
end
def get_enemy(members, player_num)
if members % 2 == 1
return if player_num == members - 3
@tkm-kj
tkm-kj / search_dotfiles.go
Created March 21, 2016 14:57
指定したユーザのdotfileリポジトリのURLをブラウザで開くスクリプト
package main
import (
"fmt"
"github.com/google/go-github/github"
"github.com/skratchdot/open-golang/open"
"log"
"os"
"regexp"
)
@tkm-kj
tkm-kj / lunch_member.rb
Last active March 1, 2016 07:24
まだプロジェクトで一緒になってない3人組の組み合わせを出力するプログラム
class LunchMember
def initialize(data)
@data = data
end
def show_combination
members = @data.flatten.uniq
lunch_patterns = members.combination(3).to_a
result = []