Skip to content

Instantly share code, notes, and snippets.

View darraghenright's full-sized avatar
🏠
Working from home

Darragh Enright darraghenright

🏠
Working from home
View GitHub Profile
@darraghenright
darraghenright / gist:1042270
Created June 23, 2011 09:52
ZCE Notes - empty()
<?php
/*
* Signature: empty(mixed $var)
* Description: A language construct to check if a *variable* is empty.
*/
// The following variables are considered empty:
// * false
i=1
for f in *.png; do
mv "$f" "draft_$((i++)).png"
done
@darraghenright
darraghenright / bisect.php
Created February 15, 2012 09:09
a simple divide-and-conquer, return-the-index-of-a-value-if-it-exists-in-an-array function :)
<?php
function bisect($haystack, $needle, $trace = false)
{
$min = 0;
$max = count($haystack);
$match = false;
do {
@darraghenright
darraghenright / generate_random_string.php
Created February 15, 2012 09:15
Simple ascii random string generator
<?php
function generateRandomString($length = 8)
{
if (0 >= $length || !is_int($length)) {
$msg = sprintf('Exception! "%s()" only accepts positive integer values of 1 or more', __FUNCTION__);
throw new UnexpectedValueException($msg);
}
$ascii = array_merge(
@darraghenright
darraghenright / array_flatten.js
Created March 24, 2012 19:04
Flatten a multidimensional array
/**
* Flatten array
*
* Iterate over array elements.
* Recurse into sub arrays.
*/
function flatten(a, f) {
var f = f || []; // init result array
#!/bin/bash
#
# First, create a test file with the three
# different line ending types LF, CR & CRLF
#
echo -en 'unix!\nclassic mac!\rdos!\r\n' > orig.txt
exit $?
<?php
// for maximum sanity
// during development
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', true);
// always remember to remove it
// it before put your code live :)
@darraghenright
darraghenright / pyrocms_perms.sh
Created December 26, 2012 19:41
A quick script to set requisite write permissions to various files and folders in a PyroCMS installation.
#!/bin/bash
#
# helper function
#
function exit_with_msg() { echo "Error! $1. Exiting script."; exit 1; }
#
# hi :)
@darraghenright
darraghenright / $PS1
Created March 4, 2013 00:53
Modified shell prompt.
export PS1="[\e[0;36m\u@osx\e[m:\e[0;33m\w\e[m]\$ "
<?php
// omitted namespace declaration and imports for brevity
class HomeController extends Controller
{
/**
* Home page
*
* @Route("/", name="home_index")