Dark Launch

This is a Dark Launch.

Internet Explorer Returns Incorrect JavaScript Object Length

Internet Explorer will incorrectly give an object length off by one if the object contains a trailing comma. In the example below, the alerts return 5 and 6, respectively.
HTML
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
alert(
[
'a',
'b',
'c',
'd',
'e'
].length
);
alert(
[
'a',
'b',
'c',
'd',
'e',
].length
);
</script>
</body>
</html>

Firefox Move Tab First, Last

To send the current tab to the beginning or end of the list of currently open tabs, add the following hotkey shortcuts to Keyconfig:
Add "Move Tab First" using keyboard shortcut Alt+Home. This will move the focused tab to the first position in the list.
Javascript
gBrowser.moveTabTo(gBrowser.mCurrentTab, 0);

Add "Move Tab Last" using keyboard shortcut Alt+End. This will move the focused tab to the last position in the list.
Javascript
gBrowser.moveTabTo(gBrowser.mCurrentTab, gBrowser.mTabContainer.childNodes.length - 1);

NOTE: Alt+Home is already used by "Home" so i disabled that default shortcut and I am using the Firefox add-on New Tab Homepage. http://www.google.com/search?btnI&q=New+Tab+Homepage
NOTE: This is in addition to my previous post
http://darklaunch.com/2009/09/30/firefox-move-tab-left-and-move-tab-right-with-wrapping-without-requiring-focus

Gmail Fixed Width Font; Fixed width fonts in Gmail; Monospace

To force messages to use a fixed width font, create or edit your Firefox userContent.css file.
Code
/home/YOURUSER/.mozilla/firefox/YOURPROFILE/chrome/userContent.css
 

For Windows:
Code
C:\Documents and Settings\YOURUSER\Application Data\Mozilla\Firefox\Profiles\YOURPROFILE\chrome\userContent.css
 

Add the following
CSS
@-moz-document domain(google.com) {
.ii, /* message body */
.Ak /* textarea when composing */
{
font-family:monospace !important;
font-size:100% !important;
}
}

Restart Firefox and now messages viewed in Gmail will be displayed with a proportional font properly aligned.

Close Terminal After Script Completes / Command Exits

To close Terminal after a script completes you will need to change it in the profile preference.
Open Terminal.
Right-click in the window and select Profile > Profile Preferences.
Open the Title and Command tab.
For "When command exists:" select "Exit the terminal".
NOTE:
myscript.py required user input. So I added a Keyboard Shortcut with the "Command" of:
Code
 
gnome-terminal --command=/path/to/myscript.py
 

The shortcut opens a terminal window for the input. The scripts then runs and the Terminal window closes after the script completes.

Clear Private Data In Firefox WITHOUT the "Clear Recent History" Dialog Window; Clear Recent History

UPDATE: Sanitisminau will clear your history WITHOUT asking.
https://addons.mozilla.org/en-US/firefox/addon/5364/
UPDATE 2: Clear private data with alert notification (and without asking):
1. Save the addon using the link above (right click and "Save Link As").
2. Open addon-5364-latest.xpi in an archive manager (like File Roller).
3. Edit addon-5364-latest.xpi/chrome/sanitisminau.jar/content/sanitisminau.js
4. Replace the code with:
Javascript
 
var Sanitisminau = {
onLoad: function() {
document.getElementById("Tools:Sanitize").setAttribute("oncommand", "Sanitisminau.goansanitismi();");
document.getElementById("sanitizeItem").setAttribute("hidden", true);
},
 
goansanitismi: function() {
var alertService = Components.classes["@mozilla.org/alerts-service;1"].getService(Components.interfaces.nsIAlertsService);
var s = new Sanitizer();
s.range = Sanitizer.getClearRange();
s.ignoreTimespan = false;
s.prefDomain = "privacy.cpd.";
try {
s.sanitize();
alertService.showAlertNotification(null, "Success", "Private Data Cleared!", false, "", null);
}
catch (er) {
alertService.showAlertNotification(null, "ERROR", er, false, "", null);
}
}
};
 
window.addEventListener("load", function(e) { Sanitisminau.onLoad(e); }, false);

5. Install the addon you updated. Type something like file:///home/user/Downloads/addon-5364-latest.xpi (or wherever you saved the addon) into the Firefox url bar and a software installation confirmation will appear. Click "Install Now" after the count down. Restart Firefox.
---
To clear private data in Firefox without the confirmation window, do the following:
1. Install Keyconfig.
2. Add a new key named Clear Private Data.
3. Add the following code:
Javascript
 
function evalScript(script, callback){
try {
eval.call(window, script);
callback();
}
catch (er){
alertService.showAlertNotification(null, "ERROR", er, false, "", null);
}
}
 
function getScript(scriptName, callback){
var gXMLHttpRequest;
gXMLHttpRequest = new XMLHttpRequest();
gXMLHttpRequest.onload =
function(e){
evalScript(gXMLHttpRequest.responseText, callback);
};
gXMLHttpRequest.open("GET", "chrome://browser/content/" + scriptName);
gXMLHttpRequest.send(null);
}
 
var alertService = Components.classes["@mozilla.org/alerts-service;1"].getService(Components.interfaces.nsIAlertsService);
getScript("sanitize.js",
function(){
try{
var s = new Sanitizer();
s.prefDomain = "privacy.cpd.";
s.sanitize();
alertService.showAlertNotification(null, "Success", "Private Data Cleared!", false, "", null);
}
catch(er){
alertService.showAlertNotification(null, "ERROR", er, false, "", null);
}
}
);

4. Set your preferred hotkey. Something like Alt+Ctrl+Shift+Del.
5. Open a new window for the new hotkey to work. Press the hotkey you set and a notification in the corner will appear.

