about 1 month 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
about 1 month ago











Oh, how fun it is to ride the NY subway.
Street Art by Poster Boy. More here.
comments
2 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
2 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
2 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
3 months ago
You have some multimedia-model (Image/Audio) in your app. The actual files are stored on Amazon S3. And to tie these 2 together you use attachment_fu.
The problem you will have if you work in a team of developers is that, since attachment_fu is expecting one bucket per environment, all developers will write their data to that 'development'-bucket and possibly overwrite each others data.

A fast solution that does not involve hacking the plugin itself is to include this simple line in your model:
  CONFIG_PATH = RAILS_ENV == 'development' ?
        "#{RAILS_ROOT}/config/amazon_s3_dev.yml" : nil
 has_attachment :s3_config_path => CONFIG_PATH,
                              :storage => :s3,
                              .......

If you are in 'development' attachment_fu will look into amazon_s3_dev.yml otherwise into the default file amazon_s3.yml.
The advantage here is that you dont have to change the (probably version controlled) default config file.

The amazon_s3_dev.yml-file should then look sth. like this:
development:
  bucket_name: social_dev_your_name
  access_key_id: your_access_key_id
  secret_access_key: your_secret_access_key
You can now also remove the development entry from amazon_s3.yml.

Don't forget to create the actual buckets on s3 to complete this setup.
comments
3 months ago
Be very, very, very careful with this!
Run this from within ./script/console [development|test|staging]:
con = ActiveRecord::Base.connection
(con.tables-['schema_migrations', 'sessions']).each do |tbl| 
    con.execute "delete from #{tbl}"
end

This will remove ALL data from all tables from your database (besides the schema_migrations and sessions table).

You might as well just drop the whole database of course but then you'd have to re-create it and run all those migrations on it which can take an awful lot of time if your app is a little older...
comments
3 months ago
If you're trying to migrate or backup your data you can do this quite elegant using rake and YAML. You can find infos and code here and there.
The only problem with these snippets are the migration of JOIN-Tables since tbl.classify.constantize won't work if tbl is 'users_roles' for example (unless you created a class for this table of course).

Solution: just define the class for each JOIN-table that does not have a class yet. Add this somewhere at the beginning of your new rake file :
class UsersRole < ActiveRecord::Base ; end
comments
4 months ago
I'm back in Munich! It feels ok to be here but there are sooo many things I will terribly miss until my return to NY this summer:
(in no particular order)

  • snickers with dark chocolate

  • not having to do my laundry (due to cheap chinese laundry)

  • not having to cook (due to cheap chinese takeout)

  • best ______ (fill in cuisine of choice) restaurant I've ever been to

  • having a president with swagger

  • sunshine

  • variety (people/clothes/food/... you name it)

  • vitaminwater (as coffee substitute)

  • NY subway musicians

  • my peeps (you know who you are...:)



comments
4 months ago


First found here. Text and Video grabbed from here.

"MIT grad student David Merrill demos Siftables -- cookie-sized, computerized tiles you can stack and shuffle in your hands. These future-toys can do math, play music, and talk to their friends, too. Is this the next thing in hands-on learning?"
comments