Skip to content

Instantly share code, notes, and snippets.

View thomastay's full-sized avatar

Thomas Tay thomastay

View GitHub Profile
@thomastay
thomastay / esbuild.js
Last active November 14, 2021 01:27
Esbuild for Node, excluding node_modules starter pack
const chalk = require("chalk");
// Credit to evanw himself: https://github.com/evanw/esbuild/issues/619
const makeAllPackagesExternalPlugin = {
name: "make-all-packages-external",
setup(build) {
const filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/; // Must not start with "/" or "./" or "../"
build.onResolve({ filter }, args => ({
path: args.path,
external: true,
@thomastay
thomastay / ziglang-master.json
Last active July 16, 2021 18:43
A scoop app manifest to get the nightly version of Zig
{
"version": "0.8.0-dev.1479-aa1c78056",
"description": "General-purpose programming language designed for robustness, optimality, and maintainability.",
"homepage": "https://ziglang.org/",
"license": "MIT",
"suggest": {
"vcredist": "extras/vcredist2019"
},
"architecture": {
"64bit": {
@thomastay
thomastay / easy-to-forget-memory-leaks.js
Last active October 19, 2020 17:09
Easy to forget memory leaks
// Case 1: accidentally capturing an outer object in a lambda
class Foo {
constructor(arr) {
this.sayHellos = [];
for (const languageData of arr) {
this.sayHellos.push(() => {
console.log(languageData.hello); // oops, languageData is captured, even though it is not needed after this call
});
};
}
@thomastay
thomastay / equivalence.js
Last active October 8, 2020 00:12
Promise <-> Async await equivalence
"use strict"
// The following are equivalent (functionally)
// Async await
async function simple() {
await setTimeout(() => console.log("hello, world!"), 1000);
}
// Promises
function simple_promise() {
@thomastay
thomastay / Update-KeePassRPC.ps1
Last active August 6, 2020 03:25
Retrives the latest download of KeePassRPC from Github, and loads it into the KeePassRPC folder in the C:\ drive
function promptYesNo ($title, $question) {
$choices = '&Yes', '&No'
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
$decision -eq 0
}
function Convert-GithubVersion($githubVersionString) {
[System.Version]$githubVersionString.Substring(1)
}
@thomastay
thomastay / ytdl-wrapper.ps1
Last active July 28, 2020 14:32
My personal wrapper for youtube-dl
[CmdletBinding(SupportsShouldProcess = $True)]
Param (
[Parameter(Mandatory = $true)]
[string]$URL,
[Switch]$audio,
[Switch]$ignoreErrors
)
$command = $URL, '-o', '%(title)s.%(ext)s'
if ($audio) {
$command += "-x", "--postprocessor-args", "`"-threads 2`""
@thomastay
thomastay / prompt.ps1
Last active April 3, 2023 15:00
Powershell fish prompt
function replaceHome($pathArray) {
# Check whether the first three paths are equal to HOME
# If it is, it substitutes it for ~
# Change this accordingly, if your home path is more than three
# paths long.
$splitChar = [System.IO.Path]::DirectorySeparatorChar
if ( ($pathArray.Length -gt 2) -and
(($pathArray[0..2] -join $splitChar) -eq $HOME)) {
@("~") + $pathArray[3..$pathArray.Length]
}
@thomastay
thomastay / mariomka-benchmark.nim
Last active August 13, 2020 03:37
quick and dirty bench for mariomka bench
import os
import std/[times, monotimes, stats]
from regex import nil
from std/re import nil
proc measureNimRegex(data, pattern: string) =
var r: RunningStat
var matches: int
let patternRe = regex.re(pattern)
for i in 1..3:
@thomastay
thomastay / chartist.html
Created April 21, 2020 08:52
Quick Demo of a chartist chart
<html>
<head>
<meta charset="utf-8"/>
<link href="/static/chartist/chartist.min.css" rel="stylesheet" />
<script src="/static/chartist/chartist.min.js" > </script>
<title>Your title here!</title>
</head>
<body>
<h1> Progress chart! </h1>
<div class="ct-chart ct-octave"> </div>
# Calculates transitive closure of a relation
# EECS 203 students: You are FORBIDDEN from using this code
# for homework purposes. Only use this for self-learning
# and testing.
import strutils, sequtils, sugar, strformat
type Matrix = seq[seq[bool]]
func `$`(m: Matrix): string =
for row in m: