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 / 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 :)
<?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 :)
#!/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 $?
@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
@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 / 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 {
i=1
for f in *.png; do
mv "$f" "draft_$((i++)).png"
done
@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