inicio mail me! sindicaci;ón

Archive for Dezember, 2011

Saving local text files to S3 using paperclip

Sometimes you need to save a locally created file to S3 instead of an uploaded file, as is the standard. Here is how:

  has_attached_file :tagged_text_file,  STORAGE_OPTIONS.merge({
    :processors   => []
  })
  def save_tagged_text_file
    file = File.open("#{RAILS_ROOT}/tmp/tagged_text_#{id}.txt", 'w+')
    file << tagged_text
    self.tagged_text_file = file
    save!
    file.close
  end

Connecting to redis via SSH tunneling

SSH tunneling is, of course, useful for a ton of services, but I happened to stumble upon it, when I wanted to connect to a remote redis server.

If you have a redis server running on , you can easily connect
to it (given you have ssh access to it, of course):

ssh -L 9999:localhost:6379 @

will open a tunnel from the remote port 6379 (redis standard) to the local port 9999.

You can now use the redis on your local port 9999 like you would if it was running locally. Nice.