Tuesday, March 8, 2011

How to Keep Numerous Tabs Open in Google Chrome

I try not to open too many tabs in Google Chrome, however, it still happens. When many tabs are open it slows down the system and take up a lot memory. An easy work around to this is to end all tabs that are not currently in use. To do this simply press Shift+Escape to bring up Chrome's task manager. End all tabs that are not being used or are taking a large share of the memory. The tab remembers its URL but doesn't load anything into memory. Refresh the page to load the contents again. Now one can have as many tabs open without slowing the system.

Friday, February 11, 2011

String Literals

What is wrong with the following code?

#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char** argv)
    char *str = "hello world";

str[0] = 'H';

    return 0;

Saturday, February 5, 2011

XOR Swap Algorithm

XOR swap algorithm is a nifty little trick to swap two variables with each other without a temporary variable.

Here is a little snippet of code showing how it works:

#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char **argv)
int x, y;

x = 123;
y = 456;

cout << "x = " << x << endl; // x = 123
cout << "y = " << y << endl; // y = 456
cout << endl;

// Swap values
x ^= y;
y ^= x;
x ^= y;

cout << "x = " << x << endl; // x = 456
cout << "y = " << y << endl; // y = 123

return 0;

Reverse Words in a String

Reverse the order of words in a string "jackdaws love my big sphinx of quartz" to "quartz of sphinx big my love jackdaws"

Solution 1: Using a Stack
Assumption: The string literal is given in a String

public String reverseString(String myStr)
String [] myStrSplit = myStr.split("-");
Stack<String> stack = new Stack<String>();
StringBuilder myStrReverse = new StringBuilder();

for ( String s : myStrSplit )
stack.push( s );

while ( !stack.empty() )
myStrReverse.append( stack.pop() );

return myStrReverse.toString();

Time Complexity
String#split + pushing on stack + popping off stack
N + N + N time
= O( 3N )

Space Complexity
myStr + myStrSplit + stack + myStrReverse
N + N + N + N
= O( 4N )

Solution 2: Using a Doubly LinkedList

public void reverseString(DLinkedList myStr)
Node next, prev;

for ( Node n : myStr )
next = n.next;
prev = n.prev;

n.next = prev;
n.prev = next;

Time Complexity
traverse myStr
= O( N )

Space Complexity
Space for next and prev
= O( 1 ) (constant space)

Solution 3: Using XOR

#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

// Find next space position
inline int nextSpacePosition(char *str, int startPosition)
int nextSpacePosition = -1;

for ( int i = startPosition; str[i] != '\0'; ++i )
if ( str[i] == ' ' )
nextSpacePosition = i;

return nextSpacePosition;

// XOR Swap
inline void swap(char *a, char *b)
*a ^= *b;
*b ^= *a;
*a ^= *b;

int main(int argc, char **argv)
char *originalStr = "jackdaws love my big sphinx of quartz";
char reverseStr[256];
int strLength;
int pos, spacePos;
bool lastIteration = false;

pos = 0;
spacePos = 0;
strcpy(reverseStr, originalStr);
strLength = strlen(reverseStr);

// Reverses string
for ( int i = 0; i < strLength/2; ++i )
swap(reverseStr[i], reverseStr[strLength-i-1]);

// Reverses words
while ( ! lastIteration )
// Find where word ends (space)
spacePos = nextSpacePosition( reverseStr, spacePos+1 );

if ( spacePos == -1 )
spacePos = strLength;
lastIteration = true;

// Reverse word
int end = pos + ((spacePos-pos) / 2);
for ( int i = pos; i < end; ++i )
swap( reverseStr[i], reverseStr[spacePos-1-(i-pos)] );

pos = spacePos + 1;

cout << "Original: " << originalStr << endl;
cout << "Reversed: " << reverseStr << endl;

Time Complexity
traverse half of reverseStr (reversing the string) + traverse reverseStr (reversing words) + string length
= O( 5/2 * N )
= O( N )

Space Complexity
Space for constant space variables
= O( 1 ) (constant space)

The appealing feature for this method is that it doesn't require any "new" data structures (i.e., linked list) and all the work is done in place.

Tuesday, October 19, 2010

Testing a Device

An interesting question is how do you test a device (e.g., vending machine, toaster, pencil, magical food creator appliance). There is no correct answer to this question but a correct thought processLike any problem that we face as an scientist/engineer is to start from the top. It is very important at this point to understand the big picture.

For a tester this means, what are the requirements of the device? A requirements document is what the product should be or perform. The requirements define the design of the product. There is also specifications which are derived from the requirements. The developer and tester shouldn't worry about writing the specifications, just that they are met, and that they have good requirements.

FURPS represent a good model for classifying software quality attributes. Use FURPS as a high level mental checklist. From there, you can branch into each category and drill down with specific tests.

Functionality - Feature set, Capabilities, Generality, Security
Usability - Human factors, Aesthetics, Consistency, Documentation
Reliability - Frequency/severity of failure, Recoverability, Predictability, Accuracy, Mean time to failure
Performance - Speed, Efficiency, Resource consumption, Throughput, Response time
Supportability - Testability, Extensibility, Adaptability, Maintainability, Compatibility, Configurability, Serviceability, Installability, Localizability, Portability

