Skip to content

Instantly share code, notes, and snippets.

Jiayu Yi yi-jiayu

Block or report user

Report or block yi-jiayu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@yi-jiayu
yi-jiayu / git-safe-to-delete
Created Oct 1, 2019
Script to check if a local Git repository can be deleted safely without losing any work
View git-safe-to-delete
#!/usr/bin/env bash
# Check if the working tree is clean.
# The working tree is clean if the output of `git status --porcelain` is empty.
[ -z "$(git status --porcelain)" ] || echo "Working tree not clean."
# Check if there are any stashes.
# There are no stashes if the output of `git stash list` is empty.
[ -z "$(git stash list)" ] || echo "Stash list not empty."
View basics-2d-accelerated.patch
diff --git a/demos/basics.scm b/demos/basics.scm
index 65280b6..a9b16f9 100644
--- a/demos/basics.scm
+++ b/demos/basics.scm
@@ -150,20 +150,31 @@
(define smiley1 (make-obj (make-smile-surf (make-random-color)) 300 300))
(define smiley2 (make-obj (make-smile-surf (make-random-color)) 500 300))
-
+(define renderer (sdl2:create-renderer! window -1 (list 'accelerated)))
@yi-jiayu
yi-jiayu / sudoku.py
Created Mar 11, 2019
A simple backtracking sudoku solver
View sudoku.py
def rows(puzzle):
return [puzzle[9 * i:9 * i + 9] for i in range(9)]
def columns(puzzle):
return [puzzle[i::9] for i in range(9)]
def boxes(puzzle):
return [puzzle[i:i + 3] +
View pokedex.ipynb
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 / autoquizzarium.ipynb
Last active Jan 4, 2019
Automatically guessing Quizzarium answers from DuckDuckGo search results based on hints.
View autoquizzarium.ipynb
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 / sleep_prevention_warning.sh
Created Dec 25, 2018
Shell script to display a notification if there are any processes preventing the system from sleeping on macOS (https://blog.jiayu.co/2018/12/get-notified-when-a-process-is-preventing-sleep-on-macos/)
View sleep_prevention_warning.sh
#!/bin/sh -
sleep_blocker=$(pmset -g | grep -m1 "sleep prevented by" | sed -E 's/.+sleep prevented by (.+)\)$/\1/')
if [ ! -z "$sleep_blocker" ]; then
osascript -e "display notification \"$sleep_blocker\" with title \"Sleep prevention warning\" subtitle \"The following processes are preventing sleep:\""
fi
@yi-jiayu
yi-jiayu / hotcorners.sh
Last active Dec 24, 2018
A script to quickly configure Hot Corners from a file on macOS (https://blog.jiayu.co/2018/12/quickly-configuring-hot-corners-on-macos/)
View hotcorners.sh
#!/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 Dec 21, 2018
Bash script with completion to connect to VPNs using TOTP passwords on MacOS
View vpn
#!/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
View vanilla_nn.py
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]
View asn.sh
asn() {
if [ -z "$1" ]
then
echo "usage: asn url" 1>&2
return 1
fi
ips=$(dig $DIG_ARGS +short $1)
if [ -z "$ips" ]
then
You can’t perform that action at this time.