Dark Launch

This is a Dark Launch.

Ubuntu Get Window Position Information; xwininfo

To get the position of a window in Ubuntu, in terminal:
Code
 
xwininfo
 

Code
 
xwininfo: Please select the window about which you
would like information by clicking the
mouse in that window.
 
xwininfo: Window id: 0x20ffa54 "Dark Launch - Mozilla Firefox"
 
Absolute upper-left X: 1039
Absolute upper-left Y: 48
Relative upper-left X: 1039
Relative upper-left Y: 48
Width: 800
Height: 600
Depth: 24
Visual Class: TrueColor
Border width: 0
Class: InputOutput
Colormap: 0x20 (installed)
Bit Gravity State: NorthWestGravity
Window Gravity State: NorthWestGravity
Backing Store State: NotUseful
Save Under State: no
Map State: IsViewable
Override Redirect State: no
Corners: +1039+48 -865+48 -865-402 +1039-402
-geometry 800x600+1039+48
 

MySQL Calculate Hours From Two Timestamps

To calculate the difference between two timestamps in seconds or hours use the following:
SQL
 
SELECT(
UNIX_TIMESTAMP("2009-08-17 10:00")-UNIX_TIMESTAMP("2009-08-17 09:00")
) AS seconds
 
>>> 3600

SQL
 
SELECT(
(UNIX_TIMESTAMP("2009-08-17 10:00")-UNIX_TIMESTAMP("2009-08-17 09:00"))/3600
) AS hours
 
>>> 1.0000

Ubuntu Nautilus Back and Forth Mouse Click Buttons

Navigate back and forward in Nautilus using the mouse back/forward buttons:
Run in terminal:
Code
 
sudo apt-get install xvkbd xbindkeys x11-utils
 

Find the mouse keys:
Code
 
xev | grep ', button'
 

Click in the window to see the mouse codes. Example:
Code
 
state 0x10, button 8, same_screen YES
state 0x10, button 8, same_screen YES
state 0x10, button 9, same_screen YES
state 0x10, button 9, same_screen YES
 

8 for left thumb click, 9 for right thumb click.
Edit the key bindings. Terminal:
Code
 
gedit ~/.xbindkeysrc
 

Code
 
"/usr/bin/xvkbd -xsendevent -text "\[Alt_L]\[Left]""
m:0x0 + b:8
"/usr/bin/xvkbd -xsendevent -text "\[Alt_L]\[Right]""
m:0x0 + b:9
 

Run xbindkeys in terminal:
Code
 
xbindkeys
 

Now clicking the back and forth mouse keys will navigate back and forth in Nautilus.

Base58 Encode and Decode using PHP with example; base58_encode(), base58_decode()

Base58 is base62 with some confusing characters removed. These removed are 0, O, l, I.
PHP
 
function base58_encode($num) {
$alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
$base_count = strlen($alphabet);
$encoded = '';
 
while ($num >= $base_count) {
$div = $num / $base_count;
$mod = ($num - ($base_count * intval($div)));
$encoded = $alphabet[$mod] . $encoded;
$num = intval($div);
}
 
if ($num) {
$encoded = $alphabet[$num] . $encoded;
}
 
return $encoded;
}
 
function base58_decode($num) {
$alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
$len = strlen($num);
$decoded = 0;
$multi = 1;
 
for ($i = $len - 1; $i >= 0; $i--) {
$decoded += $multi * strpos($alphabet, $num[$i]);
$multi = $multi * strlen($alphabet);
}
 
return $decoded;
}

PHP
 
<?php
header('Content-Type: text/plain');
 
$array =
array(
// base10 => base58
'3429289555' => '6e31iZ',
'3368' => '215',
'74' => '2h',
'75' => '2i',
'94' => '2C',
'88' => '2w',
'195102' => 'ZZQ',
'1253576' => '7qDo',
'177' => '44',
'193' => '4k',
'195' => '4n'
);
 
foreach ($array as $base10 => $base58) {
echo 'base58_encode(\'', $base10, '\') => ', base58_encode($base10), "\n";
}
 
echo "\n";
foreach ($array as $base10 => $base58) {
echo 'base58_decode(\'', $base58, '\') => ', base58_decode($base58), "\n";
}

Code
 
base58_encode('3429289555') => 6e31iZ
base58_encode('3368') => 215
base58_encode('74') => 2h
base58_encode('75') => 2i
base58_encode('94') => 2C
base58_encode('88') => 2w
base58_encode('195102') => ZZQ
base58_encode('1253576') => 7qDo
base58_encode('177') => 44
base58_encode('193') => 4k
base58_encode('195') => 4n
 
base58_decode('6e31iZ') => 3429289555
base58_decode('215') => 3368
base58_decode('2h') => 74
base58_decode('2i') => 75
base58_decode('2C') => 94
base58_decode('2w') => 88
base58_decode('ZZQ') => 195102
base58_decode('7qDo') => 1253576
base58_decode('44') => 177
base58_decode('4k') => 193
base58_decode('4n') => 195
 

NOTE:
Code
 
Base62: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
Base58: 123456789abcdefghijk mnopqrstuvwxyzABCDEFGH JKLMN PQRSTUVWXYZ