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

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

Recommended order links css rules

   1  
   2   a:link {color: blue;}        /* specificity = 1,1 */
   3   a:active {color: red;}       /* specificity = 1,1 */
   4   a:hover {color: magenta;}    /* specificity = 1,1 */
   5   a:visited {color: purple;}   /* specificity = 1,1 */

Default Sort Order For Rails models

// provide a default sort order in case an order by clause isn't defined in the find clause
// Place this code somewhere in your model's class file.

   1  
   2          def self.find(*args)
   3            order_arg = args.collect do |arg|
   4              if arg.kind_of? Hash 
   5                if arg.keys[0] == :order
   6                  arg
   7                end
   8              end
   9            end
  10  
  11            if order_arg.compact.empty?
  12              args << {:order=>"place order by clause here e.g. 'name asc'"}
  13            end
  14            
  15            super
  16          end

Return ordered list of near match items based on tag matches

// description of your code here

   1  
   2  select t2.dbid, t2.tag, count(t2.dbid) as match_count from tags as t1, tags as t2 where t1.dbid = '105319' and t2.tag = t1.tag and t1.dbid != t2.dbid GROUP BY t2.dbid 1 ORDER BY match_count;
   3  

Ordered dictionary

This is part of the pythonutils package.
   1  
   2  od = OrderedDict()
   3  od['key1'] = 'value 1'
   4  od['key2'] = 'value 2'
   5  print od
   6  {'key1': 'value 1', 'key2': 'value 2'}
   7  
   8  print od.sequence
   9  ['key1', 'key2']
  10  od.sequence.reverse()
  11  print od
  12  {'key2': 'value 2', 'key1': 'value 1'}
  13  print od.sequence
  14  ['key2', 'key1']

This dict keeps its insertion order and you can do other
manipulations. See more details here
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS