Skip to content

Instantly share code, notes, and snippets.

@kencoba
kencoba / Bridge.scala
Created February 21, 2012 10:49
Bridge pattern (Design Patterns in Scala)
// http://en.wikipedia.org/wiki/Bridge_pattern
trait DrawingAPI {
def drawCircle(x:Double, y: Double, radius:Double)
}
class DrawingAPI1 extends DrawingAPI {
override def drawCircle(x: Double, y: Double, radius: Double) = {
printf("API1.circle at %f:%f radius %f\n", x, y, radius)
}
@kencoba
kencoba / Adapter.scala
Created February 21, 2012 10:51
Adapter pattern (Design Patterns in Scala)
trait ProductPrice {
def price: Int
}
class Product {
var cost = 500
}
class ProductDelegationAdapter extends ProductPrice {
private var product = new Product
@kencoba
kencoba / Composite.scala
Created February 21, 2012 11:08
Composite pattern (Design Patterns in Scala)
// http://en.wikipedia.org/wiki/Composite_pattern
trait Graphic {
def print
}
class CompositeGraphic extends Graphic {
private var mChildGraphics = List[Graphic]()
override def print = {
@kencoba
kencoba / Decorator.scala
Created February 21, 2012 11:27
Decorator pattern (Design Patterns in Scala)
// http://en.wikipedia.org/wiki/Decorator_pattern
trait Coffee {
def cost:Double
def ingredients: String
}
class SimpleCoffee extends Coffee {
override def cost = 1
override def ingredients = "Coffee"
@kencoba
kencoba / ramen.clj
Created December 28, 2012 06:24
print traces of graph.
(use 'clojure.set)
(def middle-cols 5)
(def max-col (inc middle-cols))
(def max-row 2)
(defn row [point] (first point))
(defn col [point] (second point))
@kencoba
kencoba / tetrahedral_group.scala
Last active December 20, 2015 07:29
Multiplication table of Tetrahedral group.
val id = "ABCD" //> id : String = ABCD
val tl = "BADC" //> tl : String = BADC
val tm = "DCBA" //> tm : String = DCBA
val tn = "CDAB" //> tn : String = CDAB
val a1 = "ACDB" //> a1 : String = ACDB
val a2 = "ADBC" //> a2 : String = ADBC
val b1 = "DBAC" //> b1 : String = DBAC
val b2 = "CBDA" //> b2 : String = CBDA
val c1 = "BDCA" //> c1 : String = BDCA
val c2 = "DACB" //> c2 : String = DACB
@kencoba
kencoba / MyPhaseListener.java
Created July 28, 2013 06:24
JSF PhaseListener for logging request and session information.
package javaee.util.jsf.phaselistener;
import java.util.Map;
import javax.faces.component.UIViewRoot;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.servlet.http.HttpSession;
@kencoba
kencoba / Stack.als
Created December 12, 2013 04:12
「形式手法入門」P22「2.1.3 抽象データの表現と解析」 ref: http://qiita.com/kencoba/items/15197b19d15ebfd557ed
module Queue
abstract sig Node { next : lone Node }
abstract sig Queue { root : lone Node }
fact noCycle { no n : Node | n in n.^next }
fact noReflexive { no n : Node | n = n.next }
fact allNodeInAQueue {
all n : Node | some q : Queue | n in q.root.*next
}
@kencoba
kencoba / eventDrivenStyle.als
Created December 12, 2013 09:36
「形式手法入門」P157 「6.2.5 イベント駆動スタイル」 ref: http://qiita.com/kencoba/items/d3c91be08a871ccd4014
// 「形式手法入門」P157 「6.2.5 イベント駆動スタイル」
open util/ordering [Time]
open util/natural
sig Time{}
sig State {
a, b, c, n : Natural one -> Time,
d : Natural
}{
! 133 is Windows key
keycode 133 = Zenkaku_Hankaku Kanji Zenkaku_Hankaku Kanji
! 修飾子マップ mod4 から Win キーのコードを削除
remove mod4 = Super_L
! 101 is katakana_hiragana key
keycode 101 = Alt_R Meta_R Alt_R Meta_R
remove Control = Control_L
remove Control = Control_R