Skip to content

Instantly share code, notes, and snippets.

@huytd
huytd / parse-tree.go
Created May 10, 2021
Parse array to tree in Go
View parse-tree.go
package main
import (
"encoding/json"
"fmt"
)
const NULL = -9999999999
type TreeNode struct {
@huytd
huytd / alacritty-colors.yaml
Last active Mar 26, 2021
Github Dark Theme for Vim
View alacritty-colors.yaml
colors:
primary:
background: '#252729'
foreground: '#e0e2e4'
normal:
black: '#474646'
red: '#f97583'
green: '#85e89d'
yellow: '#ffab70'
@huytd
huytd / sorted_eq.js
Created Mar 9, 2021
Deep compare with sorted keys
View sorted_eq.js
const stringify = o => JSON.stringify(o, Object.keys(o).sort());
const eq = (a, b) => stringify(a) === stringify(b);
const a = {name: "Jack", age: 20};
const b = {age: 20, name: "Jack"};
debug(eq(a, b));
@huytd
huytd / linux-input-tweaking.sh
Created Jan 15, 2021
Some tweak for my input devices on Linux
View linux-input-tweaking.sh
# Swap Alt and Win key
setxkbmap -option altwin:swap_alt_win
# Map CapsLock to Ctrl
setxkbmap -option ctrl:nocaps
# Hold right mouse button to scroll
xinput --set-prop 'pointer:Logitech MX Ergo' 'libinput Scroll Method Enabled' 0, 0, 1
xinput --set-prop 'pointer:Logitech MX Ergo' 'libinput Button Scrolling Button' 3
xinput --set-prop 'pointer:Logitech MX Ergo' 'libinput Middle Emulation Enabled' 1
@huytd
huytd / merge_sort.rs
Created Jan 9, 2021
Rust implementation of Merge Sort algorithm from CLRS book
View merge_sort.rs
fn merge(a: &mut Vec<i32>, p: usize, q: usize, r: usize) {
let al = [&a[p..=q], &[i32::MAX]].concat();
let ar = [&a[q+1..=r], &[i32::MAX]].concat();
let mut i = 0;
let mut j = 0;
for k in p..=r {
if al[i] <= ar[j] {
a[k] = al[i];
i += 1;
} else {
@huytd
huytd / webuild-til.txt
Created Dec 3, 2020
Every #til entries of WeBuild since 2016
View webuild-til.txt
This file has been truncated, but you can view the full file.
[5/5/2016, 1:52:07 AM] [alias Trung.Le, as tle]: #elixirlang <http://kipalog.com/posts/Chen-doi-tuong-vao-mot-List-theo-chieu-nguoc-voi-ham-List-insert_at-va-index-am>
[5/15/2016, 4:51:25 AM] []: #til: Maybe Just Nothing
[5/15/2016, 4:20:09 PM] [alias Trung.Le, as tle]: *TIL* technology does not only solve biz problems but also social and political problems too. Use it wisely for the good
[5/17/2016, 8:25:18 PM] [alias Trung.Le, as tle]: *TIL* JSON Octet là gì - <http://stackoverflow.com/questions/7200554/what-is-a-json-octet-and-why-are-two-required>
[5/17/2016, 8:31:39 PM] []: #til - Bỏ bữa khiến bạn béo bụng, ăn đủ bữa bằng các loại thức ăn có lợi cho sức khỏe là con đường đúng đắn nhất giúp bạn giảm cân thành công. :parrot:
[5/17/2016, 8:34:01 PM] []: #til Muốn hiểu vì sao, hãy tự đi tìm câu trả lời bằng cái mình tự khám phá là chính xác nhất. Chỉ nghe là không đủ.
View fool.js
debug("Thẻ cái bếp nè");
@huytd
huytd / parser-combinator-demo.js
Created Jul 24, 2020
Build a parser combinator step by step
View parser-combinator-demo.js
// Error handling helper
const ok = (found, remain) => ({ found, remain });
const error = (msg) => ({ error: msg });
// Primitive parsers
const digit = (input) => {
const [head, ...rest] = input;
if (!isNaN(+head) && +head >= 0 && +head <= 9) {
return ok(head, rest);
@huytd
huytd / markdown.vim
Created Jun 15, 2020
Checkbox for markdown in Vim
View markdown.vim
syntax match todoCheckbox '\v\s*(-? \[[ x\.!\*]\])' contains=finishedCheckbox,unfinishexCheckbox,flaggedCheckbox,starredCheckbox
syntax match finishedCheckbox '\v(-? \[[ \.]\])' conceal cchar=
syntax match unfinishexCheckbox '\v(-? \[x\])' conceal cchar=
syntax match flaggedCheckbox '\v(-? \[!\])' conceal cchar=
syntax match starredCheckbox '\v(-? \[\*\])' conceal cchar=
hi link todoCheckbox Todo
hi clear Conceal
@huytd
huytd / todo.vim
Created Jun 14, 2020
A Todo list syntax in Vim, with an actual checkbox
View todo.vim
" Vim syntax file
" Language: Todo
" Maintainer: Huy Tran
" Latest Revision: 14 June 2020
if exists("b:current_syntax")
finish
endif
" Custom conceal