MetaSkills.net

How To Clean A Campfire Room Of Uploads

Posted On: August 19th, 2010 by kencollins

For us at work, our uploads to campfire are really transitory. Most of the time they are simple screenshots around a current topic. Every now and then vacation photos or even movies. And the end of the day none of it has value to us as the real value of campfire is our textual transcripts.

This morning after 4 years of campfire, we were real close to our 1GB limit of uploads. Time for a clean up. I found no easy way of automating this, so I turned to the Tinder gem. It has a nice way interface to the campfire api using HTTParty as the backend. I found out that there was no easy way to delete uploads too. So after some good ole fashion DOM inspection and knowing rails application conventions, I found my own interface. Below is a little script I used to clean up our room this morning. It basically loops thru a rooms uploads, 5 at a time, and deletes them. Pausing for a quarter of a second between each so I don't freak out the new 37signals administrator :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

require 'rubygems'
require 'tinder'

class CampfireUploadCleaner
  
  CF_DOMAIN = 'mydomain'
  CF_ROOM   = 'My Room Name'
  CF_TOKEN  = ENV['MY_CF_TOKEN']
  
  def initialize
    @campfire = Tinder::Campfire.new CF_DOMAIN, :token => CF_TOKEN
  end
  
  def room
    @room ||= @campfire.find_room_by_name(CF_ROOM)
  end
  
  def connection
    room.send(:connection)
  end
  
  def delete_uploads
    uploads = room.send(:get,:uploads)['uploads']
    uploads.each do |upload|
      id = upload['id']
      name = upload['name']
      connection.post "/uploads/delete/#{id}?n=0"
      puts "Deleted: [#{id}] #{name}"
      sleep(0.25)
    end
  end
  
  def sweep_uploads
    while room.files.present?
      delete_uploads
    end
  end
  
end

cleaner = CampfireUploadCleaner.new

cleaner.delete_uploads  # => Deletes the top 5 uploads.
cleaner.sweep_uploads   # => Deletes all uploads.

The upload hash actually contains much more than just the id and name of the upload. There is a timestamp, filetype and other attributes. So if you wanted to extend this script, you could. I did not spent a lot of time with it, but I never figured out how to get more than the top 5 uploads too. I'm sure some param hacking would yield some good results.

Tags: campfire, ruby, tinder

The alias_method_chain of Rake - Override Rake Task

Posted On: May 25th, 2010 by kencollins

Rake is cool. It is built so that multiple tasks with the same name run in a reverse defined series. This is great, but sometimes you want to override a task with your own behavior and conditionally call the earlier task. Especially if that task is defined deep somewhere else, like in a rails gem. I have had to solve this problem before in Rake. Awhile back I hacked something up that would totally trump a predefined rake task and allow you to replace it with a new one. Lately while working on the SQL Server adapter, I had a need to method chain some core rails :db namespaced tasks. So once again I googled others work and again resorted to hacking Rake. Below is what I was left with.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Rake::TaskManager.class_eval do
  def alias_task(fq_name)
    new_name = "#{fq_name}:original"
    @tasks[new_name] = @tasks.delete(fq_name)
  end
end

def alias_task(fq_name)
  Rake.application.alias_task(fq_name)
end

def override_task(*args, &block)
  name, params, deps = Rake.application.resolve_args(args.dup)
  fq_name = Rake.application.instance_variable_get(:@scope).dup.push(name).join(':')
  alias_task(fq_name)
  Rake::Task.define_task(*args, &block)
end

It's easy to use, just require it in your Rakefile. In the example below, I was able to programmatically method chain the core rails db:test:purge and only call the original if I needed to. Very cool!

1
2
3
4
5
6
7
8
9
10
11

namespace :db do
  namespace :test do
    override_task :purge => :environment do
      ...
      # To invoke the original task add ":original" to its name
      Rake::Task["db:test:purge:original"].execute
      ...
    end
  end
end

Lastly, thanks to Eugene Bolshakov, John Wood, and Mark Foster whom have tackled this rake problem before. My version above was based on their work, but correctly works with namespaces which was critical for my needs.

Tags:

Git Init XCode Projects

Posted On: February 23rd, 2010 by kencollins

Here is a little ZSH function I have been using for quickly setting up new XCode apps I call tire kickers, little play and learn apps. Being able to track your learning as you go with git.

if [[ -x `which git` ]]; then
  
	function ginit_xcode () {
	  git init
	  echo "\n\n# XCode\nbuild\n*.mode1v3\n*.mode2v3\n*.nib\n*.swp\n\
*.pbxuser\n*.perspective\n*.perspectivev3\n\n# OSX\n.DS_Store\n\n\
# TextMate\n*.tm_build_errors\n\n\n" >> .gitignore
	  git add .gitignore
	  git commit -m "Ignore Xcode stuff."
	  git add .
	  git commit -m "Initial Xcode project."
	}
  
fi

The echo lines puts out a .gitignore file that will look something like this.

# XCode
build
*.mode1v3
*.mode2v3
*.nib
*.swp
*.pbxuser
*.perspective
*.perspectivev3

# OSX
.DS_Store

# TextMate
*.tm_build_errors
Tags: git, xcode

Git & Subversion User Commit Reports

Posted On: February 1st, 2009 by kencollins

Want a list of the users and the number of commits they made? Git makes it really really easy, while I could not find such an easy method on Subversion. Here they are.

Git

git log | git shortlog -n -s

MultiRuby The MacPorts Way. Testing Your Rails Apps With Ruby 1.9

Posted On: January 19th, 2009 by kencollins

Ruby 1.9.1, the stable release, is just around the corner and if your like me, maybe you want to start playing around with it and perhaps test a few projects using 1.9 with edge rails 2.3. If so, and your on a Mac, then perhaps this installation method might appeal to you. I'll break this article up in two parts, the first will be on installing multiple versions of ruby and how to switch between them while the other will be some things I noticed when testing ruby 1.9 with edge rails on my favorite pet project HomeMarks.

Autotestify Brothers and Sisters

Posted On: December 30th, 2008 by kencollins

Based on my previous article Using Autotest For Rails Plugin Development, Brennan Dunn wrote a ZSH function that helps him with his eager rails plugin work. Testing plugins is simply the most fun you will ever have. It's nice to test in isolation and easy to make a plugin test multiple rails versions, etc. Typically plugin testing is very fast to because you are not burdened with excessive tests in a big app that might use it. Just the ones needed to test the plugin. Enjoy this ZSH function.

function autotestify () {
  git clone git://github.com/metaskills/autotest_railsplugin.git
  rm -rf ./autotest_railsplugin/.git
  mv ./autotest_railsplugin ./autotest
}

Using Autotest For Rails Plugin Development

Posted On: September 19th, 2008 by kencollins

I love autotest. I have event posted before how to extend the idea of autotest sounds to a red/green playlist but now that I am taking more time to extract some of my work to plugins, I really wanted autotest to come with me. The problem is that the default autotest mappings do not play with rails conventions, the biggest being that test files for a lib match the name of the lib with _test.rb at the END of the...