Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
# Usage: {script} DIRECTORY
# Find PHP's commented code and remove then.
#
# --help, -h Displays this help
#
# Report bugs to Henrique Moody <henriquemoody@gmail.com>
#
declare -r SCRIPT_NAME=$(basename ${0})
@henriquemoody
henriquemoody / recterm.sh
Created May 8, 2012 21:41
Record the terminal session and replay later
#!/bin/bash
# Uses script and scriptreplay to record and playback virtual terminal.
# Copyright (C) 2007 Hean Kuan Ong <mysurface@gmail.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@henriquemoody
henriquemoody / see-also.bash
Created December 11, 2018 12:41
Updates "See also" section for the Respect\Validation rules.
declare -A REFERENCES
while read filename; do
declare rule=$(cut -d '/' -f 2 <<< "${filename}" | cut -d '.' -f 1)
declare related_rules=$(
egrep '\[.+\]\(.+\.md\)' "${filename}" |
sed -E 's,.*\[.+\]\((.+)\.md\).*,\1,' |
egrep -v '(ComparableValues|BaseAccount|Vxdigit)'
)
for related_rule in ${related_rules}; do
<?php
// Based on https://stackoverflow.com/questions/965611/forcing-access-to-php-incomplete-class-object-properties
function convertObject($object, string $from, string $to)
{
// Serialize
$serialized = serialize($object);
// Replace the object-type
$objectReplaced = preg_replace(
@henriquemoody
henriquemoody / add-authors
Last active November 30, 2018 08:18
Example: list-authors name/of/file
#!/usr/bin/env bash
# Usage: {script} FILENAME
# Add the list of authors to a PHP or PHPT file.
# The list of authors is generated by the `git blame` command.
#
# --help, -h Displays this help
#
# Report bugs to Henrique Moody <henriquemoody@gmail.com>.
#
#!/usr/bin/env bash
set -e
DATE_FORMAT="%Y-%m-%d"
DATE_CREATION=$(date "+${DATE_FORMAT}")
DATE_REMOVAL=$(date -d "20 day ago" "+${DATE_FORMAT}")
DIRECTORY_BASE="/backup/mysql"
DIRECTORY_CREATION="${DIRECTORY_BASE}/${DATE_CREATION}"
#!/usr/bin/env bash
set -e
declare DIRECTORY=$(dirname "${BASH_SOURCE}")
declare URL="${1}"
declare ENTRY=$(echo "${1}" | cut -d '/' -f 4)
declare FILE_HTML="${DIRECTORY}/html/${ENTRY}.html"
declare FILE_TEXT="${DIRECTORY}/text/${ENTRY}.text"
@henriquemoody
henriquemoody / nl_langinfo.php
Last active December 20, 2015 06:59
nl_langinfo() constant values.
<?php
$langinfo = array(
'LC_TIME' => array(
'ABDAY_1' => 'Abbreviated name of fist day of the week',
'ABDAY_2' => 'Abbreviated name of second day of the week',
'ABDAY_3' => 'Abbreviated name of third day of the week',
'ABDAY_4' => 'Abbreviated name of fourth day of the week',
'ABDAY_5' => 'Abbreviated name of fifth day of the week',
'ABDAY_6' => 'Abbreviated name of sixth day of the week',
#!/usr/bin/env bash
MAX_LENGTH=0
DIRNAME="$(git rev-parse --show-toplevel)/.git/refs/heads"
for file_name in "${DIRNAME}"/*; do
length=$(basename "${file_name}" | wc -c | awk '{print $1}')
if [[ ${length} -gt ${MAX_LENGTH} ]]; then
MAX_LENGTH=${length}
fi
done;
@henriquemoody
henriquemoody / AbstractEnum.php
Created April 14, 2013 21:50
Abstract enumerable implementation
<?php
abstract class AbstractEnum
{
/**
* @var string
*/
private $name;