Skip to content

Instantly share code, notes, and snippets.

@yi-jiayu
yi-jiayu / dashboard.json
Last active April 18, 2022 04:11
greenpath.dev dashboard for https://github.com/actions
{
"name": "Actions dashboard",
"builds": [
{
"owner": "actions",
"repo": "starter-workflows",
"ref": "main",
"include_prs": true
},
{
@yi-jiayu
yi-jiayu / Linear Escape.i7
Created August 3, 2020 15:18
Linear Escape
"Linear Escape" by Jiayu Yi
Dead End is a dark room. "[if unvisited]You wake up in[otherwise]The room you woke up in is[end if] a small room with a single exit to the south."
A lit thing called a torch is in the Dead End.
The strangely-shaped rock is carried by the player.
South of the Dead End is the Overgrown Chamber. The Overgrown Chamber is a dark room. "You find yourself in a large chamber. The walls are covered with vegetation, and [sturdy vines] hang from the ceiling. The middle is occupied by a large, [ceremonial brazier]. [if the ceremonial brazier is lit]There are exits to the north and south.[otherwise]There is an exit to the north, but a stone door blocks the way south."
@yi-jiayu
yi-jiayu / sse_demo_plug.ex
Created February 8, 2020 14:45
Server-sent events in Elixir with Plug
defmodule SSEDemoPlug do
use Plug.Router
plug Plug.Logger
plug(:match)
plug(:dispatch)
get "/" do
html = """
<ul></ul>
@yi-jiayu
yi-jiayu / zebra.pl
Created January 16, 2020 15:59
Prolog solution to the Zebra Puzzle (https://en.wikipedia.org/wiki/Zebra_Puzzle)
:- use_module(library(clpfd)).
zebra(Colors, Nationalities, Pets, Beverages, Cigarettes) :-
Colors = [Red, Green, Ivory, Yellow, Blue],
Nationalities = [English, Spanish, Ukrainian, Norweigian, Japanese],
Pets = [Dog, Snails, Fox, Horse, Zebra],
Beverages = [Coffee, Tea, Milk, Orange, Water],
Cigarettes = [Old, Kools, Chesterfields, Lucky, Parliaments],
Colors ins 1..5,
Nationalities ins 1..5,
@yi-jiayu
yi-jiayu / git-safe-to-delete
Created October 1, 2019 12:49
Script to check if a local Git repository can be deleted safely without losing any work
#!/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."
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