Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Serodio dserodio

View GitHub Profile
View fabric_ssh_agent.py
def _shell_escape(string):
""" Escape double quotes, backticks and
dollar signs in given ``string``.
For example:
>>> _shell_escape('abc$') 'abc\\\\$'
>>> _shell_escape('"') '\\\\"'
"""
for char in ('"', '$', '`'):
View lockable_script_boilerplate.sh
#!/bin/bash
## Copyright (C) 2009 Przemyslaw Pawelczyk <przemoc@gmail.com>
## License: GNU General Public License v2, v3
#
# Lockable script boilerplate
### HEADER ###
LOCKFILE="/var/lock/`basename $0`"
@dserodio
dserodio / ssh_keys_match.sh
Created Jun 18, 2015
Test if a RSA keypair matches
View ssh_keys_match.sh
# http://serverfault.com/a/426429/55687
PRIVKEY=id_rsa
TESTKEY=id_rsa.pub
diff <( ssh-keygen -y -e -f "$PRIVKEY" ) <( ssh-keygen -y -e -f "$TESTKEY" )
@dserodio
dserodio / wget.ps1
Created Jun 26, 2015
Download a remote URL using Powershell
View wget.ps1
param(
[String] $remoteUrl,
[String] $localPath
)
$webClient = new-object System.Net.WebClient;
$webClient.DownloadFile($remoteUrl, $localPath);
@dserodio
dserodio / hook_stdout_stderr
Last active Dec 4, 2015
Hook into stdout and stderr of a running process
View hook_stdout_stderr
sudo strace -p $PID -e trace=write -e write=1,2
# To log started and elapsed times, add -ttT
@dserodio
dserodio / delete-all-slack-images.py
Last active Mar 28, 2018
Delete all images in Slack that were uploaded until yesterday
View delete-all-slack-images.py
#!/usr/bin/env python
"""Delete all images in Slack that were uploaded until yesterday"""
import requests
import datetime
import sys
TOKEN = 'Put your Slack auth token here'
SLACK_API = 'https://slack.com/api'
@dserodio
dserodio / route_add.sh
Last active May 22, 2017
Fix Docker Machine routes after connecting to VPN
View route_add.sh
sudo route -n add 192.168.99 -interface vboxnet0
@dserodio
dserodio / find_broken_jars.sh
Created Mar 2, 2016
Find HTML files named *.jar (to find broken JARs downloaded from codehaus.org)
View find_broken_jars.sh
find ~/.m2/repository -name '*.jar' -exec sh -c "file {} | grep -q HTML && echo {}" \; | tee ~/broken-jars.txt
@dserodio
dserodio / scrap.sh
Last active Nov 29, 2018
ps(1) tips and tricks
View scrap.sh
# show process start time for a give PID (GNU ps)
ps -o lstart= -p $PID
# show process start time for all processes (GNU ps)
ps ax -O lstart
# show process environment variables (BSD grep)
ps -Eww -p $PID
@dserodio
dserodio / test_trap.sh
Created Apr 22, 2016
Bash script which traps some signals and prints the name of the received signal
View test_trap.sh
#!/bin/bash
#
# http://stackoverflow.com/a/9256709/31493
trap_with_arg() {
func="$1" ; shift
for sig ; do
trap "$func $sig" "$sig"
done
}