Skip to content


Static HTML Embedded Gists

I use GitHub a lot, and one of my favorite features are "Gists". They’re basically just a fancy way to share code snippets, but backed up by a mini Git repo. They also allow you to embed syntax highlighted source code into other web pages.

One thing I didn’t really like is that embedding a Gist into a page requires a lot of Javascript and HTTPS requests to the GitHub servers. It’s not a huge deal, but it slows things down a little bit.

So, I created the script below. It takes a Gist ID as a command line parameter, downloads it and runs the Javascript code through Qt’s Javascript interpreter. It intercepts the document.write calls to get the raw HTML. The results can be pasted into a static HTML page, or in this case a blog entry as raw HTML.

To reduce HTTP traffic and speed things up even more, the script strips out the link to GitHub’s gist stylesheet. To compensate, I added the content of that stylesheet to the stylesheet for the WordPress theme I’m using. I also had to tweak the rule for ".gist .gist-file .gist-data pre" a little bit, to set the line-height property back to 1.

In all honesty, executing the Javascript here is overkill. A few calls to string.replace() would be as effective and probably faster. But that wouldn’t give me an excuse to play with using Qt’s Javascript engine from Python :-)

#!/usr/bin/env python3
import urllib.request
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtScript import QScriptEngine, QScriptValue
def doc_write(context, eng):
    if context.argumentCount() != 0:
        na = context.argumentCount()
        args = list()
        for i in range(na):
            args.append( str(context.argument(i).toVariant()))
        temp = ' '.join(args)
        # if not 'embed.css' in temp: broke when running the script on itself!
        if not temp.startswith('<link rel="stylesheet"'):
            temp = temp.replace("\n", '')
            print(temp)
    return QScriptValue('')
def main(args):
    gist_id = None
    if len(sys.argv) > 1:
        gist_id = args[0]
    else:
        print("No Gist ID given!")
        exit(0)
    url = "https://gist.github.com/{gist_id}.js".format(gist_id=gist_id)
    app = QtCore.QCoreApplication(args)
    qse = QScriptEngine()
    dw = qse.newFunction(doc_write)
    qse.globalObject().setProperty('doc_write', dw)
    
    fh = urllib.request.urlopen(url)
    gist_script = fh.read().decode('utf-8')
    gist_script = gist_script.replace('doc_write', 'doc_write')
    res = qse.evaluate(gist_script)
if __name__ == "__main__":
    main(sys.argv[1:])
view raw gisthtml.py This Gist brought to you by GitHub.

Posted in coding, computers. Tagged with , , , , , , .

Handy shell script

A while back I needed to free up some hard drive space. To free up the most space as quickly as possible, I wanted to focus on the larger directories first.

Of course there are a lot of utilities, like KDirStat, to do that sort of thing, but I didn’t need anything that fancy.

The solution I came up with is the following Shell/Perl one liner:

#!/usr/bin/zsh
ls -Q -d . | xargs du -b -- | \
sort -n |\
perl -e 'while (<>) { @p = split; $sz = shift @p;\
    printf("%3.2f MB \t@p\n",$sz/(1024*1024)); }'
view raw dud This Gist brought to you by GitHub.

I had to break it up into a few lines so it’d fit in the narrow column here, but it works just as well with the line breaks removed.

Here’s a sample run:

[jl2:debianlap ~/src/cgeom] dud
0.00 MB ./.git/branches
0.00 MB ./.git/objects/info
0.00 MB ./.git/refs/tags
0.00 MB ./.git/refs/remotes/origin
0.00 MB ./.git/refs/heads
0.00 MB ./.git/refs/remotes
0.00 MB ./.git/refs
0.00 MB ./.git/logs/refs/heads
0.00 MB ./.git/logs/refs
0.00 MB ./.git/info
0.00 MB ./.git/logs
0.00 MB ./datastructs/tests/__pycache__
0.01 MB ./svgimg
0.01 MB ./geom
0.01 MB ./ch2/tests
0.01 MB ./datastructs/__pycache__
0.01 MB ./datastructs/tests
0.01 MB ./ch1/tests
0.01 MB ./ch2
0.02 MB ./.git/hooks
0.02 MB ./.git/objects/pack
0.02 MB ./.git/objects
0.03 MB ./datastructs
0.04 MB ./.git
0.06 MB ./ch1
0.16 MB ./

