Friday, October 1, 2010

Tips for filing a support ticket with properietary software that you use at work

1. Be friendly but make the case that you're incapable of doing some part of your job properly. People that yell the loudest (but are friendly) and make a strong case will typically have their issues fixed first. You want to create a sense of guilt at the vendor, not hate, so someone will be more likely to work overtime or bust their ass to fix your problem.
2. You describe clearly what the problem is (more than just "it doesn't work")
3. Describe clear steps to reproduce the problem from start to finish. Include your starting point, relevant data entered and items clicked. This is very important, because it takes forever to fix a bug that can't be easily duplicated. Further, you might get stuck with nothing happening because they think you're doing something wrong.
4. Describe the results you're seeing ("Error Message _____", calculation is 10 cents off, field that's allowed to be blank is required, etc)
5. Describe the results you should be seeing. This is important because the software developer should have a QA team and be able to take the steps from #2 and make sure they've actually fixed the problem instead of simply breaking something in a different way.

Thursday, August 5, 2010

Capturing Variable Type Data By Running PHP

PHP is hard to automatically convert to other languages because there is little type information hardcoded into it. Here's some sample code that uses the debug interface to extract type information out for variables. For now, it just dumps the type data to stdout. Presumably you would need to save this to some sort of sqlite database and run all of your automated tests to ensure full code coverage. Then you could translate your parsed PHP to another language with the additional information known.



// Use xdebug to determine type information about all of the executed parts of your script
// to run, 1: execute this
// 2: export XDEBUG_CONFIG="idekey=session_name remote_autostart=1 remote_host=127.0.0.1 remote_enable=1"
// 3: run your cli php script

// Set time limit to indefinite execution
set_time_limit (0);

// Set the ip and port we will listen on
$address = '127.0.0.1';
$port = 9000;

// Create a TCP Stream socket
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
// Bind the socket to an address/port
socket_bind($sock, $address, $port) or die('Could not bind to address');
// Start listening for connections
socket_listen($sock);

/* Accept incoming requests and handle them as child processes */
$client = socket_accept($sock);

// Read the input from the client – 1024 bytes
$input = socket_read($client, 1024);
echo($input);
echo("\n");
// Strip all white spaces from input
$output = preg_replace("/[ \t\n\r]/","",$input).chr(0);
$doc = new DOMDocument();
function read_debugger()
{
global $client;
$string = '';
$char = socket_read($client, 1);
while(! socket_error() && $char <> "\0") {
$string .= $char;
$char = socket_read($client, 1);
}
return $string;
}
while(! socket_last_error($client)) {
$i++;
socket_write($client, "step_into -i ".$i."\0");
$file_line_info = socket_read($client, 1024);
preg_match('/filename="(.*?)"/', $file_line_info, $matches);
$line_no = $matches[1];
preg_match('/lineno="(.*?)"/', $file_line_info, $matches);
$filename = $matches[1];
echo("$filename : $line_no ");
$i++;
socket_write($client, "context_get -i ".$i."\0");
$dummy = read_debugger();
$context_info = read_debugger();

if (!($doc->loadXML($context_info))) {
die("FAIL ON ".$context_info);
}
$propertyNodes = $doc->getElementsByTagName('property');
for($j = 0; $j < $propertyNodes->length; $j++) {
$property = $propertyNodes->item($j);
echo($property->getAttribute('fullname').':'.$property->getAttribute('type').' ');
}

echo("\n");
}
// Close the client (child) socket
socket_close($client);

// Close the master sockets
socket_close($sock);

Wednesday, April 28, 2010

Bumper Stickers

A friend is selling some here: http://getoffyourfuckingphone.com/

Sunday, November 1, 2009

removing the texture of old pictures with FFTs












