Skip to content

Instantly share code, notes, and snippets.

View schneems's full-sized avatar

Richard Schneeman schneems

View GitHub Profile
@schneems
schneems / gist:3210445
Created July 30, 2012 21:30
Week 8 Recap Quiz
## 1) Describe the differences between manual and automated testing
## 2) What Ruby library can we use for importing data into our Rails app from spreadsheets?
## 3) What is the name of the library (and command) we can use to write (and run) one off scripts?
Hint: ____ db:migrate
@schneems
schneems / gist:3239009
Created August 2, 2012 17:40
Week 7 Recap Quiz Solutions
## 1) What is SQL Injection
SQL Injection is a security vulnerability where an attacker can run arbitrary SQL code on your machine because we are not using safe Active Record practices.
## 2) Which of these are safe from SQL Injection attacks?
A)
User.where(:name => params[:name])

Rails is a dynamic framework that serves a static index.html by default. One of my first questions ever on IRC was solved by "delete your index.html". This file is a source of confusion when starting as it over-rides any set "root" in the routes yet it itself is not listed in the routes. By making the page dynamic by default we can eliminate this confusion and show people how to set the root on their project all at the same time.

I encounter this question any time I am helping someone new learn Rails, and it is advice repeated again and again from our comments in rails/rails to external tutorials. We can remove this extra step and show people how to use rails root in the routes by allowing the index to be dynamic.

This makes it easier to understand how to replace the root if desired, or to modify the index once generated since all rails helper methods are available. Eventually we can refactor this page to use standard Rails helpers instead of pure static html.

Screenshot:

![](http://f.cl.ly/items/38212

Dynamic error pages have many benefits over static, for instance they can use the default layout if desired. By generating dynamic error pages by default we can encourage developers to take advantage of this already existing feature and build better sites. In addition to moving people towards dynamically generating their error pages we can add prompts to the default pages. One example is telling devs how to get to their logs. I have added erb to errors/500.html.erb that I believe will be extremely helpful to new developers.

While walking users through a deployment (such as with http://railsgirls.com/materials) they often are not familiar with how to retrieve logs on a given system. I've added a dynamic section that will look for an environment variable CHECK_LOG_INSTRUCTIONS and if present show a corresponding message. I can then work with @hone to get a debug log message into the ruby buildpack something like $ heroku logs --tail. While we've added a

@schneems
schneems / gist:3856323
Created October 9, 2012 03:00
Copy data locally from Heroku
heroku pgbackups:capture
curl -o latest.dump `heroku pgbackups:url`
pg_restore --verbose --clean --no-acl --no-owner -h localhost \
-U `whoami` -d `ruby -e "require 'yaml' ; File.open( 'config/database.yml' ) { |file| puts YAML::load(file)['development']['database'] }"` latest.dump
rm latest.dump

Heroku Users,

We are going to do an experiment. Next Wednesday 10/17 from 3-5pm we will be holding office hours for customers in our San Francisco office.

This is an opportunity for customers to meet us and ask questions about developing their apps and using Heroku. It is an opportunity for us to learn more about our customers.

Maybe you're a new user, and have some getting started questions. Perhaps you've been using Heroku for ages and have a high level architectural question. Or maybe you just want to shake someone's hand from the Heroku postgres team. Either way stop by our offices at the corner of 11th and Folsom, we are next to Slims.

insert google maps thingy here

Heroku Users,

We are going to do an experiment. Next Wednesday 10/17 from 3-5pm we will be holding office hours for customers in our San Francisco office.

This is an opportunity for you to come meet us and ask questions about developing your apps on Heroku. It is an opportunity for us to learn more about you and your needs.

![picture of people sitting in the kitchen?](###gogogog)

Maybe you're a new user, and have some getting started questions. Perhaps you've been using Heroku for ages and have a high level architectural question. Or maybe you just want to shake someone's hand from the Heroku postgres team. Either way stop by our offices at the corner of 11th and Folsom, we are next to Slims. We look forward to seeing you.

@schneems
schneems / mandelbrot.rb
Created October 19, 2012 15:58
mandelbrot.rb
BAILOUT = 16
MAX_ITERATIONS = 1000
class Mandelbrot
def initialize
(-39...39).each do |y|
puts
(-39...39).each do |x|
i = iterate(x/40.0,y/40.0)
@schneems
schneems / gist_snippits.rb
Created October 22, 2012 17:10
gist_snippits.rb
require 'json'
## What
# This file takes in a markdown file and converts any [codeblocks](http://daringfireball.net/projects/markdown/syntax#precode)
# into gists, then embeds the gists via JS.
# Watch out for Github rate limiting, via IP, this is not an authenticated request