Skip to content

Instantly share code, notes, and snippets.

Amandeep a-s-o

Block or report user

Report or block a-s-o

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@a-s-o
a-s-o / App.tsx
Last active Dec 15, 2017
ReactXP Navigator does not re-render the previous card after a navigation event (i.e. navigator.pop()) https://github.com/Microsoft/reactxp/issues/387
View App.tsx
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 Aug 18, 2016
Move lodash chunks into a specified entry file if it is used in more than one module
View webpack.config.js
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
Testing syntax for a validation/type-system
View def.js
/**
* 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 Dec 24, 2018
Single page app rewriting with Caddy server
View Caddyfile
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 Oct 3, 2015
requirebin sketch
View index.js
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 Aug 29, 2015
Lifecycle hooks for mithril components
View component.js
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 Aug 29, 2015
cerebral action draft implementation
View cerebral-action.js
// 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 Aug 4, 2015
Validation system for cerebral actions using tcomb
View action-validator.js
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 Aug 29, 2015
Kefir model
View kefir.model.js
/////////////
// 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 Apr 25, 2015
Basic functions for stats
View stats.js
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);
You can’t perform that action at this time.