Skip to content

Instantly share code, notes, and snippets.

eddydu44

Block or report user

Report or block eddydu44

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

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

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}'
@eddydu44
eddydu44 / number-of-files.md
Last active Feb 16, 2019
List folders by the number of files inside of it, recursively
View number-of-files.md

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
@eddydu44
eddydu44 / nginx_webp.conf
Created Jan 25, 2019
Serves webp images instead of jpg or png if supported by browser
View nginx_webp.conf
http {
##
# WebP conf
##
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
@eddydu44
eddydu44 / ALL-m4a-to-mp3.sh
Created Dec 30, 2018
convert each m4a inside a folder to mp3
View ALL-m4a-to-mp3.sh
find . -type f -name '*.m4a' -exec bash -c 'avconv -i "$0" "${0/%m4a/mp3}"' '{}' \;
View 1.fail2ban.md

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]

@eddydu44
eddydu44 / nginx-amp.conf
Last active Jan 20, 2019
Redirect every mobiles to the amp version of the site with map and try files
View nginx-amp.conf
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/";
View pyinstaller.md

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

View lagrange-poly.py
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)
You can’t perform that action at this time.