MPOV http://mpov.timmorgan.org occasional posts about programming, tech, and the dreaded etcetera posterous.com Fri, 07 Oct 2011 21:50:00 -0700 Midnight and Still Hacking http://mpov.timmorgan.org/midnight-and-still-hacking http://mpov.timmorgan.org/midnight-and-still-hacking

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Fri, 07 Oct 2011 20:01:00 -0700 Hacking Well Underway http://mpov.timmorgan.org/hacking-well-underway http://mpov.timmorgan.org/hacking-well-underway

The Tulsa Hackathon is steaming ahead. The night is still young!

People have gone from standing to sitting, staring intently at backlit screens and making things happen.

Here are some more pics...

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Fri, 07 Oct 2011 18:17:00 -0700 Tulsa Hackathon Kick-off http://mpov.timmorgan.org/tulsa-hackathon-kick-off http://mpov.timmorgan.org/tulsa-hackathon-kick-off

So far the Tulsa Hackathon, an all-night programming drive benefiting needy Tulsa non-profits, is going underway and going well.

We had an excellent catered meal, project presentations were made, and teams have been formed. People seem to be figuring out team member responsibilities and getting started on the various projects.

I'll write a couple more blog posts as the night progresses. Here are pics thus far:

 

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Tue, 13 Sep 2011 13:28:00 -0700 Robots Chatting With Other Robots http://mpov.timmorgan.org/robots-chatting-with-other-robots http://mpov.timmorgan.org/robots-chatting-with-other-robots

I wanted my own Campfire-style web chat room, so I created on with node.js and socket.io that runs on Heroku. Robot images are thanks to robohash.org.

Enjoy. github.com/seven1m/robots-chatting-with-other-robots

Robot_chat

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Mon, 11 Jul 2011 21:56:00 -0700 New Blog About Church Software http://mpov.timmorgan.org/new-blog-about-church-software http://mpov.timmorgan.org/new-blog-about-church-software Oh Good Lord in heaven, forgive me: I've started a new blog.

Many of you know I've long had a passion for churches and the software they use. I have plans to challenge the notion of what good church software should be doing. I have ideas for making better tools to aid management, shepherding and engagement.

I want desperately to sit down and just start hacking on a new product, but the older and wiser part of me (I did just turn 30 this year, you know) understands that I should have a plan, or at least, you know, a clue about what I'm going to do.

I hope to make the blog a place where I publicly share my ideas and opinions and get my assumptions tested a bit. I don't pretend to know everything about making great church software, but I like to think I am in a unique position, being both a long-time, committed volunteer in a strong church, a decent engineer, and a geek who can communicate (maybe :-).

So, lacking further ado, I present to you: Church.IO

If you're a church volunteer, minister, or geek, please stay tuned and let me know your thoughts. And subscribe!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Tue, 21 Jun 2011 20:05:00 -0700 jQuery Template Attribute Language http://mpov.timmorgan.org/jquery-template-attribute-language http://mpov.timmorgan.org/jquery-template-attribute-language

Introducing jqtal, my tiny jQuery plugin that provides a different way of doing client side HTML templating.

jqtal is different because it is a part of and lives alongside the HTML itself. An example might help:

Example

The plugin uses HTML5 data- attributes to embed data necessary for content insertion. Whereas in a normal template language, you might have something like:

<input name="first_name" value="{{ person.first_name }}"/>

...in jqtal, you do this instead:

<input name="first_name" data-val="first_name"/>

Now isn't that pretty!!!?

I'll leave explanation of all the syntax to the fairly extensive README. Go check it out.

Of course, there's nothing new under the sun, and indeed this idea is stolen shamelessly from Zope's TAL (Template Attribute Language) that I used back in the day. In fact, it was one of the few things I actually liked about Zope.

I hope you enjoy it too!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Wed, 27 Apr 2011 08:01:00 -0700 Backbone.js Talk at TulsaWebDevs May Meeting http://mpov.timmorgan.org/backbonejs-talk-at-tulsawebdevs-may-meeting http://mpov.timmorgan.org/backbonejs-talk-at-tulsawebdevs-may-meeting

