HTTP Status Codes in PHP; http header response code function

Output your desired HTTP status code using the status code and the header() function.
PHP
 
<?php
function HTTPStatus($num) {
$http = array(
100 => 'HTTP/1.1 100 Continue',
101 => 'HTTP/1.1 101 Switching Protocols',
200 => 'HTTP/1.1 200 OK',
201 => 'HTTP/1.1 201 Created',
202 => 'HTTP/1.1 202 Accepted',
203 => 'HTTP/1.1 203 Non-Authoritative Information',
204 => 'HTTP/1.1 204 No Content',
205 => 'HTTP/1.1 205 Reset Content',
206 => 'HTTP/1.1 206 Partial Content',
300 => 'HTTP/1.1 300 Multiple Choices',
301 => 'HTTP/1.1 301 Moved Permanently',
302 => 'HTTP/1.1 302 Found',
303 => 'HTTP/1.1 303 See Other',
304 => 'HTTP/1.1 304 Not Modified',
305 => 'HTTP/1.1 305 Use Proxy',
307 => 'HTTP/1.1 307 Temporary Redirect',
400 => 'HTTP/1.1 400 Bad Request',
401 => 'HTTP/1.1 401 Unauthorized',
402 => 'HTTP/1.1 402 Payment Required',
403 => 'HTTP/1.1 403 Forbidden',
404 => 'HTTP/1.1 404 Not Found',
405 => 'HTTP/1.1 405 Method Not Allowed',
406 => 'HTTP/1.1 406 Not Acceptable',
407 => 'HTTP/1.1 407 Proxy Authentication Required',
408 => 'HTTP/1.1 408 Request Time-out',
409 => 'HTTP/1.1 409 Conflict',
410 => 'HTTP/1.1 410 Gone',
411 => 'HTTP/1.1 411 Length Required',
412 => 'HTTP/1.1 412 Precondition Failed',
413 => 'HTTP/1.1 413 Request Entity Too Large',
414 => 'HTTP/1.1 414 Request-URI Too Large',
415 => 'HTTP/1.1 415 Unsupported Media Type',
416 => 'HTTP/1.1 416 Requested Range Not Satisfiable',
417 => 'HTTP/1.1 417 Expectation Failed',
500 => 'HTTP/1.1 500 Internal Server Error',
501 => 'HTTP/1.1 501 Not Implemented',
502 => 'HTTP/1.1 502 Bad Gateway',
503 => 'HTTP/1.1 503 Service Unavailable',
504 => 'HTTP/1.1 504 Gateway Time-out',
505 => 'HTTP/1.1 505 HTTP Version Not Supported',
);
 
header($http[$num]);
 
return
array(
'code' => $num,
'error' => $http[$num],
);
}

AutoIt implode like PHP implode(); _ArrayToString()

AutoIt
 
#include <String.au3>
#include <Array.au3>
 
$array = _StringExplode("foo|bar|baz", "|");
For $i = 0 To UBound($array) - 1
ConsoleWrite("array[" & $i & "] = " & $array[$i] & @CRLF)
Next
#cs
array[0] = foo
array[1] = bar
array[2] = baz
#ce

 
ConsoleWrite(implode(",", $array) & @CRLF)
#cs
foo,bar,baz
#ce

 
Func implode($glue, $pieces)
Return _ArrayToString($pieces, $glue)
EndFunc ;==>implode

PHP Simulate a slow download of a file; curl -o /dev/null

PHP
 
// 1 megabyte
$content_length = 1000000;
 
// download binary file
header('Content-Type: application/octet-stream');
header('Content-Length: ' . $content_length);
header('Content-Disposition: attachment; filename="somefile.bin"');
 
$bytes = 1000;
$length = $content_length / $bytes;
$str = str_repeat('.', $bytes);
$micro_seconds = 20000;
 
for ($i = 0; $i < $length; $i++) {
echo $str;
 
// slow the download
usleep($micro_seconds);
}


Show the download progress including Total, Received, Xferd, Average Dload, Speed Upload, Time Total, Time Spent, Time Left, Current Speed:

Find files and execute command on those files found; find file and exec

To find files and execute a command on the files found, do the following:
Code
 
cd /path/to/directory
find ./ ! -iname "*.mp3" -type f -exec echo {} \;
 

The above command finds any non-mp3 (! -iname *.mp3) file (-type f) in the current directory (./) and prints the file found (-exec echo {}). The curly brackets are replaced with the found files. "\;" signals the end of the command to execute.

The tests may be chained to together:
Code
 
find ./ ! -iname "*.mp3" ! -iname "*.m3u" ! -iname "*.pls" -type f -exec echo {} \;
 


To remove or perform another action on the files found, change the exec action. The following will remove the files found:
Code
 
find ./ ! -iname "*.mp3" ! -iname "*.m3u" ! -iname "*.pls" -type f -exec rm {} \;
 

Logitech QuickCam Communicate STX; Skype; Ubuntu

FIRST to test that your webcam at least works, run
Code
 
gstreamer-properties
 


go to the "Video" tab.
try changing the "Plugin:" setting under "Default Input"
and clicking the Test button.

mine worked with the following settings:
Plugin: Video for Linux 2 (v4l2)
Device: Default
Pipeline: v4l2src

---

NEXT, get your webcam working with Skype
Code
 
env LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype
 


this will open up an instance of Skype.
go to Options > Video Devices.
check "Enable Skype Video".
select your webcam and click the Test button.
if you see the webcam in the box works, your webcam will now work during calls.

---

Here are some of the errors that came up:

Code
 
$ luvcview
luvcview 0.2.6
 
SDL information:
Video driver: x11
A window manager is available
Device information:
Device path: /dev/video0
ERROR opening V4L interface: No such file or directory
 


Code
 
$ luvcview
luvcview 0.2.6
 
SDL information:
Video driver: x11
A window manager is available
Device information:
Device path: /dev/video0
Stream settings:
ERROR: Requested frame format MJPG is not available and no fallback format was found.
Init v4L2 failed !! exit fatal
 


---

http://ubuntuforums.org/showthread.php?t=914952
http://cwraig.id.au/?p=122

Ubuntu Skype for Linux; direct download link

Here is the direct link to download Skype for Ubuntu:
http://www.skype.com/intl/en-us/get-skype/on-your-computer/linux/post-download/

To test if you webcam is working:
luvcview is a good program

Code
 
sudo apt-get install luvcview && luvcview
 

Delete Empty Directories using bash / command line; Find empty directory

To remove empty directories, use the following:
Code
 
find -type d -empty -delete
 

To simply find empty directories:
Code
 
find -type d -empty
 

JavaScript get input caret cursor position; getSelectionStart getSelectionEnd; char position

To get the input field character position using JavaScript, use the following:
Javascript
 
function getSelectionStart(o) {
if (o.createTextRange) {
var r = document.selection.createRange().duplicate();
r.moveEnd("character", o.value.length);
if (r.text == "") {
return o.value.length;
}
else {
return o.value.lastIndexOf(r.text);
}
}
else {
return o.selectionStart;
}
}
 
function getSelectionEnd(o) {
if (o.createTextRange) {
var r = document.selection.createRange().duplicate();
r.moveStart("character", -o.value.length);
return r.text.length;
}
else {
return o.selectionEnd;
}
}

SSH Timeout Keep Alive Option; Reconnect; ssh times out

To keep your ssh session from timing out, do the following:

Edit ssh_config
Code
 
vi /etc/ssh/ssh_config
 


Append:
Code
 
ServerAliveInterval 15
ServerAliveCountMax 3
 


Additionally, use the reconnect option:
Code
 
sshfs myuser@ftp.mysite.com:/ ~/mnt/mysite -o reconnect
 

PHP Recursively list directories and files; recursive listing scan and traversal

PHP
 
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
 
header('Content-Type: text/plain');
 
$dir = dirname(__FILE__);
 
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $item) {
if ($item->isFile() || $item->isDir()) {
echo $item . PHP_EOL;
}
}