Uptonian Thoughts

Pastebin From the Command-line

· ·

Pastebin.com is a utility for sharing snippets of text with anyone. The service is simple: go to pastebin.com, paste your text, click submit, and share the link. It’s useful for sharing time-saving snippets with you team, or for an impromptu, informal code review of changes that for one reason or another haven’t been committed yet (e.g. a design decision for which the author wants early feedback.)

10:56:55 AM Mike Bulman: im gonna try to find one, but if it doesn’t exist im gonna write: a service/app for osx that will post whatevers on the clipboard to pastebin and give you a url

A couple of days ago, my friend Mike suggested that he wanted a utility that would make it easy to post to pastebin without having to break your workflow and go to the site. I thought “that sounds fun,” and went to work that evening.

Pastebin has a simple RPC API for posting content, and it’s perfect for curl. The very first version of the pastebin script was this simple curl script.

1
2
#! /usr/bin/env bash
curl -s -X POST -d "paste_code=$1" "http://pastebin.com/api_public.php" | pbcopy

paste_code is the POST parameter that the pastebin API expects to contain pasted content, so we just POST that to the public API page. The output of a successful pastebin API call is the URL for the paste, so we pipe that to OS X’s clipboard for easy pasting. Right from the beginning, this is clearly an OS X-specific script, but I don’t think it would be that hard to interact with the Linux system clipboard via xclip.

Making this work for text from stdin instead of as an argument was easy, too.

1
2
3
#! /usr/bin/env bash
to_paste=`cat /dev/stdin`
curl -s -X POST -d "paste_code=$to_paste" "http://pastebin.com/api_public.php" | pbcopy

Both Mike and I recently started using Jumpcut, a minimal clipboard manager for OS X, so I had the idea of copying the actual text that was posted to pastebin before copying the URL so both would be readily available via Jumpcut. I tried adding echo "$to_paste" | pbcopy before the curl call, but it didn’t always work. I didn’t actually find any documentation on it, but it seems that pbcopy does some sort of buffering so that too much text isn’t copied in quick succession. Adding a very hacky sleep call fixed it, so the resulting script became the following.

1
2
3
4
5
#! /usr/bin/env bash
to_paste=`cat /dev/stdin`
echo "$to_paste" | pbcopy
sleep 1
curl -s -X POST -d "paste_code=$1" "http://pastebin.com/api_public.php" | pbcopy

Having a commandline script is all well and good, but it’s on about the same usability level as using pastebin.com: instead of switching to a browser, you switch to a terminal, but you still have to paste content and get away from you original context. This is where OS X Services come into play.

The OS X Service menu is often neglected, but it’s very useful. There are some neat built-in services, like looking a word up in Dictionary or composing a new email with the selection. With tools like Automator or ThisService, creating your own service is easy. I created an Automator workflow that assumed the script was symbolically linked to /usr/local/bin/pastebin and called the script. You can easily add a keyboard shortcut to a Service in the System Preferences Keyboard Shortcuts preference pane.

I cleaned up the script by adding a few command line options using the getopts bash built-in. This was pretty useful and easy to use. I’m not a very proficient bash scripter, but I was easily able to add what I needed, including making the ability to copy the text optional and allowing a file to be used in place of stdin. Gina Trapani’s excellent todo.txt script was helpful in figuring out the correct syntax.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
while getopts ":cf:h" Option
do
    case $Option in
        c )
            PASTEBIN_COPY=1
            ;;
        f )
            PASTEBIN_FILE=$OPTARG
            ;;
        h )
            usage
            ;;
    esac
done

I wrapped the script and the Automator workflow and added it to github. You can view the original bash script in its latest form if you’re interested.

All this was well and good, but a couple of things bothered me. I didn’t like that sleep call, and I knew that the pastebin API offered a few options that I wasn’t allowing users of this script to take advantage of. So I did what any normal developer would do: I rewrote the script in python. The original version of the script was just a straight “port” of the bash script, but I had plans for more.

I have experience with simple python scripts, but I decided I should try my luck using classes in order to wrap the pastebin API. It was really easy. The beginning of the class looked like the following.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Pastebin(object):
    """A wrapper for the pastebin API"""

    pastebin_api = "http://pastebin.com/api_public.php"

    def __init__(self, paste_code, paste_name=None, paste_email=None, paste_subdomain=None,
            paste_private=False, paste_expire_date=PASTEBIN_EXPIRE_NEVER, paste_format=None):

        self.set_paste_code(paste_code)
        self.set_paste_name(paste_name)
        self.set_paste_email(paste_email)
        self.set_paste_subdomain(paste_subdomain)
        self.set_paste_private(paste_private)
        self.set_paste_expire_date(paste_expire_date)
        self.set_paste_format(paste_format)

Then all I had to do was use the class.

1
2
3
4
5
pastebin = Pastebin(paste_code=lines, paste_name=opts.paste_name, paste_email=opts.paste_email,
            paste_subdomain=opts.paste_subdomain, paste_private=opts.paste_private,
            paste_expire_date=opts.paste_expire_date, paste_format=opts.paste_format)
response = pastebin.paste()
return response

I have no idea if getters and setters are very “pythonic,” but they make sense to me, even if I’m only using them internally for this script. I used a pretty interesting trick to build the POST data string. I put the necessary data into a dictionary, but I needed to build a proper parameter string.

1
return "&".join([k + "=" + str(v) for (k, v) in params.iteritems()])

I love the syntax used for “inline” for-loops here. The extra str() call was used just in case a parameter (like expiration date) was accidentally interpreted as a number.

I updated the README to reflect the new options. Thankfully, only the symbolic link to /usr/local/bin/pastebin had to be updated in order to keep the workflow working. Using the pastebin script couldn’t be easier:

  1. Download the script source, extract it, and put it somewhere that makes sense, like ~/scripts.
  2. ln -s ~/scripts/pastebin-cl/pastebin.py /usr/local/bin/pastebin
  3. Open the workflow in automator/Paste to pastebin.com.workflow and save it as a service, which should just be as easy as ⌘-S.
  4. Open System Preferences > Keyboard, then Keyboard Shortcuts, then Services. Make sure that the “Paste to pastebin.com” service is checked. Optionally, you can give it a keyboard shortcut.
  5. Highlight some text in any OS X application and choose “Paste to pastebin.com” from the application menu’s “Services” submenu or use your keyboard shortcut. Now the pastebin URL is on you clipboard, ready to be pasted into a chat room or in a browser.

Hopefully this script will be useful to developers all over. If you have any ideas about making this more portable (i.e. for use on Linux or Windows), let me know in the comments.

Instapaper

· ·

Instapaper for iOS article view

Countless times, I have come across a piece of long-form writing that I just don’t have time to read at that moment. I used to just keep the link in question open in a tab for days and never actually get around to reading it. Sometimes I would bookmark it using Delicious, which helped me get back to the site with the article but did nothing to encourage me to read.

I recently started using Instapaper, a neat service from Marco Arment that helps one save articles and other web pages for reading later. In addition to bookmarking articles with the incredibly simple Read Later bookmarklet, Instapaper can extract text from articles and remove cruft like navigation and ads from the content you’re interested in. These tools are available on the Instapaper Extras page. Now, with a simple click, articles are saved to a list where you can easily access either the original site or just the article text.

There are a bunch of other helpful extras, too. Kindle users can download a compatible file that contains their articles, complete with sections and a table of contents. There are tons of apps with Instapaper support for OS X, Windows, iOS, and Android. I use the Instapaper iOS app on both my iPad and my iPhone. It’s great for catching up on my reading while traveling without an internet connection. The latest version offers a great progress indicator and the ability to automatically switch to dark mode based on the sunset times in your location.

Instapaper offers cool options for people who publish content, too. There’s a public settings page for the text parser so people can tweak how Instapaper extracts text from articles on sites that have lots of ads or extraneous content. Publishers can explicitly tell Instapaper which elements to use as the title and text by adding instapaper_title and instapaper_body classes to those elements, respectively. I have added the appropriate classes to articles on this site.

Instapaper on Uptonian Thoughts

There’s also a “Read Later” button that I have added to each of the articles on this site. If you’re logged in to Instapaper, you can quickly save the current article with just one click.

Marco Arment actively updates and writes about the Instapaper service, and I look forward to seeing what’s to come for this excellent tool.

The (Last) Year in Music — the Rest

· ·

I suck at writing, and I suck even more at writing often.

Here’s the rest of the list of my favorite music from 2009:

  • Number four: The Great Misdirect by Between The Buried And Me

The Great Misdirect by Between The Buried And Me

Incredible work from the always-reliable technical metal group. This is an album for serious guitar and bass aficionados; the talent on display here is profound.

  • Number three: Crack The Skye by Mastodon

Crack The Skye by Mastodon

A concept album about a paraplegic who gets involved with Russian ghosts told with typical Mastodon intensity, complete with a pretty awesome Rush tribute.

  • Number two: Beggars by Thrice

Beggars by Thrice

