Skip to content

Instantly share code, notes, and snippets.

View craigspaeth's full-sized avatar

Craig Spaeth craigspaeth

View GitHub Profile
@craigspaeth
craigspaeth / .travis.yml
Last active October 23, 2017 16:03
Product festival files
language: node_js
node_js:
- "8"
before_install:
- npm i -g danger
script: danger
@craigspaeth
craigspaeth / baobab-vs-redux.md
Last active August 9, 2020 14:31
Baobab vs. Redux

Thoughts on Redux vs. Baobab

I'm going to write down my thoughts on these two libraries that I'm conflicted between.

Disclaimer: These are just my personal stream of consciousness notes and not meant to be a well thought through blog post/opinion piece. Both these libraries are fantastic and the authors deserve huge props/respect. If you find these musings helpful I'm glad, but I encourage you to take it with a grain of salt.

Intro

The more I use Elixir, Javascript, and Coffeescript and expirement with languages like Go and Scala the more I think about what an ideal programming language would look like. I would like to see a language with...

  • Mostly explicit syntax that is similar to JS/Lua
  • Minimal surface area like Go
  • Compiles to Erlang and Javascript
  • Immutable "JSON-like" data structures... Map, List, Number, String, Null
  • Functional only
  • Loosely typed
  • Implicit lexical scope a la Coffeescript
  • Modules like Elm/JS that are per-file and require types (for tools/package mgmgt)
class ArtworkAttrSelect extends React.Component {
onChange(e) {
this.setState({ disabled: true })
$.ajax({
url: `/artwork/${this.props.id}/attr`,
type: 'PUT',
data: { [this.props.attr]: e.target.value }
}).then(() => this.setState({ disabled: false }))
}
#
# Single sign on, follow the redirect, and render the page for authenticated routes.
#
{ SECURE_ARTSY_URL } = require '../../config'
request = require 'superagent'
express = require 'express'
qs = require 'querystring'
app = module.exports = express()
#
# A library of common cache helpers. If you need to do something more complex than
# the naive query caching Backbone Cache Sync (https://github.com/artsy/backbone-cache-sync)
# provides then it's recommended to wrap it up in a function in this lib.
#
_ = require 'underscore'
{ NODE_ENV, DEFAULT_CACHE_TIME, REDIS_URL } = require '../config'
redis = require 'redis'
client = null
# API examples
cache artist, 'fetch', success: ->
#...
cache artworks, 'fetchUntilEnd', success: (artworks) ->
res.render artworks: artworks
cache fair, 'fetchExhibitors', success: ->
# ...
# Implementation
cache = (model, method, options) ->
_ = require 'underscore'
Backbone = require 'backbone'
redis = require 'redis'
module.exports = (artsyUrl) ->
# For paginated routes, this will recursively fetch until the end of the set.
#
# @param {Object} options Backbone sync options like `success` and `error`
@craigspaeth
craigspaeth / gist:8106908
Last active January 1, 2016 06:39
Notes on how routing code might be shared b/t Backbone and Express
# Pretending we have a module called rooter..
# Option #1 - Abstract only the shared portion
#
# Accepts a callback and the params. The callback takes (err, locals).
# Rooter then injects locals into the express request, and when mixed into
# Backbone it wraps the route handlers passing the locals as the first argument.
# This splits the further handling of the routing to the respective server/client
# routing engines.
@craigspaeth
craigspaeth / gist:8088618
Last active January 1, 2016 03:59
Sharing data between Browserify modules
// I have a Backbone model where I need to use the same API_URL variable
// on the server and client. With Sharify it looks something like this...
// app.js
sharify.data = { API_URL: 'http://artsy.net/api/v1' };
app.use(sharify);
// models/artwork.js
var Backbone = require('backbone'),
API_URL = require('sharify').data.API_URL;