Skip to content

Instantly share code, notes, and snippets.

View JeffCohen's full-sized avatar

Jeff Cohen JeffCohen

View GitHub Profile
@JeffCohen
JeffCohen / survival.md
Last active November 13, 2015 20:36
Entrepreneur's Survival Guide to Coding
  • Filenames must be all-lowercase and cannot contain any spaces, ever.
  • Always save your code files before refreshing your browser. Otherwise your code will not take effect.
  • All code repositories must be placed directly under your code folder.
  • Never put one code repository inside of another. Each repository must be one level down inside the code folder.
  • Use lowercase for all code (HTML tags, CSS rules, Javascript, Ruby, etc.) unless specificially instructed otherwise.
  • View the Source, Luke!
  • Use the Web Inspector, Luke!
  • Coding is deterministic. There is a cause for every effect. Allow nothing to remain "magical" or "fuzzy".
  • You should be able to verbally explain your app's behavior when called upon.
@JeffCohen
JeffCohen / easy.rb
Created September 2, 2015 04:07
Crazy initializer - good for one-off Rails apps
# Add this file to your config/initializers directory.
#
# Then you can do things like:
#
# Product[5] instead of Product.find_by(id: 5)
# Product.sample to pull a random Product row
# Product.sample(3) to pull three random Product rows (but they will be consecutive)
#
# Biggest part: automatic associations!
#
@JeffCohen
JeffCohen / product.rb
Last active August 29, 2015 14:24
product.rb
class Product
attr_accessor :title
attr_accessor :image_url
attr_accessor :url
def initialize(title, image_slug, asin)
@title = title
@url = "http://www.amazon.com/dp/#{asin}"
@image_url = "http://ecx.images-amazon.com/images/I/#{image_slug}._SL1500_.jpg"
@JeffCohen
JeffCohen / selection_sort.py
Created March 3, 2015 17:54
In-Place Selection Sort in Python
import random
def sort(items):
for position in range(0, len(items)):
min_position_so_far = position
for z in range(position+1, len(items)):
if items[z] < items[min_position_so_far]:
min_position_so_far = z
@JeffCohen
JeffCohen / gist:deb00660324495fc0872
Created February 25, 2015 16:42
Sublime Preferences
"match_selection": false,
"remember_open_files": false,
"save_on_focus_lost": true,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
@JeffCohen
JeffCohen / boostrap-template.html
Last active May 13, 2017 15:14 — forked from eng/index.html
Bootstrap Starter Template
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery-2.1.4.js"></script>
@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():
# 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 / 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

@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