Hey friends, I wanted to let you know I will be giving a presentation on Backbone.js at the next TulsaWebDevs meet-up.

For any of you using more than the tiniest amount of JavaScript in your web-based applications, Backbone.js may be something to consider. Backbone brings structure and organization to the client-side that we've long had in MVC frameworks on the server. Here are some benefits:
  • Stores data in specialized data "models" instead of directly on the DOM.
  • "Views" give you good separation of presentation from the data layer.
  • "Controllers" map url hash fragments to discreet actions.
  • Very lightweight, less than 10kb.
  • Doesn't assume much about your UI or your backend data store.
I'll be walking through a sample app and demonstrating use with Rails as a backend (or you can be easily use the server framework of your choice). I'll also give an overview of Underscore.js, a related product of the guys at DocumentCloud, used within Backbone.

You do not have to be a JavaScript whiz kid to need something like Backbone. If your last bit of JavaScript reminded you of a dish from Spaghetti Warehouse, then Backbone may be for you!

TulsaWebDevs next meeting will be on Monday, May 9th at the Tulsa Collaboratorium at 6pm. Hope to see you there!

Update: The meeting was awesome last night -- our largest meeting to date -- 14 people! Surprisingly, I think most people enjoyed my presentation and incoherent rambling.

You can view the source code for Crk and my Backbone.js slides.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Sat, 23 Apr 2011 21:30:00 -0700 Red Dirt Ruby Conference II http://mpov.timmorgan.org/red-dirt-ruby-conference-ii http://mpov.timmorgan.org/red-dirt-ruby-conference-ii

Red Dirt Ruby Conference in nearby Oklahoma City was even better this year than last, and that's saying a lot.

The format of RDRC is unlike any other conference I've attended. The key difference: each speaker (excepting keynote speakers) only talks for 18 minutes and that's it.

Speakers are grouped, four at a time, into a theme. This year's themes (for day one, which is all I was able to attend) were Ruby Implementations, Rails 3 Extensions, Rails Redux, and JavaScript. So in all, I saw 16 presentations in a single day, plus keynotes!

For us with A.D.D. fueling our disorder with wifi-enabled laptops at hand, coercing presenters to condense their subject matter down to a mere 18 minutes is like switching from a charter bus to high-speed rail -- you get to the destination considerably faster. As @JEG2 put it, if a speaker can't get to the point in 18 minutes, then they won't in an hour either.

Keynote speaker Aaron Patterson (@tenderlove) gave an entertaining and honest look into the core of Rails development, and the challenges that go with it. I don't envy his position on the core team.

Dr. Nic Williams (@drnic) gave a compelling call to action for people to join or start Ruby user groups in their communities. Dr. Nic's style is disarming and delightful alternating with hysterical and off-the-wall. Looking around the room, I saw few if any laptops open during his speech.

The best of the 18-minute talks were about alternative Ruby implementations Rubinius and MacRuby, Rails plugins OmniAuth, Haml and Sass, and finally JavaScript alternative CoffeeScript. But by far the best regular talk was from Jeff Casimir, titled "Fat Models Aren't Enough." Jeff's speaking style was engaging and provocative -- so much that he received more than one middle finger from the audience! But it was all in good fun, and that brings me to my most favorite part of the conference...

The fun. RDRC is upbeat, energetic, and just plain fun. People are just friendlier in Oklahoma than some other places I've been (even if those same people came from the other places, it seems). RDRC makes me proud to be an Okie.

After the day was done, many of the conference goers packed into a hotel suite and started hacking. This was the icing on the cake for me, because I met many amazing people who do creative work everyday. Inspiring stuff.

Thanks to James Edward Gray II and his wife Dana, and to the army of people I'm sure it took to pull this off. See you guys next year!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Wed, 13 Apr 2011 14:03:59 -0700 Auto-Compile SASS with Jammit http://mpov.timmorgan.org/auto-compile-sass-with-jammit http://mpov.timmorgan.org/auto-compile-sass-with-jammit I won't bother explaining to my regular readers what these two things are. If you need this, then you know... ;-)

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
# hack to auto compile sass when Jammit runs in Dev/Test mode

require 'haml/util'
require 'sass/engine'

