atomicules

Pertaining to: making pictures, writing code and riding bicycles.

CMUS and offline scrobbling to Last.fm and Libre.fm

As mentioned here I've (somewhat) recently moved to using CMUS instead of Rythmbox. Ever since my iPod died completely I'd been relying on a desktop player and offline scrobbling; since I am most likely to listen to music at work, but can't scrobble because our proxy server blocks it. Rhythmbox supports offline scrobbling (hurray!), but is a bit crap about it (boo!): For unknown reasons it doesn't log all tracks and - although it did successfully scrobble them to Last.fm when back on line - when I decided I'd move to Libre.fm (but then reconsidered and kept my last.fm account as well) it was even crappier at scrobbling, logging a different number of tracks for each service and then losing all tracks for Libre.fm during submission!

I'd checked (before getting carried away with the geek attractiveness of it) and CMUS supported scrobbling via a few external plugins/scripts and a couple of them also provided offline support. The only one I could get working, however, was Post.FM. Well, I say working, but I'd declared it as working after a quick online test. After a week's offline scrobbling, and months of scrobbling downtime (I always think of these things such as moving from Rhythmbox to CMUS and Last.fm to Libre.fm as little weekend tasks, but they always take me MUCH longer), I was full of anticipation for getting going with scrobbling again; however, for whatever reason, it wouldn't scrobble with a big backlog of offline scrobbles. I almost just gave up, but then I figured I'd try to get my head around Perl enough to convert the Post.FM cache to a format that I could use another programme or service to scrobble with, such as the libreimport.py tool.

