<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title>jasani.org</title><subtitle>A Wrong Turn on the Path to Enlightenment</subtitle><link rel="self" href="http://feeds.feedburner.com/AWrongTurnOnThePathToEnlightenment"></link><link href="http://jasani.org/"></link><id>url:http://jasani.org/</id><updated></updated><entry><title>Docker now supports adding host mappings</title><link href="/2014/11/19/docker-now-supports-adding-host-mappings/"></link><id>url:/2014/11/19/docker-now-supports-adding-host-mappings/</id><updated></updated><summary></summary><content type="xhtml">&lt;p&gt;In my &lt;a href='/2014/11/16/modifying-etchosts-in-docker-images-for-fun-and-profit/'&gt;previous blog entry&lt;/a&gt;, I mentioned that Docker didn't provide any way to add host-to-ip mappings to &lt;code&gt;/etc/hosts&lt;/code&gt;.  Well, the most recent version of Docker (1.3.1) now addresses that issue with a new add hosts option.  Let's take a quick look at what it does.&lt;/p&gt;&lt;p&gt;Given a standard default &lt;code&gt;/etc/hosts&lt;/code&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;% docker run -it ubuntu cat /etc/hosts
172.17.0.8	b14031841b2b
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can add a mapping for server 'foo' at '10.0.0.3'.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;% docker run -it --add-host foo:10.0.0.3 ubuntu cat /etc/hosts
172.17.0.9	189a650112db
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
10.0.0.3	foo

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can also add mappings for multiple servers, in this case 'foo' and 'bar'.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;% docker run -it --add-host foo:10.0.0.3 --add-host bar:10.7.3.21 ubuntu cat /etc/hosts
172.17.0.13	3f8543ecc372
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
10.7.3.21	bar
10.0.0.3	foo

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So far so good.  But there are a couple more scenarios to consider.  The first is how to handle the case where a single server is hosting multiple services. These services could be in a single Docker container, separate containers or not in a container at all.  What's important is that they are both on some remote server.&lt;/p&gt;&lt;p&gt;So let's consider the case where our services are named &lt;code&gt;svca&lt;/code&gt; and &lt;code&gt;svcb&lt;/code&gt;. We could try to add both of them as host mappings.  Let's see how that works out.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;% docker run -it --add-host svca:10.0.0.9 --add-host svcb:10.0.0.9 ubuntu cat /etc/hosts
172.17.0.16	5d7eaa5dcd16
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
10.0.0.9	svcb
10.0.0.9	svca

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Both services are pointing to the same IP address, but I'm not sure this is valid for &lt;code&gt;/etc/hosts&lt;/code&gt;.  The format is supposed to be &lt;code&gt;IP   hostname &amp;#91;hostalias&amp;#93;&amp;#42;&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Lucky for us, there is another option.  When invoking &lt;code&gt;add-host&lt;/code&gt;, we can include both services inside of double quotes.  It's not documented, but it does work as you can see below.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;% docker run -it --add-host &amp;quot;svca svcb&amp;quot;:10.0.0.9 ubuntu cat /etc/hosts
172.17.0.17	380df28b4612
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
10.0.0.9	svca svcb

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There we go, both services pointing to the same IP address and &lt;code&gt;/etc/hosts&lt;/code&gt; written in a valid format.&lt;/p&gt;&lt;p&gt;Another issue is how to provide hostaliases of localhost.  As far as I can tell, Docker still doesn't have anything to address this issue.  For the time being this means that I'll still be using &lt;a href='https://github.com/hiteshjasani/nim-mungehosts'&gt;Mungehosts&lt;/a&gt; to do that work.&lt;/p&gt;&lt;p&gt;In summary, &lt;code&gt;add-host&lt;/code&gt; is a valuable new tool in the Docker toolbox for pointing to remote services.  It's worked well for all the cases I needed for it and it's easy to use.  It's good to see Docker adding more config options to make our lives easier.&lt;/p&gt;</content><author><name>hitesh</name></author></entry><entry><title>Modifying /etc/hosts in Docker images for fun and profit</title><link href="/2014/11/16/modifying-etchosts-in-docker-images-for-fun-and-profit/"></link><id>url:/2014/11/16/modifying-etchosts-in-docker-images-for-fun-and-profit/</id><updated></updated><summary></summary><content type="xhtml">&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; The new Docker version 1.3.1 addresses some issues I describe in this post.  &lt;a href='/2014/11/19/docker-now-supports-adding-host-mappings/'&gt;Read about what problems Docker has solved&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Did you know that Docker doesn't let you (easily) modify &lt;code&gt;/etc/hosts&lt;/code&gt;?  You can't programmatically add aliases for localhost or new hostname-to-ip mappings.  In short, Docker treats &lt;code&gt;/etc/hosts&lt;/code&gt; like a static resource.&lt;/p&gt;&lt;p&gt;No problem.  This will just take a quick Unix script to solve.&lt;/p&gt;&lt;h2&gt;Attempt 1, the slate is wiped clean&lt;/h2&gt;&lt;p&gt;No big deal, right?  We simply write ourselves a little &lt;code&gt;sed&lt;/code&gt; script to alias localhost and add a couple additional hostname mappings.  We can run the &lt;code&gt;sed&lt;/code&gt; script from our Dockerfile.&lt;/p&gt;&lt;p&gt;Well if you tried this at home, you'd quickly find out that it doesn't work. Each &lt;code&gt;RUN&lt;/code&gt; command in a Dockerfile does another commit to the image.  Ordinarily, that's just a space problem but Docker treats &lt;code&gt;/etc/hosts&lt;/code&gt; special.  It will overwrite it whenever it wants without any regard for your modifications.  In a nutshell I wasn't able to persist any changes made during the Dockerfile.&lt;/p&gt;&lt;h2&gt;Attempt 2, mount up&lt;/h2&gt;&lt;p&gt;Okay, so we simply run our &lt;code&gt;sed&lt;/code&gt; script when we run our container.  Docker run will execute our startup script, running our &lt;code&gt;sed&lt;/code&gt; script, updating &lt;code&gt;/etc/hosts&lt;/code&gt; and finally running our server.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;sed: cannot rename /etc/sedl8ySxL: Device or resource busy 

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Unfortunately, that doesn't work either.  The way &lt;code&gt;sed -i&lt;/code&gt; works is to read from the original file, write to a temp file and then move the temp file over the original file.  This doesn't work in this case because &lt;code&gt;/etc/hosts&lt;/code&gt; is a mount point.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;root@07734c969aa6:/usr/local/src# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs           19G  3.9G   14G  23% /
none             19G  3.9G   14G  23% /
tmpfs          1005M     0 1005M   0% /dev
shm              64M     0   64M   0% /dev/shm
/dev/sda1        19G  3.9G   14G  23% /etc/hosts      &amp;lt;----
none            1.1T  159G  881G  16% /code
tmpfs          1005M     0 1005M   0% /proc/kcore

