Skip to content

Instantly share code, notes, and snippets.

View stokito's full-sized avatar
Self-hosting become easier 🤗

Sergey Ponomarev stokito

Self-hosting become easier 🤗
View GitHub Profile
@stokito
stokito / 99-disk.conf
Last active March 3, 2023 16:55
Lighttpd WebDAV+BasicAuth+CORS
server.modules += ( "mod_webdav", "mod_setenv" )
$HTTP["url"] =~ "^/dav($|/)" {
webdav.activate := "enable"
server.document-root := "/srv/disk/"
# skip basic auth check for OPTIONS method from CORS preflight request
$HTTP["request-method"] != "OPTIONS" {
auth.backend := "plain"
auth.backend.plain.userfile := "/etc/lighttpd/webdav.shadow"
auth.require := (
@stokito
stokito / alertmanager.yml
Created December 7, 2022 22:39
Prometheus AlertsManager Telegram config
# See https://github.com/prometheus/alertmanager/pull/2827
# https://prometheus.io/docs/alerting/latest/configuration/#telegram_config
route:
group_by: ['alertname']
group_wait: 30s
group_interval: 5m
repeat_interval: 1h
receiver: "telegram"
receivers:
- name: 'telegram'
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 November 7, 2022 21:39
JavaScript resolve DNS from browser
<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 October 14, 2022 08:29
golang fast float rounding
// 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
}
<!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/[email protected]/dist/css/bootstrap.min.css" integrity="sha256-7ZWbZUAi97rkirk4DcEp4GWDPkWpRMcNaEyXGsNXjLg=" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha256-wMCQIK229gKxbUg3QWa544ypI4OoFlC2qQl8Q8xD8x8=" crossorigin="anonymous"></script>
<!-- jquery needed for bootstrap-table-->
@stokito
stokito / prometheus-exposition.js
Created August 24, 2022 19:20
parse Prometheus metrics from JavaScript
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 May 5, 2025 19:09 — forked from jayluxferro/OpenWrt_Virtualbox.md
How to run OpenWrt in VirtualBox

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 July 7, 2022 10:04
bootstrap-table.com pagination with ajax call. Optionally filter with date range
<!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/[email protected]/dist/css/bootstrap.min.css" integrity="sha256-YvdLHPgkqJ8DVUxjjnGVlMMJtNimJ6dYkowFFvp4kKs=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css" integrity="sha256-YW7U7x59rUPZ3DWzQKbalM/9j2Cp8wapJVQPRxL4w1k=" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/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/[email protected]/dist/bootstrap-table.min.cs
@stokito
stokito / somehost.conf
Last active July 7, 2022 09:39 — forked from tomkersten/somehost.conf
Nginx config with CORS headers added and Basic Auth
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') {