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 / prometheus.conf
Last active February 27, 2023 23:52
Prometheus CORS workaround: Use Nginx proxy behind and set CORS header with it
# See https://github.com/prometheus/exporter-toolkit/issues/71
# Make prometheus working on localhost only and to set properly Access-Control-Allow-Origin
# Edit /etc/default/prometheus and
# add --web.listen-address=127.0.0.1:9090
# add --web.cors.origin=\"https.*\"
# The regexp looks ugly because just simple .* will result in Access-Control-Allow-Origin: *
# Then install the Nginx
# sudo apt install nginx
# put the file into /etc/nginx/sites-available/prometheus
# sudo rm /etc/nginx/sites-enabled/default
@stokito
stokito / postgresql-users.sql
Last active February 28, 2023 09:37
PostgreSQL: Setup separate users for application, all permissions for DBA and select only BA
-- The postgres user can create users and grant permissions
-- Change the default postgres user password
ALTER USER postgres PASSWORD '<new-password>';
-- The dba use it for developers or database administrator (DBA)
-- Access is given only to appdb DB.
-- For administering other dbs or users use postgres user
CREATE USER dba WITH PASSWORD '<new-password>';
GRANT ALL PRIVILEGES ON DATABASE appdb TO dba;
GRANT ALL PRIVILEGES ON SCHEMA app TO dba;
@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/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 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 August 13, 2022 10:11 — 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