Man On The Silver MountainSchipplockTumblr (3.0; @schipplock)http://schipplock.tumblr.com/Taken with instagram<img src="http://24.media.tumblr.com/tumblr_li97scpIA91qc4nx6o1_500.jpg"/><br/><br/><p>Taken with <a href="http://instagr.am">instagram</a></p>http://schipplock.tumblr.com/post/3939350656http://schipplock.tumblr.com/post/3939350656Fri, 18 Mar 2011 17:53:02 +0100Taken with instagram<img src="http://30.media.tumblr.com/tumblr_li83whJwD51qc4nx6o1_500.jpg"/><br/><br/><p>Taken with <a href="http://instagr.am">instagram</a></p>http://schipplock.tumblr.com/post/3928122129http://schipplock.tumblr.com/post/3928122129Fri, 18 Mar 2011 03:31:31 +0100Taken with instagram<img src="http://28.media.tumblr.com/tumblr_li5mfnkt2g1qc4nx6o1_500.jpg"/><br/><br/><p>Taken with <a href="http://instagr.am">instagram</a></p>http://schipplock.tumblr.com/post/3898706065http://schipplock.tumblr.com/post/3898706065Wed, 16 Mar 2011 19:19:01 +0100Improved SWT Text Widget<p>SWT is a great gui toolkit for the java platform which is easy to use, easy to change and what’s more important: it’s fast and native. <br/><br/> I use the “Text” input widget a lot because it’s common in all kinds of applications and whenever you see one of them there is probably a “label”, too…a label that describes what to enter in the input field. <br/><br/> However, there is a nice way to leave the “label” completely out of your gui. <br/><br/> Have a look: <br/><img src="http://25.media.tumblr.com/tumblr_l7nxmiWfeT1qc4nx6o1_400.png" alt="window"/><br/><br/> When you click into the Text-widget, the gray text will vanish. That’s it :D! <br/><br/> Here is the code:</p> <pre class="brush:java">package test; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; /** * * @author Andreas Schipplock */ public class ASText extends Text { private String hiddenText = ""; private final Color black; private final Color gray; public ASText(Composite parent, int style) { super(parent, style); this.black = new Color(super.getDisplay(), 0,0,0); this.gray = new Color(super.getDisplay(), 119,136,153); setForeground(gray); parent.setFocus(); this.addListener(SWT.MouseUp, new Listener () { public void handleEvent (Event e) { if (getText().equals(getHiddenText())) { setText(""); setForeground(black); } } }); } public void setHiddenText(String text) { this.hiddenText = text; } public String getHiddenText() { return this.hiddenText; } @Override protected void checkSubclass() {} } </pre> <p><br/><br/> And here the main to test the Text widget:</p> <pre class="brush:java">package test; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; /** * * @author Andreas Schipplock */ public class Main { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Test"); shell.setSize(400,250); // text input single ASText text1 = new ASText(shell, SWT.BORDER | SWT.SINGLE); text1.setBounds(2, 2, 230, 20); text1.setHiddenText("first name"); text1.setText(text1.getHiddenText()); shell.open(); while(!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } } </pre> <p><br/><br/> Andreas Schipplock.</p>http://schipplock.tumblr.com/post/1003839733http://schipplock.tumblr.com/post/1003839733Tue, 24 Aug 2010 17:32:39 +0200programmingPhoto<img src="http://25.media.tumblr.com/tumblr_l7nxmiWfeT1qc4nx6o1_400.png"/><br/><br/>http://schipplock.tumblr.com/post/1003824159http://schipplock.tumblr.com/post/1003824159Tue, 24 Aug 2010 17:27:54 +0200OMG, ich hab mir meine eigene epost ID geklaut<p>Hi,<br/> Ihr habt leider einen dicken Fehler in der Webapplikation, mit der man sich seinen Account und somit seine epost Adresse sichern kann…dieser Bug sorgt dafuer, dass ich und jeder andere auch alle moeglichen Adressen sperren kann, so dass sie niemand mehr benutzen kann. </p> <p>Wenn man das Formular ausfuellt, dann wird einem ja die Adresse vorname.nachname@epost.de angeboten…wenn man in diesem Schritt den Webbrowser schliesst, gilt diese Adresse als vergeben, obwohl man weder eine Bestaetigung noch sonst irgendwas bestaetigt hat.</p> <p>Ich habe das gerade durch Zufall gemerkt und ich bin entsetzt von solch amateurhafter Programmierung. Ich habe es gerade live erlebt und nun denkt euer System, dass andreas.schipplock@epost.de schon vergeben ist.</p> <p>Ich kann ja mal bei Gelegenheit darueber bloggen. Es gibt bestimmt genug Kiddies, die sich als Angela Merkel registrieren wollen…Frau Merkel wird sich dann freuen, wenn ihre ID dann angela.merkel.10@epost.de ist…</p> <p>Ich wuerde vorschlagen, dass ihr das an die Softwareentwicklung weiterleitet, denn solch ein Formular ist fenlerhaft…sowas laesst natuerlich andere Schluesse zu…Sicherheit…wer weiss?</p> <p>Ich geh davon aus, dass ihr mein Problem nicht loesen koennt, weil meine ID ja nun als verwendet gilt, obwohl ich nichts bestaetigt habe…solltet ihr mein Problem loesen koennen, werde ich mir epost vllt. noch mal angucken…wenn nicht, dann war es das fuer mich und meine Erfahrungen werde ich dann ausfuehrlich dokumentieren. Ich hoffe, dass dieser Bug noch unentdeckt ist, da sonst andere Unfug damit machen und bald niemand mehr seine Id im Format vorname.nachname bekommt. </p> <p>Ich weiss jetzt nicht mal, wie ich diesen Konflikt loesen kann, denn ich habe nicht mal eine Email von euch bekommen…</p> <p>M.f.G.</p>http://schipplock.tumblr.com/post/989358135http://schipplock.tumblr.com/post/989358135Sun, 22 Aug 2010 00:09:51 +0200MySQL5 foreign keys only with INNODB<p>If you work with Postgresql or even Oracle something like foreign keys are used on a daily basis…such constraints are very welcome and used all over the world except in mysql with myisam. <br/><br/> You have to turn on innodb for that. <br/><br/></p> <pre class="brush:sql">create table car ( id integer primary key not null auto_increment, name varchar not null ) ENGINE=INNODB; create table car_owner ( id integer primary key not null auto_increment, first_name varchar(100) not null, last_name varchar(100) not null, car integer not null, foreign key (car) references car(id) ) ENGINE=INNODB; insert into car (name) values ('Audi 80'); insert into car (name) values ('Mercedes 190D'); insert into car_owner (first_name, last_name, car) values ('Andreas','Schipplock',1); # works! insert into car_owner (first_name, last_name, car) values ('Andreas','Schipplock',2); # works! insert into car_owner (first_name, last_name, car) values ('Andreas','Schipplock',3); # fails! intended behavior :) </pre> <p><br/><br/> That’s it…simple.</p>http://schipplock.tumblr.com/post/894595249http://schipplock.tumblr.com/post/894595249Mon, 02 Aug 2010 22:39:37 +0200CakePHP Oracle Connection<p>I just had trouble telling cakephp to connect to my oracle 11g R2 but I finally found a solution: <br/><br/></p> <pre class="brush:php">class DATABASE_CONFIG { var $default = array( 'driver' => 'oracle', 'persistent' => false, 'connect' => 'oci_connect', 'login' => 'OE', 'password' => 'yourpassword', 'database' => 'localhost:1521/orcl', 'prefix' => '', ); } </pre> <p><br/><br/> Works! Now I can go on playing with cakephp.</p>http://schipplock.tumblr.com/post/754448544http://schipplock.tumblr.com/post/754448544Wed, 30 Jun 2010 20:01:09 +0200oracledatabasecakephpInserting an item into an array at specified position<p>Bastian and me; we just talked about how you would insert an item into a simple array at a specified position. <br/><br/> The solution was easy: <br/><br/></p> <pre class="brush:php">function array_insert_item_at_position($array, $position, $item) { $new_array_before = array_slice($array, 0, $position, true); $new_array_after = array_slice($array, $position, count($array), true); $final_array = array_merge($new_array_before, array($item), $new_array_after); return $final_array; } $foobar = array("foo","bar"); print_r($foobar); $bar = array_insert_item_at_position($foobar,1, "is not"); print_r($bar); </pre> <p><br/><br/></p> <pre class="brush:php">Array ( [0] => foo [1] => bar ) Array ( [0] => foo [1] => is not [2] => bar ) </pre> <p><br/><br/> Works for simple arrays :).</p>http://schipplock.tumblr.com/post/694417254http://schipplock.tumblr.com/post/694417254Sun, 13 Jun 2010 19:32:35 +0200programmingphp5Improved accessor methods in php5<p>Moin! <br/> Yesterday I was telling you how to write better get and set methods. However, there is another way of doing it even better but I first thought it would limit you in your ability to write useful get and set methods but it’s not. <br/><br/> Just keep in mind that whenever you set a property php5 calls __get or __set and you can use them to make accessor methods like in ruby and I first thought this would limit you in the ability to create unique get and get methods but it’s not because php is able to verify if a named method is available inside the class or not. <br/><br/> That feature got me the following code: <br/><br/></p> <pre class="brush:php">class Car { private $mileage = 123000; function __get($f) { $m = "get_".$f; return method_exists($this,$m) ? $this->$m() : $this->$f; } function __set($f,$v) { $m = "set_".$f; return method_exists($this,$m) ? $this->$m($v) : $this->$f = $v; } } $mycar = new Car; print $mycar->mileage; // 123000 $mycar->mileage = 124000; print $mycar->mileage; // 124000 </pre> <p><br/><br/> Executing this script will print out “123000124000” on your terminal which is perfectly fine though you might think you just set the private property “mileage” to some value but in fact the method __set did set the value for that private property “mileage”. <br/><br/> But now in the near future you decide that mileage can’t just be a simple number but needs some formatting attached to it (which would be bad practice here, but just to be clear), so you want to create your unique get-method, so you simply add it to your implementation: <br/><br/></p> <pre class="brush:php">class Car { private $mileage = 123000; function __get($f) { $m = "get_".$f; return method_exists($this,$m) ? $this->$m() : $this->$f; } function __set($f,$v) { $m = "set_".$f; return method_exists($this,$m) ? $this->$m($v) : $this->$f = $v; } function get_mileage() { return $this->mileage." km\n"; } } $mycar = new Car; print $mycar->mileage; // 123000 km\n $mycar->mileage = 124000; print $mycar->mileage; // 124000 km\n </pre> <p><br/><br/> Executing this script will append ” km\n” to each “getted” value because “__get” tried to check if there is a “get_mileage” method available which evaluated to true so it simply called it. <br/><br/> Basically that’s it…you can do the same with “set” and just add your unique set-method: <br/><br/></p> <pre class="brush:php">class Car { private $mileage = 123000; function __get($f) { $m = "get_".$f; return method_exists($this,$m) ? $this->$m() : $this->$f; } function __set($f,$v) { $m = "set_".$f; return method_exists($this,$m) ? $this->$m($v) : $this->$f = $v; } function get_mileage() { return $this->mileage." km\n"; } function set_mileage($newMileage) { if ($newMileage > 100000) { $this->mileage = 200000; } else { $this->mileage = $newMileage; } } } $mycar = new Car; print $mycar->mileage; // 123000 km\n $mycar->mileage = 124000; print $mycar->mileage; // 200000 km\n </pre> <p><br/><br/> Now if you have a bunch of private properties you don’t need to write accessor methods for all of them. Just when you need them you’ll implement them and you will be fine :). <br/><br/> Andreas Schipplock.</p>http://schipplock.tumblr.com/post/657801044http://schipplock.tumblr.com/post/657801044Thu, 03 Jun 2010 00:10:00 +0200programmingphp5oopaccessor methodsSimple and clean get/setter methods in PHP5<p>Moin! <br/> When I played with ruby I found some nice features of the language that I’d really like to see in php as well but apparently most of the syntactic sugar is not part of php5 at all. However, due to that you will often see classes with get and setter methods that basically do nothing special. In your getter and setter methods you can work on the data passed around which is very useful if you change this unique logic at some point later in the applications lifetime when you don’t want to change too much in your interface. <br/><br/> In my ruby quickstart I wrote about classes and how you can write short properties getters and setters. <br/><br/></p> <pre class="brush:ruby">class Car attr_accessor :mileage def initialize(mileage) @mileage = mileage end end audi = Car.new(245000) puts "old mileage: "+audi.mileage.to_s audi.mileage = 246000 puts "new mileage: "+audi.mileage.to_s </pre> <p><br/><br/> In php5 there is no such thing like “attr_accessor” but you can at least try to build something similar which is not too bad at all: <br/><br/> I first tried to replicate it 1:1 but it doesn’t work of course :). Look! <br/><br/></p> <pre class="brush:php"> class Car { private $mileage = 123000; function mileage($newMileage=0) { if ($newMileage>0) { $this->mileage = $newMileage; } else { return $this->mileage; } } } $mycar = new Car; print $mycar->mileage; $mycar->mileage = 124000; print $mycar->mileage; </pre> <p><br/><br/> This doesn’t work and throws “Fatal error: Cannot access private property Car::$mileage”. Sure, “mileage” is a private property of class “Car” so you can’t access it and I didn’t wanted to access it. I wanted to use the method like a property…no sir! <br/><br/> The best solution I came up with so far is the following: <br/><br/></p> <pre class="brush:php"> class Car { private $mileage = 123000; function mileage($newMileage=0) { if ($newMileage>0) { $this->mileage = $newMileage; } else { return $this->mileage; } } } $mycar = new Car; print $mycar->mileage(); // 123000 $mycar->mileage(124000); print $mycar->mileage(); // 124000 </pre> <p><br/><br/> This way I really lose all the verbose get and setter methods that many books teach you to write. This way you can still work on the data you pass, it’s shorter and using it in your code is by far more readable and it makes more sense. <br/><br/> Tell me if you disagree :). I really prefer it that way! <br/><br/> Andreas Schipplock.</p>http://schipplock.tumblr.com/post/654161910http://schipplock.tumblr.com/post/654161910Tue, 01 Jun 2010 22:05:00 +0200programmingphpphp5oopJavascript Objects<p>Today I’m about to tell you something about Javascript objects and how to use them properly. <br/><br/>You can use rhino (javascript interpreter and shell) to test your scripts or you can throw it into your webbrowser. I prefer rhino over the webbrowser as I can test my code without firing up the webbrowser. <br/><br/> Let’s start simple:<br/><br/> Create an object with properties and print and access them: <br/><br/></p> <pre class="brush:jscript">var car = {<br/> "make": "Audi",<br/> "engine": "V8",<br/> "mileage": "123.000"<br/>};<br/><br/>// both is possible<br/>print(car.make)<br/>print(car["make"])</pre> <p><br/><br/> Here we have a simple object with some properties. Nothing special about it. The expected result is “Audi”. <br/><br/> Sometimes if you don’t know the properties by heart, you may print the wrong propertie, e.g.<br/><br/></p> <pre class="brush:jscript">var car = {<br/> "make": "Audi",<br/> "engine": "V8",<br/> "mileage": "123.000"<br/>};<br/><br/>print(car.brand)</pre> <p><br/><br/> Rhino will simply print out “undefined”. To workaround this issue you can put default values to it: <br/><br/></p> <pre class="brush:jscript">var car = {<br/> "make": "Audi",<br/> "engine": "V8",<br/> "mileage": "123.000"<br/>};<br/><br/>print(car.brand || "the unknown brand")</pre> <p><br/><br/> And it will print out “the unknown brand” which is something you can expect and it’s always better to work with values you expect than with “undefined” ones. <br/><br/> However, here is a more detailed example of our car represented as an object: <br/><br/></p> <pre class="brush:jscript">var car = {<br/> "make": "Audi",<br/> "engine": {<br/> "type":"V",<br/> "cylinders":"8",<br/> "capacity":"4.2"<br/> },<br/> "mileage": "123.000"<br/>};<br/><br/>print(car.engine.type)</pre> <p><br/><br/> There we print out the engine type which is “V” but what happens if we mistype “engine” e.g.: <br/><br/></p> <pre class="brush:jscript">var car = {<br/> "make": "Audi",<br/> "engine": {<br/> "type":"V",<br/> "cylinders":"8",<br/> "capacity":"4.2"<br/> },<br/> "mileage": "123.000"<br/>};<br/><br/>print(car.engne.type)</pre> <p><br/><br/> We even get an exception using this so in fact the script “died”. We could use || like before, right? <br/><br/></p> <pre class="brush:jscript">var car = {<br/> "make": "Audi",<br/> "engine": {<br/> "type":"V",<br/> "cylinders":"8",<br/> "capacity":"4.2"<br/> },<br/> "mileage": "123.000"<br/>};<br/><br/>print(car.engne.type || "unknown engine type")</pre> <p><br/><br/> No, we can’t! We still get an exception. <br/><br/> So I discovered the following construct: <br/><br/></p> <pre class="brush:jscript">var car = {<br/> "make": "Audi",<br/> "engine": {<br/> "type":"V",<br/> "cylinders":"8",<br/> "capacity":"4.2"<br/> },<br/> "mileage": "123.000"<br/>};<br/><br/>print(car.engne && car.engne.type || "unknown engine type")</pre> <p><br/><br/> We don’t get an exception anymore but the result “unknown engine type”. <br/><br/> Sometimes you really want to make sure that your object has your desired property, so if you want you can check for the existense of a property, it’s simple: <br/><br/></p> <pre class="brush:jscript">if (car.hasOwnProperty("engine")) {<br/> print("car has an engine")<br/>}</pre> <p><br/><br/> To add new properties, simply write it like this: <br/><br/></p> <pre class="brush:jscript">car.engine.mileage = "12.145"</pre> <p><br/><br/> And to update values, simply put: <br/><br/></p> <pre class="brush:jscript">car.engine.capacity = "3.7"</pre> <p><br/><br/> Sometimes you want to have a prototype you can base your objects on and it’s not too difficult: <br/><br/></p> <pre class="brush:jscript">if (typeof Object.fromPrototype !== 'function') {<br/> Object.fromPrototype = function(thePrototype) {<br/> var the_new_function = function() {};<br/> the_new_function.prototype = thePrototype;<br/> return new the_new_function;<br/> };<br/>}<br/><br/>var car = {<br/> "make": "Audi",<br/> "engine": {<br/> "type":"V",<br/> "cylinders":"8",<br/> "capacity":"4.2"<br/> },<br/> "mileage": "123.000"<br/>};<br/><br/>var security_car = Object.fromPrototype(car)<br/>security_car.make = "Mercedes"<br/>security_car.platinggrade = "10"<br/><br/>print(security_car.make || "na")</pre> <p><br/><br/> It will print “Mercedes” and it’s easy to understand. Whenever you want to retrieve a value, it goes down the hirarchy and tries to find it. In this case you told javascript that “security_car” has an additional property “platinggrade” which the prototype “car” doesn’t have. But you could try to print out the mileage and you’d get “123.000”. <br/><br/> And to get rid of your newly created property, you can simply delete it: <br/><br/></p> <pre class="brush:jscript">var security_car = Object.fromPrototype(car)<br/>security_car.make = "Mercedes"<br/>security_car.platinggrade = "10"<br/><br/>print(security_car.make || "na") // Mercedes<br/><br/>delete security_car.make<br/><br/>print(security_car.make || "na") // Audi (from the prototype)</pre> <p><br/><br/> So it will print “Mercedes” and “Audi”. <br/><br/> Finally try to namespace your whole objects so that no other code can interfere: <br/><br/></p> <pre class="brush:jscript">var SCHIPPLOCK = {};<br/><br/>if (typeof Object.fromPrototype !== 'function') {<br/> Object.fromPrototype = function(thePrototype) {<br/> var the_new_function = function() {};<br/> the_new_function.prototype = thePrototype;<br/> return new the_new_function;<br/> };<br/>}<br/><br/>SCHIPPLOCK.car = {<br/> "make": "Audi",<br/> "engine": {<br/> "type":"V",<br/> "cylinders":"8",<br/> "capacity":"4.2"<br/> },<br/> "mileage": "123.000"<br/>};<br/><br/>var security_car = Object.fromPrototype(SCHIPPLOCK.car)<br/><br/>security_car.make = "Mercedes"<br/>security_car.platinggrade = "10"<br/><br/>print(security_car.make || "na")<br/><br/>delete security_car.make<br/><br/>print(security_car.make || "na")</pre> <p><br/><br/> Where “SCHIPPLOCK” is an empty object which reflects my namespace. <br/><br/><br/> For now that’s enough I think. Play around with your code and don’t make javascript too ugly :). It’s not that bad imho :). <br/><br/> Andreas Schipplock.</p>http://schipplock.tumblr.com/post/649594138http://schipplock.tumblr.com/post/649594138Mon, 31 May 2010 12:30:00 +0200programmingjavascriptthat’s what you get if you think to get a cool new job...<img src="http://28.media.tumblr.com/tumblr_l38vtiMrTh1qc4nx6o1_500.png"/><br/><br/><p>that’s what you get if you think to get a cool new job there :).</p>http://schipplock.tumblr.com/post/647364685http://schipplock.tumblr.com/post/647364685Sun, 30 May 2010 20:10:30 +0200funnyIs Ada still useful?<p>When I talk about Ada, one can probably assume I’m about to tell something about the programming language Ada and he might be right. Ada is an object oriented programming language which was initially developed by the <a href="http://www.defense.gov/">DoD</a> because they needed a solid base to build on. They needed tested, compatible, and sane tools. They needed a standardized programming language that’s strongly typed, so this is where Ada came in. <br/><br/> Read more about the Ada programming language on <a href="http://en.wikipedia.org/wiki/Ada_(programming_language)">wikipedia</a>. <br/><br/> If you are a pascal programmer or even a “delphi” coder you might feel at home when you put your hands on Ada because it all looks and feels like pascal though Ada is much more than a blind copy. <br/><br/><br/></p><h3>What compiler should I use?</h3> <br/><a href="http://libre.adacore.com/libre/">GNAT</a>. Really…this is the best supported Ada compiler these days and it’s almost available everyhwere. If you are running debian or ubuntu you can simply install gnat by issuing “apt-get install gnat” or if not search for it “apt-cache search gnat” and install the appropriate package. <br/><br/><br/><h3>I want to learn Ada</h3> <br/> Don’t believe Ada is a widely supported language. There will be times when you can’t fix an issue yourself and are stuck on yourself, too…there is a mailinglist but it’s run by adacore and you have to rely on them. <br/><br/> However… <br/><br/> In the www there are many resources to learn Ada and due to the standards defined you can rely on almost every piece of code out there. Some books are horribly and some are good. You will have to find out yourself… <br/><br/><ul><li><a href="http://en.wikibooks.org/wiki/Ada_Programming">Wikibook</a></li> <li><a href="http://www.adahome.com/Tutorials/Lovelace/lovelace.html">Lovelace</a></li> <li><a href="http://www.infres.enst.fr/~pautet/Ada95/a95list.htm">Ada95 by Gordon Dodrill</a></li> <li><a href="http://www.seas.gwu.edu/~adagroup/sigada-website/barnes-html/intro.html">Ada95 by John Barnes</a></li> <li><a href="http://goanna.cs.rmit.edu.au/~dale/ada/aln.html">Quick Ada</a></li> <li><a href="http://www.cs.kuleuven.ac.be/~dirk/ada-belgium/aia/contents.html">Practical Ada</a></li> <li><a href="http://www.adahome.com/LRM/95/Rationale/rat95html/rat95-contents.html">Rational Ada</a></li> <li><a href="http://www.it.bton.ac.uk/staff/je/adacraft/">Adacraft</a></li> <li><a href="http://oopweb.com/Ada/Documents/AdaLinux/VolumeFrames.html">Ada and Linux</a></li> </ul><br/><br/><h3>So is Ada the right choice?</h3> <br/><br/> In the first few moments I really liked Ada because I like the pascal syntax and because I developed with pascal and delphi earlier before I felt home somehow…but there is this thing what programmers and software engineers heavily rely on and which is missing in Ada…the 3rd party libraries. I’m not talking about missing bindings to connect to postgresql, mysql or oracle but you may find yourself in a strange mood when you find out that these libs are very old but due to the standardized language the chance that these old bindings work is really good. In fact I could easily establish a connection to a postgresql database but still you have the feeling there is something missing. The “big support”, the feeling that some big company is taking care…no, you don’t have it. And then you also begin to realize that nobody or at least not the mass is needing this knowledge. <br/><br/> Well… <br/><br/> This is just my personal opinion and I can’t judge for you. You will have to do it on your own. Selecting the appropriate programming language is also a task of a software developer and if you are unable to choose the right thing, it’s your fault.http://schipplock.tumblr.com/post/647009217http://schipplock.tumblr.com/post/647009217Sun, 30 May 2010 17:37:00 +0200programming languagesadaprogrammingThe doctor said “only one beer per day”. Well, here...<img src="http://28.media.tumblr.com/tumblr_l36vsaukHZ1qc4nx6o1_500.jpg"/><br/><br/><p>The doctor said “only one beer per day”. Well, here it is :). </p>http://schipplock.tumblr.com/post/644055660http://schipplock.tumblr.com/post/644055660Sat, 29 May 2010 18:14:34 +0200picsfunnyCross Platform Gui Development is hard<p>Today I had a conversation about how cross platform gui development can be accomplished as easy as possible and whenever one asks that himself the first time he might be in that illusion that cross platform gui development can be easy and that it’s not a hard thing to accomplish but whenever one is thinking like that he is probably just wrong. <br/><br/> The first idea many people come across is to develop the gui application in Java most likely with the SWING gui toolkit which is shipped with SUN’s java distribution and which can be used to create cross platform gui applications that almost look native and almost feel native. Most people fear SWING because they got reminded of the old times where swing had the metal look by default which was a lot of a difference to what the native os widgets looked like. <br/><br/> However, today JAVAs SWING toolkit is not the worst idea if you want to go cross platform. You can deploy your application to linux, windows and even os-x but you will fight with a big drawback that almost any SWING application has to fight with: a slow gui. <br/> There are SWING based java applications that are quite responsive but the majority just feels slow. They don’t even need to _be_ slow but they feel slow and for a desktop application there is this one criteria that’s very important but underrated by most programmers: startup-time. <br/><br/> Startup-time for a desktop application is very important as the user, when he clicks the icon of the application, expects the app to be started immediately. It’s a simple criteria but it exists and as you know the java virtual machine takes quite some time to start up which is not a problem for server based software but for desktop apps it is. <br/><br/> If you still want to go the java route and hate swing there is an alternative which in fact is quite a good idea. It’s called SWT, is part of eclipse and implements the native ui of the os specifically so if you want to deploy your app on os-x you’ll have to ship the os-x jar explictly. The drawback is that there aren’t many gui builder available (there is one which seems buggy). <br/><br/> There are some other gui libraries for java but the most stable are AWT, Swing and SWT which you can consider to use if you want to develop cross platform gui applications. <br/><br/> If you aren’t the java guy, but like c++, the fastest way to develop cross platform gui applications is to use Qt from Nokia. Really, the lib is one of the best you may come across when hacking c++ plus Nokia gives you the Qt IDE for free which is a killer app productivity-wise. Learning the Qt API is also very easy if you are used to programming in general and building for different platforms is a breeze. The only drawback is the license which is restrictive if you want to modify the core of Qt itself. If you just want to develop your next commercial software on top of Qt it’s absolutely no problem but it’s still a bitter taste in your mouth. Consider this license “issue” when you are doing serious development. <br/><br/> So what else do we have to cross develop gui applications? C with Gtk? C++ with FLTK? Flex? Na…we want it native! Almost at least! <br/><br/> Depending on what specific operating systems you want to support it may change your decision on what to use. If you are just want to target Windows and Linux it’s easier to choose the right tool for the right job compared to supporting OS-X, Linux and Windows at once just because the whole desktop and usage of OS-X and Linux or Windows is quite different. There are so tiny differences that make you cry out loud like OS-X not having a “tray notification bar” which is available under most Linux and Windows desktops and which can be very usable for desktop applications. There is such a thing in OS-X as well (upper right corner) but it’s still different. <br/><br/> Window management under OS-X is different. You close the main window of an app in windows and it will close the entire app (standard behaviour). You can still add that behaviour to your OS-X variant. Sure but you’ll have to take all those tiny differences and make it work. <br/><br/> Sometimes it even makes more sense to write for each platform than to have all the hassles fixing the differences with a lot of conditionals in your code. <br/><br/> Under OS-X your best bet is Xcode which is on the second DVD and which is free but you’ll have to learn objective-C which is quite a strange language if you are used to C or any other c-style language. <br/><br/> And now I’m going to tell you one big secret about me and my plans in the future and why this topic ruined many weekends trying to figure out how to develop the most generic app that runs on Windows, Linux and OS-X and I tell you what: I failed…I failed all the times and the reason is that you simply can’t code that generic. It’s just impossible. <br/><br/> I _really_ downloaded Realstudio 2010 trial because they promised cross platform development with that tool is possible and simple plus you can create binaries for Windows, Linux and OS-X under one OS (cross compiling). <br/><br/> I tried that and yes, you can do all that and it’s really a breeze to work with realstudio and I even bought a license in the end but there is still the issue of different concepts for each operating system. Realstudio handles these quite well but at some points you still have to workaround with conditionals. <br/><br/> I’m still hacking perl and clojure to develop web services and all kinds of things but for cross platform gui development realstudio 2010 is really one way to go though you have to code in a basic dialect. The only drawback is the licensecosts but the prices are quite low. I bought an os-x pro license so I can test on all supported operating systems. <br/><br/> So what? Nothing! Just that cross platform gui development needs careful thinking before you invest time that will be wasted somewhere. Think about it before you start. <br/><br/> Kind regards,<br/> Andreas.</p>http://schipplock.tumblr.com/post/647469602http://schipplock.tumblr.com/post/647469602Tue, 30 Mar 2010 00:00:00 +0200programmingPostgresql count array length<p>I faced a problem today. I defined the following table: <br/><br/></p> <pre class="prettyprint src">create table todos ( id integer primary key, user_id integer references users(id), priority smallint not null default 5, category text, title text not null, body text not null, created_on timestamp not null default CURRENT_TIMESTAMP, created_by integer references users(id), finish_on timestamp not null default CURRENT_TIMESTAMP, repeat text not null default 'none' check (repeat in ('none','yearly','monthly','weekly','daily')), reminder integer[] default '{ 44640, 10080, 8640, 7200, 5760, 4320, 2880, 1400 }', done boolean not null default false ); </pre> <p><br/> And the remind field is an array of integers and postgresql allows me to have a dynamic array with unspecified length but the drawback is that there is no real function to simply get the array length. <br/><br/> However, with the following snippet, it’s simple: <br/><br/></p> <pre class="prettyprint src">select count(*) from (select regexp_split_to_table(array_to_string(reminder, '-'), '-') from todos where id=0) as foo; </pre> <p><br/><br/> Just define a delimiter that works for your array and change the where-clause to fit your needs :). <br/><br/> Andreas Schipplock.</p>http://schipplock.tumblr.com/post/647453459http://schipplock.tumblr.com/post/647453459Fri, 19 Feb 2010 00:00:00 +0100programmingsqlpostgresqlClojure contrib.sql timestamp in postgresql<p>Hi, I’m still playing around with clojure and I wanted to do something with my postgresql database system and I started using clojure.contrib.sql to connect to the database, to execute statements etc…this library is a thin wrapper around JDBC so you need the newest jar from <a href="http://jdbc.postgresql.org">jdbc.postgresql.org</a> and put it on your classpath (java -cp …). You also need <a href="http://clojure-contrib.googlecode.com">clojure-contrib</a> in your class path. I have written a quick guide on how to get started quickly with “compojure”, a web framework for clojure, and most topics there are relevant to this, too. So if you want to get started quickly, take a <a href="http://schipplock.de/2010/01/31/clojure-web-framework-compojure/">look</a>. <br/><br/> However, I faced a problem with timestamp values in contrib.sql. I wanted to save a timestamp value and normally I simply form a string that’s a compliant “timestamp” value regarding postgresqls “timestamp” type. This idea didn’t work out for contrib.sql. <br/><br/></p> <pre class="prettyprint src">(defn create-todo [user_id title body created_on created_by finish_on repeat] (sql/insert-values :todos [:user_id :title :body :created_on :created_by :finish_on :repeat] [user_id title body created_on created_by finish_on repeat])) </pre> <p><br/><br/> This definition saves a todo entry in my todoserver-database and the fields “created_on” and “finish_on” are timestamp values with a content like “2010-02-11 00:00:00” which is a valid timestamp in postgresql. However, when contrib.sql executes this statement I got an error message about a type mismatch. <br/><br/> For this to work I had to define a “cast” definition: <br/><br/></p> <pre class="prettyprint src">(defn timestamp [time-string] (java.sql.Timestamp/valueOf time-string)) </pre> <p><br/><br/> This definition returns a java.sql.timestamp suitable for the jdbc driver. <br/><br/> I use it like that: <br/><br/></p> <pre class="prettyprint src">(defn create-todo [user_id title body created_on created_by finish_on repeat] (sql/insert-values :todos [:user_id :title :body :created_on :created_by :finish_on :repeat] [user_id title body (timestamp created_on) created_by (timestamp finish_on) repeat])) </pre> <p><br/><br/> It works! However: always try to enclose your code with the (try) macro. <br/><br/></p> <pre class="prettyprint src">(GET "/create-todo" (if (master-password-correct? (params :mp)) (if (every? #(-> % params empty? not) [:for :title :body :created_on :created_by :finish_on :repeat]) (try (sql/with-connection dbc (sql/transaction (create-todo (user-id (params :for)) (params :title) (params :body) (params :created_on) (user-id (params :created_by)) (params :finish_on) (params :repeat)))) (html "ok") (catch Exception _)) (html "2:parameter list incomplete")))) </pre> <p><br/><br/> This way you are able to see the exact error message of the jdbc driver! If you aren’t, you simply get an ugly java exception output with no valuable information. <br/><br/><strong>Important:</strong> I posted a message to the clojure mailing list and it seems to be the expected behaviour of the contrib.sql lib. IMHO the examples for contrib.sql should be optimized. I wasted quite some time to figure this out :). <br/><br/> There is also a problem with the “update-values” definition and when you are giving it numbers as criteria. JDBC is thinking you are giving a string and yes, you are but pgsql doesn’t care. <br/><br/> However, when you face an error like this: <br/><br/></p> <pre>Update counts: BatchUpdateException: Message: Batch entry 0 UPDATE todos SET done='1' WHERE id='0' was aborted. Call getNextException to see the cause. SQLState: 42883 Error Code: 0 PSQLException: Message: ERROR: operator does not exist: integer = character varying Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. Position: 34 SQLState: 42883 Error Code: 0 </pre> <p><br/><br/> You can do something like this: <br/><br/></p> <pre class="prettyprint src">(defn update-todo [id attrib_map] (sql/update-values :todos ["id=?::integer" id] attrib_map)) </pre> <p><br/><br/> Do you see the postgresql typecast in there? It’s needed! I’m running pgsql 8.4.2 with the latest jdbc driver, clojure 1.1.0 and clojure-contrib 1.1.0. <br/><br/> You can call this like that: <br/><br/></p> <pre class="prettyprint src"> (GET "/todo-done" (if (master-password-correct? (params :mp)) (if-not (empty? (params :id)) (try (sql/with-connection dbc (sql/transaction (update-todo (params :id) {:done 1}))) (html "ok") (log "HINT" (str "todo entry w. id " (params :id) " has been set to done = true")) (catch Exception _))))) </pre> <p><br/><br/> You can also give “true” or “false” as ::integer value even when you defined the field in your data definition as boolean in pgsql. I accidentially did that and faced no error because boolean values are represented using integers in postgresql. I’ll add another post about the typecasts in the near future but to give you an idea for now this should get you started on clojure.contrib.sql and postgresql. <br/><br/> Hope you liked it!<br/><br/> Kind regards,<br/> Andreas Schipplock.</p>http://schipplock.tumblr.com/post/647462484http://schipplock.tumblr.com/post/647462484Sun, 14 Feb 2010 00:00:00 +0100programmingclojurepostgresqlClojure Web Framework Compojure<p>I’ve been playing around with clojure this weekend and after I learned the basics of the language I wanted to see what possibilities I have to do web development using clojure because it’s one of my main interests for now and the last few years. <br/><br/> I googled for “clojure web framework” and found <a href="http://github.com/weavejester/compojure/">compojure</a> and though I had no idea about its quality I tried it out. <br/><br/> Compojure embeds the jetty http server and though you are not limited to jetty it’s a good default choice and my primary goal is also to embed jetty because I want to have it behind a reverse proxy like <a href="http://www.apsis.ch/pound/">pound</a> so I have the maximum flexibility. Jetty is fast, solid and easy to use. <br/><br/> To get yourself started quickly, create a directory where you will store all required jar files for your compojure web application like “/home/andreas/clojure/jars/”. You’ll need the following files:</p> <ul><li>clojure.jar (get it here: <a href="http://code.google.com/p/clojure/">clojure.googlecode.com</a>)</li> <li>clojure-contrib.jar (get it here: <a href="http://code.google.com/p/clojure-contrib/">clojure-contrib.googlecode.com</a>)</li> <li>compojure.jar and its dependencies (see <a href="http://en.wikibooks.org/wiki/Compojure/Getting_Started#Build_from_Source">wikibooks</a>)</li> </ul><p>You now should have the following files:</p> <ul><li>clojure-contrib.jar</li> <li>commons-fileupload-1.2.1.jar</li> <li>grizzly-http-servlet-1.9.10.jar</li> <li>jetty-util-6.1.15.jar</li> <li>clojure.jar</li> <li>commons-io-1.4.jar</li> <li>grizzly-http-webserver-1.9.10.jar</li> <li>servlet-api-2.5-20081211.jar</li> <li>commons-codec-1.3.jar</li> <li>compojure.jar</li> <li>jetty-6.1.15.jar</li> </ul><p>Regarding the <a href="http://en.wikibooks.org/wiki/Compojure/Getting_Started#Hello_World_with_Embedded_Jetty">wikibooks</a> hello world your hello world could look like this: <br/><br/></p> <pre class="prettyprint src">(ns hello-world (:use compojure)) (defroutes greeter (GET "/" (html [:h1 "Hello World"]))) (run-server {:port 8080} "/*" (servlet greeter)) </pre> <p>I am using gedit with the external tools plugin which is not activated by default on ubuntu but you can simply enable it in the preferences. This plugin is very useful for what I need because for this example we need a simple script that calls clojure. <br/><br/> My script for executing/compiling a clojure file looks like this: <br/><br/></p> <pre class="prettyprint src">#!/bin/bash for f in /home/andreas/clojure/jars/*.jar; do CLASSPATH=$CLASSPATH:$f done java -cp $CLASSPATH clojure.main $GEDIT_CURRENT_DOCUMENT_NAME </pre> <p><br/> If you try out the hello world example and execute it you can open your webbrowser at “localhost:8080” and you’ll see your hello world message. <br/><br/> Now if you want to distribute your web app to some customer’s server you probably don’t want to publish the source code (depends :P), so whether you create a <a href="http://en.wikibooks.org/wiki/Compojure/Getting_Started#Hello_World_in_a_War_file">war file</a> which would expect a running application server being there set up or you are going the route to have a standalone clojure/java app running that embeds jetty and runs in the background as a so called daemon. In this case you need to use a dedicated port just for this app but using pound it can give you a great flexibility (app servers are flexible, too; it simply depends). <br/><br/> In the case you want to create a standalone jar file that you can start with java -jar you have to modify your hello world example and your buildscript: <br/><br/><strong>the hello world example modified</strong><br/><br/></p> <pre class="prettyprint src">(ns main (:gen-class) (:use compojure)) (defroutes greeter (GET "/" (html [:h1 "Hello World"]))) (defn -main [] (run-server {:port 8080} "/*" (servlet greeter))) </pre> <p><br/><br/><strong>the script to build a jar file</strong><br/><br/></p> <pre class="prettyprint src">#!/bin/bash for f in /home/andreas/clojure/jars/*.jar; do CLASSPATH=$CLASSPATH:$f done echo "Main-Class: main" > $GEDIT_CURRENT_DOCUMENT_DIR/Manifest.txt echo "Class-Path: ." >> $GEDIT_CURRENT_DOCUMENT_DIR/Manifest.txt rm -rf $GEDIT_CURRENT_DOCUMENT_DIR/classes/* mkdir -p $GEDIT_CURRENT_DOCUMENT_DIR/classes for f in /home/andreas/clojure/jars/*.jar; do unzip -u $f -d $GEDIT_CURRENT_DOCUMENT_DIR/classes/ > /tmp/foo done CLASSPATH=$CLASSPATH:classes/ rm -rf $GEDIT_CURRENT_DOCUMENT_DIR/classes/META-INF java -cp $CLASSPATH clojure.main -e "(compile 'main)" > /tmp/foo jar cmf $GEDIT_CURRENT_DOCUMENT_DIR/Manifest.txt $GEDIT_CURRENT_DOCUMENT_NAME.jar -C classes . > /tmp/foo java -jar $GEDIT_CURRENT_DOCUMENT_NAME.jar </pre> <p>Gedit has a tiny bug that prevents the java process to be killed after execution. Kill the process manually and you can start the jar with “java -jar main.clj.jar”. Rename the file if you wish to do so. <br/><br/><strong>serving static files</strong><br/> by default your static files are expected to reside in “public”. <br/><br/></p> <pre class="prettyprint src">(defroutes greeter (GET "/" (html (greet "andreas"))) (GET "/*" (or (serve-file (params :*)) :next)) (ANY "*" (page-not-found))) </pre> <p><br/><strong>implement your favicon</strong><br/><br/></p> <pre class="prettyprint src">(defroutes greeter (GET "/favicon.ico" (redirect-to "/fav.ico")) (GET "/" (html (greet "andreas"))) (GET "/*" (or (serve-file (params :*)) :next)) (ANY "*" (page-not-found))) </pre> <p><br/> It only works if you serve static files as shown in this example. <br/><br/><strong>get GET parameters</strong><br/><br/></p> <pre class="prettyprint src">(GET "/greet" (html (greet (params :user)))) </pre> <p><br/><br/> For web development you probably want to read config values from a json file:<br/><br/> 1.) set up lein (see <a href="http://github.com/technomancy/leiningen/blob/master/README.md">this text</a>)<br/> 2.) clone the clojure-json repository:</p> <pre class="prettyprint src">git clone git://github.com/danlarkin/clojure-json.git</pre> <p><br/> 3.) cd to clojure-json and issue:</p> <pre class="prettyprint src">lein jar</pre> <p><br/>This will create a jar that you have to put in your jar folder or add it to your classpath.<br/><br/><strong>Let’s assume the following json file:</strong><br/><br/></p> <pre class="prettyprint src">{ "database": { "host": "127.0.0.1", "user": "postgres", "pass": "secret", "name": "mydatabase" }, "email": { "user": "foo@bar.com", "pass": "mysecret" } } </pre> <p><br/><br/> Let’s assume you want to get the value of the database host:<br/><br/></p> <pre class="prettyprint src">(ns my.config) (require '(org.danlarkin [json :as json])) (defn read-custom-config [file] (json/decode-from-str (slurp file))) (println (-> (read-custom-config "config.json") :database :host)) </pre> <p><br/><br/> You can also write it like this:<br/><br/></p> <pre class="prettyprint src">(ns my.config) (require '(org.danlarkin [json :as json])) (defn read-custom-config [file] (json/decode-from-str (slurp file))) (println (:host (:database (read-custom-config "config.json")))) </pre> <p><br/><br/> For now that’s all I know about compojure, too :).</p>http://schipplock.tumblr.com/post/647448932http://schipplock.tumblr.com/post/647448932Sun, 31 Jan 2010 00:00:00 +0100programmingclojureA quick dig example<p><span> <p>Hi, sometimes you are about to register a domainname beneath some “strange” topleveldomain like .tl, .pe, .ec and so on and in all cases you have to enter a nameserver which is responsible for that domainname you will register and I once got into trouble with cocca.cx which is the registry for .tl. I registered a name and told the nameservers but after a few months users complained that they can’t resolve my domainname but I also had a lot of users who could resolve that domainname so I believed it was a misconfigured nameserver of the side of the users…</p> <p>But in the end I was utterly wrong.</p> <p>The real problem was that the responsible dns servers of cocca weren’t synchronized so a that a bunch were up and running with correct nameserver information and some others weren’t.</p> <p>I could easily find out with “dig”:</p> <p>1.) dig</p> <p>This gives you a list of all root nameservers. Pick one, e.g. “L.ROOT-SERVERS.NET.”.</p> <p>2.) dig @L.ROOT-SERVERS.NET. as.tl</p> <p>…where “as.tl” is your desired domainname like “heise.de” e.g. It will give you a list of responsible nameservers of the associated registry which controls the topleveldomain. Pick one!</p> <p>3.) dig @ns.anycast.nic.tl. as.tl</p> <p>Do not forget to append your domainname again…you should now get a list of _your_ nameservers or the ones of your provider. If that works, the chosen nameserver “ns.anycast.nic.tl.” works and has valid records…you now have to cycle through all of them to find out if they are all synchronized!</p> <p>I’m sure you can automate all this but I just wanted to give a straight “way” to walk through to find out if your registrys nameservers are well configured…</p> <p>Hope it will help some day :P…</p> </span></p>http://schipplock.tumblr.com/post/647436907http://schipplock.tumblr.com/post/647436907Sun, 12 Jul 2009 00:00:00 +0200domains