Tuesday, October 18, 2011

How to get Pry to take in multiple commands on the command line (the hack version)

While trying to use Pry (version 0.9.6.2) in a script, I ran into some issues getting to do multiple commands from the command line. The first part was seeing if it could do multiple commands in the first place. It's not obvious, but you can. Since all it does to the -e/--exec option is put a new line at the end and pass it to the initializer of a StringIO object, it means that I should be able to insert a new line in the option and it should perform multiple commands no problem. So I tried the following command against my Rails 2.3 project:
pry -r 'config/environment' --context Class --exec 'show-method method\n exit-all'
After this command, I ran into my first issue, undefined method or variable Class. As I found out that's because it tries to get the binding for the initial context before it loads any of the required files.
Ok, so we can put the context into the exec option:
pry -r 'config/environment' --exec 'cd Class\nshow-method method\nexit-all'
This seems like it should work, but then I receive the following error:
Bad object path: Class\nshow-method method\nexit-all
. Failed trying to resolve: Class\nshow-method method\nexit-all
Why is that happening? the cd command should only receive Class not the rest of the string. Why is that? Well it turns out that what you put in the command line and what the StringIO is initialized with are two different things:
In: 'cd Class\nshow-method method\nexit-all'
At StringIO.new: 'cd Class\\nshow-method method\\nexit-all'
This alteration is causing the StringIO not to read the separate commands.

Hack Solution:

I altered bin/pry in the gem to perform a gsub!(/\\n/, "\n") on the exec option (variable exec_string) before Pry.start is called at the end of the file.

Next steps:

Upon further investigation, this double slash issue is coming up as the command line arguments are being put into ARGV.
Results of ARGV.inspect
["-r", "config/environment", "--exec", "cd Class\\nshow-method method\\nexit-all"]
Being not satisfied with my hack solution, I want to look into Slop, which is what pry uses to process define and process options, to see what can be done to enter in multiple commands a different way. I would like to find a way to do multiple commands from the command line in a cleaner format rather than having to stuff new lines into the string argument.

Tuesday, June 8, 2010

Nuturing Passion

I, like everyone else, would like to work in an environment that intrinsically keeps me passionate about what I do and allows me to pursue my interests in my field. Unfortunately that's not always the case. I know that I've been in situations where I'm just waiting for my end time to come around so I can head home. How does one keep themselves up?

Answer - Pet Projects. I know this may not be new to a lot of people, but it has been the best way I've found to help remind myself why I like doing what I do. Over the past several months, I was not in an ideal environment for myself which had a lot of times left me stressed over what I do. The way I tried to work past it is a pair of pet projects.

Pet projects come in many shapes and forms. I know a lot of people whose pet projects involve advancing their technical knowledge. I do this to an extent in my projects. Though the higher purpose of my projects is to connect myself to different communities of people.

The first project I tackled was a tool to manage data about characters from Final Fantasy Tactics. I implemented it as a tool for my wife and I to use to keep track of character progress. It is hosted publicly at github. Development of this project tailed off after we had moved on to other video games. It was at this time that I took another pastime of mine, frisbee golf, and turned it into a project. The goal was to have it ready for when I started playing again this spring/summer with my wife playing the role of customer. The result was Frisbee Golf Tracker.

Ultimately, the pet projects had reached another goal, to keep me passionate about what I do. Because regardless of what the work day was like, I knew that I could look forward to that half-hour on the train or time late night to work on something I truly enjoyed. It's my responsibility to make that I have passion and take pride in what I do.

Wednesday, August 19, 2009

Learning the Importance of Knowledge Sharing

As what happens to a lot of people, my computer's hard drive died a few weeks ago and I lost everything. I do mean everything. Some small pet projects were lost completely because I refused to upload my code base to github. Why didn't I? Because I was afraid to show what I don't know.

This may be one of the hardest lessons for me to learn in my journey. Growing up as the perennial whiz kid, to not have the best way to do something or to not have the right answer was a personal failure, and I would rather sit and rehash on a problem for a long time before I would ask a question. So of course, I'm in an industry where what is right or best changes rapidly and can be different from one person to another and in an ideology where one can't and shouldn't sit and stew by themselves.

What I'm slowly learning is that I have to be willing to expose myself in order to grow. Be willing to ask one too questions and to treat each setback not as a downfall but as a learning experience. I should be able to put my work out there for all to see and comment. Knowing me though, it will be a process. But even now, I've started to ask more questions allowing me to start minimizing personal frustration and stewing. Though I do still greatly struggle with wanting bottle up my work. But I have to be able to put it out there so that I'm not limited to my own experience and ideas, but have to access an industry's experience and ideas.

Writing this, I realize what may be the issue. I wish to to be able to give at least as much input as I'm receiving. But still being a relative beginner surrounded by those with more experience and more insight, I can't legitimately see this ideal being reached. In the end though, I have to willing to go in the red with input before I can move forward into the black in the future. I just have to take a confident foot forward with that investment.

Friday, May 8, 2009

The Next Chapter

