All posts by Josh

Today: Nov 30, 2014

Break was this week but unfortunately, that week of calmness and relaxation comes crashing down tomorrow morning when I have to hike back to campus for my morning class.

Monday, Tuesday afternoon and Wednesday I got to actually spend some hours in the office. I spent my time fixing some bugs, rewriting tests and finally learning how to make a basic DSL with Ruby. Thursday was nice, filled with good food and wine, and lots of driving to get to all the sides of the family. Friday and Saturday were spent sipping whiskey and watching movies while working on more Ruby DSL stuff.  The more I work with Ruby the more I’m starting to love it more than I love Python… That being said my Python stuff has been suffering for Ruby recently. Maybe I should update some things and write some Python code for a change…


On an unrelated note, today I stood in front of a mirror. How exciting.

I stood there, neck and cheeks white with a thick lather of shaving cream. The sink was half full and the water had tendrils of steam coming off surface. Sitting on the counter to my left was a black mug with a round stub of a handle filled with a Sandlewood shaving cream lather; The light wood handle of my badger hair brush poking out over the brim. In my hand, a small metal shaft topped with a curved bar and head; A Merkur 34C. Clamped between them sat a SuperMax Stainless steel double edge blade, used three times.

My safety razor, or also commonly known as the double edge razor, is perhaps one of my most valuable possessions I have, and one of my most worthwhile investments. Not because its expensive or will be in the future, in fact it was one of the cheapest razors which fit the criteria I was looking for and is fairly common, but because it forces me to have time.

Before I bought this razor I had only ever shaved with an electric. It took a whole 5 minutes each morning; The downside was that it had to be charged once in a while. Even if I was in a hurry and needed to shave, sometimes I just couldn’t because I forgot to plug it in the night before. Its also big and bulky and I never found a good way to hold it even after a good 4 years with it.

Last summer however, something happened that would have an enormous impact on my life: A friend finally convinced me to take the plunge and buy a safety razor. I’d known about them for awhile and always admired the simplicity of them but never could get myself to buy one. But after hearing him talk about his and having him recommend a good list of needed/helpful materials and introduction videos I jumped ship on electrics and bought a good $150 worth of shaving material.

I ended up with: a Merkur 34C, two soaps, 50 blades consisting of 25 brands, a lather mug, a badger hair brush and a RazoRock alum block. I went with the 50 blade pack because it gave me two blades per brand. I figured that each blade could get about 3-5 shaves from what I had read, and as a result I could split the 50 blades up to 25 blades per soaps, since I also got two different soaps (so far this has been an awesome idea and really opened my eyes to the differences in both soaps and blades).

The first noticeable benefit is the shave. Its smooth, clean, close. It feels good to have the blade running across your skin. The second is that the soaps, if you have fragranced soaps that is, leave your face smelling amazing. Baby smooth shaves, or BBS’s as they’re commonly referred to within the safety and straight razor community are easy to get, and last all day: I tend to grow facial hair at an alarmingly fast rate and so commonly I’d find myself going over with my electric before a night function, but with the safety razor I get go a good two days between shaves.

But all of this isn’t way this what makes this razor an amazing investment. Its the time. As it turns out, safety razor shaving takes a fair deal of time compared to electrics. Its not something you can rush, or at least I can’t, without fear of razor burn or lots of nicks and cuts. A good clean and close shave of my whole face and neck takes upwards of 45 minutes. Sure you can go faster and sure I’m just taking my time, hell I can get the same shave in about 15 minutes if I really put my mind to it.

But its that time that makes this a great investment. I have to shave, I’m not one of those people that can grow a neck beard for 5 weeks at a time. Even if its winter time when I grow out a beard, I still have to shave it to clean up the edges and keep the beard defined. As a result, I now have to force myself to slow down and make time. I set aside 2 hours ever couple of nights to take a nice long hot shower followed immediately by shaving in the still steam filled room.

I get to think, I have to think to prevent myself from being bored. The shower helps relax me and has the added benefit of opening my pores and preparing my face for the shave. I have a ritual that I go through: I get the blade in my razor switched out if its an old blade, then I get in the shower and let hot water run down my face and neck. I shampoo once, apply conditioner to my beard, soap down my body then wash the soap and conditioner out. I get out and only dry off my feet, then wrap the towel around my waist and allow the rest of my body to air dry while I shave. I turn the sink faucet on to hot and let it run while I get my face cloth. I then use the hot water its now putting out to partially fill my mug which I place my brush into to soak up some moisture before making the lather. I then fill the sink basin about half full and place my face cloth in it to heat up. I also take the time to place the head of my razor into the water for a few seconds to get the metal to warm up a tad. I then proceed to open the lid on the cream that I choose, pour out the water from the mug and shake the excess water out of the brush.

Its a science; A measured, calculated and timed process that is repeatable and consistent across nights. Its so meticulously laid out and planned that I have an enormous amount of time to think. The actual shave requires me to be relaxed unless I want to risk cuts, something which the slow process and the shower help with. Between these two, I get to have a rare chance of being at peace for a short while, which for me is no easy task these days.

Its this piece of peace that the razor gives me that makes it so valuable to me, and I appreciate that.

Today: Nov 23, 2014

It is *REALLY* cold outside right now.

Also this weekend was slightly boring but a nice reprieve from the stress of a typical school weekend. Thank goodness its break for a week.

Man I really hope the weather doesn’t turn nasty between now and tomorrow morning when I leave for work. That would just suck. *note to self: buy winter tires for Subaru*

Today, Nov 21, 2014

I think I might try to get back into this whole blogging thing… Maybe…

We’ll see.

I find blogging interesting but for some reason I can’t ever hold myself accountable to be being regular with it. But really, it is interesting. Speaking your mind talking about some subject, maybe just writing down a string of random thoughts. Or maybe you take one thought and write about it in a bit more detail? I do this a lot with friends, but that is (to me) different from blogging. On a blog such as this, who is my audience? Some posts are technical, some are personal. Who am I speaking to when I type these words into this screen? What’s the point of even doing so? Is anyone going to read this? Will it change the world? Someones day? Maybe its just a thing for me. But then, why publish it publicly? Who knows.


 

Being an american, are you suppose to feel any different when you finally turn 21? Everyone around me acted like it was a big deal, but the way I see it, the only major difference is that now I can stock my own liquor cabinet rather than having to pay someone else to do so. I’ve been 21 for a week or two now and really… I don’t feel it. I don’t feel old. I don’t feel like I’ve been on this earth 21 years now.

I walk around campus and see all these people, who every year more and more are younger than me, and think “Why can’t I be older, like them?” I see myself as a young child running around in a foreign world, not a college student who only has another year before he graduates and gets turned loose on the Real World™. That being said, I do often think that, on the outside at least, I tend to be slightly more mature than most of my peers.


 

I woke up did my normal shower and eat breakfast routine then headed to campus. While walking I got stopped by the regular morning train, and today one of those train cars had some nice reassuring graffiti on the side of it that said “I’m Jacks wasted life…”

After having getting a small giggle from the graffiti, I went to my single class for Fridays, Digital Circuit design and theory or something like that, and ended up having a pop quiz. I feel kind of bad because half the class was gone because its the Friday before our week long Thanksgiving break. Some poor soul walked in with 5 minutes left in the class and the professor just said “You want to try? You have 5 minutes. If not, have a good weekend.”

Dang. Like, I know its partly the guys fault; who comes to class with only 5 minutes left in it? But still, I found it slightly harsh.

After that I did my normal 1.5 hour drive into work, during which time I passed the Batmobile. Only, it wasn’t your normal Batmobile because obviously Batman was trying to be incognito, as said Batmobile was disguised as a 2002 Ford Mustang…

Also there was this older lady on my way back home who was a decidedly giant dick. Seriously, she was a horrible driver and she should feel bad…


Nearly everyone I know says I shouldn’t take work home with me. Thinking about it now however, thats rather hard to do since I work remote most days of the week, since I normally can’t afford 3 hours of time for just driving to and from the office. But, as I sit here I’m taking a break from programming. However I wasn’t programming for work. Although, yes, I was working on a project which is helping me learn all the things about Rails, since work has for the most part changed from a Node.js to a Ruby on Rails gig for me. Does that mean that I’m still working in some capacity?

This tends to be a big problem for me. Mostly with programming stuff. I start learning about something in class or work on something at work or throw together something for a friend and suddenly I find myself completely engorged in the subject and learning as much as I can handle. Then after about a week of it, I tend to burn out on that branch and start researching and messing around with a new thing. Sometimes however it leads into a full-on project, transientbug got started this way. So did my RethinkDB Orm wrapper for Python (speaking of which, I should probably rewrite that and update the PyPi package… someday. Someday).

Currently I’m running through rails. I built a little thing to replace a spreadsheet that I have. The spreadsheet is basically just a review of shaving blades, each time I use one in my safety razor. The app was my first foray into Rails and the first major thing that I did with any Ruby code. I did it because I learned that I was going to be working more on Rails stuff for work since the Node.js stuff was moving towards the back burner. Since then I’ve taken a break from the Python world and have tried to stay fairly into the Ruby and Rails worlds.

I’ve also started a new Rails app. With the help of some RailsCasts videos and applying my knowledge from the Python web framework world I rolled my own authentication, added role base authorization and am now rolling a conversation thread system. It should, when finished, act a little like google hangouts or something where you have a many-to-many message platform and each person can enter and leave groups and have a “read up to message #” sort of thing. We’ll see how well it goes, since I just started working on it earlier tonight after getting back from work.


Those oreos I just ate were pretty good. I needed them. Needed, obviously.

I should go across the street to the liquor store one of these days and buy some cider and maybe some vanilla porters…


Dang… 1017 Words in just a short while… WELP. Thats been today.

One of these days

Every time I open this blog, I always tell myself I’ll write a new blog post or something. Then I’ll write one, and say something like “Oh yeah, I haven’t updated this for a year…”

Welp. Looks like this is another round of that.

On an unrelated note, one of these days I’ll post a how to on a rails topic that I struggled with a while back: I wanted to only have application and the controller specific js and style sheets included on each page load, and I didn’t want to use turbolinks (I’m sorry, but no, I just won’t right now). It’s pretty easy but it does need a few steps to get things working properly so I might as well do a write up.

Maybe some day I’ll actually have interesting content on here too…

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 Busy Little Bee

Pawnee Feature Image

Pawnee

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

Flash and Light Painting Featured Image

Adventures with external flashes and light painting

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!

Python Decorators Featured

Intro to Python Decorators

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("/(.*)/")
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() + "")

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") #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("/(.*)/")
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.” N.p., n.d. Web. 14 Feb. 2012.
Learning Python. N.p. Web. 14 Feb. 2012.
Python in a Nutshell. N.p. Web. 14 Feb. 2012.
“5 PEP 318: Decorators for Functions and Methods.” N.p., n.d. Web. 14 Feb. 2012.
“PEP 318 -- Decorators for Functions and Methods.” N.p., n.d. Web. 14 Feb. 2012.
“Nice Python Decorators - Stack Overflow.” N.p., n.d. Web. 14 Feb. 2012.
“Python - Preserving Signatures of Decorated Functions - Stack Overflow.” N.p., n.d. Web. 14 Feb. 2012.
“9.8. Functools — Higher-Order Functions and Operations on Callable Objects — Python v2.7.2 Documentation.” N.p., n.d. Web. 14 Feb. 2012.
{Web: PyTe} Featured Image

Web PyTe Podcasts

{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