Skip to content

Instantly share code, notes, and snippets.

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 Dec 18, 2019
SHELL > Replace any IP by G.D.P.R :)
View logAnonymizeIps.sh
#!/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 Dec 16, 2019
Show Postfix's mail queue content
View showMailQueue.sh
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 Oct 8, 2019
PDF compression with gs (works well on Linux Mint)
View pdf_compress.sh
# 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 Jul 22, 2020
Install WKHTMLTOPDF / WKHTMLTOX on CentOS
View result_check.md

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 Mar 21, 2019
Disk performance check with dd dsync (synchronized I/O for data)
View dd_dsync_check.sh
#!/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 Mar 13, 2019
golang > the fastest version of a slice of structs filtering will be a recreation of new slice of structs
View slice_filtering.go
// 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 Mar 8, 2019
Go > ImageMagick & JPG2PDF on Debian / Ubuntu
View go_imagemagickgo_pdf.md

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 Mar 8, 2019
Fix MySQL "[ERROR] Error in accept: Too many open files" on start on Debian
View fix_mysql_too_many_fiels.md

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 Mar 7, 2019
iptables routes port 80 to 4000
View iptables_route_ports.md

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 Feb 21, 2019
PHP Argon2i test
View argon2i.php
<?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