Skip to content

Instantly share code, notes, and snippets.

View khalilgharbaoui's full-sized avatar
🎯
Focusing

Khalil Gharbaoui khalilgharbaoui

🎯
Focusing
View GitHub Profile
@dwkoogt
dwkoogt / delay_worker.rb
Created May 17, 2017 19:33
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 }
@bekarice
bekarice / wc-add-image-above-shop-product-images.php
Created June 15, 2015 17:34
conditionally add images above product images in the shop loop via a product's custom field
// Requires that you set a custom field on the product with logo_src = image url
function sv_add_logo_above_wc_shop_image() {
global $product;
// replace the custom field name logo_src with your own
$logo_src = get_post_meta( $product->id, 'logo_src', true );
// Add these fields to the shop loop if set
if ( ! empty( $logo_src ) ) {
@marcok
marcok / Core_loadDataSpec.js
Created November 20, 2012 13:40
bugfix: loadData should remove empty row if source data has more empt… …y rows than allowed by minSpareRows (issue #239)
describe('Core_loadData', function () {
var id = 'testContainer';
beforeEach(function () {
this.$container = $('<div id="' + id + '"></div>').appendTo('body');
});
afterEach(function () {
if (this.$container) {
this.$container.remove();
@rklemme
rklemme / find-duplicates.rb
Created April 22, 2012 11:08
Benchmark for determining duplicate positions
require 'benchmark'
REP = 100_000
dat = [1, 2, 3, 2, 4, 5, 4, 4]
Benchmark.bmbm 25 do |x|
x.report "Jan low level" do
REP.times do
dups = {}
@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'
@khalilgharbaoui
khalilgharbaoui / rails-jsonb-queries
Created October 7, 2019 00:30 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@julik
julik / kelder.rb
Last active October 22, 2019 22:33
A very very very rough version. There probably will be a gem of this
module Kelder
module PrefixKeyWithToken
# Prefix all generated blob keys with the tenant. Do not
# use slash as a delimiter because it needs different escaping
# depending on the storage service adapter - in some cases it
# might be significant, in other cases it might get escaped as a path
# component etc.
def generate_unique_secure_token
tenant_slug = Apartment::Tenant.current.split('_').last
"#{tenant_slug}-#{super}"
@riyad
riyad / application_helper.rb
Created May 23, 2012 13:45
Render Rails assets to string
module ApplicationHelper
# thanks to http://blog.phusion.nl/2011/08/14/rendering-rails-3-1-assets-to-string/
# you may need to change the owner of the tmp/cache/* directories to the web servers user
# e.g. for Debian systems: `chown -R www-data:www-data tmp/cache/*`
def render_asset(asset)
Conferator::Application.assets.find_asset(asset).body.html_safe
end
end
@loftwah
loftwah / docker-compose.yml
Created February 9, 2020 13:53 — forked from mTrax-/docker-compose.yml
Traefik v2 with ssl
version: "3.3"
services:
reverse-proxy:
image: traefik:latest
restart: unless-stopped
command:
- --api
- --providers.docker=true
- --entrypoints.web.address=:80
@amca01
amca01 / docker-compose010918.yml
Last active April 9, 2020 08:36
traefik and docker files
version: "3"
networks:
proxy:
external: true
internal:
external: false
services: