Skip to content

Instantly share code, notes, and snippets.

View rsperl's full-sized avatar

Richard rsperl

  • North Carolina, United States
View GitHub Profile
@rsperl
rsperl / autoload.pl
Last active July 25, 2022 14:04
handle non-existent methods or create methods on the fly with AUTOLOAD #snippet
use Data::Dumper;
sub AUTOLOAD {
my ($self) = @_;
our $AUTOLOAD; # so "use strict" is happy
# Get the last part of what was called
# (i.e., This::That::my_var, $1 set to "my_var")
print("AUTOLOAD: AUTOLOAD=$AUTOLOAD\n");
print("AUTOLOAD: \@_='" . Dumper(\@_) . "\n");
@rsperl
rsperl / rocketchatctl.sh
Last active July 25, 2022 14:12
make rocketchat stay running with a plist and launchctl #nosnippet
#!/bin/bash
# adapted from http://hints.macworld.com/article.php?story=20110617204111325
set -e
label="chat.rocket"
plistfile="$HOME/Library/LaunchAgents/$label.plist"
function setup_rocketchat() {
@rsperl
rsperl / named_capture_groups.py
Last active July 25, 2022 14:11
use named capture groups to create a dict of pattern matches in python #snippet
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
ingredient = "Kumquat: 2 cups"
# Name groups with ?P<name_of_group> syntax
pattern_text = r'(?P<ingredient>\w+):\s+(?P<amount>\d+)\s+(?P<unit>\w+)'
# compile for performance if using repeatedly
@rsperl
rsperl / venv_wrapper.sh
Last active July 25, 2022 14:26
Run a python script in a virtual environment from a shell script #snippet
#!/bin/bash
# Wrapper script for running python applications in a virtualenv
# Defaults to the awx user ansible venv used by tower
# To override, set the full path to the virtual env up to the bin dir
#
# usage: venv_wrapper.sh pythonscript.py scriptarg1 scriptarg2 ...
#
@rsperl
rsperl / grepalias.sh
Last active July 25, 2022 13:10
grep your startup options in zsh, bash to find aliases or other startup options #snippet
# How it works
# Starts zsh with an interactive (-i) login (-l) shell with XTRACE enabled (-x) and running
# a noop command (:) that returns an exit value of 0.
#
# Stderr is set to stdout so that the XTRACE output can be grepped for the given alias which
# have the form
#
# +/path/to/file:LN> alias 'youralias=your command'
#
@rsperl
rsperl / get_next_version.sh
Last active July 25, 2022 14:12
get the next version release from git tag #nosnippet
#!/bin/bash
env="test"
increment="count"
lastversion=""
debug="0"
function echo_out() {
local msg="$1"
if [[ "$debug" == "1" ]]; then
@rsperl
rsperl / jenkins_functions.sh
Last active July 25, 2022 14:13
manage jenkins jobs from a bash script using jenkins-cli.jar #nosnippet
#!/bin/bash
#
# Usage:
# $ source itdjenkins_functions.sh
# $ itdjenkins_help
#
default_jenkins_url="http://itdjml01.unx.sas.com:8080"
url=${JENKINS_URL:-$default_jenkins_url}
@rsperl
rsperl / use_tar_over_ssh_to_copy.sh
Last active July 25, 2022 14:23
use tar to copy files over ssh #snippet
#!/bin/sh
# copy from local to remote
tar zvcf - whatever/ | ssh user@host 'cat > whatever.tar.gz'
# copy from remote to local
ssh user@host 'tar cz folder/to/copy | tar -xvz
@rsperl
rsperl / .gitconfig
Last active July 25, 2022 14:10
alias to delete a git tag remotely #snippet
[alias]
rmtag= !sh -c 'git tag -d $1 && git push origin :refs/tags/$1' -
# git rmtag myTagName
@rsperl
rsperl / cheatsheet.awk
Last active July 25, 2022 13:58
awk cheatsheet #snippet
# src: https://likegeeks.com/awk-command/
# preprocessing section
BEGIN {
# Special variables
# RS - record separator (default=\n)
# FS - field separator (default=space or tab)
# OFS - output field separator (default=space)
# ORS - output record separator (default=\n)
# FIELDWIDTHS -