Skip to content

Home

Vim re-edit file as root

Have you ever found yourself in a situation where you’ve edited a file for quite some time, only to find out that you get a “Permission Error” when trying to save the changes? If vim is your editor, and you have sudo-privileges, try doing this:

:w !sudo tee %

Does the trick. :)

iPad and Comicbooks

So what can I say. I finally succumbed and bought an iPad. Mainly because my friend Kevin kept nagging me about how wonderful it was. Bastard. Gríma Wormtongue is his new nickname. I’ve had my iPad for a couple of weeks now.

But seriously though, the iPad is doing great stuff for me. I’m using it for all sorts of purposes, and the one I’m going to bring up in this case is reading comicbooks. I use an application called Comic Zeal. Now, I’ve never been a particularly avid reader of comicbooks, but I remember back during my younger years when I sat at the library, reading every edition of Elfquest that I could get my hands on. So years (yeaaaaars) later, I finally wanted to give it a try again. That’s where Comic Zeal comes into play.

comiczeal

Comic Zeal is an application able to (taken from their site):

  • Organize your comics using Series and Dividers, don’t look through hundreds to find the one you want.
  • Search and find your comics by title. On the iPad you can tag your comics for even easier searching.
  • Use Comic Zeal‘s copy function to organize your collection in amazing ways.
  • When you finish reading one comic, Comic Zeal automatically opens the next one.
  • Avoid seeing the same borders page after page with Comic Zeal’s zoom lock.
  • Load your comics through USB or wi-fi using iTunes file sharing, or other apps like Drop Box!

It really works great, I can truly recommend it.

Now, I’ve only come across a few good comicbooks so far, but the ones I can recommend are:

American Vampire

americanvampire

The series imagines vampires as a population made up of many different secret species, and charts moments of vampire evolution and inter-species conflict throughout history. The focus of the series is a new American bloodline of vampires, born in the American West in the late 1800s. The first of this new species is a notorious outlaw named Skinner Sweet, who wakes from death, after being infected, to find he has become a new kind of vampire, something stronger and faster than what came before, impervious to sunlight, with a new set of strengths and weaknesses.

The Walking Dead

thewalkingdead

The Walking Dead is a monthly black-and-white comic book series chronicling the travels of Rick Grimes, his family, and other survivors of a zombie apocalypse. Shot in the line of duty, Kentucky police officer Rick Grimes wakes from a coma in the hospital to find his town filled with walking corpses.

Witch Doctor

witchdoctor

Witch Doctor combines elements of the horror and medical drama genres. The protagonist, Dr. Vincent Morrow, is a maverick doctor who specializes in “supernatural medicine,” supplementing common medical practices with magic. Dr. Morrow’s “cases” predominantly involve infectious supernatural creatures like vampires, demonic possession, as well as elements based on the cosmic horror of H.P. Lovecraft. In the first Witch Doctor mini-series, Dr. Morrow treats (and battles) a vampire, demons possessing a child, faerie changelings, and Deep Ones (crossed with the Creature From the Black Lagoon), among others.

So there you have it! If you have any other suggestions (I’ve been recommended Sandman, Fable and Y: The Last Man so far), let me know!

Batch convert videos using Handbrake and a script

So I mainly use Linux, but for some tasks I turn to Windows. In this particular case it was setting up my iPad so that my wife could take it to Spain with her, packed with movies, to entertain the kids. This included the use of iTunes. I’m sure there’s some way to make it work in Linux as well, but I thought I’d write a post based on a solution I found in Windows, for once.

I needed to convert existing .avi-files to the format the iPad uses. This is where the program Handbrake comes into play. It’s excellent for converting from one format to another, but it’s the batch-convert part that isn’t too good. So how to solve this? Well, first install Handbrake, then proceed to create a .bat-script in the directory that contains the .avi-files. I do realize that Handbrake has a Add to queue function, but that sort of takes away the point of batch-converting. Rather I specify a folder, then it convert every file in it, than me adding a file manually one by one.

Open up Notepad, and place the following bit of text in it:

FOR /F "tokens=*" %%G IN ('DIR /B /S *.avi') DO "C:\Program Files\Handbrake\HandBrakeCLI" -i "%%G" -o "%%G".mp4 --preset="iPad"

When saving the file, remember to select All files on the Save as type-field. Then type in script.bat in the File Name field.

So when you’re done with this, it’s just a case of double-clicking the script to batch convert all of the .avi-files in the directory the script is placed in.

Oh, another word of advice. Make sure your Windows-machine doesn’t hibernate or go to sleep. I learned that the hard way.

