This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # If you run unicorn on FreeBSD Jail, you might experience the following error | |
| # when you send some signals such as HUP, USR2 to master process. | |
| # adding listener failed addr=0.0.0.0:8080 (in use) | |
| # | |
| # This snippet gives you a workaround without specifying IP address. | |
| # Returns true if the host is in the Jail. | |
| def in_jail? | |
| `sysctl security.jail.jailed` =~ /security.jail.jailed: 1/ ? true : false | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # BaseJob class is an abstruct class for all jobs. | |
| # The common operations such as newrelic monitoring should be written here. | |
| # Jobs which is inherited from this class have to override instance method of perform instead of the class method to be monitored. | |
| # Please check hello_world_job.rb as an example. | |
| class BaseJob | |
| # include NewRelic::Agent::Instrumentation::ControllerInstrumentation | |
| def self.skip_mode? | |
| $rails_config && $rails_config.app_config && $rails_config.app_config['resque_skip_queue'] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def perform(member_course_id, ls_db, retry_count=0) | |
| member_course = nil | |
| begin | |
| member_course = MemberCourse.find(member_course_id) | |
| rescue ActiveRecord::RecordNotFound => e | |
| if retry_count<3 | |
| # Chances are that the job is enqueued before the transaction is | |
| # committed. #6511 | |
| Resque.enqueue_at(30.seconds.from_now, self.class, member_course_id, ls_db, retry_count+1) | |
| return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'formula' | |
| class FileMagic <Formula | |
| url 'ftp://ftp.astron.com//pub/file//file-5.04.tar.gz' | |
| homepage 'http://www.darwinsys.com/file/' | |
| md5 'accade81ff1cc774904b47c72c8aeea0' | |
| def install | |
| system "./configure" | |
| system "make install" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| kaz:~ kazueono$ irb | |
| >> bday = Time.local 2011,3,19 | |
| => Sat Mar 19 00:00:00 +0000 2011 | |
| >> bday.yday | |
| => 78 | |
| >> Time.now | |
| => Thu Feb 03 08:19:58 +0000 2011 | |
| >> Time.now.yday | |
| => 34 | |
| >> bday.yday - Time.now.yday |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Maybe | |
| def wrap_block(block) | |
| lambda do |a| | |
| a==nil ? nil : block.call(a) | |
| end | |
| end | |
| end | |
| module MaybeNumeric | |
| def wrap_block(block) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TryChain | |
| attr_reader :obj | |
| def initialize(obj) | |
| @obj = obj | |
| end | |
| def method_missing(sym,*args,&block) | |
| @obj = @obj.respond_to?(sym) ? @obj.send(sym,*args,&block) : nil | |
| self |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| A response for: | |
| https://gist.github.com/660194 | |
| https://gist.github.com/660968 | |
| https://gist.github.com/661951 | |
| I don't discuss here whether you shouldn't change the Object class behaviour. | |
| I will write my thoughts on an assumption which it were in ruby standard library. | |
| 1. Method name must be shorter at least |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # You have to define Gemspec files for Rails 2.3 libraries. A commit bellow will help it: | |
| # http://github.com/jpzwarte/rails/commit/55ede36d8907f481b18fcefa21d099f69ae9965b | |
| # Load rails from github | |
| git 'git://github.com/reallyenglish/rails.git', :branch => '2-3-re', :ref => '1760b049f43ba2ab32eb47fdc42f5638115aeb8a' do | |
| %w(active_support active_record action_pack action_mailer active_resource).each { |lib| gem lib.sub(/_/,''), '2.3.8', :require=>lib} | |
| gem 'rails', '2.3.8' | |
| end | |
| # Load rails from your local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rmagick' | |
| dir = File.dirname(__FILE__) | |
| Dir.glob "#{dir}/**/*.jpg" do |filename| | |
| image = Magick::Image.read(filename)[0] | |
| # note: there is another useful method which you can use to resize and crop square | |
| # image.resize_to_fill(200) |