This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inputData = { | |
| 'fName': 'John', | |
| 'lName': 'Doe', | |
| 'addresses': [ | |
| { | |
| 'addr': '177 Pine St', | |
| 'city': 'San Jose', | |
| 'state': 'CA', | |
| 'zip': 95120, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ################################################################################## | |
| # 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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |