Skip to content

Instantly share code, notes, and snippets.

View mrichie's full-sized avatar

Richie Min mrichie

View GitHub Profile
@mrichie
mrichie / activeadmin-cancan.rb
Created July 9, 2012 03:01
Deep integration of CanCan into ActiveAdmin
# blog post:
# Before using this initializer, you must set up Cancan. First, add the gem to your Gemfile:
#
# gem 'cancan'
#
# Next, generate and edit an Ability class:
#
# rails generate cancan:ability
#
@mrichie
mrichie / rails_template_for_mongoid.rb
Created June 11, 2012 04:12 — forked from huacnlee/rails_template_for_mongoid.rb
A custom Rails template for Mongoid.
# coding: utf-8
# This is a Rails init template with MongoDB projects
#
# Mongoid, Devise, Bootstrap, jQuery, Redis, Cells, will_paginate, Carrierwave, simple_form, Settingslogic, Thin
#
# Usage
#
# $ rails new app_name -m https://raw.github.com/gist/2168014
#
@mrichie
mrichie / active_admin_mongoid_patch
Created May 30, 2012 08:24
hook active_admin for support mongoid
require "active_admin"
require 'inherited_resources'
require "active_admin/resource_controller"
require 'mongoid'
module ActiveAdmin
module Mongoid
end
class Namespace
#save it as config/initializers/html_in_json.rb
ActiveSupport.escape_html_entities_in_json = true
#next line is not really compulsory. It just sanitizes output(not just replaces with \u values of html entities) to protect you from DOM XSSes.
ActiveSupport::JSON::Encoding::ESCAPED_CHARS.merge! '<' => '&lt;'
@mrichie
mrichie / extend_and_method_call_bench.rb
Created May 24, 2012 05:32 — forked from mlomnicki/extend_and_method_call_bench.rb
Extend + method call VS method call
require 'benchmark'
module Foo
def bar
end
def baz
end
@mrichie
mrichie / guide.sh
Created May 24, 2012 04:29 — forked from teamon/guide.sh
Pow + nginx configuration aka give me back my 80 port!
# Install pow
$ curl get.pow.cx | sh
# Install powder
$ gem install powder
# See that firewall is fucked
$ sudo ipfw show
00100 0 0 fwd 127.0.0.1,20559 tcp from any to me dst-port 80 in <- THIS ONE!!!
65535 81005 28684067 allow ip from any to any
igrigorik ~/> ab -c 220 -n 2000 http://127.0.0.1:3000/widgets
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
@mrichie
mrichie / 0-readme.md
Created March 24, 2012 09:38 — forked from burke/0-readme.md
ruby-1.9.3-p125 cumulative performance patch.

Patched ruby 1.9.3-p125 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p125 with patches to make ruby-debug work again (#47) and boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84). It also includes the new backported GC from ruby-trunk.

Huge thanks to funny-falcon for the performance patches.

@mrichie
mrichie / ability.rb
Created March 8, 2012 08:40 — forked from watson/ability.rb
Active Admin CanCan integration with shared front/backend User model and multi-level autherization
# app/models/ability.rb
# All front end users are authorized using this class
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
can :read, :all
@mrichie
mrichie / Comfortable work with locals in Ruby.rb
Created March 6, 2012 11:16
Using locals by extending Binding
###Breaking news!
#Have you ever dreamed to extract all local variables from current context using ruby?
#Do you hate writing partials below style? :
=render partial: 'form_additional', locals: {f: f, shortname: shortname, expanded: expanded}
#I bet you do!
#Here is extension for Binding class which lets you to avoid writing hardcore something: something. It looks pretty workaround but there is no other way...