Skip to content

Instantly share code, notes, and snippets.

@garethflowers
garethflowers / git-fix-history.sh
Created May 3, 2021 21:50
Rewrite incorrect email addresses in git history.
git filter-branch --env-filter '
WRONG_EMAIL="[email protected]"
NEW_NAME="FooBar"
[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_NAME"
export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
@garethflowers
garethflowers / windows-context-entries
Created January 20, 2015 09:58
Generates entires in the Windows Explorer context menu.
Windows Registry Editor Version 5.00
; Ensure all ICON_LOCATION and EXECUTABLE_LOCATION paths are escaped
[HKEY_CLASSES_ROOT\*\shell\Sublime]
""="Open APPNAME"
"Icon"="ICON_LOCATION"
[HKEY_CLASSES_ROOT\*\shell\Sublime\command]
""="EXECUTABLE_LOCATION \"%1\""
@garethflowers
garethflowers / array_sort.sql
Last active May 3, 2021 21:41
Returns a sorted array.
CREATE OR REPLACE FUNCTION array_sort(
text[]
)
RETURNS text[]
LANGUAGE sql
IMMUTABLE
STRICT
AS $$
SELECT ARRAY(
@garethflowers
garethflowers / str_endswith.php
Last active May 3, 2021 21:34
Finds whether a string ends with another string.
/**
* Finds whether a string ends with another string
*
* @param string $haystack
* @param string $needle
* @return boolean
*/
function str_endswith($haystack, $needle) {
$strlen = strlen($haystack);
$testlen = strlen($needle);
@garethflowers
garethflowers / get_called_class.php
Last active April 19, 2023 21:55
Polyfill. Gets the name of the class the static method is called in.
if (!function_exists('get_called_class')) {
/**
* Gets the name of the class the static method is called in.
*
* @return string
*/
function get_called_class() {
$arr = array();
$arrTraces = debug_backtrace();
@garethflowers
garethflowers / array_filter_blanks.sql
Last active May 3, 2021 21:48
Returns an array with no NULL or '' (emtpy string) values
CREATE OR REPLACE FUNCTION array_filter_blanks(
ANYARRAY
)
RETURNS ANYARRAY
LANGUAGE sql
IMMUTABLE
STRICT
AS $$
SELECT ARRAY(
CREATE OR REPLACE FUNCTION reset_sequences()
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS $$
DECLARE
m_Record RECORD;
BEGIN
@garethflowers
garethflowers / replace-notepad.cmd
Created May 24, 2014 20:51
Notepad Replacement Utility. A registry (reversible) method of changing the build the default Notepad application.
rem Specify the location of the new Notepad application here
set NOTEPAD_APP=%~dp0notepad.exe
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" /v "Debugger" /t REG_SZ /d "\"%NOTEPAD_APP%\" -z" /f
@garethflowers
garethflowers / watch.sh
Created April 22, 2014 19:19
Watch Script. A drop in replacement for systems which don't have the 'watch' command.
#!/usr/bin/env bash
# usage: watch [command] [sleep duration]
while :; do
clear
date
bash -c "$1"
sleep ${2:-1}
done
@garethflowers
garethflowers / skiplicence.xml
Created July 11, 2013 13:39
Wix: code to skip the licence prompt
<?xml version="1.0" encoding="utf-8"?>
<Wix>
<Product>
<!-- skip licence dialog -->
<UI>
<Publish Dialog="WelcomeDlg"
Control="Next"
Event="NewDialog"
Value="InstallDirDlg"
Order="2">1</Publish>