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
Motorola Pulse Plus Headphones Buttons Operation
Music
Play/Pause: Press [Call 📞]
Volume Down/Up: Press [ -< ] or [ >+ ]
Previous / Next Track: Long press [ -< ] or [ >+ ]
Change Equalizer: Long press and [ -< ] AND [ >+ ]
@stokito
stokito / logback.xml
Created August 14, 2019 22:40
Get rid off Janino condition tags for the pattern and simplify it with variable reference The <if> tag requires the Janino library with full java compiler while we just need a simple pattern matching by env var. The solution is to declare two <property> constants with the pattern and then chose one of the constants as a pattern. If SINGLE_LINE_P…
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<property scope="context" name="pattern.singleLine.true" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z', UTC} %5p %logger [%t] \(%X{trace}\) %X{loggingMessageExtender}: %replace(%m%n%ex){'\n(?=[^$])','\\n'}%nopex" />
<property scope="context" name="pattern.singleLine.false" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z', UTC} -%5p %logger [%t] \(%X{trace}\) %X{loggingMessageExtender}: %m%n" />
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<Pattern>${pattern.singleLine.${SINGLE_LINE_PATTERN:-false}}"</Pattern>
</encoder>
</appender>
package com.github.stokito.experiments;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.openjdk.jmh.annotations.Mode.Throughput;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
@stokito
stokito / edit_file.sh
Created September 12, 2019 17:08
The one-liner to open a file in editor (pluma). It will show a file chose dialog and if the file is owned by root it will ask for a sudo password
FILE=$(zenity --file-selection); echo $FILE; if [ -w "$FILE" ]; then pluma "$FILE"; else pkexec pluma "$FILE"; fi;
@stokito
stokito / txt
Created October 28, 2019 00:02
replace single line comments // with multiline comments /*
Search pattern: (.*)(//)(.*)(\n)
Replace with: $1/\*$3 \*/$4
@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
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 / pkg_size.sh
Last active June 24, 2021 03:14
openwrt opkg size of all packages
grep -H Installed-Size: /usr/lib/opkg/info/*.control | sed 's,^.*/\([^/]\+\)\.control:Installed-Size: *\(.*\),\2\t\1,' | sort -n