Skip to content

Instantly share code, notes, and snippets.

View musically-ut's full-sized avatar
🐙
🐢 🎣 🐠

Utkarsh Upadhyay musically-ut

🐙
🐢 🎣 🐠
View GitHub Profile
retcode = p.poll() # Check on the application
if retcode is not None: # The application exited
break
@musically-ut
musically-ut / gist:1301248
Created October 20, 2011 14:18
Heartbeats in REPL
end_time = time.time() + 2 * g_TO
all_is_well = True
missed_TO = 0
while True:
try:
(r, w, e) = zmq.select([in_hb, in_cmd], [], [], timeout=end_time - time.time())
for sock in r:
msg = sock.recv()
@musically-ut
musically-ut / gist:1301261
Created October 20, 2011 14:21
On demand killing.
try:
(r, w, e) = zmq.select([in_hb, in_cmd], [], [], timeout=end_time - time.time())
for sock in r:
msg = sock.recv()
# ...
if sock == in_cmd:
print '[monitor] Order to execute'
all_is_well = False
@musically-ut
musically-ut / lolprogram_reliable.py
Created October 21, 2011 10:35
Restarting 'lolprogram' on restarts (by Nirbheek)
retcode = 1
while retcode:
retcode = subprocess.call(["lolprogram", "arg1", "arg2"])
print("Exiting with return code 0")
@musically-ut
musically-ut / heartbeat_logic.py
Created October 21, 2011 10:44
Heartbeats in the wrapper
# 'p' is the Popen object for the subprocess.
end_time = time.time() + 2 * g_TO # Time to initialize
all_is_well = True
missed_TO = 0
while True:
try:
(r, w, e) = zmq.select(
[in_hb, in_cmd], [], [], timeout=end_time - time.time())
@musically-ut
musically-ut / in_cmd_logic.py
Created October 21, 2011 10:49
Dealing with kill commands from the outside world
# 'p' is the Popen object for the subprocess
all_is_well = True
while True:
try:
(r, w, e) = zmq.select(
[in_hb, in_cmd], [], [], timeout=end_time - time.time())
for sock in r:
@musically-ut
musically-ut / test.R
Created October 27, 2011 17:16
Test Gist
test <- function() {
return(c(1,2,3));
}
@musically-ut
musically-ut / stddevcalc.cpp
Created December 20, 2011 15:50
Naive standard deviation calculation
class StdDevCalc {
private:
long long m_count;
double m_sum_sq, m_sum, m_var;
public:
StdDevCalc() {
m_sum_sq = m_sum = m_var = m_count = 0;
}
void append(double d) {
@musically-ut
musically-ut / KnuthStdDev.cpp
Created December 20, 2011 15:55
Knuth's numerically stable standard deviation calculation
class StdDevCalcKnuth {
private:
long long m_count;
double m_meanPrev, m_meanCurr, m_sPrev, m_sCurr, m_varianceCurr;
public:
StdDevCalcKnuth() {
m_count = 0;
}
@musically-ut
musically-ut / stddevcalc_test.cpp
Created December 20, 2011 16:01
Testing Standard Deviation calculation
int main() {
StdDevCalc c, c2;
StdDevCalcKnuth k, k2;
for(int i = 0; i < 100; i++) {
c.append(i); // Small values
k.append(i);
c2.append((double) i * 3e151); // Very very large values
k2.append((double) i * 3e151);