Skip to content

Instantly share code, notes, and snippets.

@nrutman
nrutman / git-pull-all.sh
Last active January 19, 2022 21:44
A bash script that will pull from upstream on a directory of git repositories
#!/usr/bin/env bash
# Does a git pull for every git repository in a directory and tracks the results
# Resolves a relative directory
# source: https://stackoverflow.com/questions/7126580/expand-a-possible-relative-path-in-bash
function dir_resolve()
{
cd "$1" 2>/dev/null || return $?
pwd -P
@nrutman
nrutman / git-new-branch.sh
Created May 13, 2019 14:27
Creates a new git branch, pushes it to a remote, and links it as the upstream branch
#!/usr/bin/env bash
# Creates a new branch locally and links it to the upstream in a remote (defaults to origin)
BRANCH="$1"
REMOTE="origin" # default value...can be overridden with $2
# make sure a branch name was specified
if [ "$1" == "" ]; then
echo "Error: the branch name was not specified."
@nrutman
nrutman / git-checkout-latest-x.sh
Last active January 17, 2019 18:58
Checks out the latest hotfix (.x) branch based on semver
#!/usr/bin/env bash
# Checks out the latest hotfix branch based on semver tagging
# Output function
output () {
echo -e "\033[36m\033[1m* $1 \033[0m"
return 0;
}
#!/usr/bin/env bash
# Merges the latest release into the current Git branch (based on semver
# tagging).
# Get up to date with origin
git fetch origin &> /dev/null
# Find the latest release tag
release=$(git tag --sort=v:refname | grep "^\\d\{1,2\}\.\\d\{1,2\}\.\\d\{1,4\}\$" | tail -1)
@nrutman
nrutman / git-version-tag.sh
Last active November 19, 2020 20:20
A quick bash script to display the latest release and release candidate from a git repo (based on semver tagging)
#!/usr/bin/env bash
# Parses semantic tags from Git and displays the most recent release and the
# most recent release candidate
# Get up to date with origin
git fetch origin &> /dev/null
# Find the latest release tag and the latest RC tag
release=$(git tag --sort=v:refname | grep "^\\d\{1,4\}\.\\d\{1,4\}\.\\d\{1,4\}\$" | tail -1)
@nrutman
nrutman / ios-chrome-cookie-bug.php
Created October 13, 2015 17:25
Reproduction of iOS / Chrome Duplicate Cookie Bug
@nrutman
nrutman / gmail.newMessageCount.js
Last active August 29, 2015 14:21
A Fluid userscript to show the unread message count for a Gmail SSB.
/**
* A userscript for Fluid. This script updates the dock badge for a Gmail SSB
* to the number of unread messages in the Inbox.
*
* NOTE: For best results, make sure the User Agent is set to a Safari agent.
*/
initialize();
function initialize() {
@nrutman
nrutman / inbox.newMessageCount.js
Last active August 29, 2015 14:21
A Fluid userscript to show the unread message count for a Google Inbox SSB.
/**
* A userscript for Fluid. This script updates the dock badge for a Google Inbox
* SSB to the number of unread messages in the current view. Note that the user
* must be navigated to the Inbox, and it will only count unread messages
* that are currently displayed on the screen.
*/
initialization();
function initialization() {
@nrutman
nrutman / renderTemplate.php
Created December 25, 2012 11:36
An easy templating (string / data merging) solution for PHP...for when a library is too much and the baked-in functions don't give you enough DRY. The example I needed replacement for is in the comment below.
<?php
function renderTemplate($template, $data) {
$pad_keys = create_function('$key', 'return "%" . $key . "%";');
$data_keys = array_map($pad_keys, array_keys($data));
$data_values = array_values($data);
return str_replace($data_keys, $data_values, $template);
}
/*