2013-11-29

Gäddfil

Åh så roligt!

Skulle skriva en inköpslista nu ikväll och stavade fel när jag skulle skriva gräddfil. Åh så roligt! Jag var bara tvungen att visualisera det.


Så, nu vet ni hur det skulle se ut med äkta 12-procentig gäddfil i kyldisken.

2013-04-13

Bookmarklet to open a Youtube video in a new window

Sometimes I want to work in some other window while watching a Youtube video. This little bookmarklet opens a new window/tab with the particular Youtube video on the current page, without any fluff around the video.

To install it, just drag this link to your bookmarks toolbar, or copy the link and make a new bookmark and paste the link content there. Here is the actual link content:

javascript:var url=document.location.href;if(url.match('http.?://(www.)?youtube|youtu\.be')){yid=url.split(/v\/|v=|youtu\.be\//)[1].split(/[?&]/)[0];window.open("http://www.youtube.com/v/" + yid + "&hl=en&fs=1");}else{alert("Could not find video ID")}

(you must include the "javascript:" part)

To use it, just click the bookmark when you have a Youtube page opened.

Enjoy!

2012-06-27

Using Emacs and ediff as an external diff tool

At work we have a program where one can configure an external diff tool to diff source code changes. Since I am used to work with ediff in Emacs I wanted to use it from that program as well. I ended up making a wrapper cmd file for it and thought I should share it in case someone else wants to solve the same problem.

Here is the script:


@echo off
REM c:\batfiles\ediff.cmd
set file1=%1
set file2=%2
REM Must convert the backslashes to slashes, otherwise they will be
REM interpreted as escape characters in the elisp strings. One can
REM also replace each backlslash with two backslashes to solve the
REM problem, but I like slashes better. Looks less messy.
set file1=%file1:\=/%
set file2=%file2:\=/%
%PATHTOEMACS%\bin\emacsclientw.exe -n -e "(ediff-files ""%file1%"" ""%file2%"")"

Replace %PATHTOEMACS% above with the real path to where you have installed Emacs. After that it's just a matter of selecting this cmd script as the diff tool.

Enjoy!

2012-05-09

Världens enklaste mobiltelefonställ?

MacGyver - släng dig i väggen!

När jag stog och diskade ikväll ville jag lyssna på ett TED talk och ställde som vanligt upp telefonen mot ett glas i köksskåpet. Dunk! Skåpshyllan var för hal och telefonen gled bara ned och la sig på rygg. Provade igen. Dunk. Hmm... Det är inte första gången jag gör detta och det är samma visa varje gång. Jag började tänka att jag nog borde köpa ett sånt där bean bag-ställ, eller liknande...

Men så - Eureka! Vad kan man annars använda för att göra hala saker mindre hala? Gummi... Hmm...

Gummiband!


Funkar hur bra som helst när man har något annat att luta telefonen mot men där underlaget är lite för halt. Och vem har inte ett gummiband eller två med sig i fickan, om inte annat för att göra något trolleritrick.

2012-03-25

Vad är en smidig deg?

Jag blir vansinnig! Eller ja, nästan i alla fall... I varenda recept på bröd jag läst står det att man skall arbeta degen smidig eller knåda degen smidig eller arbeta till en smidig deg (skrev lite olika varianter på uttrycken här så att de som har samma undringar som jag skall hitta denna sida).

Det står dock aldrig vad "en smidig deg" är. Troligen är detta något så allmänt känt att man aldrig förklarar vad det är, och var man inte tillräckligt uppmärksam på hemkunskapen verkar det som att man får skylla sig själv...

Nu tror jag att jag vet vad det är i alla fall. Degen är smidig när den precis släpper från bunken, dvs när den gått från att vara superklibbig till klibbig till hanterbar. Då har du fått en smidig deg.

Så, nu vet ni det.

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:

2010-06-27

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!

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:
_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_completion
The mm command, a bash script which I also put in my ~/bin folder, is very simple and looks like this:
#!/bin/bash
mplayer "/home/mathias/Videos/movies/$1"
The 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.

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-04

Mölndals brantaste backe


Uppför den här backen går jag med Emil en gång i veckan. Den är tuff, MINST 90 grader lutning, vilket både Wallén och Anders kan intyga. -- MaDa

2009-01-29

Gröna blad


Ute i skogen i dag hittade jag och Emil en buske med alldeles gröna fina blad. Nu undrar jag: vad är det för en buske och varför har bladen klarat sig?

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:


(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!

2008-12-26

Snöormen strikes back


I dag överraskades vi av den otäcka snöormen igen, denna gång i bilen. Läskigt!

2008-12-06

Min förtjänst?


När vi var och handlade på ICA förra året störde vi oss på att det var så svårt att hitta de ekologiska varorna i hyllorna. Vi la därför en lapp i förslagslådan. Ganska snart därefter upptäckte vi såna här skyltar i butiken. Sammanträffande?