Skip to content

Instantly share code, notes, and snippets.

View mvallebr's full-sized avatar

Marcelo Elias Del Valle mvallebr

View GitHub Profile
import sys
import threading
import logging
class EventScheduler(threading.Thread):
def __init__(self, event_callback, interval):
logging.info("creating scheduler")
super(EventScheduler, self).__init__()
self.setDaemon(True)
self.event_callback = event_callback
@mvallebr
mvallebr / rename.sh
Created December 11, 2015 13:23
rename files using sed
#!/bin/ksh
if [ "$#" -ne 3 ] || ! [ -d "$1" ]; then
echo "Usage: $0 FOLDER ORIGIN DEST" >&2
exit 1
fi
FOLDER=$1
ORIGIN_STRING=$2
REPLACEMENT_STRING=$3
@mvallebr
mvallebr / replace.sh
Created December 11, 2015 13:24
Replace strings in files using sed
#!/bin/ksh
if [ "$#" -lt 3 ]; then
echo "Usage: $0 alt_replace ORIGIN DEST FILEMASK" >&2
exit 1
fi
ORIGIN_STRING=$1
REPLACEMENT_STRING=$2
for ORIG in $(grep -rl $ORIGIN_STRING ${*:3})
@mvallebr
mvallebr / merge.py
Last active February 4, 2016 10:47 — forked from renzon/merge.py
Code to merge two ordered iterables
def _le(left, right):
return left if left <= right else right
def merge(left, right, cmp=_le):
"""
Merges two ordered iterables (left and right) keeping result ordered according to cmp.
:param left: iterable
:param right: iterable
:param cmp: callable which receive one element from left and another from right and returns the on to be merged.
import threading
import os
import time
stop_flag = False
def funcao(file_path):
while (not os.path.isfile(file_path)):
print('File not found!')
time.sleep(5)
if stop_flag:
import threading
import os
import time
class FileChecker(threading.Thread):
def __init__(self, file_path):
super(FileChecker, self).__init__()
self._stop_flag = False
self._file_path = file_path
@mvallebr
mvallebr / python_transformation.py
Created September 20, 2016 09:48
Example transformation
inputData = {
'fName': 'John',
'lName': 'Doe',
'addresses': [
{
'addr': '177 Pine St',
'city': 'San Jose',
'state': 'CA',
'zip': 95120,
from os import listdir
from os.path import isfile, join
from string import Template
images_folder = "/path/to/your/images/"
image_files= [f for f in listdir(images_folder) if isfile(join(images_folder, f)) and f.endswith(".png")]
li_template = "<li class="escondido" data-src="{}"> <a href><img src="{}"></a>"
li_template_list = [li_template.format(f, f) for f in image_files]
##################################################################################
# Usando head/tail como estado
biggest_of_2 = lambda v1, v2: v1 if v1>=v2 else v2
find_biggest = lambda v: v[0] if len(v) == 1 else biggest_of_2(v[0], find_biggest(v[1:]))
v = [1,2,3,5,6,7,4,1,3,2,8,4]
print ("Biggest element: {}".format(find_biggest(v)))
# Solucao recursiva
def trib_tail (result, current, n):
# print(str(result), current, n)
result.append( result[current-1] + result[current-2] + result[current-3] )
if current < n:
trib_tail(result, current + 1, n)
return result
def tribonacci(signature,n):
return signature[:n] if n-1 <3 else trib_tail(signature[:], 3, n-1)