This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# helper function | |
# | |
function exit_with_msg() { echo "Error! $1. Exiting script."; exit 1; } | |
# | |
# hi :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Flatten array | |
* | |
* Iterate over array elements. | |
* Recurse into sub arrays. | |
*/ | |
function flatten(a, f) { | |
var f = f || []; // init result array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function bisect($haystack, $needle, $trace = false) | |
{ | |
$min = 0; | |
$max = count($haystack); | |
$match = false; | |
do { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i=1 | |
for f in *.png; do | |
mv "$f" "draft_$((i++)).png" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Signature: empty(mixed $var) | |
* Description: A language construct to check if a *variable* is empty. | |
*/ | |
// The following variables are considered empty: | |
// * false |
NewerOlder