Skip to content

Instantly share code, notes, and snippets.

1. Time to show what you know about making Rails apps without scaffold. Keep the beers (you'll use them for the relationships lesson), but now we're headed for the bookstore.
2. Single model app for now. You need to decide the types that are most appropriate, and generate the model. Go ahead and make a matching controller.
Each book entry should have:
- A title
- An author
- A publication year
- An ISBN
- A genre
@RasPhilCo
RasPhilCo / rrrt.md
Last active August 29, 2015 13:55
RESTful Rails Routes Table

RRRT-- RESTful Rails Routes Table (ex: BooksController)

named path http verb crud operation controller action action has a view? view shows 1 or many? pertains to one persisted record? url adtl data needed rails route
books_path get reading index yes many no /books -- get 'books/' => 'books#index', :as => :books
new_book_path get reading* (creating) new yes one* no /books/new -- get 'books/new' => 'books#new', :as => :new_book
post creating create no -- no /books { } post 'books/' => 'books#create'
book_path(:id) get reading show yes one yes /books/:id -- get 'books/:id' => 'books#show', :as => :book
edit_book_path(:id) get reading* (updating) edit yes one yes /books/:id/edit -- get 'books/:id/edit' => 'books#edit', :as => :edit_book
@RasPhilCo
RasPhilCo / js_nothingness_to_generators.js
Last active November 25, 2015 17:56
JavaScript Nothingness to Generators in < 200 Lines
// Welcome! We're going to go from nothingness to JS generators in 200 lines.
// But first, some vocab:
// Let's use the word chore instead of function and
// let's think of a chore as a "to-do" list of instruction(s)
// We'll use the "function" syntax to define a chore's to-do instruction(s),
// including input(s) and expected ouput, if any
// Note, "return" basically says, "quit doing stuff (even if you have more to do) and output something"
// Lastly, var is a way to give bits of code a name
@RasPhilCo
RasPhilCo / csv_export.py
Created September 1, 2015 02:47
Export django model to csv
import csv
import collections
from operator import attrgetter
from myApp.models import User
csvfile = open("users.csv", "wb")
objects = User.objects.all()
fields = collections.OrderedDict([("First name", "first_name"),("Last name", "last_name"),("Email", "email"),])
writer = csv.writer(csvfile, quoting=csv.QUOTE_ALL)
@RasPhilCo
RasPhilCo / baseline-freebsd.sh
Created November 4, 2015 05:11 — forked from mclosson/baseline-freebsd.sh
Create known good baseline of FreeBSD server basics
#!/bin/sh
# Script to generate a baseline of known good values for a FreeBSD 10.x server
# The outputs should be able to be diff'd later to verify that no changes have occured
BASELINE=baseline
SUDO=/usr/local/bin/sudo
/bin/rm -rf $BASELINE
/bin/mkdir $BASELINE
/bin/hostname > $BASELINE/hostname
def create
test = Test.new format_params(params)
test.normalize_data
if test.save
render json: test
else
puts test.errors.messages
render text: test.errors.messages
end
@RasPhilCo
RasPhilCo / JsonHelper.java
Created November 14, 2015 19:34 — forked from codebutler/JsonHelper.java
Convert Android JSONObject/JSONArray to a standard Map/List.
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.*;
public class JsonHelper {
public static Object toJSON(Object object) throws JSONException {
if (object instanceof Map) {
JSONObject json = new JSONObject();
@RasPhilCo
RasPhilCo / poodr_chp_6.rb
Last active November 21, 2015 22:03
POODR, Chp 6 Acquiring Behavior Through Inheritance, Sandi Metz
class Bicycle
attr_reader :size, :chain, :tire_size
def initialize(args={})
@size = args[:size]
@chain = args[:chain] || default_chain
@tire_size = args[:tire_size] || default_tire_size
post_initialize(args)
end
@RasPhilCo
RasPhilCo / poodr_chp_8.rb
Last active November 24, 2015 17:37
POODR, Chp 8 Combining Objects with Composition, Sandi Metz
class Bicycle
attr_reader :size, :parts
def initialize(args={})
@size = args[:size]
@parts = args[:parts]
end
def spares
parts.spares

Larry Wall, Three Virtues --

There are three great virtues of a programmer:

  1. Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don't have to answer so many questions about it.
  2. Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least pretend to.
  3. Hubris: The quality that makes you write (and maintain) programs that other people won't want to say bad things about.

Sandi Metz, Ruby Rouges podcast --

Four rules for developers: