Skip to content

Instantly share code, notes, and snippets.

@JaosnHsieh
JaosnHsieh / crc32-incremental.js
Last active March 5, 2022 04:16
javascript incremental crc32 naive implementation.
/**
* javascript incremental crc32 naive implementation.
* based on http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html#ch44
* not production ready, not efficient !
dmeo:https://replit.com/join/dzezyxlpst-jaosnhsieh
*
*
*/
@JaosnHsieh
JaosnHsieh / README.md
Created February 16, 2022 09:52
list all x,y,z open street map tile map url in certain zoom level that can be used in leaflet

2022.02.16 leaflet get x y z tile image on certain zoom level learn from azure-maps/zoom-levels-and-tile-grid?tabs=csharp

Each tile is given XY coordinates ranging from (0, 0) in the upper left to (2zoom–1, 2zoom–1) in the lower right. For example, at zoom level 3, the tile coordinates range from (0, 0) to (7, 7) as follows:

demo: https://jsfiddle.net/jasonHsieh/qz5yngdk/1/

for example, zoom level 2 has below urls to fetch

@JaosnHsieh
JaosnHsieh / speedometer.js
Last active February 15, 2022 08:45
speedometer test, a window sliding algorithm to calculate streaming data speed in javascript, cloud be used in any node.js stream
var tick = 1;
var maxTick = 65535;
var resolution = 4;
var timer;
const startedAt = new Date().getTime();
module.exports = function(seconds) {
var size = resolution * (seconds || 5);
var buffer = [0];
@JaosnHsieh
JaosnHsieh / index.html
Last active February 11, 2022 05:14
use indexdb on browser to cache image files ( map tile image in the example)
<!-- working example https://jsfiddle.net/qz9g53bt/2/ -->
<!-- from https://github.com/allartk/leaflet.offline -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://unpkg.com/idb@6.1.4/build/iife/index-min.js"></script>
@JaosnHsieh
JaosnHsieh / git-find-line-deleted.md
Created February 9, 2022 09:49
How to find commit when line was deleted/removed?

2022.02.09 How to find commit when line was deleted/removed?

git log -c -S'missingtext' /path/to/file

for example, i was looking for when was webpackJson got deleted in create-react-app repo

git clone https://github.com/facebook/create-react-app.git

@JaosnHsieh
JaosnHsieh / Findings.md
Last active January 26, 2022 02:26
discover the zeromqjs use cases in real world. csv list crawled from https://github.com/zeromq/zeromq.js/network/dependents?package_id=UGFja2FnZS00OTMwNjkyMjQ%3D
@JaosnHsieh
JaosnHsieh / async-interval.js
Created January 24, 2022 02:22
interesting async fact in node.js
/*
* adding extra async execuation "await wait();" actually giving setInterval some time to execute.
* try comment "await wait();"
*/
main();
async function main() {
setInterval(() => {
console.log(new Date(), 'interval');
@JaosnHsieh
JaosnHsieh / run-this-in-chrome-inspect-console.js
Created January 4, 2022 10:03
cordova-file-plugin write file example works on android 9
// from https://forum.quasar-framework.org/topic/3375/solved-v1-download-a-file-in-cordova-app/2
window.test = {};
window.test.writeFile = (fileName, content) => {
return new Promise((ok, fail) => {
//@ts-ignore
if (!window.requestFileSystem) {
console.error(`$ window.requestFileSystem is not available`);
fail(false);
return;
}
@JaosnHsieh
JaosnHsieh / usePreviousDifferent.ts
Created December 15, 2021 08:54
useful react hook, get previous different state value
2021.12.15 useful react hooks. previous value hook
usePreviousDifferent.ts
/**
from: https://github.com/imbhargav5/rooks/blob/main/src/hooks/usePreviousDifferent.ts
from: https://github.com/imbhargav5/rooks/blob/main/src/hooks/usePreviousDifferent.ts
@JaosnHsieh
JaosnHsieh / discriminated-union-example.ts
Created December 2, 2021 09:52
typescript function overloading is better than discriminated union because it can define return type of the function
type A = { command: 'a'; s: string };
type B = { command: 'b'; b: number };
function t(option: A | B) {
switch (option.command) {
case 'a': {
return 's';
}
case 'b': {
return 1;