&lt;/code&gt;&lt;/pre&gt;&lt;h2&gt;Alternatives&lt;/h2&gt;&lt;p&gt;How are other people solving this problem today?  Some people seem to be using &lt;code&gt;dnsmasq&lt;/code&gt; as a way of bypassing the problem of &lt;code&gt;/etc/hosts&lt;/code&gt;.  Running another dns server process as a workaround seems excessive, but I'm not sure I blame them.  Doing a search of issues in the Docker Github repo found 125 issues which mentioned &lt;code&gt;/etc/hosts&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;On Stackoverflow there is the realization that &lt;code&gt;/etc/hosts&lt;/code&gt; is now writable, but &lt;a href='http://stackoverflow.com/a/25613983/217481'&gt;doesn't persist changes in running container&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Even so, I hadn't seen anyone provide a programmatic way to address the issue.&lt;/p&gt;&lt;h2&gt;Attempt 3, &lt;a href='https://github.com/hiteshjasani/nim-mungehosts'&gt;Mungehosts&lt;/a&gt; is born&lt;/h2&gt;&lt;p&gt;I took a step back and decided to write my own utility, &lt;a href='https://github.com/hiteshjasani/nim-mungehosts'&gt;Mungehosts&lt;/a&gt;.  It solves my major pain points:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Programmatic interface&lt;/li&gt;&lt;li&gt;Can add aliases for localhost (ipv4 and ipv6)&lt;/li&gt;&lt;li&gt;Can add hostname-to-ip mappings&lt;/li&gt;&lt;li&gt;Works with Docker&lt;/li&gt;&lt;li&gt;Compiled executable (Linux binary in releases)&lt;/li&gt;&lt;li&gt;No dependencies except C runtime&lt;/li&gt;&lt;li&gt;Small size (167 KB)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Check it out and provide feedback.  I know that the smart Docker folks will eventually get all of the features into the main application.  When that happens Mungehosts will retire to pasture, but it will be a good workaround until then.&lt;/p&gt;</content><author><name>hitesh</name></author></entry><entry><title>Unable to remove docker image</title><link href="/2014/10/18/unable-to-remove-docker-image/"></link><id>url:/2014/10/18/unable-to-remove-docker-image/</id><updated></updated><summary></summary><content type="xhtml">&lt;p&gt;I've been playing around with building Docker images and noticed I had a few that had &lt;code&gt;&amp;lt;none&amp;gt;&lt;/code&gt; as both the repository and tag info.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;% docker images

