Skip to content

Instantly share code, notes, and snippets.

View okapies's full-sized avatar
💭
⌨️

Yuta Okamoto okapies

💭
⌨️
View GitHub Profile
@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 / 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 / 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 / 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
},
[
@okapies
okapies / keymap.c
Created November 3, 2017 16:53
QMK Layer Tap (LT) in Let's Split
#include "lets_split.h"
#include "action_layer.h"
#include "eeconfig.h"
extern keymap_config_t keymap_config;
// Each layer gets a name for readability, which is then used in the keymap matrix below.
// The underscores don't mean anything - you can have a layer called STUFF or any other name.
// Layer names don't all need to be of the same length, obviously, and you can also skip them
// entirely and just use numbers.
@okapies
okapies / QueryOptionalColumn.scala
Created November 18, 2017 11:06
Problem in filtering an optional column in Slick 3.2
// ref. https://gist.github.com/cvogt/9193220
// See the example in http://slick.lightbend.com/doc/3.2.1/gettingstarted.html
// I add an optional `buyer` column to Suppliers:
class Suppliers(tag: Tag) extends Table[(Int, String, String, String, String, String, Option[String])](tag, "SUPPLIERS") {
...
def buyer = column[Option[String]]("BUYER")
...
}