January, 2010


27
Jan 10

"cue points" patch for xwax 0.7

I just “finished” porting the “cue points”-patch to the xwax 0.7 (beta1) code base.

With this patch each record in your library will get five cue points (you can customize this number). The cue points are shown right beside the clocks. Each cue point got its own colour and will be displayed as coloured line in the overview and closeup-view.

xwax 0.7 with cue points patch

I had to free some keys to control this functionality, so I introduced 2 modes: search and cue (call it library and dj mode if you want to). You can toggle between the two modes with the INSERT key.

key mapping

  • toggle between search and cue mode: INSERT key
  • deck one:
    • set/jump to cue points: 1, 2, 3, 4, 5
    • remove the cue points: CTRL + 1, 2, 3, 4, 5
  • deck two:
    • set/jump to cue points: 6, 7, 8, 9, 0
    • remove the cue points: CTRL + 6, 7, 8, 9, 0
  • deck three:
    • set/jump to cue points: q, w, e, r, t
    • remove the cue points: CTRL + q, w, e, r, t

How do you get it?

You can pull the 0.7+cue-points branch from my xwax repository @ githib. Github should also offer you a download button to get the source code.


20
Jan 10

“playedtracks” patch for xwax 0.7

I started to port my patches to xwax 0.7 (beta1) with the highlighting of played tracks.

Basically this patch provides a simple highlighting of played/loaded tracks in the record selector of xwax. You will see two new crates named “Played records” and “Loaded records” which are automatically managed by xwax (see screenshot below).

xwax_07 with "playedtracks" patch

Once you load a record to a deck xwax will mark the record as “loaded”. You can continue to skip through your record list and each record you load, will be marked as “loaded”. A record gets marked as “played” when the previously loaded record was loaded to another deck.

You can toggle through the 3 states (not highlighted, loaded, played) with the DEL key.

How do you get it? You can pull the 0.7+playedtracks branch from my xwax repository @ githib. Github should also offer you a download button to get the source code.


15
Jan 10

Latex: Zitieren mit jurabib

Nach etlichen (nervigen) Versuchen mit natbib, bibgerm und babelbib bin ich jetzt bei jurabib für die Zitate und das Literaturverzeichnis meiner Diplomarbeit gelandet.

Die Jurabib Dokumentation ist ausführlich und vor allem funktionieren die Fußnotenzitate und das Literaturverzeichnis so wie ich mir das wünsche.

Kurzes LaTeX Beispiel:


% jurabib einrichten

\usepackage[authorformat=smallcaps,round,ibidem=name&title&auto,oxford]{jurabib}
% jetzt kann man fröhlich zitieren
\cite{dimacs93:format}

\footcite[Seite 24,25]{weicker07:evoalg}

\cite[Seite 2 ff.]{dimacs93:format}

\citep[Seite 23,24]{weicker07:evoalg}
% für folgendes Bild:
Algorithmus laut \citep[Seite 83]{weicker07:evoalg} \footcite[Seite 83]{weicker07:evoalg}.

Ergebnis von Zeile 11 des oben stehenden Quelltextes:

\footcite mit jurabib

Daraus habe ich noch schnell einen neuen Befehl gemacht und schon geht das Zitieren relativ bequem:

\newcommand{\zitat}[2][]{
	\ifthenelse
	{\equal{#1}{}}
	{\citep{#2}\footcite{#2}}
	{\citep[#1]{#2}\footcite[#1]{#2}}
}
Algorithmus laut \zitat{weicker07:evoalg}.
Algorithmus laut \zitat[Seite 83]{weicker07:evoalg}.

6
Jan 10

ruby performance: Array#include?

Just found another easy way to (heavily) improve the performance of some code. While profiling my code I noticed that Array#include? is a bottleneck in some algorithms.

If you call Array#include? a lot, it might be a good idea to create a Set (or Hash) of the Array first – because Set#include? is way faster than Array#include?.

For more information and benchmarks read “Convert an array into an index hash in Ruby”.


4
Jan 10

ruby performance: ranges instead of loops

Today I found an interesting way to improve the performance of recombination operators for my thesis project. Most of the operators work on arrays and copy elements of one array to another.

Not being a native Ruby speaker since day one, I initially implemented this behaviour using loops (#times & #upto). What I came up with was something like:

def use_times(foo, bar)
	500.times { |index| foo[index] = bar[index] }
	501.upto(1000) { |index| bar[index] = foo[index] }
end

While refactoring the code I changed it to use Ruby’s ranges. I did this because I thought they look better (code becomes easier to understand) than my loops. What I ended up with was something like:

def use_ranges(foo, bar)
	first_range = 0..500
	second_range = 501..1000
	foo[first_range] = bar[first_range]
	bar[second_range] = foo[second_range]
end

Of course you should never trust your own source code, so I ran my test cases and wrote a little benchmark like this:

require 'benchmark'

foo = Array.new(1000)
foo.map! { |gene| true }

bar = Array.new(1000)
bar.map! { |gene| false }

timing = Benchmark.measure do
    10000.times { use_times(foo, bar) }
end
puts "Running using #times took:\n#{timing}"

timing = Benchmark.measure do
    10000.times { use_ranges(foo, bar) }
end
puts "Running using ranges took:\n#{timing}"

Results of the Benchmark (user, system, total, real in seconds):

Running using #times took:
  2.692000   0.000000   2.692000 (  2.669000)

Running using ranges took:
  0.206000   0.000000   0.206000 (  0.206000)

After I saw the results I was impressed by the performance gain of such a little change. The new code runs 10-100 times faster than before, depending on the array size (and the size of the ranges).

I think the explanation for the behaviour is simply the possibility to use memcpy (in the implementation of Ruby) instead of a loop. An assignment using Ranges is just easier to optimize by the Ruby interpreter.