Clear Firefox Cache Hotkey/Shortcut using Keyconfig

UPDATE: https://addons.mozilla.org/en-US/firefox/addon/5364/
---
To clear Firefox's cache using a simple hotkey, do the following:
1. Install Keyconfig.
2. Add a new key named Clear Cache.
3. Add the following code:
Javascript
 
var cacheService = Components.classes["@mozilla.org/network/cache-service;1"].getService(Components.interfaces.nsICacheService);
var alertsService = Components.classes["@mozilla.org/alerts-service;1"].getService(Components.interfaces.nsIAlertsService);
try{
cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
alertsService.showAlertNotification(null, "Success", "Cache cleared!", false, "", null);
}
catch(exception){
alertsService.showAlertNotification(null, "Exception", exception, false, "", null);
}

4. Set your preferred hotkey.
5. Open a new window for the hotkey to work. Press the hotkey you set and a notification in the corner will appear.
NOTE:
Go to about:cache in Firefox to see cache usage before and after clearing cache.
NOTE:
Other Storage Policy:
STORE_ANYWHERE - cache stored in any device
STORE_IN_MEMORY - cache entry in non-persistent storage (RAM)
STORE_ON_DISK - cache entry in persistent storage (HDD)
STORE_ON_DISK_AS_DISK - cache entry in persistent storage in a specific file

Automation server can't create object; jQuery

"Automation server can't create object" fixed:
Run your script with jquery-1.3.2.js (not compressed version) and the error is occurring on line 3382.
Lines 3381, 3382, 3383:
Javascript
xhr:function(){
return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
},

Replace the xhr function with:
Javascript
xhr:function(){
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
else if (window.ActiveXObject) {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
try {
return new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
return false;
}
}
}
},

The following code reproduces the error message in Internet Explorer 8:
HTML
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title></title>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.js"></script>
</head>
<body>
<script type="text/javascript">
$.ajax({
type: 'GET',
url: 'http://127.0.0.1/'
});
</script>
</body>
</html>

image

Force Plain Text Format in Internet Explorer WITHOUT Registry Hack [SOLVED]

Internet Explorer uses MIME sniffing to parse pages and will erroneously render the following page as html:
PHP
 
header('Content-Type: text/plain');
echo '<body>';
echo '<span style="font-size:600%;">';
echo 'normal <strong>bold</strong>';
echo '</span>';

To force Internet Explorer to render the page as plain text, add the following before any text is output:
PHP
 
header('Content-Type: text/plain');
echo ' ';
echo ' ';
echo ' ';
echo ' ';
echo ' ';
echo "\n";

Example:
The following will render as plain text in Internet Explorer:
PHP
 
header('Content-Type: text/plain');
echo ' ';
echo ' ';
echo ' ';
echo ' ';
echo ' ';
echo "\n";
echo '<body>';
echo '<span style="font-size:600%;">';
echo 'normal <strong>bold</strong>';
echo '</span>';

Or simply:
PHP
 
header('Content-Type: text/plain');
echo str_repeat(' ', 250) . "\n";
echo '<body>';
echo '<span style="font-size:600%;">';
echo 'normal <strong>bold</strong>';
echo '</span>';

UPDATE: Sending the X-Content-Type-Options response header will stop MIME-sniffing.
PHP
 
header('X-Content-Type-Options: nosniff');

Python Time Duration Human; Friendly Timestamp

Python
 
#!/usr/bin/python
 
def duration_human(seconds):
seconds = long(round(seconds))
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
years, days = divmod(days, 365.242199)
 
minutes = long(minutes)
hours = long(hours)
days = long(days)
years = long(years)
 
duration = []
if years > 0:
duration.append('%d year' % years + 's'*(years != 1))
else:
if days > 0:
duration.append('%d day' % days + 's'*(days != 1))
if hours > 0:
duration.append('%d hour' % hours + 's'*(hours != 1))
if minutes > 0:
duration.append('%d minute' % minutes + 's'*(minutes != 1))
if seconds > 0:
duration.append('%d second' % seconds + 's'*(seconds != 1))
return ' '.join(duration)

Example:
Python
 
seconds = [
1,
2,
3600,
7201,
49020,
86400,
100000,
172800,
300000,
31697026,
63200000,
95000000,
999999999
]
for s in seconds:
print str(s).rjust(10, ' '), '=>', duration_human(s)

Example Output:
Code
 
1 => 1 second
2 => 2 seconds
3600 => 1 hour
7201 => 2 hours 1 second
49020 => 13 hours 37 minutes
86400 => 1 day
100000 => 1 day 3 hours 46 minutes 40 seconds
172800 => 2 days
300000 => 3 days 11 hours 20 minutes
31697026 => 1 year
63200000 => 2 years
95000000 => 3 years
999999999 => 31 years
 

Example 2:
Python
 
#!/usr/bin/python
 
import time
 
start = time.time()
 
time.sleep(1)
 
end = time.time()
elapsed = end - start
print duration_human(elapsed), 'has passed'

Example 2 Output:
Code
 
1 second has passed
 

Windows XP Remove Boot / Shutdown / Logon / Logoff status messages

To remove the message boxes / windows that appear while Windows is loading do the following:
1. Start > Run > gpedit.msc > Click OK
2. In the Group Policy window select Local Computer Policy > Computer Configuration > Administrative Templates > System.
3. On the right, double-click the "Remove Boot / Shutdown / Logon / Logoff status messages" setting and select Enabled, click Apply and OK.
Restart your computer and the loading message windows / boxes will not appear.
NOTE: You may also want to disable the Welcome screen: Control Panel > User Accounts > Change the way users log on or off > uncheck "Use the Welcome screen" > click Apply Options.