Skip to content

Instantly share code, notes, and snippets.

View batasrki's full-sized avatar

Srdjan Pejic batasrki

  • S-Squared Design & Development
  • Toronto, ON
View GitHub Profile
@batasrki
batasrki / job_display_work_window.rb
Created September 25, 2011 23:06
Example model display work window
class Job < ActiveRecord::Base
def display_work_window
if (self.starttime && self.endtime)
self.starttime.strftime("%b %d, %Y") + " ~ " + self.endtime.strftime("%b %d, %Y")
elsif self.starttime
"Work commences on "+ self.starttime.strftime("%b %d, %Y")
elsif self.endtime
"Work completed by "+ self.endtime.strftime("%b %d, %Y")
else
"No date range specified"
@batasrki
batasrki / job_display_v2.rb
Created September 25, 2011 22:58
Example model display method -- better
class Job < ActiveRecord::Base
def display_name
"#{I18n.t('web-app-theme.job', :default => 'Job')}#: #{leading_zeros(self.id, 5)} / #{self.category.name} : #{self.name}"
end
def display_shortname
if self.name
"#{self.name}(#{self.category.name})"
else
"#{I18n.t('web-app-theme.job', :default => 'Job')}#: #{leading_zeros(self.id, 5)}"
@batasrki
batasrki / job_display_spec.rb
Created September 25, 2011 22:52
Example model display spec
describe Job do
before :each do
@mock_job_category = JobCategory.create!({:name => "Tester"})
@mock_client = mock_model(Client, {:name => "Test Client"})
@job = Job.new(:name => "test job", :client => @mock_client,
:category => @mock_job_category)
end
describe "display name" do
@batasrki
batasrki / job_display.rb
Created September 25, 2011 22:47
Example model display method
class Job < ActiveRecord::Base
def display_name
I18n.t("web-app-theme.job", :default => "Job")+"#: "+leading_zeros(self.id, 5)+" / "+self.category.name+" : "+self.name
end
def display_shortname
if self.name
self.name+"("+self.category.name+")"
else
I18n.t("web-app-theme.job", :default => "Job")+"#: "+leading_zeros(self.id, 5)
@batasrki
batasrki / work.rb
Created September 25, 2011 22:19
Example model
class Job < ActiveRecord::Base
validates_presence_of :name, :category, :client
end
@batasrki
batasrki / work_spec.rb
Created September 25, 2011 22:12
Example model spec
require 'spec_helper.rb'
describe Job do
before :each do
@job_category = JobCategory.create!({:name => "Tester"})
@mock_client = mock_model(Client, {:name => "Test Client"})
@job = Job.new(:name => "test job", :client => @mock_client,
:category => @mock_job_category)
end
@batasrki
batasrki / debugger.markdown
Created July 20, 2011 20:32 — forked from jcasimir/debugger.markdown
Ruby Debugger

Ruby Debugger

Most of the time simple output statements using warn, raise, or a logger will help you find your issue. But sometimes you need the big guns, and that means ruby-debug.

Ruby-Debug

The ruby-debug package has had some rocky times during the transition from Ruby 1.8.7 to 1.9.2 and beyond. But now, finally, the debugger is reliable and usable.

Installation

Currently the RubyGems index is stored as a Gzip file that is a marshalled array. Whenever Bundler needs to install a gem that is not yet installed it downloads the index, gunzips it and unmarshals it. It then looks for dependencies that are described in another file that is also a gzipped and marshalled file. There are several issues that arise from this setup:

  • The full index must be downloaded and parsed, but does not contain dependency data, which must then be downloaded and parsed. This is a relatively time consuming process.
  • The index must be centralized.

Additionally the gems themselves are currently centralized since there is nothing in the meta data that indicates where the gem should be downloaded from. However in order to allow this it is important to find ways of keeping the index from being poisoned (is this an issue in the centralized system?)

Dependency Resolution

@batasrki
batasrki / gist:1025499
Created June 14, 2011 18:17
rbx backtrace for devise issue
actionpack (3.0.5) lib/abstract_controller/helpers.rb:153:in `modules_for_helpers'
kernel/bootstrap/array.rb:117:in `map!'
actionpack (3.0.5) lib/abstract_controller/helpers.rb:144:in `modules_for_helpers'
actionpack (3.0.5) lib/action_controller/metal/helpers.rb:101:in `modules_for_helpers'
actionpack (3.0.5) lib/abstract_controller/helpers.rb:97:in `helper'
devise (1.3.4) lib/devise/controllers/internal_helpers.rb:12:in `InternalHelpers'
kernel/common/eval.rb:199:in `class_eval (module_eval)'
activesupport (3.0.5) lib/active_support/concern.rb:52:in `append_features'
kernel/delta/module.rb:75:in `include'
kernel/common/array.rb:1492:in `reverse_each'
class EngineVariant
def api_representation
{ engine: engine, locale: locale }
end
end