Skip to content

Instantly share code, notes, and snippets.

View carlesjove's full-sized avatar

Carles Jove i Buxeda carlesjove

View GitHub Profile
@carlesjove
carlesjove / executer.rb
Last active December 20, 2020 09:28
Ruby program in multiple threads (proof of concept)
# List of IDs of entities to be processed
ids = ("a".."z").to_a
# Break in groups of 5 (or any other number)
groups = ids.each_slice(5)
# Make sure that exceptions will spread.
# By default the are silenced within threads
# so you want know why your program crashed.
Thread.abort_on_exception = true
@carlesjove
carlesjove / run_script_on_heroku.sh
Created September 5, 2019 18:18
Runs a script from your computer and outputs in a file
heroku run rails c --no-tty --app APP < FILE_PATH > OUTPUT_PATH
@carlesjove
carlesjove / hashquiz.rb
Created June 29, 2019 16:47 — forked from potatosalad/hashquiz.rb
Ruby quiz for convert hash "dot paths" into actual hash hierarchy.
#require 'rubygems'
require 'pp'
#require 'ap' # Awesome Print
class Object
# expects [ [ symbol, *args ], ... ]
def recursive_send(*args)
args.inject(self) { |obj, m| obj.send(m.shift, *m) }
end
end
@carlesjove
carlesjove / useful_git_commands.md
Last active November 5, 2018 08:59
Useful Git commands

See changes introduced by last commit

$ git diff HEAD^..HEAD

diff --git a/example.rb b/example.rb
index 9c145d2..a5d3df4 100644
--- a/example.rb
+++ b/example.rb
@@ -2,7 +2,7 @@ class Example
@carlesjove
carlesjove / rspec.rb
Created March 22, 2018 07:04 — forked from 5minpause/rspec.rb
how to use sessions with capybara
# support/setup.rb
def in_browser(name)
old_session = Capybara.session_name
Capybara.session_name = name
yield
ensure
Capybara.session_name = old_session
end
@carlesjove
carlesjove / capybara cheat sheet
Created September 14, 2016 20:26 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@carlesjove
carlesjove / gist:1511f666d48eb6780abf93698132855c
Last active July 25, 2016 16:48
Importing Heroku's PG to local
$ heroku pg:backups capture --app {app name}
$ curl -o latest.dump `heroku pg:backups public-url --app {app name}`
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U {myuser} -d {mydb} latest.dump
@carlesjove
carlesjove / temping_example_to_test_module.rb
Last active March 8, 2016 08:23
How to use Temping to test a module
require "rails_helper"
# In this example I'm testing a module that introduces some
# AR validations to the model. Using shoulda matchers, as I
# normally would in a model spec, works just fine :-)
describe "Scopable concern" do
before do
Temping.create :parent_model do
end
@carlesjove
carlesjove / 0_reuse_code.js
Last active August 29, 2015 14:24
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@carlesjove
carlesjove / spec_meta_dsl.rb
Last active August 29, 2015 14:17
Draft for a CJ Spec definition that includes meta data
# Commented lines mean that this would be the assumption unless otherwise is not specified
# so:
# unless validates_as: is specified, it is validated as a :string
# unless required: true is specified, it is required: false
module CollectionJson
module Spec
definition do
defines :href, validates_as: :url