Skip to content

Instantly share code, notes, and snippets.

@garethflowers
garethflowers / inarray.pl
Created June 3, 2013 11:35
"inarray.pl" - checks if an array contains a `value`
sub inarray
{
my ( $value, @array ) = @_;
foreach my $arrayvalues ( @array )
{
foreach my $arrayvalue ( @$arrayvalues )
{
if ( $arrayvalue eq $value )
{
@garethflowers
garethflowers / friendly_date_diff.sql
Last active May 3, 2021 21:33
Returns a friendly human readble representation of how long ago a timestamp was.
CREATE OR REPLACE FUNCTION friendly_date_diff(
TIMESTAMP WITH TIME ZONE
)
RETURNS TEXT
LANGUAGE sql
IMMUTABLE
STRICT
AS $$
SELECT CASE
@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>
@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 / 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
CREATE OR REPLACE FUNCTION reset_sequences()
RETURNS void
LANGUAGE plpgsql
VOLATILE
AS $$
DECLARE
m_Record RECORD;
BEGIN
@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(
@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 / 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 / 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(