Skip to content

Instantly share code, notes, and snippets.

View RainMark's full-sized avatar

RainMark

View GitHub Profile
@algal
algal / colorize-emacs.bashsource
Last active August 4, 2023 17:46
Setting up truecolor (24 bit color) in emacs in the terminal, under iTerm2, blink.sh, and others.
# sourcing this file will define a bash functions that
# tries to run subsequent calls to emacs with 24 bit color.
#
# It sets TERM=xterm-emacs-leg if
# - we've created a user-local terminfo record for xterm-emacs-leg, and
# - we're using iTerm2 or something has set COLORTERM=truecolor
#
# This will cause emacs to use 24 bit color only when it will work,
# inside or outside of tmux. I haven't found a way to auto-detect Blink.sh yet.
#
@antonfirsov
antonfirsov / install-liburing.sh
Last active January 26, 2022 00:49
Patch Ubuntu 18.04 LTS for io_uring
mkdir liburing
pushd liburing
git clone https://github.com/axboe/liburing.git
pushd liburing
./configure
make
sudo make install
popd
@toke
toke / anybind_aio.py
Created January 28, 2020 13:06
Using TPROXY to bind to any port on many IPs (asyncio variant)
import asyncio
import socket
BIND_IP = "127.0.0.1"
TCP_PORT = 1234
SOCK_BACKLOG = 32
IP_TRANSPARENT = 19
desc = f"""
Anybind; "bind" on many IPs and many Ports.
@darkr4y
darkr4y / httpsrv.py
Last active May 2, 2024 20:42
python simple http server with upload & download
#!/usr/bin/env python
"""Extend Python's built in HTTP server to save files
curl or wget can be used to send files with options similar to the following
curl -X PUT --upload-file somefile.txt http://localhost:8000
wget -O- --method=PUT --body-file=somefile.txt http://localhost:8000/somefile.txt
__Note__: curl automatically appends the filename onto the end of the URL so
@dmfigol
dmfigol / asyncio_loop_in_thread.py
Last active June 30, 2024 09:29
Python asyncio event loop in a separate thread
"""
This gist shows how to run asyncio loop in a separate thread.
It could be useful if you want to mix sync and async code together.
Python 3.7+
"""
import asyncio
from datetime import datetime
from threading import Thread
from typing import Tuple, List, Iterable
wget -O /tmp/YaHei.Consolas.1.12.zip https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/uigroupcode/YaHei.Consolas.1.12.zip
unzip /tmp/YaHei.Consolas.1.12.zip
sudo mkdir -p /usr/share/fonts/consolas
sudo mv YaHei.Consolas.1.12.ttf /usr/share/fonts/consolas/
sudo chmod 644 /usr/share/fonts/consolas/YaHei.Consolas.1.12.ttf
cd /usr/share/fonts/consolas
sudo mkfontscale && sudo mkfontdir && sudo fc-cache -fv
@mjambon
mjambon / parallel
Last active March 28, 2024 11:09
bash: Run parallel commands and fail if any of them fails
#! /usr/bin/env bash
#
# Run parallel commands and fail if any of them fails.
#
set -eu
pids=()
for x in 1 2 3; do
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active June 29, 2024 04:08
set -e, -u, -o, -x pipefail explanation
@larytet
larytet / test_aio.c
Last active October 12, 2019 02:39
Linux AIO example
/**
* Based on https://www.fsl.cs.sunysb.edu/~vass/linux-aio.txt
* Compile gcc -Wall test_aio.c -o test_aio
* Run rm -rf /tmp/testfile ;./iotest
*/
#define _GNU_SOURCE /* syscall() is not POSIX */
#include <stdio.h> /* for perror() */
#include <unistd.h> /* for syscall() */
@mattbell87
mattbell87 / iptables.md
Last active December 22, 2023 20:25
IPtables for routing over OpenVPN on Linux

Enable forwarding:

sysctl -w net.ipv4.ip_forward=1

Create this script eg sudo nano iptables.sh

eth=$1
proto=$2