Skip to content

Instantly share code, notes, and snippets.

View fedir's full-sized avatar
🌤️
The sun is behind every cloud

Fedir RYKHTIK fedir

🌤️
The sun is behind every cloud
View GitHub Profile
@fedir
fedir / logAnonymizeIps.sh
Last active December 18, 2019 11:12
SHELL > Replace any IP by G.D.P.R :)
#!/bin/bash
sed -i -e 's/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/G.D.P.R/g' some.log
@fedir
fedir / showMailQueue.sh
Created December 16, 2019 14:06
Show Postfix's mail queue content
for emails in `mailq | awk '/^[0-9A-F][0-9A-F]/{print $1}'`; do postcat -q $emails;done
@fedir
fedir / pdf_compress.sh
Last active October 8, 2019 13:07
PDF compression with gs (works well on Linux Mint)
# Compressing to EBook quality (between "screen" and "preprocess")
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
# Black and white output, with custom resolution
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dCompressFonts=true -r150 -dNOPAUSE -dQUIET -dBATCH -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -sOutputFile=output.pdf input.pdf
@fedir
fedir / result_check.md
Last active July 22, 2020 20:02
Install WKHTMLTOPDF / WKHTMLTOX on CentOS

Installation verification

Bad

$ wkhtmltopdf https://www.google.fr output.pdf
Loading pages (1/5)
Error: Failed loading page https://www.google.fr (sometimes it will work just to ignore this error with --ignore-load-errors)

Good

@fedir
fedir / dd_dsync_check.sh
Last active March 15, 2022 20:59
Disk performance check with dd dsync (synchronized I/O for data)
#!/bin/bash
# Small files (64KB)
dd if=/dev/zero of=./dsync64KB.img bs=64 count=1000 oflag=dsync 2>&1|tee dsync-test-1-64KB.log
# Medium files (8MB)
dd if=/dev/zero of=./dsync8MB.img bs=8k count=1000 oflag=dsync 2>&1|tee dsync-test-2-8MB.log
# Big files (128MB)
dd if=/dev/zero of=./dsync128MB.img bs=128k count=1000 oflag=dsync 2>&1|tee dsync-test-3-128MB.log
@fedir
fedir / slice_filtering.go
Last active March 13, 2019 16:00
golang > the fastest version of a slice of structs filtering will be a recreation of new slice of structs
// ref. https://pauladamsmith.com/blog/2016/07/go-modify-slice-iteration.html
y := x[:0]
for _, n := range x {
if n.property !=42 {
y = append(y, n)
}
}
// If some further sorting should be done, requires Go 1.8+
// https://stackoverflow.com/a/42872183/634275
@fedir
fedir / go_imagemagickgo_pdf.md
Last active March 8, 2019 16:54
Go > ImageMagick & JPG2PDF on Debian / Ubuntu

Go > ImageMagick & JPG2PDF on Debian / Ubuntu

Installation

sudo apt-get install libmagickwand-dev
go get -u gopkg.in/gographics/imagick.v2/imagick

Additional ressources

@fedir
fedir / fix_mysql_too_many_fiels.md
Created March 8, 2019 11:47
Fix MySQL "[ERROR] Error in accept: Too many open files" on start on Debian

Fix MySQL "[ERROR] Error in accept: Too many open files" on start

Check system limtis

cat /proc/$(cat /var/run/mysqld/mysqld.pid)/limits

Update system limits

$ vim /etc/security/limits.conf
@fedir
fedir / iptables_route_ports.md
Created March 7, 2019 18:19
iptables routes port 80 to 4000

iptables port routing from 80 to 4000

Configuration

Route via iptables

$ iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 4000

Make it persistent (on Debian, Ubuntu)

@fedir
fedir / argon2i.php
Last active February 21, 2019 10:37
PHP Argon2i test
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
echo password_hash("test", PASSWORD_ARGON2I) . "\n";
// expected output:
// $argon2i$v=19$m=1024,t=2,p=2$Si9YUTV5Mk50clRPckJmNg$iiaHUvfJpx2fwVJLUDr2J0XePR31gxxIu5VHlgFMA/k