Skip to content

Instantly share code, notes, and snippets.

View mutoo's full-sized avatar

Lingjia Liu mutoo

View GitHub Profile
@mutoo
mutoo / get_source_map_links.js
Last active March 18, 2024 16:23
Get all source map links on page. Usage: create a snippet on `chrome devtools > sources > snippets` and run it.
@mutoo
mutoo / zellersCongruence.js
Last active March 15, 2023 23:04
caldulated day of week with zellersCongruence, by GPT-4
// Zeller's Congruence function
function zellersCongruence(year, month, day) {
if (month < 3) {
month += 12;
year -= 1;
}
const A = year % 100;
const B = Math.floor(year / 100);
const F = A + Math.floor(A / 4) + Math.floor(B / 4) - 2 * B + Math.floor(13 * (month + 1) / 5) + day;
@mutoo
mutoo / ping.py
Created March 14, 2023 23:41
thefuck customized rule: ping – fixes cannot resolve host issues when http(s):// is prepended (eg. copy url from browser address bar);
# -*- encoding: utf-8 -*-
from six.moves.urllib.parse import urlparse
from thefuck.utils import for_app, memoize
@memoize
def get_hostname_from_url(maybeUrl):
try:
results = urlparse(maybeUrl)
return results.hostname
@mutoo
mutoo / svg-path-data-1.1.ne
Created July 27, 2021 07:05
a nearley grammar of BNF for svg path data
# The grammar for path data
# it's implementing the svg 1.1 spec
# https://www.w3.org/TR/SVG11/paths.html#PathDataBNF
#
# N.B. This Implementation Is Ambiguous!
# e.g. M0.6.5 -> M 0 6.5 | M 0.6 0.5
#
@{%
const it = (it) => it;
@mutoo
mutoo / ecosystem.config.js
Created May 28, 2021 05:43
fan control with pm2 service
const path = require('path');
module.exports = {
apps: [
{
name: 'fan-ctrl',
cwd: path.resolve(__dirname),
interpreter: 'python3',
cmd: 'fan_ctrl.py',
// Options reference: https://pm2.keymetrics.io/docs/usage/application-declaration/
{
const ratioConfig = (x, y) => ({
x,
y,
ratio: x / y
})
const commonRatio = [ratioConfig(1, 1), ratioConfig(4, 3), ratioConfig(16, 9), ratioConfig(16, 10)];
const getRatioConfig = (x, y) => {
@mutoo
mutoo / instanceOf.js
Created July 23, 2020 23:56
the instanceOf function that works with primitive type.
function instanceOf(inst, cls) {
if (inst === null || inst === undefined)
return false;
if (typeof cls !== 'function')
throw new TypeError("Second parameter is not a constructor");
let instance = inst;
while (instance.__proto__) {
if (instance.__proto__ === cls.prototype) {
return true;
}
@mutoo
mutoo / rope-smooth-rotation.html
Created July 18, 2020 12:57
use wander(steering behaviors) as smooth rotation
<canvas id="stage"></canvas>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
</style>
<script>
const stg = document.getElementById('stage');
@mutoo
mutoo / triangles.lua
Last active June 16, 2020 14:24
draw random triangles in aseprite
local image = app.activeCel.image:clone()
local black = Color { r = 0, g = 0, b = 0, a = 255 }
local white = Color { r = 255, g = 255, b = 255, a = 255 }
local width = image.width
local height = image.height
local size = width * height
local nearest = 0.1
local farest = 1000
@mutoo
mutoo / fibonacci-50000000
Created March 14, 2020 21:32
the answer of the fibonacci[50000000]
This file has been truncated, but you can view the full file.
4602713413433154453264452332101823124660178999927878775099623274628544000826084520729275137386306313610970039542134019169094479911539667758765706548388262709395910401447414275192972397095100372901062558411172027994823308339118707411212899705108784191046990030246902890430162768476917897544323686963363526638329586402598537684995297467531450584152322402629527753056672068582799976452955077140364435633611627743030006882994464389706629103466042439399187818912431754020828466328554047723057801189261674789207224541262917263083945860320625674536625026002950952262398064897919271988481419068961330802400103216397852978258771045078666755642257479872208814339437518538616439414227876160324202838202693667701117389124410449965409845122982315624918113650650381630365765220616683628335407025058495890159377056162851945512758383382009140042967905216072731650772908134476998576255535178729325770930240128556117231001128605001837891938772915337002956920498855579997481972474558715755099585396947510028754873131439722605891277408245136842