Skip to content

Instantly share code, notes, and snippets.

View sakatam's full-sized avatar

Makoto Sakata sakatam

View GitHub Profile
@sakatam
sakatam / karabinar.json
Created April 11, 2018 21:04
vim-ish arrow key mappings
{
"global": {
"check_for_updates_on_startup": true,
"show_in_menu_bar": true,
"show_profile_name_in_menu_bar": false
},
"profiles": [
{
"complex_modifications": {
"parameters": {
@sakatam
sakatam / config.py
Created November 28, 2016 04:49
keyhac config for vim-ish cursor movement
from keyhac import *
def configure(keymap):
keymap_global = keymap.defineWindowKeymap()
keymap_global[ "Ctrl-H" ] = "Left"
keymap_global[ "Ctrl-J" ] = "Down"
keymap_global[ "Ctrl-K" ] = "Up"
keymap_global[ "Ctrl-L" ] = "Right"
@sakatam
sakatam / pardon.coffee
Last active November 10, 2017 09:49
Hubot script to catch all unhandled messages
module.exports = (robot) ->
robot.catchAll (msg) ->
if msg.message.match /// ^#{robot.name}\s ///
msg.reply "pardon?" # or whatever
@sakatam
sakatam / file0.js
Created June 19, 2014 07:44
AngularJS x Rails - $httpモジュールからの XHR が text/html と認識されちゃう問題 ref: http://qiita.com/sakatam/items/feff580add9b76e6f538
$httpProvider.defaults.headers.common["Accept"] = 'application/json';
@sakatam
sakatam / AnnealingSoftmax.coffee
Created May 12, 2014 06:43
(simplified) Softmax Annealing in CoffeeScript
# https://github.com/johnmyleswhite/BanditsBook/blob/master/ruby/algorithms/softmax/annealing.rb
class AnnealingSoftmax
constructor: (@counts, @values) ->
selectArm: ->
t = (@_sum @counts) + 1
temperature = 1 / Math.log(t + 0.0000001)
tmp_values = $.map @values, (value) -> Math.exp(value / temperature)
z = @_sum tmp_values
@sakatam
sakatam / bulk-add-pubkey.md
Last active December 31, 2015 00:09
Here's how to add a public key to multiple servers in one shot. The script below avoids duplicated entry by grepping the authorized_keys file in advance.

Template script:

$ PUB="paste your pubkey here"
$ for h in %LIST OF HOSTS%; do echo -n "$h -> " && ssh ec2-user@${h} "if grep -Fxq \"${PUB}\" .ssh/authorized_keys; then echo 'the pubkey already exists'; else echo \"${PUB}\" >> .ssh/authorized_keys && echo \"the pubkey was added\"; fi"; done

Example usage:

$ PUB='ssh-rsa XXXXXXXXXXXXXXXXXXXXX== foo'
$ for h in dev1 dev2 dev3; do echo -n "$h -> " && ssh ec2-user@${h}.mydomain.com "if grep -Fxq \"${PUB}\" .ssh/authorized_keys; then echo 'the pubkey already exists'; else echo \"${PUB}\" >> .ssh/authorized_keys && echo \"the pubkey was added\"; fi"; done
@sakatam
sakatam / circleci-specs-in-parallel
Created November 8, 2013 17:16
a circleci parallelism script optimized for rspec.this script is based on https://circleci.com/docs/parallel-manual-setup#balancing
#!/bin/bash
i=0
files=()
# sort spec files by number of examples for better balancing
for file in $(find ./spec -name "*_spec.rb" -print0 | xargs -0 grep -e "^ *it" -c | sort -t: -k2,2rn | awk -F":" '{ print $1 }')
do
if [ $(($i % $CIRCLE_NODE_TOTAL)) -eq $CIRCLE_NODE_INDEX ]
then
files+=" $file"
@sakatam
sakatam / a-better-jp-phone-regex.md
Created March 18, 2013 15:48
a better (and not too explicit) set of regular expressions for japanese phone numbers based on ministry of internal affairs' spec (総務省).
@sakatam
sakatam / better-jp-phone-regex
Created October 5, 2012 03:39
a better (and not too explicit) set of regular expressions for japanese phone numbers
// a better (and not too explicit) set of regular expressions for japanese phone numbers based on a spec defined by ministry of internal affairs (総務省).
// http://www.soumu.go.jp/main_sosiki/joho_tsusin/top/tel_number/q_and_a-2001aug.html
// fixed phones
/^0(\d{1}-?\d{4}|\d{2}-?\d{3}|\d{3}-?\d{2}|\d{4}-?\d{1})-?\d{4}$/
// mobile / PHS
/^0[789]0-?\d{4}-?\d{4}$/
// IP phones