Skip to content

Instantly share code, notes, and snippets.

@seanpdoyle
Last active January 2, 2016 11:09

Revisions

  1. seanpdoyle revised this gist Jan 12, 2014. 2 changed files with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 20140110012324_create_places.rb
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    class CreatePlaces < ActiveRecord::Migration
    include Paperclip::Schema #exclude this line in Rails apps

    def self.up
    def self.change
    create_table :places do |t|
    t.boolean :location_locked, default: false, null: false

    Binary file modified development.sqlite3
    Binary file not shown.
  2. seanpdoyle revised this gist Jan 12, 2014. 2 changed files with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions location
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,15 @@
    #!/usr/bin/env ruby
    #
    # Scrape the location from a JPG file
    #
    # Example:
    #
    # $ ./location photo_with_gps_metadata.jpg
    # $ Processing love.jpg.....
    # $ Processed file.
    # $ ------- latitude: 39.95116666666667
    # $ ------- longitude: -75.19433333333333
    #

    require "./setup"

    Binary file added photo_with_gps_metadata.jpg
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  3. seanpdoyle revised this gist Jan 12, 2014. 5 changed files with 15 additions and 8 deletions.
    4 changes: 2 additions & 2 deletions 20140110012324_create_places.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    require 'paperclip'
    require 'paperclip' #exclude this line in Rails apps

    class CreatePlaces < ActiveRecord::Migration
    include Paperclip::Schema
    include Paperclip::Schema #exclude this line in Rails apps

    def self.up
    create_table :places do |t|
    3 changes: 2 additions & 1 deletion Gemfile
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@ source 'https://rubygems.org'

    ruby '2.0.0'

    gem 'activerecord'
    gem 'paperclip-location'

    gem 'activerecord'
    gem 'sqlite3'
    8 changes: 5 additions & 3 deletions location
    Original file line number Diff line number Diff line change
    @@ -4,16 +4,18 @@

    require "./setup"

    unless image_file = ARGV.pop
    unless file_name = ARGV.pop
    raise ArgumentError, "Don't forget to pass in the path to the image"
    end

    puts "Processing #{image_file}....."
    puts "Processing #{file_name}....."
    puts
    puts "-------"
    puts

    place = Place.new photo: File.open(image_file)
    image_file = File.open(file_name)

    place = Place.new(photo: image_file)

    puts
    puts "-------"
    6 changes: 5 additions & 1 deletion place.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,10 @@
    class Place < ActiveRecord::Base
    include Paperclip::Glue
    include Paperclip::Glue # exclude this line in Rails apps

    has_attached_file :photo, styles: { large: '600x600#' },
    processors: [:thumbnail, :location]

    validates_attachment :photo, content_type: {
    content_type: %w[image/jpeg image/tiff]
    }
    end
    2 changes: 1 addition & 1 deletion schema.rb
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@

    ActiveRecord::Schema.define(version: 20140110012324) do
    create_table "places", force: true do |t|
    t.boolean "location_locked", default: false, null: false
    t.boolean "location_locked", default: false, null: false
    t.decimal "lat", precision: 10, scale: 15
    t.decimal "lng", precision: 10, scale: 15
    t.string "photo_file_name"
  4. seanpdoyle revised this gist Jan 7, 2014. 2 changed files with 8 additions and 7 deletions.
    8 changes: 1 addition & 7 deletions location
    Original file line number Diff line number Diff line change
    @@ -2,18 +2,12 @@
    #
    # Scrape the location from a JPG file

    require "active_record"
    require "paperclip/location"
    require "./place"

    Paperclip::Location::Processor.register! :location
    require "./setup"

    unless image_file = ARGV.pop
    raise ArgumentError, "Don't forget to pass in the path to the image"
    end

    ActiveRecord::Base.establish_connection YAML.load_file("database.yml")["development"]

    puts "Processing #{image_file}....."
    puts
    puts "-------"
    7 changes: 7 additions & 0 deletions setup.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    require "active_record"
    require "paperclip/location"
    require "./place"

    ActiveRecord::Base.establish_connection YAML.load_file("database.yml")["development"]

    Paperclip::Location::Processor.register! :location
  5. seanpdoyle revised this gist Jan 7, 2014. 8 changed files with 7 additions and 19 deletions.
    11 changes: 4 additions & 7 deletions Rakefile
    Original file line number Diff line number Diff line change
    @@ -4,13 +4,10 @@ require 'active_record'

    include ActiveRecord::Tasks

    db_dir = File.expand_path('../db', __FILE__)
    config_dir = File.expand_path('../config', __FILE__)

    DatabaseTasks.env = ENV['ENV'] || 'development'
    DatabaseTasks.db_dir = db_dir
    DatabaseTasks.database_configuration = YAML.load(File.read(File.join(config_dir, 'database.yml')))
    DatabaseTasks.migrations_paths = File.join(db_dir, 'migrate')
    DatabaseTasks.env = 'development'
    DatabaseTasks.db_dir = '.'
    DatabaseTasks.database_configuration = YAML.load(File.read('database.yml'))
    DatabaseTasks.migrations_paths = 'migrate'

    task :environment do
    ActiveRecord::Base.configurations = DatabaseTasks.database_configuration
    2 changes: 1 addition & 1 deletion config/database.yml → database.yml
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    development:
    adapter: sqlite3
    database: db/development.sqlite3
    database: development.sqlite3
    pool: 5
    timeout: 5000
    Binary file added development.sqlite3
    Binary file not shown.
    7 changes: 0 additions & 7 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,7 +0,0 @@
    source 'https://rubygems.org'

    ruby '2.0.0'

    gem 'activerecord'
    gem 'paperclip-location'
    gem 'sqlite3'
    4 changes: 2 additions & 2 deletions location
    Original file line number Diff line number Diff line change
    @@ -4,15 +4,15 @@

    require "active_record"
    require "paperclip/location"
    require "./app/models/place"
    require "./place"

    Paperclip::Location::Processor.register! :location

    unless image_file = ARGV.pop
    raise ArgumentError, "Don't forget to pass in the path to the image"
    end

    ActiveRecord::Base.establish_connection YAML.load_file("config/database.yml")["development"]
    ActiveRecord::Base.establish_connection YAML.load_file("database.yml")["development"]

    puts "Processing #{image_file}....."
    puts
    File renamed without changes.
    2 changes: 0 additions & 2 deletions db/schema.rb → schema.rb
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,6 @@
    # It's strongly recommended that you check this file into your version control system.

    ActiveRecord::Schema.define(version: 20140110012324) do

    create_table "places", force: true do |t|
    t.boolean "location_locked", default: false, null: false
    t.decimal "lat", precision: 10, scale: 15
    @@ -22,5 +21,4 @@
    t.integer "photo_file_size"
    t.datetime "photo_updated_at"
    end

    end
  6. seanpdoyle revised this gist Jan 7, 2014. 8 changed files with 159 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    source 'https://rubygems.org'

    ruby '2.0.0'

    gem 'activerecord'
    gem 'paperclip-location'
    gem 'sqlite3'
    50 changes: 50 additions & 0 deletions Gemfile.lock
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    GEM
    remote: https://rubygems.org/
    specs:
    activemodel (4.0.2)
    activesupport (= 4.0.2)
    builder (~> 3.1.0)
    activerecord (4.0.2)
    activemodel (= 4.0.2)
    activerecord-deprecated_finders (~> 1.0.2)
    activesupport (= 4.0.2)
    arel (~> 4.0.0)
    activerecord-deprecated_finders (1.0.3)
    activesupport (4.0.2)
    i18n (~> 0.6, >= 0.6.4)
    minitest (~> 4.2)
    multi_json (~> 1.3)
    thread_safe (~> 0.1)
    tzinfo (~> 0.3.37)
    arel (4.0.1)
    atomic (1.1.14)
    builder (3.1.4)
    climate_control (0.0.3)
    activesupport (>= 3.0)
    cocaine (0.5.3)
    climate_control (>= 0.0.3, < 1.0)
    exifr (1.1.3)
    i18n (0.6.9)
    mime-types (2.0)
    minitest (4.7.5)
    multi_json (1.8.2)
    paperclip (3.5.2)
    activemodel (>= 3.0.0)
    activesupport (>= 3.0.0)
    cocaine (~> 0.5.3)
    mime-types
    paperclip-location (0.0.5)
    exifr (~> 1.1)
    paperclip (~> 3.5)
    sqlite3 (1.3.8)
    thread_safe (0.1.3)
    atomic
    tzinfo (0.3.38)

    PLATFORMS
    ruby

    DEPENDENCIES
    activerecord
    paperclip-location
    sqlite3
    20 changes: 20 additions & 0 deletions Rakefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    require 'bundler/setup'

    require 'active_record'

    include ActiveRecord::Tasks

    db_dir = File.expand_path('../db', __FILE__)
    config_dir = File.expand_path('../config', __FILE__)

    DatabaseTasks.env = ENV['ENV'] || 'development'
    DatabaseTasks.db_dir = db_dir
    DatabaseTasks.database_configuration = YAML.load(File.read(File.join(config_dir, 'database.yml')))
    DatabaseTasks.migrations_paths = File.join(db_dir, 'migrate')

    task :environment do
    ActiveRecord::Base.configurations = DatabaseTasks.database_configuration
    ActiveRecord::Base.establish_connection DatabaseTasks.env
    end

    load 'active_record/railties/databases.rake'
    6 changes: 6 additions & 0 deletions app/models/place.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    class Place < ActiveRecord::Base
    include Paperclip::Glue

    has_attached_file :photo, styles: { large: '600x600#' },
    processors: [:thumbnail, :location]
    end
    5 changes: 5 additions & 0 deletions config/database.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    development:
    adapter: sqlite3
    database: db/development.sqlite3
    pool: 5
    timeout: 5000
    16 changes: 16 additions & 0 deletions db/migrate/20140110012324_create_places.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    require 'paperclip'

    class CreatePlaces < ActiveRecord::Migration
    include Paperclip::Schema

    def self.up
    create_table :places do |t|
    t.boolean :location_locked, default: false, null: false

    t.decimal :lat, precision: 10, scale: 15
    t.decimal :lng, precision: 10, scale: 15
    end

    add_attachment :places, :photo
    end
    end
    26 changes: 26 additions & 0 deletions db/schema.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    # encoding: UTF-8
    # This file is auto-generated from the current state of the database. Instead
    # of editing this file, please use the migrations feature of Active Record to
    # incrementally modify your database, and then regenerate this schema definition.
    #
    # Note that this schema.rb definition is the authoritative source for your
    # database schema. If you need to create the application database on another
    # system, you should be using db:schema:load, not running all the migrations
    # from scratch. The latter is a flawed and unsustainable approach (the more migrations
    # you'll amass, the slower it'll run and the greater likelihood for issues).
    #
    # It's strongly recommended that you check this file into your version control system.

    ActiveRecord::Schema.define(version: 20140110012324) do

    create_table "places", force: true do |t|
    t.boolean "location_locked", default: false, null: false
    t.decimal "lat", precision: 10, scale: 15
    t.decimal "lng", precision: 10, scale: 15
    t.string "photo_file_name"
    t.string "photo_content_type"
    t.integer "photo_file_size"
    t.datetime "photo_updated_at"
    end

    end
    29 changes: 29 additions & 0 deletions location
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/usr/bin/env ruby
    #
    # Scrape the location from a JPG file

    require "active_record"
    require "paperclip/location"
    require "./app/models/place"

    Paperclip::Location::Processor.register! :location

    unless image_file = ARGV.pop
    raise ArgumentError, "Don't forget to pass in the path to the image"
    end

    ActiveRecord::Base.establish_connection YAML.load_file("config/database.yml")["development"]

    puts "Processing #{image_file}....."
    puts
    puts "-------"
    puts

    place = Place.new photo: File.open(image_file)

    puts
    puts "-------"
    puts
    puts "Processed file."
    puts "------- latitude: #{place.lat}"
    puts "------- longitude: #{place.lng}"
  7. seanpdoyle created this gist Jan 7, 2014.
    7 changes: 7 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    source 'https://rubygems.org'

    ruby '2.0.0'

    gem 'activerecord'
    gem 'paperclip-location'
    gem 'sqlite3'