Probably my favorite band, Thrice turns yet another new page in the book of their ever-changing styles. Beggars is groovy and filled with Dustin Kensrue’s typical lyrical thoughtfulness.

  • Number one: Daisy by Brand New

Daisy by Brand New

Brand New brings an intensity to a genre that (rightly) gets accused of being stale. Seeing these guys perform songs from both Daisy and Your Favorite Weapon live is an incredible sight.

The Year in Music — Number Five: I and Love and You by the Avett Brothers

· ·

I And Love And You by The Avett Brothers

I first heard The Avett Brothers on a mix CD that a friend and I were listening to in the car. Talk on Indolence came on, and we both looked at each other in amazement. I begged him to find out from the friend who made the mix who these guys were and if they had any more music.

The Avett Brothers have come a long way since then. They have steadily become better musicians and singers, and they have reached a certain level of mainstream fame (cf. their appearance on Letterman.) I And Love And You represents both a pinnacle of achievement for the North Carolina trio and an indication that they are not quite finished sharing their music with the world.

One thing that is immediately noticeable is a focus on richer songs filled with more and varied instruments than before. The piano is featured fairly heavily. The production of this album is excellent; each song feels full and finished, which is not something that one usually thought of when listening to previous efforts. One other thing to note is the prominence of drums in most of the songs: this is somewhat unusual for a band that does not have a permanent drummer. The trio take turns drumming when they play live, and it works very well.

I And Love And You is a great opening track, full of dynamic and great piano playing. The track perfectly encompasses the whirlwind rise that the band has experienced over the past year or so. The Perfect Space is another lush piano track, with a great transition to a pop-piano-rock feel in the second half of the song.

A track that showcases the drums that I mentioned above is the aptly-named Kick Drum Heart. Very catchy, very poppy, and very good.

One of my favorite tracks on the album is Slight Figure Of Speech. It evokes the jangley pop of the sixties while still managing to sound fresh. I was lucky enough to hear a live version of this track in Austin last October, and it sounded great.

The Year in Music — Number Six: The Pariah, the Parrot, the Delusion by Dredg

· ·

The Pariah, The Parrot, The Delusion by Dredg

It’s incredible, but I had never heard of Dredg before this album. I was seriously missing out, but I am so glad that I found this album. Inspired by Salman Rushdie’s Imagine There Is No Heaven: A Letter To The Six Billionth Citizen, the album is an eclectic mix of experimental and art rock. Every song brings something to the table, but the entire album is marked by impeccable production and great musicianship.

A large number of tracks comprise the album; some shorter instrumentals and breaks intersperse longer, more traditional songs. Drunk Slide is the first of these, and even though it’s less than ninety seconds long, it is still a worthy listen. Ireland, the track that immediately follows, is one of the highlights of the album. It’s one of those tracks that makes you want to sing along, even if you don’t know the words. That quickly becomes a theme of the record.

There are so many eclectic styles of music on this record that it’s hard to sum it up. The album is definitely meant to be listened to as a whole, but that doesn’t mean that each song doesn’t stand on its own. Take Mourning This Morning, for instance. The peppy palm-muted guitar that plays throughout the song almost makes you want to dance. The preceding track, I Don’t Know is a poppy little rock groove, and a couple tracks later comes Long Days And Vague Clues, a song that could be straight out of a seventies spy flick.

Pariah certainly requires the listener’s attention, but it is well worth every moment.

Dredg dedicated the album to Deftones bassist Chi Cheng, who was left in a coma after a horrific car accident in November 2008.

The Year in Music — Number Seven: Axe to Fall by Converge

· ·

Axe To Fall by Converge

No one ever said that Converge wasn’t intense, but Axe To Fall hits you right in the face from the very first measure. If opener Dark Horse is a frantic mashing together of everywhere you expected Converge to evolve to, the next track throws all that away. Reap What You Sow still maintains that manic pace, but throws in synths and an absolutely ridiculous guitar solo. Like, straight out of Kirk Hammet’s curly locks guitar solo. If you aren’t out of breath by the time you’ve finished listening to the first two tracks, then you didn’t listen closely enough. I’m not sure that Converge could play this album live from start to finish because I’m not sure any human beings could keep up such a relentless onslaught.

The title track brings back some of that chaotic Converge riffage that we all remember from Jane Doe, but then Effigy shoves even more synthy goodness down your throat.

Axe is evidence that Converge is evolving, and their direction could not be more pointed. They have obviously always been talented musicians, but it’s almost like it took this long for the band to realize that they could showcase their diversity and musical maturity with no fear.

