Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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/>';
}
}