Skip to content

Instantly share code, notes, and snippets.

View francisco-rojas's full-sized avatar

Francisco Rojas francisco-rojas

  • San Jose, Costa Rica
View GitHub Profile
@francisco-rojas
francisco-rojas / Regex in Ruby.md
Last active January 9, 2019 22:12
A collection of regex basics and tips for workings with regex in ruby
@francisco-rojas
francisco-rojas / Chapter1.md
Last active August 29, 2015 14:11
Ruby Best Practices: Book Notes

Chapter 1: Driving Code Through Tests

retry and redo

redo and retry are both used to re-execute parts of a loop. But they differ in how much they re-execute: redo only repeats the current iteration, while retry repeats the whole loop from the start.

redo example:

(0..5).each do |i|
@francisco-rojas
francisco-rojas / Ubuntu Logrotate for Rails.md
Last active August 29, 2015 14:11
A basic guide on how to configure log rotation for a Rails app in Ubuntu.

To avoid the logs growing too large logrotation can be configured with Linux's logrotate tool. The logrotation configuration file is located at: /etc/logrotate.d/your_app_name Example of logrotate configuration file for a Rails app (remember to remove the comments!):

# monitor the /home/deploy/path/to/my/app/shared/log/*.log file
/home/deploy/path/to/my/app/shared/log/*.log {
        weekly # rotate weekly
        missingok #  avoids halting on any error and carries on with the next log file
        rotate 52 # 52 days worth of logs would be kept
 compress # compress using gzip

###du Summarize disk usage of each FILE, recursively for directories sorted by size

sudo du -x -h / | sort -n | tail -40

###truncate Truncate files to size 0MB

truncate -s 0 production.log
@francisco-rojas
francisco-rojas / chapter2.md
Last active August 29, 2015 14:03
Metaprogramming Ruby 2: Book Notes

Open Classes (also known as Monkey Patching)

Instead of creating a class that performs common operations on strings like this:

class StringUtils
  def self.to_alphanumeric(s)
    s.gsub(/[^\w\s]/, '')
  end
end