Skip to content

Instantly share code, notes, and snippets.

@aaronblondeau
aaronblondeau / callbacks.js
Created August 20, 2016 15:31
Promise.coroutine (base code - callbacks only)
var request = require('request');
var fs = require('fs');
// Note that we cannot use a try catch around all this :-(
request.get('https://s3.amazonaws.com/aaronblondeau/widgets/widgets.json', (err, response, body) => {
if(err) {
console.error(err);
}
var data = JSON.parse(body);
fs.writeFile('./widgets.json', JSON.stringify(data.widgets), (err) => {
@aaronblondeau
aaronblondeau / promises.js
Created August 20, 2016 15:33
Promise.coroutine (No coroutine - just promises)
var Promise = require('bluebird');
var request = require('request');
var fs = require('fs');
request_promise = Promise.promisify(request);
writeFile_promise = Promise.promisify(fs.writeFile);
request_promise('https://s3.amazonaws.com/aaronblondeau/widgets/widgets.json')
.then((response, body) => {
var data = JSON.parse(response.body);
@aaronblondeau
aaronblondeau / promise_coroutine.js
Created August 20, 2016 15:34
Example of Bluebird's Promise.coroutine
var Promise = require('bluebird');
var request = require('request');
var fs = require('fs');
request_promise = Promise.promisify(request);
writeFile_promise = Promise.promisify(fs.writeFile);
Promise.coroutine(function* () {
try {
@aaronblondeau
aaronblondeau / promise_coroutine_loop.js
Created August 20, 2016 15:35
Example of Promise.coroutine with a loop
var Promise = require('bluebird');
var request = require('request');
var fs = require('fs');
request_promise = Promise.promisify(request);
writeFile_promise = Promise.promisify(fs.writeFile);
Promise.coroutine(function* () {
try {
@aaronblondeau
aaronblondeau / index.android.js
Last active August 26, 2017 18:59
React Home Screen with NativeBase button
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet
@aaronblondeau
aaronblondeau / .babelrc
Created June 29, 2017 21:40
where2ride .babelrc file to allow MobX decorators.
{
"presets": ["react-native"],
"plugins": ["transform-decorators-legacy"]
}
@aaronblondeau
aaronblondeau / ApplicationState.js
Created June 29, 2017 21:43
Initial version of where2ride app state (with MobX)
import {observable} from 'mobx';
class ApplicationState {
@observable clicks = 0;
}
const state = new ApplicationState()
export default state
@aaronblondeau
aaronblondeau / index.android.js
Created June 29, 2017 21:46
where2ride home screen updated to utilize application state.
/**
* where2ride React Native App
* https://github.com/aaronblondeau/where2ride
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
} from 'react-native';
@aaronblondeau
aaronblondeau / HomeScreen.js
Last active August 26, 2017 19:15
Initial version of where2ride home screen component
import React, { Component } from 'react';
import {
StyleSheet,
} from 'react-native';
import { Container, Content, Button, Text } from 'native-base';
import {observer} from 'mobx-react';
import applicationState from '../ApplicationState'
@observer
@aaronblondeau
aaronblondeau / RideDetailScreen.js
Created June 29, 2017 21:58
Initial version of where2ride ride detail screen
import React, { Component } from 'react';
import {
StyleSheet,
} from 'react-native';
import { Container, Content, Button, Text, Icon } from 'native-base';
import {observer} from 'mobx-react';
import applicationState from '../ApplicationState'
import { NavigationActions } from 'react-navigation'