Skip to content

Instantly share code, notes, and snippets.

View vegitron's full-sized avatar

Patrick Michaud vegitron

  • University of Washington
View GitHub Profile
for registration in json_data.get('Registrations', []):
if is_unfinished_pce_course(registration):
unf_pce_course = _json_to_unfinished_pce_course(registration, term)
key = unf_pce_course.section_ref.section_label()
enrollment.unf_pce_courses[key] = unf_pce_course
Trace: What called me?
at /home/pmichaud/lrs/cloud-lrs/node_modules/lrs-users/lib/api.js:69:13
at Model.<anonymous> (/home/pmichaud/lrs/cloud-lrs/node_modules/lrs-core/lib/globals/sequelize.js:69:16)
at Model.tryCatcher (/home/pmichaud/lrs/cloud-lrs/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/pmichaud/lrs/cloud-lrs/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/home/pmichaud/lrs/cloud-lrs/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/home/pmichaud/lrs/cloud-lrs/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/pmichaud/lrs/cloud-lrs/node_modules/bluebird/js/release/promise.js:693:18)
at Promise._fulfill (/home/pmichaud/lrs/cloud-lrs/node_modules/bluebird/js/release/promise.js:638:18)
at Promise._settlePromise (/home/pmichaud/lrs/cloud-lrs/node_modules/bluebird/js/release/promise.js:582:21)
Using python's httplib, there is no way to set a timeout for the full request cycle. A timeout can be given, which will apply to the connection attempt and each blocking socket operation.
However, a malicious (or poorly performing) server can keep a connection open for an indefinite amount of time by slowly sending data. Consider this server process:
https://gist.github.com/vegitron/bc883ddc88fe9253adc3e0bccea6445e
and this client:
https://gist.github.com/vegitron/4ee269b6492ff80d350e108363689d5c
With a timeout of 0.5, the client takes 0.501363039017 seconds. With a timeout of 2.5, it takes 10.0041370392 seconds.
import httplib
import time
from socket import timeout
HOST = "my test host"
start = time.time()
try:
conn = httplib.HTTPConnection(HOST, timeout=0.5)
conn.request(method="GET", url="/tmp/slow.php")
<?php
if (ob_get_level())
ob_end_clean();
for ($i = 0; $i < 10; $i++) {
sleep(1);
echo("Slept\n");
@vegitron
vegitron / slow_server.py
Created January 5, 2017 16:29
A server that bypasses httplib's timeout
import BaseHTTPServer
import SocketServer
import time
class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(s):
s.send_response(200)
s.send_header("Content-type", "text/html")
s.end_headers()
for i in range(100):
diff --git a/playbooks/includes/django-managed-post-checkout.yml b/playbooks/includes/django-managed-post-checkout.yml
index 9110c0d..a268dd9 100644
--- a/playbooks/includes/django-managed-post-checkout.yml
+++ b/playbooks/includes/django-managed-post-checkout.yml
@@ -16,7 +16,7 @@
when: pip_upgrades_files is defined
- name: Install requirements with pip. May (probably will) take a while
- shell: source {{ base_dir }}/builds/{{current_build_value}}/bin/activate && PIP_ACCEL_CACHE={{ pip_accel_cache_dir }} pip-accel install -r {{ base_dir }}//builds/{{current_build_value}}/{{ item }} -i {{ pypi_mirror | default("https://pypi.s.uw.edu/root/pypi/+simple") }}
+ shell: source {{ base_dir }}/builds/{{current_build_value}}/bin/activate && cd {{ base_dir }}/builds/{{current_build_value}} && PIP_ACCEL_CACHE={{ pip_accel_cache_dir }} pip-accel install -r {{ base_dir }}//builds/{{current_build_value}}/{{ item }} -i {{ pypi_mirror | default("https://pypi.s.uw.edu/root/pypi/+simple"
import re
import sys
class BFBuild(object):
byte_var_table = {}
current_var_index = 0
python = ""
def __init__(self, python):
self.python = python
bash-3.2$ time echo "hello" | sleep 2
real 0m2.003s
user 0m0.001s
sys 0m0.002s
bash-3.2$ echo "ok" | time echo "hello" | sleep 2
0.00 real 0.00 user 0.00 sys
bash-3.2$
diff --git a/myuw/static/js/myuw_log.js b/myuw/static/js/myuw_log.js
index 90158e6..f1850e7 100644
--- a/myuw/static/js/myuw_log.js
+++ b/myuw/static/js/myuw_log.js
@@ -263,9 +263,11 @@ var LogUtils = {
},
get_all_cards: function(){
+ console.log("------------ Setting card, with positions");
var cards = [],