Skip to content

Instantly share code, notes, and snippets.

@seanpdoyle
Last active January 2, 2016 11:09
Show Gist options
  • Save seanpdoyle/8294526 to your computer and use it in GitHub Desktop.
Save seanpdoyle/8294526 to your computer and use it in GitHub Desktop.
Code example for `paperclip-location`
require 'paperclip' #exclude this line in Rails apps
class CreatePlaces < ActiveRecord::Migration
include Paperclip::Schema #exclude this line in Rails apps
def self.change
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
development:
adapter: sqlite3
database: development.sqlite3
pool: 5
timeout: 5000
source 'https://rubygems.org'
ruby '2.0.0'
gem 'paperclip-location'
gem 'activerecord'
gem 'sqlite3'
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
#!/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"
unless file_name = ARGV.pop
raise ArgumentError, "Don't forget to pass in the path to the image"
end
puts "Processing #{file_name}....."
puts
puts "-------"
puts
image_file = File.open(file_name)
place = Place.new(photo: image_file)
puts
puts "-------"
puts
puts "Processed file."
puts "------- latitude: #{place.lat}"
puts "------- longitude: #{place.lng}"
require 'bundler/setup'
require 'active_record'
include ActiveRecord::Tasks
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
ActiveRecord::Base.establish_connection DatabaseTasks.env
end
load 'active_record/railties/databases.rake'
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment