Skip to content

Instantly share code, notes, and snippets.

View westonplatter's full-sized avatar

westonplatter

View GitHub Profile
# example take from
# https://github.com/schneems/wicked/blob/40443aea2aba0fe506b9c878fb677f08f2114200/lib/wicked/wizard.rb
require 'active_support/concerns'
module FooBar::Concerns::Controllers::OneController
extend ActiveSupport::Concerns
# controller level methods associated with a Rails-route and View
# IE, the controller structure
@westonplatter
westonplatter / engines.md
Created July 24, 2012 09:11
Rails Docs - Engines - better formatting
# MyApp/app/models/blorgh/post.rb
# overrides Blorgh's original Post model

class Blorgh::Post < ActiveRecord::Base
  include Blorgh::Concerns::Models::Post

  def time_since_created
    Time.current - created_at
 end
lasdjflksdajfklj
@westonplatter
westonplatter / symbols.rb
Created August 10, 2012 22:42
namespace_ops
# want to see module/classes referenced via symbols.
# put this into IRB
module M # Main is 3 keys longer than M
class A
def test
"a"
end
end
> mongo
// saving records
db.test.save({"a": 1}) //
db.test.find() // { "_id" : ObjectId("502437b4a1d603739ab59206"), "a" : 1 }
db.test.save({"a": 100}) //
// retreaving range of records
db.test.find( { "a": { $gt: 0, $lt: 500 } } ) // { "_id" : ObjectId("502437b4a1d603739ab59206"), "a" : 1 }
// { "_id" : ObjectId("502675b7792a4a17c3b470b6"), "a" : 100 }
@westonplatter
westonplatter / methods.rb
Created August 22, 2012 00:19
open_classing
class Tweet
attr_accessor :status
attr_reader :created_at
def initialize(status)
@status = status
@created_at = Time.now
end
end
app1
|- app/views/photo_contests
| |- index.html.erb # => custom view template #1
|
\- Gemfile (gem 'common_engine')
app2
|- app/views/photo_contests
| |- index.html.erb # => custom view template #2
|
@westonplatter
westonplatter / first.rb
Created September 19, 2012 06:23
Rails DB Connections
# This spec fails when I run it for (JRuby + sqlite), but not (Ruby 1.9.3 + [mysql | postgres])
#
# some_model.rb
describe SomeModel
it { should have_db_index(:name).unique(true) }
end
# Even though the schema.rb shows the db field as unquiely indexed.
#
@westonplatter
westonplatter / postgresql_notes.markdown
Last active October 10, 2015 20:38
postgres_notes

command line UI.

psql -h localhost  

other helpful commands

\du list users
CREATE DATABASE db_name;

CREATE ROLE postgres;