REPOSITORY                 TAG                 IMAGE ID	...

&amp;lt;none&amp;gt;                     &amp;lt;none&amp;gt;              c1e0e48a03bb  
&amp;lt;none&amp;gt;                     &amp;lt;none&amp;gt;              c8bf15029bc0 

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I tried to delete these untagged images, but couldn't.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;% docker rmi c1e0e48a03bb
Error response from daemon: Conflict, cannot delete c1e0e48a03bb because the container 5f266c452a8b is using it, use -f to force

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Ok, so we'll try to force deletion.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;% docker rmi -f c1e0e48a03bb
Error response from daemon: No such id: b5dc67806c5f1e4abfa079a1c99f6d782e5696a25a3c9beb16043fe2e7164d19
2014/10/18 10:04:27 Error: failed to remove one or more images

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Mmm ... the original message said the image couldn't be deleted because it was in use by a container.  I didn't have any running containers as I verified by doing &lt;code&gt;docker ps&lt;/code&gt;.  But the issue is that docker holds on to images even from exited containers.  Once you realize that, then this becomes much easier to resolve.&lt;/p&gt;&lt;p&gt;To delete all your exited containers.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;% docker ps -a -q --filter &amp;quot;status=exited&amp;quot; | xargs docker rm

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And to then delete all your untagged images.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;% docker rmi `docker images -q --filter &amp;quot;dangling=true&amp;quot;`

&lt;/code&gt;&lt;/pre&gt;</content><author><name>hitesh</name></author></entry><entry><title>Apple touch inconsistency</title><link href="/2009/12/30/apple-touch-inconsistency/"></link><id>url:/2009/12/30/apple-touch-inconsistency/</id><updated></updated><summary></summary><content type="xhtml">&lt;p&gt;Apple is really known for their user interface design.  I'd say they generally have a lot more hits than misses, but one miss recently came as a surprise for me.&lt;/p&gt;&lt;p&gt;Take an iPhone, go to the Settings screen.  Scroll the screen with your finger.  Notice that the text moves in the direction of your fingers and the scrollbar moves in the opposite direction.  The paradigm is that your finger is controlling the text, directly moving it.  The scrollbar is just illustrative to let you know how far you are in the document.&lt;/p&gt;&lt;p&gt;Now take a Macbook or Macbook Pro with a multitouch trackpad.  Use two fingers to scroll a webpage or other window that has a scrollbar. Notice that this time the text moves in the opposite direction of your stroke, while the scrollbar moves in the same direction as your fingers.  The paradigm here is that your fingers control the scrollbar, which then inversely moves the text.  One might say this method is indirect control.&lt;/p&gt;&lt;p&gt;So that's kind of strange.  Two Apple devices using touch in entirely different and opposite ways.  One going for direct control and the other indirect.  This inconsistency could be Apple experimenting with touch user interface concepts or just be a result of legacy user interface design.  But whatever the reason, they will someday have to make a choice.&lt;/p&gt;&lt;p&gt;As we head towards a future in which iPhone apps and OSX apps merge and play together on a singular device - possibly the fabled touch tablet - Apple will have to decide which of the touch paradigms will live on.  Which one will it be?&lt;/p&gt;</content><author><name>hitesh</name></author></entry><entry><title>Error installing Haskell X11 libs</title><link href="/2008/11/05/error-installing-haskell-x11-libs/"></link><id>url:/2008/11/05/error-installing-haskell-x11-libs/</id><updated></updated><summary></summary><content type="xhtml">&lt;p&gt;I recently bought a new Macbook Pro and with the recent &lt;a href="http://www.reddit.com/r/programming/comments/7bav8/ghc&lt;i&gt;610&lt;/i&gt;released&lt;i&gt;type&lt;/i&gt;families&lt;i&gt;data&lt;/i&gt;parallelism/"&gt;announcment of GHC 6.10.1&lt;/a&gt;, I thought it was time to install the latest GHC and libs. &lt;a href="/2008/09/25/error-installing-haskell-x11-package/"&gt;Previously&lt;/a&gt;  I had some trouble installing the Haskell X11 libs on Leopard, but I  thought something might have been borked on my old laptop.  With this  new one and starting from scratch, I hoped things would go smoothly.  Twas not to be.&lt;/p&gt;&lt;p&gt;The X11 libraries are installed under &lt;code&gt;/usr/X11/lib&lt;/code&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;bash-3.2$ locate libX11
/Applications/CrossOver Games.app/Contents/SharedSupport/X11/lib/libX11.6.2.dylib
/Applications/CrossOver Games.app/Contents/SharedSupport/X11/lib/libX11.6.dylib
/Applications/CrossOver Games.app/Contents/SharedSupport/X11/lib/libX11.dylib
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.6.2.dylib
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.6.dylib
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.a
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libX11.6.2.0.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libX11.6.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libX11.dylib
/opt/local/var/macports/sources/rsync.macports.org/release/ports/x11/xorg-libX11
/opt/local/var/macports/sources/rsync.macports.org/release/ports/x11/xorg-libX11/Portfile
/usr/X11/lib/libX11.6.2.0.dylib
/usr/X11/lib/libX11.6.dylib
/usr/X11/lib/libX11.dylib
/usr/X11/lib/libX11.la

