Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Looking for a job

Sergey Ponomarev stokito

🚀
Looking for a job
View GitHub Profile
View append_float_into_slice.go
func Test_insert_with_override(t *testing.T) {
reqBody := []byte(`ABCDEFG`)
shifted := reqBody[1:]
strconv.AppendInt(shifted[:0], int64(123), 10)
assert.Equal(t, `A123EFG`, string(reqBody))
}
@stokito
stokito / dns-resolve.html
Created Nov 7, 2022
JavaScript resolve DNS from browser
View dns-resolve.html
<html>
<script>
// https://stackoverflow.com/a/58299823/1049542
// https://developers.cloudflare.com/1.1.1.1/encryption/dns-over-https/make-api-requests/dns-json/
// var dnsQ = fetch('https://dns.google/resolve?name=stokito.com&type=A',
var dnsQ = fetch('https://cloudflare-dns.com/dns-query?name=stokito.com&type=A',
{
headers: {
@stokito
stokito / fast_float_round.go
Last active Oct 14, 2022
golang fast float rounding
View fast_float_round.go
// https://www.h-schmidt.net/FloatConverter/IEEE754.html
// simplest rounding is just removing right bits from mantisa
func fastFloatRound(f float32) float32 {
fbits := math.Float32bits(f)
fbits = fbits >> 15
fbits = fbits << 15
fRounded := math.Float32frombits(fbits)
return fRounded
}
View bootstrap-table-csv.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sample of BootStrap Table that render CSV file</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- bootstrap itself -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" integrity="sha256-7ZWbZUAi97rkirk4DcEp4GWDPkWpRMcNaEyXGsNXjLg=" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha256-wMCQIK229gKxbUg3QWa544ypI4OoFlC2qQl8Q8xD8x8=" crossorigin="anonymous"></script>
<!-- jquery needed for bootstrap-table-->
@stokito
stokito / prometheus-exposition.js
Created Aug 24, 2022
parse Prometheus metrics from JavaScript
View prometheus-exposition.js
class Metric {
/**
* @param {string} help
* @param {string} value
* @param {string[]} values
* @param {string[]} labels
*/
constructor(help, value, values, labels) {
this.help = help
this.value = value
@stokito
stokito / OpenWrt_Virtualbox.md
Last active Aug 13, 2022 — forked from jayluxferro/OpenWrt_Virtualbox.md
How to run OpenWrt in VirtualBox
View OpenWrt_Virtualbox.md

The official doc seems too complicated OpenWrt on VirtualBox HowTo

  1. Download and install VirtualBox. On Windows add to PATH envs C:\Program Files\Oracle\VirtualBox
  2. Get an OpenWrt image openwrt-x86-64-combined-ext4.img.gz from targets/x86/64/ folder. Direct snapshot download
  3. Uncompress the image: gunzip openwrt.img.gz
  4. Convert it to native VirtualBox format:
VBoxManage convertfromraw --format VDI openwrt.img openwrt.vdi
@stokito
stokito / pages.html
Last active Jul 7, 2022
bootstrap-table.com pagination with ajax call. Optionally filter with date range
View pages.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha256-YvdLHPgkqJ8DVUxjjnGVlMMJtNimJ6dYkowFFvp4kKs=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.2/font/bootstrap-icons.css" integrity="sha256-YW7U7x59rUPZ3DWzQKbalM/9j2Cp8wapJVQPRxL4w1k=" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha256-9SEPo+fwJFpMUet/KACSwO+Z/dKMReF9q4zFhU/fT9M=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-table@1.20.2/dist/bootstrap-table.min.cs
@stokito
stokito / somehost.conf
Last active Jul 7, 2022 — forked from tomkersten/somehost.conf
Nginx config with CORS headers added and Basic Auth
View somehost.conf
server {
server_name example.com;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
root /var/www/html;
access_log off;
location / {
if ($request_method = 'OPTIONS') {
@stokito
stokito / date_utils.go
Created Jul 1, 2022
Start-End date parsing
View date_utils.go
func handleRequest(w http.ResponseWriter, r *http.Request) {
args := r.URL.Query()
startDateStr := args.Get("start") // &start=2021-10-15
endDateStr := args.Get("end") // &end=2021-10-15
startDate := parseDate(startDateStr, "today")
endDate := parseDate(endDateStr, "tomorrow")
}
func atMidnight(startDate time.Time) time.Time {
return startDate.Truncate(24 * time.Hour).In(time.UTC)
@stokito
stokito / onion-gen.js
Created Jun 28, 2022 — forked from ttaubert/onion-gen.js
Generating custom .onion names with the WebCrypto API
View onion-gen.js
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/*
* thirty-two
* https://github.com/chrisumbel/thirty-two
*