meh...

coding - hacking - rambling - brainvomiting

Downgrading a Bad Kernel on Arch With LUKS and LVM

  • boot into the ArchLinux Install Medium.
  • here the steps to get the chroot running and where to probably find the old kernel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# load dm_crypt/luks
modprobe dm_crypt
modprobe dm_mod #not sure if needed

# open the crypt container
cryptsetup luksOpen /dev/sd[x] crypt

# scan for new LVM drives and activate them
vgscan
vgchange -ay

# create a basefolder and mount all the stuff in it (I assume you use btrfs with compression and seperate partitions for root,home and var - adapt to your own system)
mkdir ${arch_base}
mount -o compress=lzo /dev/mapper/cryptpool-cryptroot ${archbase}
mount -o compress=lzo /dev/mapper/cryptpool-crypthome ${archbase}/home
mount -o compress=lzo /dev/mapper/cryptpool-cryptvar ${archbase}/var

mount -t proc proc ${archbase}/proc
mount -t sysfs sys ${archbase}/sys
mount -o bind /dev ${archbase}/dev

# start chroot
chroot ${archbase} /bin/zsh

# find your old kernel in /var/cache/pacman/pkg/linux-* and install it
pacman -U ${kernel-package}

# you propably also want to downgrade the kernel-headers
# (linux-headers-*)

# finally add this to your /etc/pacman.conf
# IgnorePkg   = linux linux-headers

# exit chroot, umount all the stuff again and reboot
exit
umount ${new_arch}/{home,var,proc,sys,dev}
umount ${new_arch}
reboot

Sinatra Sprockets and Websockets

The last few days I tried to run a sinatra application which uses sprockets for it’s assets together with EventMachnine Websockets from within one rackup file. To get this working I had to setup two things.

FYI: Dynamically Define Methods in Ruby

to create a method dynamically do something like this:

1
2
3
4
5
6
[:teacher, :group, :course, :room].each do |arg|
  method_name = ("find_by_" + arg.to_s).to_sym
  define_method(method_name) do |params|
    # to stuff here
  end
end

if the methods should be class methods modifier it like this

1
2
3
4
5
6
7
8
class << self
  [:teacher, :group, :course, :room].each do |arg|
    method_name = ("find_by_" + arg.to_s).to_sym
    define_method(method_name) do |params|
      # to stuff here
    end
  end
end

JS Playground 2: AJAX and the Browserhistory

So after managing to render my data on the client - see my last post about mustache - I wanted to get the browser histoy working again. The problem with single site pages and getting all the data via ajax is that normally the browserhistory is useless. Also you can’t bookmark stuff or send others a link to exacly the site you are seeing.

With HTML5 there is now a clean way of doing exaclty this task. With the Histoy API, nicely explained here from mozilla, you can now add new items to the browser history. This works more or less like a stack, if you want to add something just push a new state to it. If the user then clicks back the last element gets poped from the stack. The API also allows you to save some data in each state - besides the URI itself. In addition you can walk through the history in javascript, but I didn’t play with this.

Fortunatly I don’t care for old browsers, so I could just use this as all(?) modern Browsers support the Histroy API. But as with most of these features every browser does it a little bit different. I normally test apps in Opera, because thats my main browser, and I got the history woring pretty fast. So I thought lets see what Chrome does with this and of couse it didn’t work. I’m not sure if i used the API in a wrong way or if Chrome or Opera does something special here. Point is even after fiddling around for a bit it didn’t work in both browsers at the same time.

I think it should look somethink like this, but sometimes the popstate event is not the one you would want and you have to use the originalEvent and sometimes not.

1
2
3
4
5
6
7
$(window).bind("popstate", function(e) {
  var state = e.originalEvent().state
  // do stuff
});

// make a new state
history.pushState(data, title, url);

So whats the solution for that kind of problem? Just ask the internet if anybody has written a nice wrapper for this which takes care about the different browsers. And suprise, suprise I found history.js

Because I already knew how and when to add new states and how to act on a ‘back’ event, the change to history.js was pretty easy. Just had to change some keywords. And it almost immedialety work in all browsers I tested it (opera, chrome, firefox)

1
2
3
4
5
6
7
History.Adapter.bind(window,'statechange',function(){
  var state = History.getState()
  // do stuff
});

// make a new state
History.pushState(data, title, url)

Besides not having to care about browser differences the libary also supports a fallback mode for non HTML5 browsers, which is nice if you care about such stuff.

JS Playground 1: Mustache and ICanHaz.js

Over the last few days I started to play around with javascript and other front-end related stuff.

The first thing I wanted to try and use was mustache. So first I needed a backendt to serve the templates and the dynamic data. Of course I used Ruby and Sinatra for this. For the views the server had to render I also used Mustache - that’s the nice thing about Mustache you can use it everywhere.

Mustache as it is is really nice, after you understood how it will use partials and how it goes through the data you get in my optinion much nicher source template als in someting like erb. Also you don’t depend on some magic like when using haml or slim. And of course the split between data and template really helps to structure your code.

So now to the interesting part the client side. After a few very simple tests on how to use mustache.js I accounted the problem on how to get the templates to the client without having to write them directly into the javascript file. I looked around and discoverd ICanHaz.js, which is a nice wrapper around mustache and tries to solve the template issue. There are two ways to register a template for ICanHaz, the first one is to write them into the html like this:

1
2
3
<script id="group" type="text/html">
  //the template
</script>

But to use this you have to write all your templates into the html source, which I didn’t liked.

The other way is to get the templates via JS as JSON from the server and just add them to ICanHaz:

1
2
3
4
5
$.getJSON('/myserver/templates.json', function (templates) {
    $.each(templates, function (template) {
        ich.addTemplate(template.name, template.template);
    });
});

Thats really clean and your have your templates seperate from the rest of the javascript and html.

Octopress for the Win

New Year, new Blog.

I decided to kill my tumblr and start this octopress blog. At the moment I just imported most of the old posts and fixed tags/categories, but I still have to check all links and move some images.

And just for the record here are a few of the snippets used to convert the posts.

1
2
3
4
5
6
7
8
9
# download and extract posts in jekyll format
wget https://github.com/stephenmcd/jekyll/blob/master/lib/jekyll/migrators/tumblr.rb
ruby -r './tumblr' -e 'Jekyll::Tumblr.process("http://sch1zo.tumblr.com",format="md")'

# exchange tags for categories
perl -pi -e '$.==4 and s/tags/categories/;close ARGV if eof' *

# add a tumbler tag/category to each post
perl -pi -e '$.==5 and s/^/- tumblr\n/;close ARGV if eof' *

yeah I know, Perl WTF!? These snippets just were the first thing google/stackoverflow gave me after searching for this kind a task, and I didn’t want to convert them to Ruby or anything else.

Unfortunatly I couldn’t find a way to write the date into the meta data of the file. Perhaps I’m just to tired…

Here is what I got(this time in ruby). After failing here I just went ahead ant edited the 19 files by hand.

1
ruby -pie '$.==4 and $_.sub!(/^/, "date: #{"2011-03-02-here should be the current filename".match(/(\d{4}-\d{2}-\d{2}).*/)[1]}\n")' *

Compiling Ruby 1.8.7 With Gcc 4.6.*

the last few days I reinstalled archlinux and encountered a problem. You can’t compile ruby 1.8.7 or REE 1.8.7 with gcc4.6. Earlier versions probably have the same issue, but at least 1.9.2 or newer works.

But I wanted ree installed because its load requirements faster than the newer build which is important when developing rails.

How to Compile a Fast Imagemagick

yesterday I had to install ImageMagick to do some image processing on a new webapp I’m building - creating thumbnails of uploaded images to be precise.

The initial choice was to simply use the the package from the repository. But it was unbarable slow to simply create a 100x100 thumbnail of a 1080p wallpaper which I used to test it( time sad a little above 7 seconds).