I’ve found it to be 10x more useful than the regular “du” command, so I thought I’d put it up here in case anybody else wants to use it.

I could probably make it shorter using just Perl, but it doesn’t seem worth the effort, so I haven’t bothered.

Posted in coding, computers.

Heightmap Animation

A while back I wrote this small program to create animated heightmaps using USGS elevation data, 3Delight, and GDAL.

Here’s a sample of the output:

Height Map Animation from jlarocco on Vimeo.

I have to admit it isn’t very useful, but I learned quite a bit about using libgdal, 3Delight’s C interface, and how to get data from the USGS website. And some of the animations look cool, so that’s also nice.

The source code has a few parameters to tweak the image quality at the cost of memory usage. The animation above was rendered on my laptop, so I had to decrease the quality a bit.

Posted in coding, computers. Tagged with , , , , .

Using Pinboard.in with Opera

A while back I signed up with Pinboard.in and stopped using my delicious.com account. Pinboard is pretty awesome, and there are plugins/extensions for Chrome, Firefox and Safari, but not much for Opera except for the generic “bookmarklets“. Fortunately, Opera is customizable enough that no extra plugins are really necessary.

Keyboard Shortcuts

The trickiest part was adding keyboard shortcuts for bookmarking. The shortcut editor in Opera isn’t very intuitive, so this was more difficult than I expected. My goal was to have F9 add the current page to “Read Later”, F10 to bring up the “Bookmark with Tags” page, and for F11 to bring up my Pinboard bookmarks. Eventually I was able to get it working. I think the important things are:

  • Add the shortcuts under the Application section
  • Make sure single key shortcuts are turned on
  • Make sure the correct shortcuts are selected in the “Keyboard setup” list. Sometimes the change doesn’t seem to take effect…
  • Make sure F9, F10, and F11 aren’t mapped to anything else anywhere.

The following can be copy/pasted into the keyboard .ini settings file. Or, copy paste everything after the ‘=’ into the keyboard shortcut editor.

; Read Later
F9=Go to page,"javascript:{q=location.href;p=document.title;void(t=open('https://pinboard.in/add?later=yes&noui=yes&jump=close&url='+encodeURIComponent(q)+'&title='+encodeURIComponent(p),'Pinboard', 'toolbar=no,width=100,height=100'));t.blur();}"

; With tags
F10=Go to page,"javascript:{q=location.href;if(document.getSelection){d=document.getSelection();}else{d='';};p=document.title;void(open('https://pinboard.in/add?showtags=yes&url='+encodeURIComponent(q)+'&description='+encodeURIComponent(d)+'&title='+encodeURIComponent(p),'Pinboard', 'toolbar=no,width=700,height=600'));}"

; Go to Pinboard.in
F11=Go to page,"https://pinboard.in/u:jlarocco/"

Searches

Next I added two custom searches for easy access to my bookmarks.

The first one, with shortcut “pbt” uses the URL “https://pinboard.in/u:jlarocco/t:%s”, goes to my Pinboard page and displays all bookmarks with a certain tag:
pbt Search

The second one, with shortcut “pb” uses the URL “https://pinboard.in/search/?query=%s&mine=Search+Mine”, will search all of my Pinboard bookmarks:
pb_screenshot

With the above configuration it’s almost easier to use Pinboard than it is to use Opera’s built-in bookmarking functionality.

Posted in computers. Tagged with , , , .

New Project

The other night while riding my bike after work, I realized that I ride one of two routes almost every day. I had never really thought about it before, but for some reason it really bugged me. I have “alternate” routes for when the trails are too muddy, or if it’s really snowing and cold, but usually it’s the same ride all the time.

I kept thinking about it, and before long I had a solution: I could create a database of all the rides I can access from work and setup a cron job to send a randomly selected ride to me every day. It was a long ride, though, and the more I thought about it, the more features I came up with. Before too long I had a whole list of features, and it started to seem like a really cool idea.

So my new project is going to be a website, After Work Rides.

I spent most of today setting everything up so that I can get started. I decided to make the site using Python3 and the Bottle web framework. Dreamhost provides MySQL databases, so that decision was made for me. Unfortunately, I had to install Python 3.2, Bottle, and the MySQL DB connector myself, because Dreamhost only provides old versions. Not difficult, but it had to be done.

After the hosting was setup I signed up for a Google Maps API key, created a new repo on Github and setup a simple landing page.