How to Google more efficiently

Most people these days use google.com as their preferred search engine, and most times a regular search will bring you the results you are looking for. But what if you want a more complex search? Or want to filter out some results? Well, here’s a few pointers on how to Google a bit more efficiently, and some other neat tricks.

Say that I want to search for a review for the cellphone HTC Desire Z. I could always use the string “HTC Desire Z review”. Or, we could do a more efficient search.

Take the following search string as an example:

site:engadget.com ~review “htc desire z” -amazon 2010..2012

Let’s break it down:

  • site:engadget:com – Only searches the pages of the site engadget.com
  • ~review – Also searches related words, such as “check, examine, opinion”.
  • htc desire z – Searches for the exact phrase, and not each word separately.
  • -amazon – Excludes this term from the search.
  • 2010..2012 – Shows all results from within the specified timerange.

The last element above not only works with a time-range, but also with any other type of range. For instance:

  • $100..$200

..gives you results based on a range from $100 to $200.

Searching for filetypes

In certain cases you want to search for specific types of file. For instance,

filetype:pdf linux intitle:best *distribution

Again, lets break this down:

  • filetype:pdf Searches only results of the file type you specify. .doc, .jpg, .torrent, the options are endless. Close to, anyway.
  • linux – Just a regular search string.
  • intitle:best – Only shows results with that word in the title (in this case, ‘best’)
  • *distribution – Replaces itself with common terms in your search (in this case ‘Arch Linux distribution’, ‘Red Hat distribution’, will both be searched, among many others)

Definitions

To find the definition of a word, use:

define: exquisite

Unit converter

Converting from one unit to another made easy:

Distance

54 km to miles

Weight

2 kg to lbs

Currency

150 NOK to USD

Calculator

Also works great as a calculator:

20*(2+4)/5-1

Time

Check out what the time is in another part of the world:

time Hong Kong

Weather

Also handy for checking the weather:

weather Oslo

Just a few of the things one can do with the Google search engine!

BASH autocomplete for SSH

If you, like me, find yourself SSH’ing all day long, this little piece of code will do wonders. Well, it’ll save you some keystrokes at least. This line parses your .bash_history-file and tries to autocomplete the host you are trying to SSH to, given that you’ve already used SSH to access the host in question at least once before.

So, to make this work, place the following in your .bashrc or .bash_profile file:

complete -W "$(echo $(grep '^ssh ' .bash_history | sort -u | sed 's/^ssh //'))" ssh
source .bashrc

..to apply the change made to your .bashrc, if that’s the file you’ve made the change to. You should now be able to autocomplete hosts when SSH’ing with TAB.

Update: I am also (now) aware of, thanks to my colleagues, that you have to tweak and sometimes install additional packages to have a similar functionality provided by your system’s package manager. I find the solution above the easiest one, as it’s only a single line that needs to be included in a file, without any additional tweaks or packages necessary. But in the end, it’s your call!

P4 nettradio på Linux

Skulle du ønske å høre på P4 sin nettradio uten å måtte ha et nettleservindu åpen, kan du bare peke din mediaspiller (som f.eks. vlc eller mplayer) direkte til strømmen. Hvis vi bruker mplayer:

For P4:

mplayer mms://mms-cluster2.nextra.no/P4_Norge

For P4 Bandit

mplayer mms://mms-cluster2.nextra.no/P4_bandit

Bare erstatt mplayer med vlc, eller noe annet, skulle du ønske å endre mediaspiller som benyttes.

Ubuntu, Citrix, and SSL-error 61

I just attempted to install the newest Linux Citrix ICA client for a colleague, on Ubuntu, and upon a successful install, an error similar to this one popped up when trying to run the client from Firefox:

SSL error
Contact your help desk with the following information:
You have not chosen to trust”/C=US/ST=/L=/O=Equifax/OU=Equifax Secure Certificate Authority/CN=”,
the issuer of the server’s security certificate ((SSL error 61).

The solution to this? Make Firefox’s certificates accessible to Citrix, like so:

sudo ln -s /usr/share/ca-certificates/mozilla/* /opt/Citrix/ICAClient/keystore/cacerts

That should do the trick!

Nginx - Error 413 - Request entity too large

The default maximum body size of a client request, or maximum file size, that nginx allows you to have, is 1M. So when you try to upload something larger than 1M, you get the following error:

413: Request Entity Too Large.

Changing your php.ini-settings alone won’t do much. So to fix this problem, follow these steps.

Open up your nginx.conf-file, with an editor of your choice:

vim /etc/nginx/nginx.conf

..and add client_max_body_size to the http-section:

client_max_body_size 20M;

Save and close the file, apply the changes to nginx, and reload:

/usr/sbin/nginx -t
/usr/sbin/nginx -s reload

Try uploading again. Should be working. :)

Wallpaper concatenation with ImageMagick

At both home and work, I have a dual monitor setup. Having recently discovered the windowmanager xmonad, I’ve found a setup that enables me to use Xinerama, and at the same time have the functionality that a separate X screen-setup would provide me. But with Xinerama comes the Twin View-setting that the Nvidia drivers provide, which “merges” both monitors, and gives me one large virtual desktop. Finding wallpaper for it can be a bit tricky, especially the ones that are designed for one specific resolution. But this is where ImageMagick comes into play. What I want is two images, with different resolutions, side by side. You could of course use something else, like GIMP, but you’d have to align things manually, and why risk it when a simple command can do the trick?

First install ImageMagick:

yum install ImageMagick

..then do the magic:

montage wallpaper_1920x1080.jpg wallpaper_1680x1050.jpg -tile 2x1 -geometry "1920x1080+0+0" -mode concatenate final_wallpaper.jpg

By setting geometry to “1920×1080+0+0”, we set the preferred size of one of the tiles to be that, thus resizing images that are too large.

The results? Well, for me, this was it:

xmonad_wallpaper

Enjoy!

Making your BASH history more efficient

There are several ways to improve how you troubleshoot a system. One of the things I consider to be important is the BASH history. Here you can see what commands were executed. Though as default you can’t see when, or ignore certain things, like duplicate commands. Here’s a little guide to show you how.

Notice: To make these features a permanent solution, open up your /etc/profile, and add the lines to the bottom of the file. Save and close it. The next time you log in the functions should be working as you specified them!

HISTTIMEFORMAT

A simple yet effective little trick is to change the format of the output the command history spits out. In my case it comes to good use when troubleshooting a system, wanting to find out if errors in the system log match up with commands executed at that time. To enable the feature in your current terminal, run:

export HISTTIMEFORMAT="%h %d %H:%M:%S> "

So the output from history that was looking like this:

[jorge@ashitaka ~]$ history
1 ls
2 echo "Hello"
3 pwd
...

Now looks like this:

[jorge@ashitaka ~]$ history
1 Mar 24 12:53:35> ls
2 Mar 24 12:53:36> echo "Hello"
3 Mar 24 12:53:37> pwd
...

HISTCONTROL

The variable HISTCONTROL can do a few things, like ignoring duplicates if they are in a row and erasing duplicates. The difference here is that by ignoring duplicates, it will remove duplicates only if they are in a row, while erasing duplicates, it will remove previous commands from the history file. Let’s give an example:

ignoredups

First run:

export HISTCONTROL=ignoredups

The output that looked like this:

[jorge@ashitaka ~]$ history
1 pwd
2 echo "Hello"
3 ls -l
4 ls -h
5 pwd
6 pwd
...

Will now look like this:

[jorge@ashitaka ~]$ history
1 pwd
2 echo "Hello"
3 ls -l
4 ls -h
5 pwd
...

erasedups

erasedups means that if you executed the same command previously, that entry will be erased, substituted by the newly run command. Generally not recommended though. If you still wish to do so, it can be done by running the following line:

export HISTCONTROL=erasedups

So a history that looked like this:

[jorge@ashitaka ~]$ history
1 pwd
2 echo "Hello"
3 ls -l
4 ls -h
5 pwd
...

After the export, will now look like this when we run the command pwd again:

[jorge@ashitaka ~]$ history
1 echo "Hello"
2 ls -l
3 ls -h
4 pwd
...

ignorespace

If you want full control over which commands will be stored by history and which will not be stored, set HISTCONTROL to ignorespace:

export HISTCONTROL=ignorespace

So out of these commands:

ls -la
 du -h
ps

Only these will show:

[jorge@ashitaka ~]$ history
1 ls -la
2 ps
...

ignoredups and ignorespace

To use both of these features, simply use:

export HISTCONTROL=ignoreboth

HISTIGNORE

The variable HISTIGNORE will help you tell history which commands to ignore, meaning that they shouldn’t be picked up by the BASH history. For instance, let’s say that I want the commands df and free to be ignored, including optional flags:

export HISTIGNORE="df*:free*"

HISTSIZE

Setting how many lines of history to store is always a nice feature:

export HISTSIZE=10000

Thanks to pkhamre for suggesting to include HISTCONTROL and HISTIGNORE. ;)