Skip to content

Instantly share code, notes, and snippets.

View nelix's full-sized avatar
🎯
Focusing

Nathan Hutchision nelix

🎯
Focusing
View GitHub Profile
@nelix
nelix / helpers.js
Created December 5, 2015 16:37 — forked from br3tt/helpers.js
class Helpers {
currentHP(db) { return db.PlayerInfo.CurrHP }
noCurrentHPGain(db) { return db.PlayerInfo.CurrentHPGain == 0.0 }
radiation(db) { return db.PlayerInfo.TotalDamages[5].Value }
aidItems(db) { return db.Inventory['48'] }
radiationMoreThan(rads) {
return db => {
this.radiation(db) > rads;
};
@nelix
nelix / curry.js
Last active November 13, 2015 16:56 — forked from amatiasq/curry.js
Simple way to recursively curry javascript functions http://jsfiddle.net/amatiasq/osrsomq0/
/**
* @param {Function} fn Function to curry.
* @param {Number} lenght of the arguments required to invoke the function.
* @returns {Function} The currified function.
*/
const curry = (fn, length = fn.length) => function currified(...args) {
if (args.length === 0) {
return currified;
}
const merge = (obj, src) => {
let res = obj;
for (let k of Object.keys(src)) {
if (res[k] === src[k]) {
continue;
}
if (typeof src[k] === 'object' && src[k] !== null && src[k].constructor === Object) {
let sub = res[k];
@nelix
nelix / app.js
Created August 4, 2015 11:18
npm i && npm start && open index.html
const React = require('react');
const { TransitionSpring } = require('react-motion');
const Router = require('react-router');
const RouteTransition = React.createClass({
propTypes: {
pathname: React.PropTypes.string.isRequired
},
willEnter() {
@nelix
nelix / auth.js
Last active August 29, 2015 14:21
const Authenticated = function(isAuthenticated) {
return React.createClass({
displayName: 'Authenticated',
statics: {
willTransitionTo(transition) {
if (!isAuthenticated()) {
transition.redirect('login');
}
},
@nelix
nelix / app.js
Created April 17, 2015 04:55
Does not support the top level route yet, easy enough to add though. babel stage 1 needed I think?
import React from 'react';
import Router from 'react-router';
import _ from 'lodash';
class MegaRouteHander extends React.Component {
static contextTypes = {
megaApi: React.PropTypes.object.isRequired,
routeDepth: React.PropTypes.number.isRequired,
router: React.PropTypes.func.isRequired
};
@nelix
nelix / .js
Created March 21, 2015 03:22
Turn some json (with id props) into an OrderedSet of Records with ImmutableJS
class ThingRecord extends Immutable.Record({
id: null,
someData: {}
}) {}
const thingSet = Immutable.fromJS(things);
const thingsOrderedMap = thingSet.reduce((r, v) => r.set(v.get('id'),
new ThingRecord(v)),
Immutable.OrderedMap()
@nelix
nelix / actions.js
Created March 16, 2015 02:03
No callbacks
import { Actions } from 'flummox';
export default class TodoActions extends Actions {
constructor(db) {
super();
this.db = db;
}
async create(model) {
Router.run(routes, Router.HistoryLocation, (Handler, state) => {
function render() {
var data = flux.stores.getAll();
React.render(<Handler state={state} data={data} actions={flux.actions}/>, container);
}
_.each(state.routes, route => {
if (Array.isArray(route.handler.actions) { // handle all the fetching... or other static actions...
_.each(route.handler.actions, action => setTimeout(action.bind(null, state.params)));
}
router.run((Handler, state) => {
log('route change', state);
function getData() {
var data = {};
_each(ALL_STORES, (store) => {
data[store + 'Data'] = flux.store(store).getState();
});
return data;