Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Looking for a job

Sergey Ponomarev stokito

🚀
Looking for a job
View GitHub Profile
@stokito
stokito / curl_request_time.md
Created Sep 15, 2021
Measure request time with curl
View curl_request_time.md
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
@stokito
stokito / howto_webdav_lighttpd_openwrt.md
Last active Sep 13, 2021
WebDAV with Lighttpd on OpenWRT
View howto_webdav_lighttpd_openwrt.md
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 an access to the disk. First you have to install OpenWrt which is a libre firmware for router. Then you need to connect to router via SSH which is a remote command line an execute the commands bellow.

TL;DR

@stokito
stokito / howto_webdav_lighttpd_turrisos.md
Last active Aug 30, 2021
WebDAV with Lighttpd on Turris Omnia (TurrisOS/OpenWRT)
View howto_webdav_lighttpd_turrisos.md

For a vanilla OpenWRT see WebDAV with Lighttpd on OpenWRT Some instructions here are outdated.

Dependencies:

opkg install lighttpd-mod-auth lighttpd-mod-authn_file lighttpd-mod-webdav

Create /etc/lighttpd/conf.d/disk.conf:

@stokito
stokito / wgetN.sh
Last active Jan 16, 2021
bysybox wget -N
View wgetN.sh
FILE=example.txt
wget --header="If-Modified-Since:$(date -R -u -r $FILE | sed 's/\UTC/GMT/')" http://example.com/$FILE
@stokito
stokito / date.sh
Last active Jan 16, 2021
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
View date.sh
#!/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";
View EtagBench.java
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 / haserl.md
Created Jul 12, 2020
Build template-able web page and more.
View haserl.md

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
@stokito
stokito / jwt-decode.sh
Created Feb 2, 2020
OpenWrt specific shell (ash) script to decode JWT token and verify it's signature. Based on https://gist.github.com/stokito/f2d7ea0b300f14638a9063559384ec89
View jwt-decode.sh
#!/bin/ash
# Usage: cat /id_token.txt | jwt-decode.sh --no-verify-sig" > jwt_payload.json
. /usr/share/libubox/jshn.sh
base64_padding()
{
local len=$(( ${#1} % 4 ))
local padded_b64=''
if [ ${len} = 2 ]; then
padded_b64="${1}=="
@stokito
stokito / jwt-decode.sh
Last active Jul 2, 2021 — 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
View jwt-decode.sh
#!/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 / good floats.txt
Created Dec 3, 2019
Good float point numbers: finite IEEE-754 that are always equals or can be sumed without loses. Useful for testing
View good floats.txt
https://www.h-schmidt.net/FloatConverter/IEEE754.html
0.000030517578125
0.00006103515625
0.0078125
0.015625
0.125
0.25
0.5
0.75