Friday, February 15, 2013

Crop center and resize paperclip image attachment


  has_attached_file :profile_image,
    storage: :s3,
    s3_credentials: {
      bucket:            Settings.s3_bucket_name,
      access_key_id:     Settings.aws_access_key_id,
      secret_access_key: Settings.aws_secret_access_key
    },
    default_url: '/assets/default_profile_pic.png',
    styles: { square_50: '', square_100: '', square_193: '' },
    convert_options: {
      square_50: '-gravity center -resize 50x50^ -crop 50x50+0+0',
      square_100: '-gravity center -resize 100x100^ -crop 100x100+0+0',
      square_193: '-gravity center -resize 193x193^ -crop 193x193+0+0'
    }

Thursday, February 7, 2013

Restart Nginx on OSX

Best to have them as bash aliases.

alias startnginx='sudo /usr/local/Cellar/nginx/1.2.4/sbin/nginx'
alias stopnginx='sudo killall nginx'
alias restartnginx='stopnginx; startnginx'

# If you need to know where's nginx bin
locate nginx

Friday, January 18, 2013

Permission denied (publickey) error when doing cap deploy

I encountered this when trying to do a capistrano deploy on one of client's server. This error means that the server that's trying to fetch from repository on Github does not have permission to do so. We can resolve this with either:


If ssh-agent isn't running, run the following in terminal.

exec ssh-agent bash

Tuesday, December 18, 2012

Friday, November 16, 2012

Check if a dom element has children


$('#foo).children().length > 0

Wednesday, October 31, 2012

Added message to Campfire chatroom for Capistrano deploys


# Gemfile
gem 'capistrano-campfire'
gem 'tinder'

# config/deploy.rb
require 'capistrano/campfire'
require 'tinder'

namespace :campfire do
  desc "Send a message to the campfire chat room"
  task :snitch do
    campfire = Tinder::Campfire.new YOUR_CAMPFIRE_ACCOUNT, :ssl => true, :token => YOUR_CAMPFIRE_TOKEN
    room = campfire.find_room_by_name YOURC_CAMPFIRE_CHATROOM
    snitch_message = fetch(:snitch_message) { ENV['MESSAGE'] || abort('Capfire snitch message is missing. Use set :snitch_message, "Your message"') }
    room.speak(snitch_message)
  end

  desc "Send a message to the campfire chat room about the deploy start"
  task :snitch_begin do
    set :snitch_message, "BEGIN DEPLOY [#{stage.upcase}]: #{ENV['USER']}, #{branch}/#{real_revision[0, 7]} to #{deploy_to}"
    snitch
  end

  desc "Send a message to the campfire chat room about the deploy end"
  task :snitch_end do
    set :snitch_message, "END DEPLOY [#{stage.upcase}]: #{ENV['USER']}, #{branch}/#{real_revision[0, 7]} to #{deploy_to}"
    snitch
  end

  desc "Send a message to the campfire chat roob about the rollback"
  task :snitch_rollback do
    set :snitch_message, "ROLLBACK [#{stage.upcase}]: #{ENV['USER']}, #{latest_revision[0, 7]} to #{previous_revision[0, 7]} on #{deploy_to}"
    snitch
  end
end

before :deploy do
  campfire.snitch_begin unless ENV['QUIET'].to_i > 0
end

after :deploy do
  campfire.snitch_end unless ENV['QUIET'].to_i > 0
end