Skip to content

Instantly share code, notes, and snippets.

View xysun's full-sized avatar

Xiayun Sun xysun

  • London
View GitHub Profile
package org.jsun.autodiff
//import $ivy.`org.scalameta::scalameta:4.1.0`
import scala.math.{sin, cos}
import scala.meta._
object Main extends App {
// Let's say we want to differentiate this function:
def tdigest() = {
val totalData = ListBuffer[Long]()
var occ = 0
for (i <- 0 to 20000){
val seed = Random.nextInt(1000)
if (seed == 0){
occ += 1
totalData.append(100L)
}
else{
@xysun
xysun / implicit.scala
Created April 14, 2017 02:23
implicit class creates new object all the time
class A
object ExtendedA {
implicit class Aplus(a:A) extends A{
val uuid = UUID.randomUUID()
println(s"uuid is: $uuid")
private var b = 0
def setB(i:Int) = b = i
def getB = b
}
syntax on
set tabstop=4
set autoindent
set nu
set expandtab
set shiftwidth=4
let g:tagbar_ctags_bin='/usr/local/bin/ctags'
let g:tagbar_width=40
noremap <silent> tb :TagbarOpen fj <CR>
'''
Manage "My Clippings.txt" from Kindle, split notes into separate files for each book, with custom file name
usage:
python3 kindle.py <option> <clipping> <name_mapping_file> <dir>
<option>:
"list": step1; list all books in the clipping file, ask for name of the notes file, store the book name <--> notes file name mapping in <name_mapping_file>
"notes": step2; create notes for each book
@xysun
xysun / sort.ml
Created July 18, 2013 15:30
Sorting and selecting
(* sorting and selecting, benchmark in the end *)
module Sort : sig
val generate : int -> int -> int array
val merge_sort : 'a array -> 'a array
val quick_sort : 'a array -> unit
val rselect : 'a array -> int -> 'a
val dselect : 'a array -> int -> 'a
@xysun
xysun / filter.ml
Last active December 19, 2015 12:59
Different implementations of Array.filter + benchmark
(* benchmarking different implementations for Array.filter *)
(* to build:
include _tags file: true:package(core, core_bench), thread
ocamlbuild -use-ocamlfind filter.byte
*)
(* 1. use Array.append *)
module Filter =
struct
@xysun
xysun / matrix.ml
Created July 8, 2013 16:06
OCaml module for matrix calculation.
(* matrix module from Algo course *)
(* Author: Xiayun Sun *)
(* Email: xiayun.sun@gmail.com *)
(* Date: 8-JUL-2013 *)
(* all floating number matrix *)
module Matrix :
sig
val slice : 'a array array -> int * int -> int * int -> 'a array array
val merge_matrix :