Skip to content

Instantly share code, notes, and snippets.

@Gab-km
Gab-km / whyILeftHeroku.rst
Last active December 30, 2022 10:56
何故私は Heroku から離れたか、および新しい AWS セットアップのメモ

何故私は Heroku から離れたか、および新しい AWS セットアップのメモ

原著者:Adrian Holovaty
原文:Why I left Heroku, and notes on my new AWS setup

金曜日、私は Heroku から Amazon Web Services(AWS) を直接使うように Soundslice を移行しました。私はこの変更ができてとても、そうとても嬉しくて、私がどうやったかということと、もし皆さんが同じような立場だったら何故それを検討すべきかということについて広く伝えたいと思います。

trait Magma[A] {
def append(x: A, y: A): A
}
object Magma {
implicit def Monoid[A](implicit m: Monoid[A]) = new Magma[A] {
def append(x: A, y: A) = m.append(x, y)
}
}
anonymous
anonymous / gist:5685201
Created May 31, 2013 14:05
バイナリ法によるフィボナッチ数の計算。
import Data.Semigroup
import Numeric.Natural.Internal
-- 2x2 integer matrix [[a,b],[c,d]]
data Mat2x2 a = Mat2x2 a a a a deriving (Show,Eq)
-- multiply matrix [[a,b],[c,d]] . [[p,q],[r,s]] = [[a*p+b*r, a*q+b*s],[c*p+d*r, c*q+d*s]]
multiply_mat2x2 :: Num a => Mat2x2 a -> Mat2x2 a -> Mat2x2 a
multiply_mat2x2 (Mat2x2 a b c d) (Mat2x2 p q r s) = Mat2x2 (a*p+b*r) (a*q+b*s) (c*p+d*r) (c*q+d*s)

collection

each(list, iterator, [context]forEachforeach
underscoreScala
val m1 = Map(1 -> 2, 2 -> 5, 3 -> 1)
val m2 = Map(2 -> 4, 3 -> 3, 4 -> 3)
def toMultiMap[A, B](m1: Map[A, B], m2: Map[A, B]): Map[A, Set[B]] =
(m1.toSeq ++ m2.toSeq).groupBy(_._1).mapValues(_.map(_._2).toSet)
/*
scala> toMultiMap(m1, m2).mapValues(_.max)
res0: scala.collection.immutable.Map[Int,Int] = Map(2 -> 5, 4 -> 3, 1 -> 2, 3 -> 3)
*/
import scalaz._, Scalaz._
object MaxValue extends App {
val a = Map(1 -> 10, 2 -> 5)
val b = Map(2 -> 10, 3 -> 7)
val c = a.mapValues(Tags.MaxVal) |+| b.mapValues(Tags.MaxVal)
(c: Map[Int, Int]) assert_=== Map(1 -> 10, 2 -> 10, 3 -> 7)
}
@puffnfresh
puffnfresh / index.js
Created July 8, 2013 18:19
made with requirebin.com
var State = require('fantasy-states'),
Tuple2 = require('fantasy-tuples').Tuple2,
// Tuple2 Number Number
initial = Tuple2(0, 1),
// State (Tuple2 Number Number) Number -> State (Tuple2 Number Number) Number
next = discard(
State.modify(function(t) {
return Tuple2(t._1 + 1, (t._1 + 1) * t._2);
@xuwei-k
xuwei-k / A.scala
Last active December 19, 2015 12:29
compiler crash "class A(private[this] var a: => Int)"
class A(private[this] var a: => Int){
lazy val b = a
}
@puffnfresh
puffnfresh / index.js
Last active December 19, 2015 13:39
requirebin sketch
var daggy = require('daggy'),
State = require('fantasy-states'),
Cofree = require('fantasy-cofrees'),
AST = daggy.taggedSum({
Add: ['l', 'r'],
Sub: ['l', 'r'],
Num: ['n']
}),
incNode = State.get.chain(function(n) {
return discard(
@xeno-by
xeno-by / gist:5967900
Created July 10, 2013 16:38
Macro-powered structural types
import scala.annotation.StaticAnnotation
import scala.reflect.macros.Macro
import language.experimental.macros
class body(tree: Any) extends StaticAnnotation
trait Macros extends Macro {
import c.universe._
def selFieldImpl = {