Finally I can get to work on the interesting part of actually developing the site…

Posted in Biking, coding. Tagged with , , , , .

New Single Speed

Single Speed 1

I just got a great deal on a single speed mountain bike at the Trek store in Louisville. They’re giving $100 off every bike in the store for the entire month of May.

Despite the great deal, my decision to get a single speed was somewhat spur of the moment. I spent a good portion of the morning cleaning the chain and derailleurs on my regular bike. Like usual, I spent the entire time making a mess and hating it. This time it bothered me so much I decided to do something about it. Single speeds are simpler mechanically, and are supposed to require less maintenance.

I plan on keeping my regular mountain bike for longer trips and for serious mountain riding. But for my daily commute and after work rides, I’ll probably stick with the single speed. Rumor has it that single speeds make your legs stronger, so that may be a nice bonus.

Single Speed 2

Posted in Biking, Outside. Tagged with , .

Mountain Biking Season

After reaching my goal of skiing 50 days during the 2010-2011 season, I’ve been having a hard time motivating myself to go anymore. I still think about going, and I keep telling myself I’ll go again, but I really don’t know when. The super nice weather isn’t helping much – 75 degree bluebird days just aren’t skiing weather. I’ve been dying to go camping or on a backpacking trip, but unfortunately there’s still too much snow in the mountains.

That means it’s the perfect time to spend the weekends mountain biking. The last few weekends I’ve been doing some variation of this loop.

It’s a really great loop because it can be as long as I want it to be, and it covers all kinds of terrain, from the road to single track. Maybe best of all, I don’t have to drive to get to it. Sunday’s ride was the longest variation I’ve done, and is shown in the GPS track above; a 51 mile loop with ~3000 feet of elevation gain that took about 4.5 hours. the only thing that would make the ride better is if there were more trails and fewer roads. I’ve been looking for ways to do that, but haven’t had much luck.

Also over this last weekend, I rode out-and-back on Westminster’s Big Dry Creek trail, from my apartment to I-25, and back. It’s only ~18 miles, so I added a loop around Standley lake. It’s not a very exciting ride, but I get so bored riding on the street to and from work, it’s a nice change to ride any kind of trail.

The next few weekends I may actually drive out to the foothills and do some biking there. Usually, I don’t like driving to go for a bike ride, but I’m really anxious to get out on singletrack this spring. I think next weekend I’ll head over to the Walker Ranch Loop. A friend and I hiked around it a couple years ago, and it looks like a great place to ride. I might even go crazy and ride all the way to the trailhead, do the loop, and ride home, but that’d be a pretty long day. Guess I’ll see how I feel next weekend..

Posted in Biking, Outside. Tagged with .

Skiing East Wall

Today I skinned up A-Basin from the parking lot to the upper section of East Wall, then skied down North Chute, back to the parking lot. To get a feel for backcountry skiing, I was wore a full pack, including my avalanche beacon, probe and shovel.

It was my first time skiing with a pack on, and in retrospect, it was probably a mistake to ski a 45° slope right off the bat. It went okay, though, and once I got to more mellow terrain everything went great. Tomorrow I’ll try without the pack.

This video isn’t the greatest, but it shows the view well enough:

And the GPS track of the skin up and ski down…

Posted in Outside, Skiing. Tagged with , , , .

New Vimeo Account

A couple weeks ago I bought a new helmet cam to use while skiing and biking. I haven’t made anything interesting yet, but I created a Vimeo account, and uploaded a couple videos to try it out:

I’ve never done any video editing, but Rob suggested Kdenlive, and so far it’s working out pretty well, but it’s taking a little time to figure everything out. The two clips I’ve posted so far didn’t really take much editing skill…

In any case, I’m working on some tree skiing footage that should be a little more interesting to watch, but it’ll probably be a few days before I get it good enough to upload.

Posted in Outside, Skiing. Tagged with , , .

Starting a Business

I’ve been thinking this over for a while, and finally made up my mind to start my own company. I don’t think it’ll make me rich, but if I’m going to write software in my free time, I might as well make money from it if I can.

So far I’ve registered as an LLC, got the company blog up and running, and upgraded my Github account to get some “private” repos.

Next up I need to figure out what to do for the company website, and research online payment systems. I think I can just use PayPal, but I don’t really know what that entails. Should be interesting.

Posted in news. Tagged with .