Skip to content

Instantly share code, notes, and snippets.

ruby-1.9.3-p392 cumulative performance patch for rbenv

(I guarantee nothing. No warranty I am not responsible blah blah blah. Seems to work great for me so far. Thanks to Tyler Bird who I forked this from.)

This installs a patched ruby 1.9.3-p392 with the railsexpress patchsets: https://github.com/skaes/rvm-patchsets

Requirements

str = "some file name.with dots.html.markdown"
extensions = str[/(?:\.\w+)+$/]
extensions ? [ str.sub(extensions, ''), extensions[1..-1].split('.') ] : [ str ]
@rwz
rwz / gist:3281979
Created August 7, 2012 05:35
Rendering Jbuilder templates from within model
# this is the easiest way to use partials from model I could find so far
class Entry < AR::Base
def as_json
context = ApplicationController.new.view_context
context.render('/api/entries/entry.json', entry: self)
end
end
@rwz
rwz / batshitcrazy.rb
Created June 21, 2012 11:45
control class methods from instance? easy!
class MyClass
attr_accessor :klass_name
def initialize(klass_name)
self.klass_name = klass_name
end
def self.name
to_s
end
@rwz
rwz / gist:2366293
Created April 12, 2012 10:21 — forked from justinfrench/gist:2362758
Nestive
# Expected h1 title for posts#show is "My Blog :: My Post Title"
# --------------------------------------------------------------
# This was how it worked with `layout nil` in the controller
#
# posts_controller.rb
class PostsController
layout nil
@rwz
rwz / application.html.slim
Created April 11, 2012 06:44
nestive layouts
= extends :html5_base do
- append :head do
meta(http-equiv="X-UA-Compatible" content="IE=edge")
title Lolwut
= area :assets do
= javascript_include_tag 'application'
= yield
#fb-root
@rwz
rwz / ternary.rb
Created February 8, 2012 06:39
A little rubyquiz
my_object.bool_method?? 'yes' : 'no'
# or
my_object.bool_method? ? 'yes' : 'no'
# or
(my_object.bool_method?) ? 'yes' : 'no'
@rwz
rwz / authentication.rb
Created June 14, 2011 10:43
Twitter authentication fail with Omniauth credentials [FIXED, see https://github.com/jnunemaker/twitter/issues/171]
class Authentication < ActiveRecord::Base
belongs_to :user
serialize :info
serialize :credentials
def update_from_omniauth(omniauth)
self.uid = omniauth['uid']
self.provider = omniauth['provider']
self.info = omniauth['user_info']
self.credentials = omniauth['credentials']
!function(){
function fakeLength(fn, length) {
if (length == fn.length) return fn;
var fakeArgs = [];
while(length--) fakeArgs.push('$fakeArg'+length);
return eval('(function('+fakeArgs.join(',')+'){ return fn.apply(this, arguments); })');
}
Function.prototype.allRequired = function(){
// тупо
var wiget = new Class({
// ...
getSomething: function(){
if (this.something) return this.something;
this.something = new Element('div');
// тут километры кода
return this.something;