Skip to content

Instantly share code, notes, and snippets.

View jdforsythe's full-sized avatar

Jeremy Forsythe jdforsythe

View GitHub Profile
@jdforsythe
jdforsythe / get-package-json-version.sh
Created December 12, 2015 13:12
Gets the version value from a package.json file
grep -Po '"'"version"'"\s*:\s*"\K([^"]*)' package.json
@jdforsythe
jdforsythe / ExecutePowershellCmdlet.cs
Created February 16, 2016 20:28
Execute Powershell Cmdlet in C#
using System.Management.Automation;
namespace ExecutePowershellCmdlet {
class Program {
using (PowerShell pshell = PowerShell.Create()) {
DateTime yesterday = DateTime.Today.AddDays(-1);
string date_string = "\"" + yesterday.ToString("MM"_ + "/" + yesterday.ToString("dd") + "/" + yesterday.ToString("yyyy") + "\""; // "MM/dd/yyyy"
@jdforsythe
jdforsythe / find_nuget_deps.sh
Created March 23, 2016 14:24
List all VS projects with their NuGet dependencies from a top-level dev folder
#!/bin/bash
DEFAULT_VS_PROJECT_TOP_LEVEL_FOLDER="/e/dev/internal-apps"
# find all nested folders with a packages.config file (where the NuGet package references are stored)
# loop through the results
find ${1:-"${DEFAULT_VS_PROJECT_TOP_LEVEL_FOLDER}"} -name "packages.config" | while read -r filename ; do
echo
echo $(basename "$(dirname "$filename")")
cat "$filename" | grep "<package " | sed -n 's/.*id="\([^"]*\).*version="\([^"]*\).*/\1@\2/p' | sed 's/^/ |-/'
@jdforsythe
jdforsythe / find_nuget_refs.sh
Created March 23, 2016 14:47
Find all VS projects that reference a Nuget Package as a dependency from a top-level dev folder
#!/bin/bash
DEFAULT_VS_PROJECT_TOP_LEVEL_FOLDER="/e/dev/internal-apps"
echo "Finding all projects using NuGet package for ${1}"
# find all nested folders with a packages.config file (where the NuGet package references are stored)
# loop through the results
find ${2:-"${DEFAULT_VS_PROJECT_TOP_LEVEL_FOLDER}"} -name "packages.config" -exec grep -l "${1}" {} \; | while read -r filename ; do
echo $(basename "$(dirname "$filename")")
@jdforsythe
jdforsythe / create-ca.sh
Created April 11, 2016 12:42
Create Certificate Authority
#!/bin/bash
# generate root CA key
echo "Generating root CA key"
openssl genrsa -aes256 -out rootca.key 2048
# generate root CA certificate (20 years)
echo "Generating root CA certificate"
openssl req -new -x509 -key rootca.key -days 7304 -sha256
cat log.log | grep '\[2016\-05' | cut -c 23- | sort | uniq -c | sort -rn > 2016-05_error_count.log
@jdforsythe
jdforsythe / git-clean.sh
Created September 8, 2016 18:38
Git Maintenance
#!/bin/bash
echo "Cleaning git merge conflict artifacts..."
find . -name "*.bak" | while read filename; do echo "Removing: $filename" && rm -rf "$filename"; done
echo -e "\n"
echo "Counting unreachable objects in git database..."
unreachable=$(git fsck --unreachable | wc -l)
echo "There are $unreachable unreachable objects."
@jdforsythe
jdforsythe / unique_index_with_where.sql
Created November 16, 2016 21:35
PostgreSQL constraint - column A unique for rows where column B is true
-- Scenario: There should only exist one record for each distinct value for column A that has column B set to true. There can be any number of records for each distinct value for column A where column B is false.
-- i.e. there can be only one active record (column B true) for each distinct value of column A
DROP TABLE IF EXISTS test;
CREATE TABLE test (
"a" CHARACTER VARYING(3) NOT NULL,
"b" BOOLEAN NOT NULL DEFAULT TRUE
);
@jdforsythe
jdforsythe / git-commits-per-author.sh
Last active January 3, 2017 19:18
Git Repo Statistics
#!/bin/bash
if [ ! -f .mailmap ]; then
echo "WARNING: File .mailmap not found. If you get multiples of names check:"
echo "https://git-scm.com/docs/git-shortlog#_mapping_authors"
echo ""
echo "--------------------"
echo ""
fi
@jdforsythe
jdforsythe / vscode-command-editor.sh
Created May 3, 2017 14:45
Use Visual Studio Code as long command editor in Git Bash on Windows
## Bash lets you use CTRL+X CTRL+E to edit-and-execute a command
## This will allow you to set up VS Code as the editor for this (and other Bash edit functions)
echo "export VISUAL=\"code -n -w\"" >> ~/.bashrc
source ~/.bashrc
## Then when you're typing a long command and need to change something or otherwise want better
## editing control over a command, simply hit CTRL+X CTRL+E and edit the command, then save
## and exit VS Code and the command will execute
## For Sublime Text