How fast do you speak?

Interesting info. According to this article, you speak at a speed around 125 words per minute. Seems to be pretty true for me at least. Very useful to know when your are writing speeches.

Posted: May 4th, 2011
Categories: Uncategorized
Tags:
Comments: No Comments.

Enable touchpad in Ubuntu 10.10

If your touchpad doesn’t work after login, use this terminal command:

gconftool-2 --set --type boolean /desktop/gnome/peripherals/touchpad/touchpad_enabled true
Posted: December 20th, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Linux Dual Monitor Xorg Setup That Works With OpenGL

In order to make OpenGL create windows that are actually the indented size and not the (very) wide width of the dual monitor screen, add this line to your Screen section in xorg.conf:

Option "Metamodes" "DFP-0: 1920x1080 +1920+0, DFP-2: 1920x1080 +0+0; 1280x1024,1280x1024; 1024x768,1024x768; 800x600,800x600; 640x480,640x480; 1920x1080,NULL;  1280x1024,NULL; 1024x768,NULL; 800x600,NULL; 640x480,NULL;"

Edit it accordingly to include the modes you want. Note that it is the WIDTHxHEIGHT,NULL modes that enables OpenGL to create the windows with the correct desired size.

Posted: December 15th, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Linux-like non-focus window scrolling in Windows

I hate that Windows doesn’t have that nifty feature of Linux.
Luckily, a program called Wizmouse seems to do the trick.

http://helpdeskgeek.com/free-tools-review/scroll-in-any-window-without-focusing-on-it/

Posted: November 25th, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Automatically replace uploaded image with smaller one in WordPress

Found this here
And the other tip here

This is a lifesaver (or at least, disk space saver) when you have users who upload pictures directly from their digital cameras which are several megs in size.

Paste this into your functions.php file.

function replace_uploaded_image($image_data) {
    // if there is no large image : return
    if (!isset($image_data['sizes']['large'])) return $image_data;

    // paths to the uploaded image and the large image
    $upload_dir = wp_upload_dir();
    $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file'];
    $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file'];

    // delete the uploaded image
    unlink($uploaded_image_location);

    // rename the large image
    rename($large_image_location,$uploaded_image_location);

    // update image metadata and return them
    $image_data['width'] = $image_data['sizes']['large']['width'];
    $image_data['height'] = $image_data['sizes']['large']['height'];
    unset($image_data['sizes']['large']);

    return $image_data;
}
add_filter('wp_generate_attachment_metadata','replace_uploaded_image');

This might cause WordPress to yell something about add_filter not being defined. This is caused by plugin.php being loaded after functions.php, simply change this by changing

require( ABSPATH . WPINC . '/functions.php' );
require( ABSPATH . WPINC . '/plugin.php' );

into

require( ABSPATH . WPINC . '/plugin.php' );
require( ABSPATH . WPINC . '/functions.php' );

in wp-settings.php.

Posted: September 8th, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Kladdkaka

2 ägg
3 dl socker
1.5 dl vetemjöl
1.5 tsk vaniljsocker
1 krm salt
4 msk kakao
100 g smält smör

175 °C, ca 20 min.

Posted: May 9th, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

How to make Wine open links in your browser

This is how:

http://www.webupd8.org/2010/03/how-to-make-wine-open-links-in-your.html

1. HKEY_CURRENT_USER (a.k.a HKCU) -> Software -> Wine and look for a key called “WineBrowser”, if it does not exist, create it. Under the newly created “WineBrowser” key, create a string called “Browsers” with the following value:

xdg-open,firefox,konqueror,mozilla,netscape,galeon,opera,dillo

2. HKEY_CLASSES_ROOT -> http -> shell -> open -> command and edit the data value by adding “%1″ at the end of the line, so that it looks like this:

C:\windows\system32\winebrowser.exe -nohome "%1"
Posted: April 28th, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Enable aac, h264 and other restricted encodings in ffmpeg

These two threads describe excellent techniques for doing just that:
Advanced Version
Easy version

This one also helps:
Fixing ffmpeg on Ubuntu

The reason I had to do this in the first place was because I wanted to amplify the volume on the h264 encoded mp4 videos my digital camera recorded with the audio in aac format.

To increase the audio volume, simply do this:

ffmpeg -i infile.mp4 -vcodec libx264 -vol 2400 outfile.mp4

Where 2400 stands for increasing the audio volume by 2400% (yes, my microphone kind of sucks :/ )

Posted: March 4th, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Enable VPN routing via Firestarter

I had some trouble getting my VPN to work with Firestarter, so I’ll post this simple solution I found after some googling.

In Firestarter:
Go to Preferences->Network Settings.
Choose Ethernet Device (eth0) (yours may be different) as Internet connected network device.
Choose Routed IP Tunnel (tun0) (yours may be different) as Local network connected device.
Place a check mark in Enable Internet Connection Sharing box.
Stop and restart Firestarter.

