Skip to content

Instantly share code, notes, and snippets.

@changlinli
changlinli / decode_mit_blog_binary.py
Created January 25, 2014 06:30
A short and dirty Python script to decode MIT's blog post written in binary.
def group_by_n(line, n):
if line == "":
return []
elif line[0] == " ":
return [" "] + group_by_n(line[1:], n)
else:
return [line[:n]] + group_by_n(line[n:], n)
with open("post.txt") as fp:
final_string = ""
@changlinli
changlinli / hello.txt
Created February 1, 2018 02:27
Demonstrating issue for sbt-doctest
Hello
@changlinli
changlinli / Example.scala
Created March 19, 2018 04:45
Using path dependent types to ensure invariants in Scala
object StandardUnit {
type PersonId = Int
final class Person(id: PersonId, name: String)
object Person {
def lookupName(id: PersonId): Option[String] = ???
def lookupBlacklistStatus(id: PersonId): Option[Unit] = ???
@changlinli
changlinli / exampleReaderTFS2.scala
Created June 24, 2018 02:23
Example of ReaderT with fs2
object Example {
import fs2._
import fs2.async.mutable._
import cats._
import cats.data._
import cats.implicits._
/**
* This exists only because cats-effect keeps the trait expressing the
* Concurrent instance of Kleisli package private, otherwise we could just
@changlinli
changlinli / STMExample.scala
Created July 2, 2018 13:18
Example of different approaches to wrapping STM with Cats
package com.changlinli
import cats.effect.{IO, Sync}
import cats.free.Free
import cats.implicits._
import cats.~>
import scala.language.higherKinds
/*
@changlinli
changlinli / BasicLisp.scala
Last active December 3, 2018 10:23
A very bare-bones stand-alone implementation of a Lisp-like parser
/**
* This is a bare-bones implementation of some parser combinators to implement
* a simple Lisp-like parser.
*
* Note that I call it Lisp-like because I haven't yet defined any macro special
* forms in the AST.
*
* I also use unrestricted recursion here which will eventually blow the stack
* for sufficiently nested s-expressions. I could use trampolines instead to
* trade stack for heap and avoid a stack overflow.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="generator" content="pandoc"> <meta name="author" content="Changlin Li ([email protected])"> <title>Emily Dickinson: Slant Rhyme and Sound Change</title> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui"> <style> html, body, .reveal div, .reveal span, .reveal applet, .reveal object, .reveal iframe, .reveal h1, .reveal h2, .reveal h3, .reveal h4, .reveal h5, .reveal h6, .reveal p, .reveal blockquote, .reveal pre, .reveal a, .reveal abbr, .reveal acronym, .reveal address, .reveal big, .reveal cite, .reveal code, .reveal del, .reveal dfn, .reveal em, .reveal img, .reveal ins, .reveal kbd, .reveal q, .reveal s, .reveal samp, .reveal small, .reveal strike, .reveal strong, .reveal sub, .reveal sup, .reveal tt, .reveal var, .reveal b, .reveal u, .re
@changlinli
changlinli / keybase.md
Created March 31, 2020 00:37
Keybase proof

Keybase proof

I hereby claim:

  • I am changlinli on github.
  • I am changlin (https://keybase.io/changlin) on keybase.
  • I have a public key ASB9KiJFew02npmIG7PEjmYgrjs6sw8VjSsssVrhTL2QBQo

To claim this, I am signing this object: