Skip to content

Instantly share code, notes, and snippets.

Creating Rails Project

Initialization

# List available rubies, to choose which ruby to use
$ rvm list rubies

# To install new ruby use, for example version '2.4.1'
$ rvm install 2.4.1
@IslamAzab
IslamAzab / http_server_auth.py
Created July 29, 2022 14:41 — forked from mauler/http_server_auth.py
Python3 http.server supporting basic HTTP Auth (username/password)
# Extended python -m http.serve with --username and --password parameters for
# basic auth, based on https://gist.github.com/fxsjy/5465353
from functools import partial
from http.server import SimpleHTTPRequestHandler, test
import base64
import os
class AuthHTTPRequestHandler(SimpleHTTPRequestHandler):
@IslamAzab
IslamAzab / imagemagick-install-steps.bash
Last active December 9, 2015 15:54 — forked from rodleviton/imagemagick-install-steps
Installing Image Magick on Ubuntu 14.04
sudo -i
cd
apt-get install build-essential checkinstall && apt-get build-dep imagemagick -y
sudo apt-get install libperl-dev gcc libjpeg-dev libbz2-dev libtiff4-dev libwmf-dev libz-dev libpng12-dev libx11-dev libxt-dev libxext-dev libxml2-dev libfreetype6-dev liblcms1-dev libexif-dev perl libjasper-dev libltdl3-dev graphviz pkg-config
wget http://www.imagemagick.org/download/ImageMagick.tar.gz
tar xf ImageMagick.tar.gz
cd ImageMagick-6.9.2-8/
./configure --prefix=/opt/imagemagick-6.9
make
make install
@IslamAzab
IslamAzab / net-http-debug.rb
Created October 20, 2015 11:16 — forked from ahoward/net-http-debug.rb
a simple way to debug tons of libs that use ruby's net/http
BEGIN {
require 'net/http'
Net::HTTP.module_eval do
alias_method '__initialize__', 'initialize'
def initialize(*args,&block)
__initialize__(*args, &block)
@IslamAzab
IslamAzab / sublime-3-better_errors.md
Last active September 29, 2015 13:35 — forked from stevenpetryk/sb2-better_errors.md
Using Sublime Text 3 with better_errors on Ubuntu

Using better_errors on Ubuntu with SublimeText 3

After I installed the fantastic better_errors gem, I was disappointed to notice that linking to your text editor doesn't work correctly on Ubuntu (at least, it didn't for me). Here's how I fixed it.

First, create a new desktop entry:

# /usr/share/applications/subl-urlhandler.desktop
@IslamAzab
IslamAzab / benchmark.sh
Last active September 7, 2015 17:21 — forked from emersonmoretto/benchmark.sh
Apache bench + Gnuplot Script
#!/bin/bash
echo -e "\nbenchmark.sh -n<number of requests> -c<number of concurrency> <URL1> <URL2> ..."
echo -e "\nEx: benchmark.sh -n100 -c10 http://www.google.com/ http://www.bing.com/ \n"
## Gnuplot settings
echo "set terminal jpeg
set output 'benchmark_${1}_${2}.jpeg'
set title 'Benchmark: ${1} ${2}'
@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