September 18th, 2009 · general
A friend sent me a small programming challenge.
Problem: Given a list of numbers, get the sum of the overlapping pairs.
Thus: [1, 2, 3, 4, 5] reduces to [3, 5, 7, 9].
My Haskell solution:
zipWith (+) x (tail x)
I was going to use the same trick with Erlang and was surprised to find that Erlang expects the two lists to be the same length. This is my Erlang solution:
sumpairs([X,Y|T]) -> [X+Y | sumpairs([Y|T])];
sumpairs([_]) -> [].
See more solutions here: http://github.com/apauley/RandomHacks/tree/master/CodeSnippets/SumPairs/
Tags:erlang·fun·haskell
December 29th, 2008 · general
What we are trying to accomplish
We are using Rake to manage our database instances.
If a database is stopped, we want the task “database:start” to be available, but not “database:stop”. We have multiple databases running on the same server, the instance names should not be hard coded into the Rakefile.
These are the type of tasks we want to invoke:
rake development:stop
rake test:start
rake ci:status
Obviously we don’t want to define three, hard-coded namespaces (development, test, ci) and within each of those namespaces, three tasks (stop, start, status).
That would be tedious.
Simplest example
Luckily for us, Rake is still full-blown Ruby. This then is our first stab:
- Iterate over a list of database names and define a namespace for each.
- Within the defined namespace, define a task called “stop”, using the current scope (namespace) to get the database name.
["development", "test", "ci"].each do |databaseName|
namespace databaseName do
desc "stop"
task "stop" do |t|
puts "Action stop would now be performed on database #{t.scope}"
end
end
end
The task list of that file looks like this:
rake ci:stop # stop
rake development:stop # stop
rake test:stop # stop
Our own task type
We now want to define more tasks. Duplicating the task definition if only the action (stop, start, status, restart) change, seems like more tedious work. All we need to do is to define our own “task_database” that takes a database instance and an action to be performed on it:
The task list for this file looks like this:
rake ci:restart # restart - ci
rake ci:start # start - ci
rake ci:status # status - ci
rake development:restart # restart - development
rake development:status # status - development
rake development:stop # stop - development
rake test:restart # restart - test
rake test:start # start - test
rake test:status # status - test
I hope you find this useful. Similar code to this is now managing my GemStone instances
Tags:namespace·rails·rake·ruby
September 9th, 2008 · general
If you are a geek and you are in Johannesburg the weekend of 11 October, signup for BarCampJozi 2008!
Just head over to the wiki and put your name on the list. Tell your friends.
What you will get out of attending BarCamp:
- Chance to meet other like minded individuals. I made good friends back in 2006 at the last BarCampJozi.
- A feast of information. I guarantee you will learn about topics you never thought to explore yourself.
- A social engagement on that empty calendar. In my case, anyway.
What the other campers will get out of your attendance:
- Everyone has something to share, consider giving 10 minutes of your wisdom to the crowd by doing a short presentation. Just sign up on the wiki!
- A chance to meet you.
Tags:barcamp·barcampjozi·johannesburg
April 3rd, 2008 · personal
My email signature is the following:
Danie Roux *shuffle* Adore Unix
Every now and again someone figures out what I am trying to depict and they shake their heads in complete disbelieve:
- People who know me, know I am a Linux fan. In general, a Unix fan.
- Some would in fact say, I rather adore unix.
- Turns out, danie roux is an anagram for adore unix!
Here is how you too, can waste a lot of time:
On Ubuntu/Debian, install the application with:
aptitude install an
Execute it with:
an -m 5 yournamewithoutspaces
Decrease the 5 if you don’t get good results
Find more word lists here to play with.
Tags:adore·anagram·unix
July 11th, 2007 · general
Coding Horror saying what I’ve wanted to say for a while now.
To add to that:
Facebook allowed me to reconnect with some long lost friends. I’ve had some valuable conversations with these friends – on Facebook.
Those conversations are not a part of my normal email archive or flow.
I need my data to be my data.
Tags:advocacy·facebook·internet
June 26th, 2007 · general
So Google now allows us that make use of “Google Apps for your Domain” to use the Talk Gadget. Didn’t make my day, but it at least brighten up the time before coffee.
If you need the URL to get to your talk gadget for your domain, this is it:
http://hostedtalkgadget.google.com/a/yourdomain.com/talkgadget/client
Replace “yourdomain.com” with your domain. If you are one of those who thought that was obvious – yes, I would have thought so too. But trust me, you get some pretty literal people.
Now use this URL, and the trick described here to get Talk in your Firefox sidebar all day.
Big issues with the Talk Gadget:
- It does not connect all my buddies from other Jabber servers. Most notably the twitter IM bot.
- It does not connect my MSN transport. Which means I can not talk to my one MSN buddy. You can get more info about MSN transports at bigblueball.com.
So all in all, its useful in a pinch when nothing else is around. But I’ll stick to gajim and Psi for now
Tags:apps·gadget·google·talk
April 7th, 2007 · general
Missinglink made a video of the talk I did at the 27-3 dinner.
This is the video. You can view the slides I used online.
Big thanks to Dave Duarte for making the show notes I probably should have!
Update: The video should be available again.
Tags:27dinner·presentation·video
March 14th, 2007 · general
Or so I believe, with the introduction of QWAQ forums.
I was going to do a talk about something pompous like “why is collaboration not a pervasive part of computing” at the next Jozi 27 Dinner. This would have let to an introduction to Croquet and why I believe it is the perfect platform to make this happen.
Well, it has happened. A good summary that will (hopefully) make you feel as warm and fuzzy as I feel now can be found on Dr. Bert Freudenberg’s blog.
Go sign up for the Jozi 27 Dinner and come throw stuff at me if you disagree.
On a personal note, I got married this past Saturday. We were on honeymoon, but we are taking a 3 day break to attend full day lectures. We’ll resume the honeymoon this Saturday and I’ll be offline for 10 days.
Tags:27dinner·collaboration·croquet·jozi·qwaq
February 11th, 2007 · general
For the benefit of anyone getting a “java.lang.Exception: Input not an X.509 certificate” when trying to import a signed certificate using keytool:
I was trying to import the certificate that Thawte signed for me into the Java based keystore. Currently my best guess is that keytool was written by an intern with way not enough coffee in his/her body. This is what I did first:
keytool -import -keystore keystore.production -storepass pinky -file thawte.crt
The error returned to me was:
keytool error: java.lang.Exception: Input not an X.509 certificate
Right. I know its not. So what?
This error message wasted a possible precious 20 minutes of my life. To save someone some time, it turns out I forgot to specify the key alias! Very obvious from the exception, I know. This is correct:
keytool -import -keystore keystore.production -storepass pinky -file thawte.crt -alias key-alias-in-store
Tags:certificate·java·keytool·ssl
February 10th, 2007 · general
Quick post:
Use
strace -e trace=network
to quickly figure out where a process is connecting to.
This traps only system calls that the process makes regarding networking. Very useful to make sure that your process believes the same things about servers and ports that you do.
(Turns out the process needed to be told that 443 is not 8443)
Tags:linux·networking·strace