Skip to content

Instantly share code, notes, and snippets.

View mhenrixon's full-sized avatar
🐢
I may be slow to respond.

Mikael Henriksson mhenrixon

🐢
I may be slow to respond.
View GitHub Profile
@mhenrixon
mhenrixon / progressbar.pas
Created April 19, 2012 07:58
Jeeves JML progressbar
oPrgBar := Application.CreateProgressDlg('Some message to display',5);
If oPrgBar <> '' then begin
//Display progress bar
oPrgBar.SetStyle(0); //0 = straight, 1 = Circular
oPrgBar.SetCancelButton(false); //Disable cancel
oPrgBar.show;
oPrgBar.IncCount; //Display incremention
sleep(1000);
oPrgBar.IncCount; //Display incremention
sleep(1000);
@mhenrixon
mhenrixon / bootstrap_ruby.sh
Created July 16, 2012 07:16 — forked from ryanb/chef_solo_bootstrap.sh
Bootstrap ruby 1.9.3
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar -xvzf ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194/
./configure --prefix=/usr/local
make
make install
@mhenrixon
mhenrixon / configuring tire for bonsai.md
Created July 17, 2012 20:17 — forked from nz/configuring tire for bonsai.md
Configuring Tire to work with Bonsai

Configuring Tire to use the Bonsai ElasticSearch Heroku add-on

gem 'tire', '~> 0.4.1'

Bonsai provisions one ElasticSearch index per application. Tire, however, assumes that each model is using its own index.

Currently the best way to work around this is to set the Tire.configuration.url and the model's index_name manually.

@mhenrixon
mhenrixon / exit_code_patch.rb
Created August 16, 2012 08:35
Monkey patch to make ruby exit codes work with continuous integration
# Monkey Patch ruby because of a bug introduced in ruby versions greater than 1.9.2
# For some reason the exit code is all wrong in later version of ruby and even though
# the issue was closed as sorted it's still broken in ruby version 1.9.3-p194.
# (see http://redmine.ruby-lang.org/issues/5218 for more information)
# Put this in spec_helper.rb or test_helper.rb so that it only affects specs and the CI server.
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION >= "1.9"
module Kernel
alias :__at_exit :at_exit
def at_exit(&block)
__at_exit do
@mhenrixon
mhenrixon / console.js
Created October 2, 2012 14:37 — forked from dagda1/console.js
console.js
if (typeof console === "undefined" || typeof console.log === "undefined") {
console = {
log: function() {
}
};
}
@mhenrixon
mhenrixon / user_spec.rb
Created November 13, 2012 09:56
Comparison of RSpec with Test Unit
require 'spec_helper'
describe User do
describe "#password_reset" do
let(:site) { create :site }
let(:user) { create :user }
it "creates a password_reset_token" do
expect{
user.send_password_reset(site)
@mhenrixon
mhenrixon / template_spec.rb
Created November 13, 2012 10:19
More comparisons
require 'spec_helper'
describe Template do
let(:site) { create :site }
let(:template) { create :template, name: "ABCD", tpl_type: 'tpl', site: site }
subject { template }
# this also tests downcasing names
its(:tpl_name) { should eql('abcd.tpl') }
its(:dirname) { should eql("#{Rails.root}/public/sites/#{template.site_id}/templates") }
@mhenrixon
mhenrixon / query_methods.rb
Created November 19, 2012 10:04
Where to add query methods?
# 1
List.fetch_by_slug(@site, 'mys-slug')
# 2 - adding query methods on the collection
@site.lists.fetch_by_slug('my-slug')
# How achieved
class Site < ActiveRecord::Base
has_many :lists do
def fetch_by_slug(slug)
class AddCountTriggers < ActiveRecord::Migration
def up
execute %q{
CREATE OR REPLACE FUNCTION update_task_counters (taskid integer)
RETURNS void AS $$
BEGIN
update tasks set
users_count = coalesce((select count(9) from taskships where task_id = taskid), 0)
where id = taskid;
END;
@mhenrixon
mhenrixon / create_task_trigger.sql
Created November 22, 2012 19:04
How to achieve rails counter_cache directly in the database.
CREATE TRIGGER update_task_counters
AFTER INSERT OR UPDATE OR DELETE ON tasks
FOR EACH ROW EXECUTE PROCEDURE update_task_counters();