Skip to content

Instantly share code, notes, and snippets.

PLEASE NOTE: We'd prefer you send your answers to [email protected] rather than post them publicly in another Gist or in comments on this Gist ;-)

1. Voting

Each voter can vote in zero or more referenda. Each referendum has one or more questions, and each question is a yes/no vote. Write the simplest normalized schema to describe this in generic SQL statements or as an entity-relationship diagram. Point out where the indexes would be if you want to quickly know the results of a given referendum question, but you never expect to query a single voter's voting record.

2. Availability on AWS

Your client plans to host their web application on AWS. When would you advise (a) deployment in a single availability zone, (b) deployment in multiple availability zones in a single region (c) deployment in multiple regions? What operational difficulty or complexity, if any, is added as you go from (a) to (b) to (c)?

@teohm
teohm / 00_README.md
Created December 8, 2016 10:28 — forked from dbalatero/00_README.md
This is an example of how I combine interaction/service classes with Wisper event broadcasting inside Rails.

This is an example of how I combine interaction/service classes with Wisper event broadcasting in Rails.

In this example, I show a UsersController#create API, a corresponding service object, and all the test code/listeners to make it all happen.

The outcome is:

  • Concepts in your system ("Signing up a user", "Creating an order") have a single entry point in your codebase, vs. making stupid raw ActiveRecord calls to object.save in dozens of places.
  • Since your concept has one entry point (the service class), you can easily grep for usage of it.
  • Stupid easy to attach listeners to the service class
  • All event listeners are very small and easily unit tested
@teohm
teohm / rails-diff.sublime-snippet
Created April 13, 2016 09:23 — forked from JuanitoFatas/rails-diff.sublime-snippet
Generate rails old_version..new_version diff sublime snippet
<snippet>
<content><![CDATA[
Upgrade rails from ${1:old_version} to ${2:new_version}.
- Updated: [rails](http://github.com/rails/rails), [${1:old_version}...${2:new_version}](https://github.com/rails/rails/compare/v${1:old_version}...v${2:new_version})
- Updated: actionmailer, ${1:old_version}...${2:new_version} ([CHANGELOG](https://github.com/rails/rails/blob/v${2:new_version}/actionmailer/CHANGELOG.md))
- Updated: actionpack, ${1:old_version}...${2:new_version} ([CHANGELOG](https://github.com/rails/rails/blob/v${2:new_version}/actionpack/CHANGELOG.md))
- Updated: actionview, ${1:old_version}...${2:new_version} ([CHANGELOG](https://github.com/rails/rails/blob/v${2:new_version}/actionview/CHANGELOG.md))
- Updated: activejob, ${1:old_version}...${2:new_version} ([CHANGELOG](https://github.com/rails/rails/blob/v${2:new_version}/activejob/CHANGELOG.md))
- Updated: activemodel, ${1:old_version}...${2:new_version} ([CHANGELOG](https://github.com/rails/rails/blob/v${2:new_version}/activemodel/CHANGELOG.md))
BEGIN {
require 'net/http'
Net::HTTP.module_eval do
alias_method '__initialize__', 'initialize'
def initialize(*args,&block)
__initialize__(*args, &block)
@teohm
teohm / 0_reuse_code.js
Last active August 29, 2015 14:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@teohm
teohm / rails-reload-example.rb
Created January 29, 2014 01:08 — forked from garybernhardt/gist:8678679
unload/reload
# Goal: put a non-Rails-aware Ruby library using normal `require`s in
# lib/mything. Have it transparently reloaded between requests like Rails app
# code is.
#
# The code here goes inside of your configure block in
# config/environments/development.rb. There are two parts, commented inline.
# Disable reload_classes_only_on_change. This makes Rails invoke the reloader
# even if no source files are changed. This is necessary because the autoloader
# and reloader don't know about our library, so they won't know to trigger a
#!/usr/bin/env ruby
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]

I recently got PATCH mostly working with Backbone and Rails 3, here's what I needed to do.

Sticking Points:

  1. [Rails] JSON Patch gem needs updated.
  2. [Rails] Routing verb for patch missing - I believe this is fixed in Rails 4, haven't investigated.
  3. [Rails] Need to parse the 'application/json-patch+json' content type in sort of a crazy way
  4. [Rails] Building a patch and applying it to an activerecord model is kind of a pain, ideally we'd have a ActiveModel#apply_patch(json_patch)
  5. [Backbone] Building a patch from a set of attributes is tricky - I've done the bare minimum using a loop over a hash to build add operations, which should probably cover a good chunk of cases for backbone. (I imagine most people aren't going to need the json-patch support for moving, copying or deleting keys generally.)
#!/bin/bash -e
export RBENV_ROOT=/usr/local/rbenv
export PATH=/usr/local/rbenv/shims:/usr/local/rbenv/bin:/usr/local/bin:"$PATH"
APP="<%= @options[:app].application.name %>"
APP_PATH="<%= @options[:app].path %>"
RAILS_ENV="<%= @options[:rails_env] %>"
UNICORN_CONFIG="/etc/unicorn/${APP}.rb"
CUR_PID_FILE="${APP_PATH}/shared/pids/unicorn.pid"
@teohm
teohm / gist:7781729
Created December 4, 2013 03:08 — forked from afeld/gist:5704079

TODO: make gem for this

This was tested using Rails 3.2 and Rails 4.0 on Ruby 2.0.0.

Bower

  1. Set the install directory for Bower components:

// .bowerrc