module Jammit
  module Helper
    SASS_TIMESTAMPS = {}

    def include_stylesheets_with_sass(*packages)
      unless Rails.env.production?
        paths = Dir[Rails.root.join('public/stylesheets/*.scss')].select do |path|
          next if path =~ %r{/_[^/]+$} # skip partials
          t = File.mtime(path)
          if SASS_TIMESTAMPS[path] == t
            false
          else
            SASS_TIMESTAMPS[path] = t
          end
        end
        paths.each do |path|
          Rails.logger.info("Compiling #{path} with SASS.")
          engine = Sass::Engine.new(
            File.read(path),
            :load_paths => [Rails.root.join('public/stylesheets')],
            :cache => false,
            :syntax => :scss
          )
          File.open(path.sub(/scss$/, 'css'), 'w') { |f| f.write(engine.render) }
        end
      end
      include_stylesheets_without_sass(*packages)
    end

    alias_method_chain :include_stylesheets, :sass
  end
end

I know that both SASS and Compass can be setup to "watch" a directory and auto-compile when files are changed, but it seemed a waste to me to have another thing I have to remember to launch.

This hack piggybacks on Jammit's include_stylesheets helper method and compiles and .scss files in the public/stylesheets directory if they've changed since last time.

I hope this helps someone.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Wed, 06 Apr 2011 18:54:57 -0700 David Brady Screencast with James Edward Gray II http://mpov.timmorgan.org/david-brady-screencast-with-james-edward-gray http://mpov.timmorgan.org/david-brady-screencast-with-james-edward-gray Just got done watching this excellent discussion of Ruby hashes, associative arrays, testing, and Ruby culture.

James is an excellent force of enlightenment and encouragement in our little community, and I'm proud that he's also an Okie. Go watch this video.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Tue, 05 Apr 2011 13:30:14 -0700 Hanlon's razor http://mpov.timmorgan.org/hanlons-razor http://mpov.timmorgan.org/hanlons-razor Never attribute to malice that which is adequately explained by stupidity.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Fri, 18 Mar 2011 15:20:00 -0700 EC2 = Everything Cleared 2Day (FIXED) http://mpov.timmorgan.org/ec2-everything-cleared-2day http://mpov.timmorgan.org/ec2-everything-cleared-2day

I created a free micro instance on Amazon EC2 a few weeks ago. Today I remembered it and thought I would tinker around a little, only to find out that when I logged into AWS console, I had to "re-activate" my account using a phone number. Hmmm, that's weird. I distinctly remember doing that two weeks ago. So I jumped through the hoops and got logged in again to discover that my instance was gone, my security group was gone, and my elastic ip was gone. Gone. No trace whatsoever.

This gives me the willies. Luckily, I wasn't yet using the EC2 instance when it just up and vanished, but I doubt that Amazon knew that. What's to make me believe it wouldn't happen again?

I think I might stick with Rackspace for now.

PS and yes, I am logged in with the right account -- I verified against the confirmation email I got when I signed up.

Update: Ahhh... found the cause, and the solution! I posted on the Amazon support forum, and it turns out that it's possible to have what is called a "MASE" problem, which stands for "Multiple Account, Same Email." WTF!!

Indeed, I logged out, used the SAME email address, but a different password, and was able to log in with my other account and see my running instance.

OK, Amazon that isn't so bad I guess. Except, it's weird. And how in the world did I get another account?

 

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Thu, 24 Feb 2011 17:17:18 -0800 Winexe on Ubuntu http://mpov.timmorgan.org/winexe-on-ubuntu http://mpov.timmorgan.org/winexe-on-ubuntu If you're running a Linux desktop in an otherwise Windows environment, winexe may be something you'll enjoy.

Winexe allows you to execute commands from a Linux machine on a remote Windows machine, as if you're sitting at the Windows command prompt. Think of the possibilities!

Recently, I found a way to get it to compile on my beloved Ubuntu Maverick (it broke when I dist-upgraded for some reason), and I thought I'd share. Winexe doesn't have a Debian package that I'm aware of, and getting documentation on how to make it compile is spotty at best. The official SF page might be the obvious destination to find out how to get it, but alas, it no workie.

