Parsing a Link header in Javascript.

Recently I found myself in dire need of a Link header parser. Not finding anything useful (or built-in!) I had to write one myself. Here it is.

Basically, let’s say you have a bunch of Link headers in your response:

Link: <http://example.org/.meta>; rel=meta, <http://example.org/.acl>; rel=acl

All you need to do now is to pass them to the parser like this:

var r = parseLinkHeader(xhr.getResponseHeader('Link'));

Then, based on the rel type you are interested in, you just get the href value:

r['acl']['href'] outputs http://example.org/.acl

Continue reading

Improve SSD performance with fstrim

It seems that SSD performance decreases over time, since unlike hard disk drives (HDDs), NAND flash memory that make SSD cannot overwrite existing data. This means that you first have to delete the old data before writing new one.

Flash memory is divided into blocks, which is further divided in pages. The minimum write unit is a page, but the smallest erase unit is a block. This means that as time goes on, the SSD will internally fragment the blocks among the different pages, until that it reaches a point where there won’t be available any empty page. Then every time the drive needs to write a block into any of the semi-full pages, it first needs to copy the current blocks from the page to a buffer, then it has to delete the whole page to finally rewrite the old blocks along with the new one. This means that as time goes on the SSD performance degrades more and more, because for every write it has to go through a cycle of read-erase-modify-write. This is known as “write amplification”.
Continue reading

Releasing RWW.IO

Dear all! I am proud to announce the release of RWW.IO, a “personal cloud” service for your Linked Data. It offers access control and WebID authentication.

Since RWW.IO is intended to be used as a backend service for your Linked Data applications, the UI is minimal, allowing you to edit RDF documents and set ACL rules. Users can also upload a limited range of images (PNG, JPG and GIF – for all your cat pictures, wee!).

If you would like to run your own service, just grab the code from https://github.com/deiu/rww.io and get started! It is a free service, paid entirely from my personal founds and created in my free time, so please consider supporting this project if you like and use it.

Thank you!

Ubuntu Touch – PIN operations.

If you have just flashed Ubuntu Touch on your phone and you can’t seem to make/receive calls or SMS, then probably your SIM card requires a PIN to be unlocked. Since there is currently no UI for unlocking the SIM card, I have put together a short guide on how to do it through the command line.

This guide starts from the premise that you have already installed adb tools, and also that you have absolutely NO connectivity on the phone.

Update: it seems that ofono-scripts comes pre-installed in the latest builds, so you can skip directly to step 5.

Continue reading

Remove files from your entire Git history.

In case you forgot to remove sensitive or binary files from your Git repository, here is a quick script which aims to remove all said files from all you previous commits. You can run it like this:
sh script.sh file1 dir1

 


#!/bin/bash
# Script to permanently remove files/folders from your git history.  To use 
# it, cd to your repository's root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2

set -o errexit

if [ $# -eq 0 ]; then
    echo "Usage: $0 file1 file2"
    echo "   or: $0 path1 path2"
    exit 0
fi

# make sure we're at the root of git repo by checking for a .git dir
if [ ! -d .git ]; then
    echo "Error: must run this script from the root of a git repository"
    exit 1
fi

# remove all paths passed as arguments from the history of the repo
files=$@
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $files" HEAD

# remove the temporary history git-filter-branch otherwise leaves behind for a long time
rm -rf .git/refs/original/ && git reflog expire --all &&  git gc --aggressive --prune

Andrei

Disabling F10 key functionality for MC in Ubuntu.

If you use MC a lot, you probably know how annoying it is when you press F10 to quit and a menu pops up. To disable the F10 key functionality (right-click emulation) in Ubuntu 12.04, type the following commands in a terminal:

mkdir -p ~/.config/gtk-3.0
cat <<EOF > ~/.config/gtk-3.0/gtk.css

@binding-set NoKeyboardNavigation {
     unbind "<shift>F10"
}

* {
     gtk-key-bindings: NoKeyboardNavigation
}

EOF

To make sure it works, you have to exit (restart) all terminal sessions you have. I’m not sure if this fix applies to all versions of Ubuntu, but it definitely works for Ubuntu 12.04.

Andrei~

Working with Git submodules

As the title says, this post is about working with Git submodules. In case you don’t know what this is, here’s a quick example.

Say your application depends on an external library called ‘ext_lib’. Some people may want to package their application with a modified version of ‘ext-lib’, though others would rather just link to the latest version. When creating a submodule, what actually happens is that a link is added, pointing to a specific version (latest commit) of that external repository.

Continue reading

CUDA gpucomputingsdk-4.2.9.linux compile on Ubuntu 12.04 LTS fails with undefined reference to ‘gluErrorString’

HAY GUISE.

Once again, the common.mk files in CUDA SDK are not completely usable and minor adjustments are required.

Out of the box compile gives you errors like:

../../lib/librendercheckgl_x86_64.a(rendercheck_gl.cpp.o): In function `CheckBackBuffer::checkStatus(char const*, int, bool)':
rendercheck_gl.cpp:(.text+0xfbb): undefined reference to `gluErrorString'

Quick fix is the following as I have found out from these sources.

Continue reading