Skip to content

Instantly share code, notes, and snippets.

View JeffCohen's full-sized avatar

Jeff Cohen JeffCohen

View GitHub Profile
@JeffCohen
JeffCohen / deployment.md
Last active August 29, 2015 13:56
Deployment Checklist

Checklist for First-Time Deployment on VPS

One-Time: Local

  1. Gemfile: mysql2
  2. exception notification
  3. env var for rails secret token
  4. seeds file
  5. green tests
@JeffCohen
JeffCohen / vitamins.rb
Created February 19, 2014 18:51
Ruby Vitamin Check-Up
# Ruby Vitamin Check-Up
#
# (Google for "ruby array")
building_ages = [15, 56, 71, 32, 42, 46, 63, 91, 102]
# 1. How old is the oldest building?
# 2. What's the average age of these buildings?
@JeffCohen
JeffCohen / ez.md
Last active August 29, 2015 13:56
The ez gem

The EZ gem

The ez gem is intended to help non-programmers during their first few weeks of learning Rails.

Currently only the happiest of all paths have been tested, and as far as I know, it only works on my machine.

  # Add it to your Gemfile
  
 gem 'ez', group: 'development'
@JeffCohen
JeffCohen / maybe.md
Last active August 29, 2015 13:56
Maybe

Imagine you are born into a society in which you can read as many books as you like, but you aren't allowed to write any of your own. Instead, only Official Book Writers are allowed to write books.

Then you find out that you are allowed to join the Official Book Writers Society, but you first have to write your book with one of the Official Pens. You can obtain an Official Pen fairly easily (they're free), but writing with one turns out to be nearly impossible. It doesn't look like any pen you've ever tried before, and knowing how to use it seems like a secret art.

Your friends tell you about some YouTube videos that try to teach newbies how to write with an Official Pen. Turns out the first thing you have to learn in order to write with an Official Pen is how to self-install a new electrical system in your house.

You're not sure why you need a new electrical system just to use a P

How Rails is Revolutionizing Our Schools

Abstract

Rails began life aimed at professional developers, but now I'm using it to revolutionize the way kids and adults learn computer programming. Building an app enables non-programmers to step into computer science without the boring theory and math-like courses that have been traditionally used. I'll show the curriculum I'm using at schools like NU and UChicago, in which students pick up basic CS concepts and more, like design patterns, agile principles, critical thinking skills, and teamwork.

For The Review Committee

I think many developers don't know the wealth of computer science literacy that's gained when new programmers learn Rails for the first time. Students think they're building a fun app, but I use it to introduce fundamental CS concepts along the way. It's been a wonderful way for students to learn CS basics in a manner completely anti-thetical to the standard CS curriculum used across the nation.

require 'digest/md5' class List < ActiveRecord::Base

has_many :entries, -> { order('position asc') }, dependent: :destroy has_many :songs, through: :entries belongs_to :user

before_create :create_slug

validates_uniqueness_of :sharing_slug

@JeffCohen
JeffCohen / queries.rb
Last active August 29, 2015 14:07
Product Queries
# Given these models:
#
# Customer
# - name: string
#
# Product
# - price: integer
#
# Order
# - customer_id: integer
@JeffCohen
JeffCohen / gist:f22cc03ea3842b2cf8c0
Created November 4, 2014 02:45
Pattern: User Account Confirmation

Problem

A user's true identity or email address must be verified before they are given full access to your application.

Solution

The system sends an email to the user's email address containing a unique, personalized url. Visiting the url in a browser provides sufficient identity verification, since the url could only have been known to the person who received the email.

Assumptions/Flaws

# you'd obviously have more settings somewhere
set :scm, :git
set :repository, "git@github.com:defunkt/github.git"
set :branch, "origin/master"
set :migrate_target, :current # this tells capistrano where to run the migration. otherwise it would try to use the latest release directory (/path/to/app/releases/2012XXXXXXXXX)
set :use_sudo, false
set :ssh_options, {:forward_agent => true} # so you can checkout the git repo without giving the server access to the repo
set :rails_env, 'production'
# These are here to override the defaults by cap
@JeffCohen
JeffCohen / crazy.py
Created January 17, 2015 16:49
Why does python let me do this?
# Python 3.4
# A nice class
class Person:
def __init__(self, name):
self.name = name
# A nice function
def speak():