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
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 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
## 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 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
# Required: | |
# Mac OS | |
$> brew install exiftool | |
# Ubuntu && Debian | |
$> sudo apt-get install libimage-exiftool-perl | |
# Example: Set orientation to Normal (0°) |
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
# 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 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 'minitest/autorun' | |
class ExtractAndSortTest < MiniTest::Unit::TestCase | |
def setup | |
@lines = [ | |
'Article 1 -- (45)', | |
'Article 2 -- (42)', | |
'Article 3 -- (62)', | |
'Article 4 -- ()' | |
] |
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
# 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 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 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 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
# Concrete case: Google search result URLs | |
# | |
# Requirement: | |
# gem install nokogiri | |
require 'nokogiri' | |
require 'net/http' | |
require 'uri' | |
def get(url) |
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
# The goal of this code snippet isn't to make an email validator.. | |
# So the REGEX is not steady but works for simple cases. | |
# | |
# You can extract whatever you want by changing the Regex. :) | |
line = "Congratulation ! here is your email : mehdi-farsi@long-and_boring-company_name.com. Are you happy ?" | |
email = line[/(\w|[\.\-])+@(\w|[\.\-])+\.[a-zA-Z]+/] |
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 Vehicle; end | |
class Car < Vehicle | |
def initialize | |
# A composition to separate standalone Engine class. | |
# That permit to create a class Bicycle without give it | |
# the property of an engine Vehicle. | |
@engine = GasolineEngine.new | |
end |
OlderNewer