Skip to content

Instantly share code, notes, and snippets.

View TobyEalden's full-sized avatar

Toby Ealden TobyEalden

View GitHub Profile
@TobyEalden
TobyEalden / api server.js
Last active December 20, 2015 20:39
POST to API implemented using express
var express = require("express");
var app = express();
app.use(express.bodyParser());
app.post('/postTest', function(req, res) {
if (req.body.hasOwnProperty("test")) {
console.log("test property is: " + req.body.test);
res.json({ok: true });
} else {
console.log("no test property");
import React from "react";
import RefreshIndicator from "material-ui/lib/refresh-indicator";
class RefreshIndicatorBroken extends React.Component {
constructor() {
super();
this.state = {
showRefresh: true
};
@TobyEalden
TobyEalden / index.js
Last active October 4, 2016 13:46 — forked from iendjinn/index.js
var topojson = require("topojson");
//var TDXApi = require("nqm-api-tdx");
var fs = require("fs");
function propertyTransform(feature) {
return feature.properties;
}
function databot(input, output, context) {
output.progress(0);
function createSchemaFromObject(inputObj) {
const keys = Object.keys(inputObj);
const schema = {};
_.forEach(keys, (key) => {
if (typeof inputObj[key] === "string") {
schema[key] = { __tdxType: ["string"] };
} else if (_.isNumeric(inputObj[key])) {
schema[key] = { __tdxType: ["number"] };
} else {
// Check for arrays, objects, date?
var filestream = fs.createReadStream(file);
filestream.pipe(res)
.on("finish", function() {
log("resource download complete");
})
.on("error", function(err) {
errLog("failure during resource download: %s", err.message);
});
res
parseXmlStringAsync(response.text)
.then((result) => {
var entryList = [];
_.forEach(result.feed.datastream, (val) => {
if (idList.indexOf(Number(val['$']['id'])) > -1) {
var entry = {
'ID': Number(val['$']['id']),
'timestamp': Number(new Date(val.current_time[0]).getTime()),
'currentvalue': Number(val.current_value[0]),
'maxvalue': Number(val.max_value[0])
/*
* BEFORE
*/
import {dataLoader} from "nqm-app-framework";
//...
export default dataLoader.merge(
dataLoader.compose(dataLoader.trackerFactory(dataMapper), {propsToWatch: ["parentId"]}),
dataLoader.compose(dataLoader.reduxFactory(stateMapper)),
@TobyEalden
TobyEalden / codetest.js
Last active January 31, 2017 14:07 — forked from iendjinn/codetest.js
let total = 0;
for (let i = 0; i < 100; i++) {
asynchronousFunction(i, (result) => {
total = total + result;
});
}
storeTotal(total);
/*
what is wrong with this code?
@TobyEalden
TobyEalden / Bluebird.js
Last active February 17, 2017 12:44 — forked from iendjinn/Bluebird.js
// estimator.js
module.exports = (function() {
var getData = function(id, cb) {
return api.getDataAsync(id, this.state.filter);
}
function estimator(initial) {
this.state = initial;
let total = 0;
const processChunk = function(chunkList, chunkIndex) {
const chunk = chunkList[chunkIndex];
// do stuff with chunk asynchronously
return doStuff(chunk)
.then((result) => {
if (chunkIndex < chunkList.length) {
total += result;