Skip to content

Instantly share code, notes, and snippets.

View hemju's full-sized avatar
😃
Work Work

Helmut M Juskewycz hemju

😃
Work Work
View GitHub Profile
@hemju
hemju / PostgreSQL Index Check
Created June 3, 2014 13:48
Prints out all indices together with stats about size, reads, ....
SELECT
t.tablename,
indexname,
c.reltuples AS num_rows,
pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size,
pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size,
CASE WHEN indisunique THEN 'Y'
ELSE 'N'
END AS UNIQUE,
idx_scan AS number_of_scans,
@hemju
hemju / gist:94713cacdbac9d08071d
Last active August 29, 2015 14:03
Blog: Dynamic Ruby Example Example
def import_file_data(file_path, content, import_type, strategy_name, additional_attributes = {}, options = {})
# probably file_path is a String and the result file_name as well
file_name = File.basename(file_path)
# no idea what tempfile is, a string?
tempfile = write_to_temp_file(content, file_name)
uploaded_file = OpenStruct.new(:original_filename => file_name, :tempfile => tempfile)
# Is this now an instance of ResourceImport or a result of a resource import?
resource_import = ResourceImport.import!(user, project, uploaded_file, file_path, import_type, strategy_name, additional_attributes)
#!upstart
description "redis"
start on runlevel [23]
script
export HOME="/home/redis"
exec sudo -u redis /home/redis/redis-2.0.0-rc2/redis-server /home/redis/redis-2.0.0-rc2/redis.conf
end script
# IRBRC file by Iain Hecker, http://iain.nl
# put all this in your ~/.irbrc
require 'rubygems'
require 'yaml'
alias q exit
class Object
def local_methods
(methods - Object.instance_methods).sort
/Users/heli/.rvm/gems/ruby-1.9.2-p0/gems/json-1.4.6/lib/json/common.rb:71: warning: already initialized constant State
/Users/heli/.rvm/gems/ruby-1.9.2-p0/gems/json-1.4.6/lib/json/common.rb:72: warning: already initialized constant SAFE_STATE_PROTOTYPE
/Users/heli/.rvm/gems/ruby-1.9.2-p0/gems/json-1.4.6/lib/json/common.rb:73: warning: already initialized constant FAST_STATE_PROTOTYPE
/Users/heli/.rvm/gems/ruby-1.9.2-p0/gems/json-1.4.6/lib/json/common.rb:80: warning: already initialized constant PRETTY_STATE_PROTOTYPE
/Users/heli/.rvm/gems/ruby-1.9.2-p0/gems/json-1.4.6/lib/json/pure.rb:76: warning: already initialized constant JSON_LOADED
class Book < ActiveRecord::Base
belongs_to :auther
searchable do
text :title, :default_boost => 2
text :description
time :updated_at # for sorting by recent
integer :auther_id, :multi => true do
authers.map {|auther| auther.auther_id}
end
boolean :published, :using => :published?
@hemju
hemju / gist:1115340
Created July 30, 2011 08:48 — forked from sfilatov/gist:1109269
Migrate from Hoptoad to Airbrake
# Rails 2.3.5 - 2.3.11 environment settings (config/environment.rb)
config.gem 'airbrake', :version => '2.4.11', :require => "hoptoad_notifier"
# Rails 3 - bundler Gemfile(config/Gemfile)
gem 'airbrake', '2.4.11', :require => "hoptoad_notifier"
# In Hoptoad initializer (config/hoptoad.rb)
HoptoadNotifier.configure do |config|
config.api_key = '<api key>'
config.host = 'airbrakeapp.com'
@hemju
hemju / gist:1115341
Created July 30, 2011 08:48 — forked from sfilatov/gist:1109269
Migrate from Hoptoad to Airbrake
# Rails 2.3.5 - 2.3.11 environment settings (config/environment.rb)
config.gem 'airbrake', :version => '2.4.11', :require => "hoptoad_notifier"
# Rails 3 - bundler Gemfile(config/Gemfile)
gem 'airbrake', '2.4.11', require => "hoptoad_notifier"
# In Hoptoad initializer (config/hoptoad.rb)
HoptoadNotifier.configure do |config|
config.api_key = '<api key>'
config.host = 'airbrakeapp.com'
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ ~$ { access_log off; log_not_found off; deny all; }
# as we’re going to use Unicorn as the application server
# we’re not going to use common sockets
# but Unix sockets for faster communication
upstream linguist {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
# for UNIX domain socket setups:
server unix:/tmp/.sock fail_timeout=0;