Friday, August 9, 2013

Building a portable scripting environment, Part 1

As I've gotten tired of bouncing back and forth between machines, each having its own inconsistent development framework, I thought it a good idea to go ahead and create a single development environment that I could carry with me on a thumb drive.

This will look different for everyone, but here's my checklist:

Gotta-have's

  • Python (both 2.7.x and 3.x)
  • Git
  • XAMPP
  • Notepad++
Nice-to-have's
  • Eclipse w/ PyDev
  • Cygwin (or some other decent shell replacement)
  • Some form of GUI interface for GIT (a'la SourceTree, preferably)
  • PowerGUI or some other handy PowerShell IDE
  • AutoHotKey

Tonight, the Must-Have's...

First, Python. Thankfully, this one is pretty easy, with Portable Python having both version 2 and 3 available, and pre-packaged for portable use. The downloads are pretty large, and the installation takes a while when you install directly to a USB drive, but they come bundled with a lot of handy libraries, so it seems worth it.

As a sidenote, I see that Portable Python also comes packaged with PyScripter. I've never used this, personally, but if it's a decent enough IDE for my purposes, I may forego the Eclipse portion of my list and just stick with that.

Getting Git is also pretty easily handled, since msysgit releases portable versions - typically - alongside the desktop versions. Pick up the latest portable version from the download page, and extract onto the drive.

There's some config yet to do here, though, in order to truly have a portable version. This blog post covers it pretty well, so I'll skip the details here. If you're already familiar with the basic process and just need a refresher, you'll want to set your home directory to a local path within your git directory (I used /home/jeremy), set up your SSH key(s), and update your .profile to load ssh-agent for you, so you don't have to type your SSH password every time you use a git command that touches a server.

For those who aren't familiar with XAMPP, it's a bundle of Apache, MySql, Php, and Perl, for web development. I'll be using the Windows (WAMPP) bundle, available at the Apache Friends website.

Next on the Must-have list is Notepad++, my text editor of choice. It's already present on most of the systems I use, but on the off chance that I wind up working on a new/temporary machine, it'll be nice to have. Download the current version's .7z package from the Notepad++ website, and extract to your drive.

Once installed, create an empty file called doLocalConf.xml, so that N++ loads configuration files and plugins from the local directory instead of looking for them in your Windows user profile. Since I've got a Git Bash shell already open, this is easily accomplished via (my USB drive was drive G when I ran through this) touch /g/Notepad++/doLocalConf.xml.

Now that all of that's set up, I'm going to go poke around in PyScripter for a bit. Next post, I'll see how things went with these apps, and move on to some of the Nice-to-have's.

Use PowerShell to send test email in batches or on schedules

Recently, I had to test a scenario where an ActiveSync device received a relatively large (70-100) batch of emails in a relatively short (60-90s) window.

For smaller tests of this type, I've set Outlook into Offline mode, created 5-10 draft emails, sent them all, then switched back to Online mode to have them send at the same time. In this case, I wasn't interested in copypasta'ing 70 to 100 times per test, so I did some quick research, and found that Exchange 2010 has a Send-MailMessage cmdlet that ... well ... sends a mail message...

Anyhoo, a bit of Google-fu led me to this ASP.Net forum post. I ran the HTML code in the final reply through a parser, and found a script that pointed me to JFRMilner's Tech Blog. I saw an opportunity to expand that script and add some functionality, and some intense PowerShell scripting later, I had a finished product. You can check it out on Gist.