Archive
Building libfreenect with patched libusb under Mac OS X
You need:
- macports
- The following installed macports:
- git-core
- cmake
- libtool
- libusb-devel
- libfreenect:
- git clone https://github.com/OpenKinect/libfreenect.git
- libusb:
- git clone git://git.libusb.org/libusb.git
- cd path/to/libusb
- ./autogen.sh
- patch -p1 < path/to/libfreenect/platform/osx/libusb-osx-kinect.diff
- ./configure LDFLAGS=’-framework IOKit -framework CoreFoundation’
- make
- sudo make install
- cd path/to/libfreenect
- mkdir build
- cd build
- ccmake ..
- With the following changes:
- LIBUSB_1_INCLUDE_DIR: /usr/local/include
- LIBUSB_1_LIBRARY: /usr/local/lib/libusb-1.0.dylib
- press ‘c’ and afterwards ‘g’ to generate and exit
- cmake ..
- make
- sudo make install
Lisp: Emacs Autocomplete
Today I hacked some lisp in emacs because I got two new books (Let over Lambda & Land of Lisp).
After a while when the function-definitions became more frequent I missed a language-specific autocomplete (and didn’t only want to use the built-in autocomplete that completes words you wrote earlier) and after some research I found the solution: Emacs Autocomplete. It integrates different language-dictionaries and inserts new words on the fly (with the right settings).
After installing the autocomplete into .emacs.d I inserted the following lines into my .emacs-file to enable it:
;; add .emacs.d to load path (add-to-list 'load-path "~/.emacs.d") ;; enable autocomplete (require 'auto-complete-config) (add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict") (ac-config-default) (global-auto-complete-mode t) (auto-complete-mode t)
To get a lisp-specific autocomplete you’ve got to include ac-slime (found at github): put it into your .emacs.d-folder and include it in your .emacs-file via
;; add lisp autocomplete-support (require 'ac-slime) (add-hook 'slime-mode-hook 'set-up-slime-ac)
and to switch on autocomplete globally you have to apply a “dirty fix”:
;; dirty fix for having AC everywhere
(define-globalized-minor-mode real-global-auto-complete-mode
auto-complete-mode (lambda ()
(if (not (minibufferp (current-buffer)))
(auto-complete-mode 1))))
(real-global-auto-complete-mode t)
Now only one thing is missing: the mentioned inserting of new words on the fly:
;; create and add new words to the dictionary on the fly (when (require 'auto-complete-config nil 'noerror) (add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict") (setq ac-comphist-file "~/.emacs.d/ac-comphist.dat") (ac-config-default))
Java, C++: ClassLoader and Qt Resource System
Here a little comparison between the Java ClassLoader and the Qt Resource System:
If you want to load an icon and/or an image e.g. in a Java .jar-file you have to do it this way:
Icon icon;
Image image;
ClassLoader CLDR = this.getClass().getClassLoader();
String path = "src/to/images/name.png";
URL url = CLDR.getResource(path);
// An icon
if (!(url == null)) {
icon = new ImageIcon(url);
}
// An image
try {
image = ImageIO.read(CLDR.getResource(path));
} catch (IOException e) {
// ExceptionHandling here
}
In Qt there is another approach:
The resources associated with an application are specified in a XML-based .qrc-file.
The specified paths are relative to the directory containing the .qrc-file (listed files must be located in the same directory or any sub-directory).
In the source-code the resources are accessible under the same name they have in the source tree, with a “:/” prefix.
Here an example:
<RCC>
<qresource prefix="/dir/subDir" lang="en">
<file alias="AliasName">subDir/FileName<file>
<qresource>
</RCC>
In your source code you can access FileName (if FileName e.g. is a QFile) via
QFile file(":/dir/subdir/AliasName");
after adding the following line to your .pro-file:
RESOURCES = yourRsrcFileName.qrc
The option lang=”langCode” (here: “en”) is for the localization:
If you want to add another language to your application you have to have the file “AliasName_langCode” in your source tree.
And, of course, you don’t have to write the ressource file on your own if you use the QtCreator, there is a nice GUI included.
SICK Robot Day 2009
Today’s the SICK Robot Day 2009 (Link1 | Link2).
I worked on it for the University of Osnabrueck.
Our Robot named KURT avoids collisions, respects the rule “left yields right”, is able to detect numbers as well as markers and drives to the right numbers from 0-9 and/or vice versa.
So…good luck to everyone in Waldkirch.
Here some photos of Kurt2 at our self-made parcours:

And some Videos:
C++: Qt: "qBaseConverter"
Today I implemented a Base Converter in C++ using Qt and after about 15 Minutes first successes have become apparent. You can convert from any Base you want to to any Base you want to (you only have to fix the “Number of Bases”-Variable if the default 30 Bases aren’t enough for you):

The basic Function (Slot) is – guess – “void convert()” that gets a Signal whenever a ComboBox or the Text at the LineEdit gets changed:
bool BaseConverter::getInputNumber(long long &number, int base) {
bool ok;
// Get Input-Number
number = ui->lineEdit_input->text().toULongLong(&ok, base);
// Return if Conversion ok
return ok;
}
void BaseConverter::convert() {
// Base to convert from
int baseFrom = ui->comboBox_choiceFrom->currentIndex() + 2;
// Base to convert to
int baseTo = ui->comboBox_choiceTo->currentIndex() + 2;
long long number;
// If there is a valid Input
if(getInputNumber(number, baseFrom)) {
// Display the converted Number
ui->lineEdit_output->setText(QString::number(number, baseTo));
}
}
Lisp: Implementation Competition between Programming Languages
Today I have found an ‘Implementation Competition between Programming Languages’ at fefe´s Blog.
A simple Problem has been implemented and tested in different Languages [ReadMe]:
- Read in from stdio
- Split into Words
- Count the Words
- Sort Words
- Print sorted Words
I saw that it wasn´t implemented in LISP yet so I asked Christopher if we don´t want to do that!
So here is the Program in LISP:
; Splits the given 'string' at 'split-string'-Sequence
(defun string-split (split-string string)
(loop with l = (length split-string)
for n = 0 then (+ pos l)
for pos = (search split-string string :start2 n)
if pos collect (subseq string n pos)
else collect (subseq string n)
while pos))
; If 'word' in the Hashtable 'ht', increment + 1
; else create new Key-/Value-Pair with Value = 1
(defun insert-key-value (word ht)
(when (and (stringp word)
(string/= word "")
(string/= word " ")
(not (null word)))) ; no blank words
(if (gethash word ht)
(incf (gethash word ht))
(setf (gethash word ht) 1)))
; Gets a Hashtable 'ht' and a Sort-Function 'sort-fn'
; Optional Parameter: 'by' can be :keys or :values
; Returns a sorted Hashtable of key-value-Pairs
(defun sort-hash-table (ht sort-fn &optional &key (by :keys))
(let ((sorted-entries nil))
(maphash #'(lambda (k v) (push (cons k v) sorted-entries)) ht)
(let ((sort-key #'car))
(if (equal by :values)
(setf sort-key #'cdr))
(sort sorted-entries sort-fn :key sort-key))))
; Prints a given Hash-Entry = Key-Value-Pair formatted
(defun print-hash-entry (key-value-pair)
(format t "key: ~t~t~t~S - value: ~t~t~t~S~&" (cdr key-value-pair) (car key-value-pair)))
; Counts the Words in a Line and puts them into a Hashtable
; - Gets a line 'line-in' and a Hashtable
; - Splits the String into Words
; - Puts the Words into a Hashmap
(defun count-words (line-in ht)
(mapcar #'(lambda (word)
(insert-key-value word ht))
(string-split " " line-in)))
; Creates a Hashtable 'ht'
; - Reads in Lines fom the Prompt
; - Calls Count-Words
; - Sorts and prints the Hash-Table
(let ((ht (make-hash-table :test 'equal)))
(do ((line-in t))
((null line-in) nil)
(setf line-in (read-line *query-io* nil nil nil))
(count-words line-in ht))
(mapcar #'print-hash-entry (sort-hash-table ht #'> :by :values)))
