Skip to content

Instantly share code, notes, and snippets.

View nauman's full-sized avatar
🚀
Need MVP? book me in https://tidycal.com/nauman

Nauman Tariq nauman

🚀
Need MVP? book me in https://tidycal.com/nauman
View GitHub Profile

How to run examples

  1. Run $ createdb uniq-db-test to create DB
  2. Run example with Ruby (e.g., $ ruby 1_find_or_create_by_single_thread.rb)

Benchmark output

With many successful INSERTs

Warming up --------------------------------------
@benoittgt
benoittgt / memory_sampling_middleware.rb
Created January 19, 2021 10:11
Memory middleware for Sidekiq
# lib/sidekiq/memory_sampling_middleware.rb
# frozen_string_literal: true
class Sidekiq::MemorySamplingMiddleware
attr_accessor :logger
def initialize(options = { logger: Sidekiq::Logging.logger })
self.logger = options.fetch(:logger) { raise 'Missing logger parameter in options' }
end
CLASS_KEY = 'class'
@premek
premek / mv.sh
Last active March 5, 2024 17:43
Rename files in linux / bash using mv command without typing the full name two times
# Put this function to your .bashrc file.
# Usage: mv oldfilename
# If you call mv without the second parameter it will prompt you to edit the filename on command line.
# Original mv is called when it's called with more than one argument.
# It's useful when you want to change just a few letters in a long name.
#
# Also see:
# - imv from renameutils
# - Ctrl-W Ctrl-Y Ctrl-Y (cut last word, paste, paste)
@bsa7
bsa7 / api_helper.rb
Created February 20, 2019 05:25
redis namespaced wrapper for rails
module Api
module V2
module ApiHelper
## Общий метод генерации ключей для кэша redis
def self.redis_key(params)
params[:locale] = I18n.locale
params_keys = params.keys.map(&:to_s).sort.map(&:to_sym)
['.', params_keys.map { |key| "#{key}:#{params[key]}" }.join('&'), '.'].join
end
end
require 'cgi'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base = Rails.application.secret_key_base)
config = Rails.application.config
cookie = CGI::unescape(cookie)
salt = config.action_dispatch.authenticated_encrypted_cookie_salt
encrypted_cookie_cipher = config.action_dispatch.encrypted_cookie_cipher || 'aes-256-gcm'
# serializer = ActiveSupport::MessageEncryptor::NullSerializer # use this line if you don't know your serializer
serializer = ActionDispatch::Cookies::JsonSerializer
@julianrubisch
julianrubisch / categories_controller.rb
Last active January 22, 2024 06:44
Dependent Select with StimulusJS
class CategoriesController < ApplicationController
def fields
render json: Field.where(category_id: params[:id]).order(:id)
end
end
@harshavardhana
harshavardhana / nginx-minio-static.md
Last active April 19, 2025 23:56 — forked from koolhead17/gist:4b8dd8d95ec86368634693cf9ad9391c
How to configure static website using Nginx with MinIO ?

How to configure static website using Nginx with MinIO ?

1. Install nginx

2. Install minio

3. Install mc client

4. Create a bucket:

$ mc mb myminio/static
Bucket created successfully ‘myminio/static’.
@mankind
mankind / rails-jsonb-queries
Last active April 14, 2025 05:43
Ruby on 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")
class Advert::UpsertVehicle
def self.call(vehicle)
@vehicle = vehicle
@outdoria = OutdoriaAPIService.new(vehicle.retailer.api_key)
return unless @request_body = VehicleData::ToRequestBody.(vehicle)
@vehicle_code = vehicle.custom_id
if @outdoria.advert_exists?(@vehicle_code)
self.update_advert
else
@arinhouck
arinhouck / TableView Image Placeholder
Created November 18, 2015 04:20
Table view image placeholder for when waiting on API to load, makes it look like table is filled with "grey text boxes"
Set on viewDidLoad()
self.tableView.backgroundColor = UIColor(patternImage: UIImage(named: "empty-cell.png")!)
Where ever you call your table reload after API call add this line:
self.tableView.backgroundColor = UIColor.whiteColor()
Here is the empty cell image used as a background pattern I made:
http://s3.postimg.org/895ohr0c3/empty_cell.png