Skip to content

Instantly share code, notes, and snippets.

View khalilgharbaoui's full-sized avatar

Khalil Gharbaoui khalilgharbaoui

View GitHub Profile
khalilgharbaoui /
Created March 13, 2024 23:14 — forked from edisoncosta/
woo-commerce fastcgi-cache session-conflict solution (attempt)

You can jump to code directly

How it works?

1. Cache product pages

Following line does't have /products.* page. This tells Nginx to cache all product pages by default.

Idea is fast loading product pages will improve scalability of a store and also conversion.

khalilgharbaoui / mime.types
Created March 9, 2024 05:42 — forked from zeroasterisk/mime.types
nginx config: /etc/nginx/mime.types
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/x-javascript js;
application/atom+xml atom;
application/rss+xml rss;
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:
# 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)
class ParamsSlicer
def initialize(params, *whitelist)
@params = params
@nested_whitelist = whitelist.extract_options!
@whitelist = whitelist
def call
params.slice(*whitelist).tap do |result|
nested_whitelist.each do |k, v|
khalilgharbaoui / database.rake
Created June 10, 2021 07:06 — forked from olivierlacan/database.rake
Database rake tasks that I use on Code School to ferret out huge tables with millions of rows and see how many indices they have and to see which tables have missing indices on associated tables (foreign keys). The latter was taken from this great post by Tom Ward:
namespace :database do
task fat_tables: :environment do
c = ActiveRecord::Base.connection
max_table_name_width = 0
tables = c.tables.sort_by do |t|
max_table_name_width = t.length if t.length > max_table_name_width
khalilgharbaoui /
Created May 24, 2020 03:59 — forked from jaytaylor/
One liner for deleting images from a v2 docker registry

One liner for deleting images from a v2 docker registry

Just plug in your own values for registry and repo/image name.

curl -v -sSL -X DELETE "http://${registry}/v2/${name}/manifests/$(
    curl -sSL -I \
        -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
khalilgharbaoui / css-color-regex
Last active February 8, 2020 16:27 — forked from olmokramer/css-color-regex
Regex for CSS colors: hex, rgb(a), hsl(a) and named colors (149 + transparant)
khalilgharbaoui /
Created December 29, 2019 08:16 — forked from delameko/
Upgrading PostgreSQL from 9.5 to 9.6 on Ubuntu 16.04


Install Postgres 9.6, and then:

sudo pg_dropcluster 9.6 main --stop
sudo pg_upgradecluster 9.5 main
sudo pg_dropcluster 9.5 main
khalilgharbaoui / vcr_webmock_and_live_http_simultaneously.rb
Created November 21, 2019 08:07 — forked from jspillers/vcr_webmock_and_live_http_simultaneously.rb
Sandbox test to get VCR, WebMock, and "real" http all working side by side in the same spec suite
require 'rubygems'
require 'rspec'
require 'webmock'
require 'vcr'
require 'pry'
# in a Rails app, this would be in an initializer
allow_localhost: true,
net_http_connect_on_start: true
khalilgharbaoui / spec_helper.rb
Created October 19, 2019 23:19 — forked from pauljamesrussell/spec_helper.rb
RSpec matcher for ensuring a model is accepting nested attributes for an association, and accepting/rejecting the right values.
# Use: it { should accept_nested_attributes_for(:association_name).and_accept({valid_values => true}).but_reject({ :reject_if_nil => nil })}
RSpec::Matchers.define :accept_nested_attributes_for do |association|
match do |model|
@model = model
@nested_att_present = model.respond_to?("#{association}_attributes=".to_sym)
if @nested_att_present && @reject
@reject_success = model.send("#{association}").empty?