Skip to content

Instantly share code, notes, and snippets.

@IslamAzab
IslamAzab / Installing pg_activity.bash
Last active August 29, 2015 14:24
Installing pg_activity
sudo -i
apt-get update
apt-get install -y python-pip python-dev build-essential
pip install psycopg2
pip install psutil
pip install setuptools
git clone https://github.com/julmon/pg_activity.git
cd pg_activity/
python setup.py install --with-man
@IslamAzab
IslamAzab / Error trace
Created June 9, 2015 15:11
Ruby Bug #11240 "[BUG] Segmentation fault"
[1] pry(#<#<Class:0x000000068defe0>>)> quit-program
/home/myuser/.rvm/gems/ruby-2.0.0-p451@mygemset/gems/activesupport-3.2.18/lib/active_support/notifications.rb:125: [BUG] Segmentation fault
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0062 p:0002 s:0343 e:000342 EVAL /home/myuser/.rvm/gems/ruby-2.0.0-p451@mygemset/gems/activesupport-3.2.18/lib/active_support/notifications.rb:125 [FINISH]
c:0061 p:---- s:0341 e:000340 CFUNC :eval
c:0060 p:0010 s:0337 E:002598 BLOCK /home/myuser/.rvm/gems/ruby-2.0.0-p451@mygemset/gems/better_errors-2.1.1/lib/better_errors/raised_exception.rb:37 [FINISH]
c:0059 p:---- s:0331 e:000330 CFUNC :map
[user]
name =
email =
[color]
ui = true
[merge]
log = true
tool = meld
[alias]
st = status -s -uno
-- POSTGRESQL check for duplicate primary keys due to
-- BUG #11141: Duplicate primary key values corruption
-- http://www.postgresql.org/message-id/20140811083748.2536.10437@wrigleys.postgresql.org
-- Select all tables (excluding schema_migrations table)
-- SELECT TABLE_NAME AS tablename
-- FROM information_schema.tables
-- WHERE table_schema = 'public'
-- AND TABLE_NAME != 'schema_migrations'
-- ORDER BY TABLE_NAME;
@IslamAzab
IslamAzab / .gemrc
Last active August 29, 2015 14:17 — forked from jch/.gemrc
gemrc example
# http://guides.rubygems.org/command-reference/#gem-environment
---
gem: --no-document --verbose --backtrace
update_sources: true
backtrace: true

I'm hunting for the best solution on how to handle keeping large sets of DB records "sorted" in a performant manner.

Problem Description

Most of us have work on projects at some point where we have needed to have ordered lists of objects. Whether it be a to-do list sorted by priority, or a list of documents that a user can sort in whatever order they want.

A traditional approach for this on a Rails project is to use something like the acts_as_list gem, or something similar. These systems typically add some sort of "postion" or "sort order" column to each record, which is then used when querying out the records in a traditional order by position SQL query.

This approach seems to work fine for smaller datasets, but can be hard to manage on large data sets with hundreds (or thousands) of records needing to be sorted. Changing the sort position of even a single object will require updating every single record in the database that is in the same sort group. This requires potentially thousands of wri

def self.reindex!
model_name = self.name.to_s
total = self.count
indexed = 0.to_f
progress = 0.to_f
row_length = 100.to_f
log_level = Sunspot::Rails::LogSubscriber.logger.level
time_start = Time.now
each_second = Time.now
per_second = 0
@IslamAzab
IslamAzab / .irbrc
Last active August 29, 2015 14:14 — forked from erichurst/.irbrc
# Make gems available
require 'rubygems'
begin
require "ap"
alias pp ap
rescue LoadError
puts "Please install the 'awesome_print' gem."
end
@IslamAzab
IslamAzab / rtl support in gnome terminal.md
Last active August 17, 2022 20:52
How to enable Arabic support in GNOME terminal?
sudo apt-get install libfribidi0 libfribidi-dev

Download the appropriate package from here

vim /usr/share/applications/gnome-terminal.desktop

add this

Terminal=true

Exec=/usr/bin/bicon.bin

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.