Binary Search
Mike Taylor noted in a blog post that in the book Programming Pearls it is mentioned that no more than 10% of developers can correctly implement a binary search. Appalling!
Let’s see if I am in that 10% or not…
As I’ve found myself using Ruby more and more lately, I thought I’d try to implement the binary search using that language.
Here’s my stab:
The script includes code to run the binary search through the test cases for the exercise created by Steve Witham. And once the file reading worked - all tests actually passed (or the code incorrectly shows them as passed… ;).
Good training this!
/M
CommentsMigrated To Octopress
Like all cool kids blogging nowadays, as part of the attempt to rejuvinate the blog, I’ve switched to Jekyll. Or, rather, the extended fork Octopress.
As part of the migration I wanted to extract all the old posts from Wordpress into the proper markdown format used by Jekyll.
Jekyll includes a migration script for Wordpress, but this used a direct database connection to the Wordpress MySQL server to extract a minimum amount of information for each blog post. To avoid missing information that I later might want after having shut down the Wordpress server, I wanted to base the migration on a full XML export from Wordpress. This way I could go back and extract more information from the old posts, if, and when, needed.
Seeing this as a chance to play with Ruby - a language I’ve only dabbled in previously - I set out to build a simple Wordpress XML->Jekyll converter. The converter reads the Wordpress export and converts all blog posts into separate files with a proper Yaml frontmatter. It also converts the syntax highlighting markup, code markup and headings into the corresponding markdown conventions. The rest of the HTML is left alone.
For the images I just copied the files in the old Wordpress structure into the new blog directory layout so that the URLs still match. Not the nicest way, but I was too lazy to do anything about it just yet.
Anywho - the source for the Wordpress XML converter is available in the blog branch of my fork of Octopress. The source is also given below. To use, just run with the filename of the Wordpress XML export as the first argument.
It’s my first publicly available Ruby program - so be careful. Improvements welcome!
/M
CommentsNginx
For that fresh new feeling I switched this site from Apache2 to Nginx. A quick compile of the source package and following the instructions on hooking it up with Wordpress over fastcgi using php-cgi and we’re done!
Feels good with a server handling the C10K problem - and it has a fairly decent configuration language IMHO.
Also looking forward to use Nginx more in the days to come as a the web frontend for development tools server at work hosting, among some things:
- Gitorious
- Redmine
- Hudson
- Nexus
Will post more about this later!
/M
CommentsNew Direction?
More than a full year since last post - this might not be working as well as I had hoped…!
Finding the time and inspiration to write between the day job and private commitments turns out to be a challenge. Instead of seeing this as a failure, however, I will try to learn from the experience and attempt to find a new way of relating to the blog. Perhaps by being less long winded (!) in each post I could get a few more out there. There are still a lot of things going on I would like to capture, but the previous form is clearly not working.
So - let’s try to shake things up and see how that works!
/M
CommentsThe Hitchhiker’s Guide to an Ioke Dev Env From Source (part 5: Ioke and the REPL)
This is the fifth part in a series of posts for non-experts about setting up an Ioke development environment on Linux. Please see the previous posts to start at the beginning:
This time we will finally get the Ioke source code, build it, and test the Ioke REPL!
Ioke
Ioke uses Git as the source code versioning tool, with a public repository set up on GitHub (soon I’ll be linking like Jeff Atwood).
So - let’s get Ioke using Git by cloning Ola’s repository:
~/bin$ cd ~/work
~/work$ git clone git://github.com/olabini/ioke
Initialized empty Git repository in /home/melwin/work/ioke/.git/
remote: Counting objects: 9221, done.
remote: Compressing objects: 100% (2941/2941), done.
remote: Total 9221 (delta 5782), reused 8656 (delta 5351)
Receiving objects: 100% (9221/9221), 45.95 MiB | 399 KiB/s, done.
Resolving deltas: 100% (5782/5782), done.
Great - let’s quickly move on to the build step:
~/work$ cd ioke
~/work/ioke$ ant
...
[java] 2606 examples, 0 failures
jar:
[jar] Building jar: /home/melwin/work/ioke/lib/ioke.jar
BUILD SUCCESSFUL
Total time: 22 seconds
Running just ant will execute the default target in the build.xml file. This target will make sure Ioke is compiled and the test suite is run.
At the end is a summary of the test results - if these are not all successful you might have a problem with the environment or you might have checked out a broken build from the repository.
The Ioke REPL
Now all is installed and Ioke is compiled, so let’s fire up the REPL. This is done by just running the main Ioke binary:
~/work/ioke/$ bin/ioke
iik>
When doing this we get the iik> REPL prompt. From here we can execute most Ioke code. Let’s try to print a string:
Here we create a Text (Ioke’s string type) literal and send it the message println, which will cause the text to be printed to the console. The return type of println is nil (similar to null), which is printed by the REPL itself. After that we get the prompt back and can execute another line.
Let’s try a little more complex example - the factorial:
Note how the REPL prints the method definition in a canonical form - it makes it obvious how Ioke parses the code, what are messages and what are arguments.
Let’s run our new factorial function:
Ioke handles arbitrarily big numbers, so we don’t need to think about what fits in a certain number of bits.
The Iik REPL also comes with a simple debugger, which helps with handling conditions. For instance, let’s try to run the fact method, passing a message which doesn’t mean anything (yet):
The above output shows that when we try to reference something that doesn’t exist we get a chance to provide that value. Here I decided to provide a value using the useValue restart and entered the value 5. This let the method continue executing and the result was printed.
To exit the REPL, just type: exit
Next up are the Emacs modes for Ioke - stay tuned!
/M
Comments