Skip to content

Instantly share code, notes, and snippets.

View bswinnerton's full-sized avatar

Brooks Swinnerton bswinnerton

View GitHub Profile
require 'pry'
$v2 = true
module V2
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
require 'pry'
require 'nokogiri'
require 'rest-client'
endpoint_url = 'http://reddit.com'
response = RestClient.get(endpoint_url)
parsed_response = Nokogiri.parse(response)
titles = parsed_response.css('.content > .spacer > #siteTable > .thing > .entry > .title > a').map do |node|
Dir[File.dirname(__FILE__) + '/../lib/*.rb'].each { |file| require file }

Creeper

We want to make an application that has the ability to take an uploaded image and plot where it was taken on a map. To do so, we're going to need to use a few gems:

  1. pry-rails: the worlds most badass gem there ever was. Pry is a general debugging tool that allows you to set breakpoints (with something like binding.pry), lookup method definitions (with prefacing the method with $), and lots of great syntax highlighting.
  2. better_errors and binding_of_caller: is an amazing way to transform the standard rails error messages with something that has a REPL that allows you to see what the code is like at the moment of failure.
  3. paperclip: a very popular tool to allow people to upload files to your applications and store them with a model
  4. geocoder: a location management gem that allows us to do lookups of locations by latitude and longitude.
  5. mini_exiftool: as the NSA knows, all images have something called metadata associated with them. Modern cell phones (which a large populat

Back End Web Development

Rails

Generating a new application

rails new catmosphere
cd catmosphere/

Starting the rails server

require_relative 'lib/user'
require_relative 'lib/post'
#require 'pry'
brooks = User.new('Brooks', 'brooks@ga.co')
Post.new('Cat takes over the world', 'asdfasdfas', brooks)
Post.new('colbert', 'asdf', brooks)
Post.new('asdf', 'qwer', brooks)
Post.all.each do |post|
class Post
attr_accessor :title, :body
@@all = []
def initialize(title, body)
@title = title
@body = body
@@all << self
end
require 'json'
require 'rest-client'
url = 'http://reddit.com/.json'
response = RestClient.get(url)
parsed_response = JSON.parse(response)
posts = parsed_response['data']['children'].map do |post|
{

Back End Web Development

Ruby

Data types

  1. String - denoted by single or double quotes
    e.g. "Brooks", 'brooks'

  2. Integer (aka Fixnum) - A whole number
    e.g. 1, 42