Busy Little Bee

Oh wow, my last post was about a year ago, Feburary of 2013. Sorry ’bout that.

As it turns out, I’ve been a little busy; University tends to do that to you. The little teenage hacker that use to update this blog has long since (partially) grown up, and I’m now working my way towards a degree in Computer Engineering while still pursuing my personal software related projects. Since I’ve got a year or so to catch up on, I’ll start with those (warning, this post is long and jumps around a bit; don’t be surprised if parts of it seem random or out of place).

Continue reading

Posted in Josh Tagged , ,

Pawnee

Pawnee Feature Image

Pawnee Feature ImageOne of the few things I enjoy is getting outside with my DSLR for a little bit and doing some photography. I don’t always aim for a beautiful shot, or a shot that makes you go “Oh, thats pretty!” Instead I try to shoot what I see and feel at the time. I also try to remember this and to incorporate it into my post processing steps to ensure the photos represent what I was thinking and seeing.

Having moved out and entered the world of university dorm life sadly hasn’t given me much of an opportunity to get out into the fields and take many photos, simply because much of my free time lies in the time frame of midnight to 5am, the time which I prefer to use for sleep. However a few weeks ago I had a day off, and so I, along with a friend, journeyed from the beautiful rolling hills of Fort Collins, to the flat lands of eastern Colorado. If one hops on I-25 and follows it to highway 14 and then proceeds to drive a very very far distance east, one would come upon a sign stating “Pawnee National Grasslands.”

Now at this point, unless you’ve been to the Grasslands before, you may be asking yourself why anyone would want to go to a large plain full of grass to get photos. Well, the answer is: It’s not flat, and theres a whole lot more than grass out there. I’ve been out to places like Kansas, which many people consider a flat and boring world, and I’ve driven through the deserts of Arizona and New Mexico, but I have not been to a place quite like Pawnee. It’s unique and yet so well hidden at times that it’s often hard to imagine that it belongs to the north eastern corner of Colorado. rich in various hidden treasures. It’s large open dirt roads wind through the soft rolling hills, covered with browning grass. I’ve been to places such as Kansas with their rich rolling plains of wheat and corn and other such plants, and I’ve been the barren, dry deserts of Arizona and New Mexico, with their scorching heat, but I have never been to a place quite like Pawnee before.

The biggest features of Pawnee are two Buttes, East and West Pawnee Buttes. But in between these are oil fields and wells, old windmills which have long since been used. There are a number of abandoned structures and utilities. Signs riddled with bullet holes and the town of Grover skirting the border of the Grasslands. Small furry animals may, on occasion scurry past your foot, or a lone bird may fly overhead, but the true beauty of Pawnee lies in it’s geological features. From the top of hills you can see into Wyoming, and potentially the Kansas border. There are exposed rock formations which catch your eye, and numbers of small cliffs and hills each featuring a spectacular 360 degree view of the flat plains of Colorado which lie beyond the Grassland borders.

Watering hole

Bleak

Getting out to Pawnee however, might require some thought. There are only two small towns on the way from Fort Collins to Pawnee, and the last gas station we found closest to Pawnee was a small two pump station with a sign that reads “No gas – Next 60 miles.” To be honest, I didn’t even know if I was going to be able to get gas because I had forgotten cash and the station looked so old that I doubted there was going to be a credit card processor, however luck prevailed and the pumps have the ability to take credit cards. The price here was however, slightly high, compared to downtown FoCo (Was around high $2.80 range from what I saw that day) at the time of the first adventure out to Pawnee earlier in January, the price was $3.00 a gallon.

After getting out there, we started off by looking for the trail head however quickly got lost on the back roads, but that was okay with me because it showed a whole side to Colorado which I didn’t even know existed. The only area that I got fairly good photos from was a small, abandoned watering hole, complete with a jammed windmill and a rusting tank. Here’s the resulting few photos that made it through my processing queue:

Connecting lines

Contrail with the broken side wall

A plane happened to be flying past and I took the chance to align the broken tank wall with the contrail.

Need a light?

A low set sun

