Skip to content

Instantly share code, notes, and snippets.

// ==UserScript==
// @name PageUp/PageDown buttons
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add semi-transparent PageUp/PageDown buttons to the right of every page. Useful when reading web pages on e-ink screens.
// @author xiaq
// @match *://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant none
// ==/UserScript==

Code block using the elvish tag:

echo foo
each {|x| echo $x} [foo bar]

Code block using the elvish-transcript tag:

@xiaq
xiaq / 143.go
Created December 22, 2021 22:18
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func reorderList(p *ListNode) {
q := findMid(p)
q = reverse(q)
class Solution {
public int minRefuelStops(int target, int startFuel, int[][] stations) {
int p = 0; // position
int i = 0; // index of first unreachable station
var q = new PriorityQueue<Integer>(stations.length/2 + 1, Collections.reverseOrder());
q.add(startFuel);
int refills = -1; // we count initial fuel as a filling too, so initialize to -1
while (p < target) {
if (q.isEmpty()) {
@xiaq
xiaq / 943.java
Last active May 23, 2021 18:38
LeetCode 943 "Find the Shortest Superstring", Java version
class Solution {
String[] words;
int n;
int[][] prefix; // prefix[i][j] is the minimal k such that words[i][k:] is a prefix of words[j]
int[][] answer; // answer[first][ban]
public String shortestSuperstring(String[] words) {
init(words);
int first = -1;
@xiaq
xiaq / 943.go
Created May 23, 2021 17:02
LeetCode 943 "Find the Shortest Superstring"
func shortestSuperstring(words []string) string {
n := uint16(len(words))
lt := makeLenTable(words)
s := searcher{uint16(n), lt, make([]uint8, n<<n)}
min := uint8(255)
first := uint16(0)
for i := uint16(0); i < n; i++ {
val := s.search(key(i << n))
if min > val {
~/on/elvish> # Using homebrew's Go
~/on/elvish> go build -trimpath -ldflags '-X src.elv.sh/pkg/buildinfo.Reproducible=true -X src.elv.sh/pkg/buildinfo.VersionSuffix=-dev.test' -o elvish-1 ./cmd/elvish
~/on/elvish> go build -trimpath -ldflags '-X src.elv.sh/pkg/buildinfo.VersionSuffix=-dev.test -X src.elv.sh/pkg/buildinfo.Reproducible=true' -o elvish-2 ./cmd/elvish
~/on/elvish> # Using official distribution in /usr/local/go
~/on/elvish> set @paths = /usr/local/go/bin $@paths
~/on/elvish> go build -trimpath -ldflags '-X src.elv.sh/pkg/buildinfo.Reproducible=true -X src.elv.sh/pkg/buildinfo.VersionSuffix=-dev.test' -o elvish-3 ./cmd/elvish
~/on/elvish> go build -trimpath -ldflags '-X src.elv.sh/pkg/buildinfo.VersionSuffix=-dev.test -X src.elv.sh/pkg/buildinfo.Reproducible=true' -o elvish-4 ./cmd/elvish
~/on/elvish> gsha256sum elvish-* # four different binaries!
d918be4495aeb4568b74605995f95bc9eecf053a18b9f3767d774b243982d3ec elvish-1
65cb50af54e1b72c6a415d96b2b20737bebb11f757d3c41e4194b5bd22f9f92f elvish-2
rx = 0
tx = 0
ip -j -s link | from-json | all (one) | each [iface]{
if (eq $iface[ifname] lo) {
continue
}
rx = (+ $rx $iface[stats64][rx][bytes])
tx = (+ $tx $iface[stats64][tx][bytes])
}
put $rx $tx
@xiaq
xiaq / heredocs.sh
Last active September 1, 2020 16:10
cat > a.go <<EOF
package main
import (
"fmt"
"io"
"os"
)
func main() {
fn dwm-date { date "+DATE: %d/%m/%y TIME: %H:%M:%S" }
fn dwm-battery { acpi -b | cut -d ',' -f 2 | cut -d ' ' -f 2 }
modules = [
$dwm-date~
$dwm-battery~
]
while $true {
for m $modules { $m } |