Skip to content

Instantly share code, notes, and snippets.

# coding: utf-8
# python 2.7.5 / fabric 1.7.0
from fabric.api import env, run
from fabric.decorators import roles, task
from fabric.decorators import parallel
env.use_ssh_config = True
env.colorize_errors = True
env.warn_only = True
@hagiyat
hagiyat / gist:9221547
Created February 26, 2014 01:18
crontabで1分おきに交互に実行、の備忘録
00-58/2 * * * * sh /home/vagrant/tmp/test.sh >> /home/vagrant/tmp/test.txt
01-59/2 * * * * sh /home/vagrant/tmp/test2.sh >> /home/vagrant/tmp/test.txt
@hagiyat
hagiyat / gist:9459386
Created March 10, 2014 04:14
python3で文字列反転色々
#pythonっぽくない
def reverse1(data):
result = ""
for letter in list(data):
result = letter + result
return result
# 標準
def reverse2(data):
@hagiyat
hagiyat / random-word generater
Last active August 29, 2015 14:02
generate random word
function(length) {
var range = function(start, end) {
var result = [];
for(var i=start; i<=end; i++) {
result.push(i);
}
return result;
};
var source = (function(src, count) {
@hagiyat
hagiyat / remove_orig_files
Created August 25, 2014 07:18
Remove the orig file made ​​with git mergetool
# OSX
git status | gsed -n '/orig$/p' | gsed -e 's/\t//g' | xargs rm
@hagiyat
hagiyat / optimize_nested_ternary_operator
Last active August 29, 2015 14:13
三項演算子のネストを解消しつつワンライナーで書く
cond1 = false
cond2 = true
# nested ternary operater
cond1 ? 'piyo' : (cond2 ? 'baz' : 'bar')
# use lambda
[->{'piyo' if cond1}, ->{'baz' if cond1 and cond2}, ->{'bar'}].lazy.map(&:call).select(&:present?).first
=> 'bar'
@hagiyat
hagiyat / bingo.rb
Last active August 29, 2015 14:16
generate bingo card
class Bingo
def self.generate
[*1..75]
.each_slice(15)
.map { |v| v.sample(5) }
.tap { |a|
a[2][2] = nil # (´;ω;`)
break a.unshift('BINGO'.chars)
}
.map { |v|
@hagiyat
hagiyat / wercker.yml
Last active April 8, 2016 14:50
test-queue on wercker
# only run spec
box: nanapi/ubuntu-rvm-with-phantomjs@0.0.2
no-response-timeout: 10
services:
- ibash/mysql5.6
build:
# No.4
list = [50, 2, 1, 9]
list.sort_by(&:to_s).reverse.join
# No.5
[*2..9].reduce(['1']) do
|res, v| res.map { |r| ['', ' + ', ' - '].map { |oper| "#{r}#{oper}#{v}" } }.flatten
end.select { |v| eval(v) == 100 }
class Hoge
private
def fuga
'hoge'
end
end
module Piyo
def baz
fuga()