Dark Launch

This is a Dark Launch.

How refresh is different from clicking "Go"; Refresh; F5; Ctrl+F5; Ctrl+R

Code
 
cached refresh:
form:
input retains value
textarea retains value
select retains selected
img:
revalidate request sent (slower)
 
go:
form:
input value reset
textarea value reset
select selected reset
img:
HTTP_IF_MODIFIED_SINCE (faster)
 
no cache refresh:
form:
input value reset
textarea value reset
select selected reset
 

Whois panscient.com? 38.100.8.50

Their GET looks suspicious:
Code
 
HTTP_USER_AGENT: panscient.com
IP: 38.100.8.50
GET: http://darklaunch.com/.replace(/%20/g,
 

Code
 
OrgName: PSINet, Inc.
OrgID: PSI
Address: 1015 31st St NW
City: Washington
StateProv: DC
PostalCode: 20007
Country: US
 
ReferralServer: rwhois://rwhois.cogentco.com:4321/
 
NetRange: 38.0.0.0 - 38.255.255.255
CIDR: 38.0.0.0/8
NetName: PSINETA
NetHandle: NET-38-0-0-0-1
Parent:
NetType: Direct Allocation
NameServer: NS.PSI.NET
NameServer: NS2.PSI.NET
Comment: Reassignment information for this block can be found at
Comment: rwhois.cogentco.com 4321
RegDate: 1991-04-16
Updated: 2005-10-05
 
RTechHandle: PSI-NISC-ARIN
RTechName: IP Allocation
RTechPhone: +1-877-875-4311
RTechEmail: ipalloc@cogentco.com
 
OrgAbuseHandle: COGEN-ARIN
OrgAbuseName: Cogent Abuse
OrgAbusePhone: +1-877-875-4311
OrgAbuseEmail: abuse@cogentco.com
 
OrgNOCHandle: ZC108-ARIN
OrgNOCName: Cogent Communications
OrgNOCPhone: +1-877-875-4311
OrgNOCEmail: noc@cogentco.com
 
OrgTechHandle: IPALL-ARIN
OrgTechName: IP Allocation
OrgTechPhone: +1-877-875-4311
OrgTechEmail: ipalloc@cogentco.com
 

Calculate MySql Execution Time/Duration; Calculate PHP Script Execution Time/Duration

PHP
 
<?php
$stats=array();
function start(){
global $stats;
$stats['time_start']=microtime(true);
}
function stop(){
global $stats;
$stats['time_end']=microtime(true);
$stats['time_total']=$stats['time_end']-$stats['time_start'];
echo 'completed in '.$stats['time_total'].' seconds'."\n";
exit;
}
?>

PHP
 
<?php // example usage
start();
for($i=0;$i<=1000;$i++){
// ...
}
stop();
?>

Signin versus Login

Sign up
Sign in
Sign out
Join
Register
Login
Logout
I'm going with Sign (up|in|out).

CSS and Html Loading; Full screen loading; width:100%, height:100%;

XML
 
<div id="splash">
<table height="90%" width="100%">
<tbody>
<tr>
<td height="100%" align="center" width="100%" valign="middle">
<div id="splash_loading">Loading</div>
</td>
</tr>
</tbody>
</table>
</div>

CSS
 
#splash{
cursor:wait;
height:100%;
left:0;
position:absolute;
top:0;
width:100%;
}
#splash .loaded{
display:none;
}
#splash_loading{
background-image:url(loading.gif);
cursor:wait;
height:80px;
width:200px;
}

Clipboard Plaintext; Copy Plaintext to Clipboard; ClipPut(); AutoIt

Put plaintext in clipboard using Ctrl+Shift+C.
AutoIt
 
#include <GuiConstantsEx.au3>
 
; AutoIt Code: http://www.autoitscript.com/
$gui=GUICreate('',500,300,0,0)
 
; input that will receive richtext clipboard data
$input_clipboard=GuiCtrlCreateInput('my hidden input',0,0,0,0)
 
; copy plaintext to clipboard: ctrl+shift+c (normal copy to clipboard ctrl+c)
HotKeySet('^+c', 'ClipPutPlainText') ; ctrl+shift+c
 
; replaces richtext in clipboard with plaintext
Func ClipPutPlainText()
; set input value to whatever is currently in clipboard
GUICtrlSetData($input_clipboard,ClipGet())
; put plaintext data in clipboard
ClipPut(GUICtrlRead($input_clipboard))
EndFunc
 
While 1
$msg=GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

This script basically does the same thing as pasting your clipboard into notepad and then copying it back into the clipboard.
More useful hotkeys:
http://authoitkey.googlecode.com/

