Freitag, 22. Mai 2015

Smalltalkify Groovy

By adding some Mixins to a groovy script, it is possible to use some smalltalk-like expressions like

ifTrue: [ do something ] ifFalse: [do something else]

Or do some smalltalk-like exception handling like

[ aBlock ] on: #Error do: [ something ]

In groovy this would look like:

Find the full source here: gist on github

Mittwoch, 10. Oktober 2012

Using Processing.js with Amber


"The Processing language was originally created at MIT as part of the Media lab and Aesthetics and Computation group. They needed a way to bridge the gap between software developers, artists, data visualizers, etc., and to do so in a way that allowed new programmers (or non-programmers) to do complex visual work easily. Processing was built using Java, and can be thought of as a simplified Java, with a simplified Java API for drawing and graphics." (source)

Since it is possible to write Processing code with pure JavaScript, it should be possible to use Amber with Processing.
And so it is - with some little tricks.
First, Processing should get initialized in the html page like this

A Processing instance will be created, it can get accessed via Amber in this way:

processing := <Processing.instances[0]>.

After fetching this instance, it can be used like any other Smalltalk Object:

processing background: 224.

processing line: centerX y: centerY dX: myDX dY: myDY.

I converted the clock-example to Amber, you can find it in the Example-section of my Amber Git repo. And maybe soon in the "official" Amber-Examples.

You can try it out here.

Mittwoch, 27. Juni 2012

Android-Binding for GNU Smalltalk ready!

Essentially it's no big thing - just a few lines of Smalltalk-code: i created a GNU Smalltalk star Package including the "Android" class that gives access to the full Android API via SL4A.
Usage is simple. First file in the package with:

PackageLoader fileInPackage: 'Android'.

Then you can use it like this:

| android |
android := Android new.
android makeToast: 'Hello World!'.

A more complex example, using some dialogs, is included in the smalltalk_for_android.apk (you can use the QR-Code below to install the apk - but remember that you need to install sl4a before. See my previous blog-post).
To get an idea what is possible, see the the API reference. I think it is a wonderful perspective to write full blown Android apps with Smalltalk.
Coding Smalltalk on a phone or tablet is fun - the sl4a editor is a big help because it contains an api reference. If you want to hack more complex scripts, you can remote control your phone or emulator, just follow this instructions. Only one difference: you need to set the environment-variable AP_HANDSHAKE to some arbitrary value.
With this setup you can execute your script with "gst myscript.st" or just call the api via the gst console.
Sourcecode etc. is available on github.


Mittwoch, 13. Juni 2012

GNU Smalltalk on Android