Imagej (http://rsbweb.nih.gov/ij/) has an awesome feature that allows you to perform an FFT on an image, edit it, and then do an inverse FFT. This is very useful for eliminating patterns from an image, such as the texture of old photographs.

Full size images for further comparison:
http://www.flickr.com/photos/ftzdomino/4065410668/sizes/o/
http://www.flickr.com/photos/ftzdomino/4064662889/sizes/o/

Monday, October 12, 2009

Booting to a raid volume using jfs

While upgrading an older debian server, I had to make some modifications to get the kernel booting. This shouldn't normally be necessary, but for some reason the hardware was not getting auto detected. I'm almost 100% sure I messed up some other step in order to require this. The system's root drive is raid1 and uses jfs. The following changes were done:

Added: /etc/initramfs-tools/modules:
jfs
raid1
md

Created:
/etc/initramfs-tools/scripts/local-top/probes
#!/bin/sh
modprobe raid1
modprobe md
modprobe jfs

mknod /dev/md2 b 9 2
mknod /dev/md0 b 9 0
mknod /dev/md1 b 9 1
mdadm --assemble --scan

The above script must be chmod +x'd. I copied to it /etc/initramfs-tools/scripts/local-top/probe/local-premount/ just to make sure it ran.

Modified /usr/sbin/mkinitramfs in the #modutils section:
copy_exec /sbin/mdadm /sbin
copy_exec /sbin/fsck.jfs /sbin
mkdir -p "${DESTDIR}/etc/mdadm"
cp -a /etc/mdadm/mdadm.conf "${DESTDIR}/etc/mdadm/"

The above changes were done by booting into the rescue mode of a debian installer and mounting.

Tuesday, August 25, 2009

Installing Windows Server 2008 in VirtualBox

Today I installed a beta Windows Server 2008 onto a virtual machine on my Mac using VirtualBox. After some trial and error, the following settings seem to have allowed it to work:

System:
OS Type: Windows 7 (64 bit)
Base Memory: 500 MB
Processors: 1
VT-x/AMD-V: Enabled
Nested Paging: Enabled

Display:
Video Memory: 12MB
3D Acceleration: Enabled

Thursday, August 20, 2009

Blocking spam from Yahoo! Personals

I get approximately 10 messages a day from Yahoo! Personals, which pass through spamassassin because they're DKIM signed. As far as I can tell, there's no way to opt out on Yahoo's end, so I had to resort to blocking every message with their telltale subject. Here's the rule:

header SUBJECT_YAHOO_PERSONALS Subject =~ /Dating 101: Reviving Your Relationship/i
score SUBJECT_YAHOO_PERSONALS 20.0

Thursday, June 25, 2009

Debian Installation on Servers With Broadcom 5708/5709 NICs using the bnx2 driver

Installing Debian on a system with Broadcom network interfaces can be quite annoying because the firmware is no longer included. If you load the firmware onto a usb disk as suggested, you run into other problems when using scsi drives resulting in a system which requires hacking menu.lst after install to boot. This approach doesn't work if you're using iLO/DRAC/iDRAC to install as they only allow one remote media connection at a time.

An easy workaround is to modify your install iso to contain the drivers. Here's how:
  1. Download a newish Debian install iso.
  2. Mount the install iso:
    1. mkdir cdrom
    2. mount -o loop debian-testing-amd64-CD-1.iso cdrom
  3. Copy the files:
    1. mkdir isocopy
    2. cp -av cdrom isocopy
  4. Download the appropriate firmware package for your installation, such as http://packages.debian.org/squeeze/all/firmware-bnx2/download
  5. Extract the drivers and copy into your new iso:
    1. dpkg-deb -x firmware-bnx2_0.16_all.deb firmware
    2. cp firmware/lib/firmware/* isocopy/cdrom
  6. Build a new iso:
    1. cd isocopy/cdrom
    2. mkisofs -o ../modified-debian.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V disks .
  7. Done, let's look at our new iso:
    1. cd ..
    2. ls modified-debian.iso

You can now burn this iso to a CD or use it as virtual media.

There's one final step, which is getting the OS to see the firmware drivers.

Once booted to the new ISO, you need to immediately switch to another console and copy the files over before the installer looks for them:
  1. mkdir lib/firmware
  2. cp /cdrom/*.fw lib/firmware
After that's done, the Debian installer should be able to autoload the bnx2 driver without any problems.

Monday, June 15, 2009

php utf-8 chr() and ord() equivalents

As far as I can tell, PHP provides no built in methods of working with multi byte characters.

Here is a simple function for turning an integer value into a character:

function unichr($intval) {
return mb_convert_encoding(pack('n', $intval), 'UTF-8', 'UTF-16BE');
}

A uniord() function can be found in the comments of the PHP manual:
http://us.php.net/manual/en/function.ord.php

Monday, May 25, 2009

"This PDF document contains an Adobe XML form. Such files cannot be optimized."

To fix this problem:
  1. Save the document in LiveCycle with PDF compatibility
  2. Use the drop_xfa command with pdftk
This removes all of the LiveCycle data and makes the file compatible with Acrobat and other tools.

Tuesday, March 31, 2009

Some useful MegaCli commands/quick debian howto

MegaCli and MegaCli64 are the LSI utility used for Dell Perc 5 and other adapters isn't well documented. Here's some commands:

MegaCli -AdpEventLog -GetEvents -f logfile -aALL
What it does: Dump all events from the adapters event log to a file named logfile

MegaCli -PDList -aAll | less
What it does: Dump information about all Phsyical Disks (hence the PD), paged with less

MegaCli -LDInfo -LAll -aAll | less
What it does: Dump information about all Logical Disks on all adapters, paged with less

MegaCli -LdPdInfo -aAll | less
What it does: Dump information of all logical and physical disks on all known adapters

Currently these can be obtained from LSI at http://www.lsi.com/DistributionSystem/AssetDocument/support/downloads/megaraid/miscellaneous/linux/1.01.39_Linux_Cli.zip

You don't need to actually install the packages, both the MegaCli and MegaCli64 (64 bit build) are statically linked within. In order to access them in a non RPM environment, you can extract the files with the following command:
rpm2cpio MegaCli-1.01.39-0.i386.rpm | cpio -idmv
This will extra the MegaCli and MegaCli64 executables.
Alternately, you can try to convert the rpm to a .deb via alien.

Sunday, March 29, 2009

Video of morse code blinking

I modified a bike blinker to blink in morse code. Video of it in action is
here

Source is here.

Tuesday, March 10, 2009

One cause of "Fatal error: Exception thrown without a stack frame in Unknown on line 0"

"Fatal error: Exception thrown without a stack frame in Unknown on line 0" can be quite hard to debug.

php -r '
register_shutdown_function("a");
function a() {
$b = new DateTime("02/40/2009");
} '

Results in:
Fatal error: Exception thrown without a stack frame in Unknown on line 0

The problem is that PHP does not allow exceptions to be thrown in a shutdown function or anything called by a shutdown function. Initializing a DateTime object with an invalid date throws an exception, leading issues similar to above.

Friday, February 27, 2009

Fun with PHP implicit scoping on static calls

class a {
public $a = "yay!";

func call_b()
{
b::b();
}
}

class b {
function b()
{
echo $this->a;
}
}

$a= new a();
$a->call_b();


Prints:
yay!

This is because if you statically call a method that is not declared as static in PHP, it inherits the class scope of the caller. Note that if you had declared function b as a static method, you'd get a different behavior.

Wednesday, February 25, 2009

Apple Wireless Keyboard + Ubuntu Intrepid

I had some trouble pairing at first, but found this to work:
  1. Turn keyboard off
  2. Open up the new bluetooth device wizard
  3. Turn the on
  4. Select the keyboard
  5. Click Next
  6. While the wizard is waiting, enter 0000 and Enter on the keyboard
  7. Enter 0000 and Enter a second time.
The main issue seems to be that the OS doesn't prompt you at the correct time to enter the pairing password.

Tuesday, February 10, 2009

Fun with implict type conversions in PHP

PHP requires extreme care while programming. For example:
'1,234' * 1 == 1
0 == false
false == ''
0 == '0'
false != '0'

Friday, December 26, 2008

Passive monitoring of ping times on incoming TCP connections

For those of hosting web applications, it is frequently convenient to have ping time information available for all incoming connections. Most networks these days block icmp ping requests, making it impossible to actively ping users. One workaround is to passively monitor events in the TCP connection which have approximately the same round trip time as a ping request. Specifically, the time between a packet from a client with SYN and ACK flags set and the next packet received with an ACK flag set are monitored and reported.

Below is a PHP script which uses tcpdump to monitor incoming connections on ports 80 and 443. Due to the fact that packet sniffing is used, root access is required for execution.

#!/usr/bin/php

/**
* This is a script which tracks the tcp handshake to attempt to passively monitor our client's ping times.
*
*/


$ip_latency = array();

$handle = popen('sudo tcpdump -n -tt "tcp[tcpflags] & (tcp-syn|tcp-ack) != 0 && (port 80 or port 443)" 2>/dev/null', 'r');

while(! feof($handle)) {
$output = fgets($handle);

if (preg_match('/^([0-9.]+).* > ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\.([0-9]+): S .* ack /', $output, $matches)) {
// it's a SYN+ACK
// record the timestamp and wait for the response
list($dummy, $timestamp, $remote_ip, $remote_port) = $matches;

$ip_latency[$remote_ip.':'.$remote_port] = array('start' => $timestamp);

// echo("SYNACK $timestamp, $remote_ip, $remote_port\n");
} elseif (preg_match('/^([0-9.]+) IP ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\.([0-9]+) > .*: \. ack 1 /', $output, $matches)) {
// it's an ACK 1
list($dummy, $timestamp, $remote_ip, $remote_port) = $matches;

if (isset($ip_latency[$remote_ip.':'.$remote_port]) && ! isset($ip_latency[$remote_ip.':'.$remote_port]['end'])) {
$ip_latency[$remote_ip.':'.$remote_port]['end'] = $timestamp;

$latency = $timestamp - $ip_latency[$remote_ip.':'.$remote_port]['start'];
// echo("ACK $timestamp, $remote_ip, $remote_port\n");
printf("%s - %s : %2.8f\n", $timestamp, $remote_ip, $latency);
unset($ip_latency[$remote_ip.':'.$remote_port]);
}

if (rand(0, 100) == 0) {
// clean up, clear out all entries older than 100s

foreach($ip_latency as $key => $timing) {
if ($timestamp - $timing['start'] > 100) {
// echo("PURGE $key\n");
unset($ip_latency[$key]);
}
}
}
}
}

Sunday, December 7, 2008

Morse code on the EZ-430/MSP430

//******************************************************************************
// Morse code blinker program
// derived from a basic blinker app
//******************************************************************************

#include "msp430.h"

const char* morse_table[] = { 
  ".-" , // A
  "-...", // B
  "-.-.", // C
  "-..", // D
  ".", // E
  "..-.", // F
  "--." , // G
  "....", // H
  ".."  , // I
  ".---", // J
  ".-.-", // K
  ".-..", // L
  "--", // M
  "-.", // N
  "---", // O
  ".--.", // P
  "--.-", // Q
  ".-.", // R
  "...", // S
  "-", // T
  "..-", // U
  "...-", // V
  ".--", // W
  "-..-", // X
  "-.--", // Y
  "--.." // Z
  
};

/**
 * Low power mode sleep
 *
 */ 

void sleep(int howlong)
{
  int i;
    for(i=2*howlong;i>0;i--) { LPM0; }
}

/**
 * Turn on pin 1
 *
 */

inline void led_on()
{
      P1OUT |= 0x01;
}

/**
 * Turn off pin 1
 *
 */

inline void led_off()
{
      P1OUT &= ~0x01;
}

/**
 * Blink a string in morse code
 *
 * Takes a string and blinks it
 */

void blink_morse(const char *s)
{
  int i,j, letter_index;
  const char *dots;
  for(i=0;s[i] != (char) 0; i++){
    letter_index = -1;
    if (s[i] >= 'A' && s[i] <= 'Z')
      letter_index = (int) s[i] - (int) 'A';
    
    if (s[i] >= 'a' && s[i] <= 'z')
      letter_index = (int) s[i] - (int) 'a';
    
    if (letter_index != -1) {
      dots = morse_table[letter_index];
     for(j=0;dots[j] != (char) 0; j++) {
       switch(dots[j]) {
        case '.':
        led_on();
        sleep(1);
        led_off();
        break;
        
       case '-':
         led_on();
         sleep(3);
         led_off();
         break;
       }
      sleep(1);
     }
    } else {
      // not a regular character
      sleep(4); // medium gap when combined with short gap below
    }
    led_off();
    sleep(3); // short gap
  }
}

int main(void)
{
  
  WDTCTL = WDTPW + WDTHOLD;
 
 // Set pin 1 for output
  P1DIR |= 0x01;
  
 
  CCTL0 = CCIE;
  // set CCR0 delay to 60,000 
  CCR0 = 60000;
  TACTL = TASSEL_2 + MC_1;
 
  _BIS_SR(LPM0_bits + GIE);
  // start with the LED off
  led_off(); 

  for(;;)
  {

 blink_morse("This message is blinking in morse code");
 blink_morse("You can fit a paragraph or two into even the smallest MSP430");

 
    sleep(10);
  }
}

#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
 LPM0_EXIT; 
 
}