How can Linux be upgraded/updated without requiring reboot?

"When a file is deleted in linux, it is simply 'unlinked'. The inode, which contains the file's data, is not deleted until all processes have finished with it. This is why processes can carry on writing to deleted files."

JavaScript Random Number; quick random number; Math.random(); substring();

I wanted to avoid specifying a max and min.
Javascript
// Math.random(): produces integer -> 0.473239055961688
// toString(): from integer to string -> '0.473239055961688'
// substring(2): extract after period -> '473239055961688'
var str=Math.random().toString().substring(2);
alert(str);

This example function requires a max and min.
Javascript
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Math/random#Examples
function getRandomInt(min, max){
return Math.floor(Math.random() * (max - min + 1)) + min;
}

svn move multiple files; CMD; command line

Code
 
for %i in (*.php) do svn move "C:\wamp\www\old_dir\%i" "C:\wamp\www\new_dir"
 

Code
 
for i in *.js; do svn mv "$i" "/var/www/www.example.com/include/js/old/"; done
 

PHP wordwrap; although it may be temping

although it may sound like a good idea to use php's wordwrap() for user comments+, use css to control long strings
PHP
 
<?php
// from database, already santized
$comment=<<<EOF
this is a realllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllyyyyyyyyyyyyyyyyyyyyyyyy long comment that will break the layout..........................................................................................................................................................................................
EOF
;
echo
'<div class="comment">'.
$comment.
'</div>'.
'';
?>

CSS
 
.comment{
overflow-x:auto;
}

jQuery file selector works in 1.2.6

$('#myform :file[value!='']') works in 1.2.6; not in 1.3.x
Selector is looking for inputs of type file with value not empty.
Test case where "uncaught exception: Syntax error, unrecognized expression: value!='']":
XML
 
<div id="myform">
<form action="test-selector.php" enctype="multipart/form-data" method="post">
<div>
<input type="file" name="file" />
 
<input type="file" name="file" />
 
<input type="file" name="file" />
 
<input type="button" value="Send" onclick="submit_form();" />
</div>
</form>
</div>
<!--
<script type="text/javascript" src="js/jquery-1.2.6.js"></script>
-->
<script type="text/javascript" src="js/jquery-1.3.1.js"></script>

Javascript
 
function submit_form(){
var files=$('#myform :file[value!=\'\']');
if(files.length>0){
files.each(
function(i){
console.log(this);
}
)
}
else{
alert('Select some files please');
}
}
 

Why doesn't value expression work in the current release?
RE: http://dev.jquery.com/ticket/4083
---
UPDATE: $('#myform :file[value!=\'\']') selector works with the release of jQuery 1.3.2

MySql Insert

PHP
 
$query=sprintf('
INSERT INTO `mytable`(
`foo`,
`bar`
)
VALUES(
'
%s',
'
%s'
)
'

,mysql_real_escape_string($foo) // already sanitized
,mysql_real_escape_string($bar) // already sanitized
);

PHP
 
$query=sprintf('
INSERT INTO `mytable`(
`foo`,
`bar`
)
VALUES(
'
%s',
'
%s'
)
'

,mysql_real_escape_string(stripslashes(htmlspecialchars($foo,ENT_QUOTES,'UTF-8'))) // insert sanitized
,mysql_real_escape_string(stripslashes(htmlspecialchars($bar,ENT_QUOTES,'UTF-8'))) // insert sanitized
);

PHP Determine Line Breaks

PHP
 
// line endings are replaced with literal characters
$s = str_replace("\t", '\t', $s);
$s = str_replace("\r\n", '\r\n', $s);
$s = str_replace("\n", '\n', $s);
$s = str_replace("\r", '\r', $s);
echo $s . '<br /><br />';
 
// combined
$s = str_replace(array("\r\n", "\r", "\n", "\t"), array('\r\n', '\r', '\n', '\t'), $s);
echo $s . '<br /><br />';

Javascript Iframe Killer

Javascript
 
// iframe killer
while((el=document.getElementsByTagName('iframe')).length){el[0].parentNode.removeChild(el[0]);}

Awesome Javascript Debugger

Javascript
 
