This file contains 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
start_at = Resque::Failure.count - 20 | |
finish_at = Resque::Failure.count | |
Resque::Failure.all(start_at, finish_at).each do |job| | |
puts "----------" | |
puts "#{job["failed_at"]}" | |
puts "#{job["payload"]}" | |
puts "#{job["error"]}" | |
job["backtrace"].each do |line| | |
puts "#{line}" | |
end |
This file contains 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
namespace :resque do | |
nemaspace :failed_job do | |
desc 'restart the N latest failed jobs and remove them from failed jobs queue.' | |
task :restart, [:n_latest] => [:environment] do |t, args| | |
args.with_defaults(n_latest: 20) | |
start_at = Resque::Failure.count - args[:n_latest] - 1 | |
finished_at = Resque::Failure.count - 1 | |
(start_at..finished_at).each do |index| | |
Resque::Failure.requeue_and_remove(index) | |
end |
This file contains 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
## Requirements: | |
## | |
## ruby installed | |
$> gem install awesome_print | |
Fetching: awesome_print-1.2.0.gem (100%) | |
Successfully installed awesome_print-1.2.0 | |
Parsing documentation for awesome_print-1.2.0 | |
Installing ri documentation for awesome_print-1.2.0 | |
Done installing documentation for awesome_print after 0 seconds |
This file contains 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
# Required: | |
# Mac OS | |
$> brew install exiftool | |
# Ubuntu && Debian | |
$> sudo apt-get install libimage-exiftool-perl | |
# Example: Set orientation to Normal (0°) |
This file contains 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
# In the following example some simple default options are set. | |
class Dir | |
@list_options = { hidden_files: /^\./, visible_files: /^[^\.]/, files: // } | |
def self.list(path = '.', option = :visible_files) | |
entries(path).grep(@list_options[option]) | |
end | |
end | |
# Examples |
This file contains 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 'minitest/autorun' | |
class ExtractAndSortTest < MiniTest::Unit::TestCase | |
def setup | |
@lines = [ | |
'Article 1 -- (45)', | |
'Article 2 -- (42)', | |
'Article 3 -- (62)', | |
'Article 4 -- ()' | |
] |
This file contains 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
# Example: List of all sports of the Olympic Games | |
# HTML Structure: | |
# | |
# <div id="content"> | |
# <ul> | |
# <li> | |
# <a href="...">SPORT'S NAME</a> | |
# </li> | |
# </ul> | |
# </div> |
This file contains 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 usage | |
abort 'Wrong number of argument: ruby my_fir.rb FIR_SIZE' | |
end | |
def display_trunk(width) | |
trunk_width = trunk_height = ((width / 2) - 2).round | |
(1..trunk_height).each { puts ("|" * trunk_width).center(width) } | |
end | |
def display_level(width, line_length) |
This file contains 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 Time | |
def self.yesterday | |
Time.now - (24 * 60 * 60) | |
end | |
def self.tomorrow | |
Time.now + (24 * 60 * 60) | |
end | |
def self.day_after_tomorrow |
This file contains 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
# Concrete case: Google search result URLs | |
# | |
# Requirement: | |
# gem install nokogiri | |
require 'nokogiri' | |
require 'net/http' | |
require 'uri' | |
def get(url) |
OlderNewer