Skip to content

Instantly share code, notes, and snippets.

View danieljohnmorris's full-sized avatar
😀

Daniel Morris danieljohnmorris

😀
View GitHub Profile
alias rf='rake features'
# For running specific features.
function rff {
rake features FEATURE=features/"$1".feature
}
# For running specific line numbers
function rffl {
cucumber features/"$1".feature:"$2"
@danieljohnmorris
danieljohnmorris / carrierwave_gps_scan.rb
Created April 21, 2012 11:42
gps carrierwave interrogation
Magick::Image.read(Image.with_file.find_by_import_file("DSC00014.JPG").file_url(:small_thumb))[0].get_exif_by_entry('GPSLongitude')[0][1]
Magick::Image.read(Image.with_file.find_by_import_file("DSC00014.JPG").file_url(:small_thumb))[0].get_exif_by_entry('Model')
pp Magick::Image.read(Image.with_file.find_by_import_file("DSC00014.JPG").file_url(:small_thumb))[0].get_exif_by_entry
@total_file_images = Image.with_file
@total_file_images_count = @total_file_images.count
@loop_counter = 0
puts @total_file_images.collect do |i|
@danieljohnmorris
danieljohnmorris / artist_cowboy_antics.rb
Last active December 15, 2015 04:28
In Ruby you can be an artist and a cowboy, after all!
class Person
attr_accessor :pocket
end
class Artist < Person
def draw_like_an_artist
"Look, I painted a landscape."
end
end
class Address
# :street, String
# :city, String
# :state, String
# :country, String
scope :local, lambda { |query| search_by_street_or_city(query, query) }
scope :national, lambda {|query| search_by_state_or_country(query, query) }
end
require 'texticle/searchable'
class Book
# :title, String
# :author, String
extend Searchable(:title)
end
Book.create :title => "Poignant Guide to Ruby", :author => "_why"
class Search < ActiveRecord::Base
# We want to reference various models
belongs_to :searchable, :polymorphic => true
# Wish we could eliminate n + 1 query problems,
# but we can't include polymorphic models when
# using scopes to search in Rails 3
# default_scope :include => :searchable
# Search.new('query') to search for 'query'
class CreateSearches < ActiveRecord::Migration
def self.up
ActiveRecord::Base.connection.execute <<-SQL
CREATE VIEW searches AS
SELECT authors.id AS searchable_id, authors.name AS term,
CAST ('Author' AS varchar) AS searchable_type
FROM authors
UNION
SELECT books.id AS searchable_id, books.title AS term,
CAST ('Book' AS varchar) AS searchable_type
@danieljohnmorris
danieljohnmorris / command line
Last active December 18, 2015 01:39
work mode
mate /etc/hosts
*add lines to hosts file / comment out to use sites*
dscacheutil -flushcache
class hey
def hi
if true
end
end
end
@danieljohnmorris
danieljohnmorris / fix_postgres_constraints.sh
Created October 10, 2013 17:33
Postgres.app dev db fix bugged table id constraints
psql -h localhost
\c gsa_development;
REINDEX DATABASE gsa_development;
SELECT MAX(id) FROM taggings;
SELECT nextval('taggings_id_seq');
SELECT setval('taggings_id_seq', (SELECT MAX(id) FROM taggings)+1);