Skip to content

Instantly share code, notes, and snippets.

View a1mersnow's full-sized avatar
😃
Working

a1mer a1mersnow

😃
Working
View GitHub Profile
@a1mersnow
a1mersnow / catch-all-boxes.js
Created March 16, 2019 05:47
catch all boxes in page(this may not work well for fixed or sticky positioned box)
void function () {
const canvas = document.createElement('canvas')
canvas.width = document.documentElement.offsetWidth
canvas.height = document.documentElement.offsetHeight
canvas.style.position = 'absolute'
canvas.style.left = '0'
canvas.style.right = '0'
canvas.style.top = '0'
@a1mersnow
a1mersnow / str2num.test.js
Created March 30, 2019 02:38
string to number without using Number or parseFloat
/**
* @param {string} str
*/
function str2num (str) {
const [m, e = ''] = str.split('e')
const [i, f = ''] = m.split('.')
let result = 0
// handle int
let sign = 1
for (let x of i) {
@a1mersnow
a1mersnow / horizontal-single-line-all-children-height-specified-flex.html
Created April 15, 2019 03:30
horizontal single line all children height specified flex layout
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.flex-container {
background-color: blanchedalmond;
@a1mersnow
a1mersnow / find-all-properties-of-window.js
Created April 19, 2019 02:47
find all properties of window
window.onload = function () {
let names = Object.getOwnPropertyNames(window)
names = names.filter(x => !x.match(/^on/))
names = names.filter(x => !x.match(/^webkit|^WebKit/))
/**
* ---------------------------------- WHATWG ---------------------------------------
*/
{
@a1mersnow
a1mersnow / transition.js
Created April 20, 2019 04:30
JS version's transition
const tweenFns = {
linear: (from, to, t, d) => from + (to - from) * (t / d)
}
/**
* only support "linear" timing-function
* duration unit is "ms"
* @param {HTMLElement} el
* @param {({prop: String, value: String, duration: Number})[]} list
*/
@a1mersnow
a1mersnow / 2094-nll
Last active November 18, 2021 07:32
translation for "rust nfc 2094 - nll"
在我刚学习 `Rust` 的时候,我看过一遍 nll 的原文,那时候大概只能看懂一小部分。
古语说,书读百遍其义自现,真的是一句真理。
为什么通过反复读,有些不理解的地方就能理解就能想通了呢?
我觉得很大一部分原因是,你对它越来越熟悉了,你对它里面提到的概念越来越熟悉了。
你读第一遍的时候,一个概念是什么,你还要费力地想一想,
读第二三遍的时候,你已经对这个概念建立了一种直觉,
因此你的思考能量(类似于精力吧,是有限的)就可以用在其他更关键的地方。
我之所以想翻译这篇 RFC,原因之一是想锻炼一下自己的英文;