Skip to content

Instantly share code, notes, and snippets.

View samdjohnson's full-sized avatar

Sam Johnson samdjohnson

  • Chicago, IL, USA
View GitHub Profile
@samdjohnson
samdjohnson / gist:ac0a62c6099a990e7977493fb475cfb8
Created December 4, 2022 01:44
Tezos Profile Attestation
I am attesting that this GitHub handle samdjohnson is linked to the Tezos account tz1fJ86qDkgPq7uiQsgiWP5dpn99rFSpssoa for tzprofiles
sig:edsigtd7cdVptjxemFU5UmfucZSBo9NZoNkrKYUmDTXwp8i7Rv2VwN5xMCyrk5tUqnxR1JKanQexaeYcWa1iPaopgxWUYd5Hp4B
columns: [
['x', '2010-01-01', '2011-01-01', '2012-01-01', '2013-01-01', '2014-01-01', '2015-01-01'],
['sample', 30, 200, 100, 400, 150, 250]
]
@samdjohnson
samdjohnson / Time Series Aggregation with TempoIQ
Created October 15, 2014 16:09
An example of TempoIQ's aggregate function with the python SDK.
session = get_session('tempo-iq-backend-url', key, secret)
start_time = datetime.datetime(2014,1,1,0,0,0,0)
end_time = datetime.datetime(2014,1,2,0,0,0,0)
results = session.query(Device)
.filter(Device[‘building’] == 1)
.filter(Sensor.key == “temp”)
.interpolate(“linear”, “PT15M”)
.aggregate(“avg”)
@samdjohnson
samdjohnson / Time Series Rollup with TempoIQ
Last active August 29, 2015 14:07
Time Series Roll Up w/ TempoIQ
session = get_session('tempo-iq-backend-url', key, secret)
session.query(Sensor).filter(Device.key == 'foo').rollup(['avg','max','min'], 'PT15M').read()
@samdjohnson
samdjohnson / Time Series Interpolation with TempoIQ
Last active August 29, 2015 14:07
Time Series Interpolation w/ TempoIQ
selection = {
:devices => {:key => device_key}
}
start = Time.utc(2014, 1, 1)
stop = Time.utc(2014, 1, 2)
rows = client.read(selection, start, stop) do |pipeline|
pipeline.interpolate("PT1S", :linear, start, stop)
end.to_a
@samdjohnson
samdjohnson / data_calculator
Last active August 29, 2015 14:06
A Pen by Sam Johnson.
<div id="sensor_data_calculator">
<h3>How Much Data Will Your Sensors Generate?</h3>
<p>I have <span data-var="devices" class="TKBigNumberField pull-right" data-size="12"> devices</span> with <span data-var="sensors" class="TKBigNumberField pull-right" data-size="12"> sensors each,</span></p>
<p class="pull-right">collecting data <span data-var="collection_frequency" class="TKBigNumberField" data-size="2"> time(s)</span> every
<select data-var="collection_period" class="TKSelectField">
<option value="second"> second</option>
<option value="minute"> minute</option>
<option value="hour">hour</option>
<option value="day">day</option>
</select>
@samdjohnson
samdjohnson / csrf.js
Created March 6, 2013 20:42
Include this js file on django project templates to automagically protect from CSRF on ajax requests. Originally from https://docs.djangoproject.com/en/dev/ref/contrib/csrf/ Requires jQuery.
$(function(){
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));