Over all, it wasn’t very exciting to be out here, with literally just the windmill and my Subaru, but it brought a new sense of perspective to my urbanized view of the world. It is empty and bleak. Dry and dead. Not much lives out in most of the grassland, except for, you guessed it, grass.

Dead world

Loomix Feed Supplements

Vroom Vroom

Vroom Vroom – Transportation for the day

It couldn’t have gotten much more bleak than this. Small Subaru station wagon and flat land covered with a fine dust.

Next time I head out to Pawnee I’ll be sure to bring with an extra tank of gas, along with some better amounts of cash in case, but this won’t stop me. Pawnee was beautiful. I can’t imagine what it must have looked like, hundreds of years ago before all the oil rigs and gravel roads. Was it fairly similar, or more lush? Was it always this dry, or does it get better in the summer? Non the less, I can’t wait to go back…

Long drive home

Headed Home

Posted in Featured, Josh Tagged , , , , , ,

Adventures with external flashes and light painting

Flash and Light Painting Featured Image

Flash and Light Painting Featured ImageSo this weekend I got a new toy for my DSLR: a Canon 430EXII Speedlight.

Canon 430 EX II Speedlight

Canon 430 EX II Speedlight

So naturally, I had to play around with it. During this time, since I also had my grandparents basement blacked out, I took the chance to try two light painting photos, one with a light orb, and the other just for fun. Heres the results:

First Orb

First Orb

I did this with my little AAA size mag light on my key chain lanyard.

Next up is the fun with the flash. Most of these are in a mostly blacked out room, with the flash firing on ETLL mode (since I was to tired when I took them to manually set the flash power and what not) with the flash aimed at the ceiling or side wall to bounce off and pick up some color.

Dance

Dance

Superman!

Superman!

Frisbee?

Frisbee?

Ball throwing

Ball throwing

Near planking

Near planking

These next ones, I used my new remote shutter release cable. Nothing fancy right now, just an adapter for the camera and an Easter egg stuffed with two momentary contact buttons, nothing fancy yet because I haven’t had time to design and etch and program a fully featured involtometer. the light streak in my left hand is my maglight because the room was totally dark.

Kick

Kick

Second kick

Second kick

Magic

Magic

I’ll do a write up on it all later on, and after I renew my flickr pro account I’ll post them on there, until then: enjoy!

Posted in Featured, Josh Tagged , , , ,

Intro to Python Decorators

Python Decorators Featured
Python Decorators Featured

Python decorators are one of the trickier but useful sides of the language, however I feel like they are often overlooked, so much so that, for example, I didn’t even know what they were until recently. As a result of writing a decorator that would automatically generate a routing URL tuple for web.py, I thought it would be nice to concentrate all the forum questions and blog posts that I used into a short introduction to the Python decorator scheme, not only to help myself understand them better, but possibly pass some information off to others as well.

Introduction

For some inexplicable reason, I haven’t been able to pull myself way from the web.py framework. I’ve looked into the others out there, and have a small list of ones that I would like to do a serious project with at least once, however these projects are always on the back burner.

However there is one part of web.py that I don’t really like, and yet I do like. The URL routing tuple.

Sure it’s easy to use and understand, but really? I don’t want to have to maintain a list of URL’s to route to, and which object name they go with, I want to have the code automate this, so that all I do is tell it to generate an entry for an object, that will be at URL blank. So how do you do this? I have always preferred the flask/bottle way of doing routing, with decorators.

Simply put, I want to be able to simply do:

@route("/(.*)/"Smilie: ;)
class singleFileObject(baseHTTPObject):
    ...

So my journey for the next few hours was set: learn enough about decorators to program a basic one that would do this for me.

Beginnings

Most regular Python guys should be able to pick this up in a heart beat:

def h1(f):
    return ("<h1>" + f() + ""Smilie: ;)

def f():
    return "hello, World!"

g = h1(f())

This is a basic decorator. It simply takes a function f as input, and returns that functions output wrapped in

tags. This is equivalent to doing:

@h1
def f():
    return "hello, World!"

So this begs to question: what can I do with one of these?

