Skip to content

Instantly share code, notes, and snippets.

View Hareramrai's full-sized avatar

Hare Ram Rai Hareramrai

View GitHub Profile
@ryanermita
ryanermita / rails_locking.md
Last active February 17, 2024 02:19
Optimistic and Pessimistic Locking in Rails

Optimistic Locking assumes that a database transaction conflict is very rare to happen. It uses a version number of the record to track the changes. It raise an error when other user tries to update the record while it is lock.

usage

Just add a lock_version column to the table you want to place the lock and Rails will automatically check this column before updating the record.

Pessimistic locking assumes that database transaction conflict is very likely to happen. It locks the record until the transaction is done. If the record is currently lock and the other user make a transaction, that second transaction will wait until the lock in first transaction is release.

usage

@dougvj
dougvj / mysql-to-postgres.sh
Last active February 6, 2024 14:19
Mysql to Postgres SQL file conversion
# Adapted from github comment:
# https://github.com/dimitri/pgloader/issues/782#issuecomment-1136067634
if [ -z "$3" ]; then
echo "Usage: $0 <db name> <mysql dump> <psql dump output>"
echo "Requirements: docker"
exit 1
fi
if ! command -v docker &> /dev/null
@sethbro
sethbro / spec_helper.rb
Created February 10, 2012 01:09
Rails unit, functional and integration tests in Minitest spec format.
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rubygems'
gem 'minitest'
require 'minitest/autorun'
require 'action_controller/test_case'
require 'miniskirt'
require 'capybara/rails'
@next2you
next2you / Postgres Index Usage.sql
Created October 15, 2010 20:12 — forked from sriedel/Postgres Index Usage
Postgres: Determine table/index size
SELECT idx.relname as table,
idx.indexrelname as index,
pg_relation_size( idx.indexrelname::text )/1024/1024 as bytes,
cls.relpages as pages,
cls.reltuples as tuples,
idx.idx_scan as scanned,
idx.idx_tup_read as read,
idx.idx_tup_fetch as fetched
FROM pg_stat_user_indexes idx,
pg_class cls ,
@svs14
svs14 / install-couchbase-ubuntu-14.04.sh
Created June 13, 2015 04:34
Installs Couchbase on Ubuntu 14.04
#!/bin/bash
# Installs Couchbase on Ubuntu 14.04
wget -L http://packages.couchbase.com/releases/3.0.3/couchbase-server-enterprise_3.0.3-ubuntu12.04_amd64.deb
sudo dpkg -i couchbase-server-enterprise_3.0.3-ubuntu12.04_amd64.deb
rm -f couchbase-server-enterprise_3.0.3-ubuntu12.04_amd64.deb
@fabiotatsuo
fabiotatsuo / Install ElasticSearch 1.6.0 Ubuntu 15.04
Last active December 16, 2016 16:21
Install ElasticSearch 1.6.0 Ubuntu 15.04
Install Java
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
sudo aptitude -y install oracle-java8-installer
java -version
Install ElasticSearch
wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.6.0.deb
# with multiple collections + commands for renaming back the collections
require 'mongo'
# Stop writing to your database.
# Then, for each collection:
# Specify the DB and COLLECTION you want to convert.
# Will insert all modified documents into a new collection
# called 'new_' + old_collection_name.
# Then you can delete the old collection and rename the new one