Skip to content

Instantly share code, notes, and snippets.

View sampottinger's full-sized avatar

A Samuel Pottinger sampottinger

View GitHub Profile
@sampottinger
sampottinger / bootstrap_container.less
Created February 21, 2014 05:32
Putting bootstrap only on stuff that is a child of a dom element with class bootstrap.
.bootstrap {
@import "bootstrap";
}
@sampottinger
sampottinger / labjack_joystick.py
Last active August 29, 2015 13:56
Concept sketch of what a labjack-controlled virtual joystick might look like if built from a JSON file specification.
"""Sketch of what LabJack as joystick might look like.
@author: Sam Pottinger (samnsparky)
@license: GNU GPL v3
"""
import time
import yaml
@sampottinger
sampottinger / unrolled_future_config.js
Last active August 29, 2015 13:56
Unrolled into futures (time is slipping slipping slipping into the future)
function createAcceptFunc(deferred, valuesDict, setupInfo) {
return function (value) {
valuesDict.set(setupInfo.bindingClass, value);
deferred.resolve();
};
}
function createRejectFunc(deferred, errorDict, setupInfo) {
return function (value) {
/**
* Force a redraw on the rendering engine.
**/
function runRedraw()
{
document.body.style.display='none';
document.body.offsetHeight; // no need to store this anywhere, the reference is enough
document.body.style.display='block';
}
$scribeBaseURL = "http://ljsimpleregisterlookup.herokuapp.com/scribe_component?input=";
$escapedInput = urlencode('@registers(' . $view->args[0] . '):' . $view->args[1]);
$renderedHTML = file_get_contents($scribeBaseURL . $escapedInput);
print $renderedHTML;
@sampottinger
sampottinger / module.js
Created February 4, 2014 22:15
Module template
function onModuleLoad () {
}
$.ready(function () {
var framework = new Framework();
framework.on('onModuleLoad', onModuleLoad);
//...
@sampottinger
sampottinger / clarify_words.py
Created December 3, 2013 21:18
Updates pairs ambiguous words in the daxlab database to versions with clarification.
SELECT_TEMPALTE = 'SELECT rowid, snapshot_id, word FROM snapshot_content WHERE word="%s" ORDER BY rowid ASC'
UPDATE_TEMPLATE = 'UPDATE snapshot_content SET word="%s" WHERE rowid=%d'
def exchange_word(cursor, source_word, replace_first_word, replace_second_word):
select_operation = SELECT_TEMPLATE % source_word
results = list(cursor.execute(select_operation))
change_to_first_word_row_ids = results[::2].map(lambda x: x[0])
change_to_second_word_row_ids = results[1::2].map(lambda x: x[0])
for row_id in change_to_first_word_row_ids:
<div id="test-section">
<p>An analog input converts a voltage level into a digital value that can be stored and processed in a computer. Why would you want to measure voltages? There are a multitude of sensors available which convert things like temperature, pressure, etc. into voltages. The voltages can then be easily measured by various kinds of hardware, such as a LabJack T7, and then read into a computer. The computer can then convert the voltage value into it's original type (temperature, pressure, etc) and the value can then be stored in a file, emailed to someone, or used to control something else outside of the computer. The T7 exposes analog inputs through MODBUS registers as demonstrated below.</p>
<p>
First, information about configuration:
@registers(AIN Configuration Registers):AIN#(0:10)_RANGE,AIN#(0:10)_NEGATIVE_CH,AIN#(0:10)_RESOLUTION_INDEX
</p>
<p>
@sampottinger
sampottinger / dedup_and_sort.py
Created October 3, 2013 16:48
A very simple script to combine entries from the TRACER political finance activity database that have the exact same names. Should be run from the command line with two arguments: the location of the CSV file to read entries from and the location where the resulting de-duplicated / sorted list should be written to as CSV.
"""Combine TRACER entries that have the exact same name.
A very simple script to combine entries from the TRACER political finance
activity database that have the exact same names. Should be run from the
command line with two arguments: the location of the CSV file to read entries
from and the location where the resulting deduplicated / sorted list should
be written to as CSV.
@author: Sam Pottinger (samnsparky, gleap.org)
@license: MIT
@sampottinger
sampottinger / pycotracer_sync_update.py
Last active December 22, 2015 21:09
Insert TRACER data into a local db using update to avoid duplicate data (checks for equality using recordID field).
import pycotracer
import pymongo
client = pymongo.MongoClient()
db = client['tracer-records-db-2']
for year in range(2013,2014):
print "fetching tracer records for year",year