Originally found here.

Posted: February 22nd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

JR syntax highlighting in gedit

There were no syntax highlighting for the programming language JR in gedit, so I wrote one myself.

This will work for Ubuntu 9.10, but it may work for others as well.

How to install:
1. Download jr.lang.
2. Place it in either

/usr/share/gtksourceview-2.0/language-specs

or

~/.local/share/gtksourceview-2.0/language-specs

3. Download jr.xml.
4. Place it in (create it if it doesn’t exist yet)

~/.local/share/mime/packages

5. Update the mine database:

cd ~/.local/share
update-mime-database mime

All done! You should now get JR syntax highlighting when opening .jr files in gedit.

Note: The directory paths are based on an Ubuntu system and might be different for other distributions.

Alternatively, you can just run this script to install it automatically:

wget -O jr.lang http://files.kerola.nu/?file=gedit_jr_syntax_hl/jr.lang
wget -O jr.xml http://files.kerola.nu/?file=gedit_jr_syntax_hl/jr.xml
mkdir -p ~/.local/share/gtksourceview-2.0/language-specs
mv jr.lang ~/.local/share/gtksourceview-2.0/language-specs/
mkdir -p ~/.local/share/mime/packages
mv jr.xml ~/.local/share/mime/packages/
update-mime-database ~/.local/share/mime
Posted: February 20th, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

How to find out and change file encoding in Ubuntu

First, you can find a file’s encoding like this:

$ file oldfilename.txt
oldfilename.txt: ISO-8859 English text

Then, if you want to convert the file oldfilename.txt from ISO-8859 to UTF-8 and call the new UTF-8 file newfilename.txt you do like this:

$ iconv -f ISO-8859-1 -t UTF-8 -o newfilename.txt oldfilename.txt

Note that the file command says ISO-8859 and that you have to use ISO-8859-1 in the iconv command.
For a long list of available iconv encodings, use

$ iconv -l
Posted: February 9th, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

How to Connect to Chalmers VPN in Ubuntu Karmic (9.10)

This example is for Chalmers PPTP VPN.
Server: vpn-gw.chalmers.se

1. Install network-manager-pptp.

sudo apt-get install network-manager-pptp

2. Add a new VPN connection in Network Connections. Choose PPTP, create.
3. Add the following and only the following

Gateway: vpn-gw.chalmers.se
User name: NET\your-username-here
Password: your-password-here

Click Advanced...
In Authentication, select only
CHAP
MSCHAP
MSCHAPv2

In Security and Compression select all and
Security: All Available (Default).

4. Restart your computer. This is important, don’t miss out on this one.
5. When back in Ubuntu, connect to Chalmers VPN, then click Deny when it asks
about the keyring. Enter your password for your account and then select Always Allow
when it asks about the keyring the next time.
6. Done!

Why all this restarting, denying, re-entering passwords and stuff you ask? It seems like there’s a bug in network-manager-pptp which will hinder you from connecting if you don’t follow the above procedure. Don’t ask me why this bug isn’t fixed, but I don’t think doing the above steps are that gruesome in order to get the simple functionality of an otherwise well-working VPN GUI for Ubuntu.

Posted: February 8th, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Jiffy Matmarknad

Jiffy Matmarknad, Guldheden, Göteborg.

Öppettider:

mån-fre 9 – 20

lördag, 9 – 17

söndag 11 – 17

Posted: February 8th, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Forest, random forest.

Additionally, it was winter.

Posted: February 3rd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Salmon skewer with bulgur

A delicious and yet simple dish.

Servings:
4
Preparation time:
10 minutes
Ingredients:
500g salmon
2 tbsp. cooking oil
1 tsp. salt
1 tsp. lemon-pepper
1 tbsp. sesame seeds
Bulgur:
4 dl bulgur
8 dl chicken stock
1 tbsp. neutral cooking oil
2 tbsp. chopped leek
1/2 zucchini
1/2 bell pepper
salt and grounded black pepper
Pesto sauce:
2 dl crème fraiche
2 tbsp. pesto

Pesto sauce:
Mix crème fraice and pesto. Let it cool down until serving.

Bulgur:
Trim and chop the leek finely. Cut the zucchini and bell pepper into cubes. Sizzle the leek and bulgur in oil in a deep, wide kettle. Pour 4 dl of stock and cook on low heat during constant stir. Add more stock as time goes by. When the groats are soft they are done. Finish off by adding zuccini and bell pepper along with salt and newly grounded black pepper.

Salmon Skewer:
Cut the fish into smaller bits and skewer them. Brush some oil on and season with salt and lemon-pepper. Add sesame seeds over it all. Grill the skewers until they get a nice color.

Posted: February 3rd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Installing Git on a shared webhost

