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

# 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
this.selectize = this.$("#js-tags").selectize({
persist: true,
maxItems: null,
valueField: "tag",
labelField: "tag",
searchField: ["tag"],
options: tags.toJSON(), // Backbone collection
render: {
item: function(item) {
return "<div><i class='icon-tag'></i> " + item.tag + "</div>";
@regdog
regdog / README
Created November 26, 2013 04:17 — forked from vangberg/README
# Deploying a Sinatra app to Heroku
## Database
The location of the database Heroku provides can be found in the environment
variable DATABASE_URL. Check the configure-block of toodeloo.rb for an example
on how to use this.
## Server
Heroku is serving your apps with thin, with means you have all your thin goodness available,
such as EventMachine.