Fortunately, the peeps at Zenoss got your back. Here's the scoop:

(The patch is necessary to fix a tiny typo in winexe/service.c -- if it doesn't apply properly, chances are good the typo has been fixed since this blog post.)

Once you've compiled, now for some fun!

Never again must you VNC into a Windows box just to restart a service! I even have a script that remotely executes a "git pull" and then restarts all the relevant Windows services. Poor man's deploy FTW!!1

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Tue, 19 Oct 2010 15:52:00 -0700 Use a Proc with ActiveRecords' default_scope Method http://mpov.timmorgan.org/use-a-proc-with-activerecords-defaultscope-me http://mpov.timmorgan.org/use-a-proc-with-activerecords-defaultscope-me

Today, my small patch to Rails was applied by the core team. This is only my second contribution to Rails, so I'm fairly stoked about it being accepted.

This will allow you to pass a block to the default_scope method in ActiveRecord. It doesn't sound like much, but opens up some wonderful possibilities.

First, a review of what default_scope does:

1
2
3
4
5
6
7
8
9
10
11
12
class Person < ActiveRecord::Base
  default_scope where(:deleted => false)
end

Person.all
# => SELECT "people".* FROM "people" WHERE ("people"."deleted" = 'f')

Person.unscoped { Person.all }
# => SELECT "people".* FROM "people"

Person.unscoped { Person.where(:deleted => true) }
# => SELECT "people".* FROM "people" WHERE ("people"."deleted" = 't')

The first call to Person.all applies the default scope and adds a where clause that returns only non-deleted folks.

The next two calls are passed through the unscoped { } block so that the default scope isn't applied.

Great! Using default_scope keeps me from having to specify a common condition over and over again on every (or nearly every) query.

What else can we use this for?

Well, let's say you have an app with different customers. Each customer needs to have the illusion of operating in their own "database" while your server has just one.

Each customer has their own subdomain, say foo.example.com or bar.example.com. Depending on the hostname, let's scope our queries to that particular customer.

1
2
3
4
5
6
7
8
class Person < ActiveRecord::Base
  cattr_accessor :current_site_id
  default_scope where(:site_id => Person.current_site_id)
end

Person.current_site_id = 1
Person.all
# => SELECT "people".* FROM "people" WHERE ("people"."site_id" IS NULL)

Oops! This doesn't work because the call to where() is made at the time the class is created. Instead, we need the where() to be called each time a query is made.

With named_scope, you can pass a lambda/proc, but with default_scope, you cannot. Until now that is!

With my wonderful, 6-line patch (plus tests of course), you can now pass a proc to default_scope:

1
2
3
4
5
6
7
8
9
10
11
12
class Person < ActiveRecord::Base
  cattr_accessor :current_site_id
  default_scope lambda { where(:site_id => Person.current_site_id) }
end

Person.current_site_id = 1
Person.all
# => SELECT "people".* FROM "people" WHERE ("people"."site_id" = 1)

Person.current_site_id = 2
Person.all
# => SELECT "people".* FROM "people" WHERE ("people"."site_id" = 2)

This technique is exactly what my project OneBody uses to scope customer "sites" to their specific site_id based on hostname. The Person.current_site_id bit is actually called inside the ApplicationController once the hostname is determined.

It won't change the world, but being able to contribute this small bit of code back to the framework I love and use everyday feels great.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Sun, 09 May 2010 20:02:00 -0700 Use rsync instead of cp http://mpov.timmorgan.org/use-rsync-instead-of-cp http://mpov.timmorgan.org/use-rsync-instead-of-cp

I tend to use rsync when others would typically use a simple cp for copying files. A few reasons:

  1. It can be canceled in the middle, and resumed later.
  2. It can show a progress bar that (while not perfect) is great for large files or lots of files.
  3. It will only copy the changed files and won't clobber already existing directories of files at the target.

rsync is available on Linux, Mac, and there's a binary somewhere on teh intarwebs for Windows.

To use, you almost always want to pass the -a flag, which stands for "archive" -- basically a convenience flag for -r (recursive), -p (permissions), -t (timestamps), and a few others. I can't think of a time I haven't used -a when using rsync.

Following that, basic usage looks like this:

rsync -a source destination

The other thing to remember when using rsync is that it's picky with slashes; if you put a trailing lash on a path, then rsync takes that to mean you want to copy the contents of that path. If, on the other hand, you leave off the slash, it will copy the path and its contents. A few examples will help:

# This will copy the stuff directory (and its contents) to the documents directory
rsync -a /home/tim/stuff /home/tim/documents

# This will copy only the contents of stuff to the documents directory
rsync -a /home/tim/stuff/ home/tim/documents

Some other handy arguments:

  • --stats
  • --progress

So, to put it all together:

rsync -a --stats --progress /home/tim/stuff /home/tim/documents

And, better yet, rsync can work over ssh (if it's installed on both hosts). Just put an ssh host on the front of either path:

rsync -a --stats --progress /home/tim/stuff tim@foobar.example.com:/home/tim/

or

rsync -a --stats --progress tim@foobar.example.com:/home/tim/stuff /home/tim/

So, there you have it. rsync can do tons more stuff, but this is a great start. If this is all you learn of rsync, you will be that much better off.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Thu, 06 May 2010 12:18:08 -0700 Red Dirt Ruby Conf http://mpov.timmorgan.org/red-dirt-ruby-conf http://mpov.timmorgan.org/red-dirt-ruby-conf

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Sat, 01 May 2010 22:15:29 -0700 MBP Upgrade http://mpov.timmorgan.org/mbp-upgrade http://mpov.timmorgan.org/mbp-upgrade My 1st generation Macbook Pro is starting to show its age, but tonight I used my birthday money in an effort at rejuvenation.

First, a new Seagate hard drive. 500gb, 7200rpm, $99 at Best Buy. It took about an hour to get my machine apart, with all its tiny screws, get the new drive in, and put it back together.

Next, I said good-bye to Mac OS X. I installed the brand new Ubuntu 10.04 LTS, and man it screams on this machine. I'm not sure if it's Linux, the new drive, or a combination. This machine has new life!

Some pictures of the operation are below:

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Tue, 09 Mar 2010 18:51:50 -0800 Whiteboard Icons http://mpov.timmorgan.org/whiteboard-icons http://mpov.timmorgan.org/whiteboard-icons
Bulb

Back in 2005, I uploaded a bunch of crude little pictures to my Flickr account and called them my "Whiteboard Icons" set. Hundreds of people have, over the years, found them to be useful on their blogs, flowcharts, and more.

Today, I finally added a couple new icons to the set (1, 2). Only took me five years.

Enjoy.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Sun, 07 Mar 2010 18:34:29 -0800 csv2wufoo.com http://mpov.timmorgan.org/csv2wufoocom http://mpov.timmorgan.org/csv2wufoocom

csv2wufoo.com is a little side project I wrote using Sinatra, my WufooParty lib, and James Edward Gray's FasterCSV lib.

After the tenth time my wife asked me to write a one-off script to import data into her Wufoo form, I decided to generalize it a bit, slap a Sinatra app around it, and give it a domain name (well, there was a little more to it than that, but ya know...)

It hasn't quite been battle tested yet, but hopefully it will be useful to someone.

We love Wufoo at our church and use it almost daily for all sorts of things. Gathering submissions is only one small trick in its bag of 'em -- Wufoo's reporting makes it a really good platform for visualizing flattened data, among other things. Staff in our church use Wufoo in ways they should probably be using Excel, but Wufoo makes it so much easier.

With csv2wufoo, we should now have a better way of getting data into the system.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan
Tue, 26 Jan 2010 21:29:15 -0800 FacebookParty http://mpov.timmorgan.org/facebookparty http://mpov.timmorgan.org/facebookparty I wanted to understand the Facebook REST API better, and decided I needed a simple wrapper for it. HTTParty to the rescue again!

FacebookParty (rdoc) is along the same lines as my other _party style api wrappers. I can't take much credit for it though, since HTTParty is what makes this stuff so easy. Slap a pretty class on an api endpoint, and the rest is cake. And cake goes good with parties.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1335873/tim_large.jpg http://posterous.com/users/KPdg8xV4vT Tim Morgan Tim Tim Morgan