Top
Search
Elsewhere
Blog Index
The journal that this archive was targeting has been deleted. Please update your configuration.
Navigation
Sunday
May062012

Formatting Python source code in a Squarespace blog

One thing I definitely needed to be able to do on Squarespace is properly format any source code I might have in a blog post.

I currently have one posted with code here. The Python code in the post is nicely formatted.

To do this, I followed the instructions at http://www.webmasterymadesimple.com/blog/displaying-formatted-source-code-in-a-squarespace-website.html For the most part I just followed the steps one by one, but there were a few wrinkles.

I'm going to write my own version of the steps. These essentially match the original article above, but I'll call-out when I had to do something different.


Step 1: Download the latest version of SyntaxHighlighter

This worked fine for me. At the time of writing, the latest version is 3.0.83

Step 2: Uploading the SyntaxHighlighter source

This didn't work quite right. The original post calls for creating a directory, and then uploading into directory. For me, that ended up creating too many directories in the hierarchy. Instead, I skipped creating my own directory and just uploaded syntaxhighlighter_3.0.83.zip into the root of my storage area, remembering to check the Decompress Zip Files After Uploading option.

Then I simply renamed the uncompressed directory from syntaxhighlighter_3.0.83 to syntaxhighlighter

Step 3: Configuring SyntaxHighlighter

Here we add some Javascript to the Code Injection area of Squarespace. Go to Website Settings -> Code Injection and paste the following into the Extra Header Code area:


<!--SyntaxHighlighter code-->
<script type="text/javascript" 
src="/storage/syntaxhighlighter/scripts/shCore.js"></script>

<!-- At least one brush, here we choose JS. You need to include a brush 
for every language you want to highlight -->
<script type="text/javascript"
src="/storage/syntaxhighlighter/scripts/shBrushPython.js"></script>
<script type="text/javascript"
src="/storage/syntaxhighlighter/scripts/shBrushJScript.js"></script>

<!-- Include *at least* the core style and default theme -->
<link href="/storage/syntaxhighlighter/styles/shCore.css"
rel="stylesheet" type="text/css" />
<link href="/storage/syntaxhighlighter/styles/shThemeDefault.css"
rel="Stylesheet" type="text/css" />


The main difference between what I have here and the original post is the addition of the shBrushPython.js line. If you look at the Javascript itself, it tells you that this is required. The original blog post didn't explicitly mention to look, so I didn't initially realize it had to be done.


Step 4: Turning on the SyntaxHighlighter

The original post calls for adding some Javascript to the Post-canvas HTML section. Unfortunately if you just have the Standard account, you don't get access to that. Instead, you need to switch your site to Structure view, scroll to the bottom of the page and click Edit Website Footer, and then insert the following code there:


<script type="text/javascript">
     SyntaxHighlighter.all()
</script>

That's it for getting it installed properly. In terms of creating posts that use this feature, I'll refer you back to the original post, as all of his instructions there worked just fine for me. You only need to make sure that instead of brush: js you use brush: python


Friday
May042012

Squarespace

This website is now hosted on Squarespace. Over the years I've done a home-grown Django blog, as well as a hosted Wordpress site on Dreamhost.

For the amount of posting I actually do on the blog, oh of those solutions required too much upkeep. I've been looking at Squarespace for a long time, but wasn't happy with their previous pricing structure.

They've since moved to a simpler structure, and their new $8/month plan does 98% of what I want. The more expensive plan has a feature or two I'd be interested in, but not worth twice the monthly cost (for me, at least).

Otherwise I'm happy, and look forward to many long years of barely posting here.

Tuesday
Jan242012

PDF Collating/Merging

At home I have a wonderful Fujitsu ScanSnap duplex sheet-fed scanner. I can put a stack of double-sided pages into it, and it creates a perfect PDF.

At my office I have an HP all-in-one printer/scanner/copier. It's not quite so nice. It does have a sheet-fed scanner, but it can only do single-sided scans. If I wanted to scan any double-sided documents, I more or less had to take them home and do it there.

I got sick of doing this and decided to write a little Python script that can take two PDF files, and collate/merge them. The first file represents all the odd-numbered pages in the stack of paper, and the second file is the even numbered (i.e. the backs of the odd-numbered pages). My process now is to scan the stack of paper to produce the odd-numbered-pages PDF. Then I flip the stack over and scan again, generating the even-numbered-pages PDF. This PDF is in reverse order (when you flip the stack over, the last page gets scanned first), so my program knows to go backwards through the even-numbered document. I pass these two files to my program and it collates them and outputs a new PDF. The end result is the same as if I had used my ScanSnap at home, just with a little more effort. Better than schleping the documents back and forth from the office every time.

You can find it in all its glory here: https://github.com/parlarjb/PDF-Merge

Wednesday
Jan042012

iTunes Match and "Download All"

Google results for "iTunes Match download all" weren't fantastic, so once I figured it out on my own, I decided to document it  here for future generations.

The problem: I have two Macs, and a lot of the music on one was not yet synced over to the other via iTunes Match. While it was easy enough to download one track at a time by clicking on the iCloud icon beside the track, that was going to be a huge pain for a large number of songs.

Here's what I did to solve this.

  1. Make sure that the "iCloud Download" column is visible in iTunes. You can enable this via the iTunes menu with View->View Options->iCloud Download
  2. You should now have an iCloud column visible when looking at your music library. Click on the cloud icon to "sort by iCloud" 
  3. You should now have all the songs available via iCloud (but not yet on your computer) grouped together in your library. Simply select them all (click on the first one, scroll down, hold "Shift" and click on the last one), right-click or control-click (hold the "control" button and then click) on the list of selected songs, and choose "Download".

That's it! All your iTunes Match songs should start to download.

Yes, in hindsight this is all quite obvious, but I spent a good five minutes looking through iTunes for a button that says "Download All".

Thursday
Nov102011

Lyra's Birthday Surprise

There's a video on YouTube that Lyra loves to watch, involving people going into a room full of balloons and popping them all. We decided to replicate that for her birthday.