Friday, March 13, 2015
Rails test helper for stubbing a constant
The way I use it is to include it in ActiveSupport::TestCase somewhere in test/test_helper.rb.
class ActiveSupport::TestCase
include WithStubbedConst
...
end
Monday, January 21, 2013
Fixing the caps lock key in Gnome in Fedora 18
The gsettings command to make caps lock act as a control key in Gnome is this:
If you are worried about losing any other settings you might have in xkb-options, then do this:
This is an explanation I got just now (from someone who should know about this stuff):
"GNOME 3.0 shipped with input methods separately from xkb, now the two have been brought together to have one dialog. I suspect xkb options will come back, but that'll take another iteration"
Ps, for more info on gnome input sources, see these blog posts by mclasen.
Pps, I've been an anti-caps lock campaigner for a while now :)
Wednesday, October 31, 2012
Nice brief git log format
Firstly, I just learned about the core.pager option which solves the problems I was solving previously with this ugliness:
ll = "!git --no-pager log --pretty=nice -n30; echo"
Secondly, the %+d. I generally don't use the --graph log formats, (such as these), that show you the branch paths, but seeing where the refs are is super useful. The + makes it appear on the next line without adding a line break when there are no refs.
Here's a screenshot of how it looks (with details obscured to protect the innocent).
nice = format:%Cblue%h %C(cyan)%cr %Cgreen%an%Creset %s%C(yellow)%d %Creset
Tuesday, October 2, 2012
Some "progress" on my Tau in Ruby patch
"Once τ is widely accepted in these communities, we might add it..."
But also:
"...if it were just up to me, I'd add it just to show support. It's a rather tiny and harmless addition."
See the ticket here.
Tuesday, August 14, 2012
Wednesday, August 8, 2012
Make it easier to use partials with blocks in rails
How to make pinned tabs in Firefox a bit wider
Wednesday, February 8, 2012
Make ActiveRecord::Base#create respect the :type attribute
I think I've needed and implemented this twice now, so let's make a post about it.
The problem occurs when you are using f.fields_for and nested forms, as per these railscasts, and the nested objects are using STI.
(Will leave a more detailed explanation for future posts).
Update 1: Even though this works as described, I don't think it solves my problem. Will post again if I figure it out...
Update 2: Found this which is I think what I was using last time I had this problem... :S
Monday, October 3, 2011
Tuesday, September 20, 2011
A Rails 3 gotcha with html_safe
My (first) contribution to Rails
You'd think DHH would be number one, but actually he's not. Take a look at the list.
Here is my original pull request if you'd like to read more about it.
Ps, I also reported a capybara bug (along with a failing test) that got fixed pretty quickly. But my fork didn't get merged so none of my commits are recorded. :P
Friday, June 17, 2011
Tau in Ruby
Here is tau.rb so you can just require 'tau'. (Maybe this should be a gem...) Ps, I just learned about module_function.
Update 1: I made this ticket which has been mostly ignored.
Update 2: Ticket has been noticed and discussed! :) Ticket has been categorised as joke! :(
Update 3: Some active debate is going on now and the ticket is now 'assigned'! :) See the details.
Update 4: (28-Jun-2014) Made a pull request in Github.
Update 5: See https://github.com/jneen/math-tau/
Thursday, March 17, 2011
beginning_of_fortnight gem is out
Install in the usual way:
sudo gem install beginning_of_fortnight
It requires ActiveSupport and adds {next,end_of,beginning_of}_fortnight methods to the Date and Time class. They work the same as the *_week methods defined by ActiveSupport. You can set where you want fortnight boundaries to be (or just use the default).
For more info see:
I carefully made sure the docs look good in RDoc but, rubydoc.info uses YARD. So they don't look so great and actually the main usage examples which I put at the top of the file aren't showing at all...
I guess I will convert to using YARD. Is RDoc fading away? The website looks pretty musty.
(Just for fun, here are tweets where it all began).
Bash functions to dump and load a mysql database
Thursday, February 24, 2011
Using the singleton class to include a module on-the-fly
I still don't entirely understand the syntax for accessing the singleton class, but I have found a use for it. :) The goal is to be able to make an object include a mixin on the fly.
If you do self.class.send(:include,module_name) instead of using the singleton class then the change affects every instance, not just the one you intended.
So it seems to work pretty well. Ruby is all like "sure buddy, have some rope, take as much as you need". :)
I should say that this technique was designed to be a quick fix to let us work around some legacy code that really should be refactored and fixed properly. I'm not saying this is a sensible design pattern, but it is cool that ruby can do it.
Here is a good explanation of singleton classes in ruby.