Skip to content

Instantly share code, notes, and snippets.

View bjrmatos's full-sized avatar

BJR Matos bjrmatos

View GitHub Profile
@Siedrix
Siedrix / add-register.py
Created September 7, 2014 21:21
Redbird example with adding host with redis
import redis
import json
register = {
"src" : "nodebots-dev.mx",
"target" : "http://127.0.0.1:4500/"
}
registerAsStr = json.dumps(register)
@netpoetica
netpoetica / decoupling-dependencies
Created October 16, 2014 18:53
Even more decoupled than the original - pass dependencies in as args so that they can be easily changed later
document.addEventListener("DOMContentLoaded", function(event) {
/*
Later you can easily change this to any other PubSub library you like.
var _pubSub = PubSub;
or you can even wrap it to define your own API. This way, later on
you can still continue to use _ps.sub and _ps.pub even if you change
out the library defining that behaviour. Let's go with the latter.
var If = React.createClass({
render: function() {
return this.props.value && this.props.children;
}
});
// usage
<If value={this.state.whatever}>
Stuff
</If>
@iamdustan
iamdustan / index.jsareact-router-autonav.js
Last active August 29, 2015 14:16
react-router-autonav.js
/** @flow */
require('./styles.css');
var React = require('react');
var {Link} = require('react-router');
var ignoreSplatRoutes = a => !/\*$/.test(a.path);
var ignoreDefaultRoutes = (a, b) => a !== b.defaultRoute;
var Toc = React.createClass({
@kriswallsmith
kriswallsmith / 01_mixins_Secure.js
Last active August 29, 2015 14:16
My first bit of React code worth sharing.
var React = require('react');
var Router = require('react-router');
var SessionStore = require('../stores/SessionStore');
var Stash = require('../utils/Stash');
function authentication(transition) {
if (!SessionStore.isLoggedIn()) {
Stash.set('onLogin', transition.retry);
transition.redirect('login');
return false;
// with static data, do filtering and sorting in the client
<Autocomplete
initialValue="Ma"
items={getUnitedStates()}
getItemValue={(item) => item.name}
shouldItemRender={(item, value) => (
state.name.toLowerCase().indexOf(value.toLowerCase()) !== -1 ||
state.abbr.toLowerCase().indexOf(value.toLowerCase()) !== -1
)}
sortItems={(a, b, value) => (
@rwaldron
rwaldron / object-api.md
Created September 18, 2012 18:17
Object.define, Object.assign (or Object.put)

Recently, Allen produced a strawman proposal[0][1] for the "object define properties" operator, which was designed to provide syntax that differentiated semantics of define vs. assign. Towards the end of the thread, IIRC, Brendan suggested some new Object functions: Object.define() and Object.assign().[2]

I spent time over the weekend preparing common use cases for batch assignment based on real world examples from jQuery[3], Dojo[4], Node.js[5] and Lodash (an improved Underscore)[6][7] (With all due respect, Prototype is no longer considered a relevant library for use in modern day web development). Initially, I assumed that the jQuery "deep extend" was the common case and drafted an attempt at handling "nested assignment" or "deep extending". Off-list, Dave Herman reminded me that there is no way to know what the user actually wants with regard to nested object properties:

  1. Target property does not exist: define source value
  2. Target property exists, its value is anything except a nested object: A
@fson
fson / rapid-prototyping-with-relay.md
Created October 18, 2015 20:08
Rapid prototyping with Relay (Reactive 2015 lightning talk proposal)

This is a proposal for a lightning talk at the Reactive 2015 conference.

NOTE: If you like this, star ⭐ the Gist - the amount of stars decides whether it makes the cut!

Rapid prototyping with Relay

Relay makes data fetching in React apps simpler, by letting you declare the data needs of your components instead of writing complex imperative code. React, Relay, GraphQL and the other complementary tools are changing how apps are built.

@mwcz
mwcz / gsa.js
Last active December 17, 2015 16:29
(mostly complete) CasperJS script to configure the Dynamic Navigation section of a GSA, because Google's API doesn't provide that ability...
(function () {
var system = require('system');
var casper = require('casper').create({
clientScripts : [ 'jquery.min.js' ],
waitTimeout : 30000, // ms
logLevel : 'debug', // info, debug, warning, or error
verbose : system.args.indexOf('-v') >= 0
});
@kpdecker
kpdecker / nodebf.md
Last active June 2, 2016 18:02
mobile.walmart.com #nodebf 2014

Mobile Server Side Rendering

This year marks the first year that we are doing full scale rendering of our SPA application on our mobile.walmart.com Node.js tier, which has provided a number of challenges that are very different from the mostly IO-bound load of our prior #nodebf.

The infrastructure outlined for last year is the same but our Home, Item and a few other pages are prerendered on the server using fruit-loops and hula-hoop to execute an optimized version of our client-side JavaScript and provide a SEO and first-load friendly version of the site.

To support the additional CPU load concerns as peak, which we hope will be unfounded or mitigated by our work, we have also taken a variety of steps to increase cache lifetimes of the pages that are being served in this manner. In order of their impact:

Event Loop Management