Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
⌨️

Yuta Okamoto okapies

💭
⌨️
View GitHub Profile
@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
@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 / 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]) =
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
},
[
@okapies
okapies / keymap.c
Created Nov 3, 2017
QMK Layer Tap (LT) in Let's Split
View keymap.c
#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 Nov 18, 2017
Problem in filtering an optional column in Slick 3.2
View QueryOptionalColumn.scala
// 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")
...
}