Skip to content

Instantly share code, notes, and snippets.

View khalilgharbaoui's full-sized avatar
🎯
Focusing

Khalil Gharbaoui khalilgharbaoui

🎯
Focusing
View GitHub Profile
@khalilgharbaoui
khalilgharbaoui / register_chrome_with_window_size.rb
Last active September 8, 2019 05:14 — forked from mars/register_chrome_with_window_size.rb
Set window size for Capybara/Selenium/chromedriver
# This works best in 2019 forward because its basically the code from the gem itself with some tweaks added:
# https://github.com/teamcapybara/capybara/blob/master/lib/capybara/registrations/drivers.rb
# The additional option/flags work for me but you probebly want to checkout what you would need here first:
# https://peter.sh/experiments/chromium-command-line-switches/
Capybara.register_driver :selenium_chrome_headless do |app|
# Capybara::Selenium::Driver.load_selenium
browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts|
opts.args << '--window-size=1920,1080'
class Hash
def has_keys?(*keys)
keys.inject(self) do |pointer, key|
return false if !pointer.respond_to?(:has_key?) || !pointer.has_key?(key)
pointer[key]
end
true
end
end
@khalilgharbaoui
khalilgharbaoui / rspec_rails_cheetsheet.rb
Created April 9, 2019 12:40 — forked from mlr/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet with expect syntax (including capybara matchers)
# Model
expect(@user).to have(1).error_on(:username) # checks whether there is an error in username
expect(@user.errors[:username]).to include("can't be blank") # check for the error message
# Rendering
expect(response).to render_template(:index)
# Redirecting

Settting up a Container Registry with docker-gitlab

This should be used for new users to getting started with the container registry feature on docker-gitlab.

Requirements

@khalilgharbaoui
khalilgharbaoui / db.rake
Created February 3, 2019 21:29 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# Original source: https://gist.github.com/hopsoft/56ba6f55fe48ad7f8b90
# Merged with: https://gist.github.com/kofronpi/37130f5ed670465b1fe2d170f754f8c6
# Benefits of: https://gist.github.com/e12e/e0c7d2cc1d30d18c8050b309a43450ac
# And fixes of: https://gist.github.com/joelvh/f50b8462611573cf9015e17d491a8a92
namespace :db do
desc 'Dumps the database to backups'
task dump: :environment do
dump_fmt = ensure_format(ENV['format'])
dump_sfx = suffix_for_format(dump_fmt)
backup_dir = backup_directory(Rails.env, create: true)
@khalilgharbaoui
khalilgharbaoui / delay_worker.rb
Created October 23, 2018 00:36 — forked from dwkoogt/delay_worker.rb
Delay worker with delay handler and Rails adapter for Sneakers
#
# enqueue with following parameters hash:
# - headers
# - work_at - time of execution
# - work_queue - destination queue for actually doing the work
#
class DelayWorker
include Sneakers::Worker
from_queue :treadmill, { handler: Sneakers::Handlers::Delay }
  1. Add gem 'rails_12factor' to your Gemfile. This will add error logging and the ability for your app to serve static assets.
  2. bundle
  3. Run RAILS_ENV=production rake db:create db:migrate db:seed
  4. Run rake secret and copy the output
  5. From the command line: export SECRET_KEY_BASE=output-of-rake-secret
  6. To precompile your assets, run rake assets:precompile. This will create a folder public/assets that contains all of your assets.
  7. Run RAILS_ENV=production rails s and you should see your app.

Remember to clobber your assets (rake assets:clobber) and re-precompile (rake assets:precompile) if you make changes.

@khalilgharbaoui
khalilgharbaoui / swiss locales for faker
Last active May 20, 2018 22:52
swiss locals: cities, postal codes, phone numbers
de:
faker:
locales:
locale: [de, en, fr]
salutations:
de: [Herr, Frau]
en: [Mr, Mrs]
fr: [M., Mme]
address:
country_code: [CH, CH, CH, DE, AT, US, LI, US, HK, VN]
@khalilgharbaoui
khalilgharbaoui / validate_with_matcher.rb
Last active May 20, 2018 18:55 — forked from pcrglennon/validate_with_matcher.rb
RSpec matcher for validates_with
# RSpec matcher for validates_with.
# https://gist.github.com/2032846
# Usage:
#
# describe User do
# it { should validate_with CustomValidator }
# end
#
# describe User do
# it do