DZone 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

Snippets

  • submit to reddit

Recent Snippets

                    ([12][0-9][0-9](0[1-9]|1[0-2])(0[1-9]|[13456789][0-9]|2[023456789AB])[0-9][0-9][0-9][0-9][0-9][0-9])([0-9][0-9])

cf http://u-blog.net/dda/note/11 pour les explications
(et reste à valider la clé de contrôle)                
                    The "cvs status" command is practically useless, given the amount of stuff it spews out. So I do the following to find out the status of my local working copy. This shows all updated, added, or deleted files, as well as those CVS know nothing about (and which perhaps should be added):

cvs status 2>&1 | egrep "(^\? |Status: )" | grep -v Up-to-date
                
                    A neat trick in iTunes 4.5 that changes the little arrows next to each artist/album/title to search your library for that string instead of the iTunes Music Store.

defaults write com.apple.iTunes invertStoreLinks -bool YES
                
                    Sometimes you want to log generated SQL selectively, so popping -DEOAdaptorDebugEnabled=true on the command line of your app is verbose overkill. Here's how you can selectively enable and disable SQL logging:

NSLog.allowDebugLoggingForGroups(0x10000L);
// Do something that roundtrips the DB, like editingContext.saveChanges().
NSLog.refuseDebugLoggingForGroups(0x10000L);
                
                    
(new DOMConfigurator()).doConfigure(resourceManager().inputStreamForResourceNamed("log4j.xml", "app", null), LogManager.getLoggerRepository());
                
                    
NSLog.debug.setAllowedDebugLevel(NSLog.DebugLevelDetailed);
NSLog.allowDebugLoggingForGroups(NSLog.DebugGroupRules);
                
                    
# -*- coding: utf-8 -*-

Add this line at the beginning of your code. Python won't complain anymore about non-ascii characters in your code.                
                    Sometimes I find it useful having an overview about the keys an array has; PHP function Get_Array_Keys_UL will create an nested HTML Unordered List string of the keys of a given array. Makes best sense with literal keys, e.g. $_POST:
/**
 * Creates recursively a nested HTML UL of array keys.
 * @param array $array Array
 * @return string Nested UL string
 */
function Get_Array_Keys_UL($array=array()) {
 $recursion=__FUNCTION__;
 if (empty($array)) return '';
 $out='<ul>'."\n";
 foreach ($array as $key => $elem)
   $out .= '<li>'.$key.$recursion($elem).'</li>'."\n";
 $out .= '</ul>'."\n";  
 return $out;
}

Use like this:
$ul=Get_Array_Keys_UL($_POST);
echo $ul;
                
                    XoloX's cute function directoryToArray($directory, $recursive) will become "real recursive" by adding the recursion's directory content to array $array_items:
if($recursive) { 
  #directoryToArray($directory. "/" . $file, true); 
  $array_items=array_merge($array_items,directoryToArray($directory. "/" . $file, $recursive));
} 
                
                    class A
  def A.inherited(clazz)
    puts "Hey, #{clazz} is subclassing me"
  end
end
 
class B < A; end
 
 
Produces:
 
$ ruby x.rb
Hey, B is subclassing me