Skip to content

Instantly share code, notes, and snippets.

@brenes
brenes / README
Created July 28, 2012 21:26
patch for installing rvm and ruby 1.9.2 on Ubuntu 11.10
This patch was found on http://deadmemes.net/2011/10/28/rvm-install-fails-on-ubuntu-11-10/ when looking for a problem installing ruby 1.9.2 on Ubuntu 11.10
@brenes
brenes / gist:3293652
Created August 8, 2012 09:07
jquery validation for selects and uniform
$('form').validate({
errorPlacement: function(error, element) {
if (element[0].tagName == "SELECT") {
element.parent().addClass('error');
}
return true;
},
unhighlight: function(element, errorClass, validClass) {
@brenes
brenes / _README
Created August 27, 2012 12:02
How to solve Globalize3 issue with old migrations when adding translated fields
There's an issue on globalize when adding or removing fields from the translations that causes the original migrations don't work properly (https://github.com/svenfuchs/globalize3/issues/131).
In my example I have a post model whih I create with some translated fields: name, slug and body. Some days later, I realise I need an excerpt field with a summarized version of the post and it has to be translated, so I create a migration to add this field.
Unfortunately, when you create the translation table it takes not only the fields you set in the params (:name => :string, :slug => :string, :body => :text) but also the params specified to the translates method in the model (:excerpt included) and creates a column for each one of those.
Solution here is to overwrite the translated attribute names of the class in the migration, so when you execute a migration you know which translated attributes will be declared and not need to worry about attributes that are not declared when you create the migration.
Overwriti
@brenes
brenes / setup_load_paths.rb
Created September 5, 2012 10:49
setup_load_paths para rvm
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
puts rvm_path
rvm_lib_path = File.join(rvm_path, 'lib')
puts rvm_lib_path
# $LOAD_PATH << rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
@brenes
brenes / app|decorators|models|refinery|page_decorator.rb
Created October 30, 2012 09:12
Decoration of Refinery::Page for getting rid of locale=XX bug on refinerycms_translate_routes
Refinery::Page.class_eval do
# When this page is rendered in the navigation, where should it link?
# If a custom "link_url" is set, it uses that otherwise it defaults to the nested path.
# This method is decorated so the ?locale=es doesn't appear at the end of the urls
def url
if link_url.present?
link_url_localised?
else
nested_path
@brenes
brenes / sample.tex
Created December 18, 2012 16:07
Simple latex document template
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish,activeacute]{babel}
\title{Titulo}
\author{Autor}
\begin{document}
@brenes
brenes / Readme
Created January 9, 2013 12:20
CVE-2013-0156 quick patch for Rails 2.3 apps
This patch fixes vulnerability CVE-2013-0156 in ActionPack[1] and it's intended for those apps that can't be updated and must find a quick solution.
Just add the files to your project, require lib/patch/hash_conversions.rb, and that's all.
This code patches ActiveSupport::CoreExtensions::Hash::Conversions methods so it takes into account the disallowed types and is based on 2.3 patch[2]
[1] https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ/discussion
[2] https://rubyonrails-security.googlegroups.com/attach/c1432d0f8c70e89d/2-3-xml_parsing.patch?gda=ulUUK0YAAABpGVv8GMoSBgW4J3Kez9oiOxgqxuyBYM9wRi8LhPWtIxxSeo4ig8fNU0gXvTeISk5x40jamwa1UURqDcgHarKEE-Ea7GxYMt0t6nY0uV5FIQ&pli=1&view=1&part=3
@brenes
brenes / model_extension.rb
Last active February 14, 2024 11:39
Removing validation of a model declared on a gem
# We have to remove validations on email, as it's no longer needed.
# Based on a solution found at http://stackoverflow.com/questions/7545938/how-to-remove-validation-using-instance-eval-clause-in-rails
Model.class_eval do
_validators.reject!{ |key, _| key == :field }
_validate_callbacks.each do |callback|
callback.raw_filter.attributes.delete :field
end
@brenes
brenes / xml_parser.rb
Created January 15, 2013 22:08
Wukong XML Parser
# Based on http://thedatachef.blogspot.com/2011/01/processing-xml-records-with-hadoop-and.html although I only can find it through Google Cache:
# http://webcache.googleusercontent.com/search?q=cache:VuIRvlkYpjcJ:thedatachef.blogspot.com/2011/01/processing-xml-records-with-hadoop-and.html+&cd=1&hl=es&ct=clnk&gl=es
#!/usr/bin/env ruby
require 'rubygems'
require 'wukong'
require 'wukong/encoding'
require 'crack'
@brenes
brenes / ngingx_conf
Created January 18, 2013 12:33
Nginx Configuration to redirect development assets to production site (and not having to download all the assets)
location ~* ^/.+\.(jpe?g|gif|png|ico|zip|tgz|rar|bz2|doc|xls|exe|pdf|ppt|html?|tar|mid|midi|wav|bmp|rtf|swf|avi|mp3)$ {
expires 30d;
rewrite ^ http://www.example.com/$request_uri? permanent;
break;
}