January 14, 2012

Rails tests gotcha with I18n.locale

A example of a bad I18n rails test... Found some tests failing in a project because tests in different files would change I18n.locale, changes like this make your tests fail if the tests are not run in the standard order. since this took me awhile to track down, I thought I should share a quick example for others to find. So if you are having a issue like this remember to add a teardown method that resets I18n.locale to the default local.

December 27, 2011

Ruby processing: making it snow

I re-found a fun holiday project I did a couple years ago making snow with Ruby processing.

snow-processing.jpg

December 17, 2011

Cleaning up files after hacking

This blog was hacked awhile ago. It was annoying, I hadn't updated my blog software for awhile and there was a security hole. It was a good learning experience of how to deal with the intrusion. It was also nice to be able to quickly whip together some scripts to help clean everything up.

This let me see which files were recently modified

find . -type f -mtime -3 | grep -v "/Maildir/" | grep -v "/logs/"

The exploiters were modifying my .htaccess and adding a few files of their own, this deleted their files

This code helped remove exploit code that was injected into all of the pages on the site.

After upgrading my software and installing security patches, a bit of other cleanup, and file permission fixes everything was back to normal.

November 16, 2011

ActiveRecord / Rails case insensitive ordering

It is pretty common to want to have the results of a query sorted by order. I wanted the results sorted by name on a user object. Oddly it is hard to find how to make a string based order case insensitive on google. So for other having the same issue, it is simple, just add lower(field) in the order clause and it will sort in a case insensitive manner. Now I don't care when a user doesn't capitalize the first letter of their name.


User.order('lower(name)').all

November 14, 2011

Announcing NothingCalendar

I wanted a small project to play around with. A project that was small and simple that I could actually get done in my free time. An app I would use myself. I ended up deciding to build NothingCalendar, which was inspired by CalendarAboutNothing. It let's users track events, anything they feel like tracking over time. Mark off days you worked out, kept to your diet, worked on writing, studied, quit smoking, or anything else.

The idea was a simple way that I could add marks on a calendar on my phone, and have it sync-able and shareable. I also wanted it to be useable when you are offline, since phones loose connection often in metros, planes, lines, etc.

One goal with the project is to keep it is small enough that I can build it and play around with different ideas. It is such a small app, that I could rewrite the entire thing with a new methodology if I wanted. Which is exactly what I plan on starting to do. I wanted a app that I could practice new skills and techniques on, while still being useful, and something I would use on a day to day basis.

I started working on the project with the idea to build up a chain of doing some open source experimental development having a playground to try things and learn. A small app where I could push myself to look at new technologies, and to force myself to release them into a production environment, opposed to another one off script or tests that never see the light of day. I highly recommend forcing yourself to do a bit of development every day, it is recommended by a bunch of smart people (Andrew Hunt and David Thomas's The Pragmatic Programmer: From Journeyman to Master, Chad Folwer's The Passionate Programmer, Paul Graham's Hackers and Painters). I was in part inspired by Chris Strom (@eee_c), who has done incredible work keeping up a chain and blogging about what he learns.

NothingCalendar is a testament to what you can do in about 15 minutes a day. That is about how much time I have spent on it most evenings. Just forcing myself to do a bit every day, has led to my longest streak on CalendarAboutNothing (66 days at the moment). Just remembering to code a bit everyday, keeps the project in your mind, keeps you improving it. It also makes refactoring little things a perfect task, you only have a few minutes take something on. Complete a tiny refactoring of from a todo list and check it in. I frequently just check in #TODO comments, and grep for them when I don't have much time or an idea of what to work on. After a tiny todo, call it a day and know you will have more time sometime soon to do something more substantial.

Please give NothingCalendar a try, and let me know how it goes or any problems / feature ideas. I will will be working more more on it each day, and trying to rewrite large parts of the app using some new ideas.

November 13, 2011

working with Facebook Dialog Feed and urls with params

Facebook's documentation always sucks. There are many examples of working with facebooks dialog feed, but none of them include passing urls that have params. They are all simple examples like share 'http://example.com', well if you want to share 'http://example.com?foo=bar&buzz=baz' you are kind of out of luck. It took me far longer than I care to admite to figure out the right way to get facebook to share a link that included params.

I was using ruby and rails, creating a link with _url and params, and then trying to encode it and send it to facebook. Below is what ended up working. Note that it seems to be a bit of an odd encoding, but it allows one to send urls with params and encoded '?' and '&' properly through facebook and have the share url include the params your expecting.


facebook_shared_url = action_url({:foo => 'bar', :buzz => 'baz'})
facebook_url = "https://www.facebook.com/dialog/feed?app_id=#{FACEBOOK_CLIENT_ID}&redirect_uri=#{URI.encode(facebook_shared_url).gsub('&','%26')}&description=#{text}&name=#{via}&link=#{URI.encode(facebook_shared_url).gsub('&','%26')}"

Web 2.0 craziness

View Dan Mayer's profile on LinkedIn


I Power Seekler
I Power Seekler

www.flickr.com
This is a Flickr badge showing public photos and videos from mayer_dan. Make your own badge here.

Creative Commons License
This weblog is licensed under a Creative Commons License.