Skip to content

Instantly share code, notes, and snippets.

@likev
likev / server.py
Last active July 11, 2022 10:27 — forked from mdonkers/server.py
Simple Python 3 HTTP server for logging all GET and POST requests
#!/usr/bin/env python3
"""
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
import cgi
@likev
likev / index.html
Created December 23, 2021 15:40
AES-GCM encrypt decrypt and download
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AES-GCM encrypt decrypt and download</title>
</head>
@likev
likev / Spline_interpolation.links.md
Last active November 6, 2021 15:39
Spline_interpolation
@likev
likev / for-loop-slow-in-firefox-console.js
Created October 12, 2021 03:10
when use global variables,the for loop run 100x slow in firefox dev console!
"use strict";
//when use global variables,the for loop run 100x slow!
const CHECK_LENGTH = 1E6,
CHECK_POINT = Math.ceil(Math.sqrt(CHECK_LENGTH));
var test1 = _ => {
let cn = new Array(CHECK_LENGTH);
for (let j = 2; j < 1E3; j++) {
@likev
likev / js-closure-memory-leak-and-fix.js
Created October 9, 2021 06:37
js closure memory leak and fix demo
function test() {
//very long string
let s = new Array(1000 * 500).join(new Array(1000).join('x'));
window.check = function() {}//closure
let out = setTimeout(_ => {
if (window.check) {
//random index
@likev
likev / alarm-list.js
Created August 19, 2021 18:27
get weather alarm list from http://www.12379.cn
async function test(){
let f = await fetch('https://icors.vercel.app/?http%3A%2F%2Fwww.12379.cn%2Fdata%2Falarm_list_all.html')
let d = await f.json()
console.log(d.alertData)
for(let item of d.alertData){
//https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/includes
if(item.headline.includes('孟津')){
console.log(item)
@likev
likev / index.html
Created July 24, 2021 09:38
smoothPolygon use turf // source https://jsbin.com/hapemesege
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>smoothPolygon use turf</title>
<style>
canvas{
margin:20px;
}
Call to putImageData took 41 milliseconds.
Call to fillRect took 2019 milliseconds.
@likev
likev / integers_factor_graph.js
Last active June 25, 2021 10:10
Starting with 2, integers are added, in order, as vertices to a graph. Any two vertices are joined if one of them is a factor of the other. What is the maximum integer if none of the edges are allowed to cross? https://twitter.com/mathstechnology/status/1407585626015338499
//numbers 2-23
var run = async _ => {
let canvas = $("<canvas width=1000 height=800></canvas>")[0]
$('body').empty().append(canvas)
const ctx = canvas.getContext('2d');
const get_random = (a, b) => {
return (b - a) * Math.random() + a;
}
@likev
likev / performance_test.js
Created June 11, 2021 04:55
JavaScript Math function performance test
function performance_test(name, func, iterations=1E8){
console.time(name);
for(var i = 0; i < iterations; i++ ){
func();
};
console.timeEnd(name)
}
performance_test('sin', _=>{Math.sin(Math.random())})