Skip to content

Instantly share code, notes, and snippets.

@dariosky
dariosky / dropbox_wise_ignore.py
Last active February 17, 2023 19:30
A Python script to be run in a Dropbox folder - so it exclude all the node_modules and __pycache__ folders - we want them locally but not in the cloud
#!/usr/bin/env python3
import argparse
import os
import shutil
from xattr import xattr
top_folder = "."
CACHE_FOLDERS = {"__pycache__", ".pytest_cache", ".cache"}
@dariosky
dariosky / andre_read.py
Created March 2, 2018 22:38
A Solution for André's puzzle here: https://pastebin.com/C9Zbm3dE
def iterelements(tree):
""" Tree is a list, generate the element with the logic of the problem
element can be a value or a list, when a list recur
"""
for el in tree:
if isinstance(el, list):
yield el # when a list, iterate the list first, then the child
yield from iterelements(el)
else:
yield el
@dariosky
dariosky / ffmpegall.py
Created July 10, 2016 00:47
A wrapper to encode with ffmpeg all video file in the current folder. Ideal for get rid of belly fat around videos. Video are saved in h264 with 1024 long size resolution and mp3 192
#!/usr/bin/env python
# coding=utf-8
import os
import sys
from subprocess import call, Popen, PIPE
VIDEO_EXTENSIONS = {'mov', 'mpeg', 'avi', 'mvk', 'mp4'}
@dariosky
dariosky / buffered_smtp_log.py
Created March 15, 2016 17:01
An SMTPHandler that send mail only on flush: on max size or on termination. Quite configurable.
from __future__ import print_function
import logging
import smtplib
from email.mime.text import MIMEText
from logging.handlers import BufferingHandler
class BufferedSmtpHandler(BufferingHandler):
""" This is a memoryhandler buffer, that never flush with big capacity (just to split MB emails)
that will send a mail using configured smtp at the end
@dariosky
dariosky / ijustcode.py
Created April 14, 2015 20:22
Tribute to Stevie Wonder
#!/usr/bin/python
import collections
__author__ = "Dario Varotto"
""" This was thought while I was showering, sorry :) """
def stevie():
stack = collections.deque()
stack.append("from the bottom")
@dariosky
dariosky / gist:5081432
Created March 4, 2013 10:43
Script for creating a complex mongodb shard for testing purpose on the local machine. Wrote for the Mongodb 102 course (week6) to facilitate the setup. Change the settings on the top of the script and run it. All commands are passed to mongo via subprocess, no pyMongo required. I keep it as mongo shell reference.
#!/bin/env python
# @author: Dario Varotto
"""
Script for creating a complex mongodb shard for testing purpose on the local machine.
Wrote for the Mongodb 102 course (week6) to facilitate the setup.
Change the settings on the top of the script and run it.
All commands are passed to mongo via subprocess, no pyMongo required.
I keep it as mongo shell reference.