Skip to content

Instantly share code, notes, and snippets.

View wikiti's full-sized avatar
🚀
I are prrugrameeng 🚀

Daniel Herzog wikiti

🚀
I are prrugrameeng 🚀
View GitHub Profile
@wikiti
wikiti / csv.rb
Last active November 12, 2021 09:38
Generate CSV file or strings with ruby
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
@wikiti
wikiti / bash.sh
Last active August 20, 2019 10:54
Find the values of the inherited environment variables of a process
# 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'
@wikiti
wikiti / bash.sh
Created January 21, 2019 15:13
Show a git tree as a graph using basic git commands
# Format
git log --oneline --graph
# To show all refs
git log --oneline --graph --all
@wikiti
wikiti / bash.sh
Created January 8, 2019 13:22
Watch a file for process changes.
# 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
@wikiti
wikiti / bash.sh
Last active January 2, 2019 13:07
Use `sha1sum` command to calculate the SHA1 hash code for a set of files.
# Format
sha1sum <files>
# Example:
sha1sum document.docx
# ab9d7658e42da2a00c56d3bc6cdf1d9d5f0d3c6e document.docx
# Using multiple arguments:
sha1sum document.docx another_file.docx
# ab9d7658e42da2a00c56d3bc6cdf1d9d5f0d3c6e document.docx
@wikiti
wikiti / bash.sh
Created December 18, 2018 13:30
Run a command until it returns a non-zero exit code. Alternatively, run a command until it returns a zero exit code.
# 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
@wikiti
wikiti / bash.sh
Last active October 19, 2018 10:45
Use find command to search and delete/remove files by name (globs). This can be useful to remove temporary files.
# 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
@wikiti
wikiti / bash.sh
Last active October 9, 2018 10:05
Resolve a binary conflict when performing merges. Of course, this works too for plain text files.
# 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
@wikiti
wikiti / datetime.rb
Created October 2, 2018 13:28
Parse any datetime string on any known timezone
# 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
@wikiti
wikiti / bash.sh
Last active September 14, 2018 12:23
Find which application is using a file descriptor
# Use this command
fuser path/to/file.ext
# For example:
fuser log/development.log