The most remarkable parts of this album come at the end. The final two tracks are such a radical departure from the chaos of the rest of the album. Cruel Bloom is almost a sort of weird Tom Waits tribute, if Tom Waits were in to haunting your nightmares. The slow pace is a change, but you can still feel the intensity that the band projects. I’m not sure if that’s because of the residue from the rest of the album, but this song certainly stands on its own.

Closer Wretched World is a work of art. I know that a lot of Converge fans won’t want to hear this one at a show, but no one can deny the emotion that this song evokes. A lot of Jacob Bannon’s lyrics come from a heartbroken point of view, but this song manages to wrap some of the saddest lyrics in such beautiful music. I would love to hear more from this side of Converge.

When it’s over, Axe To Fall is Converge’s strongest effort to date. I don’t think they’ll be playing on your local radio station any time soon, but this album is strong enough to please fans of old while perhaps opening some new eyes to this quartet’s music.

The Year in Music — Number Eight: The Satanic Satanist by Portugal. The Man

· ·

The Satanic Satanist by Portugal. The Man

I have a bone to pick with Portugal. The Man. The European LP comes packaged in a beautiful and intricate piece of folded and cut cardboard. The US version is just a gatefold. I pre-ordered The Satanic Satanist on vinyl in support of the band, and now I wish I had the “cool version.” Fortunately, the packaging of an album has no bearing on the quality of the music inside. (But seriously, I covet that artwork.)

Satanist is one of those pop rock albums that goes just far enough into left field to pique your interest with every song but stays mainstream enough to make it a hit at any party you host. I was singing along with this album before I even knew the words. The Beatles influences abound here, but where that might be an insult to some (or even many) bands, Portugal. The Man knows how to use their idols for inspiration and not for source material.

Lovers in Love remains my favorite track on Satanist even though there are ten other contenders for the top spot on this eleven track album. Something about John Gourley’s falsetto and the fast-paced wah-guitar and bongos of the chorus just really hits me in the right way. The entire album has this groove to it that mandates that you listen to it as a whole. The cohesion of the songwriting and the musicianship is uncanny. I made mention of the “singability” of this album earlier, but I must repeat it again because it’s so important. You’ll be singing along to Lovers, Everyone is Golden, and The Home before you’ve finished listening to those songs for the first time. I think that’s a sign of a band that really understands the art of songwriting, and these guys certainly aren’t afraid to show off their talent.

It’s been a long time coming, but I think Portugal. The Man is about to become something big. The quintet has already recorded a follow-up to Satanist to be released this coming spring, but this album already goes a long way towards convincing the world that punctuation in medias res is cool again.

The Year in Music — Number Nine: Desperate Living by HORSE the Band

· ·

Desperate Living by HORSE the Band

It might be considered rash to place an album that you have been listening to for less than two weeks in your top ten list of best albums of the year, but I don’t think choosing Desperate Living as my number nine album is a decision I’ll regret. HORSE the Band is certainly not a mainstream band (their chiptune beats and hardcore tendencies mixed with Nathan Winneke’s bizarre lyrics is not a combination that everyone can get into), but this is great music with a huge sense of originality.

The first track I heard from Desperate Living was Shapeshift. What starts out as a moody and ethereal track soon crashes into blast beats and screams, which soon transforms into this sort of alt-rock breakdown, which is then interrupted by what can only be described as the soundtrack to a Game Boy game from 1993. It only gets weirder from here, and this is only one track! Xiu Xiu frontman Jamie Stewart makes an angelic contribution to the song’s outro, which is somewhat unusual for a HORSE track.

The album is filled with pitch-shifted tones that remind you of the warped soundtracks from bad VHS transfers and some of the most intricate guitar and drum work out there. If that’s not a mind-bender, I don’t know what is. Here’s the thing: it all sounds amazing. Every single track keeps you on your toes and gets you to alter all of your expectations. I must have listened to this album more than ten times already, and I hear something new every time.

Desperate Living is certainly a step forward for HORSE the Band in terms of sound and songwriting, but there is still that familiar “Nintendo-core” vibe and wacky humor that longtime fans have come to expect. Take the end of of the title track for instance: The words “I’m a plumber, but what I plumb is the fruit of infinity. I’m deeper than infinity, so infinite, I look infinity look like a four” are spoken with no explanation whatsoever. And there’s that bit about dinosaurs in the aforementioned Shapeshift. And the nearly-comical synth breakdowns on The Failure of All Things. And they fact that they named a song after themselves. And the album’s cover artwork.

The Year in Music — Number Ten: Merriweather Post Pavillion by Animal Collective

· ·

Merriweather Post Pavillion by Animal Collective