&lt;/code&gt;&lt;/pre&gt;&lt;h2&gt;I've fallen down and I can't get up&lt;/h2&gt;&lt;p&gt;Here are some things I tried that didn't work.&lt;/p&gt;&lt;p&gt;&lt;ul&gt;&lt;/p&gt;&lt;p&gt;&lt;li&gt;Try adding an entry for &lt;code&gt;extra-lib-dirs&lt;/code&gt; to &lt;code&gt;X11.cabal&lt;/code&gt;&lt;/li&gt;&lt;/p&gt;&lt;p&gt;&lt;p&gt; A &lt;a href="http://haskell.org/haskellwiki/Xmonad/Frequently&lt;i&gt;asked&lt;/i&gt;questions#X11&lt;i&gt;fails&lt;/i&gt;to&lt;i&gt;find&lt;/i&gt;libX11&lt;i&gt;or&lt;/i&gt;libXinerama"&gt;FAQ&lt;/a&gt; entry for XMonad offers up some helpful tips to try. &lt;/p&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class="config"&gt;extra-lib-dirs:     /usr/X11/lib

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;p&gt; and try to configure ... &lt;/p&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;bash-3.2$ runhaskell Setup.hs configure

checking for X... no
configure: error: X11 libraries not found, so X11 package cannot be built
See `config.log' for more details.

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;li&gt;Try passing option to configure&lt;/li&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;bash-3.2$ runhaskell Setup.hs configure --extra-lib-dirs=/usr/X11/lib

checking for X... no
configure: error: X11 libraries not found, so X11 package cannot be built
See `config.log' for more details.

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;li&gt;Try setting &lt;code&gt;LD&amp;#95;LIBRARY&amp;#95;PATH&lt;/code&gt;&lt;/li&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;bash-3.2$ export LD_LIBRARY_PATH=/usr/X11/lib; runhaskell Setup.hs configure

checking for X... no
configure: error: X11 libraries not found, so X11 package cannot be built
See `config.log' for more details.

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;li&gt;Try setting &lt;code&gt;DYLD&amp;#95;LIBRARY&amp;#95;PATH&lt;/code&gt;&lt;/li&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;bash-3.2$ export DYLD_LIBRARY_PATH=/usr/X11/lib; runhaskell Setup.hs configure

checking for X... no
configure: error: X11 libraries not found, so X11 package cannot be built
See `config.log' for more details.

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;li&gt;Try setting &lt;code&gt;DYLD&amp;#95;FALLBACK&amp;#95;LIBRARY&amp;#95;PATH&lt;/code&gt;&lt;/li&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;bash-3.2$ export DYLD_LIBRARY_PATH=/usr/X11/lib
bash-3.2$ runhaskell Setup.hs configure

