Dark Launch

This is a Dark Launch.

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;
}
}