Skip to content

Instantly share code, notes, and snippets.


Khalil Gharbaoui khalilgharbaoui

View GitHub Profile
khalilgharbaoui / rspec_rails_cheetsheet.rb
Created Apr 9, 2019 — forked from mlr/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet with expect syntax (including capybara matchers)
View rspec_rails_cheetsheet.rb
# 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.


khalilgharbaoui / db.rake
Created Feb 3, 2019 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
View db.rake
# Original source:
# Merged with:
# Benefits of:
# And fixes of:
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 / delay_worker.rb
Created Oct 23, 2018 — forked from dwkoogt/delay_worker.rb
Delay worker with delay handler and Rails adapter for Sneakers
View delay_worker.rb
# 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 }
View running_app_in_production_locally.markdown
  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 / swiss locales for faker
Last active May 20, 2018
swiss locals: cities, postal codes, phone numbers
View swiss locales for faker
locale: [de, en, fr]
de: [Herr, Frau]
en: [Mr, Mrs]
fr: [M., Mme]
country_code: [CH, CH, CH, DE, AT, US, LI, US, HK, VN]
khalilgharbaoui / validate_with_matcher.rb
Last active May 20, 2018 — forked from pcrglennon/validate_with_matcher.rb
RSpec matcher for validates_with
View validate_with_matcher.rb
# RSpec matcher for validates_with.
# Usage:
# describe User do
# it { should validate_with CustomValidator }
# end
# describe User do
# it do
khalilgharbaoui /
Created Apr 23, 2018 — forked from JunichiIto/
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value
View gitcheats.txt
# shortform git commands
alias g='git'
# push changes to an empty git repository for the first time
git push --set-upstream origin master
# remove untracked files in a git repository
git status -su | cut -d' ' -f2- | tr '\n' '\0' | xargs -0 rm
# get most modified files and counts
You can’t perform that action at this time.