Skip to content

Instantly share code, notes, and snippets.

View z-rui's full-sized avatar
🏠
Working from home

张睿 Zhang Rui z-rui

🏠
Working from home
View GitHub Profile
@z-rui
z-rui / zh_tts.js
Created May 6, 2021 14:41
OsmAnd zh_tts: get rid of "tenths of a mile" and other fixes
// IMPLEMENTED (X) or MISSING ( ) FEATURES, (N/A) if not needed in this language:
//
// (X) Basic navigation prompts: route (re)calculated (with distance and time support), turns, roundabouts, u-turns, straight/follow, arrival
// (X) Announce nearby point names (destination / intermediate / GPX waypoint / favorites / POI)
// (X) Attention prompts: SPEED_CAMERA; SPEED_LIMIT; BORDER_CONTROL; RAILWAY; TRAFFIC_CALMING; TOLL_BOOTH; STOP; PEDESTRIAN; MAXIMUM; TUNNEL
// (X) Other prompts: gps lost, off route, back to route
// (X) Street name and prepositions (onto / on / to) and street destination (toward) support
// (X) Distance unit support (meters / feet / yard)
// (N/A) Special grammar: (please specify which)
// (X) Support announcing highway exits
@z-rui
z-rui / comb.c
Created July 25, 2020 04:35
Combination encoder / decoder
/**** combination (n choose k) encoder / decoder ****
* *
* a k-combination {c1,...,ck} of {0,1,...,n-1} can *
* be encoded as C(c1,1) + C(c2,2) + ... + C(ck,k). *
* *
****************************************************/
#include <stdio.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
static void
hanoi(unsigned char n)
{
void *s[32];
char p[3] = "ABC", t;
if (n >= 32) n = 31;
@z-rui
z-rui / parsegen.tex
Created March 15, 2020 01:10
Parse Generator
\input luaotfload.sty
\input luatypezh
\input zr/verb
\font\tenmib=cmmib10 \font\sevenmib=cmmib7 \font\fivemib=cmmib5
\baselineskip=14pt \everydisplay{\baselineskip=12pt\relax}
\verbatimindent=2em
% % %
@z-rui
z-rui / kmp.py
Created October 29, 2019 05:47
Knuth–Morris–Pratt
#!/usr/bin/python3
def make_pi(p):
n = len(p)
pi = [0] * n
i = 0
for j in range(1, n):
while i > 0 and p[i] != p[j]:
i = pi[i-1]
if p[i] == p[j]:
@z-rui
z-rui / verb.tex
Created July 21, 2019 04:50
TeX verbatim typesetting
% Verbatim typesetting
\catcode`@=11
\def\uncatcodespecials{\begingroup
\def\do##1{\catcode`\noexpand##1=12 }%
\edef\next{\endgroup\dospecials}\next}
\let\verbfont=\tentt
\def\nohyphenation{\hyphenchar\font\m@ne}
@z-rui
z-rui / eexp.c
Created July 14, 2019 06:39
Expand "2[ab3[c]]" into "abcccabccc"
char*f(char*s){char*t;int n;for(t=s;*t;t++)if(*t==']')break;
else if(*t>>4==3){for(n=*(s=t++)-48;*t>>4==3;n=n*10+(*t++-48));
if(*t=='[')for(s=t+1;n--;t=f(s));else for(t--;s<=t;putchar(*s++));}
else putchar(*t);return t;}int main(int c,char**v){f(v[1]);}
@z-rui
z-rui / makepdf.sh
Created July 14, 2019 04:16
Make a 16-page booklet
#!/bin/bash
size="3300x2550" # 11" x 8"
# size="3508x2480" # 297mm x 210mm
cvtopts="+append -adaptive-resize $size -gravity center -extent $size -set density 300 -unsharp 0x5+0.3+0"
if [[ ! -z $1 ]]; then
N=$1
elif [[ $PWD =~ FILE([0-9]+) ]]; then
@z-rui
z-rui / .tmux.conf
Created November 17, 2018 18:35
Tmux configuration
unbind C-b
bind-key C-a send-prefix
set -g prefix C-a
set -g mouse on
set -g set-titles on
set -g status off
set -g escape-time 100
setw -g mode-keys vi
@z-rui
z-rui / hash.c
Created November 2, 2018 19:59
Open addressing, linear probing hash table
#include "hash.h"
#include <assert.h>
void **hash_find(void **base, size_t n, void *key,
size_t hash, int (*equal)(const void *, const void *))
{
void **p, **q, **end;
p = q = base + hash % n;
end = base + n;