Skip to content

Instantly share code, notes, and snippets.

@jch
jch / rails-engines.md
Created December 19, 2013 01:36
Rails Engines

This is a quick brain dump of problems I've run into using Rails Engines.

Problems

  • Dependencies If an Engine requires a gem at version X, and the application requires the same gem at version Y. You could specify a lose version constraint on the Engine, but that's just asking for trouble. If the application updates to a newer version that the Engine isn't expecting, things go wrong.
  • Layouts/Assets To customize these, you need to overwrite certain magical paths. This ends up duplicating a lot of the engine and forces you to dig into the internals of how the Engine works rather than trusting it as a standalone component.
  • Models If you use an Engine's models, you're crossing into the Engine's abstractions again. It seems like a good place to share code, but it means your models will need to become versioned.
  • Complexity It's hard to debug problems when they come up. Is it coming from the engine, the app, or the app's overrides of the engine
@jch
jch / js-tools.md
Last active December 21, 2015 06:19

JavaScript Toolbox

This is a list of JavaScript libraries I like or would like to investigate. It will be kept short intentionally to be things I find useful for most JS projects.

Testing

  • Karma - test runner. adapters for testing libraries, runs within browser clients
  • Mocha - test library
  • Sinon.js - spies and stubs. Can create fake servers and responses.
  • QUnit - test library. like it's simplicity. Also likely to be maintained long-term because of jQuery. Will take off the list if I like Mocha.
@jch
jch / polling_request.coffee
Created August 16, 2013 22:01
some pseudocode for polling long running jobs
# # PollingRequest
#
# A xhr request that repeatedly polls a [progress-aware endpoint](#progress-aware-endpoint).
#
# req = PollingRequest.new
# url: /states.csv
# interval: 2000 # polling interval in milliseconds
# progress: (n)->
# console.log "Progress: #{n} percent"
# success: (res)->
@jch
jch / geocoding-google.rb
Created July 24, 2013 22:54
Simple Google Geocoding API V3 client. All I needed was a state name given a postal code. Might be interesting to build this out, but felt I'd share the basics first.
require 'uri'
require 'multi_json'
require 'net/http'
# Simple client wrapper around Google Geocoding API V3
# https://developers.google.com/maps/documentation/geocoding
#
# geo = Geocoding::Google.geocode('91106')
# geo.state
#

Interview your libraries

I love working with John Barnette, even if we don't work on the same stuff regularly. The other day, he wrote this in a discussion:

Every time we bring in an external library, we inherit its opinions, shortcomings, idioms, and taste. This isn't a reason to rewrite everything ourselves, but it's good for us to interview libraries like we interview new GitHubbers.

I loved this. In two short sentences, Barnette summed up why we should evaluate new dependencies before adding them to an existing project.

Why not drop in a library?

@jch
jch / pdf_document.rb
Created May 2, 2013 01:07
some exploration about creating PDFs from a resque background job with PDFKit
class PDFDocument
include ActionDispatch::Integration::Runner # lets you grab assets. See #session
include Rails.application.routes.url_helpers
# quote or invoice or receipt
def initialize(document)
@document = document
end
def pdf
require 'base64'
require 'nokogiri'
module Rack
# Rack middleware to inline css and images from underlying application so it
# can be proccessed by PDFKit without additional network requests.
#
# For example, this middleware will transform this response:
#
# <html>
@jch
jch / minitest-hooks.rb
Last active December 16, 2015 15:09
Work in progress MiniTest runner allowing multiple setup and teardown hooks around the whole test suite, and individual test cases.
require 'minitest/unit'
module MiniTest
module Hooks
class Runner < MiniTest::Unit
def _run_suite(suite, type)
# TODO: copy over ivars into the testcase instance binding
suite._before_all_blocks.each(&:call)
result = super
suite._after_all_blocks.each(&:call)

Introductions

  • jerry - enterprise developer
  • danish - enterprise sales

Overview

  • github overview
    • started as a side project to share and host code
      • grown much bigger. now the goal is to be a suite of collaboration tools. work better together
  • what version control is?
@jch
jch / prototype.rb
Created March 22, 2013 00:18
ruby prototyping
# Manage user email subscriptions and opt-outs.
module OptOut
def config
@config ||= Configuration.new
end
def configure(&blk)
blk.call(config) if blk
config
end