Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Kenny http://standsolid.com

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Active Record to_hash

With this mix-in, you can have nice "to_hash" methods on your active record objects.

I find it good for programming JSON apps.

In lib/ar_hashing.rb
module ActiveRecordHashing
  def to_hash
      Hash[*self.map{ |m| [m.id, m]}.flatten]               
  end
end


and in config/environment.rb
require 'ar_hashing'

class ActiveRecord::Associations::AssociationCollection
  include ActiveRecordHashing
end

Sanitize runaway Z indexes!

This is a function I wrote to sanitize zIndexes of a list of elements that you may continually are bringing to the top of a page. This function goes through HTML Elements and makes all the numbers as low as can be without affecting ordering.

Feel free to make suggestions or to use this code how you'd like.

One condition, please just tell me if you're using it, and if you have ideas for improvement, let me know
kenny[@t ]]]standsolid.com

function sanitizeZ(elements){

	function sortByZIndex(a, b){
		return a[1] - b[1];
	}

	var tempZArray = new Array();
	for(i in elements)
		tempZArray.push([i, elements[i].style.zIndex]);

	tempZArray.sort(sortByZIndex);

	for(i in tempZArray)
		elements[ tempZArray[i][0] ].style ['zIndex'] = i;

}
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS