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.