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)?

# based on the following:
# http://saintgimp.org/2013/01/22/merging-two-git-repositories-into-one-repository-without-losing-file-history/
# http://blog.caplin.com/2013/09/18/merging-two-git-repositories/
git clone repo_main
git clone repo_sub
cd repo_main
git remote add repo_sub ../repo_sub
git fetch repo_sub
@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))
@teohm
teohm / MD5Example.java
Created September 8, 2015 14:19
Examples of md5 checksum signature calculation for ReferralCandy advanced integration
import java.util.*;
import java.lang.*;
import java.io.*;
import java.security.*;
import java.math.*;
class MD5Example
{
public static void main (String[] args) throws java.lang.Exception
{
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 / datetime-omg.rb
Last active August 29, 2015 14:03
Does anyone know why?
require 'date'
# 1) this doesn't work, why?
format = "%-m/%-d/%Y %-l:%M:%S %p"
d = DateTime.new(2014,6,5,1,5,9)
d == DateTime.strptime(d.strftime(format), format) # raised ArgumentError: invalid date
# 2) this works, why?
format = "%-m/%-d/%Y %-l:%M:%S %p"
format2 = "%m/%d/%Y %l:%M:%S %p"
@teohm
teohm / solved-failed-to-build-ruby2x-with-readline63.md
Last active August 29, 2015 14:00
[Solved] Failed to build ruby 2.x with readline 6.3

[Solved] Failed to build ruby 2.x with readline 6.3

Error

readline.c:1977:26: error: ‘Function’ undeclared (first use in this function)
     rl_pre_input_hook = (Function *)readline_pre_input_hook;

Read more

rake local_gem:init
rake local_gem:update_projects
cd project_dir
begin
abort if git_staging_dirty?
bundle_update(gem_name)
abort unless lockfile_modified?
git_add(gem_name)
git_commit(MSG_GEM_UPDATED, gem_name)