Reload Chrome with xdotool

I found it to be rather tedious to switch between vim and my browser just to refresh it. Sure, there are some extensions to auto-reload on file change. But what happens if you're change, say, the database?

Come on, it's way cooler to do this on a keyboard shortcut.

#!/bin/bash
xdotool search --onlyvisible --class "Chrome" windowfocus key 'ctrl+r'

See screenshot for an example how to register a global shortcut in Linux Mint.

Extended version:

I extended the script with a "switch the focus back to the last window".

#!/bin/bash

focused_window_id=$(xdotool getwindowfocus)                             # remember current window
xdotool search --onlyvisible --class "Chrome" windowfocus key 'ctrl+r'  # send keystroke to refresh
xdotool windowactivate --sync $focused_window_id                        # switch window, sync to "wait"

Why move to ZSH

  • Have found this great article today and would like to share it with you guys ( and archive it here ).
  • Super easy installation with oh my zsh.

Network fails on a fresh Ubuntu Clone

Short: The System remembers its old MAC address, remove it so it knows where to bind eth0 to.

sudo vim /etc/udev/rules.d/70-persistent-net.rules

remove "your old MAC addresses", and change your "new one" to eth0.

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:fb:d5:1e", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:fb:d5:1c", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Source

dist-upgrade on Ubuntu XEN Guests

Short: Don't even think about it.

Fuck it. I tried to migrate several Ubuntu Hardy maschines (XEN guests) in the past view months. Since, yeah - you know: it's an unsupported LTS. The first broke due to an interupted SSH connection. Yeap, they warned me. My fault.

Then I got smarter, and upgraded trough a SSH connection to the XEN host which then connected (somehow) to serial port. Upgrade seemed (always) to go fine. Took a while and a lot of "NO dont modify my config file". In 4 cases the upgrade went through, requested a reboot and was gone for good. In 2 cases it stopped at "copying image-something from somewhere" (I guess the XEN host tried to get the linux image).

Screw it, I'll keep running Ubuntu 8-something Hardy for good. I guess backing-up, reinstalling and reconfiguring the whole thing would go a lot faster and safer.

Is this just a problem for me, or a bonkers (Xen?)-Setup (at Strato)? Don't get me wrong, I quite enjoy their (recently abandoned) Multiservers. Got three of them w/ 21 systems running perfectly smooth.

Now What?

So, this Blog is essentially dead. I made it roughly one year ( last post was March '13 ) without even thinking of posting here.

First of all: Changing the Software to Jekyll is to cut out any tasks concerning my servers security. ( Wordpress Updates )

Second: I like this domain, I like the idea of having a blog. I'm - well - just unsure what to do with it.

Technology / Programming / Games:

I'm at least 2 years to late for most things that I'd like to share. The brief time I have for gaming is reserved for gaming. I have not the slightest of interests to put my opinion on the latest crap from (for example) Samsung on here.

Private stuff

... is kinda a notorious thing to do on the internet - nobody wants to know how and what I do - and nobody needs to know :-)

So what now?

For about 3 years now I'm "working" (a few hours a month) on a game. If I find myself with something more than 100-ish prototypes that nothing look like something someone expects from a game, I'd be happy to share.

I'll get back to that at some point :-)

Goodbye Wordpress. Hello Jekyll!

So long and thanks for all the fish

I used Wordpress almost for 10 Years now ( For memories click here ). It was comfortable, set up pretty quick, for everything you could find a plugin dnd there were a lot of gorgeous themes around.

I never had serious problems - well, even then, I was able to fix them since it's documented very good and the code is not that hard to read.

Wordpress has grown a lot. It's still growing from Blogplatform to become a CMS. I had increased problems with overall speed and it felt not that responsive anymore.

Why the Jekyll ?

Jekyll is nothing like Wordpress or any other popular Blogsoftware out there. It is essentially a "generator" for good old static html files. And yes, it kinda feels like a step backwards. No database, no "shortcodes", no Uploader, no Filebrowser, no Search, no Login ( I could continue ).

