Skip to content

Instantly share code, notes, and snippets.

Utkarsh Upadhyay musically-ut

Block or report user

Report or block musically-ut

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:1301233
retcode = p.poll() # Check on the application
if retcode is not None: # The application exited
break
View gist:1301248
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()
View gist:1301261
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 Oct 21, 2011
Restarting 'lolprogram' on restarts (by Nirbheek)
View lolprogram_reliable.py
retcode = 1
while retcode:
retcode = subprocess.call(["lolprogram", "arg1", "arg2"])
print("Exiting with return code 0")
@musically-ut
musically-ut / heartbeat_logic.py
Created Oct 21, 2011
Heartbeats in the wrapper
View heartbeat_logic.py
# '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 Oct 21, 2011
Dealing with kill commands from the outside world
View in_cmd_logic.py
# '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:
View test.R
test <- function() {
return(c(1,2,3));
}
@musically-ut
musically-ut / stddevcalc.cpp
Created Dec 20, 2011
Naive standard deviation calculation
View stddevcalc.cpp
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 Dec 20, 2011
Knuth's numerically stable standard deviation calculation
View KnuthStdDev.cpp
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 Dec 20, 2011
Testing Standard Deviation calculation
View stddevcalc_test.cpp
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);
You can’t perform that action at this time.