Back to Basics

Lets start with the basics. What is a decorator?

They’re in simple terms, a function or object which you “wrap” around another function or object. This allows you to modify the wrapped object on run time, or to modify the incoming arguments to the object.

And… what can you do with them?

Well, for starters, they allow you to do something before a function is called, or afterwards, or you can use them to make sure that a function always gets a specific type of arguments. There really is a near infinite things you can do with a decorator. For my personal use, I learned about decorators to write my own automatic router for my API’s that use web.py. Decorators are also really popular with tool programmers, however I have not seen them quiet as much in application programming. Another common use of decorators, is announcing a function or object to an API so that it may take advantage of the object. This is similar to what my goal is.

Okay, so now lets build this up from the ground to get a feel for how to use and program decorators.

The shortcut syntax for decorators in python is:

@decorator
def f():
    ...
#which is equal to:
f = decorator(f())

From this you can build just about anything your heart desires. You can also chain together decorators:

@decoratorOne
@decoratorTwo
def f():
    ...

#which unfolds to:
f = decoratorOne(decoratorTwo(f()))

But we’ll get to that later. First, lets look at what the decorator function looks like:

def decorator(targetObject):
    return targetObject()

@decorator
def f():
    ...

Lines one and two are the decorator function. What it’s doing is simply intercepting the function f it is decorating on line 4 and then promptly returning it, with no operations or modifications done upon the function. Next up we’ll work with decorators which will intercept and print out the arguments passed to the function being decorated.

Advancing Forward

Now that we’ve looked at the basic decorator building blocks, lets look at a decorator that provides a little more usefulness.

Lets say we’re passing arguments to the function we want to decorate. We’ll write a basic decorator that prints out what arguments are passed, and passes those on to the function. This could allow us to produce a basic logging decorator, or to modify the arguments before they reach the function.

To do this we need to add a second function within the decorator which accepts *args and **kwargs, like so:

def decorator(targetObject):
    def argumentWrapper(*args, **kwargs):
        print "I got args: "
        print args
        print "And kwargs:"
        print kwargs
        targetObject(*args, **kwargs)
    return argumentWrapper

This will go through and intercept all the arguments, both none keyword’ed and keyword’ed arguments and print them out, followed by passing them to the target object or function we have decorated. So now we have a function structure that looks a little like so:

decorated function
    |----> functions arguments

Okay, cool. Now we can intercept arguments passed to a decorated function, then possibly modify them in some way, and modify the function itself, whats next?

Arguing with the Decorator

So now that we can decorate a function, and we have been able to pass arguments to that decorated function, lets look at passing arguments to the decorator itself. As it turns out, this is fairly logical in how its done, however not immediately obvious to some. The decorator function must first catch it’s arguments before it can catch the function being decorated, and that functions arguments, so we end up with a structure that looks a bit like this:

decorator arguments
    |----> function or object being decorated
        |----> decorated objects arguments

So now we can write a decorator function that looks like:

def decorator(*args, **kwargs):
    def wrapper(targetObject):
        def targetArguments(*args, **kwargs):
            targetObject(*args, **kwargs)
        return targetArguments
    return wrapper

Okay, neat trick Josh, but now what? We want to see a live example.

Alright, well I have one right here for you:

def wrapInTag(tag):
    print "Wrapping in a %s tag" % tag
    def targetToWrap(targetObject):
        def targetToWrapArguments(whatToSay):
            print "Saying: %s" % whatToSay
            return ("<%s>" % tag) + targetObject(whatToSay) + ("<!--%s-->" % tag)
        return targetToWrapArguments
    return targetToWrap

@wrapInTag('h1')
def saySomething(whatToSay):
    return whatToSay

>>> saySomething("Hello"Smilie: ;) #run the command
Saying: Hello
'<h1>Hello</h1>' #final result

Here we have a decorator called ‘wrapInTag’ which takes one argument, named tag as defined by line 1. This decorator then takes in a function whose output it will wrap in the given tag, and finally it allows the decorated function to take an input about what to say, and prints it all out in wrapped form when done.

