Skip to content

Instantly share code, notes, and snippets.

View maxim's full-sized avatar
🛠️

Max Chernyak maxim

🛠️
View GitHub Profile
@maxim
maxim / rails_autoload_issue.rb
Last active August 29, 2015 14:21
Problem with Rails autoload and classes used for directory namespacing
# If you have the following setup, Rails autoload will depend on load order in a hard-to-trace way:
# app/models/foo.rb
class Foo
def initialize(arg)
@arg = arg
end
end
# app/models/foo/bar.rb
@maxim
maxim / gist:1b88e10527b282022510
Last active August 29, 2015 14:23
Pin your monkey patches to certain gem version in rails
# in an early initializer
def PinMonkeypatch!(gem_name, expected_version)
if gem_spec = Gem.loaded_specs[gem_name]
actual_version = gem_spec.version.to_s
if actual_version != expected_version
raise "Monkeypatch for #{gem_name} requires version "\
"#{expected_version}, but current version is #{actual_version}"
end
else
-- here's my start.sh --
cd /var/www/tshirts/current && nohup thin start -e production -p6000 -s3 -d && cd /var/www/tshirts/current && nohup rake jaxer:sync:staging; export DISPLAY=":80" && nohup Xvfb :80 -screen 0 1280x1024x24 & nohup /opt/AptanaJaxer/scripts/start.sh
-- here's my cap deploy:start --
task :start, :roles => [:web, :db, :app] do
run "#{deploy_to}/current/config/start.sh"
end
class Color
def hex
[@red, @green, @blue].map do |el|
r = el.to_s(16)
r = '0' + r if r.size < 2
r
end.join
end
alias_method :to_s, :hex
class PagesController < ApplicationController
def index
respond_to do |format|
format.js { render :template => "pages/#{params['path']}"}
end
end
end
# step 1
def index
respond_to do |format|
format.js {render_erb}
end
end
# step 2
def index
Paperclip::Attachment.interpolations[:hashed_id_3x3] = lambda do |attachment, style|
hash = Digest::MD5.hexdigest(attachment.instance.id.to_s)
hash_path = ''
3.times { hash_path += '/' + hash.slice!(0..2) }
hash_path(1..12)
end
Paperclip::Attachment.interpolations[:hashed_id] = lambda do |attachment, style|
Digest::MD5.hexdigest(attachment.instance.id.to_s)
end
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:ApplyBreakingRules /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--> <!-- /* Font Definitions */ @font-face {font-family:SimSun; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:\"\\@SimSun\"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:\"\"; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:\"Times New Roman\"; mso-fareast-font-family:SimSun;} @p
- [F] sqlite3-ruby
- [F] flexmock
- [F] turn
- [ ] hoe = 1.8.2
- [ ] rubyforge = 1.0.1
- [I] rake = 0.8.3
- [F] rcov
- [F] paperclip
- [F] mime-types
- [R] rubyzip = 0.9.1
gem_plugin (0.2.3)
gemsonrails (0.7.2)
rubygems-update (1.3.1, 1.3.0, 1.2.0, 1.1.1)