sam's bits

ramblings on technology and other stuff
1

Export all your Last.fm scrobbles

Music listening data can be very interesting to analyse when combined with a GPS position (where did the user listen to what song?) and music data (danceability, bpm, mood) from Echonest. It could potentially show my “mood” in certain places and at certain times. With approximate speed from the GPS track you could see if on average I walk faster when listening to high-BPM music.

I’ve aquired my location history (>110000km) of the past 2 years from Google Latitude and exported it with Google Takeout to a JSON file. Getting the Last.fm data from my profile wasn’t as straight-forward, but it worked.

You need to get this Python script, that has been created by Libre.fm so their users can migrate to them from Last.fm:

Make sure you have Python installed and then execute the script like so:

./lastexport.py -u YourLastFmUsername ./scrobbles.txt

No API key or other credential is needed since everyones scrobbles are public. The script downloads all scrobbles with a unix timestamp, song title, artist, album and id into a tab seperated file.

You can download my file here.

Categories: Data Liberation

Tags: music, scrobbles, last.fm

Comments: 1 Comment

3

Install and enable Alternative PHP Cache (APC) on Ubuntu 12.04 LTS

If you want to speed up your website, a good option (apart from code optimisation, HTTP request reduction and the likes) is to enable opcode caching on the server. Most blogs and other dynamic websites on the internet run with PHP. There are many PHP accelerators and APC is open source, pretty easy to install and has many configuration options.

For a heavy application consisting of a large source code base such as Drupal, you can expect around a 3x increase in page generation speed as a result. - List of PHP Accelerators on Wikipedia

First you need to install PEAR and dev packages, this is Ubuntu specific but similar on other platforms.

  • apt-get install php-pear
  • apt-get install php5-dev
  • apt-get install make
  • apt-get install apache2-prefork-dev

Once that’s done, install the APC module with pecl:

  • pecl install apc

Go with the defaults, if you don’t know better. If the module has been succesfully installed, don’t forget to add the extension to your php.ini somewhere:

  • extension=apc.so

Check out all the configuration options

Now that you’ve installed APC, just restart your webserver (e.g. sudo service apache2 restart) and your PHP is now “accelerated”! APC provides a web interface with detailed information on the cache (memory usage, hits & misses, cache entries). By default it is not accessible so you need to copy the file /usr/share/php/apc.php to somewhere you can browse to.

Categories: PHP, Ubuntu

Tags: php5, apc, apache2

Comments: 3 Comments

2

Easy and fast LaTeX editing with Sublime Text 2 and Skim PDF Viewer

I recently had to write a couple of letters and didn’t want to use Word, Pages or Google Docs. They’re all great word processors, but all require a lot of effort to set the template up correctly or get the spacings right. LaTeX is a great option for people who like to focus on their content without worrying about the representation. Write up your stuff and LaTeX can by default produce a beatiful result. Customisations are possible of course.

You could use an editor like TexShop or Lyx, but if you like it bare-bones and use Sublime Text 2 for development anyway, then you might as well write your LaTeX documents with it. The macros, shortcuts and snippets functions are what make Sublime Text 2 great. And creating a PDF out of your LaTeX is done with a simple shortcut.

Here’s a straight-forward guide to get you going (if you’re running Mac OS X):

  1. Download and install MacTeX
  2. Download and install Sublime Text 2
  3. Download and install the Sublime Package Control
  4. Download and install Skim PDF Viewer (required by the Sublime Plugin)
  5. Open up Sublime Text 2 and hit “cmd+shift+p”. Search for “Install Package” and hit return.
  6. In the package list, search for “LaTeXTools” and hit return. The plugin will be installed.
  7. Done!

Open up your TeX file and hit “cmd+b” which will create a PDF and open up the Skim PDF Viewer. To get you started you can just copy the TeX below which is a standard letter for Switzerland:

\documentclass[%
    fontsize=11pt,%
    version=last,%
    foldmarks=false,%       
    refline=dateleft,% 
    paper=a4,% 
    fromalign=left,% 
    fromrule=aftername,% 
    backaddress=false,% 
    parskip=half,% 
    enlargefirstpage=true% 
]{scrlttr2} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[scale=0.81]{geometry}
\usepackage{%
    ngerman,
    graphicx,
    url,
    lmodern,
    paralist}

\renewcommand*\familydefault{\sfdefault}

\setkomavar{fromname}{\newline \newline Max Muster}         
\setkomavar{fromaddress}{Musterweg 7\
                        8000 Zürich} 

\setkomavar{signature}{ \newline Max Muster}        
\setkomavar{subject}{Gesuch um ein Schmorbraten}
\setkomavar{place}{Zürich}  

% die signatur ist linksbuendig
\let\raggedsignature=\raggedright

% Manche finden, dass scrlttr2 so eine riesige Fusszeile hat 
% einfach die nächste Zeile auskommentieren, dann wird sie kleiner:
% \setlength{\footskip}{pt}     

\begin{document}
\begin{letter}{Barbara Bonus \ Bankengasse 7 \ 8000 Zürich}         

\opening{Sehr geehrte Damen und Herren,}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
 tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
 quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
 consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
 cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
 proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 

\closing{Mit freundlichen Grüssen}

\begin{compactitem}[-]
\item Lorem
\item Ipsum
\item Dolor
\item Sit
\end{compactitem}

\end{letter}    
\end{document}

Categories: LaTeX

Tags: skim, latex, sublime text 2, letter template

Comments: 2 Comments