Discover Snippets

joe / installrubyrbenv.txt Created at Mon Jun 22 06:47:33 CDT 2020
Install Ruby using rbenv
git clone ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec bash
git clone ~/.rbenv/plugins/ruby-build
rbenv install 2.7.1
rbenv global 2.7.1
joe / bash_get-unix-timestamp-ms.txt Created at Sun Oct 13 23:53:52 CDT 2019
Get the Unix timestamp in milliseconds for the specified date and/or time. The date and time can be formatted in a multitude of different ways.
echo $(($(date -d 'date_and_time' +'%s') * 1000))

Some valid date and time formats are:

* 'YYYY-mm-ddTHH:mm:ss'
* 'mm/dd/YYYYThh:mm:ss'
* 'YYYYmmdd hh:mm'

Relative formats are also acceptable:
joe / matrix-synapse_purge-remote-media.txt Created at Sun Oct 13 23:52:14 CDT 2019
Purge remote media from Synapse last accessed before the specified Unix timestamp in milliseconds. Replace domain, timestamp, and token.
curl -X POST "https://domain.tld/_synapse/admin/v1/purge_media_cache?before_ts=unix_timestamp_ms&access_token=token" --data '{}'
joe / matrix-synapse_change-community-admin.txt Created at Sat Sep 14 15:44:27 CDT 2019
Change admin status in Matrix community. Replace community and user IDs with relevant values. See
Connect to the synapse database (in postgres):
\c synapse

To list community members:
SELECT * FROM group_users;

To grant user admin status in a community:
UPDATE group_users SET is_admin='t' WHERE group_id='+community:domain.tld' AND user_id='@user:domain.tld';
joe / deactivate-matrix-account.txt Created at Tue Sep 10 13:06:30 CDT 2019
Deactivate a Matrix account. Replace domain, ID, and token with relevant values.
curl -X POST 'https://domain.tld/_matrix/client/r0/admin/deactivate/%40username%3Adomain.tld?access_token=token' --data '{}'
joe / view-ssh-sessions.txt Created at Tue Sep 10 13:03:41 CDT 2019
View SSH sessions
netstat -tnpa | grep 'ESTABLISHED.*sshd'
joe / Created at Thu Jun 27 12:59:23 CDT 2019
Anonymize IP Addresses in a File

HELP="Usage: ipanon [OPTION…]\n
'IP Anonymizer' removes the last two octets from IP addresses
in text files using 'sed'.

ipanon                # Start the script normally.
ipanon -f [ARG]       # Where [ARG] is a text file path. Anonymizes IP addresses in the given file.
ipanon -h             # Display this help information.
joe / logrotate-test Created at Thu Jun 27 11:05:04 CDT 2019
Test logrotate Configuration
To test what logrotate will do when running the file at "/etc/logrotate.d/nginx" you would enter the following:
logrotate -dfv /etc/logrotate.d/nginx

To test what logrotate would do NOW rather than if being forced to run you would enter the following:
logrotate -dv /etc/logrotate.d/nginx

"-d" = debug    "-f" = force    "-v" = verbose
joe / Update All Local Git Branches From Remote Created at Thu Apr 11 04:18:43 CDT 2019
I was having an issue where Atom wouldn't list all the branches in a repository I cloned. This updates every local branch from it's remote tracking branch. Credit to Wookie88 on stackoverflow
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
joe / View Hyper-V Snapshot Merge Status Created at Tue Apr 09 07:47:38 CDT 2019
Run in PowerShell
get-wmiobject -namespace “root\virtualization” -Query “select * from Msvm_ConcreteJob” | Where {$_.ElementName -eq ‘Merge in Progress’}