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

                    
window.onbeforeunload = function (evt) {
  var message = 'Are you sure you want to leave?';
  if (typeof evt == 'undefined') {
    evt = window.event;
  }
  if (evt) {
    evt.returnValue = message;
  }
  return message;
}
http://www.highdots.com/forums/archive/index.php/t-66363.html                
                    This attaches a style attribute to the tr tag, but only on every other tag.

<xsl:template match="my_repeating_item">
<tr>
  <xsl:if test="position() mod 2 != 1">
    <xsl:attribute  name="style">background-color:#dddddd</xsl:attribute>
  </xsl:if>
  <xsl:apply-templates/>
</tr>
<xsl:template>
                
                    Mark all links except ones inside your domein
a:not([href*="mydomain"]) {
	padding-right: 10px;
	background: transparent url("images/aoutside.gif") center right no-repeat;
}

Mark all links that start with 'http://'
a[href^="http"] {
padding-right: 10px;
background-image: url(external.gif);
background-position: right !important;
background-repeat: no-repeat;
}
                 
                    
<cfdirectory action="LIST" directory="d:\www\docs\" name="dirlist">
<cfloop query="dirlist">
	<cfset outSize = dirlist.size / 1000>
	<a href="docs/#dirlist.name#" target="_blank">#dirlist.name#</a> 
	(#NumberFormat(outSize)# kB, 
	#lsdateformat(dirlist.dateLastModified, 'dddd d mmmm yyyy')#)
</cfloop>
                
                    
REReplaceNoCase(string,"<[^>]*>","","ALL")
                
                    PHP function Singleton allows you holding exactly one object of a class in memory. If an object of a given class doesn't exist, Singleton will create and store a new one in static array singleton. It then (and otherwise) will return a reference to it.

Adding an optional ID allows holding more than one object a class. Assigned ID will distinguish array keys.

/**
 * Singleton Repository
 * @param string $class PHP Class Name
 * @param string $id Optional Object ID
 * @return reference Reference to existing Object
 */
function &Singleton($class, $id='') {
  static $singleton = array();
  if (!array_key_exists($class.$id, $singleton))
    $singleton[$class.$id] = &new $class();
  $reference = &$singleton[$class.$id];
  return $reference;
}

Use like this:
[edit] I'm sorry there was a mistake in the first exmaple for three days or so. Fixed.
# first call: create object
$site_user=&Singleton('Student');
$site_user->Drink_Beer(5);

# second call: get a reference
$current_user=&Singleton('Student');
echo $current_user->Show_Beers_Counter();
#will be 5

#Two different objects
$one=&Singleton('Some_Class','one');
$two=&Singleton('Some_Class','two');

Works fine with PHP4, not tested on PHP5                
                    I create a batch file (w.bat) containing just
wget -krmnp %1

Then I call
C:\>w [what-ever-url]
                
                    Current python for series 60 (version 1) doesn't support graphics drawing on screen. But it still allows you to open an image file or other content file using external content handler. Here is the short and shorter versions to demonstrate.

# this version wait for external app to exit, then it continue.
import e32
lock = e32.Ao_lock()
handler = appuifw.Content_handler(lock.signal)
hander.open(filename)  # eg. an image file
lock.wait()	# wait for lock.signal to unlock

# this is a short, one-line version which doesn't wait
appuifw.Content_handler().open(filename)
                
                    
import shutil
shutil.copyfile(source, destination)
                
                    Python for series 60 enables many fun bluetooth stuff.
from socket import *
a = '00:10:60:ab:25:6f'
bt_obex_discover(a)	# found at port 3
f = u'C:\\Nokia\\Startermonlog.txt'
bt_obex_send_file(a, 3, f)