Here is a simple but powerful way to use Python to search and find all files with a specific extension within a given folder and all of its sub-folders using os.walk(). I use it a lot to find map documents with broken data sources, images that need to be organized or just to get a quick count of certain files in a directory.
directorypath = raw_input("Enter a directory path: ")
extension = raw_input("enter an extension: .")
#Loop through all folders and subfolders in your target directory.
for root, dirs, files in os.walk(directorypath):
fileList = [os.path.join(root, f) for f in files if f.endswith(extension)]
for item in fileList:
print item #or do something else with each file found.
The county I work for had a one page geography quiz with outdated questions and a poorly structured user interface. It was just an unstyled list of select dropdowns and a submit button. The answer page that was returned just listed each question with all the answer choices under them. One answer under each question was highlighted in yellow but it wasn’t made clear to the user whether this was the correct answer or just the answer they chose.
To compound things, the quiz was stuck in an enterprise CMS that gave it a really ugly url. I wanted to change that so it would look good and be really easy to understand. Thankfully I wasn’t restricted to any particular language or technology stack to build the new quiz.
A few years back I had played around with Django and thought it was a cool framework but I had never really applied it to any project. So I said to myself “why not?” and set out to build a new geography quiz app with Django. Over the next couple of days I put together the components of the new application:
A PostgreSQL database to store the questions and answers
Models to define the data in the database
Views to process and send the data and to route user answers to the answer page
Templates to render the data
Everything seemed to be going along smoothly although I wasn’t very happy with the way I wrote my views to handle the user submitted answers. The app basically builds a form on the fly (questions with radio button answers) then does a POST when the quiz taker clicks the submit button. The view then takes the POST data and turns it into a Python list. The rest of the view just slices and dices the list and uses offsets to pull out the matching questions and answers.
I know there are cleaner ways of doing this. Especially since the returned POST data is a querydict object which is basically just a Python dictionary. Manipulating key/value pairs seems neater. But the way I did it worked and I got it up and running fast. Maybe a project next time I’m bored will be to make the code cleaner and more maintainable.
Remember earlier when I said that I asked myself “why not?” when considering using Django? Well, I was about to answer that question and the answer wasn’t pretty.
While I was developing my quiz app I used Django’s built-in server which is a lightweight “please don’t use in production” server. It worked great. Then I decided it was time to port the app to my production server and actually use it in the real world. At that point I remembered we use IIS on a Windows server.
IIS isn’t all bad, especially if you work in a place that uses .NET components heavily which I do. Unfortunately, Django was never really developed to run on IIS. Django was really designed to live in a Unix world and be served out with something like Apache. I remembered that from my prior experience with the platform – I just forgot.
There are several tutorials on the web (most of them several years old) that discuss running Django under IIS but none of them were very straight-forward. The solution that seemed like the quickest route to a running app was to use Helicon’s Python Hosting Package (part of the Helicon Zoo repository available through the IIS Web Package Installer). The hosting package basically loads all of your dependencies and does all of the complicated work of getting IIS to run an antagonistic technology. You then load a Python Project module which builds everything for you including:
A virtual Python install specific to your app
A web config file with needed environment variables
Permissions and application pool settings
The only pain point I had with using Helicon’s solution was discovering it doesn’t work with Django 1.7. I had developed in 1.7 and then when I migrated into the Helicon environment everything broke. This really threw me for a loop for a while until I found a post suggesting using Django 1.6. This didn’t turn out to be a big deal as it didn’t affect my apps functionality. I just had to remove a couple of middleware classes from my settings file and I was good-to-go.
I love working with Django. If I wasn’t in a Windows environment I might be trying to use it throughout my office GIS site. But I can’t see trying to force uncommitted technologies into a relationship they don’t even seem to want. I guess Django is just going to be a hobby framework for me for now. Fortunately there are plenty of others out there just waiting to be learned and implemented.
A couple of months ago I started searching for “the best” code editor for web development. I wanted to see what was out there and how it compared to what I have used and was currently using.
Since most of my co-workers live in the .NET world I have access to Visual Studio, which I actually like as an IDE. I’ve used it to do a good deal of development over the last couple of years. But I wanted to explore more of what was out there for code editors that might be more lightweight, fun and available wherever I might want to use it (work, home, on the road…).
For web and desktop work at home I’ve used Notepad, Notepad ++ and Aptana and have never been really happy.
Notepad ++ actually works really well but I hate the interface (it’s boring and ugly rolled into one). Besides, it would be nice to use something platform independent for portability. On the plus side (sorry), in Notepad ++ you can configure styles and keyboard mappings and there;s a lot you can do with the preferences to make things work the way you want them to.
That’s actually the story with the majority of editors and IDEs out there today. Most of them have customizable settings and functionality either built-in or available through plug-ins or extensions. Some of them are geared toward specific languages or uses but most of them seem to handle the most common languages.
No Magic Bullet
I’ve come to the conclusion that there is no “best” editor. There are only ones with fewer annoyances than others. Out of the editors I have been trying lately there are a few I have only used for a few seconds (like Atom) and some I’ve done some heavy lifting with (like Sublime Text). My favorite so far has been Brackets, the open source project from Adobe.
I really like the look and feel of Brackets. It has a nice flat design. It doesn’t overwhelm you with controls and menus. But that led me to pause and question – where are all the controls and menus? It turns out, a lot of your customizations are done directly through json files or through extensions. That’s great because I love working in json.
Changing the keymap is not as straight-forward as most code editors and IDEs but it is intuitive and simple. You just have to override the default mappings in the keymap.json file. I set up my block and single line mappings because the defaults almost always annoy me.
Brackets really shines with its extensions manager. This is where you can install/uninstall user created extensions or Brackets themes. You can also search Github for extension, download the zip file and drag the zip right into the extension manager. It only took a few minutes to search for and install a few extensions to make development easier. These included Grunt, indent guides, code folding and code beautification(formatting).
I have notices some of the extensions can slow Brackets way down so that’s something to watch as you’re loading new ones up. Now I’m just looking for a reason to create an extension of my own or some reason to hack Brackets itself.
I had a ArcGIS user that I support come to me with a corrupted shapefile the other day. It had the old “number of shapes does not match number of table records” error. It turns out, he’s still using this shapefile as his layer’s main data source and he and several others regularly edit it! In this day and age?
I tried to convince him using a file geodatabase would be more stable for editing but he had been using shapefiles so long I don’t even think my comments registered. He just wanted a tool that could fix the shapefile.
I pointed him to the shapechk tool by Andrew Williamson. I’ve used the tool for years because <sarcasm>for some odd reason</sarcasm> I often run into people with corrupted shapefiles after people edit them over long periods of time. The shapefile works OK as a data exchange format but doesn’t always hold together under regular heavy use.
In the words of Pete Seeger, “when will we ever learn?”
With Linkedin allowing background photos for your profile you now have one more way to express yourself creatively on the platform. But Linkedin isn’t Facebook. It’s a professional network and is typically understood to have professionally presented profiles. Having a clean, flat layout with a simple blue and grayscale color scheme has helped keep Linkedin profiles in line with that strategy.
Before background photos the worst offense a user could do visually was insert Homer Simpson as their profile picture. Now we are given the power to screw up a much larger portion of our profile’s real estate.
Is it worth possibly reducing the professional look of your profile just to “express” yourself on one more social channel? Or is it worth the time and effort it will take to produce an image that will still project the professionalism that a plain background already does? The answer to both of these questions is – probably not. I doubt that a connection, employer or recruiter will give a second thought to your profile header not having some sort of graphic behind it. A good head shot as your profile picture will, however, still be expected.
But that doesn’t mean that you absolutely shouldn’t use a background photo. If an image is well thought-out and conveys important information upfront to someone viewing your profile, it could be very worthwhile. Putting in a picture of balloons, sunsets or your dog will probably only serve to distract viewers. However, a picture of you speaking at an event gives the impression that you’re an expert in your field and have experience with public speaking. Likewise, a picture of a map might strengthen the profile of a cartographer or GIS professional.
When someone views your profile, your title and profile picture are usually the first things they see. As we all know, first impressions can make a real impact. If you can influence that first impression positively, then the extra profile eye-candy could be an asset.
I’m still on the fence about whether to put a background photo on my own Linkedin profile page. At this point in time I think Linkedin background photos are a bit of a risk for both Linkedin and its users. While profile customization can make your page look nice, it also runs the risk of making it look like a wannabe Facebook page. That’s not in keeping with the feel of Linkedin. If you do decide to add a background photo, keep it simple and above all, relevant to the rest of your profile.
There are those moments when you realize that certain sports just aren’t worth it. I spotted this encouraging sign in a pile of old junk while hiking a local ski resort in the off season. It does encourage me not to crash but mostly by convincing me not to take up skiing.
I wonder how long it took for someone to realize that instilling terror in your patrons isn’t a good marketing ploy.
I’ve installed a lot of Python packages over the years using Distutils, SetupTools/easy_install and PIP. Distutils is Python’s built-in package distribution module and is pretty easy to use. However, it has some limitations, primarily that you have to manually download the package dependencies and there is no method to uninstall packages.
The Setuptools easy_install script takes care of downloading packages and package dependencies but still lacks certain features you would want from a fully functioning package manager. It doesn’t provide version control support, package tracking and uninstallation. There is a lot more to the Python package discussion but there is no point in bringing it up.
Anyway, while I use package distribution tools I rarely have to install the tools themselves since they only get loaded once. When I do have to set up a new machine or upgrade someone elses, I always forget the steps to get Setuptools and PIP installed. So I thought I would document the steps here. Now I just have to remember to come back here when I need them.
1. Right click on this ez_setup.py link and save the file to your Python Scripts folder (If you have ArcGIS loaded you will usually find this at C:\Python27\ArcGIS10.x\Scripts).
2. Open a command prompt and change into the SCRIPTS directory.
then hit enter to execute the code. This will run the script which will download and install setuptools on your system.
Click here to see an example of a custom Google Map style.
The International Association of Antarctica Tour Operators is cautioning all potential travelers to Antarctica who pine to fly a drone to check with their travel agent or tour operator before packing their device. Jennifer Harper – The Washington Times
Tourists are pining to fly drones in Antarctica? What kind of tourist pines to fly drones in Antarctica? The bigger question is who uses the word pining anymore?
Tidings of a new browser coming from Microsoft have some wondering whether IE is on its last legs. The sad news is that there are still so many old versions (7, 8 and 9) sitting on millions of computers, and their users don’t know any better. So even if Spartan, or its children, eventually displace Internet Explorer, front-end developers will be playing patty cake with old versions for years to come.
It’s interesting that Microsoft is coming out with a brand new browser when IE11 has so many improvements and seems much less maligned than its older versions. Makes me think maybe this is just the start of a rebranding effort.