function dump(arr,level){var dumped_text="";if(!level)level=0;var level_padding="";for(var j=0;j<level+1;j++)level_padding+=" ";if(typeof(arr)=='object'){for(var item in arr){var value=arr[item];if(typeof(value)=='object'){dumped_text+=level_padding+"'"+item+"' ...\n";dumped_text+=dump(value,level+1)}else{dumped_text+=level_padding+"'"+item+"' => ""+value+""\n"}}}else{dumped_text="===>"+arr+"<===("+typeof(arr)+")"}return dumped_text}
function dbg(msg){
var debugbox=document.getElementById('dbg');
if(!debugbox){
debugbox=document.createElement('div');
debugbox.setAttribute('id','dbg');
debugbox.setAttribute('style',
'font-family:monospace;'+
'font-size:90%;'+
'border:solid black 3px;'+
'padding:8px;'+
'margin:10px 0;'
);
document.body.appendChild(debugbox);
debugbox.innerHTML='<h1 style="text-align:center;font-size:90%;">Debugging Output</h1>';
}
var div=document.createElement('div');
if('object'==typeof(msg)){
msg=dump(msg);
}
div.appendChild(document.createTextNode(msg));
debugbox.appendChild(div);
}

don't, just don't

don't use short open tags: <? ?>; always use the long form of the PHP open tag (<?php ?>)

don't use print; use echo

PHP
<?
// bad
print $var;
?>
 
<?php
// good
echo $var;
?>

Limit Google Search To A Domain; Code

You can limit a Google search to a specific domain using the following code. Change the value of the hidden input to the site of your choice.
XML
 
<form action="http://www.google.com/search">
<div>
<input name="sitesearch" type="hidden" value="darklaunch.com" />
<input name="q" type="text" value="" />
<input type="submit" value="Search" />
</div>
</form>

Form is implied GET without method="get".
The <input name="sitesearch" type="hidden" value="darklaunch.com" /> targets only the specified domain.

Example PHP Page; PHP Syntax Highlighting Page

PHP
 
<?php // Example
/**
* Define MyClass
*/

class MyClass{
// Declare a public constructor
public function __construct() { }
 
// Declare a public method
public function MyPublic() { }
 
// Declare a protected method
protected function MyProtected() { }
 
// Declare a private method
private function MyPrivate() { }
 
// This is public
function Foo(){
$this->MyPublic();
$this->MyProtected();
$this->MyPrivate();
}
}
$myclass=new MyClass;
$myclass->MyPublic(); // Works
$myclass->MyProtected(); // Fatal Error
$myclass->MyPrivate(); // Fatal Error
$myclass->Foo(); // Public, Protected and Private work
 
// Valid constant names
define("TITLE","Example");
define("TITLE","Exa $this_is_a_variable mple");
 
// Page header
include 'header.inc';
 
echo ''.
'<div>'.
'<form action="/">'.
'<div>'.
'<label for="q">'.
'Search the internets'.
(!empty($_COOKIE['name'])?
' '.htmlspecialchars($_COOKIE['name']):
''
).
'<input id="q" name="q" type="text" value="" />'.
'</label>'.
'<input type="submit" value="Go" />'.
'</div>'.
'</form>'.
'</div>'.
'';
 
// Javascript
include 'javascript.inc';
 
/**
* Lazy load function to prevent regex from being stuffed in
* cache.
*/

protected function _loadRegex() {
$oct = '(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])'; // 0-255
$this->ip4 = "(?:{$oct}\\.{$oct}\\.{$oct}\\.{$oct})"; // PHP complex variable
}
?>

<?php // Example
/**
* Define MyClass
*/
class MyClass{
// Declare a public constructor
public function __construct() { }
// Declare a public method
public function MyPublic() { }
// Declare a protected method
protected function MyProtected() { }
// Declare a private method
private function MyPrivate() { }
// This is public
function Foo(){
$this->MyPublic();
$this->MyProtected();
$this->MyPrivate();
}
}
$myclass=new MyClass;
$myclass->MyPublic(); // Works
$myclass->MyProtected(); // Fatal Error
$myclass->MyPrivate(); // Fatal Error
$myclass->Foo(); // Public, Protected and Private work

// Valid constant names
define("TITLE","Example");
define("TITLE","Exa $this_is_a_variable mple");

// Page header
include 'header.inc';

echo ''.
'
'.
''.
'
'.
''.
'Search the internets'.
(!empty($_COOKIE['name'])?
' '.htmlspecialchars($_COOKIE['name']):
''
).
''.
''.
''.
'
'.
''.
'
'.
'';

// Javascript
include 'javascript.inc';

/**
* Lazy load function to prevent regex from being stuffed in
* cache.
*/
protected function _loadRegex() {
$oct = '(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])'; // 0-255
$this->ip4 = "(?:{$oct}\\.{$oct}\\.{$oct}\\.{$oct})"; // PHP complex variable
}
?>

Cross-site request forgery (CSRF/XSRF)

CSRF ("sea-surf").
Example:
XML
 
/* from http://malicious-site.com/index.php */
<html>
<body>
<img alt="you have just been signed out" src="http://example.com/signout" />
</body>
</html>

