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
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
# CLOSURES IN RUBY Paul Cantrell https://innig.net | |
# Email: username "cantrell", domain name "pobox.com" | |
# I recommend executing this file, then reading it alongside its output. | |
# | |
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments, | |
# then trying to guess the output of the code! | |
# A closure is a block of code which meets three criteria: | |
# |
Name | Aliases | Description |
---|---|---|
$! | $ERROR_INFO | The exception information message set by the last 'raise' (last exception thrown). |
$@ | $ERROR_POSITION | Array of the backtrace of the last exception thrown. |
$& | $MATCH | The string matched by the last successful pattern match in this scope. |
$` | $PREMATCH | The string to the left of the last successful match. |
$' | $POSTMATCH | The string to the right of the last successful match. |
$+ | $LAST_PAREN_MATCH | The last group of the last successful match. |
$1 to $9 | The Nth group of the last successful regexp match. | |
$~ | $LAST_MATCH_INFO | The information about the last match in the current scope. |
In order to have your cache always created with a group of www-data you need to do the following:
cd yourrailsapp
chgrp www-data ./tmp
sudo chmod g+s tmp
This sets the group id on your folder so that everything underneath tmp gets created with the correct permissions
References:
Using curl to log in setting the cookie and extracting the CSRF token:
curl http://localhost:3000/users/sign_in --cookie-jar cookie | grep csrf
curl http://localhost:3000/users/sign_in -L --data "user[email]=user@users.com&user[password]=my_password&authenticity_token=oy4J2HVPezOc5JrTXMyaSjeCDHhN%2Bv5yVzlvShm%2FjFc%3D" --cookie cookie
To create a Read only user
Access postgres console:
sudo -u postgres psql
Create user and grant read access to the database
CREATE USER user_name WITH ENCRYPTED PASSWORD 'your_password';
CREATE DATABASE user_name;
###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