Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Khalil Gharbaoui khalilgharbaoui

View GitHub Profile
@khalilgharbaoui
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
View GitlabContainerRegistrySetup.md

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 Feb 3, 2019 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
View db.rake
# 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 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
khalilgharbaoui / swiss locales for faker
Last active May 20, 2018
swiss locals: cities, postal codes, phone numbers
View swiss locales for faker
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 — forked from pcrglennon/validate_with_matcher.rb
RSpec matcher for validates_with
View validate_with_matcher.rb
# 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
@khalilgharbaoui
khalilgharbaoui / alias_matchers.md
Created Apr 23, 2018 — forked from JunichiIto/alias_matchers.md
List of alias matchers in RSpec 3
View alias_matchers.md

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.