Skip to content

Instantly share code, notes, and snippets.

@asm-jaime
asm-jaime / grid.clasterization.js
Created September 18, 2020 07:53
fast clasterization by k-mean+grid on javascript
const grid_clasterization = (points, quadrant_size, grid_size, x_max, y_max) => {
const quadrants = Array.apply(null, {length: Math.ceil(grid_size/quadrant_size)}).map(e => 0);
const grid_width = Math.sqrt(grid_size);
const quadrant_width = Math.sqrt(quadrant_size);
const grid_quadro_x_size = (x_max / grid_width)*quadrant_width;
const grid_quadro_y_size = (y_max / grid_width)*quadrant_width;
for(const point of points) {
const x_index = (Math.ceil(point.x/grid_quadro_x_size) - 1);
@asm-jaime
asm-jaime / index.html
Created February 13, 2020 15:13
button, open json data in new tab
<button onClick={() => {
const jsonData = JSON.stringify(state, null, 2);
const w = window.open();
w.document.open();
w.document.write('<html><body><pre>' + jsonData + '</pre></body></html>');
w.document.close();
}}>open</button>
@asm-jaime
asm-jaime / fetch-b64.js
Created June 15, 2018 15:07
convert Image url to Base64 with use fetch
const fetch = require('node-fetch');
function btob64(buff) {
let binary = '';
const bytes = (new Array()).slice.call(new Uint8Array(buff));
for(let i = 0; i < bytes.length; ++i){
binary = binary + String.fromCharCode(bytes[i]);
}
@asm-jaime
asm-jaime / index.html
Last active May 17, 2018 16:40
good grid+flexbox
<!DOCTYPE html>
<html lang="en">
<head>
<title>pr</title>
<style>
body {
margin: 0px;
padding: 0px;
@asm-jaime
asm-jaime / braces_valid.js
Last active May 12, 2018 05:04
javascript braces validation, with use array and object as dictionary
// ========== array brace validation
const edict_arr = [
['[', ']'],
['(', ')'],
['{', '}'],
];
function valid_arr(braces){
@asm-jaime
asm-jaime / index.html
Last active May 10, 2018 08:14
one file MVC
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>pistonizator</title>
</head>
<body style="text-align: center; font-size: 24px;">
<p>MVC</p>
<img id="mainv" src="http://fb.ru/misc/i/gallery/51506/2272349.jpg"></img>
<br/>
@asm-jaime
asm-jaime / 12345.html
Created May 8, 2018 20:16
12345 mutations and diffs
<!DOCTYPE html><html><head><style type="text/css">
#main_wrapper {
margin: 0;
padding: 0;
overflow: none;
}
.nvtooltip {
position: absolute;
background-color: rgba(255,255,255,1);
@asm-jaime
asm-jaime / 1234.html
Created May 8, 2018 20:14
1234 mutation and diffs
<!DOCTYPE html><html><head><style type="text/css">
#main_wrapper {
margin: 0;
padding: 0;
overflow: none;
}
.nvtooltip {
position: absolute;
background-color: rgba(255,255,255,1);
@asm-jaime
asm-jaime / tree_walker.js
Created May 4, 2018 14:50
this javascript example about tree traversal with use recursion and simple cycle while
// ========== data
const data = [{
"value":49,
"childs":[
{"value":54, "childs":[
{"value":25, "childs":[{"value":5, "childs":[]},{"value":5, "childs":[]}]},
{"value":15, "childs":[{"value":25, "childs":[]},{"value":125, "childs":[]},{"value":625, "childs":[]},{"value":55, "childs":[]}]},
{"value":35, "childs":[{"value":25, "childs":[]}]}
]},
{"value":55, "childs":[{"value":85, "childs":[]},{"value":45, "childs":[]},{"value":25, "childs":[]}]},
@asm-jaime
asm-jaime / mgo.go
Last active December 24, 2017 04:58
go mgo mongodb+test example, test insert same data to unique key
package main
import (
mgo "gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"time"
)
// ========== model