Skip to content

Instantly share code, notes, and snippets.

@koki-h
koki-h / Vagrantfile
Created May 28, 2020 10:30
docker-compose が最初から動くVagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-18.04"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.provision "shell", inline: <<-SHELL
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
usermod -aG docker vagrant
@koki-h
koki-h / semaphore.js
Created May 18, 2020 04:06 — forked from gregkorossy/semaphore.js
A simple implementation of a semaphore in JS
function Semaphore(max) {
var counter = 0;
var waiting = [];
var take = function() {
if (waiting.length > 0 && counter < max){
counter++;
let promise = waiting.shift();
promise.resolve();
}
@koki-h
koki-h / semaphore.js
Last active May 18, 2020 04:06 — forked from gregkorossy/semaphore.js
A simple implementation of a semaphore in JS
function Semaphore(max) {
// 排他制御のためのセマフォ
// https://gist.github.com/Gericop/e33be1f201cf242197d9c4d0a1fa7335
var counter = 0;
var waiting = [];
var take = function() {
if (waiting.length > 0 && counter < max){
counter++;
@koki-h
koki-h / locale_from_migration.rb
Created February 11, 2020 08:03
コメントを利用してマイグレーションファイルからロケール(yaml)を作成
require 'psych' # to_yamlを使うため
def table_name(line)
line.scan(/create_table :(.+), comment: \"(.+)"/)
$LOCALE["ja"]["activerecord"]["models"][$1] = $2
$LOCALE["ja"]["activerecord"]["attributes"][$1] = {}
$1
end
def column_name(line)
@koki-h
koki-h / conv.rb
Created February 6, 2020 02:24
カレントディレクトリ内のcsvファイルをUTF-8からShift_JISへ変換
Dir.glob("./*.csv") do |f|
p f
`mv #{f} #{f}.bak`
`nkf -W -s #{f}.bak > #{f}`
end
@koki-h
koki-h / set_table_name_with_filename.rb
Created January 17, 2020 07:37
ActiveRecordモデルクラスの参照先テーブル名をモデルクラスの定義されているファイル名と同じに設定するスニペット
require 'tempfile'
require 'fileutils'
tables = %w|
table1
table2
table3
table4
table5
table6
@koki-h
koki-h / boot_chronium.sh
Last active February 16, 2019 11:39
chroniumをキオスクモードで起動する
#ディスプレイ番号を指定すれば別のコンソールからも起動可能
# cronの @reboot に書けば自動でブラウザ起動
DISPLAY=:1 chromium --kiosk
@koki-h
koki-h / mov2mp4.sh
Last active May 29, 2018 13:21
movからmp4へ変換(acodecは指定しなくても大丈夫そう) ref: https://stackoverflow.com/questions/12026381/ffmpeg-converting-mov-files-to-mp4
ffmpeg -i in.MOV -vcodec copy out.mp4
@koki-h
koki-h / diff_dir_every.rb
Created April 19, 2018 07:53
2つのディレクトリ名を受け取り、それぞれの中にある同名のファイルのdiffを取る
dir1 = ARGV[0]
dir2 = ARGV[1]
Dir.glob("#{dir1}/*").sort.each do | file |
filename = File.basename(file)
puts "#{file} vs #{dir2}/#{filename} :"
puts `sdiff -bBWs #{file} #{dir2}/#{filename}` #side-by-sideで差分のある行だけを表示
end
@koki-h
koki-h / parse_swift_time.php
Last active February 23, 2018 04:49
swiftのtimeIntervalSinceReferenceDateで生成した日付数値をphpでパースする
<?php
// SwiftのtimeIntervalSinceReferenceDateは'2001-01-01 00:00:00 UTC'からの経過秒数を返すため
// phpでは'2001-01-01 00:00:00 UTC'のUnixタイムを加算して日付に変換する。
// see: https://developer.apple.com/documentation/foundation/nsdate/1417376-timeintervalsincereferencedate$reference_time = strtotime('2001-01-01 00:00:00 UTC');
$reference_time = strtotime('2001-01-01 00:00:00 UTC');
$swift_time = 541047955; //example
$d = date("Y/m/d H:i:s",$swift_time + $reference_time );
var_dump($d); //string(19) "2018/02/23 03:05:55"