Skip to content

Instantly share code, notes, and snippets.

View mwlang's full-sized avatar

Michael Lang mwlang

View GitHub Profile
@mwlang
mwlang / properties.rb
Created June 27, 2013 14:19
Example defining "counts" -- See "Properties" column
index do
id_column
column :name
column "Properties" do |o|
o.properties.size
end
column "Added", :created_at
column "Updated", :updated_at
default_actions
end
@mwlang
mwlang / activerecord log
Created July 1, 2013 20:26
Active Record output on start up...
04:24:53:website >> rails s
=> Booting WEBrick
=> Rails 4.0.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
/Users/mwlang/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-4.0.0/lib/active_record/core.rb:103: warning: already initialized constant #<Module:0x007fe037e05e60>::AttrNames
/Users/mwlang/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-4.0.0/lib/active_record/core.rb:103: warning: previous definition of AttrNames was here
/Users/mwlang/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-4.0.0/lib/active_record/core.rb:103: warning: already initialized constant #<Module:0x007fe039291e10>::AttrNames
/Users/mwlang/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-4.0.0/lib/active_record/core.rb:103: warning: previous definition of AttrNames was here
/Users/mwlang/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-4.0.0/lib/active_record/core.rb:103: warning: already initialized constant #<Module:0x007fe0394c29f0>::AttrNames
@mwlang
mwlang / framework trace
Created July 5, 2013 19:48
A Status class that isn't persisted to the DB.
activerecord (4.0.0) lib/active_record/associations/association_scope.rb:13:in `initialize'
activerecord (4.0.0) lib/active_record/associations/association.rb:100:in `new'
activerecord (4.0.0) lib/active_record/associations/association.rb:100:in `association_scope'
activerecord (4.0.0) lib/active_record/associations/association.rb:84:in `scope'
activerecord (4.0.0) lib/active_record/associations/singular_association.rb:42:in `find_target'
activerecord (4.0.0) lib/active_record/associations/association.rb:139:in `load_target'
activerecord (4.0.0) lib/active_record/associations/association.rb:52:in `reload'
activerecord (4.0.0) lib/active_record/associations/singular_association.rb:9:in `reader'
activerecord (4.0.0) lib/active_record/associations/builder/association.rb:70:in `status'
formtastic (2.2.1) lib/formtastic/inputs/base/fileish.rb:9:in `block in file?'
@mwlang
mwlang / attorney.rb
Created July 14, 2013 13:31
Extract of an Attorney model (basically a Person)
class Attorney < ActiveRecord::Base
# Added :uniq qualifier, not without some strife. First, in the Agile 1.2 dev book,
# they incorrectly called the parameter ":unique". Then, when you get a .count
# on this association (attorney.community_organizations.count), it returns the non-
# unique count. So, instead, to receive an accurate count that respects the :uniq
# parameter, use .size, so attorney.community_organizations.size.
has_many :community_organizations,
:through => :affiliations,
:conditions => %{community_organization_type_id != #{CommunityOrganizationType::PROFESSIONAL_TYPE_ID}},
:order => 'name',
class Practice < ActiveRecord::Base
default_scope order(:name)
has_many :attorneys, -> { where(active: true)}, :through => :attorney_practice_links
has_many :attorneys_only, -> {where(active: true, is_attorney: true) },
:through => :attorney_practice_links,
:include => [:position],
:source => :attorney
has_and_belongs_to_many :normal_events,
:join_table => 'events_practices',
:conditions => "type = 'NormalEvent' AND status_id = #{Status[:published].id}",
:association_foreign_key => "event_id",
:order => 'starts_on ASC'
has_and_belongs_to_many :normal_events_future,
:class_name => 'NormalEvent',
:join_table => 'events_practices',
:conditions => "type = 'NormalEvent' AND status_id = #{Status[:published].id} AND starts_on >= '#{0.days.ago.to_s(:db)}'",
:association_foreign_key => "event_id",
@mwlang
mwlang / deploy.rb
Last active December 21, 2015 04:29
Cap deploy issue
require "bundler/capistrano"
require 'rvm/capistrano'
set :rvm_ruby_string, '2.0.0'
set :rvm_type, :system
set :application, "demo"
set :server_address, "rackspace"
set :use_sudo, false
set :use_monit, false
@mwlang
mwlang / ensure_remote_user.rb
Created August 23, 2013 10:45
If you configure basic or digest authorization on Apache/Lighthttpd/nginx, when a user is authenticated, the "REMOTE_USER" is set to the user that was authenticated. This Rack middleware lets you do development outside of a web server by setting REMOTE_USER automatically. Useful for Intranet based websites that are authenticated against Active D…
# Injects a default REMOTE_USER into the headers so your Ruby app sees someone as being
# "logged in" (authenticated) as would normally happen when the web server has been configured
# to do basic or digest authentication before passing through to the web app.
module Rack
class EnsureRemoteUser
def initialize(app)
logger.debug "Ensure REMOTE_USER module initialized!"
@app = app
end
@mwlang
mwlang / nocache.rb
Last active December 21, 2015 14:09
A Rack module that will cause the browser to always fetch the entire contents of page. Useful for environments where you're behind a caching server.
module Rack
class NoCache
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
headers['Pragma'] = 'no-cache'
-------------
4. API access
-------------
The API allows other applications running on the same system to get p0f's
current opinion about a particular host. This is useful for integrating it with
spam filters, web apps, and so on.
Clients are welcome to connect to the unix socket specified with -s using the