Skip to content

Instantly share code, notes, and snippets.

@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 August 17, 2024 01:35
Run tailscale on WDMyCloud

Install Tailscale

  1. Install go if it's not there.
  2. Install tailscale commands.
    go install tailscale.com/cmd/tailscale@v1.46.1
    go install tailscale.com/cmd/tailscaled@v1.46.1
    

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
@lilac
lilac / fstore.md
Last active October 20, 2023 03:45
A database tailored for feature store

Build a persistent, high availability and low latency key-value storage engine for derived data. One of such use cases is feature store. These use cases share some common characteristics, that we could utililze to build a better performing database.

  1. The data is derived, so no need to handle replication or data recovery.
  2. All the writes are through bulk loading, so no concurrency control needed.

In summary, it's like a scalable cache engine.

Features

  • High throughput bulk load
@lilac
lilac / a-guide.md
Last active December 4, 2022 09:13
Embed javascript in JVM

Prerequisites

  1. Install graalvm.
sdk install java 22.3.r19-grl
  1. Change current JVM to graalvm.
sdk use java 22.3.r19-grl
  1. Install Graal js following the guide.