Skip to content

Instantly share code, notes, and snippets.

View giwa's full-sized avatar

Ken Takagiwa giwa

  • Nombre Premier
  • Tokyo
View GitHub Profile
@giwa
giwa / file0.rb
Last active February 3, 2016 09:37
Understand What Ruby considers to be True ref: http://qiita.com/giwa/items/8d083c48152bdb99f3fa
[3] pry(main)> true.class
=> TrueClass
[4] pry(main)> false.class
=> FalseClass
def vs_pascal(p):
max_len = len(l_to_str(p[-1]))
for e in p:
print(l_to_str(e).center(max_len))
def l_to_str(l, d=" "):
return d.join(map(lambda x: str(int(x)), l))
def comb(n, r):
"""
fibonacci
┌ 1; n = 0
fibo(n) = ┤ 1; n = 1
└ fibo(n-1) + fibo(n-2); n > 1
http://www.geocities.jp/m_hiroi/light/pyalgo01.html
"""
@giwa
giwa / file0.txt
Last active January 8, 2016 10:09
Recusive and Tail Recursive: factorial ref: http://qiita.com/giwa/items/4d9528aed2d8a2ebb8ae
# Definiation of factorial
# 0! = 1
# n! = n * (n - 1)!
#
#|Call:1 │->│Call:2 │->│Call:3 │->│Call:4 │->│Call:5 │
#│n:4 │ │n:3 │ │n:2 │ │n:1 │ │n:0 │
#│value : 24│<-│value : 6 │<-│value : 2 │<-│value : 1 │<-│value : 1 │
#
#@profile
def fact(n):
import random
def vs_insertion(l, i):
n = l.copy()
n.insert(i+1, "*")
n.insert(i+1, "]")
n.insert(0, "[")
print(" ".join(map(lambda x: str(x), n)))
import random
import math
def bs_print(elements, low, high, middle):
"""
visulize binary search process
"""
es = elements.copy()
ms = es[middle]
import math
"""
Given list of integer and find primes
"""
l = list(range(1, 101))
def is_prime(x):
if x == 1:
return False
@giwa
giwa / file0.txt
Last active October 26, 2015 21:23
SQLAlchemy + DB migration by Alembic ref: http://qiita.com/giwa/items/87789d7ac22e633024d2
from sqlalchemy import create_engine
@giwa
giwa / ansible-mkdir
Created October 24, 2015 16:29
ansible-scripts
#!/bin/sh
#
# Create directories for ansible
# .
# ├── common-roles/
# │ ├── base/
# │ │ ├── defaults/
# │ │ │ └── main.yml
# │ │ ├── files/
# │ │ │ ├── ...
@giwa
giwa / file0.txt
Created October 7, 2015 14:35
Error: Failed to update tap: caskroom/versions ref: http://qiita.com/giwa/items/0727890be57ed3b07666
$ brew untap caskroom/versions
$ brew tap caskroom/versions
$ brew update
Already up-to-date.