Skip to content

Instantly share code, notes, and snippets.

View lshoo's full-sized avatar

lshoo lshoo

View GitHub Profile
@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();
@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 / 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 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 / 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
*/
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:9785645
Created March 26, 2014 15:13
Slick2 generic dao
package slicks.docs.dao
import scala.slick.driver.PostgresDriver.simple._
import scala.slick.driver._
trait Profile {
val profile: JdbcProfile
}
@lshoo
lshoo / PromiseFutures.scala
Last active December 21, 2015 01:39
Future的onComplete后面的内容输出如何显示? 原因主线程结束时,future线程还没执行完 增加Thread.sleep(5000)
package neophyte.guide
import concurrent._
import ExecutionContext.Implicits.global
import neophyte.guide.PromiseFutures.TaxCut
import scala.util.{Failure, Success}
object PromiseFutures {
case class TaxCut(reduction: Int)
@lshoo
lshoo / effective_akka2.java
Created March 12, 2013 14:01
经过内部actor后为什么收到反馈信息?
package programmingscala.Chapter09.jaxmagazine09
import concurrent.{Promise, ExecutionContext}
import scala.concurrent.duration._
import akka.actor._
import akka.pattern.ask
import akka.util.Timeout
import java.util.concurrent.TimeoutException
@lshoo
lshoo / effectiv_akka.scala
Last active December 14, 2015 20:08
akka中的内部actor如何调用?
package programmingscala.Chapter09.jaxmagazine09
import concurrent.{Promise, ExecutionContext}
import scala.concurrent.duration._
import akka.actor._
import akka.pattern.ask
import akka.util.Timeout
import java.util.concurrent.TimeoutException