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 / good floats.txt
Created December 3, 2019 14:01
Good float point numbers: finite IEEE-754 that are always equals or can be sumed without loses. Useful for testing
https://www.h-schmidt.net/FloatConverter/IEEE754.html
0.000030517578125
0.00006103515625
0.0078125
0.015625
0.125
0.25
0.5
0.75
@stokito
stokito / jwt-decode.sh
Last active June 16, 2023 10:17 — forked from KevCui/jwtDecoder.sh
A shell (ash, dash, Bash) script to decode JWT token. Version ported to OpenWrt here https://gist.github.com/stokito/43afca84fc34d1d362bf210cd941a366
#!/bin/sh
# Decode a JWT from stdin and verify it's signature with the JWT issuer public key
# Only RS256 keys are supported for signature check
#
# Put OAuth server public key in PEM format to /var/cache/oauth/$JWT_KID.key.pub.pem
# You must create the folder first
# $ sudo mkdir -p /var/cache/oauth/
# To converted key from JWK to PEM use https://8gwifi.org/jwkconvertfunctions.jsp or https://keytool.online/
# NOTE: For Google you can get the keys in PEM format via https://www.googleapis.com/oauth2/v1/certs
# Decode the keys with decodeURIComponent()
@stokito
stokito / README.md
Last active January 9, 2022 14:02
OpenWrt specific shell (ash) script to decode JWT token and verify it's signature. Based on https://gist.github.com/stokito/f2d7ea0b300f14638a9063559384ec89

You'll need to instll OpenSSL and it will use about 1.3Mb. So check that it's enought of available space:

df -h | grep /overlay

Then install it:

opkg install openssl-util

It also will install libopenssl1.1 and libopenssl-conf.

@stokito
stokito / haserl.md
Created July 12, 2020 09:50
Build template-able web page and more.

Build template-able web page and more.

busybox httpd

Start the httpd in debug mode:

$ busybox httpd -f -vvv -c ./httpd.conf

See config:

$ cat httpd.conf:
I:test.tt
package com.github.stokito.experiments;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import java.util.StringTokenizer;
@stokito
stokito / date.sh
Last active January 16, 2021 21:45
htpdate service on busybox httpd. Put the script to /cgi-bin/date.sh and call it like curl http://localhost:8080/cgi-bin/date.sh -v
#!/bin/sh
# This is run once a day - don't care about performance
# RFC date must have GMT in the end
# but GNU date return +0000 instead and bb date returns UTC
# So we must strip +0000 or UTC and add GMT ourselves
DATE=$(date -R -u | sed 's/\UTC/GMT/' | sed 's/\+0000/GMT/')
echo "Date: $DATE\nStatus: 200\n";
@stokito
stokito / wgetN.sh
Last active January 16, 2021 22:07
bysybox wget -N
FILE=example.txt
wget --header="If-Modified-Since:$(date -R -u -r $FILE | sed 's/\UTC/GMT/')" http://example.com/$FILE
@stokito
stokito / howto_webdav_lighttpd_turrisos.md
Last active December 17, 2022 22:17
WebDAV with Lighttpd on Turris Omnia (TurrisOS/OpenWRT)

For a vanilla OpenWRT see WebDAV with Lighttpd on OpenWRT. Those instructions are slightly different.

What is this for?

You can turn your router into a small NAS and file server. Just connect an SSD into USB and install a WebDAV server which allows to get access to the disk. Then you need to connect to router via SSH which is a remote command line an execute the commands bellow.

Full instruction

@stokito
stokito / howto_webdav_lighttpd_openwrt.md
Last active October 22, 2023 11:46
WebDAV with Lighttpd on OpenWRT
@stokito
stokito / curl_request_time.md
Created September 15, 2021 14:19
Measure request time with curl
time curl -X POST --location "http://127.0.0.1:8080/url" \
  -H "Content-Type: application/json" \
  -d "{\"id\":\"1234567893\"}" \
  -s -o /dev/null -w "%{time_starttransfer}\n"

Output will be like:

127618