Skip to content

Instantly share code, notes, and snippets.

@yi-jiayu
yi-jiayu / hotcorners.sh
Last active January 27, 2023 15:04
A script to quickly configure Hot Corners from a file on macOS (https://blog.jiayu.co/2018/12/quickly-configuring-hot-corners-on-macos/)
#!/usr/bin/env bash
set -e
config_dir=${HOTCORNERS_CONFIG_DIR:-$HOME/.hotcorners}
if [ -z "$1" ]; then
echo "usage: hotcorners profile" 1>&2
exit 1
fi
@yi-jiayu
yi-jiayu / vpn
Created December 21, 2018 03:09
Bash script with completion to connect to VPNs using TOTP passwords on MacOS
#!/usr/bin/env bash
config_file="${config_file:-$HOME/vpn.conf}"
if [ ! -f $config_file ]; then
echo "could not find config file at $config_file"
exit 1
fi
username=$(grep -m1 username <$config_file | awk -F\= '{print $2}')
if [ -z "$username" ]; then
import random
import itertools
def E(x, y):
return (x - y) ** 2
def forward_pass(w, x):
x[2] = w[0] * x[0] + w[2] * x[1]
asn() {
if [ -z "$1" ]
then
echo "usage: asn url" 1>&2
return 1
fi
ips=$(dig $DIG_ARGS +short $1)
if [ -z "$ips" ]
then
@yi-jiayu
yi-jiayu / book.ipynb
Created July 30, 2018 16:35
NLB book info
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yi-jiayu
yi-jiayu / README.md
Last active June 16, 2018 02:42
The SUTD logo as a PBM file

SUTD logo in PBM format

Using ImageMagick, you can render a PBM file into some other format, for example PNG:

Command

convert SUTD.pbm -scale 4000% -transparent white SUTD.png
select
  p.web_name,
  t.name                as club,
  r.singular_name_short as position,
  max(p.total_points)   as total_points
from players p left join teams t on p.team = t.id
  left join roles r on p.element_type = r.id
group by p.team;
@yi-jiayu
yi-jiayu / submissions.csv
Created May 20, 2018 14:51
Data used to analyse Reddit submissions for Benford's law
tab subreddit id score num_comments
hot gaming 8ks3o4 15084 213
hot aww 8krvk4 13202 203
hot NatureIsFuckingLit 8ks1sn 6366 172
hot worldnews 8krdwg 17227 1940
hot PrequelMemes 8krmxy 10996 74
hot gifs 8kr91u 28793 597
hot FortNiteBR 8krn5p 10476 202
hot MadeMeSmile 8krwsu 4905 55
hot technology 8krbip 10103 772
@yi-jiayu
yi-jiayu / benford.ipynb
Last active June 12, 2018 15:51
Analysing Reddit submissions for Benford's Law https://blog.jiayu.co/2018/05/benfords-law-and-reddit/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import argparse
import sys
import markovify
def main(files, n):
text = ''
for f in files: