Tag Archives: programming

Owned by StackOverflow's design

#programming    #oopsies   #stackoverflow  

So, it's fun when you find a question on StackOverflow that is the same question you're looking for an answer for.  You see the accepted answer and start working on that.

A little while later you realize the question asker accepted the wrong, or least optimal, answer and the very next answer, which has way more votes, is just off the bottom of the screen since the accepted, not most-up-voted answer is always at the top.

Google+: View post on Google+

woofi, a location-aware WiFi switcher for Android devices.

Woofi

My most recent project is an app called woofi.  Let me quote the apps description from its market page:

Simply put, with woofi you define locations like “home”, “work”, or “Joe’s house”, and woofi turns your WiFi radio on when near those points and off when not.

More detailed explanation:

Say, for example, that the only place you connect your phone to WiFi is at home. This means you don’t need for the WiFi radio in your phone to be on when you’re not at home. The rest of the day it’s just sitting there trying to connect to access points and wasting battery.

With this app you would save your “home” location (and wherever else you connect to WiFi regularly…like at the office), and the app would keep track of your location throughout the day and when you weren’t near these saved locations turn your WiFi radio off, and then when you were near them it would turn your WiFi radio back on.

You can, of course, simply turn the WiFi radio on and off manually when you are at-home/not-at-home, the only purpose of this app is to automate doing this for you. I always forget to do this manually…thus the idea for this app.

Most people seem to leave their WiFi on all the time and not realize that it’s on because it just connects to networks that they’ve connected to before automatically.

Here’s what normally happens without this app: Once you’ve connected to your home (or office, or wherever) WiFi, Android will just connect to your home WiFi every time you’re in range. The only way it knows to do this is because the WiFi radio in your phone is on all the time looking for WiFi networks to connect to.

This app replaces that procedure by checking your phones location and leaving the WiFi radio off unless it is needed. Doing this saves battery life.

Coming soon expect some posts about the logic and trade offs made in the development of this app.

Android Application Development for Dummies

I’ve been working through the book Android Application Development for Dummies and noticed a little problem on page 182, paragraph 3 where it states:

At this point, you can install the Silent Mode Toggle application, long-press the home screen, and choose the Widgets category; now you should see the Silent Mode Toggle present.

The problem is that this isn’t true.  It’s not till the next page where you edit the AndroidManifest.xml file will you be able to see the widget.

Hopefully, this helps anyone getting frustrated trying to get the widget to show up!

On a related note, the author, Donn Felker, has been very responsive to emails about this issue.  He even offered to take the time to go through the code I’d already written.  I’ll definitely be looking for other books by him because of this.  Thanks Donn!

Soundswitch source on Github

If anyone is interested in hacking on the Soundswitch source, you can find it on GitHub.  Be sure to submit a pull request back to me if you make any changes!

Apple Trailer Downloader

This isn’t currently working because of changes to Apple’s site. I hope to fix it before the end of the year.

I wanted all the movie trailers from Apple in the highest resolution available (1080p for most of them), so I wrote this script in python to fetch them all.

Usage

Update: I wasn’t very clear about this before. ATD keeps a database of what it’s already downloaded, so each time you run it, it will just download everything you haven’t downloaded yet.

This works through the command line in a very simple manner.

I’ll start out with some examples and then provide a full option list.

The following example will download 500 megabytes worth of trailers and save them to C:\Trailers.

atd -l 500 -d "C:\Trailers"

The next example will do the same and also append “-trailer” to the filename and change the extension to “.hdmov”.

atd -l 500 -d "C:\Trailers" -a "-trailer" -e "hdmov"

If there is a certain trailer you would like atd to download again (say you deleted the trailer on accident), you can call it as follows. The one downside to this method is that all this does is tell ATD to not skip this trailer when processing the trailer list. If it doesn’t make it to the movie because you’ve used the download limit option it won’t download it again. Changing this behavior is on my todo list.

atd --redown "Iron Man 2"

If you want the maximum resolution it downloads to be 480p you do it like so:

atd --respref "480p"

To get help you do this:

atd -h

Which will ouput:

Usage: atd [options]

If no options passed, it will download all not already downloaded trailers to a
subdir called Trailers.

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -l MB, --downlimit=MB
                        Approxmiate megabytes to download per session
                        (default: 0)
  -d DIR, --dest=DIR    Destination directory. (default: Trailers)
  -a TEXT, --append=TEXT
                        Appends the specified text to the filename. (default:
                        -trailer)
  -r, --rename          Rename trailer with movies name.
  -e EXTENSION, --ext=EXTENSION
                        Changes file extension to what is specified
  --redown=movie name   Redownloads the trailer for the specified movie.  Ex:
                        --redown Iron Man 2
  --flush               WARNING: This option deletes your download history
                        which means that all trailers will be downloaded again
  --respref=RESPREF     Get specified resolution or less.  Options are
                        ['1080p', '720p', '480p', '640w', '480']
  --reslimit=RESLIMIT   Get specified resolution or dont get trailer at all
  --mdate=DATE          Only get trailers for movies with a release date after
                        this. (format: YYYY-MM-DD)
  --tdate=DATE          Only get trailers released after this date. (format:
                        YYYY-MM-DD)
  --fake                Don't download, just print list of movies it would
                        download trailers for with the specified commandline.
                        (Ignores download limit)
  --htenfo              Writes an nfo file for use with the Home Theater
                        Experience XBMC script.
  --imdb                Fetches missing information like MPAA rating from
                        IMDB.  (Slows down parsing)

Please report any bugs or feature requests you may have. This script is dependent upon how Apple presents it’s trailers on the web. If they change the correct (or incorrect depending on how you look at it) things this script will break. I’ll do my best to keep up with such changes.

Newest Version

Version 0.2.2 is here.

Source

ATD is now on github.

Older versions

Version 0.2.1 is here.

Version 0.2 for Windows users is here.
Version 0.2 for Linux users or users interested in the source can get it here.

Version 0.1 for Windows users is here.
Version 0.1 for Linux users or users interested in the source can get the source code here.

Planned Features

Rolling updates

With this feature, ATD will be able to keep a folder full of only trailers for movies past a certain date (for example, only trailers for movies that haven’t been released yet).  It will remove trailers for movies before the date and add/dl trailers for movies with new trailers.

Known Bugs

  • With --imdb, ATD fetches info for all trailers even if because of other options like --downlimit we’ve limited the number of trailers that will download.
  • Funkiness with --redown.
  • Unicode handling is currently a hackjob.

MySQL and Python 2.6 on Windows, Redux

As I noted before, getting a version of MySQLdb that works for Python 2.6 on Windows is an exercise in frustration.  Until now.

An anonymous commenter on the previous post pointed to a web page with instructions for compiling MySQLdb with Visual Studio.  This was quite the salvation to me as I have no experience with Visual Studio or really any sort of compiling on Windows at all.

The only thing lacking in those instructions is the bit about “vsvars32.bat”.  It says:

make sure “vsvars32.bat” exists in “C:\Program Files\Microsoft Visual Studio 8\Common7\Tools”

That’s the last mention of that file.  The problem is that you have to actually run that batch file prior to compiling.

The only other adjustments I had to make were to account for the fact that I’m using Visual Studio 2008 which has a different path than Visual Studio 2005.

All that resulted in my own Windows installer for MySQLdb for Python 2.6.  This was compiled on Windows 7 64-bit, I’m not sure how it’ll work on other operating systems, but if it doesn’t work for you make a comment and I’ll see if I can compile a version for your environment.

Download it here.

A hotkey to switch between headphones and speakers. Soundswitch.

I use USB headphones. I also use regular speakers connected to my sound card. Windows makes it a multi-step process to switch from headphones to speakers.