And that is kind of where I am today:

  1. Using Post.FM (unmodified until I figure out Perl more) to cache offline scrobbles.
  2. Using a complementary Perl script (work in progress) to convert the Perl Storable cache format to a scrobble.log format.
  3. Submit scrobbles to Last.fm and Libre.fm via Scroblr.net (for the time being. I'd prefer to use a command line tool, but Scroblr is quick and painless so I'm in no rush; my initial plan was to use libreimport.py and forward scrobbles to Last.fm from Libre.fm, but it didn't work out right and I hit this bug with multiple scrobbles appearing on Last.fm; hence going and finding Scroblr.net).

To the Command Line, Batman!

For reasons that I am unable to properly explain (to myself, let alone others), over the past few months I have been unable to resist the compulsion to investigate and set-up command line mail clients (in general).

It probably has something to do with low memory requirements, well a lot to do with that, and that would be my reasoning now, but it wasn't like I actually had that foresight that prompted all this tinkering. But, yeah, at home I have the old Powerbook that is maxed out at 1.25GB RAM and always has at least one other account constantly logged in with Safari, etc, sucking a blackhole's amount of swap space, and at work I live in a virtual machine and so only have 1GB of RAM to play with. So low memory applicationss do make A LOT of sense.

Oh, and I guess the other obvious thing is command line applications are more likely to be cross platform.

It started with mail clients...

Mail

Since I like Vim, I kind of figured out that Pine/Alpine/Re-Alpine were out of the question (although I belatedly understand it is possible to use Vim with them) and that really that only left Mutt, but I just couldn't bring myself to figure it out. There's plenty of help out there, but the more I read the more tricky is looked. Such was my aversion to knuckling down and figuring Mutt out I managed to find some alternatives:

  • Sup is written in Ruby, is a breeze to setup, easy to use, but by default assumes that you don't really care about synchronising local and remote sources. Which might work fine for folk who are always on the same machine all the time and who also aren't forced to use webmail occasionally. As far as I can tell, if you use local mbox files, then it is possible to sync, but then there also does not seem to be any mbox equivalent to the excellent OfflineIMAP (which uses maildir). There is a maildir sync branch someone created, but that would require manaully trying to merge and keep in sync with development.
  • Notmuch, found this as a result of Sup. It's meant to be a re-write of Sup taking the best bits, making them faster and leaving the bad bits, but from my point of view it is almost the opposite. I wanted the mail client (Notmuch isn't one) as Sup has a great UI. There are some kind of interfaces provided, but the developers seem to prefer emacs over vim. Poop.
  • Cone. Another Pine derivative. I think, well, it must at least be influenced by it, hence its name. Easy to setup, but just was never going to work for me if I couldn't use Vim.
  • Vmail, and then I found this. Wow! I don't understand how I missed this one. This is the kind of thing I'd been searching for, for ages. I.e. I want a twitter client in Vim, find TwitVim, I want a mail client in Vim. Nada. I just never found this. Was very excited about this, but it assumes Gmail (in theory does other IMAP, but I couldn't get that to work) which isn't so great as I'm trying to de-googlefy and so have moved one email account away from Gmail. Also, I don't want an online only approach and since it needs to connect to an IMAP server (as far as I can tell) I ended up looking at Offlineimap + Dovecot + Vmail. And I started going down this route and trying to get Dovecot configured and then I just decided THIS IS UTTER INSANITY. Running my own IMAP server locally, just to read my mail that is already on an IMAP server somewhere else? It just doesn't seem right, or easy.
  • Mutt And there we are. Right back to the start and the thing I was trying to avoid all along. It is true what it says on the tin: "All mail clients suck, this one just sucks less". As to configuration, I'll cover that elsewhere, perhaps, but it's similar to Vim: you just have to suck it up, figure it out and get on with it.

Twitter

I've been using Twitvim for a little awhile now since it makes a lot of sense if you like Vim, plus its unobtrusive at work. I'm now also using TTYtter (2, currently Beta). They work well together as TwitVim is better for paging through Tweets if you are so inclined to catch up on stuff you've missed whilst TTYtter does the realtime/streaming side of things and handles message threads better. In TTYtter I use a plugin for spam reporting and one to get occasional timestamps.

Web (only at home)

TenFourFox is an excellent browser, but it's memory requirements aren't exactly low. So for quickly checking some websites (mainly BBC Weather, until I find/write a command line weather app) elinks is great; it even does tabbed browsing!

Music (only at work)

CMUS since Rhythmbox has memory issues for me. CMUS is fab, but I've found getting scrobbling working tricky. And I'll come to that separately, probably, eventually, maybe.

A little Python command line app I wrote that uses the Simplenote.py module from mrtazz (Daniel Schauenberg) to synchronise arbitary files across multiple machines via the Simplenote service. Basically I wanted a way to synchronise certain "dotfiles" without the "expense" of a Git repository. More info in the README if you follow the link.

My 'Listening to New Music' Goal of 2010

I'll mostly skip the end of year review thing this time around as otherwise I will be unable to prevent a moan of truly EPIC proportions. I'll just let out a little sigh and crack on with this:

I don't think I explicitly set this as a new year's resolution last year, but during the year I certainly developed an intent of listening to as much new music as possible. And although it felt like I'd achieved that aim I wanted to prove it.

I found this excellent Last.fm discoveries app via build.last.fm earlier in the year, which almost exactly does what I want, but it only works with artists that have a minimum of twenty five plays in your library whereas I wanted to count even one play (because I'd have still listened to that artist even if I'd then immediately decided it was crap and warranted no further plays).

Rather than try to hack/modify that, it just so happened that I'd also been playing with moving (or simultaneously using) libre.fm and so was exporting scrobbles from last.fm to a local file. I'd started using the tool recommended on libre.fm, but it missed some scrobbles (even though it went through every page of my last.fm scrobbles) so looking around I then found this other tool that worked much better and got everything; it backs up to an XML file, rather than the (nicer) simple file format used by the lastexport.py script (I'm still trying to find the time to make sure my libre.fm history matches my last.fm history, let alone set-up dual scrobbling; it's harder than it seems to get reliable offline scobbling on Linux).

Using R it's really easy to import an XML file and get it into a dataframe. It's then possible to split plays by year and identify what artists haven't appeared in a previous year:

#Last.fm analysis

library('XML')
# See here for use: http://www.omegahat.org/RSXML/gettingStarted.html

doc = xmlRoot(xmlTreeParse("lastfmscrobbles.xml"))
mat = xmlSApply(doc, function(x) xmlSApply(x, xmlValue)) #Has side effect that all cell contents are in lists
mat <- t(mat) #transpose
scrobbles <- as.data.frame(mat)

#Unlist columns of interest
scrobbles$date <- unlist(scrobbles$date, use.names=FALSE)
scrobbles$artist <- unlist(scrobbles$artist, use.names=FALSE)
#Make sure dates are actual dates.
scrobbles$date <- as.Date(scrobbles$date, "%d %b %Y")

#Subset scrobbles by year
scrobbles2011 <- subset(scrobbles, grepl("^2011", date))
scrobblespre2011 <- subset(scrobbles, !grepl("^2011", date))
scrobbles2010 <- subset(scrobbles, grepl("^2010", date))
scrobblespre2010 <- subset(scrobbles, !(grepl("^2011", date) | grepl("^2010", date)))

#Then find number of unique in a year
#2011
unique(scrobbles2011$artist)[!unique(scrobbles2011$artist) %in% unique(scrobblespre2011$artist)]

#2010
unique(scrobbles2010$artist)[!unique(scrobbles2010$artist) %in% unique(scrobblespre2010$artist)]

Based on this raw data, I had 162 artists in 2011 and 113 in 2010. However, this needs quite a bit of manual filtering as I've only been scrobbling since 2008 and I like to delve back into the past (bands I listened to when I was about sixteen seem to be a favourite). So, after a bit of manual sifting I get this to 129 new artists for 2011 vs 73 new artists for 2010. So, yep, I did succeed in my goal of finding more new music.

This is pretty impressive as both my iPod mini (finally!) and iPod Touch died permanent deaths last year so listening and scrobbling has relied on me using a computer. This year I'm taking it easier: It was just too much work to keep checking through the Line of Best Fit and the Guardian New Band of the Day feeds, looking for what seemed interesting and then trying to "find" tracks by those artists lying around on the internet. I'm hoping to use libre.fm to find more legitimately free music to listen to this year, but I'm not going to go mad about it.

(As a footnote: One of the most impressive things about last year is that I managed to oust Freesteylers from my top artists spot. That took a lot of self-control).

A Quick Note for Idiots (me) on Installing the xapian-full gem on Linux

I've been playing around with Sup (I'll come to that in another post soon, fingers crossed), but couldn't get the xapian-full gem to install on Linux as it bombed out as follows:

