Dark Launch

This is a Dark Launch.

PHP Plural; Pluralize Words in PHP; Plural Word, plural()

PHP
 
function plural($count, $singular, $plural = 's') {
if ($plural == 's') {
$plural = $singular . $plural;
}
return ($count == 1 ? $singular : $plural);
}

Example:
PHP
 
header('Content-Type: text/plain');
 
$amount = 5;
echo 'And then I found ' . $amount . ' ' . plural($amount, 'dollar') . "\n";
 
$count = rand(1, 2);
echo 'Roll the ' . plural($count, 'die', 'dice') . "\n";

Output:
Code
 
And then I found 5 dollars
Roll the die
 

Pluralize Words in AutoIt; Plural Word

AutoIt
 
Func plural($count, $singular, $plural = "s")
If $plural == "s" Then
$plural = $singular & $plural
EndIf
Return _Iif($count == 1, $singular, $plural)
EndFunc

Parse Twitter created_at value into friendly time format; relative time; time ago

Javascript
 
// from http://widgets.twimg.com/j/1/widget.js
var K = function () {
var a = navigator.userAgent;
return {
ie: a.match(/MSIE\s([^;]*)/)
}
}();
 
var H = function (a) {
var b = new Date();
var c = new Date(a);
if (K.ie) {
c = Date.parse(a.replace(/( \+)/, ' UTC$1'))
}
var d = b - c;
var e = 1000,
minute = e * 60,
hour = minute * 60,
day = hour * 24,
week = day * 7;
if (isNaN(d) || d < 0) {
return ""
}
if (d < e * 7) {
return "right now"
}
if (d < minute) {
return Math.floor(d / e) + " seconds ago"
}
if (d < minute * 2) {
return "about 1 minute ago"
}
if (d < hour) {
return Math.floor(d / minute) + " minutes ago"
}
if (d < hour * 2) {
return "about 1 hour ago"
}
if (d < day) {
return Math.floor(d / hour) + " hours ago"
}
if (d > day && d < day * 2) {
return "yesterday"
}
if (d < day * 365) {
return Math.floor(d / day) + " days ago"
} else {
return "over a year ago"
}
};
 
console.log(H("Wed, 08 Apr 2009 19:22:10 +0000"));
console.log(H("Thu, 20 May 2010 19:22:10 +0000"));

JavaScript on a Valid XHTML page using CDATA

Best option:
Javascript
 
<script type="text/javascript">
/* <![CDATA[ */
var someScriptHere;
/* ]]> */
</script>

Can be written on one line:
Javascript
 
<script type="text/javascript">/* <![CDATA[ */var someScriptHere;/* ]]> */</script>

Further Testing:
PHP
 
<?php
$javascript =
'var foo = 1, bar = 2;' .
'foo && bar;' .
'alert("horray!");' .
'';
 
// character "&" is the first character of a delimiter but occurred as data
// unescaped ampersand error
// xmlParseEntityRef: no name
// multiple lines
// alert works
$script_1A =
'<script type="text/javascript">' . "\n" .
$javascript . "\n" .
'</script>' . "\n" .
'';
 
// character "&" is the first character of a delimiter but occurred as data
// unescaped ampersand error
// xmlParseEntityRef: no name
// one line
// alert works
$script_1B =
'<script type="text/javascript">' .
$javascript .
'</script>' .
'';
 
// Valid XHTML 1.0 Strict
// multiple lines
// alert works
$script_2A =
'<script type="text/javascript">' . "\n" .
'//<![CDATA[' . "\n" .
$javascript . "\n" .
'//]]>' . "\n" .
'</script>' . "\n" .
'';
 
// Valid XHTML 1.0 Strict
// one line
// alert does not work (commented out)
$script_2B =
'<script type="text/javascript">' .
'//<![CDATA[' .
$javascript .
'//]]>' .
'</script>' .
'';
 
// Valid XHTML 1.0 Strict
// multiple lines
// alert works
$script_3A =
'<script type="text/javascript">' . "\n" .
'/* <![CDATA[ */' . "\n" .
$javascript . "\n" .
'/* ]]> */' . "\n" .
'</script>' . "\n" .
'';
 
// BEST OPTION
// Valid XHTML 1.0 Strict
// alert works
// one line
$script_3B =
'<script type="text/javascript">' .
'/* <![CDATA[ */' .
$javascript .
'/* ]]> */' .
'</script>' .
'';
 
echo
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' .
'<html xmlns="http://www.w3.org/1999/xhtml">' .
'<head>' .
'<meta http-equiv="content-type" content="text/html; charset=UTF-8" />' .
'<title>page title</title>' .
'</head>' .
'<body>' .
/*
$script_1A .
$script_1B .
$script_2A .
$script_2B .
$script_3A .
*/

$script_3B .
/*
*/

'</body>' .
'</html>' .
'';

NOTE: HTML5 doesn't need CDATA tags to validate. The following successfully validates:
PHP
 
echo
'<!doctype html>' .
'<html>' .
'<head>' .
'<meta http-equiv="content-type" content="text/html; charset=UTF-8" />' .
'<title>page title</title>' .
'</head>' .
'<body>' .
$script_1A .
$script_1B .
$script_2A .
$script_2B .
$script_3A .
$script_3B .
'</body>' .
'</html>' .
'';

Sync Two Directories in Ubuntu using rsync

To sync two directories, use rsync with the following command:
Code
 
rsync --recursive --verbose --delete --progress /from/this/source/ /to/this/destination/
 

To view the resulting changes without applying them, add the --dry-run option.
Code
 
rsync --recursive --verbose --delete --progress --dry-run /from/this/source/ /to/this/destination/
 

Enable Directory Listings/Contents using .htaccess

To show or display directory listings, create a .htaccess with the following:
Code
 
Options +Indexes
 

To disable directory listings, use the following:
Code
 
Options -Indexes