This great article describes how to install git on a remote machine where you don’t have root access. It’s really useful if you want to use your web host’s server as a place to backup your code. You’ll need SSH access to the server though.

http://writepermission.com/2009/09/install-git-on-a-shared-webhost/

Just to make sure this information stays online, I’ve just made a copy of the article’s most useful part below:

This rpm needs to be installed, but you won’t be able to use the regular rpm installer because this requires root access. You can extract the rpm file with the command:

rpm2cpio git-1.6.x.x.rpm | cpio -imdv

This will create a usr/ directory in currect directory. You best move this directory to your home root:

mv usr ~/usr

Now we are almost there, we only need to add the directory to $PATH variable. Doing this will make it possible to execute the command git from anywhere. Open your ~/.bashrc file with your favorite editor (vim or pico) and add the following line:

export PATH=$PATH:$HOME/usr/bin:$HOME/usr/libexec/git-core

And that’s it. To activate this change, run source ~/.bashrc or log out and in again.

Posted: February 3rd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Get remote HTML with PHP

This piece of code retrieves the HTML code from a page, which you can then process and manipulate as you see fit. In the below example, the source code of my Last.fm page is retrieved.

<?php
// This variable will hold the code
$content = "";

// You have to divide host and the rest of the url,
// so in this example, the full url you wanted to get
// would be http://www.last.fm/user/CaseuS_
// As you can see, you don't have to specify the
// protocol used.
$host = "www.last.fm";
$url = "/user/CaseuS_";

// Open the connection on port 80
// $errno and $errstr can be used to
// get the error number and error message
// in case something went wrong.
// 30 stands for the timeout, in seconds,
// that we use for the connection attempt.
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp)
{
    echo "$errstr ($errno)<br />\n";
}
else
{
    $out = "GET $url HTTP/1.1\r\n";
    $out .= "Host: $host\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp))
    {
        $content .= fgets($fp, 128);
    }
    fclose($fp);
}

// Do something with $content, e.g. output the whole code:
echo $content;
?>
Posted: February 3rd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Google CSE Module URL Rewrite

I found a great tip regarding fully integrating the Google CSE module with the rest of your Drupal installation.

Basically, the tip I found to be really useful was the rewrite rules for the Google CSE search itself. Since Drupal comes with this built-in search module which is easily accessible at http://kerola.nu/search/your-terms-here, it’s really great to use Apache URL rewrite and redirect users from that Drupal search (which I think isn’t really that good) to the Google CSE result page. The only real change from the original page is the last line of the code, which sort of sums things up and enables the user to search directly from “search/your-terms-here”. Take a look at the code below!

In your .htaccess file, add the following lines:

RewriteRule ^search$ /search/google [R=301,NC,L]
RewriteRule ^search/node$ /search/google [R=301,NC,L]
RewriteRule ^search/node/(.*)$ /search/google?query=$1 [R=301,NC,L]
RewriteRule ^search/taxonomy_search$ /search/google [R=301,NC,L]
RewriteRule ^search/taxonomy_search/(.*)$ /search/google?query=$1 [R=301,NC,L]
RewriteRule ^search/((?!google).*)$ /search/google?query=$1 [R=301,NC,L]

Idea from http://www.mc-kenna.com/general/2008/12/tips-for-google-cse-plugin-for-d…
Thanks!

Posted: February 3rd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Fix endless redirection issue with Drupal Google CSE and Search 404 module

When using the Search 404 module and Google CSE (Custom Search Engine) together, the result is an endless redirection that will… well, you know, loop endlessly and stop you from doing more important things, like getting to your search results.

The problem occurs in at least Search 404 version 6.x-1.7.

This can be easily fixed by changing one line into two in the /sites/all/modules/search404/search404.module file.

On line 117, in function search404_page(), change

drupal_goto ('search/google/'. $keys);

into

$_REQUEST['destination'] = 'search/google/'. $keys;
drupal_goto();
Posted: February 3rd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Fix Spotify sound in Ubuntu Karmic (9.10)

When I first ran Spotify through Wine after just having had installed the new Ubuntu Karmic I immediately noticed that the sound from Spotify wasn’t the best, really. Actually, I’m being a bit too kind here. The sound was horrible! It sounded like the audio wasn’t decrypted or something like that since all I heard was a lot of noise.

Luckily, there is a solution to this.

  1. Make sure the package “wine1.2″ is installed:
    sudo apt-get install wine1.2
  2. Type winecfg in terminal, go into the Audio
    tab and change the following as below:
    Sound Drivers: Check both OSS and ALSA
    Hardware Acceleration: Full
    Default Sample Rate: 44100
    Default Bits Per Sample: 16
Posted: February 3rd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Shorten a text string

This piece of code shortens a text string to the specified length on a word basis and adds “…” after. Perfect for use in teasers of lengthy text pieces and so on.

