Paste2Upload—Completion Through Change

2009-08-01

There are reasons for everything as I always recall in regular discussions with friends, family, and other acquaintances. Paste2Upload is not an exception, that’s for sure. An avid Lifehacker reader, I remind myself consistently that if there is a noted repetition in my daily life that it is necessary it be dealt with.

One thing that I do, without fail, throughout the day is open up a new tab in whichever browser I am feeling favourable to that day (mainly Firefox or Safari), navigate my way to Paste2, and paste a snippet of text; whether it be a funny conversation, an important selection of a website, or some code that I want to share quickly and efficiently. This works quite well, I must admit, but on the last note of the previous sentence there exists one issue with the current workflow: efficiency.

A Solution

Beginning

As we all know, especially the engineers of the crowd, there are many solutions to any given problem. Now, when I’m among a circle of my peers, I’ll make a point to insist that my solution is right. It’s all in good fun, just like they’d insist that theirs is right to me—it’s the engineer’s way.

And so, working diligently, I analyzed the situation at hand and came up with a solution (the right solution, I might add, to any of the aforementioned crowd). What I needed was clear:

A swift, efficient way to paste text—sans-browser. I don’t always work with a browser open, but I do often communicate with an instant messenger at hand, so I wanted to untie myself from that single necessity.

  • A system-wide solution —I work in a variety of environments and share an equal variety of ways that I obtain information to share. Again, snippets from various mediums including both conversations and code. [Note: Although room exists for various implementations to be system-wide, the actual execution of such is not addressed directly in the code, though I do handle it in a way specific to Apple’s OS X. See a soon-to-follow post for more information.]
  • Full Functionality —Paste2 supplies three fields, two of which are greatly important to me: language and “code.” Although the code field can be anything, as I’ve already stated twice above, the language field denotes options to format the text via syntax highlighting. Whether that be plain text, Python, MySQL, or other, I knew that it was necessary to implement this.

As you read through my implementation, please don’t hesitate to chime in with comments here and there. They’re never hushed away and are instead acted quite the opposite to, I welcome them. While around my peers for the effect of playful banter and competition I’ll insist that I’ve devised the end-all, be-all solutions, I welcome open-mindedness and request any suggestions. If they seem reasonable and well-placed and have a relevancy to the topic, I’ll implement them as necessary.

Implementation

My goals were outlined and the implementation of them became clear. My original vision with this was that I create a command-line based utility in Python that would allow me to execute something along the following lines:

./paste2 --verbose --language python --description “A little taste of some code that I wrote” [text]

An explanation is in line here:

  • Verbose —We all know that this usually means the program being noisier in its execution. For me, it simply meant that the program would output to stdout “Pasted to http://paste2.org/p/..”
  • Language —Working from the syntax highlighting options given on Paste2, this would do the obvious and allow me to specify a language to highlight for.
  • Description —On the revision of Paste2 that exists at the time of this writing, you can supply some context to your pasted information in a description field. This data will appear below your paste.
  • [text]—This one, although all options are optional, I did not specify because I wanted to note its impact on the end-product and how it existed in my original vision. The idea was that, if unspecified, the text would be supplied via a small clipboard module that I wrote (also in Python) to get the current clipboard data from the computer for Linux, Unix, Windows, and OS X-based operating systems.
  • Return Value —The return was always similar, the program would exit cleanly and leave the user with a newly set clipboard containing the Paste2 posting URL.

A Mutable Plan

As a testament to my earlier promise, I am never afraid to welcome new ideas or proposed changes. Talking with a good friend of mine, Will Donnelly, I showed him my code at its then-completed state. It functioned according to the specifications above. Being the kind and praising friend that he is, he immediately pointed out everything that he saw wrong with it.

His main complaint was that my mindset did not seem to embrace the “UNIXy” side of things. I asked him to expand and he pointed out that my program forced the user to have their clipboard modified (which would hinder various implementations), had the unnecessary (and unwelcomed) [-v, –verbose] flags, and that it accepted only input from the clipboard or via directly input text.

To me, that last part was not an issue until he expanded further on his complaint. As he put it, I was failing to meet the standard by not accepting input-by-file or input through stdin. This is when everything clicked: a change had to be made.

The Mutation

I overlooked the proposed changes and implemented them with ease. It wasn’t many lines of change, but the payoff was well worth it. The program now accepted input through both stdin and file (which was simple enough, since Python treats the former just as it would the latter).

The verbose flags were removed as the program would now always output the URL to stdout so that, in the UNIXy fashion that was so demanded, it could be piped wherever necessary—whether xsel (Linux) or pbcopy (OS X).

Text input was removed in favour of file-name specification, which could be specified as a single dash (“-”) to let the program know that stdin input was requested.

The End Product

The end product, distributed freely under the MIT License, can be viewed at its GitHub repository page. The code itself can be viewed directly from the GitHub website as well.

The Message

Although I wanted to take an opportunity to share this bit of code with everyone, and I hope others will find it useful to their daily lives in reducing repetition and increasing efficiency, I had a greater meaning to this post.

First, as my preface suggested, I wanted to stress to all programmers (or - if not a programmer, to those who may want to suggest a small project for me to tackle) that if you notice repetition and inefficiency through your daily life, this is ample opportunity to write some productive code and simplify your life.

Second, I want to remind everyone that—no matter the field that you work in—I know that it is easy to get an idea stuck and committed in your head, but don’t let that block you from the bigger picture. Always take a step back, share your idea with friends and family, and don’t shun their input away. Although you may think that your original idea is the end-all solution and will work exactly how you want it, you may find from a little bit of open-mindedness that other possibilities can branch outwards from a little seed. As was with my code above, clipboards were my main concern at the beginning. Toward the end, various implementations are much less limited.

← all posts

michael schade

I built out engineering and operations teams at Stripe as employee #20 from 2012 to 2019; now I'm working on something new. I like helping people, photography, reading, gym, traveling, and learning new things. Say hi! 🏳️‍🌈