Streams of thought by...

This is the (tumble) log by Innerfusion, I'll post various things about code, design, politics, or whatever is interesting at the moment.

10/21/2010
12:23am
14 notes
Comments (View)

Introducing Bam : A simple deployment utility

As a thought about the post that I wrote the other day. I figured why not just turn it into a gem? This would be a good excuse for me to write my first command line gem and also learn all the intricacies involved with it. So without further ado, here it is: bam the easiest, most fastest way to deploy your project! It’s super simple to get going and use too!

Installation

  gem install bam # => you might need sudo here

Usage

  cd into/your/project/root
  bamify
  # it should generate a deploy.bam file, go ahead and open it up and update it
  # do some work on your project
  bam

That’s it! No DSL to learn, a minimal amount of ceremony involved with setting it up, and best of all, the deploy file just involves setting 2 variables at the minimum. Now you to can deploy your recipes, er, I mean your site or project the Emeril Lagasse style with BAM! There’s also some variables to allow you to do some pre deployment tasks and post deployment tasks that are limited to running commands locally, but most of the time I don’t need them and honestly if it gets more complicated than that, just do yourself a favor and use capistrano.

Ok enough talk, show me already!

Alright here’s a basic demo of how it works:

Get the source at http://github.com/vanntastic/bam if you want to fork it. Here’s a quick video of Emeril reminding you how fast and simple your deployments can be:

Posted in: ruby gems deployment rsync bam
10/19/2010
1:29pm
4 notes
Comments (View)

Quick Deployment with Rsync and Ruby

UPDATE, this is now a gem!

As I’ve mentioned before, I’m a huge fan of using rsync for deployment. When working on smaller sites and projects, I find that the other deployment method that I use; capistrano, is a bit of overkill, I rarely, if ever need to rollback revisions or share assets across deployments on simple websites. Since I use git, I can rollback revisions and ignore certain files using .gitignore. With that said, I think that I’ve come up with the most simple and perfect way to deploy small projects. This assumes that you use the following:

  • OSX or any *nix variety OS (haven’t tested it on ubuntu, but I assume this’ll work the same)
  • rsync / ssh
  • git
  • and of course ruby
  • textmate or any other editor that accepts textmate’s bundle snippet system
  1. Add the following snippet to your bundles:
  1. Assign the word deploy for the snippet expansion.
  2. Add a file called deploy.rb to the root of your project, make sure and chmod 755 it.
  3. Type deploy and expand the snippet and fill in your deployment details.
  4. Once you are ready, just run ./deploy.rb in the terminal.

The great thing about this is that you ignore files on deployment simply by using .gitignore and rollback using git. Why attempt to re-do those things when git does such a good job of it itself? Enjoy!

Posted in: rsync ruby deployment git
9/15/2010
12:36pm
5 notes
Comments (View)

Phusion Passenger 3.0.0 public beta 1 is out! – Phusion Corporate Blog →

Can’t wait to use it.

Posted in: passenger ruby rails
7/1/2010
12:24pm
0 notes
Comments (View)

Phusion Passenger Lite can listen on a Unix domain socket instead of a TCP socket, just like Thin and Unicorn. In reverse proxy setups this can yield much higher performance than TCP sockets.

— This can potentially be a big deal…via The Road to Passenger 3: Technology Preview 3 – Closing the gap between development and production & rethinking the word “easy” – Phusion Corporate Blog

Posted in: ruby rails web servers passenger unix
1/6/2010
3:21pm
1 note
Comments (View)

Quick convenience methods for String

I’m wondering why this isn’t in Core?

  # should be in Ruby Core
  class String
    # grab the first character
    def first
      self[0..0]
    end

    # grab the last character
    def last
      self[(self.length-1)..(self.length-1)]
    end
  end

Grab the gist

Posted in: ruby snippets
11/17/2009
3:51pm
0 notes
Comments (View)

Get the current branch in a git repo

Ever need to get the current branch name in a ruby app?

