Skip to content

Instantly share code, notes, and snippets.

View jcasimir's full-sized avatar

Jeff Casimir jcasimir

View GitHub Profile
@jcasimir
jcasimir / flash.markdown
Created September 11, 2011 16:51
Managing the Flash

Managing the Flash

HTTP is a stateless protocol. The server, generally speaking, has no idea if request number 243 came from the same user as request number 236. That's beautiful and, at the same time, annoying.

In the context of web applications we frequently want to persist state between requests. That might mean something like a shopping cart that follows a user through the online store, but it can be as simple as a status message.

In modern applications users expect feedback. They click a delete link and they expect to no just see the item disappear, they'll expect a "Item Deleted" message. In Rails we handle these messages using the flash.

Flash as Hash

@jcasimir
jcasimir / friendly_urls.markdown
Created September 11, 2011 15:48
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@jcasimir
jcasimir / better_rails_through_better_ruby.markdown
Created September 13, 2011 18:32
Better Rails Through Better Ruby

The Problem is Your Ruby

(Intro)

Stop Trying

Stop trying to be an expert at Rails.

Is it Hard?

Transactions

As your business logic gets complex you may need to implement transactions. The classic example is a bank funds transfer from account A to account B. If the withdrawal from account A fails then the deposit to account B should either never take place or be rolled back.

Basics

All the complexity is handled by ActiveRecord::Transactions. Any model class or instance has a method named .transaction. When called and passed a block, that block will be executed inside a database transaction. If there's an exception raised, the transaction will automatically be rolled back.

Example

The Turing School of Software & Design is a 501(c)3 non-profit school located in Denver, Colorado. Our primary program focuses on Ruby, Rails, and JavaScript across four six-week semesters for a total engagement of 27 weeks.

In March of 2015 we joined with a collective of other training providers to form the New Economy Skills Training Association (NESTA). That organization put together a list of outcomes data points that member organizations would publish in the future.

This is the 2015 Outcomes Report for Turing. The following data represents the 1406, 1407, 1409, 1410, 1412, 1502, 1503, and 1505 cohorts of the Turing School, who graduated between December 2014 and December 2015.

Completion Rates

  • Total students who could have graduated: 136
  • Number of students who are still enrolled: 4 (due to repeated modules / breaks)

Hello Courtney,

The Brand Coordinator role stood out to me because I am creative, organized, and have over 7 years of professional media experience. In each position I've held, I have developed systems for managing campaigns, created multi-channel content, and collaborated with team members across departments.

Through leading various production and digital media campaigns for organizations in Denver, CO over the past 4 years, I have increased engagement and operating funds by over 11% collectively. I've utilized Google Analytics to create strategic marketing plans for clients and manipulated metadata and tags on WordPress sites to enhance SEO. Further, my communications work with Skill Distillery involved managing a number of events and creating marketing collateral to increase company recognition and strengthen employer relationships.

I am self-motivated, learn quickly, and work well under pressure. Much of my work has been directly related to education and I believe my interpersonal skills would allow me

Ruby Debugger

Most of the time simple output statements using warn, raise, or a logger will help you find your issue. But sometimes you need the big guns, and that means ruby-debug.

Ruby-Debug

The ruby-debug package has had some rocky times during the transition from Ruby 1.8.7 to 1.9.2 and beyond. But now, finally, the debugger is reliable and usable.

Installation

@jcasimir
jcasimir / filters.markdown
Created July 22, 2011 18:14
Controller Filters

Controller Filters

The Rails REST implementation dictates the default seven actions for your controllers, but frequently we want to share functionality across multiple actions or even across controllers. Controller filters are the easiest way to do that.

Before, After, and Around

There are three types of filters implemented in Rails:

  • a before_filter runs before the controller action
  • an after_filter runs after the controller action

Binary Sort

Instructions

Complete these steps with roles Person 1 (P1) and Person 2 (P2):

  • P1 selects 8 of your numbers at random
  • P2 walks through the Building the Tree algorithm for those eight numbers out loud without counting steps
  • P1 walks through the Traversing the Tree algorithm out loud without counting steps
  • P1 adds four new cards, shuffles

Merge Sort

Instructions

Complete these steps with roles Person 1 (P1) and Person 2 (P2):

  • P1 selects 5 of your numbers at random
  • P2 walks through the algorithm sorting those five numbers out loud to practice without counting steps
  • P1 adds three new cards, shuffles, and sorts the set out loud. P2 counts the steps using the guidelines below.
  • P2 adds two more cards, shuffles, and sorts the set out loud. P1 counts the steps using the guidelines below