Skip to content

Instantly share code, notes, and snippets.

View Eddy-Barraud's full-sized avatar

Eddy Barraud Eddy-Barraud

View GitHub Profile
@Eddy-Barraud
Eddy-Barraud / gethint.php
Last active May 6, 2019 18:59
Sample for converting textarea containing links with php & ajax
<?php
$q = trim($_POST["q"]);
$lines = explode(PHP_EOL, $q);
$result = "";
foreach ($lines as $key => $value) {
$result .= $value . PHP_EOL;
}
echo $result;
exit;
?>
@Eddy-Barraud
Eddy-Barraud / count-number-of-lines-in-each-files.md
Created March 14, 2019 17:16
sum the number of lines in each file of a folder

Run this command to sum the number of lines in each file of a folder

find . -maxdepth 1 -type f -exec wc -l {} + | awk '{sum+=$1} END {print sum}'

@Eddy-Barraud
Eddy-Barraud / number-of-files.md
Last active February 16, 2019 12:17
List folders by the number of files inside of it, recursively

This one line command will list each folders in current path by the number of files inside of it, recursively.

find . -type d -exec sh -c "fc=\$(find '{}' -type f | wc -l); echo \"\$fc\t{}\"" \; | sort -nr

For only one/specified level of recursion :

find . -maxdepth 1 -type d -exec sh -c "fc=\$(find '{}' -type f | wc -l); echo \"\$fc\t{}\"" \; | sort -nr
@Eddy-Barraud
Eddy-Barraud / nginx_webp.conf
Created January 25, 2019 17:46
Serves webp images instead of jpg or png if supported by browser
http {
##
# WebP conf
##
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
@Eddy-Barraud
Eddy-Barraud / ALL-m4a-to-mp3.sh
Created December 30, 2018 12:55
convert each m4a inside a folder to mp3
find . -type f -name '*.m4a' -exec bash -c 'avconv -i "$0" "${0/%m4a/mp3}"' '{}' \;

Install fail2ban

apt install fail2ban

Fail2ban will ban IPs reported in log files. So, you need to configure it to know wich reported IP is to ban.

All configs are located in /etc/fail2ban/ A jail is configured inside the jail.local file that will overwrite jail.conf. It refferes to a filter file inside the filter.d folder. Here are some usefull example of jails.

[DEFAULT]

@Eddy-Barraud
Eddy-Barraud / nginx-amp.conf
Last active January 20, 2019 14:35
Redirect every mobiles to the amp version of the site with map and try files
http{
...
##
#AMP
##
map $http_user_agent $mobile_agent{
default "";
"~*android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino" "/amp/";

PyInstaller Quickstart

Install PyInstaller from PyPI:

pip install pyinstaller

Go to your program’s directory and run:

pyinstaller yourprogram.py

It will generate an executable in a dist folder

from functools import reduce
from sympy import Symbol
X = Symbol('X')
def Lagrange(points):
P=[reduce((lambda x,y: x*y),[(X-points[j][0])/(points[i][0] - points[j][0]) for j in range(len(points)) if i != j])*points[i][1] for i in range(len(points))]
return sum(P)