Skip to content

Instantly share code, notes, and snippets.

View EtherDream's full-sized avatar
👓
🎃

EtherDream EtherDream

👓
🎃
View GitHub Profile
@EtherDream
EtherDream / event_timestamp.js
Last active August 24, 2017 07:39
e.timeStamp vs Date.now()
var t1, t2;
function sleep(ms) {
var s = Date.now();
while (Date.now() - s < ms);
}
document.addEventListener('mousemove', function(e) {
if (!t1) {
t1 = Date.now();
var URL = 'http://gd1.alicdn.com/imgextra/i1/394695430/TB2d4w3cXXXXXc4XXXXXXXXXXXX_!!394695430.jpg';
var img = new Image();
img.onload = function() {
var c = document.createElement('canvas');
var w = c.width = img.width;
var h = c.height = img.height;
ctx = c.getContext('2d');
ctx.drawImage(img, 0, 0);
var data = ctx.getImageData(0, 0, w, h);
@EtherDream
EtherDream / prime.html
Created October 14, 2017 12:50
2 to N primes in Jekyll/Liquid
<table border="1">
<tr>
<td width="100">id</td>
<td width="100">num</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
{%- assign MAX = 10000 -%}
@EtherDream
EtherDream / prime.scss
Last active October 16, 2020 09:33
2 to N primes in SCSS
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
@function is_prime($num, $sqrt) {
@for $i from 3 through $sqrt {
@if $num % $i == 0 {
@return false;
}
@EtherDream
EtherDream / formatTime.js
Created March 15, 2018 08:55
date object -> "yyyy/MM/dd hh/mm/ss"
function formatTime(date) {
var d = new Date(date - 60000 * date.getTimezoneOffset());
var s = d.toISOString();
return s.substr(0, 10) + ' ' + s.substr(11, 18);
}
formatTime( new Date() ); // "2018-03-15 16:52:34.969Z"
@EtherDream
EtherDream / formatTime.js
Created March 15, 2018 08:55
date object -> "yyyy/MM/dd hh/mm/ss"
function formatTime(date) {
var d = new Date(date - 60000 * date.getTimezoneOffset());
var s = d.toISOString();
return s.substr(0, 10) + ' ' + s.substr(11, 8);
}
formatTime( new Date() ); // "2018-03-15 16:52:34"
@EtherDream
EtherDream / install-openresty.sh
Last active October 16, 2020 09:31
Compile OpenResty
OPENRESTY_VER=1.17.8.2
ZLIB_VER=1.2.11
PCRE_VER=8.44
OPENSSL_VER=1.1.1h
DIR=$(mktemp -d)
echo $DIR
cd $DIR
git clone https://github.com/google/ngx_brotli.git --recurse-submodules
(function() {
'use strict'
async function pending() {
return 11
}
function mayPending() {
if (Math.random() < 0.001) {
return pending()
# see https://github.com/EtherDream/freecdn/blob/master/examples/free-host/npm-upload.sh
IFS=$'\n'
if [[ "$NPM_PKG" == "" ]]; then
echo "\$NPM_PKG is not specified"
exit
fi
if [[ "$*" == "" ]]; then
echo "file list empty"

打造闭环:

var a = {}
var b = {}
a.b = b
b.a = a

底层逻辑: