Skip to content

Instantly share code, notes, and snippets.

View luochen1990's full-sized avatar
🏠
Working from home

Luo Chen luochen1990

🏠
Working from home
View GitHub Profile
@luochen1990
luochen1990 / ast-pattern-via-free-monad.hs
Created November 5, 2020 05:39
a demo about Expressing an AST pattern via Free Monad
{-# language TemplateHaskell #-}
{-# language TypeFamilies #-}
{-# language StandaloneDeriving, DeriveFunctor, DeriveFoldable, DeriveTraversable, DeriveGeneric, DeriveDataTypeable, DeriveAnyClass, FlexibleContexts #-}
import Control.Monad.Free
import Data.Functor.Foldable
import Data.Functor.Foldable.TH
import Data.Functor.Classes
import Text.Show.Deriving
import Data.Foldable
@luochen1990
luochen1990 / bisect.rs
Last active October 14, 2020 09:17
Binary Search in Rust
/*
Assuming:
1. l <= r
2. forall u, v, u < v -> f(u) <= f(v)
So, curve of f should looks like
______
f: ___|
So we know:
@luochen1990
luochen1990 / JsonHelper.java
Created June 17, 2020 05:00
Gson custom TypeAdapter (including serialization and deserialization) for Generic Types like Optional/List
package tools;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import io.vavr.collection.List;
import io.vavr.control.Option;
import java.io.IOException;
@luochen1990
luochen1990 / xeyes.strace
Created May 27, 2020 03:04
for WSL bug report
899 execve("/usr/bin/xeyes", ["xeyes"], 0x7ffc75d322e8 /* 29 vars */) = 0
899 brk(NULL) = 0x5630ea012000
899 arch_prctl(0x3001 /* ARCH_??? */, 0x7ffd2662e3f0) = -1 EINVAL (Invalid argument)
899 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
899 openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
899 fstat(3, {st_mode=S_IFREG|0644, st_size=53133, ...}) = 0
899 mmap(NULL, 53133, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f8626f6c000
899 close(3) = 0
899 openat(AT_FDCWD, "/usr/lib/x86_64-linux-gnu/libXext.so.6", O_RDONLY|O_CLOEXEC) = 3
899 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340E\0\0\0\0\0\0"..., 832) = 832
@luochen1990
luochen1990 / my.demo.project.test.JsonTest.java
Created May 19, 2020 13:04
Gson custom Serialization and Deserialization for Option
package my.demo.project.test;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import io.vavr.control.Option;
import org.junit.Test;
import my.demo.project.tools.JsonHelper;
public class JsonTest {
@luochen1990
luochen1990 / Utils.java
Created May 11, 2020 13:17
Let in Java
public final class Utils {
public static <T> T let(Supplier<T> supplier){
return supplier.get();
}
}
@luochen1990
luochen1990 / math24.hs
Created April 6, 2020 13:08
solution of the math24 game in Haskell, also see https://www.zhihu.com/question/307729091
import Data.List
import Data.Maybe
import Data.Ratio
import Data.Char
import Control.Monad (liftM2, join, forM_)
import Control.Parallel.Strategies (parMap, rseq)
import Control.Arrow ((&&&))
import GHC.Exts (groupWith, sortWith)
type Number = Rational
type VarID = Int
@luochen1990
luochen1990 / miio-example.js
Created December 5, 2019 08:14
XiaoMi Mi Home, miio usage demo
const miio = require('miio')
const color = require("cli-color")
miio.device({
address: '192.168.0.120',
token: '0b806f990d9ca4ff7be7f07f0168dcae'
})
.then(device => {
console.info(color.green('> Connected to:'), device)
//console.log('Device Props: ', Object.getOwnPropertyNames(device))
@luochen1990
luochen1990 / profiles.json
Last active June 4, 2024 10:45
My Windows Terminal Profile (Configuration/Preference)
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions":
[
{
"command": "unbound",
"keys": "ctrl+shift+d"
},
{
@luochen1990
luochen1990 / bisect.js
Last active October 14, 2020 09:21
Binary Search in JavaScript
/*
Assuming:
1. l <= r
2. forall u, v, u < v -> f(u) <= f(v)
So, curve of f should looks like
______
f: ___|
So we know: