Skip to content

Instantly share code, notes, and snippets.

@lilac
lilac / patterns.md
Last active February 26, 2025 09:12
Query patterns of Feature Families
Query Pattern Feature Type Comment
Point lookup (query) Entity Feature Family 1 entity key → 1 row
Batch query by a context Context Feature Family N context keys → N rows
Recall candidates by a context Candidate Feature Family 1 entity key → N rows
@lilac
lilac / A-Read-Me.md
Created November 27, 2024 02:55
A Scala script that reads a hex string from the system clipboard and compute the length of it

Intro

This is a Scala script that reads a hex string from the system clipboard and compute the length of it.

Use case

It's mainly a utility for blob. Our data is stored in Cassandra (or ScyllaDB) as blob, but sometimes we need to analyze the data.

Usage

  1. Install scala-cli in your system.
  2. Copy the hex string to your clipboard.
  3. Run the script via scala-cli hex-length.scala.
@lilac
lilac / deployment.yaml
Created May 8, 2024 09:37
Deploy Code Server to k8s
apiVersion: apps/v1
kind: Deployment
metadata:
name: coder
spec:
replicas: 1
strategy:
type: Recreate
template:
spec:
@lilac
lilac / blog.md
Created October 25, 2023 16:14
Building a Minimal HTTP Server with Virtual Threads in Java

Building a Minimal HTTP Server with Virtual Threads in Java

In the latest release of JDK 21, virtual threads have become a stable feature, revolutionizing the way we write concurrent programs in Java. With virtual threads, it is now easier than ever to create highly performant and scalable applications. In this blog post, we will explore how to build a minimal yet fully functional HTTP server from scratch using virtual threads.

Introduction to Virtual Threads

Virtual threads, also known as fibers, are lightweight threads that can be scheduled cooperatively by the JVM. Unlike traditional threads, which are managed by the operating system, virtual threads are managed at the application level, resulting in reduced overhead and improved scalability. By leveraging virtual threads, we can achieve higher concurrency without the need for complex thread management.

Setting Up the Project

@lilac
lilac / Makefile
Created October 17, 2023 01:34
Wasm with threads
.phony: run
run: thread.wasm
wasmtime run --wasm-features threads --wasi-modules experimental-wasi-threads ./thread.wasm
thread.wasm: thread.wat
wat2wasm --debug-names --enable-threads thread.wat
@lilac
lilac / HelloWorld.java
Last active October 8, 2023 02:53
Native Image of Java Hello World
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
@lilac
lilac / A ReadMe.md
Last active December 30, 2024 20:13
Run tailscale on WDMyCloud

Install Tailscale

  1. Install go if it's not there.
  2. Install tailscale commands.
    go install tailscale.com/cmd/[email protected]
    go install tailscale.com/cmd/[email protected]
    

Install service

Since this linux is an old version, it still use sysv scripts for service management. To run tailscaled as a daemon (service), follow the procedure below.

@lilac
lilac / dag.star
Last active March 30, 2023 06:19
DAG for home page recommendation
# builtin functions
# graph is a builtin module exposed by the host environment
# graph.nodes = {}
# graph.edges = []
def node(name, operation, conf={}, predicate=None):
"""
:rtype: str the node name is returned
@lilac
lilac / demo.scala
Last active March 16, 2023 14:14
Starlark interoperation to JVM
package example
import com.google.common.collect.{ImmutableCollection, ImmutableList, ImmutableMap}
import net.starlark.java.annot.{Param, StarlarkBuiltin, StarlarkMethod}
import net.starlark.java.eval.{Dict, EvalException, Module, Mutability, Starlark, StarlarkFunction, StarlarkInt, StarlarkList, StarlarkSemantics, StarlarkThread, Structure, Tuple}
import net.starlark.java.syntax.{FileOptions, ParserInput}
import scala.collection.mutable.ListBuffer
object StarlarkDemo extends App {
@lilac
lilac / ReadMe.md
Created March 6, 2023 04:31
A js interpreter in WebAssembly (wasm)

Playground

  • Install wazero with the following commmand.

    go get github.com/tetratelabs/wazero@latest
  • Download the wasm file of a Javascript interpreter. For simplicity, the following ways are listed.

    • If you have wapm installed, you could download one with