Skip to content

Instantly share code, notes, and snippets.

@matenia
matenia / gist:a8e8f075fadc453cf56c
Created March 4, 2015 04:29
poro and struct ancestors
2.1.4 :004 > MyClass.ancestors
[
[0] MyClass < Object,
[1] Object < BasicObject,
[2] PP::ObjectMixin,
[3] ERB::Util,
[4] ActiveSupport::Dependencies::Loadable,
[5] JSON::Ext::Generator::GeneratorMethods::Object,
[6] Kernel,
[7] BasicObject
@matenia
matenia / awesome_nested_set_optimization_helper.rb
Created September 5, 2010 01:25 — forked from lancejpollard/awesome_nested_set_optimization_helper.rb
Converts awesome_nested_set model into a flat array (one sql query!)
def simple_nested_set(clazz) # Post for example
stack = [] # Post for example
result = []
clazz.all(:order => "lft").each do |node|
if stack.empty?
stack.push({:node => node, :children => []})
result << stack.last
next
end
if stack.last[:node].lft < node.lft && node.lft < stack.last[:node].rgt
@matenia
matenia / template.rb
Created December 27, 2011 14:08
Rails 3.1 template
# Standard Init Script for New Custom Rails 3.1.3 app
RailsVersion = "3.1.3"
instructions =<<-END
Running Standard Init Script for Rails 3.1.3
--------------------------------------------------
During installation a number of questions will arise and
@matenia
matenia / config-initializers-page_constraint.rb
Created December 28, 2011 07:23
Dynamic page routes with friendly_id
#config/initializers/page_constraint.rb
class PageConstraint
def initialize
@page_paths = Page.all.map { |p| "/#{p.friendly_id}"}
end
def matches?(request)
@page_paths.include?(request.path)
end
@matenia
matenia / deploy.rb
Created December 30, 2011 02:36
Deploy from local project via capistrano
require "bundler/capistrano"
require 'capistrano/ext/multistage'
require 'new_relic/recipes'
set :application, "sampleapp"
set :branch, "master"
# deploy from local
set :scm, :git
set :repository, ".git"
set :deploy_via, :copy
@matenia
matenia / slug_table_access.rb slug_table_access.rb
Created February 25, 2012 13:27
Hack for FriendlyId 4.x - Access Slug table within the app
# loaded into config/initializers/slug_table_access.rb
### HACK TO LOAD SLUG TABLE ACCESS
# required for use with path constraints in routes
autoload :Slug, 'friendly_id/slug'
# Access Slug table via FriendlyId::Slug
# NOTE: In FriendlyId 3.x the Slug model is available within your app
# This is a hack for FriendlyId 4.x
@matenia
matenia / page.rb
Created February 25, 2012 14:35
Route Constraints, mapping Friendly Id 4.x to /:id of any model
# app/models/page.rb
class Page < ActiveRecord::Base
extend FriendlyId
friendly_id :title, :use => [:slugged, :history]
end
@matenia
matenia / bootstrap_topbar_list.rb
Created March 2, 2012 14:49 — forked from tmaier/bootstrap_topbar_list.rb
BootstrapTopbarList for simple-navigation and Twitter Bootstrap integration
# Renders an ItemContainer as a <ul> element and its containing items as <li> elements.
# Prepared to use inside the topbar of Twitter Bootstrap http://twitter.github.com/bootstrap/#navigation
#
# Register the renderer and use following code in your view:
# render_navigation(level: 1..2, renderer: :bootstrap_topbar_list, expand_all: true)
class BootstrapTopbarList < SimpleNavigation::Renderer::Base
def render(item_container)
if options[:is_subnavigation]
ul_class = "dropdown-menu"
def edit
@profile = Profile.find(params[:username])
what = params[:what]
if not what.nil?
if ["basics", "location", "details", "photos", "interests"].member?(what)
render :action => "edit_#{what}"
else
render :action => "edit_basics"
end
@matenia
matenia / gist:2758056
Created May 20, 2012 13:08 — forked from jdkealy/gist:1323514
rails_admin ckeditor implementation
config.model PagePart do
configure :content do
ckeditor true
end
end