Skip to content

Instantly share code, notes, and snippets.

@yi-jiayu
yi-jiayu / index.js
Created July 5, 2017 03:11
Using Google Cloud Functions to display data from Google Analytics as a README badge
"use strict";
const google = require('googleapis');
const key = require('./credentials.json');
const viewId = 'YOUR_VIEW_ID';
function getUsers(key, viewId) {
// https://github.com/google/google-api-nodejs-client#using-jwt-service-tokens
const jwtClient = new google.auth.JWT(
@yi-jiayu
yi-jiayu / escape_sequences.c
Created July 19, 2016 09:09
Manipulating a compatible terminal using escape sequences
#include <stdio.h>
main(void) {
\\ enter alternate screen mode
printf("\033[?1049h");
\\ move the cursor to the upper left corner
printf("\033[H");
printf("Hello, World");
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 March 11, 2019 08:42
A simple backtracking sudoku solver
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] +
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 January 4, 2019 10:25
Automatically guessing Quizzarium answers from DuckDuckGo search results based on hints.
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 December 25, 2018 05:37
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/)
#!/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 / 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]
@yi-jiayu
yi-jiayu / ssh-invalid-users.sh
Created September 19, 2016 05:51
Displays a sorted list of users used in failed SSH login attempts
sudo cat /var/log/secure | grep invalid | awk '{ print $9 }' | sort | uniq -c | sort -bnr | less