Skip to content

Instantly share code, notes, and snippets.

View RuyiLi's full-sized avatar
🐶
if id ex mem wb

Roy Li RuyiLi

🐶
if id ex mem wb
View GitHub Profile
@RuyiLi
RuyiLi / bee.ts
Last active May 29, 2023 22:59
5153 - IndexOf
import type { Equal } from '@type-challenges/utils'
type IndexOf<T, U, C extends `According to all known laws of aviation, there is no way a bee should be able to fly.
Its wings are too small to get its fat little body off the ground.
The bee, of course, flies anyway because bees don't care what humans think is impossible.
Yellow, black. Yellow, black. Yellow, black. Yellow, black.
Ooh, black and yellow!
Let's shake it up a little.
Barry! Breakfast is ready!
Coming!
@RuyiLi
RuyiLi / cssvalue.ts
Created April 20, 2023 18:31
TS compile time $token substitution
const theme = {
color: 'blue',
padding: '1px 2px',
margin: '2px $padding $size',
size: '3rem'
} as const
type CSSSingleVarToken<S extends string> = S extends `$${infer _} ${infer _}`
? never
: S extends `$${infer K}`
# Generated by Powerlevel10k configuration wizard on 2021-06-28 at 18:35 EDT.
# Based on romkatv/powerlevel10k/config/p10k-lean.zsh, checksum 19275.
# Wizard options: nerdfont-complete + powerline, small icons, unicode, lean, 12h time,
# 1 line, compact, many icons, concise, instant_prompt=verbose.
# Type `p10k configure` to generate another config.
#
# Config for Powerlevel10k with lean prompt style. Type `p10k configure` to generate
# your own config based on it.
#
# Tip: Looking for a nice color? Here's a one-liner to print colormap.
@RuyiLi
RuyiLi / d1p1.jl
Last active January 21, 2020 14:20
AOC 2018 Solutions For Google Code-In
# Author: weCryOpen (Ruyi Li)
function d1p1(file)
open(file) do f
total = 0
for line in eachline(f)
# Iterate through each line in the file
# Convert it to an integer,
n = parse(Int, line)
# and add it to the total.
@RuyiLi
RuyiLi / main.jl
Last active January 21, 2020 13:28
Calculating the value of Pi in Julia - Google Code-In
# Author: Ruyi Li (weCryOpen)
function mypi(n::Int)::Float
total_sum::Float = 0
for i = 1:n
total_sum += 1 / (i * i)
end
(total_sum * 6) ^ 0.5
end
@RuyiLi
RuyiLi / index.html
Created December 9, 2019 03:14
Soldier simulator application for my Math Extended Essay.
<canvas></canvas>
<button onclick="josephus()"> Start </button>
<button onclick="eliminate()"> Kill </button>
<script>
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
const SIZE = 640;
canvas.width = canvas.height = SIZE;

Keybase proof

I hereby claim:

  • I am ruyili on github.
  • I am wecryopen (https://keybase.io/wecryopen) on keybase.
  • I have a public key ASBErN8SGkckrb14D073PzIuuJUwbAoEmXSnAFQKiNEYFgo

To claim this, I am signing this object:

@RuyiLi
RuyiLi / goosegen.js
Created September 15, 2019 01:06
LONGOOSE
g=a=>`:goose-${a}:`;[g('top'),...Array(+prompt('Length of goose neck:')).fill(g('middle')),g('bottom')].join`\n`
@RuyiLi
RuyiLi / index.html
Created September 4, 2019 17:37
argebe - A fun and unique browser game smaller than 3kb (uncompressed, without comments)
<canvas style="position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);"></canvas>
<script>
/*
w - The width of the canvas in pixels.
h - The height of the canvas in pixels.
s - The size of the character in pixels.
c - The canvas element.
t - The graphics context.
u - The available colors.
q - The player's current colors.
@RuyiLi
RuyiLi / assignments3.md
Last active August 7, 2019 14:43
Big Assignments

Make sure to use styles!

Choice 1 - Rock Paper Scissors Poker

Rules of the game:

Each player draws five cards (either rock, paper, or scissors) from an unlimited deck. Both players will pick one card, and if one player's cards beat the other (rock beats scissors, paper beats rock, scissors beats paper) then that player wins. If there is a tie (e.g. both play rock) then whoever has more of the chosen card in the hand wins. If they both have the same amount, it is counted as a tie.

As an extra challenge, modify the game so that there are 5 rounds, with a point being awarded each time a player wins. At the end of the five rounds, print the status of the game (either a win, tie, or a loss).