Skip to content

Instantly share code, notes, and snippets.

View sntran's full-sized avatar

Sơn Trần-Nguyễn sntran

View GitHub Profile
@sntran
sntran / README.md
Created November 20, 2023 16:06
Fshare API v3
View README.md
@sntran
sntran / build.mjs
Created May 19, 2023 20:38
Esbuild serve and reload
View build.mjs
import esbuild from "esbuild";
import { createServer } from "http";
const clients = [];
esbuild
.build({
entryPoints: ["./index.tsx"],
bundle: true,
outfile: "bundle.js",
@sntran
sntran / Chunker.ts
Created February 6, 2023 03:50
A TransformStream that slices into chunks of a given size.
View Chunker.ts
/**
* A TransformStream that slices into chunks of a given size.
*/
export class Chunker extends TransformStream<Uint8Array, Uint8Array> {
constructor(chunkSize: number) {
let partialChunk = new Uint8Array(chunkSize);
let offset = 0;
function transform(chunk: Uint8Array, controller: TransformStreamDefaultController) {
let i = 0;
@sntran
sntran / shell2http.exs
Created December 10, 2021 04:38
HTTP-server to execute shell commands in a single file
View shell2http.exs
#!/usr/bin/env elixir
help = ~S"""
HTTP-server to execute shell commands.
The CLI takes a pair of path and the shell commands and generates the
routing. Upon requests to a matched path, the corresponding shell command
is executed, and the output is responded to the client.
The routing is generated by Plug.Router so it is really fast, and only
@sntran
sntran / fclone.sh
Last active August 28, 2021 17:46
fclone.sh - rclone wrapper with extra functionality
View fclone.sh
#!/bin/bash
# fclone.sh v0.4.0
#
# Wrapper around rclone with extra functionality:
#
# - Flag `--drive-service-account-file-path` to take a random service account file from that folder
# - Flag `--drive-service-account-file-path` can also take a URL for a service account credentials.
# - `remote:{ID}` syntax to use the folder with that ID in the remote, instead of full path.
#
# Usage:
@sntran
sntran / decode.exs
Created April 26, 2021 03:00
Erlang's yEnc benchmarks
View decode.exs
# Usage: mix run bench/decode.exs [optional switches]
# Optional switches:
# -z, --size <bytes> - Binary size in bytes to decode (default is 76800)
# -s, --sleep <seconds> - warmup time before real benchmark, in seconds (default is 2)
# -j, --jobs <number> - number of processes to be used for each benchmarking job (default is 1)
# -x, --extended_statistics - whether to show extended statistics
#
# Hit Ctrl+C twice to stop it.
{options, _argv, _invalid} = OptionParser.parse(System.argv(),
@sntran
sntran / $.js
Created October 25, 2019 16:28
jQuery-like $
View $.js
const $ = (selector, parent = document) => Array.from(parent.querySelectorAll(selector));
View keybase.md

Keybase proof

I hereby claim:

  • I am sntran on github.
  • I am sntran (https://keybase.io/sntran) on keybase.
  • I have a public key ASBcUAzxTk-x6WlcKCjLyc8hYXHZpLpInPoBAEJ20Z9M-wo

To claim this, I am signing this object:

View main.css
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font:inherit;font-size:100%;vertical-align:baseline;}html{line-height:1;}ol,ul{list-style:none;}table{border-collapse:collapse;border-spacing:0;}caption,th,td{text-align:left;font-weight:normal;vertical-align:middle;}q,blockquote{quotes:none;}q:before,q:after,blockquote:before,blockquote:after{content:"";content:none;}a img{border:none;}#header_features{position:relative;z-index:1;}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section,summary{display:block;}* html{font-size:93.75%;}html{font-size:15px;line-height:1.73333em;}html *{-webkit-box-sizing:borde
@sntran
sntran / calendar.xsl
Created January 29, 2015 14:50
A Calendar in XSLT
View calendar.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="calendar">
<xsl:param name="month" select="substring($page-modified-date, $date-modified-length - 7, 2)" />
<xsl:param name="year" select="substring($page-modified-date, $date-modified-length - 4, 4)" />
<!-- Default to an empty node list. -->
<xsl:param name="events" select="/.." />
<xsl:variable name="month-name">