Skip to content

Instantly share code, notes, and snippets.

View iberianpig's full-sized avatar

Kohei Yamada iberianpig

View GitHub Profile
@iberianpig
iberianpig / genesis.json
Created March 9, 2018 03:44
genesis file for multiple nodes testing
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"nonce": "0x0000000000000042",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
@iberianpig
iberianpig / cahe_support.rb
Last active October 18, 2017 07:33
ActiveRecordProxyのメソッドチェーンでcache_keyを提供する
module CacheSupport
extend ActiveSupport::Concern
module ClassMethods
def cache_key
"#{name}/#{ids.hash}-#{maximum(:updated_at).to_i}"
end
end
end
@iberianpig
iberianpig / pre-commit
Created August 16, 2017 08:44
run lints for rails with pre-commit
#!/usr/bin/env ruby
require "pry-byebug"
# execute pre-commit hooks
class PreCommitRunner
def run
check_eslint
check_rubocop
end
@iberianpig
iberianpig / sentakushi.rb
Last active February 2, 2017 11:39
文字列を与えると一様な組み合わせを返す
['a', 'b', 'c', 'd'].permutation.to_a[Digest::MD5.hexdigest("hogefuga").to_i(16) % 24]
#=> ["a", "b", "d", "c"]
@iberianpig
iberianpig / wimax_switch.md
Created January 14, 2017 17:11
Linuxから監視して3GBに達したらノーリミットモードに変更。 データ使用量取得とモード切替のスクリプト。 パッケージバージョン: 1.1.8.1 CUバージョン: 0.7.0.0 ファームウェアバージョン: 0.2.40.0/2.3.9.4

$ cat watch.sh

#!/bin/bash 

wget -O - --http-user=admin --http-password=hoge http://192.168.0.1/usr/jp/adm/statistic.asp | gzip -c -9 > "$(date '+%Y%m%d%H%M%S').html.gz" 

$ cat switch.sh

@iberianpig
iberianpig / yamadash.rb
Created December 18, 2016 07:13
Amazon Dash Buttonを押すとIFTTT経由で出社時刻を報告する
require 'dashed'
require 'net/https'
# main class
class Yamadash
USERNAME = 'yamada'
ICONURL = ''
MACADDRESS = '12:34:56:78:90:ab'
DEVICENAME = 'wlp2s0'
@iberianpig
iberianpig / letsencrypt.crontab
Last active June 7, 2016 18:41
let's encrypt の 自動更新
# monthly 25th 18:00(UTC) == 03:00(JTC) renew
00 18 25 * * /etc/init.d/nginx stop && /home/iberianpig/certbot/certbot-auto renew --force-renew && /etc/init.d/nginx start
@iberianpig
iberianpig / db.rake
Last active May 23, 2016 09:42
db:dump_seed_fu[model]で実行。 db:seed_fuで使えるseedデータがdb/fixtures内に生成されるrake task。
# ./lib/tasks/db.rake
require 'active_record'
@logger = Logger.new(STDOUT)
namespace :db do
desc "Make seed data importable with seed_fu"
task :dump_seed_fu, [:model] => :environment do |t, args|
model_name = args.model.underscore
class_name = args.model.camelize
@iberianpig
iberianpig / toggle_browser_terminal.sh
Created April 20, 2016 05:19
toggle browser and terminal from shellscript
#!/bin/bash
browser_title="Google Chrome"
terminal_title="byobu"
current_window_id=$(xdotool getwindowfocus)
browser_window_id=$(xdotool search --name --onlyvisible "$browser_title")
terminal_window_id=$(xdotool search --name --onlyvisible "$terminal_title")
if test $current_window_id -eq $browser_window_id
@iberianpig
iberianpig / tlp
Created April 18, 2016 16:34
/etc/default/tlp
# ------------------------------------------------------------------------------
# tlp - Parameters for power save
# See full explanation: http://linrunner.de/en/tlp/docs/tlp-configuration.html
# Hint: some features are disabled by default, remove the leading # to enable
# them.
# Set to 0 to disable, 1 to enable TLP.
TLP_ENABLE=1