<?php
/**
* Shortens a string to the specified number of characters on a word basis.
* Adds "..." to the end of the string if the string was longer than specified.
* Example 1
* $text = "The sky is not the limit, I know 'cause I feel higher today!";
* echo shortenText($text);
*
* Would print:
* The sky is not the limit, I know 'cause I feel higher today!
*
* Example 2
* $text = "The sky is not the limit, I know 'cause I feel higher today!";
* echo shortenText($text, 20);
*
* Would print:
* The sky is not the...
*/
function shortenText($text, $chars = 256)
{
    // Do not shorten if the text is already
    // shorter that the desired amount.
    if(strlen($text) <= $chars)
        return $text;

    $text = $text." ";
    $text = substr($text,0,$chars);
    $text = substr($text,0,strrpos($text,' '));
    $text = $text."...";

    return $text;
}
?>
Posted: February 3rd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Prevent hot-linking

Hot-linking is the act of someone showing an image from your site on a site that ain’t yours, meaning that you get no visitors or any kind of recognition for having the image on your site, but you’ll still have to pay for it with your bandwidth. That sounds kind of unreasonable, don’t you think?

So let’s learn how to prevent it by adding a few rows in our .htaccess file in the root of our website.

Add the code in the box into your .htaccess file to make it work.

# Anti-hotlinking
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?kerola\.nu/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]

The first row checks if the referer (i.e. the place on the Internet your visitor came from) isn’t your own domain.

RewriteCond %{HTTP_REFERER} !^http://(.+\.)?kerola\.nu/ [NC]

The second row checks if the referer isn’t empty, i.e. the user typed in the URL to the image directly in her browser.

RewriteCond %{HTTP_REFERER} !^$

The third row generates a HTTP 403 Error (Forbidden) if the two above conditions were met and the requested file type was one of jpg, jpeg, gif, bmp or png.

RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]

So in short, this code denies access to your image if you aren’t requesting it from kerola.nu or directly through the browser window. Exactly what we wanted! :)

Posted: February 3rd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Change Caps Lock Into Scroll Lock

The caps lock key is really useless and just a burden in everyday life. You accidentally hit it while typing and come out as a Rageaholic 9000 to the people around you.

So what can you do about this? Disable caps lock entirely, you say? Well, that is possible, but if you think about the whole situation for a second there, you’d soon realize that you’d be throwing a whole key away from your keyboard. While playing games (say) I sometimes wish I’d had an extra key right around the regular WASD area, so that I could bind it to something useful. If the whole Caps Lock key is disabled, that can’t be done. Therefore, let’s change the Caps Lock key into an equally useless key, but much more harmless key: Scroll Lock. Scroll Lock is also never being used, but nothing scary happens when you push it.

So let’s combine the Caps Lock’s dreamy position with the harmlessness of the Scroll Lock key shall we?

To do this, you need a mere simple registry hack.

Go to the following place:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout

Change the value of ScanCode Map to the value below, restart your computer and you’re done!

00000000 00000000 02000000 46003A00 00000000

If you’d like a bit more explanation of what this actually does then sure. Basically the ScanCode Map value is just a field wish tells Windows that we want to remap some key into another.

Let’s analyze those numbers a bit, shall we?

We start with

00000000 00000000

This is just here to waste space. Brilliant!

Then we have

 02000000

This number 2 in here stands for how many keys we are going to remap plus one. In this case, 1 + 1 = 2. Simple enough. The following zeros just waste space, again.

Then we get to the interesting section:

 46003A00

The first four numbers, 4600, stands for the scan code of the key we are going to map to. The last 4 numbers are the scan code of the key we are going to map from.
Luckily for us, 4600 is the scan code for Scroll Lock and 3A00 is the one for Caps Lock. So a little logic processing tells us that we are going to map the keyboard so that whenever you press Caps Lock, it will behave as if you’d pressed Scroll Lock. Just what we wanted! :)

The remaining

 00000000

just wastes some more space, nothing to worry about.

Don’t forget to restart your computer or it won’t work!

Posted: February 2nd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Nice urls with .htaccess

This code turns ugly urls full of parameters into user- and search-engine-friendly browser urls. And it’s totally automatic. This is a win-win-situation :)

Edit your .htaccess file like this if you want your urls to function like this:
http://domain.com/about -> http://domain.com/about.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
# http://domain.com/about -> http://domain.com/about.php

Or, if you want
http://domain.com/about -> http://domain.com/index.php?q=about

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# http://domain.com/about -> http://domain.com/index.php?q=about
Posted: February 2nd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.

Hello world!

This page is just a place for me to dump random stuff that I need to get off my mind but still don’t want to forget completely. So be prepared for a ruthless mind dump!

Posted: February 2nd, 2010
Categories: Uncategorized
Tags:
Comments: No Comments.
kerola.nu
ip track image