Skip to content

Instantly share code, notes, and snippets.

@regdog
regdog / add_attachment_data_to_wrapper.rb
Created September 5, 2011 15:02 — forked from janv/add_attachment_data_to_wrapper.rb
Small tips for building a polymorphic usage of Paperclip, with video to flv, video thumbnail, mp3 tag extraction, zip file listing processors.
class AddAttachmentsDataToWrapper < ActiveRecord::Migration
def self.up
add_column :wrappers, :data_file_name, :string
add_column :wrappers, :data_content_type, :string
add_column :wrappers, :data_file_size, :integer
add_column :wrappers, :data_updated_at, :datetime
end
def self.down
remove_column :wrappers, :data_file_name
@regdog
regdog / realty_request_controller.rb
Created October 27, 2011 01:48 — forked from andreapavoni/realty_request_controller.rb
Rails 3: An improved Search agnostic model using Arel
class RealtyRequestController < ApplicationController
#... other actions ...
def search
@s = Search.new(RealtyRequest,params[:search]) do |s|
s.contract_id :eq # value to search defaults to params[:search][:contract_id]
s.price_max :lteq # same here
s.price_min :gteq
s.zone :matches, "%#{params[:search][:zone]}%" # here I look for '%param%'
s.province :matches, "%#{params[:search][:province]}%"
s.municipality :matches, "%#{params[:search][:municipality]}%"
@regdog
regdog / gist:3228081
Created August 1, 2012 15:53 — forked from pckujawa/gist:2246185
android coverflow widget example
/*
* Copyright (C) 2010 Neil Davies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@regdog
regdog / gist:3228084
Created August 1, 2012 15:53 — forked from pckujawa/gist:2246183
android coverflow widget
/*
* Copyright (C) 2010 Neil Davies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software

Your app/widgets directory can get crazy pretty fast. If you're learning Apotomo, then you'll probably move things around and try many ways to order your widgets directory. This is not so much about that - I still haven't found a good way to organize my widgets, but I've found a way to keep the widget classes themselves DRY.

Create an ApplicationWidget just like Rails' ApplicationController

And it should look something like this:

# A BaseWidget to apply stuff to widgets across
# the board. All widgets should inherit from this
class ApplicationWidget < Apotomo::Widget

include ActionController::RecordIdentifier # so I can use dom_id

@regdog
regdog / gist:5992976
Created July 14, 2013 02:32
Impressionist mongoid generator result
$ rails g impressionist --orm mongoid --trace
/home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/impressionist-1.4.2/lib/impressionist/models/active_record/impression.rb:8:in `<top (required)>': uninitialized constant ActiveRecord (NameError)
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/impressionist-1.4.2/lib/impressionist/engine.rb:25:in `include_orm'
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/impressionist-1.4.2/lib/impressionist/engine.rb:7:in `block in <class:Engine>'
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/r
@regdog
regdog / gist:6006291
Created July 16, 2013 06:35
install impression-1.4.4 for mongoid
/home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/impressionist-1.4.4/lib/impressionist/models/active_record/impression.rb:8:in `<top (required)>': uninitialized constant ActiveRecord (NameError)
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/impressionist-1.4.4/lib/impressionist/engine.rb:25:in `include_orm'
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/impressionist-1.4.4/lib/impressionist/engine.rb:7:in `block in <class:Engine>'
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
from /home/wangyang/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
# I strongly suggest using object id's instead of auto incrementing id's
# but since you're here, I'm assuming you've already got your heart set!
# First, create a counter via mongodb console
db.counter.insert({_id:"something",count:0})
# Now, automatically use the counter on save
class Something

Your app/widgets directory can get crazy pretty fast. If you're learning Apotomo, then you'll probably move things around and try many ways to order your widgets directory. This is not so much about that - I still haven't found a good way to organize my widgets, but I've found a way to keep the widget classes themselves DRY.

Create an ApplicationWidget just like Rails' ApplicationController

And it should look something like this:

# A BaseWidget to apply stuff to widgets across
# the board. All widgets should inherit from this
class ApplicationWidget < Apotomo::Widget

include ActionController::RecordIdentifier # so I can use dom_id

# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby