Teaching kusanku to sankyu

March 11th, 2010

Last night, after some kicking drills and sparring, sensei entrusted the adult class to me and told us to work on kusanku. The ‘adult class’ yesterday consisted of three sankyu.
I looked at the clock, rubbed my hands together and said “Alright everyone, we have twenty-five minutes’ worth of kusanku. Let me know if you have questions or doubts.”
When we had finished walking through it, I looked at the clock. I’d spent twenty minutes on the form, and they all looked happy. I don’t think I really stood still for more than a few seconds at a time during those twenty minutes.
It reminded me of the first time I led the adult class, and I spent twenty-five minutes on seisan kata. I distinctly remember that it did not go quite as smoothly. It is usually hard to convince ranks under shodan that seisan is a very important, subtle kata, full of knowledge to be examined ;-) It’s a realization they must come to by themselves.

My favorite moment of those twenty minutes (besides the part where they all had a big smile, at the end), was one of the signature kusanku moves (koza dachi, right hand shuto to the throat, left hand behind your head like in seiuchin). I knelt by each one, adjusted the position of their rear foot with my hands, then stood up and watched their faces light up as the lesson sank in – in the proper stance, the legs and hips are looser, and thus the hips can turn more and still be more comfortable!

I _like_ teaching.

Gentoo on a Dell Inspiron Mini 10

March 1st, 2010

There are a few gotchas:
1) If you have a SSD drive, you need to modprobe pata_sch to see it.
2) when using GRUB, install it on whatever drive the hard drive is, even if it’s /dev/sdc — and let your FSTAB use /dev/sda. Chances are that /dev/sda is your liveUSB.
3) In the kernel, in the I2C options, don’t let it pick automatically – instead, select the algorithm options in the menu that appears (I don’t know it off-hand, will edit this post later to add the important information). This will allow you to install the kernel driver for the poulsbo card (kmod-psb, I believe).

For the rest, so far, it seems that the howto on the Gentoo wiki is good. I installed e17 very painlessly.

Wireless was a bit trickier.
I needed to use gentoo-sources-2.6.33, which at the time of this writing was masked as ~x86. A big advantage though is that it has support for the Atom processor (and the proper driver for the broadcom card!).
Enable the “B43″ driver in the kernel.
Then, follow the instructions given here:

git clone http://git.bu3sch.de/git/b43-tools.git
cd b43-tools/fwcutter
make
cd ..

Use version 4.174.64.19 of Broadcom’s proprietary driver. (The tarball is mislabeled as “4.178.10.4″, but it is actually 4.174.64.19.)
Download and extract the firmware from this driver tarball (Gentoo’s installation directory for this is /lib/firmware):

export FIRMWARE_INSTALL_DIR=”/lib/firmware”
wget http://downloads.openwrt.org/sources/broadcom-wl-4.178.10.4.tar.bz2
tar xjf broadcom-wl-4.178.10.4.tar.bz2
cd broadcom-wl-4.178.10.4/linux
sudo ../../fwcutter/b43-fwcutter -w “$FIRMWARE_INSTALL_DIR” wl_apsta.o

At the time of this writing, although the b43-firmware is available and promises to give us what we need, the b43-fwcutter tool is only at version 12, and not 13, so it can’t be used. This is why we need to use git to download the latest version and correctly build the firmware by hand.

Country alert levels #funny

January 20th, 2010

Let’s break the monotony with something funny:

The English are feeling the pinch in relation to recent terrorist threats? and have raised their security level from “Miffed” to “Peeved.” Soon, ?though, security levels may be raised yet again to “Irritated” or even “A? Bit Cross.” The English have not been “A Bit Cross” since the blitz in 1940 ?when tea supplies all but ran out.

Terrorists have been re-categorized from ?”Tiresome” to a “Bloody Nuisance.” The last time the British issued a? “Bloody Nuisance” warning level was in 1588 when threatened by the Spanish Armada.??

The Scots raised their threat level from “Pissed Off” to “Let’s get the? Bastards” They don’t have any other levels. This is the reason they have? been used on the front line of the British army for the last 300 years.

??The French government announced yesterday that it has raised its terror ?alert level from “Run” to “Hide”. The only two higher levels in France are? “Collaborate” and “Surrender.” The rise was precipitated by a recent fire?that destroyed France’s white flag factory, effectively paralyzing the ?country’s military capability.

It’s not only the French who are on a? heightened level of alert.
Italy has increased the alert level from “Shout ?loudly and excitedly” to “Elaborate Military Posturing.” Two more levels ?remain: “Ineffective Combat Operations” and “Change Sides.”?

?The Germans also increased their alert state from “Disdainful Arrogance” to?”Dress in Uniform and Sing Marching Songs.” They also have two higher? levels: “Invade a Neighbour” and “Lose”.?

?Belgians, on the other hand, are all on holiday as usual, and the only ?threat they are worried about is NATO pulling out of Brussels.

??The Spanish are all excited to see their new submarines ready to deploy. ?These beautifully designed subs have glass bottoms so the new Spanish navy ?can get a really good look at the old Spanish navy.??

Americans meanwhile and as usual are carrying out pre-emptive strikes, on?all of their allies, just in case.?

?And in the southern hemisphere…

??New Zealand has also raised its security levels – from “baaa” to “BAAAA!”. ?Due to continuing defense cutbacks (the airforce being a squadron of spotty ?teenagers flying paper aeroplanes and the navy some toy boats in the Prime?Minister’s bath), New Zealand only has one more level of escalation, which? is “I hope Australia will come and rescue us”.??

Australia , meanwhile, has raised its security level from “No worries” to?”She’ll be right, mate”. Three more escalation levels remain: “Crikey!’, “I ?think we’ll need to cancel the barbie this weekend” and “The barbie is? cancelled”. So far no situation has ever warranted use of the final? escalation level.

New gem: ListBrowser

January 15th, 2010

~~~~ ListBrowser README ~~~~

I was working on a parser for a very specific tree structure, and was frustrated that there wasn’t a simple way to parse it in irb. “What??”, I thought. “I have to use my brain?! God forbid!”. So I set to using my brain a little more to create this tool. It’s not much, but maybe it’ll make someone’s life a little easier.

Install: (set up gemcutter)
gem install ListBrowser

It can be used in irb, and really should be used there – when you call it on a tree structure, you’ll get a menu with a list of choices on how you want to go through whatever structure you gave it.

In my particular, special case, I would do something like this:

require ‘sgf_parser’ # For my tree structure require ‘list_browser’ # For this.

tree = SgfParser::Tree.new :filename => “kogo.sgf”

ListBrowser.new tree.root, ‘parent’, ‘children’, ‘properties’

# And follow the menu!

In my particular case, I would not need to enter those strings, as they
just happen to be the names I chose for my tree structure, but they should
serve as a good enough example!

Ruby SgfParser now really working!

December 31st, 2009

Thanks @alfmikula, it saves properly and has even been gemified. I will soon push it to gemcutter and maybe put a homesite on Rubyforge, not sure.
It can be found at http://github.com/Trevoke/SGFParser for now, get the code while it’s hot! :-)

Git : moving a remote branch

December 29th, 2009

One can’t actually move a remote branch, but you can copy a branch and delete a branch, so…

Copy oldbranch in repo to newbranch.

git push {repo} {oldbranch}:heads/{newbranch}

Ex: git push origin foobranch:barbranch
renames foobranch to barbranch

Remove a remote branch: it’s all about the colon:

git push <remote_repo> :heads/<branch>

Example: git push origin :heads/some-branch removes some-branch from the remote repo (apparently git push origin :some-branch works as well).

This works for removing a tag as well: git push origin :sometag

Random constrained permutations in Ruby

December 17th, 2009

Look, Ma, these are my baby steps in algorithms!

# list is the elements to be permuted
# y is the number of results desired
# z is the number of elements per result
# equalizer keeps track of who got used how many times
def constrained_permutations list, y, z
  list.uniq! # Never trust the user. We want no repetitions.
  equalizer = {}
  list.each { |element| equalizer[element] = 0 }

  results = []
  # Do this until we get as many results as desired
  while results.size < y
    pool = []
    puts pool
    least_used = equalizer.each_value.min
    # Find how used the least used element was
    while pool.size < z
      # Do this until we have enough elements in this resultset
      element = nil
      while element.nil?
        # If we run out of "least used elements", then we need to increment
        # our definition of "least used" by 1 and keep going.
        element = list.shuffle.find do |x|
          !pool.include?(x) && equalizer[x] == least_used
        end
        least_used += 1 if element.nil?
      end
      equalizer[element] += 1
      # This element has now been used one more time.
      pool << element
    end
    results << pool
  end
  return results
end

constrained_permutations [0,1,2,3,4,5,6], 6, 2
=> [[4, 0], [1, 3], [2, 5], [6, 0], [2, 5], [3, 6]]
constrained_permutations [0,1,2,3,4,5,6], 6, 2
=> [[4, 5], [6, 3], [0, 2], [1, 6], [5, 4], [3, 0]]

Inter-array permutations in Ruby

December 17th, 2009

I don’t really have a better name for this. It’s also not completely clean, but it works. I had, almost a year ago (362 days ago), written a blog post about lexicographic permutations. That was about permutations of elements within one array.
Someone on ruby-forum asked about permutations between multiple arrays. I found something in C#, which I was happy to transcribe to Ruby and tweak a little.

def array_permutations array, index=0
  # index is 0 by default : start at the beginning, more elegant.
  return array[-1] if index == array.size - 1 # Return last element if at end.
  result = []
  array[index].each do |element| # For each array
    array_permutations(array, index + 1).each do |x| # Permute permute permute
      result << "#{element}, #{x}"
    end
  end
  return result
end

So, we get this:

first = ['one', 'two']
second = ['three', 'four']
third = 'five', 'six']
result = array_permutations [first, second, third]
=> ["one, three, five", "one, three, six", "one, four, five", "one, four, six", "two, three, five", "two, thre
e, six", "two, four, five", "two, four, six"]

Magic!

——
Edit – of course, my solution is hackish, and someone came up with a quicker and more elegant solution:

def fancy_array_permutation array
  return array[0] if array.size == 1
  first = array.shift
  return first.product( fancy_array_permutation(array) ).map {|x| x.flatten.join(" ")}
end

This gives the same result as above.

Open source is wide open: Calling RAKE tasks

December 15th, 2009

Open source is wide open: Calling RAKE tasks.

Good to know.

On re-reading old code

December 9th, 2009

I came across this beauty:

def same_modality? list
  check = list[0][0]
  list.each do |i|
    return false if check != i[0]
  end
  return true
end

This was “necessary” because I got an array of one-element arrays back, and I wanted to check whether or not that one element was the same across the array.

Three seconds of thinking made me realize that just maybe, I could do this:

list.uniq.size == 1

I -like- Ruby.