Skip to content

Instantly share code, notes, and snippets.

View m4nh's full-sized avatar

Daniele De Gregorio m4nh

  • eyecan.ai
  • Italia
View GitHub Profile
@m4nh
m4nh / sh
Last active May 2, 2020 22:39
#bash #for #loop to #print indices #zeropadding
#!/bin/bash
for i in $(seq -f "%05g" 00 10 50);
do
echo $i
done
@m4nh
m4nh / sh
Last active May 2, 2020 22:39
#bash script to #remove #delete #files recursively choosing type
find . -name "*.xml" -type f|xargs rm -f
@m4nh
m4nh / gist:9226c5ea6b295c79b369a939aea5ebb5
Last active May 2, 2020 22:37
#bash script to #copy recursively files form source folder to *destination* with Exclusion pattern
rsync -avz --exclude '*.txt' source/ destination/
@m4nh
m4nh / print_image.py
Last active May 2, 2020 22:38
#python function to print an #image within #console using special characters and colors
import sys, numpy as np, fire, sty
from PIL import Image
def print_image(filename, scale=0.1, ratio=7/4, character='█'):
"""
Args:
filename (Str): input image
scale (float): output scale. Default [0.1], means 48 cells width
ratio (float): image2cells ratio. Default [7/4]
character (char): character used to fill cells
@m4nh
m4nh / tree_with_defaultdict.py
Created May 2, 2020 22:45
#python #hack to build recursive #tree with #dict
# Definition
from collections import defaultdict
def tree(): return defaultdict(tree)
# Sample
t = tree()
t['one']['two']['three']=1.23
@m4nh
m4nh / pytest.sh
Created May 13, 2020 12:51
#pytest samples
# launch pytest on single file/class/function
pytest <FILE_NAME>::<CLASS_NAME>::<FUNCTION_NAME>
@m4nh
m4nh / nbstripout_as_precommit_hook.md
Last active June 3, 2024 02:17
#nbstripout #pre-commit #hook

Install nbstripout

pip install --upgrade nbstripout

in target repository:

nbstripout --install
@m4nh
m4nh / profiling_samples.md
Created May 20, 2020 11:10
#python #profiling

Timing test:

%timeit -n 1 -r 1 test_function()

where n is the number of consecutive tests and r is the repetition for each test

Simple Profile

@m4nh
m4nh / images_to_video.sh
Last active August 5, 2020 14:35
#ffmpeg #video from #images
# Create from folder
ffmpeg -framerate 1 -pattern_type glob -i '/tmp/ciao/*.png' -c:v libx264 -r 30 -pix_fmt yuv420p /tmp/out.mp4
# Repeat video until CTRL+c (is very dense! )
ffmpeg -stream_loop -1 -i /tmp/out.mp4 -c copy /tmp/out_repeat.mp4
# Convert into MP4 yuv420p