Skip to content

Instantly share code, notes, and snippets.

View benjaminmbrown's full-sized avatar
💭
Visit Chainwave.io

Benjamin Michael Brown benjaminmbrown

💭
Visit Chainwave.io
View GitHub Profile
@benjaminmbrown
benjaminmbrown / websocket_server.py
Last active February 19, 2016 20:14
Python imports for websocket_server.py
#!/usr/bin/env python2.7
import json
import random
from tornado import websocket, web, ioloop
import datetime
from time import time
# Random number generator
r = lambda: random.randint(0,255)
class WebSocketHandler(websocket.WebSocketHandler):
def open(self):
print 'Connection established.'
#close connection
def on_close(self):
print 'Connection closed.'
# Our function to send new (random) data for charts
<html>
<head>
<meta charset="utf-8">
<title>Dimensional Charting</title>
<link rel="stylesheet" type="text/css" href="http://dc-js.github.io/dc.js/css/dc.css"/>
<script type="text/javascript" src="http://dc-js.github.io/dc.js/js/d3.js"></script>
<script type="text/javascript" src="http://dc-js.github.io/dc.js/js/crossfilter.js"></script>
<script type="text/javascript" src="http://dc-js.github.io/dc.js/js/dc.js"></script>
</head>
import time
import random
import json
import datetime
from tornado import websocket, web, ioloop
from datetime import timedelta
from random import randint
paymentTypes = ["cash", "tab", "visa","mastercard","bitcoin"]
namesArray = ['Ben', 'Jarrod', 'Vijay', 'Aziz']
function render_plots(){
yearRingChart
.width(200).height(200)
.dimension(yearDim)
.group(spendPerYear)
.innerRadius(50);
spenderRowChart
.width(250).height(200)
.dimension(nameDim)
@benjaminmbrown
benjaminmbrown / datavis-static.html
Last active February 23, 2016 05:54
static d3 & crossfilter chart solution
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dimensional Charting</title>
<link rel="stylesheet" type="text/css" href="http://dc-js.github.io/dc.js/css/dc.css"/>
<script type="text/javascript" src="http://dc-js.github.io/dc.js/js/d3.js"></script>
<script type="text/javascript" src="http://dc-js.github.io/dc.js/js/crossfilter.js"></script>
<script type="text/javascript" src="http://dc-js.github.io/dc.js/js/dc.js"></script>
@benjaminmbrown
benjaminmbrown / connection-onmessage.js
Created February 23, 2016 06:15
connection-onmessage.js
connection.onmessage = function(event) {
var newData = JSON.parse(event.data);
var updateObject =[{
"Name": newData.Name,
"Year": newData.Year,
"Spent": newData.Spent,
"payType": newData.payType
}]
//resetData(ndx, [yearDim, spendDim, nameDim]);
xfilter.add(updateObject);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dimensional Charting</title>
<link rel="stylesheet" type="text/css" href="http://dc-js.github.io/dc.js/css/dc.css"/>
<script type="text/javascript" src="http://dc-js.github.io/dc.js/js/d3.js"></script>
<script type="text/javascript" src="http://dc-js.github.io/dc.js/js/crossfilter.js"></script>
<script type="text/javascript" src="http://dc-js.github.io/dc.js/js/dc.js"></script>
#pseudo code for simple non-blocking I/O with polling loop (busy-wait)
resources = [socketA, socketB, pipeA];
while(!resources.isEmpty()){
for(i = 0; i< resources.length; i++){
resource = resources[i];
//attempt to read resource
var data = resource.read();
if(data === NO_DATA_AVAILABLE)
continue
/*pseudocode for event demultplexer*/
socketA, pipeB;
watchedList.add(socketA, FOR_READ);
watchedList.add(pipeB, FOR_READ);
while(events = demultiplexer.watch(watchedList){
foreach(event in events){
/*non blocking read always returns data*/
data = event.resource.read();