Sam's Site

  • Home
  • SCEditor
  • Contact
  • JavaScript check if a font is available

    Small function to check if a font is available to use on a web page. No external libraries required, just plain JS.

    How it works

    It works by first calculating the widths of the generic font families monospace, serif and sans-serif for the letters wi repeated 99 times. w because it's a wide and i because it should have a different width in monospaced and proportional fonts.

    To check if a font is available, the CSS font-family of the test node is set to the font with either monospace, serif or sans-serif set as the fallback. The widths are then compared to the pre-calculated widths of the fallback and if the widths don't match, it means the fallback wasn't used and the font is available. If the widths match, another fallback is used until all 3 fallbacks have been attempted.

    Read more…

  • Spotify Python Puzzles

    Not that long ago I discovered the Spotify puzzles and thought they would be a good excuse to improve my limited Python knowledge.

    So here are my attempts at solving the ”Reverse” and “Zipfsong” puzzles in Python:

    Read more…

  • How to install Aptana Studio 3.3.2 in Ubuntu 12.10 (Quantal Quetzal)

    Prerequisites

    Before anything else, install the prerequisites:

    sudo apt-get install openjdk-7-jre libwebkitgtk-1.0-0 git-core
    

    Although Aptana Studio doesn't officially support OpenJDK, I've yet to encounter any problem using OpenJDK with Aptana Studio.

    If you would rather use the Sun Java instead, do the following:

    sudo apt-get install libwebkitgtk-1.0-0 git-core
    
    # Java source: http://goo.gl/X0J6e
    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    sudo apt-get install oracle-java7-installer
    

    Read more…

  • How to install Cloud 9 IDE on Ubuntu 12.04 LTS (Precise Pangolin)

    The easiest way to use Cloud 9 is to simply use it online (in the Cloud) at c9.io.

    But if like me you want to run it on your own computer with Ubuntu 12.04, here’s how.

    1. Install the prerequisites

    sudo apt-get install -y build-essential g++ curl libssl-dev apache2-utils git libxml2-dev
    # Remove any previous version of node
    sudo apt-get remove nodejs
    

    Read more…

  • How to install Aptana Studio 3 on Ubuntu 12.04 LTS (Precise Pangolin)

    Update: An updated version of these instructions for Ubuntu 12.10 (Quantal Quetzal) is available here.

    1. Install the prerequisites

    sudo apt-get install openjdk-7-jdk libjpeg62 libwebkitgtk-1.0-0 git-core
    

    Read more…

← Older

© 2013 Sam Clarke.