Monday, March 29, 2010

DNS issues with Netgear WGR614v5

Sooo... here's the story.

I keep getting stuck on "Resolving host" when browsing the web. I developed a simple test. Open 9 tabs at the same time and see which get through and which don't. My Godaddy sites never come through, and most of the time neither do Twitter and Blogger.

What's really going on? Since it was stuck on "Resolving host" I reverted to some manual nslookup debugging. Even nslookup showed "DNS request timed out", and "timeout was 2 seconds".

I then updated my local LAN card to use Comcast's server instead of relying on the router's ability to do lookups. No change.

Solution:
Convert UDP DNS requests to TCP!! It seems that this router gets overwhelmed by routing the DNS requests and drops them.

When this happens, the WGR614v5 loses the ability to resolve DNS for about 5 - 10 seconds. During this time, I tested a custom DNS lookup using both UDP and TCP. The UDP lookup failed, and the TCP lookup worked. This prompted me to write a simple server which listens for DNS requests, wraps the data with the customary 2 byte size header and sends it on as a TCP request. Once the response comes back, I remove the 2 byte size header from the response, and I send it back to the requester.

The router may have a general UDP problem, as opposed to a UDP DNS problem, but all I care about at the moment is my ability to get to my webpages. As HTTP is TCP and it just relies on the DNS requests to get the address, this solves my problem well enough for now.

A new router is being purchased in the next few days...

Friday, March 5, 2010

HTML stuff...

Never put a block-level element inside a paragraph :

...

! This is illegal in HTML 4.01 (http://www.w3.org/TR/html4/struct/text.html#h-9.3.1)

"The P element represents a paragraph. It cannot contain block-level elements (including P itself)."

---

IE8 - JSON works, but only if you have:

otherwise IE8's JSON object is undefined...

---

IE8 - eval function - Accepts string only, and should be enclosed in parenthesis! So if you are eval'ing an object then the object name is put in quotes. For example:

parse(jsonString) {
return eval('(' + jsonString + ')');
//return eval(jsonString); -- Illegal!
}

---

PHP - isset should be used to see if variable exists, also variable indexes and the like.
ie: isset(myObj['testExist'])); will return true if testExist exists and is non-null

---

Chrome and Safari (guessing it's a webkit issue) won't keep the text selected if you just use an onFocus callback with a text.select() call. You must cancel the mouseup event otherwise the text most of the time gets deselected. Argh

Thursday, February 18, 2010

Downloaded NVIDIA driver? Screensaver may still turn on when playing a movie in full screen

I'm running Vista x64 SP2 and Windows Media Player 11. I have an NVIDIA GeForce 8600 graphics card. I also make sure that the "Allow screen saver during playback" is unchecked in WMP -> Tools -> Options. After 20 minutes my screen saver kicks in.

Anyhow I've solved the problem with the screen saver. I like to keep my system as updated as possible, so I install NVIDIA's drivers directly from their website. Yesterday I removed NVIDIA's drivers, and I let Windows install it's own drivers for the graphics card. Of course Microsoft is just packaging a form of NVIDIA's drivers, but now my screen saver stays disabled when I play a movie.

Saturday, February 6, 2010

Interesting HW interview question... Serial binary input divisible by 5

I'm in California at the third round of interviews and I'm asked a question that baffled me. Given a serial input of a binary number, write a state machine that tells if that value is divisible by 5.

I first solved the problem thinking the input was MSB first. This is pretty trivial. 5 states and some very simple movements. Then it was clarified that they wanted it solved LSB first. I thought about it but I could not come up with a solution.

It is now the next day and I approached the problem again. I have a good and clear solution, but I'd love to know if there is a better one.

WARNING - Solution below:


A single bit, in any location, when converted to decimal will always end in either 2, 4, 8, or 6 except of course the least significant bit which is 1.
1, 2, 4, 8, 16, 32, 64, 128, 256...
1, 2, 4, 8, 6, 2, 4, 8, 6...
A divide by 5 problem at any given time can be in one of five situations. It's either 0, 1, 2, 3, or 4 from being divisible by 5. Ie: it is 0 and is divisible, or 1 and needs another 4, or 2 and needs another 3...

By combining both of these ideas you can build a state machine with 20 states that easily solves this problem. It's like 5 small 4-stated machines. The 4-stated machine keeps moving between 2, 4, 8, and 6 when there's a 0 input, and moves to one of the other machines when there is a 1. Of course you need an extra start state to deal with the first bit. And anytime you are in the 0 4-stated machine then the value is divisible.

Best way to explain is by example:
current value, add value (c, a) where c goes from 0 to 4 and a is 2, 4, 8, or 6.

Starting in first bit state:
Value that will be given is 25 (11001).
1: First bit state moves to (1, 2) since current value is 1 and next bit will add 2.
0: (1, 2) moves to (1, 4) since current value is still 1 and next bit will add 4.
0: (1, 4) moves to (1, 8) since current value is still 1 and next bit will add 8.
1: (1, 8) moves to (4, 6) since current value is now 4 (9 divided by 5 leaves a remainder of 4) and next bit will add 6.
1: (4, 6) moves to (0, 2) since current value is now 0 (10 divided by 5 leaves a remainder of 0) and next bit will add 2.

That's it.

Tuesday, January 12, 2010

Spice circuit simulator - part 2

I did it! I made a circuit and I got it to run. I have returned back to Berkeley's 3f5 spice. Using cspice I can input the file circuit.txt:

My first circuit
.op
vcc high 0 dc 10
r1 high bw 3
r2 bw 0 4
.end

This is a very simple circuit with 10v going to a 3 ohm resistor and then a 4 ohm resistor and then back to ground.  10v -- 4ohm -- 3ohm -- gnd

I run this simulation with this command on Windows: cspice.exe < circuit.txt

This results in actual output! Much of this I learned from Berkeley's documentation at http://bwrc.eecs.berkeley.edu/classes/IcBook/SPICE/ under Interactive User Guide. I also referenced Kevin Cosgrove's article 'Analyzing Circuits with SPICE on Linux' at http://www.linuxjournal.com/article/2169.

I am not anywhere near the point of running spice to do transient analyses. I only want very simplistic static results of basic digital circuits. This is what I now feel confident that I can do.

Monday, January 11, 2010

Spice circuit simulator

I'm learning electrical engineering... Pretty tough to understand this stuff, but www.allaboutcircuits.com really helps. Another tool I'm trying to use is a spice simulator. This way I can write tiny circuits and see if I understand what they're supposed to do, and spice can verify that.

Anyhow, I started searching for spice, and that was a bit of a challenge just because of it's name... Google doesn't bring you to what you're looking for directly, so here's a good starting point: http://bwrc.eecs.berkeley.edu/Classes/IcBook/SPICE/ - Homepage
http://bwrc.eecs.berkeley.edu/Classes/IcBook/tools.html - List of available spice simulators

OK. So which one to download. I like to work as manually as possible to increase my understanding as much as possible, so this meant I wanted a tool that was as much like the UNIX version (I'm on Windows) as possible. I also want a text based tool for now. This led me to download Berkeley's spice3f5.tar.gz, and to figure out how to compile this with Visual C++ 2008. A good starting point is http://rayslogic.com/Spice/compile_berkeley_spice_3f5.htm. I did some things differently from what he listed, but I believe his directions will work too. A tip would be to use GnuWin32's find, xargs, and sed tools to perform the necessary changes to the files. Also when following the /OUT: directions you have to add that line to only the files he listed, otherwise the lib files won't get added correctly. I chose a more generic method of modifying the batch files with something like this in the relevant msc51.bat files:
set LIBPARAM=
set LIBNAME=..\..\dev1.lib
if not exist %LIBNAME% set LIBPARAM=/OUT:
lib %LIBPARAM%%LIBNAME% @response.lib >> ..\..\..\msc.out

... After getting it to compile I realize that it doesn't create spice3.exe, and only really creates bspice.exe and cspice.exe. I don't currently know much about spice so I don't really know what those files do for you, but from what I can see they aren't what I was looking for.

At this point I started looking for another alternative. I found ngspice: http://ngspice.sourceforge.net/download.html. The download page is http://sourceforge.net/projects/ngspice/files/. I know it says that they only release sources, but that's not true, download the zip file and you'll see it has Windows binaries. I'm guessing that they never bothered to update that information.

Last thing... Seems that spice uses something referred to as decks (input decks). Trouble is no one bothers to tell you what that is. I am once again positing that this term comes from very old systems that accepted commands on actual cards. Each command was put on a card and the cards were fed into a machine. The combined cards were referred to as decks. I found a reference to cards and decks here: http://www.eecg.toronto.edu/~johns/spice/part1.html. So an input deck seems to just be a set of input commands.

Will update as I learn more. At this point I'm still just a fish flapping around on dry land with regards to spice.

Sunday, December 27, 2009

Secure Your Password - Chrome extension

https://secureyourpassword.com
http://code.google.com/p/secureyourpassword/

Passwords are notoriously insecure. Secure Your Password changes that.

How your password is exposed
1. Logging into a non-secure website from a public WiFi network
2. All website which you log into have access to your password
3. 3rd party password security sites keep your password

What Secure Your Password does for you.
1. Never stores or receives your password, your password never leaves your computer
2. Creates a salt (random word) which obfuscates your password on a website by website basis
3. Stores the salt on a secure (https) server, and retrieves that salt whenever you want to access the website
4. Does all of this transparently after the initial creation of the password