Other things to keep in mind: input/output, display, and data model.

Related articles:

Apply your knowledge:

Sunday, February 21, 2010

HTC Touch Pro Keyboard Fix

Two months later my keyboard stopped working again. I followed my own fix but it didn't work. I bought a new keyboard from eBay for $26 and installed it. No problems yet. Side note, I had to buy a Phillips size #000 screw driver to remove the four screws holding the keyboard to the sliding bracket. Again, this video on replacing the keyboard was useful.

Recently the keyboard on my Sprint HTC Touch Pro stopped working. I also didn't have the phone insurance plan (d'oh!) so I couldn't send it in to get it fixed without costing to much. So I did some research and found that when pushing down hard on the space key on the keyboard it makes the keyboard work again. This actually worked, however, it did not last. After a week of on and off keyboard functionality I decided it was time to dig deeper for a solution by opening the phone. Below the space key on keyboard is the keyboard's connector to the cellphone. It seems that the connector gets loose or the solder doesn't correctly make the connection. The solution is to push down on the solder so it makes the connection firm again.

Warning: Disassembling the phone WILL void your warranty and MAY damage your phone. Only do this if you feel comfortable dealing with electronics.

Torx screw driver with T-6 head
Flathead screw driver (Recommend 3.0mm)
(Top) Torx screw driver, with T-6 Head
(Bottom) 3.0mm flathead screw driver

Before we begin, this video on keyboard replacement might be helpful in see how the phone looks on the inside. However, we will not be replacing the keyboard.

  1. Turn off the cellphone, remove the back cover and remove the battery.
  2. Unscrew the 4 Torx screws from the back. The screw in the top left has a sticker over it, removing this will most likely void the warranty.
  3. Using the flathead screw driver, push down on the edges to pop out the keyboard. The keyboard should slowly push out on the other side. Work your way around the keyboard a few times. Alternatively, you can run the flathead screw driver or your finger nail around between the keyboard and the chrome frame until it pops out.
  4. Once the keyboard is free, lift the side up next to the volume keys. Note: the keyboard frame is connected on BOTH sides, therefore it will not become fully detach, careful not to yank out the connector on the other side.
  5. Lift up the orange cable directly below the space key.
  6. Take the flathead screw driver and gently push down on the connector area. This should make the keyboard connection more firm.
  7. Push the orange cable back down and put everything back.
Now the keyboard should be working again, enjoy. :-)

Keyboard cable (lift up)

Keyboard connector (push down)

Monday, November 23, 2009

Microsoft Notepad Bug

In my probing of Notepad I've found a bug in the Find dialog:

OS: Windows XP SP 3 (Version 5.1.2600)
In the Find dialog box it allows one to enter a number of characters (unlimited?). However it only looks at the first 128 characters entered in the Find box. This could be misleading when somebody pastes a long string into the find dialog box. Additionally, when you reach the end of the search, when it prints out the string it cannot find it mentions only the first 128 characters. Find only does search for the first 128 characters, but it doesn't explicitly make it clear.

Below is an example when I tried entering 128 characters of 'a' then typing in 'ignored'. The image show how 'ignored' is not part of the search: finds the first 128 characters and when at the end of the find it displays that it cannot find the only the first 128 characters of the find string.

Thoughts & Fixes:
  1. Allow only 128 characters to be entered into the Find text box.
  2. When more than 128 characters get pasted into the Find text box have a message bubble explaining that the text was truncated.
  3. Notepad++ seems to suffer from a similar issue in not explicitly making the user aware that its only searching for only first number of characters. However, Notepad++ actually cuts the string off after you execute the search, which implicitly tells the user that only the first number of characters were searched. Notepad only does this after you perform the search, close the Find dialog and reopen it, does it cut off the find string.

Sunday, November 22, 2009

Software Testing: Overview

Here's my condensing of Wikipedia's Software Testing and a few sub pages.

Software testing can’t make your code 100% bug free, but give more confidence it has less bugs.

Software Testing Topics
Functional vs. non-functional testing
Functional testing
  • verify a specific action or function of the code
  • Can the user do this?
  • Does this particular feature work?
Non-functional testing
  • May not be related to a specific function or user action (i.e., scalability or security)
  • How many people can log in at once?
  • How easy is it to hack this software?

Saturday, November 21, 2009

Windows 7 Paint Bug

As I was testing the line feature in Microsoft Paint in Windows 7 (Version 6.1, Build 7600) I noticed a (small) bug in the line drawing behavior.

When one draws a line (and before the line loses focus), I noticed that Rotate 180 degrees, Flip vertical, and Flip horizontal all don't work on the line. It seems as if a line gets treated differently as the other shapes (all other shapes have a dotted bounding box around them, whereas a line doesn't). However, its strange that Rotate left/right 90 degrees both work but Rotate 180 degrees doesn't -- maybe somebody just forgot?

The issue can be resolved in one of two ways: gray out the three Rotate drop down options, or (better) implement the logic necessary to get the three malfunctioning rotates to work.