Skip to content

Instantly share code, notes, and snippets.

⛑️

Huy huytd

⛑️
View GitHub Profile
@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
View vscode-vim.json
"vim.incsearch": true,
"vim.useSystemClipboard": true,
"vim.useCtrlKeys": true,
"vim.hlsearch": true,
"vim.insertModeKeyBindings": [
{
"before": [
"j",
"k"
],
View customized-lichess.css
.crosstable { display: none; }
.analyse__moves::before {
content: " white black ";
width: 100%;
display: block;
text-align: center;
white-space: pre-wrap;
padding: 5px;
font-weight: bold;
View bitboard-demo.js
// Run this code at: https://algorithm-pad.now.sh/
const matrix = (n) => [
[ (n >> 8) & 1, (n >> 7) & 1, (n >> 6) & 1 ],
[ (n >> 5) & 1, (n >> 4) & 1, (n >> 3) & 1 ],
[ (n >> 2) & 1, (n >> 1) & 1, (n >> 0) & 1 ]
];
let board = 0b000100010;
const pawn = 0b000100000;
View edit-distance.cpp
#include <iostream>
#include <algorithm>
using namespace std;
int min3(int a, int b, int c) {
return min(a, min(b, c));
}
int main() {
string a, b;
View 8-queen.js
// Run online at:
// https://algorithm-pad.now.sh/?gist=https://gist.githubusercontent.com/huytd/d9c162e8d6392c39595395521896c028/raw/343c11a97c8edc5538ae88a3144e754be1162a74/8-queen.js
board = [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
View word-delimiter-split.js
const solve = (s, d) => {
// Write your code here
let word = "";
let words = [];
let del = [];
let i = 0;
while (i < s.length) {
if (d.indexOf(s[i]) === -1) {
word += s[i];
i++;
View for-in.js
const array = [5,3,3,6,2,3,4,67,7,2,2];
for (let i in array) {
debug({ i: i, value: array[i] });
}
You can’t perform that action at this time.