DRY jQuery to toggle elements

Friday, 4 September 2009

I always have links that will hide something on a page. something like:

Hot Sheet
Uploaded with plasq’s Skitch!

This is how I have done it in the past:

  $("#rollup").click( function() {
    $("#new_capacity_form").slideToggle();
  });

But by adding a rel value to your links, you can do it smarter

  $('#rollup').click( function(){
    var what = $(this).attr('rel');
    $('#' + what ).slideToggle();
  });

In my views, I add this link

  link_to "cancel", "#", :id => 'rollup', :rel => 'new_capacity_form'

vois la! now I am able to rollup all over my site with only one line of jQuery.


don’t eat yellow snow leopards

Monday, 13 July 2009

Thanks to my ADC membership, I was able to install OSX 10.6 -the new Operating System from Apple. I would be lying if i said the upgrade was perfect; but hey, this thing is still in Beta. However, Windows users should feel right at home. The following is a list of stuff that is a bit flakey.

Works

  • Adium
  • VMware Fusion
  • Tweetie
  • NewsFire

Doesn’t

  • Nambu ( heaps of errors and no solutions )
  • 1Password fix
  • Textmate… key commands are buggy fix
  • CyberDuck Use the latest alpha
  • ForkLift ( no info! app crashes upon startup )
  • LimeChat ( see RubyCocoa )
  • RubyCocoa

apple script can move all of your windows to main display

Thursday, 4 June 2009

So I just got home from doing a bit of coding at my favorite coffee shop. I probably have 25-30 application windows open right now and as soon as I plug into my external display I will have to readjust all 30 windows. The problem is that when I am just using my MacBook Pro I like to have all of my app’s windows on that display… obviously! But when I come home and plug into my external display I no longer want my windows open in the MacBook Pro’s 15″ display, I want them open on my 24″ display. So for the past year I have manually dragged each application over to my large display. I estimate that I have wasted 4-5 hours in the past couple of months. I will not do the machines work any longer! Enter this script and you will add hours to your life!! I am really surprised that Apple has not addressed this issue.

 
tell application "System Preferences"
	set current pane to pane id "com.apple.preference.displays"
	reveal (first anchor of current pane whose name is "displaysArrangementTab")
	tell application "System Events" to tell process "System Preferences"
		set frontmost to true
		click checkbox "Mirror displays" of group 1 of tab group 1 of front window
	end tell
	set current pane to pane id "com.apple.preference.displays"
	reveal (first anchor of current pane whose name is "displaysArrangementTab")
	tell application "System Events" to tell process "System Preferences"
		set frontmost to true
		click checkbox "Mirror displays" of group 1 of tab group 1 of front window
	end tell
end tell
quit

working with webrat + factory girl

Monday, 11 May 2009

Webrat is a nice driver for your integration testing. I have been using it in place of my controller and view specs. Factory Girl is what you should replace your fixtures with. So . . . . When you are using factories in your webrat integration tests, it is sometimes helpful to do things like this:

Given a customer exists with an id of "12345"

and that translates into a step like this:

Factory.factories.each do |name, factory|
  Given /^an? #{name} exists with an? (.*) of "([^"]*)"$/ do |attr, value|
    Factory(name, attr.gsub(' ', '_') => value)
  end
end

And all of this default behaviour is what you get when you install cucumber and factory girl. But today i ran into a little issue. One of my features needed to use the object that was created by Factory Girl in another step, so i caught the factory object with this addition

Factory.factories.each do |name, factory|
  Given /^an? #{name} exists with an? (.*) of "([^"]*)"$/ do |attr, value|
     ######
    @object = Factory(name, attr.gsub(' ', '_') => value)
  end
end

Now i can use @object in my other steps!

That is all.


where the magic happens

Saturday, 2 May 2009

Think Fast Tank
Global Headquarters


phone

desk

good coffee makes a good programmer

good coffee makes a good programmer


results from startup weekend

Sunday, 26 April 2009

TreadEx
Investor’s Presentation!
blog post on KCStartup page

I had such a fun time! I came up with an idea to connect bicycle messengers with local business owners on Thursday night. I pitched the idea friday night at the Kansas City Startup Weekend ( with a little help from my friends ) and started from scratch on Saturday morning. Sunday night, we presented the idea and launched our site. It was awesome! Here are some highlights:


TreadEx Sunday Afternoon Update from Dan Melton on Vimeo.


TredEx Team Update from Dan Melton on Vimeo.


Help the Bikers Team from Dan Melton on Vimeo.


BookUp made the news

Monday, 13 April 2009

Read more here -> www.unews.com


has_many has many features

Wednesday, 8 April 2009

Not only is `has_many` an excellent way to set up foreign keys ( Person has_many :fingers where fingers represents an Active Record class Finger) but has_many can also define custom relationships. Behold,

class Book < ActiveRecord::Base
  has_many :listings
  has_many :users, :through => :listings
  has_many :active_listings, :class_name => "Listing", :conditions => { :market_status => 1 }
end

.

This way whenever I want to grab all of the active listings that a book has, i can do this:

  @book.active_listings.count

That is all.


Dear Bookstore, screw you. kthxby.

Saturday, 4 April 2009

So on Tuesday of last week I revived an old idea.  I  wanted to create a web app that helps college students trade their textbooks.

Let me explain this idea with an example.

As a student. I want to save as much money as possible. I can do this by not buying my books from the university bookstore. But if I do not buy my books from the bookstore, how then shall i get the required reading material? My solution is to BookUp! So, lets say that I just finished Calculus III and I no longer need my 50lb Calculus book. I go to BookUp, find my Calculus book on the list and then I will create a listing associated with the book. This listing will show the world that I no longer need this book and I wish to give it to a student who does. I could sell it for cash or cashews, it does not matter because BookUp does not assume that much. BookUp is more of a tool to connect students and less of an commerce app. So basically this is a Craig’s List for college textbooks.

Let me know what you internet people think about this idea. . . . And now, in case you missed the link

BookUp


Safari 4 open new link in tab

Sunday, 29 March 2009

I like the new Safari a whole lot. Unfortunately there is no easy way to force Safari to open links in a new Tab. However, with this simple terminal command, the aforementioned annoyance can be laid to rest.

defaults write com.apple.Safari TargetedClicksCreateTabs -bool true

Restart Safari and voila!