Setup.hs:3:0:
    Warning: In the use of `defaultUserHooks'
             (imported from Distribution.Simple):
             Deprecated: &amp;quot;Use simpleUserHooks or autoconfUserHooks, unless you need Cabal-1.2
             compatibility in which case you must stick with defaultUserHooks&amp;quot;
Setup.hs: &amp;amp;lt;command line&amp;amp;gt;: can't load .so/.DLL for: dl (dlopen(libdl.dylib, 9): image not found)

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/ul&gt;&lt;/p&gt;&lt;p&gt;It's a bit disappointing how different OSX is from the Linux distros. Yeah it doesn't suck like Windows, but even so I wish it weren't so different from Linux.&lt;/p&gt;&lt;h2&gt;So what did work?&lt;/h2&gt;&lt;p&gt;Just like in  my &lt;a href="/2008/09/25/error-installing-haskell-x11-package/"&gt;previous  article&lt;/a&gt;, using the &lt;tt&gt;LDFLAGS&lt;/tt&gt; variable solves the problem.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;bash-3.2$ export LDFLAGS=-L/usr/X11/lib; runhaskell Setup.hs configure

Setup.hs:3:0:
    Warning: In the use of `defaultUserHooks'
             (imported from Distribution.Simple):
             Deprecated: &amp;quot;Use simpleUserHooks or autoconfUserHooks, unless you need Cabal-1.2
             compatibility in which case you must stick with defaultUserHooks&amp;quot;
Warning: defaultUserHooks in Setup script is deprecated.
Configuring X11-1.4.4...
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
checking for X... libraries , headers 
checking for gethostbyname... yes
checking for connect... yes
checking for remove... yes
checking for shmat... yes
checking for IceConnectionNumber in -lICE... yes
checking whether to build Xinerama... yes
checking for egrep... grep -E
checking for ANSI C header files... rm: conftest.dSYM: is a directory
rm: conftest.dSYM: is a directory
yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking X11/extensions/Xinerama.h usability... yes
checking X11/extensions/Xinerama.h presence... yes
checking for X11/extensions/Xinerama.h... yes
configure: creating ./config.status
config.status: creating config.mk
config.status: creating X11.buildinfo
config.status: creating include/HsX11Config.h
config.status: creating include/X11_extras_config.h

&lt;/code&gt;&lt;/pre&gt;</content><author><name>hitesh</name></author></entry><entry><title>Error installing Haskell SDL-image</title><link href="/2008/10/10/error-installing-haskell-sdl-image/"></link><id>url:/2008/10/10/error-installing-haskell-sdl-image/</id><updated></updated><summary></summary><content type="xhtml">&lt;p&gt;I really like OSX, except when I have to jump through extra hoops to install things on it versus Linux.  The latest challenge was installing the Haskell SDL-image bindings on Leopard.&lt;/p&gt;&lt;p&gt;Configure would bomb right away, saying it couldn't find the libs even though I had them installed via MacPorts.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;bash-3.2$ runhaskell Setup.lhs configure
Configuring SDL-image-0.5.2...
checking for sdl-config... /opt/local/bin/sdl-config
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for IMG_Load in -lSDL_image... no
configure: error: *** SDL_image lib not found! Get SDL_image from
http://www.libsdl.org/projects/SDL_image/index.html

bash-3.2$ locate SDL_image
/opt/local/include/SDL/SDL_image.h
/opt/local/lib/libSDL_image-1.2.0.1.5.dylib
/opt/local/lib/libSDL_image-1.2.0.dylib
/opt/local/lib/libSDL_image.a
/opt/local/lib/libSDL_image.dylib
/opt/local/lib/libSDL_image.la

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So if you try using the same trick I did with installing Haskell X11 libs ...&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;bash-3.2$ export LDFLAGS=-L/opt/local/lib; runhaskell Setup.lhs configure
Configuring SDL-image-0.5.2...
checking for sdl-config... /opt/local/bin/sdl-config
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for IMG_Load in -lSDL_image... yes
configure: creating ./config.status
config.status: creating config.mk
config.status: creating SDL-image.buildinfo
config.status: creating includes/HsSDLConfig.h
config.status: includes/HsSDLConfig.h is unchanged
bash-3.2$ runhaskell Setup.lhs build
Preprocessing library SDL-image-0.5.2...
Undefined symbols:
&amp;quot;_ZCMain_main_closure&amp;quot;, referenced from:
	_ZCMain_main_closure$non_lazy_ptr in libHSrts.a(Main.o)
&amp;quot;___stginit_ZCMain&amp;quot;, referenced from:
	___stginit_ZCMain$non_lazy_ptr in libHSrts.a(Main.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
linking dist/build/Graphics/UI/SDL/Image/Version_hsc_make.o failed
command was: /opt/local/bin/ghc -optl-L/opt/local/lib -optl-lSDL_image dist/build/Graphics/UI/SDL/Image/Version_hsc_make.o -o dist/build/Graphics/UI/SDL/Image/Version_hsc_make

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It gets further, but still fails.  Now's the time to read the nice MACOSX file included with the distro.  It tells you to write your own hsc2hs script to help it find certain dependencies on your system. For the most part the instructions are good, but for me it was still having trouble finding &lt;tt&gt;HsFFI.h&lt;/tt&gt;.  I had to add a &lt;code&gt;cflag&lt;/code&gt; directive to make it work.  So here is my &lt;code&gt;myhsc2hs&lt;/code&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;#!/bin/sh
# added include dir of /opt/local/lib/ghc-6.8.2/include
echo &amp;quot;/opt/local/bin/hsc2hs -v --cc=gcc --ld=gcc --cflag=&amp;quot;-I/opt/local/lib/ghc-6.8.2/include&amp;quot; --lflag=&amp;quot;-L/opt/local/lib -lSDLmain -framework AppKit -framework SDL&amp;quot; $@&amp;quot;
/opt/local/bin/hsc2hs -v --cc=gcc --ld=gcc --cflag=&amp;quot;-I/opt/local/lib/ghc-6.8.2/include&amp;quot; --lflag=&amp;quot;-L/opt/local/lib&amp;quot; --lflag=&amp;quot;-lSDLmain&amp;quot; --lflag=&amp;quot;-framework&amp;quot; --lflag=&amp;quot;AppKit&amp;quot; --lflag=&amp;quot;-framework&amp;quot; --lflag=&amp;quot;SDL&amp;quot; &amp;quot;$@&amp;quot;

&lt;/code&gt;&lt;/pre&gt;</content><author><name>hitesh</name></author></entry><entry><title>Error installing Haskell X11 package</title><link href="/2008/09/25/error-installing-haskell-x11-package/"></link><id>url:/2008/09/25/error-installing-haskell-x11-package/</id><updated></updated><summary></summary><content type="xhtml">&lt;p&gt;Recently I was having trouble installing the Haskell X11 package on OSX Leopard.  Running configure generated an error.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;bash-3.2$ runhaskell Setup.hs configure
Warning: defaultUserHooks in Setup script is deprecated.
Configuring X11-1.4.3...
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for X... no
configure: error: X11 libraries not found, so X11 package cannot be built
See `config.log' for more details.

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Of course I had X11 libraries.  In fact, I had them from both Leopard and MacPorts.  I had them all over the place, but cabal wasn't finding them.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;bash-3.2$ locate libX11.dylib
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libX11.dylib
/Previous Systems.localized/2008-07-15_1549/Developer/SDKs/MacOSX10.3.9.sdk/usr/X11R6/lib/libX11.dylib
/Previous Systems.localized/2008-07-15_1549/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.dylib
/Previous Systems.localized/2008-07-15_1549/usr/X11R6/lib/libX11.dylib
/opt/local/lib/libX11.dylib
/opt/local/var/macports/software/xorg-libX11/1.1.3_0/opt/local/lib/libX11.dylib
/usr/X11/lib/libX11.dylib

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I tried adding &lt;code&gt;extra-lib-dirs: /usr/X11/lib&lt;/code&gt; to &lt;code&gt;X11.cabal&lt;/code&gt;, but it didn't fix the error.  I upgraded Cabal to version 1.4.0.2, but that didn't work either.  What did finally work was setting &lt;code&gt;LDFLAGS&lt;/code&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code class="bash"&gt;bash-3.2$ export LDFLAGS=-L/usr/X11/lib
bash-3.2$ runhaskell Setup.hs configure
Warning: defaultUserHooks in Setup script is deprecated.
Configuring X11-1.4.3...
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for X... libraries , headers
checking for gethostbyname... yes
...

&lt;/code&gt;&lt;/pre&gt;</content><author><name>hitesh</name></author></entry><entry><title>Emacs Erlang snippets</title><link href="/2008/08/19/emacs-erlang-snippets/"></link><id>url:/2008/08/19/emacs-erlang-snippets/</id><updated></updated><summary></summary><content type="xhtml">&lt;p&gt;Continuing with my previous &lt;a href="http://code.google.com/p/yasnippet/"&gt;yasnippet&lt;/a&gt; &lt;a href="/2008/08/11/textmate-ruby-snippet-to-yasnippet"&gt;for Ruby&lt;/a&gt;, here are some snippets for Erlang mode.&lt;/p&gt;&lt;h2&gt;Installation&lt;/h2&gt;&lt;p&gt;&lt;ul&gt;   &lt;li&gt;Create an &lt;code&gt;erlang-mode&lt;/code&gt; directory under &lt;code&gt;text-mode&lt;/code&gt;&lt;/li&gt;   &lt;li&gt;&lt;p&gt;Save the following code in a file named &lt;code&gt;mod&lt;/code&gt;.&lt;/p&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class="elisp"&gt;#name : -module().
#contributor : hitesh &amp;amp;lt;hitesh.jasani gmail.com&amp;amp;gt;
# --
-module(${1:$(file-name-nondirectory 
               (file-name-sans-extension (buffer-file-name)))}).
$0

&lt;/code&gt;&lt;/pre&gt;  &lt;/li&gt;&lt;p&gt;  &lt;li&gt;&lt;p&gt;Save the following code in a file named &lt;code&gt;exp&lt;/code&gt;.&lt;/p&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class="elisp"&gt;#name : -export([]).
#contributor : hitesh &amp;amp;lt;hitesh.jasani gmail.com&amp;amp;gt;
# --
-export([${1:start/0}]).
$0

&lt;/code&gt;&lt;/pre&gt;  &lt;/li&gt;&lt;p&gt;  &lt;li&gt;&lt;p&gt;Save the following code in a file named &lt;code&gt;imp&lt;/code&gt;.&lt;/p&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class="elisp"&gt;#name : -import([]).
#contributor : hitesh &amp;amp;lt;hitesh.jasani gmail.com&amp;amp;gt;
# --
-import(${1:lists}, [${2:map/2, sum/1}]).
$0

&lt;/code&gt;&lt;/pre&gt;  &lt;/li&gt;&lt;p&gt;  &lt;li&gt;&lt;p&gt;Add a hook in your &lt;code&gt;.emacs&lt;/code&gt; to enable yas mode with   erlang.&lt;/p&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class="elisp"&gt;(add-hook 'erlang-mode-hook 'yas/minor-mode-on)

&lt;/code&gt;&lt;/pre&gt;  &lt;/li&gt;&lt;/ul&gt;</content><author><name>hitesh</name></author></entry><entry><title>textmate ruby snippet to yasnippet</title><link href="/2008/08/11/textmate-ruby-snippet-to-yasnippet/"></link><id>url:/2008/08/11/textmate-ruby-snippet-to-yasnippet/</id><updated></updated><summary></summary><content type="xhtml">&lt;p&gt;&lt;a href="http://drnicwilliams.com/"&gt;Dr. Nic&lt;/a&gt; recently put together a &lt;a href="http://drnicwilliams.com/wp-content/uploads/2008/06/textmate-snippets-running-ruby.mov"&gt;screencast of adding a Ruby snippet to TextMate&lt;/a&gt;.  This particular snippet makes a class definition using the filename as the default classname. I always enjoy listening to Dr. Nic, so definitely check out the 'cast.&lt;/p&gt;&lt;p&gt;I used to love TextMate, but I can't use it anymore since I'm working on multiple platforms.  Emacs is my editor of choice now and I can't say that I'm missing anything.&lt;/p&gt;&lt;p&gt;Dr. Nic's example was interesting enough that I decided to replicate it using &lt;a href="http://code.google.com/p/yasnippet/"&gt;yasnippet&lt;/a&gt; and elisp. As you'll see in the video, TextMate supports shelling out to bash or Ruby to do complex processing of snippets.  Yasnippet supports inline elisp to handle complex snippets and allows shelling out to other processes when necessary.&lt;/p&gt;&lt;h2&gt;Usage&lt;/h2&gt;&lt;p&gt;If you're editing a file named &lt;code&gt;foo.rb&lt;/code&gt; and use the snippet, it will create a class definition for &lt;code&gt;Foo&lt;/code&gt;.  If you're editing a file named &lt;code&gt;currency&amp;#95;converter.rb&lt;/code&gt;, it will create a class named &lt;code&gt;CurrencyConverter&lt;/code&gt;.&lt;/p&gt;&lt;h2&gt;Installation&lt;/h2&gt;&lt;p&gt;Put the following code into a file named &lt;code&gt;kls&lt;/code&gt; in the &lt;code&gt;ruby-mode&lt;/code&gt; directory.  Then use it like you would any other yasnippet.&lt;/p&gt;&lt;pre&gt;&lt;code class="elisp"&gt;#name : class ... end
#contributor : hitesh &amp;lt;hitesh.jasani gmail.com&amp;gt;
#contributor : Roberto H.
# --
class ${1:`(let ((fn (capitalize (file-name-nondirectory
				(file-name-sans-extension
		(or (buffer-file-name)
			(buffer-name (current-buffer))))))))
	(replace-regexp-in-string &amp;quot;_&amp;quot; &amp;quot;&amp;quot; fn))`}
$0
end

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Update (2010-01-31):&lt;/strong&gt; Thanks to some good input this routine has been improved to handle multiple underscores in the filename.&lt;/p&gt;</content><author><name>hitesh</name></author></entry><entry><title>ELisp doesn't support closures</title><link href="/2008/07/19/elisp-doesnt-support-closures/"></link><id>url:/2008/07/19/elisp-doesnt-support-closures/</id><updated></updated><summary></summary><content type="xhtml">&lt;p&gt;I'm hacking some ELisp functions recently and I realize that ELisp doesn't have a filter function or support closures.  That's disappointing.  One sort of takes it for granted nowadays that a decent language will have both.  AFAIK ELisp was written before there was a Common Lisp standard.  But even then, I'm surprised it didn't evolve with the times.&lt;/p&gt;&lt;p&gt;I don't mind writing my own filter function since I'm only going to have to do it once.  But not having closures is a little bigger impact.&lt;/p&gt;&lt;p&gt;Instead of being able to write something like this ...&lt;/p&gt;&lt;pre&gt;&lt;code class="elisp"&gt;(defun string-match-c (s)
  (lambda (x) (string-match s x)))

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I'll have to write this instead.&lt;/p&gt;&lt;pre&gt;&lt;code class="elisp"&gt;(defun string-match-c (str)
  (lexical-let ((s str))
    (lambda (x) (string-match s x))))

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Usage is the same for both.&lt;/p&gt;&lt;pre&gt;&lt;code class="elisp"&gt;(filter (string-match-c &amp;quot;ba&amp;quot;) '(&amp;quot;foo&amp;quot; &amp;quot;bar&amp;quot; &amp;quot;baz&amp;quot;))
;; =&amp;gt; (&amp;quot;bar&amp;quot; &amp;quot;baz&amp;quot;)

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But they really can't compare to Haskell, which doesn't need a string-match-c function defined since it supports partial application.&lt;/p&gt;&lt;pre&gt;&lt;code class="elisp"&gt;filter (isPrefixOf &amp;quot;ba&amp;quot;) [&amp;quot;foo&amp;quot;, &amp;quot;bar&amp;quot;, &amp;quot;baz&amp;quot;]

&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Emacs is still my favorite editor, but I sure wish it was using Common Lisp, Scheme or Haskell.&lt;/p&gt;&lt;h2&gt;Resources&lt;/h2&gt;&lt;p&gt;&lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.emacswiki.org/cgi-bin/wiki/FakeClosures"&gt;Faking a closure&lt;/a&gt;&lt;/li&gt;   &lt;li&gt;&lt;a href="http://www.emacswiki.org/cgi-bin/wiki/ElispCookbook#toc22"&gt;Write your own filter function&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;&lt;/p&gt;&lt;h4&gt;Previous Comments&lt;/h4&gt;			 &lt;blockquote&gt;&lt;p&gt; maybe wlcompose.el help to solve this problem. I think Elisp support closure indirectly. In Elisp, some functions are nothing more than a list whose car is &amp;quot;lambda&amp;quot;, we can construct such list(or function) as we want. &lt;/p&gt;&lt;footer&gt; &lt;a href='http://www.emacswiki.org/emacs/Wang&amp;#95;ChunYe'&gt;Wang Chunye&lt;/a&gt; http://www.emacswiki.org/emacs/wcy-compose.el&lt;/footer&gt;&lt;p&gt;&lt;/p&gt;&lt;/blockquote&gt;</content><author><name>hitesh</name></author></entry></feed>