Wednesday, August 24, 2011

How to save money when shopping online

I thought since I referenced it in my last post, albeit subtly, I should mention retailmenot.com, which has saved me a ton of money when I shop online.

Just shop like you normally would from your online retailer of choice. When you're checking out, stop by retailmenot.com, type the name of the site in their search bar, and see if there are any available coupon codes for that site before you complete your purchase. It's completely free.

No, I'm not getting paid by retailmenot.com to say this (not that I would turn down such an offer ;)), but there are a lot of coupon code sites out there, and most of them are garbage. retailmenot.com is the only one I've found that isn't worthless.

So try it out. The worst that could happen is you'll save some money. (Actually I suppose it'd be worse if you didn't save any money, but I digress...)

Monday, August 15, 2011

Cheapest way to unlock GSM phones

Looking to unlock your GSM phone? One word: ebay.

Of course you should always shop around and do some googling, if for no other reason than the fact that some phones can be unlocked for free, in particular many nokia models:

Free Nokia Unlock Codes

But if you do end up having to pay, ebay can save you a lot of money. For instance, I recently unlocked a Motorola Defy using a code I bought off ebay for $8 by searching "motorola defy unlock code." By comparison, this is what some of the unlock sites charge for a code to unlock that same phone (I'm including ebay in this list in case people skip right to this part of the post):

ebay: $8
cellunlock.net: $15 ($30 before coupon code)
cellunlocker.net: $30
cheapunlocks.com: $20
gsmliberty.net: $25
unlockgenie.com: $30
unlockitnow.com: $30

I'll let you do the math ;)

Tuesday, August 9, 2011

re-enable second monitor in linux after it goes blank

solution:



  1. if your resolution was also changed, restore the original resolution:
    xrandr -s 0

  2. re-enable your second monitor:
    xrandr --auto

  3. restore any special setup. for example, I have my second monitor to the right of my first, extending my desktop. this is what I did to get it to work:
    xrandr --auto --output DFP2 --right-of DFP1



DFP1 and DFP2 are the names of my monitors, so that command probably won't work for you. in order to get the names of your monitors, in a terminal, run this command to list the connected monitors:
xrandr -q | grep " connected"

if you run this command before you run xrandr --auto, your disabled monitor should show up in the list without a resolution. for example, in my case DFP2 is the name of the disabled monitor:
$ xrandr -q | grep " connected"
DFP1 connected 1680x1050+0+0 (normal left inverted right x axis y axis) 473mm x 296mm
DFP2 connected (normal left inverted right x axis y axis)


to get the possible options for the --output parameter, just run xrandr --help to list them all.


details:



I have a dual-monitor linux setup, and in particular when running full-screen apps using Wine, my second monitor will go blank. once I close the app, my second monitor stays blank, and all my windows are moved to the first monitor.

up to this point I've been too lazy to figure out how to re-enable my second monitor, and I'd just reboot, which always fixes it. today I finally took the time to figure it out.

of course the best solution to any problem is preventing it in the first place. here's a great article I found on preventing this while I was looking for a solution to my problem:

How to Run Fullscreen Games In Linux With Dual Monitors

Monday, July 25, 2011

an intriguing look at software patents

When Patents Attack!



Why would a company rent an office in a tiny town in East Texas, put a nameplate on the door, and leave it completely empty for a year? The answer involves a controversial billionaire physicist in Seattle, a 40 pound cookbook, and a war waging right now, all across the software and tech industries.

listen to it online now, or you can download the podcast for free for a short time:

http://www.thisamericanlife.org/radio-archives/episode/441/when-patents-attack

Monday, July 18, 2011

Python mysqldb UnicodeDecodeError: 'ascii' codec can't decode byte

Solution:

If you run into the error mentioned in the title of this post using python's mysqldb module version 1.2.1 or less, decode your data/query first:

mydata.decode('utf8')

(modifying 'utf8' to whatever encoding your data happens to be in)

Details:

So I was writing some code in python on Ubuntu, and it was working just fine. When I went to run it in RHEL, I got this error:

Traceback (most recent call last):
File "", line 50, in ?
File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line 146, in execute
query = query.encode(charset)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 223: ordinal not in range(128)


My first thought was that it was due to the incredibly old version of Python that ships with RHEL 5 (Python 2.4), but it didn't take me long to realize the problem was with the MySQLdb module itself. Ubuntu 10.10 ships with version 1.2.2 of that module, while RHEL 5 ships with version 1.2.1. A minor difference, but apparently in that time this bug was fixed:
http://sourceforge.net/tracker/index.php?func=detail&aid=1521274&group_id=22307&atid=374932

Apparently MySQLdb 1.2.1 tries to indiscriminately encode the data to be put into the database to utf8 (well, at least when you specify utf8 as the database character set), without checking whether the string is already utf8 or not. My solution was just to decode my data from utf8 (to unicode) before passing it to my mysql query, at which point the encoding works just fine.

Like so (the first line's the relevant one):

mydata.decode('utf8')
query = ('INSERT INTO %(database)s (%(column)s) VALUES (%(value)s)' % {'database': database, 'column': column, 'value': mydata})
cursor.execute(query)


Of course, you should modify the 'utf8' part to whatever encoding your data is in.

Edit: If you're using MySQLdb.escape_string(), make sure you run that first before doing the decode, like so:

MySQLdb.escape_string(mydata).decode('utf8')

Friday, June 3, 2011

R.java: No such file or directory


solution:




  1. run this in a terminal:
    rm ~/.android/debug.keystore


  2. rebuild your project: go to Project --> Clean --> Clean projects selected below --> check your project --> OK







backstory:



okay, so I was tinkering with android today in Eclipse, and all of a sudden, my android project shows it has an error. not on any particular file, but on the project itself. normally when I get random errors, I select the project and go to Project --> Clean. today, that didn't work.

I wasn't seeing anything helpful in the console. after cleaning the project, I saw this in the console:

[2011-06-03 15:21:52 - android_test] ERROR: Unable to open class file /home/user/workspace/android_test/gen/us/test/test/R.java: No such file or directory

that was weird, because the file existed. so I went ahead and deleted the gen folder and rebuilt the project (which is what the clean command basically does), and still got the same error.

thinking my eclipse installation was corrupted, but too lazy to reinstall, I restored backups of various folders. no dice. I reinstalled the android SDK tools. nope. I checked permissions, tried reimporting my project, even tried creating a new project, and nothing worked.

finally, out of desperation, I deleted the .android folder in my home directory. success! after looking further into the issue, I found the solution here:

http://stackoverflow.com/q/2194808/399105

although what frustrates me the most is I never saw any errors related to the debug certificate.

of course, wanting to know the details, I ran the keytool command on my backup of the old keystore (the keystore password is "android"):

keytool -list -keystore ~/Desktop/android-backup/debug.keystore -v
Enter keystore password:

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

Alias name: androiddebugkey
Creation date: Jun 3, 2010
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 4c07f835
Valid from: Thu Jun 03 13:45:09 CDT 2010 until: Fri Jun 03 13:45:09 CDT 2011
Certificate fingerprints:
MD5: 49:56:C0:A8:02:9F:38:97:81:D1:22:BA:F3:50:17:23
SHA1: 3D:E8:57:A1:87:97:45:EA:AD:E2:03:66:29:3A:36:DE:9F:F5:35:43
Signature algorithm name: SHA1withRSA
Version: 3


...and there's my exact problem: it looks like the debug certificate generated by the Android SDK is only good for a year.

oh well, at least I'm back in business :)

Edit:

argh, I just ran into this again, but it took me a while to find it because this time the error was "Your project contains error(s), please fix them before running your application." selecting the project, then going to Window --> Show View --> Problems gave me the error "R cannot be resolved to a variable". gotta love these detailed errors...

well I shouldn't run into this again because Google's changed it so now my debug certificate is good for 30 years :)

Wednesday, June 1, 2011

nullege.com: search python source code

the title sums it up pretty well. I know you can find just about anything using google, but supposedly nullege.com is a little smarter when it comes to python. it's a cool idea, at any rate. I haven't had a need to try it out yet, but I'm sure I will before long:


http://nullege.com/