Capistano and bundler working for a git deploy

Posted: April 20th, 2012 | Author: | Filed under: ruby, web | Tags: , , , | No Comments »

I’ve been using the “git” deploy that github talked about so long ago for a while now. I finally got around to deploying something new and decided to use the built in bundler code for capistrano. A long time ago I had to fight with it and eventually gave up. I think they finally fixed it so you can override “current_release” which lets you work in a strategy that doesn’t force releases on you.

Adding the above lines somewhere in your deploy (change as needed) will allow you to override the default and get the deploy working.

It’s interesting that they don’t list “current_release” as an option you can change but if you look at the code it’s being pulled in just like all the others.


rspec view spec and dealing with current_user

Posted: March 30th, 2012 | Author: | Filed under: ruby | Tags: , , | No Comments »

I was trying to learn about view specs since doing everything in Cucumber has been considered to be a bit of overkill recently. I was looking for a solution to deal with current_user and this is what I’m using.

items/show.html.haml

show.html_spec.rb


vim config

Posted: March 24th, 2012 | Author: | Filed under: ruby | Tags: , | No Comments »

I’ve been working on a project which has a really nice set of vim plugins with a decent configuration. I’ve been trying to send in a few patches but it was a bit of a pain to use mine but keep it updated with the main repo. A bit of searching gave me a nice setup.

This clones my fork and also adds the parent as the upstream remote.

Now if you add this to your .gitconfig you can do an easy git pu to pull in changes from both branches.

Thanks
http://gitready.com/intermediate/2009/02/12/easily-fetching-upstream-changes.html


Vim + Ruby + CommandT = win

Posted: March 22nd, 2012 | Author: | Filed under: ruby, web | Tags: , | No Comments »

So I’ve been trying to get vim working on my macbook with the command-t plugin for file searching. I spent quite a while trying to get it working a while ago and finally did a really simple thing and it just worked.

I’m using rbenv with ruby 1.9.3-p125 as my main ruby, but you need to make sure that you compile command-t against whatever ruby vim as compiled with. The homebrew-dupes forumla uses the system ruby (which lives at /usr/bin/ruby) and even if you have rbenv global set to another ruby, you can always directly use the system ruby.

Thanks to:
https://github.com/Casecommons/vim-config
https://github.com/Casecommons/casecommons_workstation/blob/master/recipes/vim.rb


hello vim

Posted: February 17th, 2012 | Author: | Filed under: ruby, web | No Comments »

So I started a new job and the main text editor is vim. I am now a big fan.


Adding the current path to the Window PATH variable

Posted: October 19th, 2011 | Author: | Filed under: Uncategorized | No Comments »

I was trying to find a way to add my current directory plus a subdirectory to my PATH.

If you add ./subdirectory to your windows PATH environment variable it works and you can run anything in your current_dir/subdirectory.


MongoDB, mongoid, elasticsearch and tire issue

Posted: June 28th, 2011 | Author: | Filed under: mongodb, ruby | Tags: , , , | 1 Comment »

I just setup a quick app with MongoDB, mongoid, elasticsearch and the tire gem. The system seems to work nicely but there is an issue you should be aware of. Since tire uses the ‘after_save’ callback to insert data into elasticsearch it will be pretty automatic, which for the most part is nice.

The issue occurs when you have a unique index in mongodb but don’t have a ‘validates_uniqueness_of’ in your model. With this combination and two similar records, mongo will reject the new record, but it will still insert into elasticsearch giving you a record in elasticsearch that doesn’t exist in mongodb. This is potentially a nasty bug.

The quick fix is to make sure that any unique index in your database also includes the ‘validates_uniqueness_of’ validator in your model.


In Rake tasks, :needs has been depricated

Posted: June 8th, 2011 | Author: | Filed under: ruby | No Comments »

I updated a project from Rake 0.8.7 to 0.9.2 (now that it doesn’t gag on the older code) and was met with this new “error”

So as an example here is one of my old tasks without arguments. I’ve

And the fixed version.

Now an example with arguments.

And the fixed version.

I’m not sure if you need to use the arrays, but it works and the examples do show that.


Serving assets in Rails 3.1 with nginx

Posted: June 7th, 2011 | Author: | Filed under: ruby, web | 3 Comments »

I decided to create a site that uses the new Rails 3.1rc. I have a nice setup for nginx to serve my static assets and I was able to get it working with rails 3.1. There’s nothing really too tricky since it’s setup to do it, but you need to make sure that you pre-compile your assets when deploying. The only confusing bit is that you should remove all of your assets before running the rake task to make sure you’re not duplicating files and/or serving the wrong thing. I did a bit of testing and found it was necessary to remove the files and re-compile before starting the server to get the correct files served. I’ve added a small snippet of code below to show how I did it. I also decided it wasn’t necessary to symlink the files into the shared directory since they were getting removed on every deploy anyway. I’m sure there’s a way to only delete the files that changed, but for now this works.


Letting multiple users modify sets of records from a larger group

Posted: April 22nd, 2011 | Author: | Filed under: ruby, web | Tags: , , | No Comments »

The title really isn’t great but it does describe an issue I recently ran into. I’m working on a web application that lets a user set wether an attached term is correct or incorrect. While this can be done on a record by record basis, it becomes quite tedious. I set up a system that would show a listing of all of the terms along with a snippet of the text where the term was annotated. This worked well as I had searching, sorting and pagination and users could always move to page two or three if they wanted. This also worked when I had 1000 records. Once I bumped the dataset up to 300k records, pagination in MySQL became pretty lethargic.

I decided to remove the pagination and show the user the first set of records available. It then dawned on me that once you had multiple people working on the same page, they would all see the same records. This isn’t very efficient when you have a lot of stuff to get done. On a side note, this same problem existed in the paginated version, but when you have a link to move to the next page, it doesn’t crop up as much)

So now I needed to figure out a way to determine who was seeing what records, make sure that someone else didn’t see those same records at the same time, and make sure that if nothing was done to the records, they would return to the general pool in a reasonable amount of time.

Enter Redis.

I like redis. I’ve used it on a few other projects and felt that it would be a good fit since it has some nice set manipulation commands and the ability to expire a key after a specified amount of time. I started thinking about how to remove records after the user processed them and such, but I ran into some issues with possible AJAX search lag and that some records I didn’t really care about might be removed from the general population. Also, what do you do if the user only wanted to update a subset of those records? By modifying the key, I’d need to reset the expiration timer.

After writing a bit of code, I figured out that if I deleted the current user’s key before I make a union of all the users records, I wouldn’t have to worry about orphan records and unmodified records. Every time the user saw a list of records, only the current visible set would be removed from the general population.

Here’s a quick overview of what the script does.
2. Add the current user id to the set of curator ids
3. Remove the key that holds the current user’s reserved records
4. Get all the curator ids
5. Generate keys for all the curator reserved records
6. Get the union of all of the reserved records

I have to make a special note here. Redis expects arguments in the form SUNION “key1″ “key2″ “key3″. When you have an array in ruby, generally it will look something like ["key1", "key2", "key3"] The * (splat) operator splits out the array into a group of keys that works for the Redis command.

7-10. Find the first 15 currently available records and store the ids in the current user’s set in Redis.
11. Add a five minute expiration to the current user’s key.

It was interesting to me after thinking about it for a while that the solution ended up being so simple.