gem install xapian-full
Building native extensions.  This could take a while...
...
checking whether the C compiler works... no
configure: error: in `/home/me/.rvm/gems/ruby-1.9.2-p290/gems/xapian-full-1.2.3/xapian-core-1.2.3':
configure: error: C compiler cannot create executables
See `config.log' for more details.
rake aborted!


Tasks: TOP => default
(See full trace by running task with --trace)


Gem files will remain installed in /home/me/.rvm/gems/ruby-1.9.2-p290/gems/xapian-full-1.2.3 for inspection.
Results logged to /home/me/.rvm/gems/ruby-1.9.2-p290/gems/xapian-full-1.2.3/./gem_make.out

And checking config.log I got:

configure:3866: checking whether the C compiler works
configure:3888: gcc   -R/home/me/.rvm/gems/ruby-1.9.2-p290/gems/xapian-full-1.2.3/lib conftest.c  >&5
gcc: error: unrecognized option '-R'
configure:3892: $? = 1
configure:3930: result: no

I found this post on archlinux (which almost exactly explains what to do, I just didn't quite get it at the time) and this github issue but it took me awhile to figure out how to apply the patch. It's always easy when you know how...

gem fetch xapian-full
gem unpack xapian-full-1.2.3.gem
cd xapian-full-1.2.3
curl -O https://github.com/rlane/xapian-full/pull/4.patch
patch < 4.patch
gem build xapian-full.gemspec
gem install ./xapian-full-1.2.3.gem
cd ..
rm -rf xapian-full-1.2.3
rm xapian-full-1.2.3.gem

I thought after unpacking I'd just be able to run rake and install the gem that way, but if you can I can't figure out how. So repacking it (build) it is - at least that doesn't take long.

Have to say, Ruby on Linux has been a lot fiddlier than I thought. On my ancient OSX 10.5 PPC no problems at all installing xapian and sup. Colour me suprised.

Looping Through Figures, Sweave vs Tikz (pgfSweave)

Almost as soon as you start using R you hear about Sweave (probably because it is included with the base install of R) which allows you to embed R code within LaTeX documents. However, I placed learning it on the back-burner for about a year so I could just spend time getting my head around R (although how I've managed to avoid LaTeX until now, considering my background and the amount of technical reports I've written over the years, is another matter).

Then, as soon as you start using Sweave you come across the issue of plot fonts and sizes not matching the main report (personally I can live with the different font style, but the different sizes is annoying). And so that's when you hear about pgfSweave.

However, I was using Lattice graphics built-in capability to produce multiple pages of plots (see 'layout'):

The number of pages is by default set to as many as is required to plot all the panels, and so rarely needs to be specified. However, in certain situations the default calculation may be incorrect, and in that case the number of pages needs to be specified explicitly.

In Sweave, the way you would use one code chunk to produce multiple figures is to use a tex chunk rather than a fig:

%Traditional Sweave Loop
%Sweave file extract

<<eval=TRUE, echo=FALSE, results=hide>>=
#Cleanup - delete previous files
file.remove(list.files(pattern = glob2rx("ybygroup*.png")))
#No need to use a loop here, lattice graphics will produce the necessary number of pngs
png(file="ybygroup%03d.png", width=1000, height=2000)
xyplot(Y ~ Date | Grouping, datatable, layout=c(1,8), ylim=c(-100,100), xlim=as.Date(c("2011-01-01", "2011-07-01")) )
#This echos when using PNGs, so put in it's own block and hide.
dev.off()
@


<<results=tex, echo=FALSE>>=
files <- list.files(pattern = glob2rx("ybygroup*.png"))
for(file in files){
    cat("\\begin{figure}")
    cat("\\begin{center}")
    cat("\\includegraphics{", file, "}\n\n", sep="")
    cat("\\end{center}")
    cat("\\end{figure}")
}
@

Link to gist

I still haven't fully got my head round pgfSweave and Tikz, but for individual plots you indicate the use of Tikz within the figure:

%Reference for pgfSweave / Tikz option
%Sweave file extract

\begin{figure}
<<fig=TRUE, tikz=T>>=
print(
    xyplot(Y ~ Date | Grouping, datatable[levels(datatable$Grouping)[1:8]], layout=c(1,8), ylim=c(-100,100), xlim=as.Date(c("2011-01-01", "2011-07-01")) )
)
@
\end{figure}

But I wanted to be able to produce all plots via a loop as per Sweave, rather than have to manually set up enough fig chunks so I came up with the following:

%Tikz loop
%Sweave file extract

\usepackage{tikz}
%...

<<results=tex, echo=FALSE>>=
#Need to know how many levels
nl <- length(levels(datatable$Grouping))
#then how many per graph
ng = 8
#Can then loop

for (i in 1:ceiling(nl/ng)) {
    cat("\\begin{figure}\n")
    cat("\\begin{center}\n")
    tikz(console=TRUE)
    start=(i-1)*ng+1
    end=i*ng
    print(
        xyplot(Y ~ Date | Grouping, datatable[levels(datatable$Grouping)[start:end]], layout=c(1,ng), ylim=c(-100,100), xlim=as.Date(c("2011-01-01", "2011-07-01")) )
    )
    dev.off()
    cat("\\end{center}\n")
    cat("\\end{figure}\n")
}

@

All of this looks and seems amazingly obvious as I write it up now, but it wasn't at the time. Especially because I came across this weird bug (which, thinking about it now, might not be a bug, rather a nuance of the data.table package - I need to investigate further):

works:

#Extract of R code
#This works as expected

#Need to know how many levels
nl <- length(levels(datatable$Grouping))
#then how many per graph
ng = 8
#Can then loop

for (i in 1:ceiling(nl/ng)) {
    start=(i-1)*ng+1
    end=i*ng
    print(
        xyplot(Y ~ Date | Grouping, datatable[levels(datatable$Grouping)[start:end]], layout=c(1,ng), ylim=c(-100,100), xlim=as.Date(c("2011-01-01", "2011-07-01")) )
    )
}

Link to gist

doesn't work:

#Extract of R code
#This doesn't work properly

#Need to know how many levels
nl <- length(levels(datatable$Grouping))
#then how many per graph
ng = 8
#Can then loop

for (i in 1:ceiling(nl/ng)) {
    print(
        xyplot(Y ~ Date | Grouping, datatable[levels(datatable$Grouping)[(i-1)*ng+1:(i*ng)]], layout=c(1,ng), ylim=c(-100,100), xlim=as.Date(c("2011-01-01", "2011-07-01")) )
    )
}

#Instead of using the start and end variables within the loop, the values are calculated directly
#as applied to the datatable. For some reason, from the 2nd loop onwards, `i*ng` seems to be 
#evaluated as `(i+1)*ng` which means Lattice automatically produces two pages of graphs, instead
#of just the one page per loop that it should. 

#This is probably just a data.table nuance actually, not a bug.

Since this just uses Tikz within a tex chunk, in theory pgfSweave isn't actually required to process this and just plain Sweave would do, in practice however, since pgfSweave can externalise the graphics by default, it will avoid text memory capacity issues with a large number of loops, where Sweave will run into them.

When I got the Tikz solution working, I actually decided to go back to the plain Sweave way of doing things as for me it was much faster (producing Lattice xyplots, especially with lots of data points, is slow via Tikz) and using the \includegraphics approach, the pngs scale better and you don't run into overfull \hbox issues. You just need to tweak the text sizes for the plots to look ok.

Since this, I've also come across a post which uses a latex loop (which I thought must be possible, but wasn't clever enough to work out), but then also goes on to mention Brew which looks interesting... and easier.

