Skip to content

Instantly share code, notes, and snippets.

@a-s-o
a-s-o / App.tsx
Last active December 15, 2017 15:06
ReactXP Navigator does not re-render the previous card after a navigation event (i.e. navigator.pop()) https://github.com/Microsoft/reactxp/issues/387
import * as RX from 'reactxp'
import Navigator, { Types, NavigatorDelegateSelector as DelegateSelector } from 'reactxp-navigation'
import { EventEmitter } from 'events'
const exampleStore = new EventEmitter()
export class App extends RX.Component<{}, { counter: number }> {
state = { counter: 0 }
private navigator: Navigator
@a-s-o
a-s-o / webpack.config.js
Created August 18, 2016 21:51
Move lodash chunks into a specified entry file if it is used in more than one module
new webpack.optimize.CommonsChunkPlugin({
name: 'someEntryFile',
minChunks (module, count) {
return module.resource && module.resource.indexOf('lodash') !== -1 && count > 1;
}
});
@a-s-o
a-s-o / def.js
Last active May 12, 2016 00:56
Testing syntax for a validation/type-system
/**
* Internal helpers
*/
// Predicates can return true/false or they can return an error message.
// true, null, undefined and empty string are considered a valid result
function isValid (result) {
return result === true || result === null || result === void 0 || result === '';
}
@a-s-o
a-s-o / Caddyfile
Last active January 6, 2021 10:28
Single page app rewriting with Caddy server
localhost:80
gzip
ext .html
root /home/deploy/current/build/www
proxy /graphql localhost:3000
rewrite /login {
to {path} /login
}
@a-s-o
a-s-o / index.js
Last active October 3, 2015 14:45
requirebin sketch
const t = require('tcomb');
const Person = t.struct({ name: t.Str, money: t.Num }, 'Person');
Person.prototype.pay = function (amount) {
return Person.update(this, {
money: { $set: this.money + t.Num(amount) }
});
};
@a-s-o
a-s-o / component.js
Last active August 29, 2015 14:27
Lifecycle hooks for mithril components
m.createComponent = function createClass (displayName, opts) {
const hooks = _.defaults(opts, hookDefaults); // Apply some defaults (excluded)
const methods = _.methods(_.omit(opts, hookNames)); // Get instance methods
const propTypes = createValidator(hooks.propTypes, displayName); // Create a prop type validator (excluded)
const Component = {
controller () {
const initialState = hooks.getInitialState() || {};
const ctrl = {
@a-s-o
a-s-o / cerebral-action.js
Last active August 29, 2015 14:26
cerebral action draft implementation
// Action definition signature
const Definition = t.struct({
fn: t.Func,
displayName: t.maybe(t.Str),
inputs: t.maybe(t.Obj),
exits: t.maybe(t.Obj),
sync: t.maybe(t.Bool)
});
cerebral.action = function cerebral$action (action) {
@a-s-o
a-s-o / action-validator.js
Created August 4, 2015 15:36
Validation system for cerebral actions using tcomb
function checkValue (msg, value, type) {
const check = t.validate(value, type);
if (!check.isValid()) {
console.error(msg + ' ' + check.firstError().message);
}
return value;
}
// This method accepts an object and returns a function that
@a-s-o
a-s-o / kefir.model.js
Last active August 29, 2015 14:22
Kefir model
/////////////
// Factory //
/////////////
Kefir.model = function (store, tx) {
if (typeof tx !== 'function') tx = x => x;
const getset = function kefir$model (update) {
if (arguments.length > 0) {
@a-s-o
a-s-o / stats.js
Created April 25, 2015 00:56
Basic functions for stats
function sum (arr) {
return arr.reduce((x, i) => x + i, 0);
}
function mean (arr) {
return sum(arr) / arr.length;
}
function variance (arr) {
let m = mean(arr);