Skip to content

Instantly share code, notes, and snippets.

Avatar
💃
./do run hello

Albert Llop mrsimo

💃
./do run hello
View GitHub Profile
View gist:4f54bd620c4fbfe9e7e90aa052c91909
// 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,
View syck-schema-cache.rb
# 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
@mrsimo
mrsimo / rewriter.rb
Created Jun 16, 2017
Rewrite tests from def test_ to test "" and setup/teardown blocks
View rewriter.rb
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
@mrsimo
mrsimo / rewrite.rb
Created Jun 15, 2017
Convert all those controller tests to the new Rails 5 syntax
View rewrite.rb
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
View gist:6155671
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
View 1.9.3-p327-railsexpress
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
@mrsimo
mrsimo / rest_object.rb
Created Jan 15, 2013
This used to work in ruby 1.8 In ruby 1.9 it creates an endless recursion. Where's my mistake?
View rest_object.rb
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
View helper.rb
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 / helper.rb
Created Jul 16, 2012
This SCREAMS to be moved to a model -_-
View helper.rb
def participation_options(invitation)
options = []
options << :yes if invitation.can_change_to_yes? || invitation.can_buy_tickets? || invitation.participation == :yes
options << :maybe if invitation.can_change_to_maybe? || invitation.participation == :maybe
options << :no if invitation.can_change_to_no? || invitation.participation == :no
options
end
@mrsimo
mrsimo / request.rb
Created Jul 4, 2012
HTTPS request with Net::HTTP and basic http auth
View request.rb
site = URI("https://some.domain.net/path?event_id=#{event.id}")
http = Net::HTTP.new(site.host, site.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if Rails.env.development?
http.open_timeout = 1
http.read_timeout = 1
req = Net::HTTP::Get.new("#{site.path}?#{site.query}")
req.basic_auth 'user', 'pass'