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 'csv' | |
# To a file | |
CSV.open('path/to/file.csv', 'wb') do |csv| | |
csv << ['row', 'of', 'CSV', 'data'] | |
csv << ['another', 'row'] | |
# ... | |
end | |
# To a String |
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
# Find out the PID of the process | |
ps -aux | grep <process-name> | |
# Check the environment variables | |
cat /proc/<pid>/environ | tr '\0' '\n' | |
# For example: | |
cat /proc/1234/environ | tr '\0' '\n' |
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
# Format | |
git log --oneline --graph | |
# To show all refs | |
git log --oneline --graph --all |
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
# TODO: This does not work | |
# To add a watcher | |
sudo auditctl -w </absolute/path/to/file> | |
# To remove a watcher | |
sudo auditctl -W </absolute/path/to/file> | |
# To list auditd rules | |
sudo auditctl -l |
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
# Format | |
sha1sum <files> | |
# Example: | |
sha1sum document.docx | |
# ab9d7658e42da2a00c56d3bc6cdf1d9d5f0d3c6e document.docx | |
# Using multiple arguments: | |
sha1sum document.docx another_file.docx | |
# ab9d7658e42da2a00c56d3bc6cdf1d9d5f0d3c6e document.docx |
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
# Format | |
while <command>; do :; done | |
# Example | |
while bundle exec rspec spec/models/project_spec.rb:15; do :; done | |
# Alternatively, you may use `until` instead of `while` to run a command until it returns a 0 exit code. | |
until <command>; do :; done |
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
# Find files by name | |
find path/to/folder -name <name or pattern> | |
# Find files and remove by name | |
find path/to/folder -name <name or pattern> -exec rm {} \; | |
# Examples | |
find ~/secrets -name super_secret.txt | |
find ~/images -name *.png |
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
# Use this commands after a git merge conflict, if you can't | |
# (or don't want to) fix the conflicts on some files. | |
# To use the base branch's file, use this: | |
git checkout --ours -- path/to/your/file.ext | |
git add path/to/file.ext | |
# To use the compare branch's file, use this: | |
git checkout --theirs -- path/to/your/file.ext | |
git add path/to/file.ext |
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
# Fetch a Rails timezone, and use it to parse a string | |
ActiveSupport::TimeZone[time_zone].parse(str) | |
# For example: | |
ActiveSupport::TimeZone['Madrid'].parse('2018-08-30 14:36') | |
# Thu, 30 Aug 2018 14:36:00 CEST +02:00 |
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
# Use this command | |
fuser path/to/file.ext | |
# For example: | |
fuser log/development.log |
NewerOlder