Skip to content

Instantly share code, notes, and snippets.

View yishn's full-sized avatar
🏳️‍🌈
˚✧₊⁎( ˘ω˘ )⁎⁺✧༚

Yichuan Shen yishn

🏳️‍🌈
˚✧₊⁎( ˘ω˘ )⁎⁺✧༚
View GitHub Profile
@yishn
yishn / playing-go.txt
Last active July 9, 2017 14:24
Playing Go
( °-°) ┬─┬ •ノ(°-° )
( °-°)ヽ° ┬─┬ (°-° )
( °-°) ┬─┬ •ノ(°-° )
( °-°)ヽ° ┬─┬ (°-° )
( °-°) ┬─┬ •ノ(°-° )
@yishn
yishn / face.tex
Created February 21, 2017 19:56
LaTeX face
\overbrace{\left(\ddot{\stackrel{\quad>}{\smile}}\right)}_{\begin{align}\hline\qquad\end{align}}
@yishn
yishn / lines_of_code
Last active August 20, 2017 23:10
Count number of lines of code
git diff --stat 4b825dc642cb6eb9a060e54bf8d69288fbee4904
% This shows the differences from the empty tree to your current working tree.
% Which happens to count all lines in your current working tree.
@yishn
yishn / amount.js
Created March 12, 2018 23:00
Pretty print money amounts
exports.amount = function(amount) {
if (isNaN(amount)) return exports.amount(0)
if (amount < 0) return `-${exports.amount(-amount)}`
let result = (Math.round(amount * 100) + '').padStart(3, '0')
let [number, float] = [result.slice(0, -2), result.slice(-2)]
let thousands = []
for (let i = 1; -3 * i >= -number.length; i++) {
thousands.unshift(number.slice(-3 * i, (-3 * i + 3) || undefined))
@yishn
yishn / normalrand.js
Last active June 20, 2018 08:16
Box-Muller transform
// Standard normal variate using Box-Muller transform
// https://en.wikipedia.org/wiki/Box-Muller_transform
function normalrand() {
let u = 0, v = 0;
while (u === 0) u = Math.random();
while (v === 0) v = Math.random();
return Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);
}
@yishn
yishn / uuid.js
Last active April 9, 2024 18:22
Get shorter UUID
function id() {
return crypto.randomUUID().split('-').map(x => parseInt(x, 16).toString(36)).join('')
}
@yishn
yishn / takeScreenShot.js
Created November 21, 2019 12:27
Take screenshot in the browser
const canIRun = navigator.mediaDevices.getDisplayMedia
const takeScreenShot = async () => {
const stream = await navigator.mediaDevices.getDisplayMedia({
video: { mediaSource: 'screen' },
})
// get correct video track
const track = stream.getVideoTracks()[0]
// init Image Capture and not Video stream
const imageCapture = new ImageCapture(track)