Skip to content

Instantly share code, notes, and snippets.

@HouzuoGuo
HouzuoGuo / gist:31e640d4f61229f3e76853bfa4537b05
Created July 6, 2020 05:40
Fix all sorts of timer and sleep issues for Ubuntu 20.04 running in WSL
Solution is taken from: https://github.com/microsoft/WSL/issues/4898#issuecomment-646790723
cat <<'EOF' > nanosleep.c
#include <time.h>
#include <unistd.h>
int nanosleep(const struct timespec *req, struct timespec *rem)
{
return clock_nanosleep(CLOCK_MONOTONIC, 0, req, rem);
}
int usleep(useconds_t usec)
@HouzuoGuo
HouzuoGuo / gist:dbffed31a26359f610f6d9595fb37ef2
Last active April 29, 2020 09:44
Useful system packages (Ubuntu 20.04 LTS)
apt install -y ansible apache2-utils apt-transport-https autoconf automake bash binutils busybox bzip2 caca-utils ca-certificates cgroup-tools cloc cscope ctags curl dateutils dbus diffutils dnsutils dos2unix expat findutils finger gdb gnupg gnutls-bin hostname htop iftop iotop iputils-ping iputils-tracepath lftp lm-sensors locales locales-all lrzsz lsof mailutils make minicom miscfiles moreutils mosh netcat net-tools nicstat nmap nmon openssl p7zip patchutils pciutils procps psmisc rsync screen shellcheck silversearcher-ag snmp socat software-properties-common strace sudo tcpdump tcptraceroute telnet tmux traceroute tree tshark unar uniutils unzip usbutils util-linux util-linux-locales vim wbritish wget whois wiggle yamllint zip zlib1g
@HouzuoGuo
HouzuoGuo / gist:83eaab9a46a8ab3c7473323b34f9ea62
Last active March 22, 2020 11:43
Use PostgreSQL to convert CSV into JSON

Start the server

docker run -it --rm -e POSTGRES_PASSWORD=demo -e POSTGRES_HOST_AUTH_METHOD=trust postgres:10

Prepare DB client

cat <<EOF >test.csv
title,url
"NHS facing Italian-style coronavirus crisis if we don't stay at home, says Boris Johnson",https://www.telegraph.co.uk/politics/2020/03/21/nhs-facing-italian-style-crisis-dont-stay-home-says-boris-johnson/

Italy: PM warns of worst crisis since WW2 as coronavirus deaths leap by almost 800,https://www.theguardian.com/world/2020/mar/22/italian-pm-warns-of-worst-crisis-since-ww2-as-coronavirus-deaths-leap-by-almost-800

@HouzuoGuo
HouzuoGuo / gist:098fb7c5398e1941bbb194eae5171999
Last active January 15, 2020 12:23
Cross-compile and build OpenSSL for 32-bit ARM (with hardware floating point) on an Intel/AMD Ubuntu 18.04 computer
# Run the commands in a docker container: docker run -it --rm ubuntu:18.04
cat > /etc/apt/sources.list <<EOF
deb http://archive.ubuntu.com/ubuntu/ bionic main restricted
deb-src http://archive.ubuntu.com/ubuntu/ bionic main restricted
deb http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted
deb-src http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted
deb http://archive.ubuntu.com/ubuntu/ bionic universe
deb-src http://archive.ubuntu.com/ubuntu/ bionic universe
deb http://archive.ubuntu.com/ubuntu/ bionic-updates universe
deb-src http://archive.ubuntu.com/ubuntu/ bionic-updates universe
@HouzuoGuo
HouzuoGuo / gist:a5326b49cb17b7db2c46900f387dfaf5
Created January 14, 2020 09:03
Cross-compile and build OpenSSL for 32-bit ARM (hard-float) on an Intel/AMD computer
# Edit APT sources list file and uncomment/enable deb-src sources, then:
sudo dpkg --add-architecture armhf
sudo apt-get update
sudo apt-get install crossbuild-essential-armhf
sudo apt-get build-dep -a armhf openssl
apt-get source openssl
cd openssl-1.1.1
debuild -- clean
env DEB_HOST_MULTIARCH=armhf DEB_BUILD_OPTIONS=nocheck debuild -uc -us -aarmhf
section .text
global _start
_start:
push 1
push 2
call add2 ; rax = add2(1, 2)
push 3
push 4
@HouzuoGuo
HouzuoGuo / gist:a5512173a79fce84c3f17d72d8eaaa28
Created September 10, 2019 14:19
I am hguo on keybase.io
### Keybase proof
I hereby claim:
* I am HouzuoGuo on github.
* I am hguo (https://keybase.io/hguo) on keybase.
* I have a public key whose fingerprint is 60BD 93B6 F0C4 FCC7 1735 08D4 4132 7BD9 50FA B38C
To claim this, I am signing this object:
@HouzuoGuo
HouzuoGuo / gist:5becdf602eab2e7e2b5990659e1dc5f9
Created June 18, 2019 06:23
Squid HTTPS proxy - non-transparent proxy inspects TLS destination server name via SNI
debug_options ALL,2
coredump_dir /var/spool/squid
pid_filename /var/run/squid-https.pid
access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
# Avoid interfering with timeout behaviour of TCP client applications
# The timeout values are 10x their default
shutdown_lifetime 10 seconds
@HouzuoGuo
HouzuoGuo / gist:90cea01dbe2c7b6d7815de243a33e1b2
Last active May 16, 2021 08:48
Arduino UNO R3 serial port example: read input string via serial and print it back
void setup()
{
Serial.begin(1200);
Serial.setTimeout(1000);
Serial.println("Microcontroller has started");
}
int seqNum = 0;
String lastRead = "";
@HouzuoGuo
HouzuoGuo / gist:67f054aac42bc05df2bcc7dbb7bfbfe7
Created November 29, 2018 13:13
Forward HTTP traffic from intermediate Squid proxy to an exit Squid proxy
Intermediate proxy, the initial receipient of HTTP traffic:
coredump_dir /var/spool/squid
pid_filename /var/run/squid-http.pid
access_log /var/log/squid-http.log
cache_log /var/log/squid-http.log
via off
cache_peer 127.0.0.1 parent 13129 0 default no-query no-digest
never_direct allow all
http_access allow all