I recently added this rake task to our project. It performs fast database saves and restores using another postgres database. This is a very handy rake task to have around if you need to quickly go back to a previous version of your database and the normal create/restore process is too slow (for instances, restoring using a scrubbed database backup hosted on S3)
Friday, January 17, 2014
Friday, January 10, 2014
Find the most popular capitalization of a word or phrase
Today, I needed to find the most popular capitalization of user entered product brands. Previously, I'd just used lowercase brands, something like this:
However, this was returning "whole foods" instead of "Whole Foods", which was considered more desirable.
Using window functions and common table expressions, this is what I came up with:
However, this was returning "whole foods" instead of "Whole Foods", which was considered more desirable.
Using window functions and common table expressions, this is what I came up with:
Tuesday, August 13, 2013
Adding Process ID and timestamps to the Rails Logger
For the last few days, I've been trying to debug a race condition between several Delayed::Job workers. After looking at log files for many hours, it became very frustrating to not know which one of my 3 workers was writing which statement. I finally found this post which almost did what I wanted.
To add process ids and timestamps to your Rails logs, you can add this as a Rails initializer (config/initializers/log_formatting.rb for instance) and restart your application / workers:
To add process ids and timestamps to your Rails logs, you can add this as a Rails initializer (config/initializers/log_formatting.rb for instance) and restart your application / workers:
Wednesday, May 8, 2013
How to write a simple Rails gem
Today, I wrote my first Ruby on Rails gem. It was a very simple refactoring of our code that I undertook when I needed to add the same functionality to a new model and I decided to do it as a gem instead of keeping it within our project. I wanted to see how it worked and this is what I ended up with. You can follow the Rails Guide, but it didn't cover everything I wanted to do.
Friday, September 7, 2012
Benefits of Standing Desks
One of the perks of working from home is that I have total control over my work environment: chair, desk, computer, climate, light, etc*. However, like many professionals, I sit for a lot of the day; 45+ hours a week, 48+ weeks a year for the past 12 years. This isn't healthy or natural. I've been pretty good about getting exercise regularly, but since 45, or more, of my 120 waking hours during a week are spent working, there is a great opportunity to lead a healthier lifestyle with simple changes during work; small, simple sustained improvements can have a huge overall impact on your lifestyle and goals.
Labels:
marginal gaines,
self improvement,
working from home
Location:
Kirkwood, MO 63122, USA
Wednesday, September 5, 2012
Expanding multiple sections of a JQuery Accordion
I've loved using jQuery and jQuery UI on my current project. They work, on all browsers, and they make things simple. They are powerful and extensible - great tools. However, one thing that has really annoyed me is the jQuery UI accordion. They have this snippet in their documentation:
This drives me nuts! If you have to write a note about something that the control doesn't do, bolded and in a larger font size in the documentation, because lots of people want to do that, or are asking for it, the control should probably perform that function.
This is exactly what I wanted to try out for one of our UI prototypes. Usually, we wanted one section open at a time (the accordion behavior), but sometimes we want to see all 5 sections (say for printing or so you don't have to remember the first section when looking at the last section.
I found this excellent example of how to hack the jQuery UI accordion to allow multiple sections to be expanded at the same time: http://jsbin.com/eqape.
I then added this bit of JavaScript to expand and collapse all the sections. These are hooked up as click handlers for a couple of icons on the page.
This improved the jQuery accordion significantly and I hope we see all this behavior native to the control sometime in the future.
NOTE: If you want multiple sections open at once, don't use an accordion
This drives me nuts! If you have to write a note about something that the control doesn't do, bolded and in a larger font size in the documentation, because lots of people want to do that, or are asking for it, the control should probably perform that function.
This is exactly what I wanted to try out for one of our UI prototypes. Usually, we wanted one section open at a time (the accordion behavior), but sometimes we want to see all 5 sections (say for printing or so you don't have to remember the first section when looking at the last section.
I found this excellent example of how to hack the jQuery UI accordion to allow multiple sections to be expanded at the same time: http://jsbin.com/eqape.
I then added this bit of JavaScript to expand and collapse all the sections. These are hooked up as click handlers for a couple of icons on the page.
This improved the jQuery accordion significantly and I hope we see all this behavior native to the control sometime in the future.
Labels:
accordion form,
jquery,
jqueryui
Location:
Kirkwood, MO
Monday, September 3, 2012
How I backup my photos
As my wife will quickly let you know, we lost some important photos of a trip we took due to a hard drive crash. Since then, I've become very paranoid about how I store and back up our photos and videos. Here is how I now back my photos and videos.
Subscribe to:
Posts (Atom)