Skip to content

Instantly share code, notes, and snippets.

View lshoo's full-sized avatar

lshoo lshoo

View GitHub Profile
object SemiGroupApp {
trait SemiGroup[T] {
def append(a: T, b: T): T
}
/*object IntSemiGroup extends SemiGroup[Int] {
def append(a: Int, b: Int) = a + b
}*/
@lshoo
lshoo / gist:4718c8e7c7cce1ba10ff
Created April 12, 2015 09:09
DateTimeUtls.scala
package utils
import org.joda.time.DateTime
import org.joda.time.format.{DateTimeFormatterBuilder, DateTimeFormat, DateTimeFormatter}
import scala.concurrent.stm._
/**
* Created by liaoshifu on 2015/4/11
*/
@lshoo
lshoo / scala
Created June 17, 2016 08:01
cats Free monad tutorial
sealed trait KVStoreA[A]
case class Put[A](key: String, value: A) extends KVStoreA[Unit]
case class Get[A](key: String) extends KVStoreA[A]
case class Delete(key: String) extends KVStoreA[Unit]
import cats.free.Free
type KVStore[A] = Free[KVStoreA, A]
import cats.free.Free.liftF
@lshoo
lshoo / updateLiveStats.scala
Last active November 2, 2016 07:20
updateLiveStats
def updateLiveStats(
time: Time,
liveId: String,
event: Option[Iterable[LiveEvent]],
state: State[LiveStatistics]
): Option[LiveStatistics] = {
event.flatMap { es =>
val (creates, notCreates) = es.partition(_.isCreate)
@lshoo
lshoo / scala
Created September 13, 2017 10:07
Shapeless example
import shapeless.{:+:, ::, CNil, Coproduct, Generic, HList, HNil, Inl, Inr, Lazy}
/**
* http://www.cakesolutions.net/teamblogs/solving-problems-in-a-generic-way-using-shapeless
*/
trait Depth[T] {
def depth(t: T): Int
}
object Depth {
@lshoo
lshoo / rust
Created August 22, 2019 07:44
Rust merge
use std::borrow::BorrowMut;
use std::ptr::replace;
pub fn do_sth() {
test_merge_sort();
}
fn merge_sort(to_sort: &mut Vec<i32>, all: &mut Vec<i32>) {
let len = to_sort.len();