Skip to content

Instantly share code, notes, and snippets.

View okapies's full-sized avatar
💭
⌨️

Yuta Okamoto okapies

💭
⌨️
View GitHub Profile
@okapies
okapies / Id.scala
Created May 27, 2012 15:02
How to implement case class manually. (for Scala 2.9.2 final)
import scala.runtime.ScalaRunTime
/**
* A sample code to implement a customized case class manually (for Scala 2.9.2 final).
*
* Id has two properties: name and displayName. 'displayName' has default value that
* is same value as 'name'.
*/
class Id private ( // make primary constructor not to be accessible. (standard case class can do)
@okapies
okapies / Prob.hs
Last active December 10, 2015 15:38
An example code for "Making monads" in "Learn You a Haskell for Great Good!".
-- usage: joinProb $ fmap sort flipThree
-- joinProb $ fmap (all (==Tails)) flipThree
import Control.Monad
import Data.Function (on)
import Data.List (groupBy, sortBy)
import Data.Ord (comparing)
import Data.Ratio
newtype Prob a = Prob { getProb :: [(a, Rational)] } deriving Show
@okapies
okapies / promises-are-functional.md
Last active August 14, 2023 11:44
翻訳: ”命令型のコールバック、関数型のプロミス: Node が逸した最大の機会” by James Coglan

命令型のコールバック、関数型のプロミス: Node が逸した最大の機会

Original: "Callbacks are imperative, promises are functional: Node's biggest missed opportunity" by James Coglan

Translated by Yuta Okamoto (@okapies)

Note

  • 訳者は JavaScript や Node.js に関する専門知識がほとんどありません。識者のツッコミをお待ちしております。「◯◯が分からない」等も歓迎です。
  • 元記事から構成を一部変更しています。また、関数型プログラミングに関する記述のうち、議論の骨子に絡まないものは省略しています。
@okapies
okapies / gist:7182102
Last active December 26, 2015 16:48
Value type as Sum types
// value class
class Param(val i: Int) extends AnyVal
implicit def asParam(i: Int) = Param(i)
// followings are invalid because `Param` is a final class.
case class AnyParam(_i: Int) extends Param(_i)
case object ConstantA extends Param(-1)
@okapies
okapies / part7.scala
Last active December 29, 2015 11:09
「プログラマの為の数学勉強会」の資料を ScalaNLP で写経してみたかった http://nineties.github.io/math-seminar/
import breeze.linalg._
/*
* p.15 (http://nineties.github.io/math-seminar/7.html#/15)
*
* Note: Does breeze basically recommend side effects?
* Note: The compiler will complain 'could not find implicit value for parameter canMapValues'
* if you make the type parameter 'Int' as a generic type.
*/
def matAdd(a: DenseMatrix[Int], b: DenseMatrix[Int]) =
@okapies
okapies / HogeOps.scala
Created January 30, 2014 10:29
scalac is crazy with private[this] in value class
class HogeOps(val underlying: Any) extends AnyVal {
private
[this] // <-- !!!
def toOption[A](v: => A): Option[A] = ???
}
@okapies
okapies / MessageLogger.scala
Created May 14, 2014 16:52
Slick 2.0 Sample
import java.io.BufferedReader
import java.io.InputStreamReader
import scala.annotation.tailrec
import org.joda.time._
import com.github.tototoshi.slick.H2JodaSupport._
object MessageLogger extends App {
val profile = scala.slick.driver.H2Driver
@okapies
okapies / fpinscala-chap11-note.md
Last active August 29, 2015 14:12
FP in Scala chapter notes - Chapter 11: Monads
@okapies
okapies / Ergo-JIS-layout.kbd.json
Last active May 31, 2016 03:43
Ergo-JIS layout
[
{
"name": "Ergo-JIS layout",
"author": "@okapies",
"switchMount": "cherry",
"switchBrand": "gateron",
"switchType": "KS-3-Red",
"pcb": true
},
[
@okapies
okapies / Ergo-JIS-layout.kbd.json
Last active December 25, 2016 06:59
Ergo-JIS layout
[
{
"name": "Ergo-JIS layout",
"author": "@okapies",
"switchMount": "cherry",
"switchBrand": "gateron",
"switchType": "KS-3-Red",
"pcb": true
},
[