Skip to content

Instantly share code, notes, and snippets.

View binary-signal's full-sized avatar

Evan binary-signal

  • Athens
View GitHub Profile
@binary-signal
binary-signal / supervisor.py
Last active January 22, 2019 22:15
Dead simple Python script supervisor
# -*- 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
@binary-signal
binary-signal / news_producer.py
Created October 31, 2017 07:23
module logging
# 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)
@binary-signal
binary-signal / util.py
Created October 31, 2017 07:22
pid to file
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))
@binary-signal
binary-signal / util.py
Created October 31, 2017 07:21
get the md5 hash of a url
def hashurl(url):
m = hashlib.md5()
m.update(url.encode('utf-8'))
return m.hexdigest()
@binary-signal
binary-signal / util.py
Created October 31, 2017 07:19
get-ip-addr
def get_ip_address():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
return s.getsockname()[0]
@binary-signal
binary-signal / bunnyhophop.sh
Created May 11, 2017 00:09
compile flex parser and run with test input file
#!/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
@binary-signal
binary-signal / rotate.py
Created April 27, 2017 18:43
rotate a node in a list
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]
@binary-signal
binary-signal / is_hamiltonian.py
Created April 27, 2017 18:42
condition to check if graph has hamiltonian cycle
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:
@binary-signal
binary-signal / graph.m
Created April 23, 2017 18:18
graphs in matlab
num_nodes =10
G = graph;
for n=1:num_nodes
G= addnode(G,strcat('node_',int2str(n)));
end
k =G.Nodes