This is a link to a link, which I almost detest doing, but in this case I feel the notes I've added to my Pinboard bookmark merit it. I've been trying to figure this out on and off now for a couple of weeks. Resizing the VirtualBox VDI was the easy bit, getting the Linux guest to recognise and use the increased "volume" was where I was struggling.

Data.Table Dingleberry

It's not the first time (and I'm sure it won't be the last time) that I blindly copied, pasted and adapted code before fully understanding what's going on.

I had two sets of data ("Step 1" and "Step 2"), both of which looked something like this:

          id             Date
[1,]  1986524-23      2011-01-20
[2,]  2458768-21      2011-04-17
[3,]  2457845-24      2011-05-15
[4,]  4785874-32      2011-02-28
[5,]  7841111-12      2011-03-01
...

For each row in the Step 2 set of data, I wanted to find the matching IDs in Step 1, calculate the date difference(s) (since there could be more than one match), find the minimum date difference, and then add that into a new column into the Step 2 data.

I was being clever and using the data.table package (since it really is much, much speedier for lookups than using functions like subset(), but I was misled (because these examples abound!) by the help files and seeing things like this:

DT["a"]     # join to 1st column of key
DT[J("a")]  # same

(DT[J("a")] crops up a lot, but as far as I can tell (unless I'm completely ignorant) it is just a frivolous example as it's just doing DT[data.table("a")], and why on earth would you want to create a data.table just for "a"?)

And confused by the FAQ(PDF file), section "1.6 Ok but I don’t know the expressions in advance. How do I programatically pass them in?" and the use of eval() and quote(), etc, which (I think I've now twigged) are really for j expressions, not i expressions.

So I ended up with this:

step1.dt  <- data.table(step1)
setkey(step1, id)
duplicates.step2$days.between  <- sapply(
    1:nrow(duplicates.step2), #For each row in duplicates.step2
    function(q) {
        step2id <- duplicates.step2.dt[,id][q] #Gets the id
        temp  <- min(
            difftime(
                duplicates.step2.dt[, Date][q], #Gets the date
                step1.dt[J(eval(quote(step2id))]$Date, #gets the dates for all step1 rows of the same id. This is where it all goes wrong
                units=c("days")
            )
        )
    }
)

Link to gist

The eval and quote are doing NOTHING here, removing them gets the same result (and still takes just as long). For my case, doing the below was 2400%(!) faster:

duplicates.step2$days.between  <- sapply(
    1:nrow(duplicates.step2),
    function(q) {
        step2id <- as.character(duplicates.step2.dt[,id][q]) #as.character is important bit!
        temp  <- min(
            difftime(
                duplicates.step2.dt[, Date][q],
                step1.dt[step2id]$Date, #No need to crazily create another data.table
                units=c("days")
            )
        )
    }
)

Thought it was worth pointing out, just in case anyone else is as stupid as me and takes the trivial DT[J("a")] example at face value.

It wasn't meant to be this way

I had one of those sudden dawn-of-realisation moments last month: It just occurred to me that I was using Windows seven days a week. And yet if I thought back to over a decade ago, when I was buying my first computer (proper) I remember my operating shortlist was: OSX, BeOS or some flavour of Linux. Windows didn't even get a look in! (During University, as well as the norm of Windows NT in the lab and people using 98/ME at home, I'd got to use Solaris and Vax/VMS on my year out - so I was fortunate enough to at least know there were alternatives). At the time I did not consider myself geeky (capable) enough to use Linux. I would have loved to use BeOS, but - as far as I can recall from at the time - it's future was already looking dead. And of course OSX wasn't yet out, but the promise of the beta was enough to sway me to drop my graduate loan on an iMac. And the rest is history...

...or it should have been.

Ok, I knew I'd pretty much have to use Windows five days a week at work, but could live with that if I didn't have to at home, but with the advent of wife plus kids my computer quickly became the family computer which then soon became "the family, minus me" computer.

My work, for some obscure reason, provides me with a laptop as opposed to desktop and I'm free to take this home so I at least can have "my computer" again, but, "urgh!", Windows. So I started off using VirtualBox and Linux Mint for my home/personal use, but I was unsure if using and installing VirtualBox on a 'commericial' machine was really compliant with the licensing and technically you are still using Windows (even if only as a host), so I swapped to using Slax as then I could boot off a usb drive (even the miserly 512mb one I'd got for free from work) and all was well - I was much happier.

Then my work laptop was up for renewal and I got a brand spanking new one, which was all very nice, but I could no longer get my wireless to work with Slax, or anything else I tried so after a while I just gave up. Afterall, I thought, I spend most of my time immersed in Vim and Chrome, what does the OS matter? (Plus, at about this time, I still had possession of my iPod Touch more than the kids did so that became by primary computer; until it got squashed - hmm, perhaps that also spurred my "dawn of realisation moment").

I don't know what made me look, but recently Haiku popped upon my radar and I fancied giving it a whirl. From a networking point of view (i.e. actually being able to use the thing), using a virtual image looked like the best bet. Looking at VirtualBox again I realised that the licensing for the personal edition actually permitted 'commerical use', i.e. I could legitimately install this on my work laptop without dropping my employer or myself in it (the fact that I'm still not meant to install anything is by-the-by; shouldn't give everyone admin rights then). So I had a play with Haiku (I love it) and at some point whilst searching for information on VirtualBox I stumbled across a blog comment (I can't damn well find the thing now; have spent ages trying!) along the lines of "...my company insists we use Windows, so I just use VirtualBox to run the OS of my choice..." which immediately got me thinking: Why don't I just do that?

The majority of my computer usage is at work so being able to escape Windows for all seven days of the week would be amazing. My job had changed and no longer required specialist Windows specific software, work were just piloting Outlook Exchange 2010 so there was finally a decent web client should I fail to get any desktop software working with Exchange (likely), and there was a web client for our internal messaging service. All things considered, there was nothing really stopping me from switching.

And so I did. Haiku, as fun as it is, wouldn't cut it as a replacement OS so I went looking at Ubuntu (I had played with Ubuntu before), learnt about the whole Unity vs Gnome 3 thing, saw Gnome 3 and thought "Wow!" and went and downloaded Fedora 15. Well, kind of, I did have a go with Ubuntu first, but not for long.

So far, so good. I run Fedora full screen in VirtualBox and I don't really have to know I'm in Windows at all. And mostly don't have to go back... just for the odd document compatibililty issue and screen share.

Of course, after I've done all this and I'm bringing my work laptop home at weekends so I finally have something that resembles my own computer again... "Dad, can I go on your work computer...."

"Aaargh!!!"

I have (roughly) documented my experiences with living in a VirtualBox.

OS and Network Conditionals in Vim Configuration

A bit of a follow-up to this vim post since - as happens to all Vim uses - my .vimrc file has grown a bit in complexity. It's still nowhere as near insane as some people's, but has changed enough to make that post redundant. Oh, and so has the number of plugins I'm using.

I am still very much cross platform (as much Linux as possible, OSX when I get the chance and Windows when I have to; too frequently) so finally moved to using git submodules and pathogen to synchronise across platforms. I'm not making my dotvim repository public though, as - well - who the hell actually wants to read through someone elses .vimrc?

What is worth mentioning though is how you can use conditional statements in the .vimrc to really have just one file you can use anywhere.

OS Specific Configuration

This is a little more obvious and I'm sure lots of people do this. I'm using this approach by Mikolaj Machowski to set OS specific items, mainly font sizes, but also different settings for TwitVim. Note: OSX is "Darwin" and uname doesn't work on Windows so have this as my final else statement.

Network Specific Configuration

Not exactly tricky, but amazingly useful, is extending the above to make settings based on the network you are on. I.e. for me this is whether I'm at work or at home. So in the OS specific sections I'm looking to find the IP address (it's OS specifc since a different command is needed on each OS):

"OS Specific
"-----------
let os = substitute(system('uname'), "\n", "" ,"") "thanks to http://objectmix.com/editors/149466-operating-system-checking-vimrc-files.html#post517594
if os == "Linux"
    ...
    let ip = match(system('ip addr show'), "10.0.1")
elseif os == "Darwin"
    ...
    let ip = match(system('ipconfig getifaddr en1'), "10.0.1") "Or whichever enX interface you need
else "Assume windows as uname doesn't work on Windows   
    ...
    let ip = match(system('ipconfig'), "10.0.1")
endif

Link to gist

(I know at home my IP address will be in the range "10.0.1.X")

Then I can set proxies for TwitVim and SimpleNote.vim just for when I'm at work:

"IP Address specific
"-------------------
"(i.e. Home or Work)
if ip == -1
    "Set proxies, Python urllib2 (TwitVim, Simplenote.vim) will automatically pick
"these up  
    let $http_proxy = 'http://<username>:<password>@<proxy-url>:<proxy-port>'
    let $https_proxy = 'http://<username>:<password>@<proxy-url>:<proxy-port>'
endif

And that's a whole interesting thing in itself...

These are the ten most recent posts, for older posts see the Archive.