Skip to content

Instantly share code, notes, and snippets.

View Shonke's full-sized avatar
😗
I may be slow to respond.

xiaoke Shonke

😗
I may be slow to respond.
View GitHub Profile
@72lions
72lions / concat.array.buffers.js
Created January 14, 2013 09:22
Concatenates two ArrayBuffers
/**
* Creates a new Uint8Array based on two different ArrayBuffers
*
* @private
* @param {ArrayBuffers} buffer1 The first buffer.
* @param {ArrayBuffers} buffer2 The second buffer.
* @return {ArrayBuffers} The new ArrayBuffer created out of the two.
*/
var _appendBuffer = function(buffer1, buffer2) {
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
@dpino
dpino / ns-ipv6-no-nat.sh
Created April 29, 2016 22:19
Create Network Namespace with IPv6 connectivity via Hurricane Electric tunnel (no NAT66 needed)
#!/usr/bin/env bash
set -x
if [[ $EUID -ne 0 ]]; then
echo "You must run this script as root."
exit 1
fi
# Fill up IPv6 addresses for the veth pair. Addresses must belong to the
@bom-d-van
bom-d-van / mysql-tcpdump.sh
Last active February 19, 2025 12:18
tcpdump advanced filters
# https://www.percona.com/blog/2008/11/07/poor-mans-query-logging/
tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER)/i) {
if (defined $q) { print "$q\n"; }
$q=$_;
} else {
$_ =~ s/^[ \t]+//; $q.=" $_";
}
@staltz
staltz / music.md
Last active November 23, 2024 22:31
coding music

Not for everyone. Each programmer has their own appreciation of what is good coding music.

For when I need to think deep, debug something, or design

(From most influential to least)

systemd containers

Assumptions

This how-to uses mybox as container name, mkosi in order to create containers (it works for multiple distributions and has more features compared to dnf --installroot), and crudini for configurations file (you can use your preferred text editor instead).

How to create a container with mkosi

# mkosi --cache /var/cache/mkosi -d fedora -t directory -o /var/lib/machines/mybox
@ageis
ageis / systemd_service_hardening.md
Last active February 22, 2025 12:01
Options for hardening systemd service units

security and hardening options for systemd service units

A common and reliable pattern in service unit files is thus:

NoNewPrivileges=yes
PrivateTmp=yes
PrivateDevices=yes
DevicePolicy=closed
ProtectSystem=strict
@mustafaturan
mustafaturan / network-tweak.md
Last active December 31, 2024 19:09
Linux Network Tweak for 2 million web socket connections

Sample config for 2 million web socket connection

    sysctl -w fs.file-max=12000500
    sysctl -w fs.nr_open=20000500
    # Set the maximum number of open file descriptors
    ulimit -n 20000000

    # Set the memory size for TCP with minimum, default and maximum thresholds 
 sysctl -w net.ipv4.tcp_mem='10000000 10000000 10000000'
@Luzifer
Luzifer / README.md
Last active August 25, 2024 10:01
Running docker-compose as a systemd service

Running docker-compose as a systemd service

Files

File Purpose
/etc/compose/docker-compose.yml Compose file describing what to deploy
/etc/systemd/system/docker-compose-reload.service Executing unit to trigger reload on docker-compose.service
/etc/systemd/system/docker-compose-reload.timer Timer unit to plan the reloads
/etc/systemd/system/docker-compose.service Service unit to start and manage docker compose
# Load the contents of the receipt file
receipt_file = open('./receipt_data.bin', 'rb').read()
# Use asn1crypto's cms definitions to parse the PKCS#7 format
from asn1crypto.cms import ContentInfo
pkcs_container = ContentInfo.load(receipt_file)
# Extract the certificates, signature, and receipt_data
certificates = pkcs_container['content']['certificates']
signer_info = pkcs_container['content']['signer_infos'][0]