This file contains 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
# -*- coding: utf-8 -*- | |
""" | |
Dead simple supervisor for python scripts to ensure | |
script terminated normally and got the job done. | |
Why to use this ? | |
tl;dr Programmed a web crawler which crashed many times |
This file contains 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
# top level logging object | |
logFormatter = logging.Formatter("%(asctime)s %(name)s [%(levelname)-5.5s] %(message)s", datefmt='%Y-%m-%d %H:%M:%S') | |
logger = logging.getLogger(__name__) | |
logger.setLevel(logging.INFO) | |
# file level logging object | |
fileHandler = logging.FileHandler("{}".format(logfile)) | |
fileHandler.setFormatter(logFormatter) | |
logger.addHandler(fileHandler) |
This file contains 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 mark_me(main_file): | |
pid = os.getpid() | |
with open('proc.pid', "w") as f: | |
f.write("{} pid:{} ".format(os.path.basename(main_file), pid)) |
This file contains 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 hashurl(url): | |
m = hashlib.md5() | |
m.update(url.encode('utf-8')) | |
return m.hexdigest() |
This file contains 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 get_ip_address(): | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
s.connect(("8.8.8.8", 80)) | |
return s.getsockname()[0] |
This file contains 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/bash | |
clear | |
filex="mylexer.l" # input file for flex | |
folex="lex.yy.c" # output file of flex | |
fogcc="mylexer" # outpuf file of gcc | |
fe1="myprog.fc" # example file to run | |
now="$(date +"%r")" # Get the system time now |
This file contains 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 rotate(path, j): | |
""" | |
rotate list of vertices at vertex j | |
:param path: a list of nodes | |
:param j: vertex to perform rotation at | |
:return: rotated path | |
""" | |
if j in path: | |
i = path.index(j) | |
newpath = path[:i + 1] |
This file contains 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 is_hamiltonian(path, v, n): | |
""" | |
:param path: a list nodes in path | |
:param v: current head | |
:param n: total number of nodes in the graph | |
:return: True if it's a hamiltonian path False otherwise | |
""" | |
if path[0] == v and len(path) == n: | |
return True | |
else: |
This file contains 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
num_nodes =10 | |
G = graph; | |
for n=1:num_nodes | |
G= addnode(G,strcat('node_',int2str(n))); | |
end | |
k =G.Nodes |