2010-11-04
Går det att baka bröd med gammal torrjäst?
Ja, det är frågan. Jag skulle precis till att baka lite goda grahamsbullar till en fika med en kompis i kväll och var ganska säker på att jag hade torrjäst hemma. Det var bara ett litet problem: den var gammal. Bäst före-datum är juli 2010 och nu är vi inne i november. Skulle det fungera? Så. Klart. Gott mos, som vi säger här nere.
2010-10-20
Slight change of default Ubuntu 10.10 theme
Tonight I got sick of one tiny detail in the default Ubuntu theme.
First some background: I use the task panel a lot not only to select another application but also to minimize the task/application currently in focus. I do this because I think it is easier (and it *is* easier, read up on Fitt's Law for more details) to click the quite large task icon then it is to click the minimize button of the current window.
Now, the problem is that in the current default theme (at least I think it is the default, it is dark brow/grey with some purple stuff here and there and orange icons) you cannot easily and quickly see which of the tasks in the task panel is the selected one, if any. If you look carefully you will of course see it, but the difference in look/color is not much from the unselected ones. So I thought maybe I could figure out how to change it.
I was prepared for a long journey but just a few "locate" and "find" I was able to correctly guess what images that are used, and they are placed under /usr/share/themes/Ambiance/gtk-2.0/apps/img. The image in question is panel-button-active.png. I used sudo, chgrp and chmod to grant myself write access to that image (could have done the editing using sudo as well but I rather like to use my normal user) and then using The Gimp I simply filled the image with a new color that matched one of the purple ones already in use. I then had to force a reload of the panel and it was easy: $ gnome-panel --replace (you don't need to use sudo here). Voila! My new image is now used for the active task and it is much easier to see which task is active. Granted, it's not as nice looking but for me it is worth more to see it clearly.
After that change I discovered that I also wanted to change the hover image so that the purple image was not replaced by a brown/grey one. That one is named panel-button-hover.png and I used the same process as above to change that.
I have included the two changed images in this post in case you want to try it out too.
Enjoy!
panel-button-active.png:

panel-button-hover.png:
First some background: I use the task panel a lot not only to select another application but also to minimize the task/application currently in focus. I do this because I think it is easier (and it *is* easier, read up on Fitt's Law for more details) to click the quite large task icon then it is to click the minimize button of the current window.
Now, the problem is that in the current default theme (at least I think it is the default, it is dark brow/grey with some purple stuff here and there and orange icons) you cannot easily and quickly see which of the tasks in the task panel is the selected one, if any. If you look carefully you will of course see it, but the difference in look/color is not much from the unselected ones. So I thought maybe I could figure out how to change it.
I was prepared for a long journey but just a few "locate" and "find" I was able to correctly guess what images that are used, and they are placed under /usr/share/themes/Ambiance/gtk-2.0/apps/img. The image in question is panel-button-active.png. I used sudo, chgrp and chmod to grant myself write access to that image (could have done the editing using sudo as well but I rather like to use my normal user) and then using The Gimp I simply filled the image with a new color that matched one of the purple ones already in use. I then had to force a reload of the panel and it was easy: $ gnome-panel --replace (you don't need to use sudo here). Voila! My new image is now used for the active task and it is much easier to see which task is active. Granted, it's not as nice looking but for me it is worth more to see it clearly.
After that change I discovered that I also wanted to change the hover image so that the purple image was not replaced by a brown/grey one. That one is named panel-button-hover.png and I used the same process as above to change that.
I have included the two changed images in this post in case you want to try it out too.
Enjoy!
panel-button-active.png:

panel-button-hover.png:

2010-06-27
Kotänkbart
Nytt ord: kotänkbart - sånt som kor går och funderar på.
2010-06-26
List of Sony Ericsson Xperia X10 Mini hardware sensors
I tried to find a list of all hardware sensors that the SonyEricsson Xperia X10 Mini has and could not find any information about it, so I delved down into the Android Javadoc and wrote a small program to list them all. I am posting the list here in case someone else might have use for it.
First comes the name/ID/model and then the maker:
AK8973 Orientation - Asahi Kasei Corp.
AK8973 Orientation Raw - Asahi Kasei Corp.
AK8973 Magnetic - Asahi Kasei Corp.
AK8973 Temperature - Asahi Kasei Corp.
BMA150 accelerometer - Bosch Sensortec GmbH
APDS9700 Proximity - SEMC
MSM Lightsensor - SEMC
The question is now what exactly can be done with them? For example, for what do I use the magnetic sensor? I downloaded a compass program but that seemed to only use the GPS.
Anyway, enjoy!
First comes the name/ID/model and then the maker:
AK8973 Orientation - Asahi Kasei Corp.
AK8973 Orientation Raw - Asahi Kasei Corp.
AK8973 Magnetic - Asahi Kasei Corp.
AK8973 Temperature - Asahi Kasei Corp.
BMA150 accelerometer - Bosch Sensortec GmbH
APDS9700 Proximity - SEMC
MSM Lightsensor - SEMC
The question is now what exactly can be done with them? For example, for what do I use the magnetic sensor? I downloaded a compass program but that seemed to only use the GPS.
Anyway, enjoy!
2009-10-01
Bash completion for playing movie
Sometimes I play movies (mostly tv series) on my Ubuntu installation. The movie player I have got used to the most, and which can handle pretty much everything I throw at it, is mplayer.
I mainly use mplayer from the command line (I have GUIs for it installed too but don't use them much) and about a week ago I got tired of having to cd to my movie folder to play movies, or to type long path names, each time I wanted to watch a movie. I knew that bash has programmable completion so I set out to see how I could use that to get tab completion for all my movies regardless of where I am in the file system.
Getting it to work was a small adventure, let me tell you that. I started by looking under /etc/bash_completion and borrowed some snippets from there but soon I needed help so I went over to the gnu.bash.bug newsgroup and started a new thread.
It took a while to understand how it all fits together. Bash is very competent and the manual has a lot of details but in my opinion it is very terse and does not explain things in more detail that is really really necessary. If you don't grok everything about all the expansion and completion facilities it can be hard to dive in and get something like this working.
Anyway, with a lot of help I finally got it to work, and really well I must say. The main issues I had had to do with how to handle space and other metacharacters in file names, quoting/escaping them the correct way etc, and how to handle movie files in subfolders.
The solution concists of two parts: the programmable completion, consisting of one bash function and an accompanying call to the complete command, and a small bash script to start mplayer.
The bash function is responsible for finding all movie files and match them against the current user input. The work horse is the find program, for finding the movie files, in combination with grep, to filter the matches (it can theoretically be done using find only but then the solution does not become exactly how I want it).
The bash script is more or less just a wrapper around the mplayer program but it also prepends the movie folder path to the argument sent in. You will understand later.
Here is the bash function:
It's not very complicated once you get it working but the devil are in the details so I should comment it anyway:
First we set up some local variables.
Next we make sure the magic COMPREPLY array is made empty before we fill it with values used for the completion.
After that we need to get hold of the currently entered text on the command line, if any, and place this into the cur variable.
Next up is an if statement that will build the pattern to look for. This is not strictly needed but I wanted to be able to have one command that did prefix matching and one for substring matching, i.e. matching the beginning or anywhere in file names, respectively.
The pattern is finally used in the call to grep which filters all files found by find. I made it simple and only pick out avi files, since all my movies are in avi format. The P in the format string makes find skip printing the leading part of the path (otherwise that would be part of all completion candidates). The last part of the pipe is for shell quoting/escaping spaces and other shell metacharacters.
In the files variable all matching file names are separated by a newline so before we let the shell split it into array elements to be placed in COMPREPLY we must change the IFS field separator to a newline.
The last line in the function puts the completion candidates in COMPREPLY from where bash then reads it when the user asks to complete filenames.
The helper function _ms is used to get a substring matching version of the completion.
Next comes the calls to the complete command which is what activates the completion for various commands. The -F parameter says to get the completion candodates by calling a function and the _mm is the name of the function. The last parameter is the command name for which we want to add the completion:
Both the mp and ms commands are just symlinks to the main script, mm. They are only needed to control the two variants of completion (substring and prefix). I put both the functions and calls to complete in a file called ~/bin/bash_completion, together with other completion stuff, and source this file from my ~/.bashrc, like so:
Okay, I hope this can be as useful to others as it is to me. The technique, of course, could be applied to any similar needs you might have.
If you like, check out the discussion I started over at gnu.bash.bug,
it contains a lot more details which made this hack of mine end up the way it did
Happy completing!
I mainly use mplayer from the command line (I have GUIs for it installed too but don't use them much) and about a week ago I got tired of having to cd to my movie folder to play movies, or to type long path names, each time I wanted to watch a movie. I knew that bash has programmable completion so I set out to see how I could use that to get tab completion for all my movies regardless of where I am in the file system.
Getting it to work was a small adventure, let me tell you that. I started by looking under /etc/bash_completion and borrowed some snippets from there but soon I needed help so I went over to the gnu.bash.bug newsgroup and started a new thread.
It took a while to understand how it all fits together. Bash is very competent and the manual has a lot of details but in my opinion it is very terse and does not explain things in more detail that is really really necessary. If you don't grok everything about all the expansion and completion facilities it can be hard to dive in and get something like this working.
Anyway, with a lot of help I finally got it to work, and really well I must say. The main issues I had had to do with how to handle space and other metacharacters in file names, quoting/escaping them the correct way etc, and how to handle movie files in subfolders.
The solution concists of two parts: the programmable completion, consisting of one bash function and an accompanying call to the complete command, and a small bash script to start mplayer.
The bash function is responsible for finding all movie files and match them against the current user input. The work horse is the find program, for finding the movie files, in combination with grep, to filter the matches (it can theoretically be done using find only but then the solution does not become exactly how I want it).
The bash script is more or less just a wrapper around the mplayer program but it also prepends the movie folder path to the argument sent in. You will understand later.
Here is the bash function:
_mm() {
local cur files
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if [ "$1" == "substring" ]; then
pattern="${cur}"
else
pattern="^${cur}"
fi
files=$(find /home/mathias/Videos/movies/ -iname "*.avi" -type f -printf "%P\n" | grep -i "$pattern" | while read file; do
printf "%q\n" "$file"
done)
local IFS=$'\n'
COMPREPLY=(${files})
}
_ms() {
_mm "substring"
}
It's not very complicated once you get it working but the devil are in the details so I should comment it anyway:
First we set up some local variables.
Next we make sure the magic COMPREPLY array is made empty before we fill it with values used for the completion.
After that we need to get hold of the currently entered text on the command line, if any, and place this into the cur variable.
Next up is an if statement that will build the pattern to look for. This is not strictly needed but I wanted to be able to have one command that did prefix matching and one for substring matching, i.e. matching the beginning or anywhere in file names, respectively.
The pattern is finally used in the call to grep which filters all files found by find. I made it simple and only pick out avi files, since all my movies are in avi format. The P in the format string makes find skip printing the leading part of the path (otherwise that would be part of all completion candidates). The last part of the pipe is for shell quoting/escaping spaces and other shell metacharacters.
In the files variable all matching file names are separated by a newline so before we let the shell split it into array elements to be placed in COMPREPLY we must change the IFS field separator to a newline.
The last line in the function puts the completion candidates in COMPREPLY from where bash then reads it when the user asks to complete filenames.
The helper function _ms is used to get a substring matching version of the completion.
Next comes the calls to the complete command which is what activates the completion for various commands. The -F parameter says to get the completion candodates by calling a function and the _mm is the name of the function. The last parameter is the command name for which we want to add the completion:
complete -F _mm mp
complete -F _mm mm
complete -F _ms ms
Both the mp and ms commands are just symlinks to the main script, mm. They are only needed to control the two variants of completion (substring and prefix). I put both the functions and calls to complete in a file called ~/bin/bash_completion, together with other completion stuff, and source this file from my ~/.bashrc, like so:
. ~/bin/bash_completionThe mm command, a bash script which I also put in my ~/bin folder, is very simple and looks like this:
#!/bin/bashThe reason we prefix the filename with the root movie folder is that the completion function is made not to include it, for ease of typing.
mplayer "/home/mathias/Videos/movies/$1"
Okay, I hope this can be as useful to others as it is to me. The technique, of course, could be applied to any similar needs you might have.
If you like, check out the discussion I started over at gnu.bash.bug,
it contains a lot more details which made this hack of mine end up the way it did
Happy completing!
2009-03-13
2009-03-04
2009-02-08
2009-01-29
2009-01-10
Creating multiple shells in Emacs
Sometimes you want to have more than one shell going in Emacs. If you have tried that you know it does not work like you would have expected - you end up in the current shell buffer instead of getting a new one. So I created this small hack:
It prompts for a name for a new shell buffer. If none is given it will generate one for you. Naming shell buffers can be useful when you are doing a certain kind of work in a certain buffer and want to switch to that buffer easily using parts of the name.
Enjoy!
(defun new-shell (name)
"Start a shell with name NAME, or a generated name if empty.
Returns the name of the new shell."
(interactive "sName: ")
(let ((shell-name
(if (not (string= "" name))
(concat "*shell*<" name ">")
(generate-new-buffer-name "*shell*"))))
(shell shell-name)
shell-name))
It prompts for a name for a new shell buffer. If none is given it will generate one for you. Naming shell buffers can be useful when you are doing a certain kind of work in a certain buffer and want to switch to that buffer easily using parts of the name.
Enjoy!
2009-01-08
2008-12-26
2008-12-12
2008-12-06
2008-11-20
2008-11-18
I too want to write about Dired...
Inspired by this blog post by Greg Newman about Dired, Emacs' Directory Editor, I wanted to add a few tips myself - I love Dired! Most, if not all, of what I will write about is of course already there in the excellent manual, but it seems that some are as lazy as me and does not always read manuals, so... :)
First a couple of comments to the post Greg did:
Starting Dired
Starting Dired can be done from `C-x C-f' (find-file) as well. Just type a directory name instead of a file name. However, starting it using `C-x d' has certain advantages: you can, for example, enter a file name pattern and the listing will then be limited to that, even if you type `g' to refresh the listing. This can be pretty handy. Also, if you like you can get a recursive listing, a really powerful tool. To do that, use a prefix argument, `C-u', before you execute `C-x d'. You will be prompted for switches to ls. Add a `R' to the existing prompt and type `RET'. Voila! All the power of Dired to a whole directory tree.
Navigation
You can navigate as usual with `C-n' and `C-p' but also with the more convenient `n' and `p'.
Copying and renaming
When copying or renaming you can type arrow down or `M-n' to get the current file's name at the prompt. This is really handy when renaming files. It also works from normal buffers if you use `M-x rename-file' or similar.
You can change the case of file names using the commands `% u' (`dired-upcase') and `% l' (`dired-downcase'). I use it all the time when I have copied photos from my digital camera (I hate those uppercase names, especially the file extensions).
Marking
The basics
At first glance, the concept of marking files in Dired does not seem very special. You mark files with `m' and unmark then with `u' and marked files can be operated on in various ways. I would like to present some powerful tools. First you should learn about the kill command, by default bound to `k', which does not really kill/delete any file, it just removes the file from the listing. You can get it back with the normal `undo' command (available on `C-x u' and other key bindings). Then there is `t' for toggling the marks. Marked files become unmarked and unmarked becomes marked.
Marking by file name or content, and more cool tricks
You can also mark files by matching a regexp against the file name, with `% m', and against the content of the file with `% g'. Together with kill and toggle, these are really powerful tools. Let's say I want to search through all java files in a certain directory for the pattern `'PATTERN and get a listing of only those, after which I want to do some operations (copy, rename, whatever). First I open the directory of interest and do `% m \.java$ RET'. This will mark all files with the .java extension. Next I will kill the rest by first toggling the marks with `t', and then killing them with `k'. Next, use `% g PATTERN RET' to mark only those files that contain PATTERN. When the search is done I do the toggle-kill combo again, and Voila!, I see only the files I want and can do whatever I want to do with them. If you would mark or unmark files or kill files from the listing by mistake, just use undo. Simple as that.
These features alone make Emacs worth learning, at least if you do a lot of file juggling like I do.
The end?
I think this has to do for now. One last thing though: `wdired'. It lets you edit file names as if they were normal text in a buffer, with all the possibilities that gives you with search/replace, rectangle commands etc. It's under the Immediate menu in Dired, under the name `Edit File Names'. Edit the file names and save with `C-x C-s'. Crazily handy for cleaning your mp3-collection :)
I recommend everyone to check out the menus that becomes visible when using Dired. There are a lot of hiddens gems up there. And, of course, read the manual section for Dired for more crazy marking and stuff. Try out `M-x find-dired' some time as well.
Okay okay okay, I said I would stop, and I will. Now.
Thanks for listening!
First a couple of comments to the post Greg did:
Starting Dired
Starting Dired can be done from `C-x C-f' (find-file) as well. Just type a directory name instead of a file name. However, starting it using `C-x d' has certain advantages: you can, for example, enter a file name pattern and the listing will then be limited to that, even if you type `g' to refresh the listing. This can be pretty handy. Also, if you like you can get a recursive listing, a really powerful tool. To do that, use a prefix argument, `C-u', before you execute `C-x d'. You will be prompted for switches to ls. Add a `R' to the existing prompt and type `RET'. Voila! All the power of Dired to a whole directory tree.
Navigation
You can navigate as usual with `C-n' and `C-p' but also with the more convenient `n' and `p'.
Copying and renaming
When copying or renaming you can type arrow down or `M-n' to get the current file's name at the prompt. This is really handy when renaming files. It also works from normal buffers if you use `M-x rename-file' or similar.
You can change the case of file names using the commands `% u' (`dired-upcase') and `% l' (`dired-downcase'). I use it all the time when I have copied photos from my digital camera (I hate those uppercase names, especially the file extensions).
Marking
The basics
At first glance, the concept of marking files in Dired does not seem very special. You mark files with `m' and unmark then with `u' and marked files can be operated on in various ways. I would like to present some powerful tools. First you should learn about the kill command, by default bound to `k', which does not really kill/delete any file, it just removes the file from the listing. You can get it back with the normal `undo' command (available on `C-x u' and other key bindings). Then there is `t' for toggling the marks. Marked files become unmarked and unmarked becomes marked.
Marking by file name or content, and more cool tricks
You can also mark files by matching a regexp against the file name, with `% m', and against the content of the file with `% g'. Together with kill and toggle, these are really powerful tools. Let's say I want to search through all java files in a certain directory for the pattern `'PATTERN and get a listing of only those, after which I want to do some operations (copy, rename, whatever). First I open the directory of interest and do `% m \.java$ RET'. This will mark all files with the .java extension. Next I will kill the rest by first toggling the marks with `t', and then killing them with `k'. Next, use `% g PATTERN RET' to mark only those files that contain PATTERN. When the search is done I do the toggle-kill combo again, and Voila!, I see only the files I want and can do whatever I want to do with them. If you would mark or unmark files or kill files from the listing by mistake, just use undo. Simple as that.
These features alone make Emacs worth learning, at least if you do a lot of file juggling like I do.
The end?
I think this has to do for now. One last thing though: `wdired'. It lets you edit file names as if they were normal text in a buffer, with all the possibilities that gives you with search/replace, rectangle commands etc. It's under the Immediate menu in Dired, under the name `Edit File Names'. Edit the file names and save with `C-x C-s'. Crazily handy for cleaning your mp3-collection :)
I recommend everyone to check out the menus that becomes visible when using Dired. There are a lot of hiddens gems up there. And, of course, read the manual section for Dired for more crazy marking and stuff. Try out `M-x find-dired' some time as well.
Okay okay okay, I said I would stop, and I will. Now.
Thanks for listening!
2008-09-20
klibb.com nere igen
Så var det dags igen... I morse startade inte datorn. Som några kanske minns har den varit lite krasslig de senaste månaderna, och det har yttrat sig på det viset att när man trycker på startknappen så har det tagit ett par minuter innan datan varvat igång. Mycket besynnerligt. Troligen ett nätaggregatsproblem. Men, som sagt, i dag gick det inte längre så nu får jag väl ta tjuren vid hornen och skaffa ett nytt :(
2008-05-08
2008-05-06
Chassifläkt is the shit
Jag bloggade tidigare om min klickande dator som visade sig vara för varm. I dag dror jag äntligen å stad och inhandlade en sådan här goding:

Den är tyst (CPU-fläkten överröstar den) och hänger sitter fast i chassit med skojiga gummipluppar. Nu kan jag dra ner varvtalet på CPU-fläkten utan att tempen överstiger 60 grader. Men vid CPU-intensiva operationer, typ som att kåda en film för mobilen som jag precis gjorde, går tempen upp rejält, men då är det bara att höja varvatalet "ikraan".
Som dom säger, gott mos!

Den är tyst (CPU-fläkten överröstar den) och hänger sitter fast i chassit med skojiga gummipluppar. Nu kan jag dra ner varvtalet på CPU-fläkten utan att tempen överstiger 60 grader. Men vid CPU-intensiva operationer, typ som att kåda en film för mobilen som jag precis gjorde, går tempen upp rejält, men då är det bara att höja varvatalet "ikraan".
Som dom säger, gott mos!
Subscribe to:
Posts (Atom)