Skip to content

Instantly share code, notes, and snippets.

View goravbhootra's full-sized avatar
🏠
Working from home

Gorav Bhootra goravbhootra

🏠
Working from home
View GitHub Profile
@goravbhootra
goravbhootra / index_scan_cost.md
Last active September 9, 2023 04:23
index scan cost in PostgreSQL

Factors Influencing Index Scan Costs

  1. IO Cost: Costs related to reading pages from disk into memory. Parameters like random_page_cost and seq_page_cost are relevant here.

  2. CPU Cost: Overhead of computation, usually represented by cpu_tuple_cost and cpu_index_tuple_cost.

  3. Predicate Evaluation: Costs of evaluating WHERE clause conditions.

  4. Sort Cost: If the query involves sorting not covered by the index.

for f in `find . -iname '*.eex' -type f -print`;do  mv "$f" ${f%.eex}.heex; done
@goravbhootra
goravbhootra / gist:c928c49eebf5e2de8bfda4afd92a1de3
Created September 21, 2020 18:23
postgres - finding non-numeric values in a field in Rails
Table.where("field !~ '^[0-9\.]+$'")
@goravbhootra
goravbhootra / reset_pg_sequence.md
Created December 2, 2019 05:26
Reset sequence of pg table

postgres# Select setval('zones_id_seq', (SELECT max(id) from zones));

@goravbhootra
goravbhootra / rails-jsonb-queries
Created March 18, 2018 16:23 — 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")
@goravbhootra
goravbhootra / Flexible Dockerized Phoenix Deployments.md
Created February 23, 2018 06:52 — forked from jswny/Flexible Dockerized Phoenix Deployments.md
A guide to building and running zero-dependency Phoenix (Elixir) deployments with Docker. Works with Phoenix 1.2 and 1.3.

Prelude

I. Preface and Motivation

This guide was written because I don't particularly enjoy deploying Phoenix (or Elixir for that matter) applications. It's not easy. Primarily, I don't have a lot of money to spend on a nice, fancy VPS so compiling my Phoenix apps on my VPS often isn't an option. For that, we have Distillery releases. However, that requires me to either have a separate server for staging to use as a build server, or to keep a particular version of Erlang installed on my VPS, neither of which sound like great options to me and they all have the possibilities of version mismatches with ERTS. In addition to all this, theres a whole lot of configuration which needs to be done to setup a Phoenix app for deployment, and it's hard to remember.

For that reason, I wanted to use Docker so that all of my deployments would be automated and reproducable. In addition, Docker would allow me to have reproducable builds for my releases. I could build my releases on any machine that I wanted in a contai

@goravbhootra
goravbhootra / app.js
Created January 5, 2018 02:18 — forked from taiansu/app.js
Phoenix brunch config which just make sense
import "phoenix_html"
import "bootstrap"
import "jquery"
import "toastr"
// ...
@goravbhootra
goravbhootra / factory_girl_in_console.txt
Created June 16, 2017 21:40
Factory Girl in Console
FactoryGirl.definition_file_paths = ['spec/factories']
FactoryGirl.find_definitions
# You can use this line to see what factories are loaded
FactoryGirl.factories
@goravbhootra
goravbhootra / mysql-docker.sh
Created May 23, 2017 07:03 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE