September 5th, 2008
We use a MediaWiki instance at work to manage a tremendous amount of random facts. We have it setup with Sphinx FTI to get good search results and have found the wiki to be a huge help in managing our data. In fact, via a bit of reverse proxy magic, some of the notes fields in our internal billing application are chunks of a wiki page for that client with links to all of that client’s other attached wiki pages

Media Wiki Notes Field Screen Shot
We wanted the ability to interact with the wiki in a more programatic manner (such as making cancelation notes), so I started checking into the media wiki api. It gives you the ability to do almost anything you would want to do with the Media Wiki engine programatically (except I cant figure out how to get it to render wiki markup for me). I wanted a wrapper around this in Common Lisp which could take care of formulating the messages to the wiki engine and determining whether or not we succeeded preferably leaving these as just function calls to the rest of application. Because I could find no mention of a library like this elsewhere, I decided to go ahead and whip one up.
Using :cxml :drakma, & :cl-unification, I have written a very incomplete wrapper around media wiki remote api. The basic call cycle so far is as follows:
- Build a list of parameters / values based on the api documentation
- Feed these into Drakma to make the request of the media wiki api
- Use CXML to parse the returned XML string into an XML-S tree
- Use CL-Unification to match the response XML and extract data for return (when successful) and error conditions which we signal (if it is not).
GIT: http://repo.or.cz/r/cl-mediawiki.git
Trac: http://trac.acceleration.net/cl-mediawiki
CLiki: http://www.cliki.net/cl-mediawiki
Posted in Lisp, Programming, Web Hack, media wiki | No Comments »
August 22nd, 2008
I often want to attach little bits of meta data to certain instances of an object without all the hassle of declaring a million and one types. If I have a set of 5 mixins that I want to add in various combinations to a concrete class there are like 5! new classes I have to create to get them all. What I often want is to just add a mixin to a specific instance of a class and let that instance’s init args/fns handle the rest. I was able to accomplish this (with help from vic on #lisp) with the meta-mixin mixin. Applied to a class, it lets you pass a list of mixins as an initarg and will change the class of your running object to one that contains all the superclasses requested in the correct order (and with the same metaclass) as the original object.
I found this to be a nifty, useful way to interact with my objects. Check out the paste for code and example.
Posted in Lisp, Programming | No Comments »
July 17th, 2008
So traditionally, regular expressions have been… err… regular. While regular expressions are incredibly useful, being regular is a limitation. The canonical example of what a regular language cannot do, is counting parentheses. For example, if I am trying to match an expression with arbitrary nesting, I need a more robust matching solution than a regular language can provide.
I have seen that CommonLisp - Portable Perl-compatible regular expressions (cl-ppcre) supported a parse tree representation of regular expressions. My hope was that this would allow arbitrary embedding of CL code into the matching structure of the regular expressions. It does.
To teach myself how to use this tool, I decided to count parentheses. The basic structure of the parse tree is just a list of symbols that get compiled into specific matching functions.
- ‘.’ -> :EVERYTHING
- ‘*’ -> :GREEDY-REPITITION
To embed a lisp function you create a node in that parse-tree named :FILTER whose child is a function of one argument (the position in the string this function should try to match). This function returns how many charcters it consumes (by position), or nil if it did not match.
Keep in mind that the following sample is not reentrant, but could be made to be so. Now without further ado, the code:
link to the paste
Posted in Lisp, Nifty Bordom, Programming | 1 Comment »
May 20th, 2008
As a piece of speculative work, we created a tool for visualizing utility usage for our fair city Gainesville, FL. We chose to write it in Common Lisp using a somewhat modified version of the UCW web framework. This will be the third site we have written in Common Lisp and the first that is publicly available. It is also our first publicly deployed site with a PostgreSql backend. We chose to use pgsql because the bridge between sqlserver on windows and Steel Bank Common Lisp on Debian/GNU/Linux is a bit leaky through the multiple layers of C. Most of the data for this site is static, and shouldn’t need to tax the database too much (not that postgres couldn’t handle it, just that we might not have all of the config worked out yet).
We are hoping that this site will be useful for local developers, the city council, and for GRU (the local utility company) in better planning and executing “green” initiatives. We also hope that by putting something in place to allow consumers to see how well they are doing ecologically (compared to those around them), that those consumers can take charge of their utility usage and make better decisions that leave the earth a better place.
We chose to write the application in Common Lisp because:
- It allows us to get our ideas to the web with less work.
- I don’t have to interact with xml in terms of angle brackets. In our XHTML generation library (built on CXML and CHTML) I can write functions that take, manipulate and return DOM nodes. This allows tremendous abstraction possibilities on the HTML front.
- Macros - sometimes they are the only abstraction that works, and then they are great to work with.
- I compile once and then never think about it again as I continuously work in a running image. I continue to compile frequently, but each of these is only for a form or file and takes very little time to finish. This has led to problems with broken check-ins, but I think that is more of an issue with my usage patterns than the environment.
- I get to retain small pieces of my sanity that C# would mercilessly torment to Death death = new Death (my_sanity).
We will hopefully be blogging about this a bit more in the future so stay tuned if you care and if you don’t… um… continue not caring.
Posted in Eco, Lisp, Programming | No Comments »
May 14th, 2008
Note: I wrote this a while ago and never proof read / published it, so this patch was actually included in Bind a while ago.
I finally got around to trying out Gary King’s Metabang-Bind library. There has been a bit of grumbling around the office about how I might be doing it wrong, if I need to bind so many variables that I need this library. I felt this at first as well, but to some extent, the things I was working on pretty were imperative. I am writing a replacement for our invoicing program and had about twenty bindings in a row. I found the code to be neater and easier to read after switching to bind so I feel that this was a win overall.
After using it a bit, I found a few things that I wanted to add. It was pleasing to discover that the code was very easy to extend. To add a new binding pattern was simply a matter of specializing a new method based on the first token in the binding form.
The first change I made was that, when binding accessors I wanted to be able to write to the variable and have that effect the values in the object. The current binding scheme for accessors converted to a let* form. My change simply made the accessors bind using a with-accessors form instead of the let*. The older form involving the let* is still available using the :accessors-read-only symbol instead of :accessors. The following is the lift unit test demonstrating this patch in action:
1: (addtest (test-classes)
2: basic-accessors-1
3: (ensure-same
4: (bind ((obj (make-instance ‘metabang-bind-class-2
5: :a 1 :b 2 :c 3 :d 4 :e 5))
6: ((:accessors a c e) obj))
7: (setf a :a c :c)
8: (list (e obj) (c obj) (a obj)))
9: ‘(5 :c :a) :test ‘equal)) |
Posted in Lisp, Programming | No Comments »
March 11th, 2008
At work we just released our first version of our first ever flash video game. Its a game where you try to fly your dot..er..spaceship into the target area. Might not be fun for everyone, but some of you might be able to kill a few minutes at work and have a bit of fun.
![Celest, Our First Flash Game [Screen Shot]](http://russ.unwashedmeme.com/blog/wp-content/uploads/2008/03/celest_screen.PNG)
Posted in Uncategorized | No Comments »
September 27th, 2007
The problem we have is that a significant portion of our codebase was written with the idea that the whole process will be using the same configuration data. This has worked pretty well for many years, but today we wanted to set up one of our projects to talk to a different database than the other projects in our solution. This problem is compounded because the connection string is stored in our standard configuration data. We also never pass this data anywhere as all our code connects to the database by going through specific utility functions/classes in our code base. Because both of the child projects interact with codebase and just link it in, there was no easy way we could come up with to alter the configuration of just one of the DLLs without altering the config for all projects.
Our solution makes use of the ILMerge tool from Microsoft. This tool is useful for combining many .Net assemblies and executables into a single assembly/executable. How this helps us solve our problem is that it supports a couple neat command line arguments. (ILmerge can also be run programmatically and as a nant task.) By using /internalize, we can completely absorb all of the merged in binaries, thereby not exposing them to anything that links to our library. (This is important because our goal is to internalize our code base which everything links to). Now by compiling in our configuration data (resx files), we get an assembly that while using our codebase internally, only looks at its internal configuration data, rather than the configuration shared by the rest of the application.
The command line used to accomplish this:
ilmerge /internalize /allowDup /out:Merged.dll ClassLibrary1.dll Codebase.dll
Some interesting notes. While the internalized binary reports its type as having the same name as the dll, when comparing whether the Types are ==, it returns false (which makes sense, otherwise it would be linked to duplicate type names.
Posted in C#, Programming | No Comments »
April 4th, 2007
To Disable Page Titles and Wiki Title from MediaWiki pages:
In MediaWiki:Common.css add the following lines. Useful for creating prettier printable versions of documents.
div#content>H1.firstHeading{display:none};
#siteSub{display:none};
Posted in Uncategorized | No Comments »
March 28th, 2007
These are the new language features that I found being talked about;
- Better Type Inferencing including the use of “var’ key word which macro-ishly rewrites to the type of object you assign to it. This is also the case with Arrays which now do not need explicit type declarations
- var x = 42;
- var arr = new[]{”This”, “is”, “a”, “string”, “array”};
- Keyword Arguments in Constructors
- new Point( X = 3, Y = 4)
- X, and Y have a syntax to declare them similar to public accessors
//Due to Better Type inferencing we can elide Point
var r = new Rectangle {
P1 = { X = 0, Y = 1 },
P2 = { X = 2, Y = 3 }
};
- Seems to have anonymous types / classes with an easy syntax
- var x = new (X = 3, Y = 4)
var p1 = new { Name = "Lawnmower", Price = 495.00 };
var p2 = new { Name = "Shovel", Price = 26.95 };
p1 = p2; //These are of the same anonymous type
- Opening base classes to provide functionality (a bit, you still cannot get to non public members on that class.)
namespace Extender{
public static class XMLUtil {
public static string ToXML(this Point pt) {
// stuff
}
}
}
- Notice that our first parameter must be a type definition for the object we are wanting to extend.
- Lambda expressions which in C# 3.0 seem to be mostly better syntax for anonymous delegates with outer variable capture(sic). For some reason they thought that the ADwOVC were a little verbose for the task at hand, and were not quite enough like LISP lambdas.
- x => x + 1 // Implicitly typed, expression body
- x => { return x + 1; } // Implicitly typed, statement body
- (int x) => x + 1 // Explicitly typed, expression body
- (int x) => { return x + 1; } // Explicitly typed, statement body
- (x, y) => x * y // Multiple parameters
- () => Console.WriteLine() // No parameters(Yay Thunk!)
- Query Expression / LINQ: This is a big, so I am only going to cover it briefly. The goal of this is to allow set processing language in your C# program. It will convert a “Query Expression” into a series of function calls that will operate on a set of data. There is a ton more information about this out on the web if it piques your interest.
from c in customers
from o in c.Orders
orderby o.Total descending
select new { c.Name, o.OrderID, o.Total }
from c in customers
join o in orders on c.CustomerID equals o.CustomerID
join d in details on o.OrderID equals d.OrderID
join p in products on d.ProductID equals p.ProductID
select new { c.Name, o.OrderDate, p.ProductName }
- Expression Trees (from the spec): permit lambda expressions to be represented as data structures instead of executable code. Expression trees are efficient in-memory data representations of lambda expressions and make the structure of the expression transparent and explicit. While this certainly sounds interesting I wish they would have spent more than a paragraph on it in the language spec. My guess is that this is mostly in there to support what LINQ is doing more than that this was intended for end user use much. It is possible though that this would allow for macros expressed as operations on an Expression Tree. It also seems to backdoor in runtime evaluation.
The final result is that C# 3 is still static all over the damn place, but hey… they are working on it. Maybe version 4 will have a regular old eval function (hehehe)
C# 3.0 Language Spec
Extremely long article that I skimmed through and stole an example out of
Also … I started this cool post war on reddit.
Posted in C#, Programming | No Comments »
March 23rd, 2007
Dear Senator Nelson,
I am writing to urge you to support the Restoring the Constitution act of 2007. Your vote of support for the Military Commissions Act of 2006 was, in my opinion, the low point of your senatorial career. You can work to undue the harm that was caused by this act, by voting now to support the reinstatement of habeas corpus and by declaring that we are a land of free people, not a police state.
As stated in a previous email to this office, I do not in anyway, ever, support torture. Working to make that the official stance of the United States government, is incredibly important to me. From what I understand of the Restoring The Constitution Act of 2007, it would bring us back to the sound principles of treating everyone fairly and without torture, and force us to comply with our foreign obligations under the Geneva Convention.
I have read that nearly 400 men continue to be held indefinitely and without charge at Guantanamo Bay, and that a good many of them are provably innocent. Please allow due process to help these individuals see some form of justice.
Thank you very much for your consideration on this issue.
Russ Tyndall
My last letter to Bill Nelson urging him not to support the Military Commissions Act of 2007
Posted in Politics | 1 Comment »