Posted by matijs
Sun, 27 Jun 2010 21:10:00 GMT
In some of my Rails projects, I have been a contented user of the memory_test_fix plugin. However, I rather dislike the use of Rails plugins, because I find updating them later on rather difficult, and I don’t like including external libraries in my own source tree (hence, I don’t like the practice of vendoring gems much either). When the concept of ‘gem plugins’ was introduced, I created a fork on github and created the necessary files to build the plugin as a gem, and have Rails properly load it.
Somehow I never got around to seeing if all this actually worked. However, recently I revisited an old project that I never quite finished, updated it to Rails 2.3.8, and decided to try replacing the memory_test_fix plugin code it included with a simple call to config.gem. It worked fine.
After incorporating a patch to allow the use of in-memory databases for any environment (use for development and production is of course not recommended), the gem is now at version 0.1.3, and has been pushed to gemcutter.
From the README:
Install the gem:
gem install memory_test_fix
In your config/environments.rb, use:
config.gem 'memory_test_fix'
In your database.yml, use:
test:
adapter: sqlite3
database: ":memory:"
It runs much faster!
This makes me the official maintainer of this gem, which may not be ideal in the long run, since I’m not really the main author of this code. Feel free to ask me for access or to contact me to discuss other options.
Posted in software | Tags gem, memory_test_fix, plugin, rails, ruby | no comments | no trackbacks
Posted by matijs
Thu, 15 Apr 2010 05:42:00 GMT
You can implement a programming language in assembly. C is an example. This
has the advantage of being able to leave your language and use assembly
when necessary. You drop down to assembly for speed.
You can also implement a programming language in lisp. CLPython is an
example. This has the advantage of being able to leave your language and
use lisp when necessary. You drop down to lisp for expressiveness.
If lisp is the ultimate language, does this not make it the best option for
implementing other languages?
Posted in software | Tags design, language, lisp | no comments | no trackbacks
Posted by matijs
Sun, 11 Apr 2010 12:22:00 GMT
Because URL shortening services can go away at any time, I decided
to install my own. In the spirit of your-own-dogfood, and to make hacking
it as enjoyable as possible, it had to be in Ruby (this ruled out
YOURLS, which otherwise does exactly what I want). There are tons
of URL shortening projects in Ruby on GitHub. Unfortunately, they all
lacked one feature: password protection for the adding of URLs. In the end,
I picked a nice simple one and changed it to my liking. The result can be
found in my fork of turl.
Why is this safer than using one of the existing services? The reason tr.im
went under is that they couldn't make it pay for itself, and there was a
lot of abuse from spammers. Both problems are absent for my own service: I
don't need to make any money off of it, and I'm the only one who can create
new short URLs.
Some observations on developing this software:
For a small project like this, putting everything in one file is very,
very nice. Ramaze allows you to do this (as do other frameworks),
Ruby on Rails does not. I wonder how seamless the transition is if
your project starts small like this and then gradually becomes big enough
that you need to split it into different files.
Ramaze's documentation needs some love. Everything is documented well in
principle, but with the split-off of the innate library, it took me
ages to find the documentation for the a method and friends.
I really like the idea of [Sequel][sq]::Model where you define the
table schema right in the model. I'm not sure how or how well it works
with migrations, but for a small project like this, it's nice and clean.
Ramaze could use some more options for session storage. In particular,
something file-based shouldn't be too much to ask for. I'm using the
LocalMemCache option, and keep having to log in.
I really like Ramaze, and am eager to try Sinatra. I have been
ignoring these more light-weight frameworks for far too long.
Posted in software, web | Tags ramaze, ruby, shorten | no comments | no trackbacks
Posted by matijs
Tue, 02 Feb 2010 09:20:00 GMT
Daring Fireball quotes Zeldman:
Flash won’t die tomorrow, but plug-in technology is on its way out.
Exactly. And good riddance.
Posted in software, web | Tags browser, flash, ins, ipad, plug | no comments | no trackbacks
Posted by matijs
Fri, 29 Jan 2010 12:47:00 GMT
Learning about monads is hard, and there seems to be no magic pill. Probably one reason is that they have several different uses. Many articles focus on one of those uses, making it hard to get the whole picture. On the other hand, articles that try to directly explain what monads are leave the reader wandering what they're good for. Some links.
- Brent Yorgey argues that any shortcut by focusing on a particular metaphor (e.g., monads are like burritos) will not work.
- Mark Dominus argues why monads are indeed like burritos.
- [Monads as Containers][cont] fits in nicely by abstracting away from burritos (or space suits) to containers. It goes on to talk about how this relates to IO and other uses for monads. I'm still working on reading through this article.
- sigfpe starts from the other end, showing how certain needs could automatically lead to monads. I haven't finished that one either, but so far it's been very insightful.
- I also found The Continuation Monad in Clojure very insightful. Again, it focuses more in the use and implementation, rather than abstract theory. I'm not yet sure whether the insights I myself got from it are actually correct. More on that later, perhaps.
Posted in software | no comments | no trackbacks
Posted by matijs
Sun, 13 Dec 2009 18:58:00 GMT
The Problem
You have been running a Typo blog since 2005, but you still can’t
quite get your Apache configuration right. In particular, you still get the
occasional
Not found: http://www.matijs.net/blog/2005/07.html/24/from-bryar-to-typo
Note the weird 07.html part.
The Solution
This particular message turns up if you have turned the MultiViews option
on: The file 07.html was cached earlier, and Apache finds it a good
candidate for the 07 part of the URL. Of course it can’t find a
subdirectory 24 inside that file! I personally consider this behavior
extremely weird, but that doesn’t make it go away.
The solution is to turn off MultiViews and implement a poor man’s version
that does no more than what’s needed.
# Turn off MultiViews
<Directory /var/www/www.matijs.net/public>
Options FollowSymLinks -MultiViews
</Directory>
# Rewriting must be on
RewriteEngine on
# Implement simplistic MultiViews in the blog sub-uri
RewriteCond %{QUERY_STRING} "^$"
RewriteRule ^/blog/?$ /blog/index.html [QSA,L]
RewriteCond %{QUERY_STRING} "^$"
RewriteRule ^/blog([^.]+)/?$ /blog$1.html [QSA,L]
# Implement simplistic MultiViews elsewhere (static content)
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^([^.]*)$ $1/index.html [QSA,L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.html -f
RewriteRule ^([^.]*)$ $1.html [QSA,L]
That ‘s it.
Some notes:
The mapping to html files is implemented differently in the $/blog$
sub-uri than elsewhere. In the static part of the site, if there’s an
URI /some/where, and and URI /some/where/else, this is stored on
disk as /some/where/index.html and /some/where/else.html,
respectively. In the blog part, Rails’ static caching system uses
/some/where.html and /some/where/else.html.
Turning on MultiViews for the static part of the site is not possible,
since turning it off for the blog then does not seem to work. This may
have something to do with the directory layout demanded by Passenger.
It’s easy to get this wrong and cause Apache to never see the cached
files. It’s also easy to get this wrong in other ways.
The QSA part is probably not necessary. Call its presence a case of
cargo-cult configuration.
If your blog is not in the sub-URL blog you’ll have to change things,
of course. Good luck.
Posted in software, meta, howto | Tags apache, typo | no comments | no trackbacks
Posted by matijs
Sun, 25 Oct 2009 11:25:00 GMT
I run rake spec and get:
Test::Unit::AssertionFailedError in 'XmlController test_bad_format'
Expected response to be a <:missing>, but was <301>
/var/lib/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/test_case.rb:114:in `clean_backtrace'
./spec/controllers/xml_controller_spec.rb:152:in `test_bad_format'
So, things fail in xml_controller_spec, right? So, I run:
./script/spec spec/controllers/xml_controller_spec.rb
And I get this:
27 examples, 0 failures
WTF??
Yes, this turns out to be due to the fact that the spec in question was in its original form as migrated from Test::Unit. But that’s not really an excuse: Either Test::Unit style tests work in RSpec, or they don’t. They shouldn’t work some of the time. Now I suddenly can’t trust any of the Test::Unit style tests in Typo anymore: Are they passing because the code works, or because of some mystical internal RSpec magic?
I am mass-replacing lines of def test_bla_bla by it "test_bla_bla" do right now.
Posted in software | no comments | no trackbacks
Posted by matijs
Mon, 18 May 2009 09:14:00 GMT
Gnome’s file manager, Nautilus, does not natively support showing the deletion date for trashed items. This has annoyed me, and others, for a very long time.
Long story short, I created a very simple implementation in Python as a Nautilus plugin. You can find it in its github repository.
This solution has one drawback to : Nautilus plugins can only add string columns, so to make it sort right the date is not in a very user-friendly format. I like to think of it more as proof-of-concept.
What’s next? Nautilus has hard-coded support for sorting by each of its possible date columns. It would be nice to make that more generic so as to allow adding arbitrary date columns, or columns with the sort key and user-visible text separated.
Posted in software | Tags nauilus, python | no comments | no trackbacks
Posted by matijs
Sun, 17 Feb 2008 21:14:00 GMT
Hm, so Arc is here, and Paul Graham gives the Arc challenge. The answer in Arc is short indeed. First, let’s see an answer in Rails (loading a framework is allowed according to the challenge), with said_controller.rb:
class SaidController < ApplicationController
def index; end
def click; session[:it] = params['what']; end
def show; end
end
and some templates, for the first page, index.html.erb:
<% form_tag '/said/click' do %>
<%= text_field_tag 'what' %>
<%= submit_tag %>
<% end %>
second page, click.html.erb:
<%= link_to 'click here', {:action => 'show'} %>
third page, show.html.erb:
You said <%= session[:it] %>
The Rails answer may be a little longer (although by how much is hard to say due to the different syntax — is end a token?), but it not a case of the same but longer.
First, the Rails version is in temporal order, the Arc version is not. Perhaps there’s a way of reading the Arc version that makes this order natural, but right now, it looks confusing.
But the most striking difference is that it is based on a completely different philosophy of how web applications should be developed. The Arc answer is great if you want a web application based on continuations. The Rails answer is what you would use if you want to use REST.
I’m definitely in the REST camp, which makes this example meaningless as a demonstration of Arc. It shows me that Arc can be used to write a short program that does something I don’t want to do.
The ultimate question of course is whether brevity (in terms of number of tokens, not characters) is the single best metric for language power.
Update: Someone wrote a Ruby version that is about as short as the Arc version, uses the same paradigm, and is in temporal order:
def said
aform(input("foo"), submit) {
w_link("click here") {
"you said: #{arg :foo}"}}
end
Posted in software | Tags arc, continuations, design, language, rest, ruby | 2 comments | no trackbacks
Posted by matijs
Thu, 14 Feb 2008 21:35:00 GMT
I’m upset. I’m so upset that I was originally going to call this entry “Fuck you, Python”. Now, I realize that’s not a very nice thing to say, and actually, Python can’t really help it anyway. Except by not existing.
Why, why, why must every other new language created these days have significant indenting? You see a new language, like Cobra, you read the overview of features, and you go, cool, great runtime performance, static and dynamic typing, and contracts, too. So you browse on to the hello world example, and boom! the absence of end-of-block tokens hits you in the face like an iron fist.
Now, in Python’s case you can tell from the reasoning and the implementation that somebody actually thought this through, but Cobra has the following rationale for using this method of block structuring:
Cobra uses indentation to denote code structure since adept programmers do this anyway in languages that don’t even require it (C#, Java, C++, etc.)
Wow. I’m going to make a language that uses the comma-space token to separate function arguments, since adept programmers put a space after the comma in languages that don’t even require it.
Look, if you use indenting for block structure because you like Python, just say so already.
Oh wait, there’s more:
In Cobra, one INDENT is accomplished by one TAB or four SPACES.
Huh? Because adept programmers indent four characters anyway even in languages that don’t require it? Because adept programmers use one tab per four spaces anyway even in editors that don’t require it?
Sheesh.
I feel much calmer now.
Posted in software | Tags cobra, indent, madness, python | 3 comments | no trackbacks