My Girls is an incredible song. You should stop reading this review and go watch the video right now. Make sure it’s in HD.

Animal Collective is less of a band and more of a, well, collective. The lineup shifts regularly, and every album is a new adventure. Merriweather Post Pavillion is, however, the group’s crowning achievement. Their eighth studio album contains some of the most accessible and focused songs they have written, but still maintains that familiar (if “familiar” is even a term that can be used to describe their sound) neo-psychedelic pop rock that we have come to love over the past few years.

The airy intro of In the Flowers gives way to hand claps and bouncy beats and serves as the perfect intro to the aforementioned My Girls. Every song on the album has a distinct feel to it yet still manages to sound just like an Animal Collective album should. It’s interesting that I would be reviewing this album now, almost exactly one year since I first listened to it. Its uplifting melodies and beats stand in stark contrast to the dark and cold nights that I associate with listening to the album. This is a summer album, through and through. It should be listened to in a car with no top or while lying on a blanket in a green field. Case in point: Summertime Clothes. I dare you not to start bopping your head to this song.

Towards the end of the album, we are all invited to slow down on the track No More Runnin. This easy-going lullaby quickly gives way to one of the quirkiest and poppiest tracks on the album. Closer Brother Sport will have you humming the melody for days and even weeks after the song has stopped playing.

Merriweather is some of Animal Collective’s best produced and most cohesive work to date, and all that extra effort definitely pays off. Just be careful that you don’t spend too long staring at that mesmerizing album art.

The Year in Music — Honorable Mentions, Part Two

· ·

Part two of my list of great albums that didn’t quite make my top ten list continues. You can find part one here.

Fever Ray by Fever Ray

Fever Ray by Fever Ray

Karin Dreijer Andersson has a prolific musical history. She has collaborated on numerous tracks by fellow Scandinavians Röyksopp, and The Knife’s Heartbeats has been covered numerous times. Her debut solo album doesn’t stray too far from the pitch-shifted multi-tonal vocals that give The Knife such a distinctive sound; Fever Ray is marked by sparse beats and deep lyrics.

Lungs by Florence + The Machine

Lungs by Florence + The Machine

This is pop music, through and through. But it’s well-written, uplifting, and magical pop music. Florence Welch has an imposing voice, and she uses it to great effect. Kiss with a Fist, the first single, is a spunky tune about a couple that are a little too close, but it’s not even the strong point of the album. Opener Dog Days are Over just makes you want to sing along until your neighbors yell at you, and if Drumming doesn’t get your toes tapping, there’s something amiss.

Two Suns by Bat for Lashes

Two Suns by Bat for Lashes

Natasha Khan has one of those voices that makes you stop and really listen. At once airy and prominent, the songwriting on Two Suns complements her voice perfectly. Leadoff single Daniel has been playing nearly every day since I found out about this album. I only recently found out about Bat for Lashes, but I am already hooked.

Tarot Sport by Fuck Buttons

Tarot Sport by Fuck Buttons

Tarot Sport is the perfect album to listen to while you’re doing something else. That’s not an insult to the album; on the contrary, the droning noise rock and minimalist beats make this a favorite programming album. There’s more substance to the songs on Tarot Sport than on their previous album Street Horrrsing, but I’ll leave it to you to decide whether that makes this band more mainstream.

Grey Britain by Gallows

Grey Britain by Gallows

Gallows is bringing back good old punk rock, and they don’t care if you want it or not. Vocalist Frank Turner spits and sneers at you through every one of the brutal tracks on this album. Even the acoustic act one of The Vulture gets you pumped for the inevitable: Gallows knows how to rock. This is a band I’d love to see live.

Worse Than Alone by The Number Twelve Looks Like You

Worse Than Alone by The Number Twelve Looks Like You

The Number Twelve Looks Like You seems to be one of the most overlooked bands in recent memory. I never hear anyone talk about them, yet they have outdone themselves musically album after album, and they continue to be a group whose releases I really look forward to. Unfortunately, the band broke up in November. The most technical of mathcore dominates Worse Than Alone, with time signature shifts, key changes, and varying tempos galore, this album requires your full attention. What a parting gift for their fans.

The Crooked Vultures by Them Crooked Vultures

Them Crooked Vultures by Them Crooked Vultures

I had the immense pleasure to see Mssrs. Homme, Grohl, and Jones in Austin, TX at the Austin City Limits music festival in October. No one knew any of their songs, but everyone knew that they were listening to something special. And who should expect anything less from this trio? The pounding tempo change at the end of No One Loves Me And Neither Do I leaves you in awe, and, if for no other reason, see them live for the intro to Elephants.