Skip to content

Instantly share code, notes, and snippets.

💭
Baby Yoda is my spirit animal

Berkeley Martinez BerkeleyTrue

💭
Baby Yoda is my spirit animal
View GitHub Profile
View routes.jsx
import { createServer, at } from 'fyfe';
import { GET, composeRoutes, composeMiddleware } from 'fyfe-compose-routes';
import fyfeDefaults from 'fyfe-defaults';
// composes routes together
// first route to return something other then Void will win
const routes = composeRoutes(
// use a route handler
// Request => Responce|String|Stream|Void
GET('/', renderIndex),
@BerkeleyTrue
BerkeleyTrue / thunkToObservable.js
Last active Nov 17, 2016
Convert thunk to observable
View thunkToObservable.js
function thunkToObservable(thunk) {
return (getState, ...args) => {
return new Observable(observer => {
const dispatchProxy = new Subject();
const dispatch = action => dispatchProxy.next(action);
thunk(...args)(dispatch, getState);
return dispatchProxy.subscribe(observer);
});
};
}
View ReactRx.js
import { ActionsObservable } from 'redux-observale/lib/ActionsObservable';
import rootEpic from './epics';
const flux = new Reactor({ /*...*/ });
const input$ = new Subject();
const actions$ = new ActionsObservable(input$);
const epic$ = new Subject();
epic$
@BerkeleyTrue
BerkeleyTrue / actions.js
Last active Sep 20, 2016
redux create types
View actions.js
import createTypes from 'redux-create-types';
export const ns = 'app';
export const types = createTypes(
[
'openModal',
'onClick',
'updateEmailSettings',
createAsyncTypes('fetch')
],
View timed-out-epic.js
import { Observable } from 'rxjs';
export default function logOutEpic(actions, { getState }) {
return Observable
.interval(500)
.takeUntil(actions.ofType('LOG_OUT').first())
.map(() => {
const { app: { accessToken } = {} } = getState();
return accessToken;
})
@BerkeleyTrue
BerkeleyTrue / serializeForm.js
Created Sep 18, 2016
serialize a form element
View serializeForm.js
export function serializeForm(form) {
const data = [].filter.call(form.elements, node => !!node.name)
.reduce((data, node) => {
data[node.name] = node.value;
return data;
}, {});
return JSON.stringify(data);
}
View async-assert.js
function(cb) {
$.ajax()
.then(() => {
// do test
cb();
});
}
View login-expire.js
const logoutTime = 15* 60;
const warningTime = 14 * 60;
function createLogoutActionStream() {
return Observable.merge(
Observable.of({ type: 'showLogoutMessageWarning' }).delay(warningTime * 1000),
Observable.of({ type: 'logOut' }).delay(logoutTIme * 1000)
);
}
mouseEventStream
View get-email-percent.js
var fs = require('fs');
var emailName = process.argv[2];
var percent = process.argv[3];
var emails = require('./' + emailName + '.json');
var newEmails = emails.slice((emails.length * (percent / 100)));
console.log(
'Do emails end the same? %s',
emails[emails.length - 1] === newEmails[newEmails.length -1]
);
View gist:7f641ad89ae54b707de0e20bfd80a1c0
// add the custom static method to the Loopback User model
// note the dollar sign here indicatest to the user this function
// returns an Observable
User.getPointsById$ = function getPointsById$(id) {
return Observable.create(observer => {
let isDisposed = false;
// Here we tap into mongodb method
// safe ObjectID creation
// MongoID(id: ObjectID|String) => ObjectID
// MongoDB requires id's to be of type ObjectID
You can’t perform that action at this time.