Skip to content

Instantly share code, notes, and snippets.

View atsuya046's full-sized avatar

Nobuya Oshiro atsuya046

View GitHub Profile
@atsuya046
atsuya046 / prototype.py
Created March 13, 2014 14:09
GoF design pattern with Python - Prototype
# -*- coding: utf-8 -*-
import copy
class Prototype:
def __init__(self):
self._objects = {}
def register_object(self, name, obj):
"""Register an object"""
@atsuya046
atsuya046 / grammar.clj
Created February 1, 2015 01:51
clj_grammar
; ====== 値の束縛 ========
; シンボルに値を束縛する(いわゆる代入)
(def x 3)
(def y (+ x 1))
; ====== 関数 ========
; 関数を定義する
(defn hello-clojure []
(println "Hello Clojure"))
@atsuya046
atsuya046 / image_file_attachement.rb
Last active August 29, 2015 14:17
papeclipで画像ファイル向けのUtilityメソッドを定義するサンプル
# paperclipでは画像ファイル以外も添付できるので、気をつけないと画像ファイル以外のObjectからも呼ばれる危険性がある。
# 画像ファイルに限定したUtilityメソッドを安全に定義するための例として以下の様な実装を考えてみた。
module ImageFileDecorator
extend ActiveSupport::Concern
module ClassMethods
# Public
#
@atsuya046
atsuya046 / 0_reuse_code.js
Last active August 29, 2015 14:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@atsuya046
atsuya046 / simple-http-server.md
Created May 29, 2015 02:45
pythonで簡単にWebサーバを作る

htmlファイルを作成

touch index.html
vi index.html
<h1>Hello World</h1>
@atsuya046
atsuya046 / README.md
Last active November 5, 2015 20:09
test_webpack

Install webpack

npm install webpack -g

Build

webpack ./main.js bundle.js
@atsuya046
atsuya046 / fizzbuzz.clj
Last active August 29, 2015 14:27
Fizz Buzz with Typed Clojure
(ns fp.match
(:require [clojure.core.match :refer (match)]))
(defprotocol TFizzBuzz
(to-string [this]))
(deftype Fizz [number] TFizzBuzz
(to-string [this] "Fizz"))
(deftype Buzz [number] TFizzBuzz
(to-string [this] "Buzz"))
@atsuya046
atsuya046 / unittest_with_scala.md
Last active August 29, 2015 14:27
ユニットテストのこと。あとspecs2のことも。

ユニットテストする意義

ユニットテストを書こう!http://qiita.com/kompiro/items/78f2c8d2022a685baa83

Maintainability

プロダクションコードの変更時、既存と振る舞いが変わる箇所はテストが失敗する。そのため、変更が影響を及ぼす範囲がわかる

ユニットテストを書くと、コードの振る舞いがテストコードに明示されるため、振る舞いを予測可能な範囲が増える

Design

ユニットテストを書くときは、APIの利用者になるため、APIの利用者から見て利用しやすいコードを目指すモチベーションを産みやすい

@atsuya046
atsuya046 / Example1.scala
Last active October 13, 2015 03:33
specs2 example
class Core {
def run(): Boolean = {
true
}
}
@atsuya046
atsuya046 / MyClass.scala
Last active January 28, 2016 02:48
ScalaCheckで独自のGeneratorを作る ref: http://qiita.com/atsuya046/items/2ab7505336a9f892bc47
case class MyClass(number: Int, multiplier: Multiplier) {
def calc: Int = {
number * multiplier.number
}
}
case class Multiplier(number: Int)