I crosscompiled GNU Smalltalk 3.2.4 with the Android NDK (r8).
Because interaction with GST on Android was complicated (couldn't read stdout/ stderr reliable), i decided to use the Android Scripting Framework.
So if you want to try it, first you need to install SL4A. You should install the sl4a_r5.apk (not r4!)
After installing SL4A, you can download and install smalltall_for_android.apk. Remember to allow installation from untrusted sources.
I tested "smalltalk for android" with an android virtual device running Android 2.3.3. The Screenshot was made on my Samsung Galaxy S3.
Currently there is no binding for the SL4A API - you can execute Smalltalk code, but there is no interaction with the Android API.
So, if anyone would like to help implementing the JSON-RPC bridge to SL4A - that would be really great.
The Source is on github.

Samstag, 21. Januar 2012

Domain-Verification mit Schlund Technologies für Google Apps

Ich habe ein Google Apps Konto für eine Non-Profit Organisation eingerichtet. Die Domain, die ich mit dem Konto nutzen möchte habe ich bei Schlund Technologies gekauft.
Um nun die Domain mit dem Google Apps Konto nutzen zu können, muss diese verifiziert werden - das war aber in meinem Fall eine echte Herausforderung. Dieser Spezialfall scheint auch nicht dokumentiert zu sein.
Es gibt verschiedene Möglichkeiten der Verifikation, so kann man z.B. auf der Homepage der Domäne spezielle HTML-Tags einfügen oder auf dem Server eine präparierte Datei ablegen. Das Vorhandensein dieser Informationen impliziert, dass man Eigentümer der Domäne ist.
Das funktioniert nur leider nicht, wenn man nur die Domain hat und keinen zugehörigen Webspace (den will man ja gerade mit Google Apps verwalten).
Die andere Variante ist, bei der Domänenkonfiguration einen TXT-Record mit einem speziellen Wert anzulegen. Google fragt den TXT-Record beim Nameserver ab und kann so das Eigentum an der Domäne verifzieren. Die Konfiguration des speziellen TXT-Records ist bei Google Apps für einige Domain-Provider beschrieben - leider nicht für Schlund.
Nach mehrstündigem rumprobieren und diversen Forensuchen konnte ich das Problem lösen: Bei Schlundtech kann für den neuen TXT-Record ein Name angegeben werden. Hier muss "@" eingetragen werden.
Interessanterweise konnte ich den TXT-Record speichern und die Google-Verifikation erfolgreich zum Abschluß führen. Beim nächsten Aufruf der Domain-Konfigurationsmaske bei Schlund war das @-Zeichen wieder verschwunden.

Donnerstag, 5. Januar 2012

Ambrhino

Today i'd like to announce my newest Project "Ambrhino". Ambrhino integrates Amber Smalltalk with the Java Virtual Machine.
Ambrhino can act as a Server to serve Amber and persist changes to the filesystem (you could use it instead of node.js).
It can also act as a runtime to execute Amber-Programs.
Ambrhino is written in Java and uses JSR223 to execute Javascript with the Mozilla Rhino Engine
An interesting feature is, that you can directly call Java classes from a compiled Amber Smalltalk, e.g.:


buttonPrintit := .
buttonPanel add: buttonPrintit.


A really cool feature is that it seems to be possible to add Smalltalk BlockClosures as ActionListeners to (Swing-) Buttons like this:



buttonDoit addActionListener: [ 
self eval: (textArea javaObject getSelectedText).
].

The main goal of this project is not to use Amber to write Swing-Applications - it feels somehow weird to use a Webbased-IDE to create a native Swing Application ...
Someday i want to use it to create Android-Applications with Amber - i could start an Ambrhino-Server on the Android-Emulator to create/ compile/ package programs. The Android-API will be called with the Android Scripting Framework (ASF)
But to get familiar with the (sometimes strange looking) Smalltalk-Java-Javascript-Mixture, i made a little Swing-Application - a simple Workspace to execute Smalltalk-Code.

To try it out you may fork the project on Github or just download the ambrhino.zip unpack it and start the workspace.bat file.

Like in other Smalltalk-Workspaces you can select text and execute it by pressing  "do it" or "print it".

To get an idea of what is possible you can copy this gist to the workspace and execute it. It fetches via HTTP-GET content from a Webserver and displays it on a JTextPane. Not really useful - but somehow cool.

Ideas, Hints, Help and rants are very welcome!

Freitag, 23. September 2011

Using Amber with a free WebDAV-Service

I really love Amber - but there's one thing i could not get used to. To persist the code you produce you need to setup a local WebDAV-Server or you need to run the Amber server-tool based on node.js.
The Problem i had is that i wanted to work only with a browser. Do some work on my PC, then switch to my wifes notebook, work in an internet-café, have a quick look at some code when i'm at my mothers house and so on.
My first attempt was a project on the google-app-engine, where jtalk (now "Amber") code was saved to a database. That approach was a quick hack and somehow proprietary. I also ran JTalk on the JVM on the serverside using google-backend-technology. Everything was much too complicated.
My current idea is to keep everything simple, use free services and have a real cloud-approach. I needed a free WebDAV-Service, accessible by a Webbrowser and the possibility to sync my files with a local folder on my harddisc.
I had the idea to use Dropbox, because Dropbox has an easy to use syncing tool and a nice web-view. I used Dropbox to server my Twitterwall demo for Amber. It would be quite easy to put a git-repository in my public Dropbox-folder and server Ambers index.html to the Cloud. But since Dropbox has no WebDAV-support it would not be possible to work from somewhere and save code and then push the changes to github when i'm back to a PC with git installed. To solve this problem, i would need to use the Dropbox-API. But that approach has other difficulties ...
On my quest i was experimenting with a lot of Cloud, WebTop and Filehosting Services and the only one that was easy and free to use and was working with Amber was the gmx MediaCenter.
There are just a few steps:
  1. Register a gmx account
  2. Navigate to the MediaCenter
  3. Upload the git-repository with Amber sources (drag & drop)
  4. Navigate to https://webdav.mc.gmx.net/ and login with your gmx-passwort
  5. Go to the index.hmtl in your amber-folder, do some coding and press "commit package"
The commited Category js will be updated in the gmx MediaCenter!
When you want to push your code to github, you just need to go to a PC where you can sync your gmx MediaCenter to a local disc and where a git-client is available.
It's possible to share WebDAV-folders with other gmx users so you easily could collaborate outside of github.
There's only one drawback - you can't grant access to everybody, it's restricted to gmx-users. So if you want to show something to a wider audience you would need to copy the files e.g. to your Dropbox folder.