Wednesday, January 8, 2014

Control your Yamaha AV Receiver (RX-V673, RX-A720, RX-V773, RX-A820, RX-A1020 etc.) with a python script

Please check out

for a python script to control your Yamaha AV Receiver.
This is more or less the same stuff the Android and iOS apps are based on.
So feel free to make a nice GUI if you like.

Have fun!

Monday, August 5, 2013

Streams from "Structure and Interpretation of Computer Programs" with Gambit Scheme

Figuring out how to implement Streams in the sense of Structure and Interpretation of Computer Programs by Abelson, Sussman and Sussman (great book!) in Gambit Scheme was difficult.

Clearly, "cons-stream" has to be a Macro.But how to do that with Gambit and it's confusing (for me!) macro system(s) ??

I found some older discussions and most helpful of all was

However, the definition of cons-stream works fine in the REPL, but when I put the code in a file "streams.scm" and load it via

(load "streams.scm")

I get an error:

1> (cons-stream 1 2)                                        
*** ERROR IN (console)@3.2 -- Unbound variable: cons-stream

The reason for this might be that Gambit needs to know about the macro before it is read by the reader. (?) "Including" the file with the macro definition did not work either. (confusing stuff for a Clojure programmer where Macros just work ... )

The solution is to put the Macro in a file ".gambcini".
Now, we are ready for stream-fun:

(cons-stream 1 2)  
(1 . #<promise #2>)

This works with Gambit v4.2.8 in the Debian Repositories and with Mac OSX.

Saturday, March 23, 2013

Magento: How to add Download Link for Data Sheet PDFs to Product Page

Let's add a download link for arbitrary files (in this case, data sheets in PDF) to your products on Magento.
(This is relatively easy, so no need to buy an extension ...  )

To do this, we create a new attribute (Admin Panel, go to "Catalog->Attributes->Manage Attributes").

Create a new Attribute:

Attribute Code: pdf_download
Scope: Global
Catalog Input Type for Store Owner: Textfield
Default: <empty>
Apply To: (arbitrary, I chose "All Product Types")

Visible on Product View Page on Front-end: Yes
Used in Product Listing: Yes

Under "Mange Label / Options" enter "Data Sheet".

Save the new attribute.

Open "Catalog->Attributes->Manage Attribute Sets" and choose a set (I chose "Default").
Drag your new Attribute "pdf_download" from the right column into the General group and save.

Open a Product from your Catalog and hopefully you'll find the new attribute "Data Sheet".

Now, create a folder "files" in your Web Server's document root (e.g. var/www/files or apache/htdocs/files). Copy your data sheet pdf there:


We can now specify the link to our data sheet in the "Data Sheet" text field in Magento's backend:

  Data Sheet: <a href="http://localhost/files/datasheet.pdf"> Data Sheet </a>

Refresh Magento's Index and Cache and navigate to your product on the front page. You should now see a table titled "Additional Information" with the link to our data sheet.

This approach has two problems, however: If we move our shop to a different server, we would need to adjust the attribute for all our products with a downloadable data sheet. Further, we always have to speficy the full link which is tedious.

We can do better than that.
Let's mess with some Magento internals and modify "attributes.phtml".
(don't forget to make a backup of this file in case something goes wrong!)
Search for attributes.phtml, in my case it was

Search for this block at the end of the file:

and change it to:
That's it (for now & testing purposes). You can now replace the text for the attribute

   Data Sheet: <a href="http://localhost/files/datasheet.pdf"> Data Sheet </a>

with the much simpler

Data Sheet:  datasheet.pdf

Please test if that works. Now, let's get rid of the hard coded url (http://localhost). To do that, first put the pdfs in a subfolder of magento, i.e.


Now change the line
You're done.

Sunday, May 27, 2012

Clojure macro for LibGDX input polling

A very simple macro:
(defmacro when-pressed
  ([key form]
  `(when (.isKeyPressed Gdx/input (. com.badlogic.gdx.Input$Keys ~key))
  ([key form & rest]
        (when-pressed ~key ~form)
        (when-pressed ~@rest))))
example usage:
 (when-pressed LEFT  (do-something)
               RIGHT (do-something-different)
               SPACE ( ... )
expands to:
user=> (pprint (macroexpand-1 '(when-pressed LEFT (do-something))))
 (.isKeyPressed Gdx/input (. com.badlogic.gdx.Input$Keys LEFT))
user=> (pprint (macroexpand-1 '(when-pressed LEFT (do-something)
                                             RIGHT (do-something-else))))
 (when-pressed LEFT (do-something))
 (when-pressed RIGHT (do-something-else)))

Saturday, May 12, 2012

Android: A two column ListView with an ImageView

Struggling with ListViews and SimpleAdapters on Android, I came up with the following simple example of a ListView with two columns: an image and some text. In res/layout, create a xml list_item.xml for the listview items:
<?xml version="1.0" encoding="utf-8"?>
<!-- list_item.xml -->
    <ImageView android:layout_width="100px"
    <TextView android:id="@+id/TEXT_CELL"


Add a ListView to main.xml main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
      android:text="Some Text"
  <ListView  android:id="@+id/LISTVIEW"

Finally, the code:
   :exposes-methods {onCreate superOnCreate}
  (:import ( Activity)
           (android.os Bundle))))

(defn -onCreate  [this bundle]
    (.superOnCreate this bundle )
    (.setContentView this$layout/main)
    (let [ids (int-array [$id/LOGO_CELL
          names (into-array ["logo" "text"])
          thelist (java.util.ArrayList.
                   [{"logo"$drawable/logo1 "text" "Text 1"}
                    {"logo"$drawable/logo2 "text" "Text 2"}]
                   aa (android.widget.SimpleAdapter. this thelist
                                           $layout/list_item names ids)]
      (.setAdapter (.findViewById this$id/LISTVIEW) aa)))
This will find the two pngs "logo1.png" and "logo2.png" in the res/drawable folders.