Skip to content

Instantly share code, notes, and snippets.

@yattom
yattom / fizzbuzzA.py
Last active September 25, 2018 05:49
[print(("Fizz" if i%3==0 else "") + ("Buzz" if i%5 == 0 else "") or str(i)) for i in range(1,101)]
@yattom
yattom / vending_machine.rb
Last active September 17, 2018 11:52
自動販売機のRubyコードとspecファイル。モブプログラミングでTDDで書いたもの。アジャイルジャパン2017にて / VendingMachine ruby code and spec written in a mob programming session in TDD way at Ajile Japan 2017
# cola/lib/vending_machine.rb
class VendingMachine
attr_reader :dispense_box
attr_reader :refund_box
attr_accessor :zaiko_count
def initialize
@zaiko_count = 1
end
@yattom
yattom / dist_dice.py
Last active August 7, 2018 04:31
show distribution of roll of dices
def dice_dist(n):
d = [0]
for i in range(n):
d = [b + r for b in d for r in range(1, 7)]
for r, c in {n: d.count(n) for n in d}.items():
print(f"{r:>3} {c/6**n:>5.1%} {'*'*c}")
[ec2-user@ip-172-30-0-209 ~]$ mkdir foo
[ec2-user@ip-172-30-0-209 ~]$ cd foo
[ec2-user@ip-172-30-0-209 foo]$ python3 -m venv .
[ec2-user@ip-172-30-0-209 foo]$ . bin/activate
(foo) [ec2-user@ip-172-30-0-209 foo]$ pip install pytest-testmon
Collecting pytest-testmon
Downloading https://files.pythonhosted.org/packages/04/71/0f7ff7772cfd96b5ac1627d1218e2568ce2a2cb6d40b8c7dede4f25d262a/pytest-testmon-0.9.11.tar.gz
Collecting pytest<4,>=2.8.0 (from pytest-testmon)
Downloading https://files.pythonhosted.org/packages/d3/75/e79b66c9fe6166a90004bb8fb02bab06213c3348e93f3be41d7eaf625554/pytest-3.6.1-py2.py3-none-any.whl (194kB)
100% |████████████████████████████████| 194kB 4.0MB/s
@yattom
yattom / FizzBuzz.php
Created June 1, 2018 04:03
An example of PHP unit test for FizzBuzz and implementations (a very buggy one and correct one)
<?php
declare(strict_types=1);
final class FizzBuzz
{
public function translate($num) {
if ( $num % 15 == 14 ) {
return "FizzBuzz";
}
if ( $num % 3 == 0 && $num != 72) {
@yattom
yattom / __main__.py
Created December 28, 2017 07:01
du.py
import sys
from du import main
if __name__=='__main__':
if len(sys.argv) > 1:
main.main(sys.argv[1])
else:
main.main()
@yattom
yattom / fraction.md
Last active July 25, 2017 22:54
TDDのお題 計算機

いろいろな計算ができる計算機を作ってください。以下のインターフェースはあくまで一例(イメージ)です。

  1. 整数の足し算ができるようにしてください

calc("+", 3, 4) => 7

  1. 整数の引き算ができるようにしてください

calc("-", 10, 4) => 6

PLoP(Pattern Language of Programming)のイベントで知ったアイスブレークがあります。

  1. 全員が輪になる
  2. 最初の1人(司会など)がスタートとして、右の人に"tic"、左の人に"toc"という
  3. あとは、以下のルールで伝えていく
    • なにか(ticかtoc)言われたら、"What?"と聞き返す
    • "What?"と右から言われたら、そのまま左に"What?"と流す。左から言われたら右に
    • 2回目になにか(ticかtoc)言われたら、その言葉を次の人に伝える(右から来たら左へ、左から来たら右へ)
  4. ぐるっと回って最初の人までticとtocが伝わったら、おわり
在庫管理システムをモデリングしてください。
以下の機能が必要です。
* 商品ごとに在庫がいくつあるか管理できる
* 出荷時に、倉庫に対して何をいくつ出荷するかピッキングリストを表示する
* 商品の変化(入荷、出荷、移動、など)をすべて記録し、履歴が残る
## ユースケース001
前提: 商品Aが50個在庫している
function prompt() {
Write-Host "[" -nonewline
Write-Host "$(Get-Location)" -foregroundcolor Cyan -nonewline
Write-Host "]" -nonewline
Write-Host " ${env:USERNAME}@${env:COMPUTERNAME}" -foregroundcolor Magenta
"> "
}
function Add-Path($path) {
if("" -eq $path) {