Solution to Beginning Problem

My final solution for the web.py URL tuple problem was to pass a routing regex to the decorator, and use it to decorate the object that I wanted to map that regex match to:

urls = (
    "", "slash"
)

def route(routeURL):
    """
    Router decorator
    Auto adds the decorated object to the url routing pool
    Usage:
        @route(regex pattern)
    """
    def wrapper(HTTPObject):
        global urls
        urls += (routeURL, HTTPObject.__name__,)
        return HTTPObject
    return wrapper

@route("/(.*)/"Smilie: ;)
class singleObject(baseHTTPObject):
    def get(self, **kwargs):
        return json.dumps({"message": "hello"})

Where to From Here?

Well, decorators are pretty powerful. I wrote one that, in 7 lines, generated and appended to the URL tuple in web.py a URL routing regex and which object to route that regex match to, so that I don’t have to manually enter objects into a URL tuple. I’ve seen decorators used for timing functions, logging or debugging. Their true power comes in the fact that they allow you to do such things as debug or log, or time without repeating code, and without changing the code within the decorated object. This is useful when your working with a library object and can not reprogram it, or the solution or code is only temporary.

Works Consulted

Web forums, articles and books used to help write this (and help me understand decorators).

“Understanding Python Decorators - Stack Overflow.” Web. 14 Feb. 2012.
Learning Python. Web. 14 Feb. 2012.
Python in a Nutshell. Web. 14 Feb. 2012.
“5 PEP 318: Decorators for Functions and Methods.” Web. 14 Feb. 2012.
“PEP 318 -- Decorators for Functions and Methods.” Web. 14 Feb. 2012.
“Nice Python Decorators - Stack Overflow.” Web. 14 Feb. 2012.
“Python - Preserving Signatures of Decorated Functions - Stack Overflow.” Web. 14 Feb. 2012.
“9.8. Functools — Higher-order Functions and Operations on Callable Objects — Python V2.7.2 Documentation.” Web. 14 Feb. 2012.

Posted in Featured, How To, Josh Tagged , , , , , , , , , ,

2012 Blueprints

New JoshAshby.com Featured Image
New JoshAshby.com Featured Image

I’d like to welcome you all to the newest rendition of JoshAshby.com!

After 5+ years of moving around from server to server, theme to theme and blog to blog, JoshAshby.com has seen many corners and dark times on the internet, however since the move to a private virtual server from GigaTux/GenVPS, JoshAshby.com now has its first true personal home.

Continue reading

Posted in Josh Tagged ,

Web PyTe Podcasts

{Web: PyTe} Featured Image
{Web: PyTe} Featured Image

Introducing the Web PyTe project podcasts.

I could not come up with an easier way to show the development process behind my high schools capstone than to do a podcast. This is currently only the audio however in the next week I plan on pairing it with video, mainly slides and screen captures from my development
server. But without further ado:

Web PyTe Podcast #1

Posted in Josh, School Tagged , , , , , , , , ,

Arch-droid

Well, after having ran Cyanogenmod 7.1RC for a few weeks, I though it was fit to see about getting some unix tools since I can ssh into my phone.

Continue reading

Posted in How To, Josh Tagged , , , , , , , , , ,

Hello Server!

Welcome to the new JoshAshby.com Server!

I  finally got around to making a memory efficient web server on my VPS so now JoshAshby.com is hosted thanks to GenVPS, lighttpd, php5, mysql, maradns, vsftpd and openSSH. Enjoy!

Posted in Josh

New Theme

Time for the yearly new theme design (some may notice that for the last few weeks, I’ve been running a stock theme because a few features in my old one were being broken) So until I get this theme worked out and going, I maybe bouncing around themes.

Posted in Josh

Photography

Just felt like doing a short thing on why I love to take photos.

Those of you who know me, and have done things like go on hikes with me, or been around me when I have my camera, know that I tend to take a lot of photos. In a week I can do upwards of 1000 if not more (but only a few make it onto flickr, for those who watch my stream).

Continue reading

Posted in Josh Tagged , , , ,