Skip to content

Instantly share code, notes, and snippets.

View danieljohnmorris's full-sized avatar
😀

Daniel Morris danieljohnmorris

😀
View GitHub Profile
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
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'
require 'texticle/searchable'
class Book
# :title, String
# :author, String
extend Searchable(:title)
end
Book.create :title => "Poignant Guide to Ruby", :author => "_why"
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
@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
@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|
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"
gem 'rails', '3.0.9'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'devise'
gem 'omniauth'
gem 'jquery-rails'
gem "less"
@danieljohnmorris
danieljohnmorris / watermark.rb
Created November 12, 2011 14:01 — forked from laurynas/watermark.rb
Paperclip Watermark processor
# Based on
# https://github.com/ng/paperclip-watermarking-app/blob/master/lib/paperclip_processors/watermark.rb
# Modified by Laurynas Butkus
module Paperclip
class Watermark < Processor
# Handles watermarking of images that are uploaded.
attr_accessor :format, :whiny, :watermark_path, :position
def initialize file, options = {}, attachment = nil
@danieljohnmorris
danieljohnmorris / app_template__prepare_testing.rb
Created May 19, 2010 12:31
r3 app tpl - setup cucumber and rspec for rails
# usage (in app dir):
# rake rails:template LOCATION=http://gist.github.com/406257.txt
gem "database_cleaner"
group :test do
gem "launchy" # So you can do Then show me the page
# gem "capybara" # alternative to webrat
gem "spork"
gem "cucumber-rails"
gem "cucumber", "0.7.2"