<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title>Code, the universe and everything</title>
	<link href="http://oberschweiber.com/atom.xml" rel="self" />
	<link href="http://oberschweiber.com" />
	<updated>2011-09-17T02:13:45-07:00</updated>
	<id>http://oberschweiber.com</id>
	<author>
		<name>Jonas Oberschweiber</name>
		<email>jonas@oberschweiber.com</email>
	</author>
	
	
	<entry>
		<title>Background blit performance in pygame</title>
		<link href="http://oberschweiber.com" />
		<updated>2011-09-17T00:00:00-07:00</updated>
		<id>http://oberschweiber.com/2011/09/17/pygame-background-blit-performance</id>
		<content type="html">&lt;p&gt;I&amp;#8217;m participating in this week&amp;#8217;s &lt;a href='http://pyweek.org'&gt;pyweek&lt;/a&gt; and was having performance problems blitting a background image to the screen. Specifically, the game dropped to 20 frames per second on my brother&amp;#8217;s five year old Linux box. The fix was simple, but not that easy to find if you don&amp;#8217;t know where to look: There are &lt;a href='http://www.pygame.org/docs/ref/surface.html#Surface.convert'&gt;convert&lt;/a&gt; and &lt;a href='http://www.pygame.org/docs/ref/surface.html#Surface.convert_alpha'&gt;convert_alpha&lt;/a&gt; methods that will turn the surface into a more efficient in-memory format, greatly speeding up blitting. If you don&amp;#8217;t do the conversion yourself, pygame has to convert the surface on every blit. That&amp;#8217;s why the performance impact is worse when blitting larger images.&lt;/p&gt;

&lt;p&gt;Use them like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='python'&gt;&lt;span class='bp'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;background&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;pygame&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;image&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;load&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;#39;gfx/bg01.png&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;convert&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
	</entry>
	
	<entry>
		<title>Emacs + Clojure + Slime + Ring + Reloading</title>
		<link href="http://oberschweiber.com" />
		<updated>2009-04-08T00:00:00-07:00</updated>
		<id>http://oberschweiber.com/2009/04/08/emacs-clojure-slime-ring-reloading</id>
		<content type="html">&lt;p&gt;I was just playing around a bit with the &lt;a href='http://github.com/mmcgrana/ring'&gt;Ring&lt;/a&gt; library for Clojure and wanted to be able to use it from within Emacs/Slime. Getting Jetty to start is actually really easy: You just start it like they do in the examples that come with Ring.&lt;/p&gt;

&lt;p&gt;Reloading upon recompile (using C-c C-c), however, did not work out of the box. Jetty continued to use the old version of whatever Ring fed it (a Servlet, I suppose). Now Ring has this concept of a middleware, which is basically a function that wraps your own function and performs some magic before calling that. One of the included middlewares is &amp;#8220;reload&amp;#8221;, which, on every request, reloads a set of namespaces you pass it. This did not work for me. It always complained about not being able to find the namespace I passed it and the documentation actually clearly states that it would only work with .clj-files, not with jars or compiled classes. What did work, however, was something much simpler:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='clojure'&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='k'&gt;defn &lt;/span&gt;&lt;span class='nv'&gt;app&lt;/span&gt; &lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='nv'&gt;req&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&gt; &lt;span class='o'&gt;...&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='k'&gt;defn &lt;/span&gt;&lt;span class='nv'&gt;reloader&lt;/span&gt; &lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='nv'&gt;req&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&gt;
  &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nf'&gt;app&lt;/span&gt; &lt;span class='nv'&gt;req&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt;

&lt;span class='c1'&gt;;; now call jetty.run and pass it reloader as the app&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now when you make a change to app and hit C-c C-c to compile it, refreshing the page should execute your new code. My guess is that this works because Ring creates a Servlet class using the function you pass it which then gets passed to Jetty. When you recompile your function, that class stays the same. The function that gets passed will, however, be aware of the environment around it. So when you (by recompiling) change the definition of &amp;#8220;app&amp;#8221;, &amp;#8220;reloader&amp;#8221; will use that from then on.&lt;/p&gt;</content>
	</entry>
	
	<entry>
		<title>Programming Clojure</title>
		<link href="http://oberschweiber.com" />
		<updated>2009-02-18T00:00:00-08:00</updated>
		<id>http://oberschweiber.com/2009/02/18/programming-clojure</id>
		<content type="html">&lt;p&gt;Over the course of the last week I&amp;#8217;ve been reading through &amp;#8220;Programming Clojure&amp;#8221; by Stuart Halloway. The book is currently in beta and you can buy it over at &lt;a href='http://www.pragprog.com/titles/shcloj/programming-clojure'&gt;Pragmatic Programmers&lt;/a&gt;. This is the first beta book I&amp;#8217;ve ever bought and in fact the first eBook I&amp;#8217;ve ever bought. It is also what inspired my previous post about PDF reading devices. I first tried to get it onto my iPhone and read it via &lt;a href='http://lexcycle.com'&gt;Stanza&lt;/a&gt;, but the formatting got all messed up. It was really unreadable, so I just continued to read it on my notebook. Not the best experience, but acceptable.&lt;/p&gt;

&lt;p&gt;First, a thought on beta books in general: I like the idea of getting early access to content. I&amp;#8217;m usually an impatient guy and when I wanted to read the book and saw it would only be out in print in April I decided to give the beta a shot. I was positively surprised. The quality is really good and everything seemed to be there. There were no obvious &amp;#8220;holes&amp;#8221; in the book, only a few spelling mistakes. I would buy a beta book again.&lt;/p&gt;

&lt;p&gt;Now, for the book itself: I like it. It definitely is a better introduction to Clojure than any of the (really sparse) tutorials I&amp;#8217;ve found online. The basics are explained quickly and with a bit of preliminary Lisp knowledge (e.g. Scheme) you will be able to read Clojure source after little time.&lt;/p&gt;

&lt;p&gt;A highlight is the chapter on concurrency. The up- and downsides of the four Clojure concurrency primitives are well explained and there even is a small example in which the author demonstrates how you would choose between them.&lt;/p&gt;

&lt;p&gt;If you want to get into Clojure (and you really should!) this book is a great start. I have also found that it helps to subscribe to the &lt;a href='http://groups.google.com/group/clojure'&gt;Clojure mailing list&lt;/a&gt; and just try to read as much of it as you can, even if you are not able to participate in the discussion. Clojure seems to be a language that is changing constantly and the book obviously can&amp;#8217;t keep up with all the changes, so the list is your best chance of keeping up.&lt;/p&gt;</content>
	</entry>
	
	<entry>
		<title>The One Missing Device</title>
		<link href="http://oberschweiber.com" />
		<updated>2009-02-11T00:00:00-08:00</updated>
		<id>http://oberschweiber.com/2009/02/11/the-one-missing-device</id>
		<content type="html">&lt;p&gt;With all the devices out there, all the computers and phones and everything, there is still one device I&amp;#8217;m missing: A decent, portable PDF reader. Why? To read technical eBooks. From what I can see, there really is no device that does that well. I first had hopes that the Kindle would, but from what I am reading, it and other eBook readers all have flawed PDF support. Besides, it is not available in Germany anyway.&lt;/p&gt;

&lt;p&gt;I realize that PDF is not a good eBook format. It is a terrible one, in fact. What PDF is designed for is to give similar output on both the screen and physical paper. The content is not allowed to reflow (exception: there is an extension in newer versions of the PDF file, which is not heavily used as far as I can tell). This is bad for eBook readers, which often have a limited screen (on the other hand, you would not want the reader to reflow the code samples).&lt;/p&gt;

&lt;p&gt;There must be some way to have a whole A4 or Letter page displayed readably on a screen. Netbooks might be a solution and so might traditional Table PCs, I have yet to try them. (Although the latter is sort of out of the question for cost reasons) What I did try was turning my 15&amp;#8221; MacBook Pro on the side and then rotating the internal screen using &lt;a href='http://www.magesw.com/displayrotation/'&gt;Display Rotation Menu&lt;/a&gt;. This works to some extent, but the notebook is just too heavy to hold for extended periods of time.&lt;/p&gt;</content>
	</entry>
	
</feed>
