execute a command during boot as root

Problem
During the boot process you want to execute a command as root. For instance, I needed a symbolic link in /run, but /run is a virtual file system and its content is lost when you switch the machine off.

Solution
Edit the file /etc/rc.local . Example:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# this link is required by a project of mine
ln -s /media /run/media

exit 0

This tip is from here.

Categories: ubuntu Tags: ,

open a terminal in a specified folder

Problem
From a script I want to launch a terminal that opens in a specified folder.

Solution
Thanks to #linux, I got two solutions:

1) I use konsole, which has an option for this:

konsole --workdir /tmp

It will open a terminal in the /tmp directory.

2) Change directory to the specified folder and launch the terminal:

cd /tmp; konsole

If you want to do it from a script, the idea remains the same.


If you want to execute a command automatically in the opening terminal, use this:

konsole -e mc

Find more info here.

Categories: bash, linux Tags: , ,

resize an image to a given width by keeping the aspect ratio

Problem
You want to resize an image to a given width but you want to keep the width/height ratio of the image.

Solution

convert -resize 200 big.jpg small.jpg

Here the new width will be 200 pixels.

Categories: bash Tags: , ,

Google Maps knows where you are

If you type in Google Maps your name, it will show where you are located most of the time. It worked for me. Scary…

list your Firefox add-ons

Problem
I use several machines and I would like to create a unified list that contains my favourite Firefox add-ons. This list could be kept in Dropbox, thus I could access it on all my machines. How to generate a list of installed add-ons?

Solution
The add-on Addon List Dumper can do exactly this. Here is a screenshot about this add-on:

addons

Categories: firefox Tags:

how to sort 3 values

Problem
You have 3 values (e.g. three numbers), and you need to sort them. It could be a simple interview question to warm you up :)

Solution
The easiest way might be to use the good ol’ bubble sort. It can be done manually, without loops, since we only have three numbers.

Three values (let’s call them A, B, and C) are sorted, if A <= B <= C. Thus, the pseudo code to sort them is the following:

if A > B: swap(A, B)
if B > C: swap(B, C)    # the largest value is now in C
if A > B: swap(A, B)    # A and B are also sorted now

And now, let’s see it in C:

#include <stdio.h>

int main(int argc, char *argv[])
{
    int a = 8;
    int b = 7;
    int c = 6;
    int tmp;

    /* sort them in asc. order */
    if (a > b) {
        tmp = a; a = b; b = tmp;
    }
    if (b > c) {
        tmp = b; b = c; c = tmp;
    }
    if (a > b) {
        tmp = a; a = b; b = tmp;
    }

    /* print result */
    printf("%d <= %d <= %d\n", a, b, c);

    return 0;
}

Output:

6 <= 7 <= 8

Links

GitHub status page

https://status.github.com/messages

If GitHub is down or slow, visit the address above to figure out what’s going on.

Categories: Uncategorized Tags:
Follow

Get every new post delivered to your Inbox.

Join 78 other followers