b = `git branch`.split("\n").delete_if { |i| i.first != "*" }
b.first.gsub("* ","")

Or maybe you might want to put it into ~/.irbrc:

def branch
   b = `git branch`.split("\n").delete_if { |i| i.first != "*" }
   b.first.gsub("* ","")
end

Posted in: snippets ruby git
11/4/2009
6:49pm
0 notes
Comments (View)

ActionMailer woes with gmail

NOTE: that this only applies to Rails versions less than 2.3 (< 2.2.x), Rails

I’ve been having issues lately working with Gmail’s SMTP servers and older Rails apps. Fortunately I found the fix in the form of a plugin here : http://douglasfshearer.com/blog/gmail-smtp-with-ruby-on-rails-and-actionmailer

However, I was still getting errors in that looked like:

  ArgumentError (wrong number of arguments (3 for 2)):
      /vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb:33:in `check_auth_args'
      /vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb:33:in `do_tls_start'
      /vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb:18:in `send'
      /vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb:18:in `start'
      /vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb:10:in `start'
      /vendor/plugins/action_mailer_optional_tls/lib/action_mailer_tls.rb:9:in `perform_delivery_smtp'

Browsing through the comments in that link mentioned above reveals that you must update a call to check_auth_args at about line 33, so here’s what you do:

  # go to line 33 and change:
  check_auth_args user, secret, authtype if user or secret
  # to this (remove authtype):
  check_auth_args user, secret if user or secret

It’s a quick hack I know…, but sometimes you just need to get something working so that you can get on with your day :/

Posted in: ruby rails gmail
8/31/2009
4:00am
0 notes
Comments (View)

Less is more

I’m a big fan of the less command, which allows you to read files similar to vim, except without the editing capability. I use it a ton to quickly scan through text files and even programmatically push text through it. When I use script/console, I sometimes find it handy to use less as a quick way to view a bunch of content or even a nice way to output arrays. Simply add the following method to ~/.irbrc :

    # hook for the system's less command, allows you to pass in arrays too!
    # EX : 
    #     less "A bunch of content"
    #     less %w(1 2 3) 
    #     less [1,2,3]
    def less(content)
      content = content.join("\n") if content.is_a?(Array)
      system('echo "' << content << '"|less')
    end

fork the gist

Posted in: snippets code ruby rails
8/5/2009
1:55pm
0 notes
Comments (View)

Git and irbrc sitting in a tree…

Using git and rails together? Need some git love in your console? Here’s a list of command git commands that I often use, abstracted into a method, just throw this in ~/.irbrc :

  # git hook
  def git(*args)
    if args.length == 1
      # EX : git :st 
      #      git "push origin master"
      cmd = "git #{args.first.to_s}"
    elsif args.length > 1
      # EX : git :st, :origin, :master
      #      git :push, :origin
      cmd = args.first.to_s
      args.delete_at(0)
      arg = args.join(" ")
      cmd = "git #{cmd} #{arg}"
    elsif args.blank?
      cmd = "git [*cmd] or git.[st|ci|push|config]"
    end
    
    cmd.instance_eval do
      
      # git.st
      def st
        system("git st")
      end
      
      # git.ci 'msg'
      def ci(msg)
        system("git add .;git commit -m '#{msg}'")
      end
      
      # git.push 'args' 
      def push(args=nil)
        args.nil? ? system("git push") : system("git push #{args}")
      end
      
      # git.url
      def url
        system 'cat .git/config | grep url'
      end
      
      # git.config
      def config
        system 'vi .git/config'
      end
      
    end
    
    args.blank? ? cmd : system(cmd)
  end

Now you can do things like:

  # git status
  >> git.st 
  >> git :st
 
  # git push 'msg'
  >> git.push 'msg'
  >> git :push 'msg'

  # you can even modify the config in vi from the console
  >> git.config

Go ahead and fork the gist at : http://gist.github.com/162857

Posted in: git rails ruby snippets