1 day ago
I finally found the time to clean up the delayed_paperclip - plugin I wrote a while back and load it up to Github. You can find it here:

http://github.com/sens3/delayed_paperclip

If you are using Paperclip for media attachments and think about loading the processing off to a background job (delayed_job in this case) this might be for you. Enjoy!
comments
11 days ago
Covers 37 Signals' Sprocket, Authentication with Gigya, Prince (PDF Generation)....
More info and download here.
comments
11 days ago
The following module allows you to call *_count methods on any ActiveRecord Object.
i.e @post.comments_count instead of @post.comments.count

It looks kinda stupid and unnecessary but comes in handy if you have(!) to specify a method by passing a symbol. In my case I was using this in JSON serialization parameters.
@user.to_json :methods => [:post_count, :comment_count]
The module also takes care of the respond_to? method by checking if the given association exists.
module AssocationCounts
  
  def respond_to?(name, include_private=false)
    if as = get_association(name)
      !self.class.reflect_on_association(as).nil?
    else
      super
    end
  end

  def method_missing(name, *args, &block)
    if respond_to?(name) && as = get_association(name)
      self.send(as).count
    else
      super
    end
  end
  
  def get_association(name)
    if md = name.to_s.match(/^(.+)_count$/)
      md[1].to_sym
    end
  end
  
end

class ActiveRecord::Base; include AssocationCounts; end
comments
3 months ago
This is all over the internets but I'm sick of always having to search for it, so...

 ActiveRecord::Base.logger = Logger.new(STDOUT)

comments
3 months ago
If you're developing a RESTful app you may or may not allow actions for certain controllers in your routes.rb
map.resources :posts do |post|
  post.resources :comments, :only => [:index, :create]
end

Now since (dis-)allowing certain actions can be quite a sensitive part of your app it should definitely be spec'd.
Here's a simple 1-liner of how to test this in your controller specs:

it "should not allow update" do
 lambda {put :update, :id => @com.id}.should raise_error(ActionController::RoutingError)   
end

comments
9 months ago
Tell Rails to use memcached. In production.rb (or staging.rb or...)
ActionController::Base.cache_store = :mem_cache_store, "ip_address_of_memcached_server",
                                                 {:namespace => "my_super_app"}

Specify the action you want to cache.
class PostsController < ApplicationController
   cache_action :posts_with_comments
   def posts_with_comments
     # shows all posts with comments
   end
end

Create a sweeper. (app/sweepers/post_comment_sweeper.rb)
class PostCommentSweeper < ActionController::Caching::Sweeper
  observe Post, Comment

  def after_save(rec)
    expire_cache_for(rec)
  end
  
  def after_destroy(rec)
    expire_cache_for(rec)
  end
  
  private
  def expire_cache_for(rec)
    expire_action(:controller => '/posts', :action => 'posts_with_comments')
  end
end
Note: the '/' in the controller name is important if you will invoke the sweeper from a nested controller. Without the '/' the cache_key will be wrong and rails will not find your data in the cache.

In each controller where we want our sweeper to be invoked if a observed model is saved or destroyed add the following line.
  cache_sweeper :post_comment_sweeper

Now our cached action will be expired everytime a Post or a Comment is saved or destroyed.
BUT: this will only happen if the save or destroy is called from within one of the controllers we added the cache_sweeper to.

The Sweeper will NOT be invoked if you do something like Post.last.save in script/console.
I dont know why it's implemented that way but that's how it is.

Now fire up your memcached instance and you're set!


comments
9 months ago











Oh, how fun it is to ride the NY subway.
Street Art by Poster Boy. More here.
comments
9 months ago
Richie Hawtin just announced the release of a Twitter DJ app that instantly tweets a track you played with Traktor. So if you're playing somewhere people around the world can follow every single tune you play.

Here's a good article on beatportal that pretty much sums up all the pro's and con's of this and how it might change everything.


http://www.beatportal.com/feed/item/how-twitter-tracklist-app-will-change-everything/
comments
9 months ago
Tired of using Skype or some other IM thingy to show a fellow developer/student some code or text you just wrote?
Yeah there are some fancy tools out there but cl1p.net makes this super easy, all you need is a browser.

Just pick a clipboard name, share the link and you're good to go.

I haven't tried it in action but it looks quite useful and there's a ton of other things you can do. (i.e. accessing URL's on your mobile phone of choice).

Unfortunately the site isn't really well designed which makes for a worse user experience than expected. I think design is key for being successful in the online world nowadays. There's just too much out there to not put your best suit on to keep people interested!

Try it! www.cl1p.net

Update: Forget cl1p, use gist on github. It does pretty much the same BUT looks way better! All you need is a github account but you should have one anyway...

comments
9 months ago



Stolen from Let's Kiosk's Flickr Stream.
They are a design studio from UK doing awesome album covers and more. Look!
comments