I'll be entering what I consider the next chapter of my career here at Obtiva when I move on-site on Monday. It's interesting to think that I just walked in the door nine months ago. I have learned a lot in that span. I came in as new college graduate whose primary language was basic Java (w/Swing) with a dabbling in C++ and C#. In nine months, I've added Ruby (on Rails), Perl (CGI), Objective-C, some Javascript, and an update to my HTML/CSS knowledge. I've also been learning practices to programming that were never really touched upon in my formal education. Which in some ways makes me wish that my college classes were structured differently so that maybe I would have learned some of these practices/languages before the start of my apprenticeship. At the same time though, I know that I've always learned best by doing, and I don't usually like to toot my own horn (except in the eleven years I played trumpet, yeah, I know, bad joke), but I've done a lot since I've arrived, and I'm excited to move forward when I trade my 3 minute walk to Studio (from the train station) for a 15-20 minute walk to the on-site client. Here's to the knowledge of the past, the vigilance of the present, and the challenges of the future. Cheers.

Friday, April 24, 2009

Radiant, CMS

The past couple of weeks I've had a change of pace and have been spending some working on content and css for the company website. I say change of pace because it involves a new technology that I haven't used before, a plugin called Radiant. Radiant is a Content Management System which means that the content which would normally be in views in a normal rails app are stored in the database. This system is convienient for sites that have a lot of content, but less going on the backend. The only hiccup that I've hit with Radiant is that since the content is the database, it becomes hard to put in source control. So, if you have made a bad change to content and want to revert it, you better remember what it was. (If anyone knows a way to remedy this, it would help) Radiant also has a lot extensions which add functionality similar to rails such as pagination and extensions that add new features like permanent redirection. Another question I've ran into while working on the site is where does the CSS files belong in this kind of structure. Does it belong in the CMS with the rest of the content or in the repository which contains the radiant plugin? I'm starting to be more convinced that maybe it belongs with latter (after working with the former). Unlike the rest of the content, the CSS files are more prone to change and tweaking than the other content files and would have more benefit being part of source control. However this does cause the developer to have two seperate environments open, the CMS for page content and a text editor or IDE for the CSS, additionality I don't know how this would work Radiant's page caching. At this point, if starting from scratch I would choose to put CSS in source control. However, if mid-flight, I don't think source control adds enough to demand the time for a switch over.....but then again I may be converted yet. I had been wondering for a while if there was a Ruby option for content-based sites and have found that Radiant is overall a good solution.

Wednesday, April 15, 2009

Searching for the Answer

It's remarkable how much time as a programmer I spend scouring the web for answers to problems or for some sort of example of the use of a function due to under-documentation. Which always brings to mind how to adequately search for solutions. The two stages are choosing your keywords carefully, and trying to find relevant results. This occurred to me today while I looking for uses of Cucumber involving seeing whether or not with_tag could take a regular expression as an argument.

The first part is trying to choose keywords. Obviously, I didn't want use just Cucumber otherwise I'd a hundred salad recipes but nothing to do with testing. (As it turns out a search for Cucumber wields links to the github repository at 2 and 4 with an article about it at 3) so to narrow my search I added the method I was looking for. After a few tries of various combinations of keywords (including Rspec, regex, :text, etc.), I found a set of results that I could search through for the answer I was looking for. Using the small blurbs of the websites included, I had to make sure that all my keywords were found within the same portion of text. In the end, after several searches I found that with_tag ('td', /#{regex}/) was possible and was able to go green with my tests.

This is a process that many of us go through at least a couple times each day, and most of the time we don't really think about what we are actually doing. We just go through the actions that we believe will get us to the most viable and relative answer the fastest. But underneath, there is a certain level of practice and skill needed to make sure that our time is not spent wasting away through piles of unrelated content, but rather quickly finding that nugget of knowledge needed to move forward.

Thursday, December 18, 2008

Let me introduce myself....I'm Turner King

I'm relatively new to the blogosphere and thought I just describe my programming journey that has brought me to where I am today. My first exposure to programming was back in middle school(1999) when I was introduced to HTML through an elective that I took back then. It introduced me to some of the simple concepts of html and in turn lit a spark that would push me through high school. Even though through high school I only did some sparse html work on my own, I was convinced that I wanted to become a computer programmer. The problem I had was that I had no idea where to go from there.

I graduated from high school in 2004 and earned a full tuition scholarship to Carthage College in Kenosha, WI. After taking an introductory course that taught me a little more HTML and some Javascript. I finally was exposed to C++ that spring.

On a side note, it'd be very rare for me to choose C++ to program anything these days (but then again I may just not be experience enough), but as an introductory language it's great. Because as you move on to the Javas, Perls, Rubys, Pythons, you truly appreciated the things you get for free in newer languages.

As I moved through college, I got introduced to OOP a little in C++, but more extensively in Java. The jump from C++ to Java at the time felt like I had riding a bike, but now was given a car. I did hit some rocky points early due to a scheduling conflict that forced me to take some advanced courses before I took the intermediate courses. It's hard to implement polymorphism
when you just only got introduced to basic OO concepts. I graduated from Carthage in 2008 with a B.A. in Computer Science and Theatre with a minor in Mathematics with no job prospects in site.

With no previous internships and no experience whatsoever, I had a hard time finding a job and it turned into two and a half long months with a couple of close calls, but nothing I got truly excited about. I got interviewed by Obtiva near of July and got offered a job in a fairly unique situation where I was to be apprenticing under consultants while building my skills and credentials. It turned out to be a very good week as I also got engaged to my girlfriend of nearly two years a few days before.

This blog I intend to use to display what I've learned since arriving at Obtiva since arriving in August of 2008. It may not show any complex concepts (at least not right away), but is intended to reflect my current skills as a programmer and to help those on a similar path.