Skip to content

Instantly share code, notes, and snippets.

Hare Ram Rai Hareramrai

Block or report user

Report or block Hareramrai

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ryanermita
ryanermita / rails_locking.md
Last active Dec 3, 2019
Optimistic and Pessimistic Locking in Rails
View rails_locking.md

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

@fabiotatsuo
fabiotatsuo / Install ElasticSearch 1.6.0 Ubuntu 15.04
Last active Dec 16, 2016
Install ElasticSearch 1.6.0 Ubuntu 15.04
View 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
@svs14
svs14 / install-couchbase-ubuntu-14.04.sh
Created Jun 13, 2015
Installs Couchbase on Ubuntu 14.04
View install-couchbase-ubuntu-14.04.sh
#!/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
@sethbro
sethbro / spec_helper.rb
Created Feb 10, 2012
Rails unit, functional and integration tests in Minitest spec format.
View spec_helper.rb
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 Oct 15, 2010 — forked from sriedel/Postgres Index Usage
Postgres: Determine table/index size
View Postgres Index Usage.sql
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 ,
View convert_ids.rb
# 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
You can’t perform that action at this time.