Skip to content

Instantly share code, notes, and snippets.

View mrsimo's full-sized avatar
💃
./do run hello

Albert Llop mrsimo

💃
./do run hello
View GitHub Profile
@mrsimo
mrsimo / helper.rb
Created September 28, 2012 15:26
Ugly helper
def filter_dropdown(select_options, options)
current_text = select_options.find { |text, filter| filter == options[:current] }.try(:first) || select_options.first.first
image = '<img height="6" width="8" src="/img/v/transparent_r1.gif" class="icn icn-ext-ctr-arrow-down">'
link = content_tag :strong do
link_to("#{current_text} #{image}".html_safe, "#", :"data-simplelayer" => "##{options[:key]}")
end
uls = content_tag :ul, :id => options[:key], :class => "dropdown", :style => "display:none" do
select_options.map do |text,key|
klass = (options[:current] == key ? 'selected' : nil)
@mrsimo
mrsimo / rest_object.rb
Created January 15, 2013 09:48
This used to work in ruby 1.8 In ruby 1.9 it creates an endless recursion. Where's my mistake?
class RestObject
(...)
##
# To be able to serialize objects they can't have Proc's, and @response/@request
# have them. So we remove them before actually doing the to_yaml.
def to_yaml(*args)
old_values = @response, @request
@response, @request = nil, nil
build_package_patch_ruby_railsexpress() {
fetch_git rvm-patchsets git://github.com/skaes/rvm-patchsets.git master
for p in rvm-patchsets/patches/ruby/1.9.3/p327/railsexpress/* ; do
patch -p1 < $p
done
}
install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz"
install_package "ruby-1.9.3-p327" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz" patch_ruby_railsexpress autoconf standard
build_package_patch_ruby_railsexpress() {
fetch_git rvm-patchsets git://github.com/skaes/rvm-patchsets.git master
for p in rvm-patchsets/patches/ruby/1.9.3/p392/railsexpress/* ; do
patch -p1 < $p
done
}
install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz"
install_package "ruby-1.9.3-p392" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz" patch_ruby_railsexpress autoconf standard
@mrsimo
mrsimo / rewrite.rb
Created June 15, 2017 10:52
Convert all those controller tests to the new Rails 5 syntax
require 'parser/current'
require 'byebug'
class FixGets < Parser::Rewriter
def on_send(node)
receiver_node, method_name, *args = *node
if [:get, :patch, :post, :put, :delete, :mobile_get].include?(method_name)
if args.size > 1 && !args[1].loc.expression.source.include?("xhr: true")
rub = args[1].loc.expression.source
@mrsimo
mrsimo / rewriter.rb
Created June 16, 2017 10:34
Rewrite tests from def test_ to test "" and setup/teardown blocks
require 'parser/current'
require 'byebug'
class FixDefTest < Parser::Rewriter
def on_def(node)
name, args_node, body_node = *node
if name.to_s.start_with?("test_")
replace(node.location.keyword, "test")
replace(node.location.name, %("#{name.to_s.gsub(/^test_/, "").gsub("_", " ")}" do))
end
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
// Place your settings in this file to overwrite the default settings
{
"files.autoSave": "onFocusChange",
"search.useIgnoreFiles": true,
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"test/vcr_cassettes": true,
},
"git.enabled": false,