Skip to content

Instantly share code, notes, and snippets.

View split_file_into_two_parts.sh
FILE="myfile.txt"
split -l $(( $(wc -l "$FILE" | cut -d" " -f1) / 2 )) "$FILE" "$FILE_split_"
@mperlet
mperlet / gist:563055c0b7df5f2af8968568d685ab21
Created Jun 10, 2017
Merge mp4 files with ffmpeg in one bash line
View gist:563055c0b7df5f2af8968568d685ab21
# input current mp4 files, output: merged.mp4
ls *mp4 | sed "s#^#file '#g" | sed "s#\$#'#g" > tm.txt && ffmpeg -f concat -safe 0 -i tm.txt -c copy merged.mp4 && rm tm.txt
@mperlet
mperlet / crt_to_pem.sh
Created Jun 9, 2017
Shell function to convert .crt to .pem files. Useage: crt_to_pem <my_cert_without_ext>
View crt_to_pem.sh
crt_to_pem = function() {
openssl x509 -in "$1.crt" -out "$1.pem" -outform PEM
}
@mperlet
mperlet / cpdf.sh
Created Jun 6, 2017
compress pdf file $> cpdf my_large_pdf_file.pdf
View cpdf.sh
function cpdf() {
/usr/bin/gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$1.compress.pdf $1
}
View 120secondsofyes.sh
for i in {0..20}
do
yes > /dev/null &
done; sleep 120; kill -9 $(pidof yes)
@mperlet
mperlet / pmap.py
Created Apr 12, 2017
parallel python map function
View pmap.py
def pmap(func, iter, pool_size=4):
""" Like pythons map() function but parallel """
from multiprocessing.dummy import Pool
return Pool(pool_size).map(func, iter)
@mperlet
mperlet / latex commands
Created Apr 6, 2017
list most used latex commands
View latex commands
find . -name "*.tex" -exec cat {} \; | sed "s# #\n#g" | sed "s#\t##g" | sort | grep '^\\' | grep -v '\\end' | uniq -c | sort -nr | head -n100
@mperlet
mperlet / check_iban.py
Created Apr 5, 2017
Python IBAN Checker
View check_iban.py
# Based on http://codereview.stackexchange.com/questions/135366/python-iban-validation
import string
def is_iban(unchecked_iban):
LETTERS = {ord(d): str(i) for i, d in enumerate(string.digits + string.ascii_uppercase)}
def _number_iban(iban):
@mperlet
mperlet / deep_photo_styletransfer_install_example.sh
Created Mar 28, 2017
deep-photo-styletransfer vagrant setup history
View deep_photo_styletransfer_install_example.sh
sudo apt-get update
sudo apt-get install octave git libmatio2 libprotobuf-dev protobuf-compiler nvidia-cuda-toolkit octave-image
git clone https://github.com/luanfujun/deep-photo-styletransfer.git
cd deep-photo-styletransfer/
bash models/download_models.sh
cd ..
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; bash install-deps;
./install.sh
@mperlet
mperlet / cpdf.sh
Created Mar 28, 2017
Shell function to compress pdf file usage: cpdf my_big_document.pdf
View cpdf.sh
function cpdf() {
/usr/bin/gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$1.compress.pdf $1
}