What's going on?
You just requested an image and it signed you out of example.com.
How does it work?
You visit a malicious site that has the tag. Technically you are requesting the sign out page and provide the proper authentication (that is, without crossing domains). Because you requested the page, you have been signed out.
More
The tag is one example. A form and data can be submitted. An iframe can be requested ().

Javascript Insert Tabs into Textarea; Insert Tabs Into Input; Javascript Tab Indent

How to insert tabs and auto-indent using jQuery.
XML
 
<textarea cols="50" id="mytextarea" rows="15"></textarea>

Case 13 is the indenting.
Javascript
 
$(document).ready(function(){
$('#mytextarea').keydown(
function(e){
if(this.setSelectionRange){
var start=this.selectionStart,val=$(this).val();
switch(e.keyCode){
case 9: /* tab */
$(this).val(val.substring(0,start)+'t'+val.substr(this.selectionEnd));
this.setSelectionRange(start+2,start+2);
this.focus();
e.preventDefault();
return false;
break;
case 13: /* enter */
var match=val.substring(0,start).match(/(^|n)([ t]*)([^n]*)$/);
if(match){
var spaces=match[2],length=spaces.length+1;
$(this).val(val.substring(0,start)+'n'+spaces+val.substr(this.selectionEnd));
this.setSelectionRange(start+length,start+length);
this.focus();
return false;
}
break;
}
return true;
}
}
);
});

Javascript Tab Inserts Tab / How To Insert An Actual Tab in an Input or Textarea

The textarea or input. This is inline via onkeydown.
XML
 
<textarea cols="50" onkeydown="return interceptTabs(event,this);" rows="15"></textarea>

The javascript
Javascript
 
function interceptTabs(evt,control){
key=evt.keyCode?evt.keyCode:evt.which?evt.which:evt.charCode;
if(key==9){
insertAtCursor(control,'t');
return false;
}
else{
return key;
}
}
function insertAtCursor(myField, myValue){
if(document.selection){
/* ie */
myField.focus();
sel=document.selection.createRange();
sel.text=myValue;
}
else if(myField.selectionStart||myField.selectionStart=='0'){
/* mozilla support */
var startPos=myField.selectionStart;
var endPos=myField.selectionEnd;
restoreTop=myField.scrollTop;
myField.value=myField.value.substring(0,startPos)+myValue+myField.value.substring(endPos,myField.value.length);
myField.selectionStart=startPos+myValue.length;
myField.selectionEnd=startPos+myValue.length;
if(restoreTop>0){
myField.scrollTop=restoreTop;
}
}
else{
myField.value+=myValue;
}
}

EDIT: see the jQuery version of this http://darklaunch.com/2009/02/03/javascript-insert-tabs-into-textarea-insert-tabs-into-input-javascript-tab-indent

Denote important things

PHP
 
header('location: http://example.org');
exit; // !important
 
// OR SIMPLY
 
header('location: http://example.org');
exit; // !

Javascript
 
/* snippet... */
switch(e.keyCode){
case 13:
/* code for ENTER */
break; /* !important */
case 27:
/* code for ESC */
break; /* ! */
}
return true;

Javascript KeyCode; Common Javascript KeyCodes; Backspace (8), Tab (9), Enter (13), Escape (27)

Javascript
 
var keyCodes = {
BACKSPACE: 8,
TAB: 9,
ENTER: 13,
ESC: 27,
SPACE: 32,
PAGE_UP: 33,
PAGE_DOWN: 34,
LEFT: 37,
UP: 38,
RIGHT: 39,
DOWN: 40,
DEL: 46
};

Example:
Javascript
 
$("#search-input").keydown(function(event) {
switch (event.keyCode) {
case keyCodes.ENTER:
event.preventDefault();
var query = $("#search-input").val();
ajaxSearch(query);
break;
default:
break;
}
});

Javascript should be used as an enhancement

except for a few cases, javascript should be used to enhance a site
develop the site with javascript disabled so it works THEN add the javascript to include:
focus onload
add/remove css on hover
ajax
the exceptions include chat like meebo (meebo.com)

hello

hello and welcome.

Facebook Engineer Eugene Letuchy tells us:

“The secret for going from zero to seventy million users overnight is to avoid doing it all in one fell swoop. We chose to simulate the impact of many real users hitting many machines by means of a "dark launch" period in which Facebook pages would make connections to the chat servers, query for presence information and simulate message sends without a single UI element drawn on the page. With the "dark launch" bugs fixed, we hope that you enjoy Facebook Chat now that the UI lights have been turned on.”

Dark Launch is fitting.

I hope to share here what I've gathered from many hours searching the net.