<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kasper Johansen&#039;s blog</title>
	<atom:link href="http://wordpress.kaspernj.org/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://wordpress.kaspernj.org</link>
	<description>A blog about Linux, Open Source and my life.</description>
	<lastBuildDate>Sat, 28 Aug 2010 14:30:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Handeling retries, timeouts and errors in Ruby</title>
		<link>http://wordpress.kaspernj.org/?p=119</link>
		<comments>http://wordpress.kaspernj.org/?p=119#comments</comments>
		<pubDate>Sat, 28 Aug 2010 12:02:24 +0000</pubDate>
		<dc:creator>Kasper Johansen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[knjrbfw]]></category>
		<category><![CDATA[retries]]></category>
		<category><![CDATA[retry]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[timeout]]></category>

		<guid isPermaLink="false">http://wordpress.kaspernj.org/?p=119</guid>
		<description><![CDATA[I have now coded many apps that uses SOAP, Rest and normal HTTP/Regex-parsing. The problem in many of these apps, is that the system I am communicating with sometimes timeouts or returns invalid XML, which makes my scripts crash or at least very sad.
I then came up with a very handy-retry class, which implements the [...]]]></description>
			<content:encoded><![CDATA[<p>I have now coded many apps that uses SOAP, Rest and normal HTTP/Regex-parsing. The problem in many of these apps, is that the system I am communicating with sometimes timeouts or returns invalid XML, which makes my scripts crash or at least very sad.</p>
<p>I then came up with a very handy-retry class, which implements the Timeout-class from Ruby&#8217;s standard-lib and extends it with being able to retry the given operating catching specific or all exceptions.</p>
<p>The problem is that every time you just want et to retry your code-block, you have to write a whole new loop, keep count of the times you have retried, implement the timeout-functionality, and even though this is properly between 10 to 20 lines of code in Ruby, it is very annoying &#8211; and lets face it, you should not write the same code three times.</p>
<p>To use this retry-functionality, you can do something like this:</p>
<pre class="brush:ruby">count = 0
Knj::Retry.try(:tries =&gt; 5, :timeout =&gt; 3, :errors =&gt; [RuntimeError]) do
   count += 1
   print "Try #{count.to_s}\n"
   raise "Test"
end</pre>
<p>In my opinion the script pretty much speaks for itself. It will try to run the block 5 times, if the block takes more than 3 seconds to execute it will try again, if the block raises an error of the class RuntimeError, it will be caught and the block will then be tried again.</p>
<p>It it hits the maximum executions, the exception will actually be thrown and not caught. If &#8220;:errors&#8221; is not given, it will catch all errors except Interupt and SystemExit (though you can give it a :exit =&gt; false to not catch the SystemExit).</p>
<p>This way of handling retries and timeouts makes it much more safe for me to write SOAP-, Rest- and HTTP/Regex-parsing scripts &#8211; and have drastically reduced my error reports from these scripts to almost zero.</p>
<p>If you want to have look at the code the Knj::Retry-class, visit &#8220;knjrbfw&#8221; at Github.com here:</p>
<p><a href="http://github.com/kaspernj/knjrbfw/blob/master/retry.rb" target="_blank">http://github.com/kaspernj/knjrbfw/blob/master/retry.rb</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.kaspernj.org/?feed=rss2&amp;p=119</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advarsel mod Stofa Net og Stofa TV!!!</title>
		<link>http://wordpress.kaspernj.org/?p=115</link>
		<comments>http://wordpress.kaspernj.org/?p=115#comments</comments>
		<pubDate>Tue, 06 Jul 2010 08:00:05 +0000</pubDate>
		<dc:creator>Kasper Johansen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://wordpress.kaspernj.org/?p=115</guid>
		<description><![CDATA[Jeg blev meget glad, da jeg så af kabel-tv udbyderen Stofa tilbød 50 mbit på min vej. De var meget hurtige til at få sendt udstyret ud, og jeg kom næsten problemfrit på.
Det kørte perfekt de første 2 uger. Derefter begyndte jeg at ryge af nettet næsten tilfældigt. Jeg forsøgte at få deres support til [...]]]></description>
			<content:encoded><![CDATA[<p>Jeg blev meget glad, da jeg så af kabel-tv udbyderen Stofa tilbød 50 mbit på min vej. De var meget hurtige til at få sendt udstyret ud, og jeg kom næsten problemfrit på.</p>
<p>Det kørte perfekt de første 2 uger. Derefter begyndte jeg at ryge af nettet næsten tilfældigt. Jeg forsøgte at få deres support til at hjælpe mig, som lavede alle mulige målinger, og godt kunne se at der var noget i vejen. Jeg snakkede med naboerne, som også havde haft problemer i et stykke tid &#8211; en af dem havde faktisk haft det sådan i et år!!</p>
<p>Stofa er dog ikke istand til at hjælpe og deres drifts SMS og email er næsten som spam!! VÆLG ALDRIG STOFA HVIS DU STÅR OG SKAL BESTILLE INTERNET!!!</p>
<p>Jeg håber det her når ud på Google, så andre ikke begår samme fejl som jeg selv.</p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.kaspernj.org/?feed=rss2&amp;p=115</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby-GTK behavior in JRuby-GTK (using Java&#8217;s GTK)</title>
		<link>http://wordpress.kaspernj.org/?p=85</link>
		<comments>http://wordpress.kaspernj.org/?p=85#comments</comments>
		<pubDate>Fri, 25 Jun 2010 18:28:43 +0000</pubDate>
		<dc:creator>Kasper Johansen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://wordpress.kaspernj.org/?p=85</guid>
		<description><![CDATA[When I first started playing around with JRuby, I quickly found out, that the GTK-extension for Ruby did not work with JRuby, since it was a native C-extension, which could not be loaded into Java.
To load GTK in JRuby anyway, I had to install the Java GTK on my Ubuntu machine. This is pretty easy [...]]]></description>
			<content:encoded><![CDATA[<p>When I first started playing around with JRuby, I quickly found out, that the GTK-extension for Ruby did not work with JRuby, since it was a native C-extension, which could not be loaded into Java.</p>
<p>To load GTK in JRuby anyway, I had to install the Java GTK on my Ubuntu machine. This is pretty easy &#8211; just fire off a &#8220;sudo aptitude install libjava-gnome-java&#8221; and your done&#8230;</p>
<p>Java&#8217;s GTK is a lot different from the Ruby version. First of all a lot of the Ruby-objects has optimized constructors. You can construct a window with a title by doing:</p>
<pre class="brush:ruby">window = Gtk::Window.new("The title")</pre>
<p>In Java this is not possible, so if you give the argument your app fails. This meant that JRuby wasnt able to handle some of my GTK-apps. I then decided to write a kind of wrapper, which would emulate the behavior of the Ruby-GTK in JRuby-GTK (Java&#8217;s GTK). This turned out to be a lot harder than I first thought.</p>
<p>First off I had to make dynamic events-classes for the connect-method, to first do it the Java-way and then call blocks in Ruby to turn it into the Ruby way &#8211; which I had never done before.</p>
<p>All in all I was able to get the following examples to work in JRuby with Java&#8217;s GTK loaded:</p>
<pre class="brush:ruby">require "knj/jruby-gtk2/gtk2.rb"
require "knj/jruby-gtk2/gladexml.rb"

class WinAppEdit
	def initialize
		@glade = GladeXML.new("win_app_edit.glade"){|h|method(h)}
		@glade["window"].show_all
	end

	def on_btnSave_clicked
		print "Save clicked.\n"
	end

	def on_btnCancel_clicked
		print "Cancel clicked.\n"
	end

	def on_window_destroy
		print "Destroyed!\n"
		Gtk.main_quit
	end
end

WinAppEdit.new

Gtk.main</pre>
<p>And the normal one:</p>
<pre class="brush:ruby">require "knj/jruby-gtk2/gtk2.rb"

button = Gtk::Button.new("Test")
button.connect("clicked") do
	print "Clicked!\n"
end

win = Gtk::Window.new("Trala")
win.add(button)
win.show_all

win.connect("destroy") do
	print "Destroy!\n"
	Gtk.main_quit
end

Gtk.main</pre>
<p>Why go through all of this, just so my Ruby-GTK applications can run through JRuby? Scalability, real threads, packaged Java-apps and so on&#8230;</p>
<p>The whole thing can be checked out at my account on GitHub:</p>
<p><a href="http://github.com/kaspernj/knjrbfw">http://github.com/kaspernj/knjrbfw</a></p>
<p><a href="http://github.com/kaspernj/knjrbfw/blob/master/jruby-gtk2/gtk2.rb">http://github.com/kaspernj/knjrbfw/blob/master/jruby-gtk2/gtk2.rb</a></p>
<p><a href="http://github.com/kaspernj/knjrbfw/blob/master/jruby-gtk2/gladexml.rb">http://github.com/kaspernj/knjrbfw/blob/master/jruby-gtk2/gladexml.rb</a></p>
<p>Be warned that this project is far from done &#8211; its actually more a proof of concept for myself <img src='http://wordpress.kaspernj.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.kaspernj.org/?feed=rss2&amp;p=85</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby and GTK on the N900</title>
		<link>http://wordpress.kaspernj.org/?p=84</link>
		<comments>http://wordpress.kaspernj.org/?p=84#comments</comments>
		<pubDate>Sun, 10 Jan 2010 20:34:40 +0000</pubDate>
		<dc:creator>Kasper Johansen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://wordpress.kaspernj.org/?p=84</guid>
		<description><![CDATA[I finally compiled Ruby and GTK packages for the N900. It was a very big disappointment, when I found out that neither the official or the extras repositories had any ruby-gtk packages &#8211; even though Ruby itself had been packaged (but not optified).
Because of this, I decided to compile my own Ruby packages, which I [...]]]></description>
			<content:encoded><![CDATA[<p>I finally compiled Ruby and GTK packages for the N900. It was a very big disappointment, when I found out that neither the official or the extras repositories had any ruby-gtk packages &#8211; even though Ruby itself had been packaged (but not optified).</p>
<p>Because of this, I decided to compile my own Ruby packages, which I have just tested on my phone (I cross-compiled them on my laptop).</p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.kaspernj.org/?feed=rss2&amp;p=84</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Borders on images with rounded corners using GD-lib in PHP</title>
		<link>http://wordpress.kaspernj.org/?p=78</link>
		<comments>http://wordpress.kaspernj.org/?p=78#comments</comments>
		<pubDate>Wed, 25 Nov 2009 19:54:06 +0000</pubDate>
		<dc:creator>Kasper Johansen</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://wordpress.kaspernj.org/?p=78</guid>
		<description><![CDATA[I just extended my &#8220;image.php&#8221;-script (which I have written about in a previous post) to be able to add borders on images. Nothing special really &#8211; except the script also supports doing it with rounded corners. Its actually just extending the rounded-corners-function, because it would be a hell doing it manually on a picture, after [...]]]></description>
			<content:encoded><![CDATA[<p>I just extended my &#8220;image.php&#8221;-script (which I have written about in a previous post) to be able to add borders on images. Nothing special really &#8211; except the script also supports doing it with rounded corners. Its actually just extending the rounded-corners-function, because it would be a hell doing it manually on a picture, after it had gotten rounded corners.</p>
<p>Its done by adding &#8220;edgeborder=htmlcolor&#8221;. Like this:</p>
<pre class="brush:bash">https://www.kaspernj.org/image.php?picture=temp/kasper_test_blog.jpg&amp;edgeborder=0000ff&amp;edgesize=35&amp;bgcolor=000000&amp;force=true&amp;width=400</pre>
<p>&#8230;which will result in:</p>
<p><img class="alignnone" src="https://www.kaspernj.org/image.php?picture=temp/kasper_test_blog.jpg&amp;edgeborder=0000ff&amp;edgesize=35&amp;bgcolor=000000&amp;force=true&amp;width=400" alt="" width="400" height="306" /></p>
<p>This enables me to make nice rounded images with borders &#8211; without having to send tons of HTML to the client. The image is even cached through the image.php-cache &#8211; saving both the server and the client for tons of calculations. Just sending a cached image to every clinet &#8211; wee <img src='http://wordpress.kaspernj.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.kaspernj.org/?feed=rss2&amp;p=78</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chrissi&#8217;s iPhone: Jailbreak, SSH automount and VLC+MPlayer media players</title>
		<link>http://wordpress.kaspernj.org/?p=70</link>
		<comments>http://wordpress.kaspernj.org/?p=70#comments</comments>
		<pubDate>Wed, 25 Nov 2009 19:08:45 +0000</pubDate>
		<dc:creator>Kasper Johansen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://wordpress.kaspernj.org/?p=70</guid>
		<description><![CDATA[Today Christina had a lot of trouble with getting her iPhone working with Linux. Since Apple apparently hate their own customers (Microsoft 2 anyone?), I had to take several steps to get some basic functionality up and running on her expensive phone.
First of all she needed to transfer music back and forward to the phone. [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Today Christina had a lot of trouble with getting her iPhone working with Linux. Since Apple apparently hate their own customers (Microsoft 2 anyone?), I had to take several steps to get some basic functionality up and running on her expensive phone.</p>
<p style="text-align: left;">First of all she needed to transfer music back and forward to the phone. My first guess was just using iTunes under VirtualBox &#8211; but that was just too ugly and complicated. I then jailbroke her phone using BlackRain&#8217;s tool. It was pretty easy, once I got my Windows-box connected.</p>
<p style="text-align: left;">I then installed Cydia &#8211; and through that SSH.</p>
<p style="text-align: left;">I then installed the &#8220;ipod-convenience&#8221; package on her laptop and was able to mount the iPhone via &#8220;iphone-mount&#8221;. Shortly after I found out that Apple fucked every application which worked with the iTunes-music-dir format up &#8211; simply because they didn&#8217;t want the iPhone to work with anything else than their own iTunes (wtf!?). Fucking retards&#8230;</p>
<p style="text-align: left;">I then installed MPlayer and vlc4iphone to get basic media functionality up again&#8230; Further more I set up &#8220;autofs&#8221; on Christina&#8217;s laptop and copied her SSH-key to her phone, so she didnt have to mount anything. I altered the DHCP-config, so her phone always were on the same IP. Then I made the following config in &#8220;/etc/auto.iphone&#8221; for &#8220;/media/iphone_auto&#8221;:</p>
<pre style="text-align: left;">iPhone -fstype=fuse,allow_other,reconnect,uid=1000,gid=1000 sshfs\#192.168.1.155:/var/mobile/Media</pre>
<p style="text-align: left;">Everytime Christina now accesses /media/iphone_auto/iPhone &#8211; her system will automatically try to mount her iPhone via SSHFS (SSH File System).</p>
<p style="text-align: left;">She can now copy music, pictures and all the other stuff over by using Nautilus (the filemanager of Gnome &#8211; Linux).</p>
<p style="text-align: left;">This whole thing was even easier on the OpenMoko-phone I played with a year back&#8230; I am never going Apple&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.kaspernj.org/?feed=rss2&amp;p=70</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Glade auto connect in JRuby</title>
		<link>http://wordpress.kaspernj.org/?p=66</link>
		<comments>http://wordpress.kaspernj.org/?p=66#comments</comments>
		<pubDate>Sun, 15 Nov 2009 16:26:44 +0000</pubDate>
		<dc:creator>Kasper Johansen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[auto]]></category>
		<category><![CDATA[connect]]></category>
		<category><![CDATA[glade]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[jruby]]></category>

		<guid isPermaLink="false">http://wordpress.kaspernj.org/?p=66</guid>
		<description><![CDATA[I have been playing a lot around with JRuby lately (since I was scared away from IronRuby by another lame Microsoft-patent). I have been really disappointed by the Gtk-implementation in Java &#8211; it really misses a lot of the good stuff from PHP-GTK &#8211; like the auto-connect functionality.
I decided I wanted to write my own [...]]]></description>
			<content:encoded><![CDATA[<p>I have been playing a lot around with JRuby lately (since I was scared away from IronRuby by another lame Microsoft-patent). I have been really disappointed by the Gtk-implementation in Java &#8211; it really misses a lot of the good stuff from PHP-GTK &#8211; like the auto-connect functionality.</p>
<p>I decided I wanted to write my own Glade Auto Connect functionality to learn some more about JRuby &#8211; it turned out a bit harder than I expected. In the end I got it working with some of the basic widgets (GtkButton::Clicked, GtkWindow::destroy, GtkTreeViewSelection::changed and so on). I am adding support for more events as I continue my adventure into JRuby.</p>
<p>It works like this &#8211; when you want to spawn a new Glade-object, you do it through my function:</p>
<pre class="brush:ruby">class MyWindow
  def initialize
    @glade = GladeAutoConnect("gladefile.glade", "window", self)
  end

  def on_window_destroy
    print "The window was closed!\n"
  end
end</pre>
<p>No more connecting events manually &#8211; just write the event-names in the Glade-application directly. This functionality really shortens the code &#8211; which is what I like about Ruby: Less code to write. Right now it produces some eval-code though, which I plan to remove, when I learn more about how to dynamically make new classes in Ruby.</p>
<p>The code can bee seen here:<br />
<a href="http://knjrbfw.kaspernj.org/jruby_gtk.rb">http://knjrbfw.kaspernj.org/jruby_gtk.rb</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.kaspernj.org/?feed=rss2&amp;p=66</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HowTo: Make a simple GtkWindow with IronRuby, GtkSharp, Glade and events (not Ruby-Gtk!)</title>
		<link>http://wordpress.kaspernj.org/?p=62</link>
		<comments>http://wordpress.kaspernj.org/?p=62#comments</comments>
		<pubDate>Sun, 08 Nov 2009 19:27:48 +0000</pubDate>
		<dc:creator>Kasper Johansen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[glade]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[ironruby]]></category>

		<guid isPermaLink="false">http://wordpress.kaspernj.org/?p=62</guid>
		<description><![CDATA[To make this a lot easier for the ones of us using Ubuntu, I added IronRuby to my Ubuntu-repository. Read more about how to set it up here:
http://wiki.kaspernj.org/index.php/KnjUbuntuRepository
Afterwards do a: &#8220;sudo aptitude install ironruby glade libgtk2.0-cil libglade2.0-cil&#8221;.
While you are at it, install &#8220;glade&#8221; (&#8221;glade-3&#8243; if you are using Jaunty, I think). Make a new project [...]]]></description>
			<content:encoded><![CDATA[<p>To make this a lot easier for the ones of us using Ubuntu, I added IronRuby to my Ubuntu-repository. Read more about how to set it up here:</p>
<p>http://wiki.kaspernj.org/index.php/KnjUbuntuRepository</p>
<p>Afterwards do a: &#8220;sudo aptitude install ironruby glade libgtk2.0-cil libglade2.0-cil&#8221;.</p>
<p>While you are at it, install &#8220;glade&#8221; (&#8221;glade-3&#8243; if you are using Jaunty, I think). Make a new project folder &#8211; I have called mine &#8220;IronRubyTest&#8221;. Make a small Glade-file (not GtkBuilder) with a label and a button. Remember the names &#8211; I called mine &#8220;window1&#8243;, &#8220;label1&#8243; and &#8220;button1&#8243;.</p>
<p>To load the Glade-file, we have to import some modules first. To get the names of the modules, type &#8220;gacutil -l | grep gtk&#8221; and &#8220;gacutil -l | grep glade&#8221;. Type this in the beginning of your Ruby-code:</p>
<pre class="brush:ruby">require "gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f"
require "glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f"</pre>
<p>Be aware you properly have to use the lines, that you got from the &#8220;gacutil grep&#8221;-command.Its possible that yours can be different. Then type this afterwards in the Ruby-file:</p>
<pre class="brush:ruby">include Gtk
include Glade</pre>
<p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre; "><br />
</span></p>
<p>We are now ready to begin coding our class:</p>
<pre class="brush:ruby">class MainWindow
  def initialize
    Application.init

    tha_glade = Glade::XML.new("test.glade", "window1", nil)
  end
end</pre>
<p>Notice the &#8220;Application.init&#8221; &#8211; I guess this is to init the Gtk-stuff, like you would do in other languages when you are using Gtk.</p>
<p>The GladeXML-object is stored in the &#8220;tha_glade&#8221;-variable. &#8220;window1&#8243; is the name of the Window, which can be set through Glade.</p>
<pre class="brush:ruby">...
    tha_window = tha_glade.GetWidget("window1")
    tha_window.ShowAll
    tha_window.destroyed{|sender, e|
       Application.Quit
    }

    tha_button = tha_glade.GetWidget("button1")
    tha_button.clicked{|sender, e|
       tha_window.destroy
    }</pre>
<pre>...</pre>
<p>We store the GtkWindow in the &#8220;tha_window&#8221; variable. Afterwards we attach some code to the destroy-event &#8211; we actually make the application kill itself, when we close the Window.</p>
<p>Further more we store the GtkButton in the &#8220;tha_button&#8221; variable. Afterwards we make the button close the window &#8211; which calls the other event and kills the application.</p>
<pre class="brush:ruby">main_window = MainWindow.new
Application.run</pre>
<p>The code here is placed at the very end of the file &#8211; not included in any function or class. This start our MainWindow-class, loads the window and everything and starts a loop, so our application doesnt end itself after loading the window and all.</p>
<p>The entire code can be seen here:</p>
<pre class="brush:ruby">require "gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f"
require "glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f"

include Gtk
include Glade

class MainWindow
	def initialize
		Application.init

 		tha_glade = Glade::XML.new("test.glade", "window", nil)

		tha_window = tha_glade.GetWidget("window")
		tha_window.ShowAll
		tha_window.destroyed{|sender, e|
			Application.quit
		}

		tha_button = tha_glade.GetWidget("button1")
		tha_button.clicked{|sender, e|
			tha_window.destroy
		}
	end

	def on_button1_clicked(object, event)
		print "hmm\n"
	end
end

main_window = MainWindow.new
Application.run</pre>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.kaspernj.org/?feed=rss2&amp;p=62</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New cool image-PHP-script, which can be used from every programming language</title>
		<link>http://wordpress.kaspernj.org/?p=55</link>
		<comments>http://wordpress.kaspernj.org/?p=55#comments</comments>
		<pubDate>Wed, 04 Nov 2009 16:46:54 +0000</pubDate>
		<dc:creator>Kasper Johansen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://wordpress.kaspernj.org/?p=55</guid>
		<description><![CDATA[I just wrote a new set of cool image-functions and a small script to automatically invoke and cache stuff it generates.
The script is able to do smart resizes, resizes, padding, rounded edges, caching, equal sizes, set quality and dynamically output in different support formats (jpeg, png, bmp, wbmp, gif etc).
To start with an example, I [...]]]></description>
			<content:encoded><![CDATA[<p>I just wrote a new set of cool image-functions and a small script to automatically invoke and cache stuff it generates.</p>
<p>The script is able to do smart resizes, resizes, padding, rounded edges, caching, equal sizes, set quality and dynamically output in different support formats (jpeg, png, bmp, wbmp, gif etc).</p>
<p>To start with an example, I have uploaded a picture (&#8221;kasper_test_blog.jpg&#8221;) and symlinked to the script, so I can call it. It is a picture of me holding a speech at the 2007 OpenSource Days conference. I now want the same width and height + rounded edges on the picture. I set src of an &lt;image&gt; to &#8220;image.php?picture=temp/kasper_test_blog.jpg&amp;equaldim=true&amp;edgesize=35&amp;bgcolor=000000&amp;force=true&amp;width=400&amp;padding=15&amp;paddingorigsize=true&#8221; resulting in:</p>
<p><a href="https://www.kaspernj.org/image.php?picture=temp/kasper_test_blog.jpg&amp;equaldim=true&amp;edgesize=35&amp;bgcolor=000000&amp;force=true&amp;width=400&amp;padding=15&amp;paddingorigsize=true"><img class="alignnone" title="Test image" src="https://www.kaspernj.org/image.php?picture=temp/kasper_test_blog.jpg&amp;equaldim=true&amp;edgesize=35&amp;bgcolor=000000&amp;force=true&amp;width=400&amp;padding=15&amp;paddingorigsize=true" alt="" width="400" height="400" /></a></p>
<p>This will:</p>
<ol>
<li>Make the width and height the same size because of &#8220;equaldim=true&#8221;.</li>
<li>Make 35 size rounded corners because of &#8220;edgesize=35&#8243;.</li>
<li>Use black as the backgroundcolor for everything because of &#8220;bgcolor=000000&#8243;.</li>
<li>Not use cache because of &#8220;force=true&#8221;.</li>
<li>Force the width to 400 pixels because of &#8220;width=400&#8243; (could also have used &#8220;height=400&#8243;).</li>
<li>Make 15 pixels of padding on top, bottom, left and right because of &#8220;padding=15&#8243; (still using black as color for the padding because of &#8220;bgcolor=000000&#8243;).</li>
<li>When using padding, instead of increasing the image-size by the padding, it will keep the original size because of &#8220;paddingorigsize=true&#8221;.</li>
</ol>
<p>Other possible parameters are:</p>
<ol>
<li>&#8220;quality=85&#8243; &#8211; sets a specific quality of the outputted image. Good when using it for a lot of thumbnails.</li>
<li>&#8220;type=jpg&#8221; &#8211; output the image as JPG (default is PNG). Could also be &#8220;type=bmp&#8221;, &#8220;type=gif&#8221;, &#8220;type=png&#8221;, &#8220;type=wbmp&#8221; or whatever.</li>
<li>&#8220;smartsize=200&#8243; &#8211; makes the width or height to 200 &#8211; based on which is the larger one. Great for handling sizes on a personal gallery.</li>
</ol>
<p>The sourcecode for the script and its framework can be found here:</p>
<ol>
<li>http://knjphpframework.kaspernj.org/scripts/image.php</li>
<li>http://knjphpframework.kaspernj.org/functions_knj_picture.php</li>
<li>http://knjphpframework.kaspernj.org/functions_knj_picture_bmp.php</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.kaspernj.org/?feed=rss2&amp;p=55</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgraded to Karmic!</title>
		<link>http://wordpress.kaspernj.org/?p=52</link>
		<comments>http://wordpress.kaspernj.org/?p=52#comments</comments>
		<pubDate>Thu, 29 Oct 2009 23:34:24 +0000</pubDate>
		<dc:creator>Kasper Johansen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[cpu frequency]]></category>
		<category><![CDATA[karmic]]></category>
		<category><![CDATA[kde]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://wordpress.kaspernj.org/?p=52</guid>
		<description><![CDATA[I finally upgraded to Karmic. This is the first time I have not been part of the beta or alpha.
Still, I noticed some problems. First of all, I still use KDE 3 &#8211; I am still scared of KDE 4 since the initial unstable release and dont dare using it&#8230; yet.
I had no items in [...]]]></description>
			<content:encoded><![CDATA[<p>I finally upgraded to Karmic. This is the first time I have not been part of the beta or alpha.</p>
<p>Still, I noticed some problems. First of all, I still use KDE 3 &#8211; I am still scared of KDE 4 since the initial unstable release and dont dare using it&#8230; yet.</p>
<p>I had no items in KControl what so ever. I solved this by installing &#8220;kdebase-kde3&#8243; and &#8220;kpersonalizer-kde3&#8243; and executing this command:</p>
<pre class="brush:shell">sudo ln -s /opt/kde3/etc/xdg/menus/kde-settings.menu /etc/xdg/menus
sudo ln -s /opt/kde3/etc/xdg/menus/applications-merged/kde-essential.menu /etc/xdg/menus/applications-merged/kde-essential.menu</pre>
<p>Further more I could configure the CPU frequency applet in Gnome to change frequency without requesting my password. This can be solved by entering this:</p>
<pre class="brush:shell">gksudo gedit /usr/share/polkit-1/actions/org.gnome.cpufreqselector.policy</pre>
<p>Scroll to the end of the file and change the &#8220;&#8230;admin_auth_passwd&#8221; (or something) to &#8220;yes&#8221;.</p>
<p>This post serves mostly as my own personally note for the future <img src='http://wordpress.kaspernj.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://wordpress.kaspernj.org/?feed=rss2&amp;p=52</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
