Skip to content

Instantly share code, notes, and snippets.

Avatar

JJS 0xYUANTI

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am 0xyuanti on github.
  • I am yuanti (https://keybase.io/yuanti) on keybase.
  • I have a public key ASAVjKmujfL5xp2V7HHVm9HVxufwaZkwQp7W34Mu4c6mnwo

To claim this, I am signing this object:

View foldIncremental.scala
// this seems like a useful FS2 Stream function, is it already built in?
// Folds a function into a stream and gives you a stream of the intermediate
// accumulator values, i.e.:
// > val ones = Stream.iterate(1)(x => x)
// > ones.foldIncremental(0)(_ + _) take 3 toList
// ==> List[Int] = List(1, 2, 3)
implicit class StreamOps[F[_], O](private val self: Stream[F, O]) {
def foldIncremental[O2](z: O2)(f: (O2, O) => O2): Stream[F, O2] =
self.mapAccumulate(z) {
View polling_producer_consumer_fs2.scala
import fs2.interop.scalaz._
import fs2.{Scheduler, Strategy, time}
import scala.concurrent.duration._
import scalaz.concurrent.{Task => ZTask}
// porting some code from scalaz.concurrent.chan to fs2...
// we need to call a few external rest apis every N seconds and process the results.
object App {
def main(args: Array[String]): Unit = {
View gist:65e76db7bbebb5db190ae14d6418dcb2
object icm {
// Types
type Player = Int
type Chips = Double
type Stacks = Map[Player, Chips]
type Rank = Int
type Money = Double
View gist:9bc9d83ff964d79b4d461a10c8b8f5f8
adding
type intLeaf = | Leaf int;
results in
jakob@crunchy:/usr/home/jakob/git/botcloud/telegram-re$ rebuild -pkg cohttp.lwt wtf.native
+ /usr/local/bin/ocamldep.opt -modules -pp refmt -impl wtf.re | tee wtf.re.depends wtf.ml.depends
Fatal error: exception Not_found
File "wtf.re", line 1:
View wtf.re
/* example from cohttp readme, works with rebuild -pkg cohttp.lwt wtf.native */
open Lwt;
open Cohttp;
open Cohttp_lwt_unix;
let coroutine =
Client.get (Uri.of_string "http://www.reddit.com/") >>= fun (resp, body) => {
let code = resp |> Response.status |> Code.code_of_status;
Printf.printf "Response code: %d\n" code;
View gist:97714b76cf2fb718f443
// build.sbt
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
"org.scalaz" %% "scalaz-core" % "7.1.1",
"org.scalaz" %% "scalaz-effect" % "7.1.1",
"org.scalaz" %% "scalaz-concurrent" % "7.1.1",
"org.tpolecat" %% "doobie-core" % "0.2.1",
"org.tpolecat" %% "doobie-contrib-postgresql" % "0.2.1",
View gist:493f83a025d47d3c8f50
### Keybase proof
I hereby claim:
* I am cannedprimates on github.
* I am cannedprimates (https://keybase.io/cannedprimates) on keybase.
* I have a public key whose fingerprint is 734D ECBA C500 533A 95AA 32B7 333D C302 DD8D 2180
To claim this, I am signing this object:
View gist:69c50ace9a5d888c9a48
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.4 (OpenJDK 64-Bit Server VM, Java 1.6.0_32).
Type in expressions to have them evaluated.
Type :help for more information.
scala> def f = 1
def f = 1
f: Int
@0xYUANTI
0xYUANTI / gist:4176609
Created Nov 30, 2012
The reftrick: assembly
View gist:4176609
{function, recv, 1, 9}.
{label,8}.
{line,[{location,"reftrick.erl",33}]}.
{func_info,{atom,reftrick},{atom,recv},1}.
{label,9}.
{test,is_eq_exact,{f,10},[{x,0},{integer,0}]}.
{move,{atom,ok},{x,0}}.
return.
{label,10}.
{allocate_zero,1,1}.