Skip to content

Instantly share code, notes, and snippets.

Yuta Okamoto okapies

Block or report user

Report or block okapies

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@okapies
okapies / Id.scala
Created May 27, 2012
How to implement case class manually. (for Scala 2.9.2 final)
View Id.scala
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 Dec 10, 2015
An example code for "Making monads" in "Learn You a Haskell for Great Good!".
View Prob.hs
-- 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 Mar 14, 2020
翻訳: ”命令型のコールバック、関数型のプロミス: Node が逸した最大の機会” by James Coglan
View promises-are-functional.md

命令型のコールバック、関数型のプロミス: 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 Dec 26, 2015
Value type as Sum types
View gist:7182102
// 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 Dec 29, 2015
「プログラマの為の数学勉強会」の資料を ScalaNLP で写経してみたかった http://nineties.github.io/math-seminar/
View part7.scala
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 Jan 30, 2014
scalac is crazy with private[this] in value class
View HogeOps.scala
class HogeOps(val underlying: Any) extends AnyVal {
private
[this] // <-- !!!
def toOption[A](v: => A): Option[A] = ???
}
View MessageLogger.scala
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 Aug 29, 2015
FP in Scala chapter notes - Chapter 11: Monads
View fpinscala-chap11-note.md
View Ergo-JIS-layout.kbd.json
[
{
"name": "Ergo-JIS layout",
"author": "@okapies",
"switchMount": "cherry",
"switchBrand": "gateron",
"switchType": "KS-3-Red",
"pcb": true
},
[
View Ergo-JIS-layout.kbd.json
[
{
"name": "Ergo-JIS layout",
"author": "@okapies",
"switchMount": "cherry",
"switchBrand": "gateron",
"switchType": "KS-3-Red",
"pcb": true
},
[
You can’t perform that action at this time.