Jekyll is a simple, blog aware, static site generator. It takes a template directory [...] and spits out a complete, static website suitable for serving with Apache or your favorite web server. This is also the engine behind GitHub Pages, which you can use to host your project’s page or blog right here from GitHub.

Why would anybody choose that?

  • For somebody who spends most of his time between a terminal, vi and git this is quite appealing.
  • Have you ever tried 'hacking' a static html page?
  • Try a benchmark. I dare you

Downside

  • "No dynamic content" (1)

    • => Nowadays Javascript is always an option.
    • => Static HTTP Pages can be included in every "dynamic" application
    • => (NodeJS, Ruby (on rails), PHP etc.)
  • More work

    • => Yeah. No. Id say "more control"
  • Not for beginners.

    • => Beginners are still reading this? Get lost. Seriously

If anybody wonders, this is the "Hyde"-Theme. Modified a bit

Ruby: assign boolean logic result to variable

Or: Why the hell?

This would be a more suitable title. Recently I ran in several potholes that took me ages to figure out. Well, usually locating the mistake in an grown code base accounts for most of the "lost time". Replicating the issue is another factor. I often encounter issues that occur seemingly random. Some would throw huge rocks, engraved with the words 'testing', at various body parts of me. I like tests. I actually do tests. Well, on most parts anyway. But in this case it was in some stupid, 10 lines of code daemon-launcher.

I love making mistakes. Searching for them will force you to do several things you should've done while coding. I'm not talking about an missing ";" or "end". I'm talking about some wrong behavior in certain circumstances. Code gets DRYed and refactored because nobody wants to debug complex methods. You also (re)write tests for everything involved. I often find myself writing tests for the expected behavior but don't spend enough time to think about other cases.

I digress. Todays pothole (simplified)

a = 2
b = (a > 20 and a <= 23) or (a >=0 and a <= 4)

b => false

WTF? To make this more clear:

a = 2
b = (a > 20 and a <= 23) 
c = (a >=0 and a <= 4)
d = b or c
d => false

Funny though:

a = 2
b = (a > 20 and a <= 23) 
c = (a >=0 and a <= 4)
d = c or b
d => true

Aha! Turns out, I did the assignment wrong. This one works as expected:

a = 2
b = (a > 20 and a <= 23) 
c = (a >= 0 and a <= 4)
d = (b or c)
d => true

Apparently in this case you need the braces. No idea why though. Please enlighten me.

On Delphi Exception raising, re-raising and try-except blocks

Took me nearly 3 days to locate the error in following code:

procedure DoSomething;
  try
    something that may raise an exception
  except
    on e: EMyError1 do
      raise e // to re-raise the thing
    on e: Exception do // everything else
      raise EMyError2.Create('something happend');
  end;
end;

procedure WrapperForDoSomething;
begin
  try
    DoSomething;
  except on E: Exception do
    ShowMessage(e.message);    
    DoSomethingElseWith(e);
    Log(e.message);
  end;
end;

You see it, right? Yeah, me neither. Well at least I do now. I got an "Invalid Pointer Operation" right after Log(e.message). "E" was (still) accessible in the Log-Function. But was Free-ed long ago. Where do you ask? Right after the first except block in DoSomething. I didn't know this behavoir existed. It's kind of logical, now, to that this local variable in the try-except block should be destroyed afterwards.

Simple fix: instead of

...
on e: EMyError1 do
raise e // to re-raise the thing
...

do this: try ... except on e: EMyError1 do raise EMyError1.create(e.message); // to re-raise the thing in the correct way ...

Update Turned out that I'm wrong (or not efficient enough) on this one again. Comments & Reddit tought me the correct way:

try
...
except on e: EMyError1 do
  raise; // to re-raise the thing in the correct way
end

I'm working in a multithreaded environment and I was looking 2 of the 3 days in the wrong direction because I thought it had something to do with the (lack) of CriticalSections or Synchronization. Well - turned out to be dead simple.