Skip to content

Instantly share code, notes, and snippets.

var AWS = require("aws-sdk");
AWS.config.update({
region: "eu-west-1",
});
var dynamodbDoc = new AWS.DynamoDB.DocumentClient()
var table = "serverless-counter";
const weightData$ = get$(`/1/user/-/body/log/weight/date/${today}.json`)
.map(response => response.data.weight[0]);
server.get('/user', (req, res) => {
res.send({
token: req.user.token
});
});
const token$ = rx.Observable.fromPromise(axios.get('/user'))
.map(response => response.data.token);
const get$ = path => token$.flatMap(token => rx.Observable.fromPromise(axios.get(`https://api.fitbit.com${path}`,
{headers: {Authorization: 'Bearer ' + token}})));
passport.use(new FitbitStrategy({
clientID: process.env.ID,
clientSecret: process.env.SECRET,
callbackURL: host + "/auth/callback"
},
function(accessToken, refreshToken, profile, done) {
done(null, {token: accessToken});
}
));
@lhahne
lhahne / list.js
Last active August 29, 2015 14:23
declarative html generation
var HelloMessage = React.createClass({
render: function() {
var generateList = function() {
return [1, 2, 4].map(function(i) { return <li>{i}</li> });
};
return (
<div>Hello {this.props.name}
<ul>{generateList()}</ul>
</div>
);
@lhahne
lhahne / core.clj
Last active August 29, 2015 14:23
json from clojure
(ns clojure-json.core
(:require [cheshire.core]))
(defn my-json
[numbers-to-take numbers-to-map]
{:time (new java.util.Date)
:topic "Generating json from clojure"
:numbersToTake numbers-to-take
:letsNestIt {:someNumbers (take numbers-to-take (repeatedly rand))}
:numbersDoubled (map (partial * 2) numbers-to-map)})
@lhahne
lhahne / StationList.js
Last active August 29, 2015 14:21
react native view
var React = require('react-native')
var {Text, ListView, AppRegistry} = React
var StationMetadataStore = require('./StationMetadataStore')
var StationList = React.createClass({
getInitialState() {
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2})
return {stations: ds.cloneWithRows([])}
},
@lhahne
lhahne / StationList.js
Last active August 29, 2015 14:21
react view
var React = require('react')
var StationMetadataStore = require('./StationMetadataStore')
var StationList = React.createClass({
getInitialState() {
return {stations: []}
},
componentDidMount: function() {
this.unsubscribe =
@lhahne
lhahne / StationMetadataStore.js
Last active August 29, 2015 14:21
StationMetadataStore
var Bacon = require('bacon')
var _ = require('lodash')
var METADATA_URL = 'http://rata.digitraffic.fi/api/v1/metadata/station'
var stations = Bacon.fromPromise(fetch(METADATA_URL))
.flatMap(response => Bacon.fromPromise(response.json()))
var stationsByCode = stations.map((stations) =>
_.indexBy(stations, 'stationShortCode'))