Skip to content

Instantly share code, notes, and snippets.

@dongliu
dongliu / proxy.js
Last active August 29, 2015 14:10
reverse proxy express
/**
* @fileOverview a middleware for express deployment behind a reverse proxy
* @param {string} proxy - the known reverse proxy host
* @param {string} proxied_service - the url assigned by proxy
* @return {function} the middleware
* /
function proxied (proxy, proxied_service) {
return function (req, res, next) {
req.proxied = false;
req.proxied_prefix = '';
@dongliu
dongliu / example
Last active August 29, 2015 14:14
bootstrap progress bar with markers and labels
mixin progress(id)
.bar-wrap
.progress.no-extra-space(id=id)
.progress-marker(style='right:25%')
.progress-marker(style='right:50%')
.progress-marker(style='right:75%')
mixin time-axis
.time-axis
.time-spot-end now
.time-spot.text-center 6 hours ago
@dongliu
dongliu / page.js
Last active August 29, 2015 14:20
typeahead example and bootstrap style
travelerGlobal.usernames.initialize();
$('#username').typeahead({
minLength: 1,
highlight: true,
hint: true
}, {
name: 'usernames',
display: 'displayName',
limit: 20,
/*!
* Bootstrap v3.3.5 (http://getbootstrap.com)
* Copyright 2011-2015 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
html {
font-family: sans-serif;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
@dongliu
dongliu / json2list.js
Created June 18, 2012 22:53
Convert a json object to an html dl list
function Json2List(json) {
var output = '';
for (var k in json) {
if (json.hasOwnProperty(k)) {
if (typeof(json[k]) == 'object') {
output = output + '<dl>' + '<dt>' + k + '</dt>' + '<dd>' + Json2List(json[k]) + '</dd>' + '</dl>';
} else {
output = output + '<b>' + k + '</b>' + ' : ' + json[k] + '<br/>';
}
}
@dongliu
dongliu / gist:3130674
Created July 17, 2012 17:22
sublime 2 text replace -(dash) in id with _(underscore)
find what: #(\w+_)*(\w+)-
replace with: #$1$2_
@dongliu
dongliu / snapshot_pv.py
Created November 16, 2012 17:50
snapshot pv
start = time.time()
for pv_name in pv_list:
pv = PV(pv_name)
if pv.wait_for_connection(timeout=1.0):
result[pv_name] = pv.get(use_monitor=False)
else:
result[pv_name] = 'not connected'
duration = time.time() - start
print int(round(duration * 1000))
@dongliu
dongliu / snapshot_ca.py
Created November 16, 2012 17:53
snapshot ca
start = time.time()
for pv_name in pv_list:
ch = ca.create_channel(pv_name, connect=False, auto_cb=False)
result[pv_name] = [ch, None, None]
for pv_name, data in result.items():
result[pv_name][1] = ca.connect_channel(data[0], timeout=1.0)
ca.poll()
for pv_name, data in result.items():
if result[pv_name][1]:
ca.get(data[0], wait=False)
@dongliu
dongliu / pv_threading.py
Created November 16, 2012 21:28
snapshot pv multi-threading
# ...
from multiprocessing import Process, Manager
def get(d, pv_name, size, start, pid):
pv = PV(pv_name)
if pv.wait_for_connection(timeout=1.0):
d[pv_name] = pv.get(use_monitor=False)
else:
d[pv_name] = 'not connected'
if len(d) == size:
@dongliu
dongliu / snapshot_ca_threading.py
Created November 16, 2012 21:30
snapshot ca multi-threading
def get(d, pv_name, size, start, pid):
ch = ca.create_channel(pv_name, connect=False, auto_cb=False)
if ca.connect_channel(ch, timeout=1.0):
d[pv_name] = ca.get(ch, wait=True)
else:
d[pv_name] = 'not connected'
if len(d) == size:
print int(round((time.time() - start) * 1000))
os.kill(pid, signal.SIGTERM)