Skip to content

Instantly share code, notes, and snippets.

@nicholasrq
nicholasrq / sunspot_reindex.rb
Created September 17, 2014 04:40
Method to reindex sunspot model with progress bar. You just need to add it to any of your models.
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
@panmari
panmari / postgresql_random_retrieve.rb
Last active May 11, 2018 10:59
Benchmark of various methods to retrieve a random record from a table using ActiveRecord and a Postgresql db behind.
require 'benchmark'
# Disable logging if in development/test mode
ActiveRecord::Base.logger = nil
model_name = Icd
N = 100
Benchmark.bm(11) do |x|
x.report('ruby rand') { N.times { model_name.offset(rand(model_name.count)).first } }
@CliffordAnderson
CliffordAnderson / brew-install-script.sh
Last active May 22, 2024 08:06
Brew script for installing packages and applications on OSX
#!/bin/sh
# Homebrew Script for OSX
# To execute: save and `chmod +x ./brew-install-script.sh` then `./brew-install-script.sh`
echo "Installing brew..."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo "Installing brew cask..."
brew tap homebrew/cask