I tired of this, so I wrote a program to rectify the situation and I called it Soundswitch because I’m a wordsmith. You can find this program here:

Available here.

Basic Use and Installation

Unzip it to the directory of your choice.

Look in the Sound applet in control panel to see which two sound devices you want to switch between. In the following image, the two I switch between are labeled 1 and 4. Thus, in the ini file, I used 1 for Source1 and 4 for Source2.  Update:  Note that the number of items will vary based upon whether you have “Show Disabled Devices” and “Show Disconnected Devices” checked (Right click anywhere in the list to see these).  For the purposes of Sound Switch make sure both options are checked before counting the items. The screenshot below doesn’t reflect this.

sound_panel

The ini by default has the switch key assigned to Ctrl-Alt-F12. Edit this as you like.

Tested on Win7 x64 and Vista x32.   Update:  XP no longer works with the latest updates.  Use this older version for XP compatibility:  soundswitch

Any comments on this are welcome and I’ll try to fix any bugs reported.

Version 2 Notes

I’ve added a good number of features in the latest version. All accessible through the .ini file.

  • “Scroll” through each enabled item in your Sound panel.
  • Hide the tray icon
  • Switch between two speaker configurations for your current active playback device
  • Switch/scroll just the default comm device, default playback device, or both
  • Hotkey to terminate the program

JSON feed for Source servers

I’m kind of a statistics whore.

To further my pursuit of more statistics, I’ve developed a Python CGI which provides a JSON feed of all sorts of information about servers based on Valve’s Source engine.

This script has three dependencies outside of what is in the standard Python library:

Once you have those installed (worst-case scenario just drop them in the same directory as sourcejson.py), you need to edit sourcejson.ini.  This file just has three options: rcon_pass, ip, and port.  If you don’t have the rcon password for the server you wish to monitor just leave it blank.

To access the JSON feed just use the url to sourcejson.py.  Something like this:

http://YOUR_DOMAIN/sourcejson.py

To access the extended information that having an rcon password allows use:

http://YOUR_DOMAIN/sourcejson.py?info=extended

If you use the extended format, but haven’t provided an rcon password in sourcejson.ini, it will just default to the basic feed.

Included in the zip is a .htaccess to prevent directory listings, which will help protect the contents of sourcejson.ini.

Download sourcejson here!

Using Python 2.6 + MySQL on Windows is nearly impossible

Update:  I made progress on this issue.  See my newer post here.

If you’re interested in writing Python scripts on Windows which access MySQL databases, be sure you avoid Python 2.6.

The standard way to interact with a MySQL database via Python is to install the mysql-python package The problems arise because of several things.

  1. mysql-python still doesn’t have compiled binaries for 2.6
  2. Windows doesn’t ship with a C compiler.
  3. It’s a SOB to use any of the free C compilers to compile from source.

A couple of kind souls have provided their own compiled versions in this forum thread, but neither of the provided versions works on the two Windows machines I’ve tried them on.

I tried following the official directions to compile on windows using the “setup.py build”-method, but MinGW spits out several bajillion lines indicating the following(bolded part indicates error found over and over again):

C:\Program Files (x86)\MySQL\MySQL Server 5.1\lib\opt/mysqlclient.lib(./mysqlcli
ent.dir/relwithdebinfo/inftrees.obj):(.text[_inflate_table]+0x4e3): undefined re
ference to `@__security_check_cookie@4′
collect2: ld returned 1 exit status
error: command ‘gcc’ failed with exit status 1

There’s very little useful information to be found from a google search on this, so as it stands, I’m pretty much unable to use Python 2.6 + MySQL.

I really wonder why MySQL support isn’t packaged with Python.  It’s not like accessing MySQL is an unheard of operation…

Automatic MP3 organization using AutoIt

Somebody on the Something Awful forums asked me about my code that automatically organizes MP3’s I download, so here’s how it works…
Read more »