Skip to content

Instantly share code, notes, and snippets.

@t0350
t0350 / jssqlite
Created September 27, 2025 12:47
read sqlite file in javascript
const ENCODING_NAME = {
1:"SQLITE_UTF8",
2:"SQLITE_UTF16LE",
3:"SQLITE_UTF16BE"
}
const PAGE_TYPE = {
2:"INTERIOR_INDEX",
5:"INTERIOR_TABLE",
@t0350
t0350 / t.md
Last active August 22, 2020 06:38
tickless kernel

time

  • real time and process time
    • real time
      Real time is defined as time measured from some fixed point
    • process time
      Process time is defined as the amount of CPU time used by a process(user/systime)
      time(2), getrusage(2), clock(3)
  • hardware clock
    rtc, software clock based on rtc(by counting timer interrupt, once per jiffy)
  • software clock, HZ and jiffies
@t0350
t0350 / killtcp.md
Last active July 3, 2020 15:47
tcp refuses to die
@t0350
t0350 / partition.md
Last active March 20, 2020 07:16
A discipline of programming - chapter 14

想记录一下有关划分区间的一个有趣问题,来源是 dijkstra 老爷子的 A discipline of programming。

开始之前我们先来看看快排的区间划分。快排的区间划分就是取分点,分点将左右划分为两个区间。比如分点为 pivot,那么一般的,左区间满足小于等于 pivot,右区间满足大于等于 pivot。

比如,考虑区间 [lo, hi],我们对它进行划分。

// lo < hi
func partition(A []int, lo, hi int) int {
@t0350
t0350 / t.c
Last active March 4, 2020 05:08
one by one
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
static int ownership = 1;
static pthread_mutex_t lock;
static void *
odd(void *p) {
for (;;) {
@t0350
t0350 / s.md
Last active March 10, 2018 04:51
select/poll/epoll/kqueue
@t0350
t0350 / task.lua
Last active November 28, 2017 03:01
channel and task scheduling in lua
-- cooperative task scheduler based on lua coroutine
local running_tasklist = {}
local iter_index = 0
local function create_task(f, ...)
local co = coroutine.create(f)
table.insert(running_tasklist, {co = co, args = {...}, start = false})
return co
end
@t0350
t0350 / bound_prime.go
Last active November 22, 2017 12:07
csp prime number generator
package main
import (
"os"
"fmt"
"strconv"
)
func sieve(ch chan int, stop chan bool) {
nextc := make(chan int)
modulus p = 23, base g = 5
secret a = 6, b = 15
public A = g^a mod p = 8, B = g^b mod p = 19
share secret:
s = B^a mod p = g^(ab) mod p
= A^b mod p = g^(ba) mod p = 2