The Code Cookbook - Allhttp://code-cookbook.com/The Code Cookbook - Freshly served code snippets Set Your Site's Apple Touch Icon http://code-cookbook.com/entry/86/set-your-sites-apple-touch-icon Apple?s mobile devices are taking over the world. iPhones and iPod Touches are all over the place. You can set an Apple Touch Icon for your website just like you can set a favorite icon.

<link rel="apple-touch-icon" href="/apple-touch-icon.png"/>
2009-07-17 07:12:39 http://code-cookbook.com/entry/86/set-your-sites-apple-touch-icon
[RUBY] Print a Fibonacci series http://code-cookbook.com/entry/85/ruby-print-a-fibonacci-series- Simple Fibonacci sequence printer, enjoy!

def fib_max(max)
     num1, num2 = 1, 1
     while num1 <= max
          yield num1
          num1, num2 = num2, num1 + num2
     end
end
puts "What number would you like the Fibonacci sequence to go up to?"
fib_max(gets.chomp.to_i) {|f| print f, " "}
2009-06-17 16:52:17 http://code-cookbook.com/entry/85/ruby-print-a-fibonacci-series-
Wordpress Enable Adsense Shortcode http://code-cookbook.com/entry/84/wordpress-enable-adsense-shortcode Wordpress allows developers and theme creators to write functions that allow the user to use shortcode, i.e., [adsense]. This kind of "pseudo" code makes it easy for end users to insert elements where they would like without knowing about coding. Knowing that we can create shortcodes, we can create one to insert a Google Adsense ad anywhere in our theme.

function showads() {  
     	return '<div id="adsense"><script type="text/javascript"><!--  
     	google_ad_client = "pub-XXXXXXXXXXXXXX";  
    	 google_ad_slot = "4668915978";  
    	 google_ad_width = 468;  
    	 google_ad_height = 60;  
    	 //-->  
		 </script>  
 
		 <script type="text/javascript"  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">  
 		 </script></div>';  
 }  
 
 add_shortcode('adsense', 'showads');
2009-04-29 08:37:33 http://code-cookbook.com/entry/84/wordpress-enable-adsense-shortcode
C# Excel Column Number to Name and Vice Versa http://code-cookbook.com/entry/82/c-excel-column-number-to-name-and-vice-versa Convert a column number to a column name and vice versa in an Excel spreadsheet.

private int colNameToNum(final String colName)
{
        int result  = 0;
        String  lcColName   = colName.toLowerCase();
        for (int ctr = 0; ctr < lcColName.length(); ++ ctr)
            result  = (result * 26) + (lcColName.charAt(ctr) - 'a' + 1);
        --result;
        return (result);
}

private String colNumToName(int colNum)
{
        StringBuffer    sb  = new StringBuffer();
        int cycleNum    = colNum / 26;
        int withinNum   = colNum - (cycleNum * 26);
        if (cycleNum > 0)
            sb.append((char) ((cycleNum - 1) + 'a'));
        sb.append((char) (withinNum + 'a'));
        return (sb.toString());
} 
2009-04-27 07:49:24 http://code-cookbook.com/entry/82/c-excel-column-number-to-name-and-vice-versa
Display Error Messages in WordPress http://code-cookbook.com/entry/81/-display-error-messages-in-wordpress Add the line of code below to the top of your .htaccess file in the root directory of your WordPress website. Remember to only use this technique to help troubleshoot errors and remove it as soon as you are done.

php_flag display_errors on 
2009-04-14 04:04:44 http://code-cookbook.com/entry/81/-display-error-messages-in-wordpress
PHP Month Number to Month Name http://code-cookbook.com/entry/80/php-month-number-to-month-name An easy way to convert a month number to a month name without a switch statement.

$monthName = date("F", mktime(0, 0, 0, $monthNum, 10)); 
2009-03-31 03:17:00 http://code-cookbook.com/entry/80/php-month-number-to-month-name
C# String to Byte Array http://code-cookbook.com/entry/78/c-string-to-byte-array Converts a String to a Byte Array and vice versa.

//String to byte array
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
byte[] byteArray =  enc.GetBytes(str);

//Byte array to string
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
String str = enc.GetString(byteArr);
2009-03-27 01:38:02 http://code-cookbook.com/entry/78/c-string-to-byte-array
Make IE8 Emulate IE7 http://code-cookbook.com/entry/77/make-ie8-emulate-ie7 Put this XHTML in your code to make IE8 render pages like IE7.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
2009-03-20 06:11:42 http://code-cookbook.com/entry/77/make-ie8-emulate-ie7
High Quality CSS Thumbnails in IE7 http://code-cookbook.com/entry/76/high-quality-css-thumbnails-in-ie7 IE7 supports a custom bicubic resampling mode for images. This produces a much higher image quality for resized images.

/* HTML:
<img src="pic.jpg" alt="This image is really 500x500 big" class="thumb" width="50" height="50" />
*/

img.thumb { -ms-interpolation-mode: bicubic; }
2009-03-13 10:00:03 http://code-cookbook.com/entry/76/high-quality-css-thumbnails-in-ie7
Bash Script to Post to Twitter http://code-cookbook.com/entry/75/bash-script-to-post-to-twitter Here is a quick/easy way to post to twitter from the command line interface. Put the script in /usr/local/bin/ Then it is as easy as: user@river:~$ twitter Your Message Here

#!/bin/bash

# Login information.
USERNAME="email address"
PASSWORD="password"
URL=http://twitter.com/statuses/update.xml

# Check message length.
if [ ! -n "$1" ]; then
        echo "Message not long enough"
        exit
fi

# Check message length again.
message="$@"
maxlen=140;
len=`echo ${#message}`

if [ $len -gt $maxlen ]; then
        echo "Your message was longer than 140 characters...";
fi

# Post to Twitter.
result=`curl -u $USERNAME:$PASSWORD -d status="$message" $URL`
2009-03-06 17:03:51 http://code-cookbook.com/entry/75/bash-script-to-post-to-twitter
CSS Opacity http://code-cookbook.com/entry/71/css-opacity This is universal and should work on all browsers. The values represent percentage of opacity.

.opacity {
	opacity:0.9;
	filter: alpha(opacity=90); 
	-moz-opacity: 0.9;
}
2009-03-04 04:05:56 http://code-cookbook.com/entry/71/css-opacity
Target iPhone with CSS http://code-cookbook.com/entry/70/target-iphone-with-css The logic of this is that only browsers that understand "screen" understand "only", and of these, only the iphone has a "max-device-width" of 480px. The reason for the anti-IE comments is that some versions of IE render CSS regadless of media type declarations.

<!--[if !IE]>
<link media="only screen and (max-device-width: 480px)"
    href="iPhone.css" type="text/css" rel="stylesheet" />
<![endif]-->
2009-02-27 01:51:22 http://code-cookbook.com/entry/70/target-iphone-with-css
HTML Meta Tags http://code-cookbook.com/entry/68/html-meta-tags META tags should be placed in the head of the HTML document, between the &lt;HEAD&gt; and &lt;/HEAD&gt; tags (especially important in documents using FRAMES).

<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<META HTTP-EQUIV="Content-Language" CONTENT="en-GB">
<META HTTP-EQUIV="Refresh" CONTENT="3;URL=http://www.some.org/some.html">
<META HTTP-EQUIV="Window-target" CONTENT="_top">
<META HTTP-EQUIV="Ext-cache" CONTENT="name=/some/path/index.db; instructions=User Instructions">
<META HTTP-EQUIV="Set-Cookie" CONTENT="cookievalue=xxx;expires=Friday, 31-Dec-99 23:59:59 GMT; path=/">
<META NAME="ROBOTS" CONTENT="NOINDEX,FOLLOW">
<META NAME="description" CONTENT="Citrus fruit wholesaler.">
<META NAME="keywords" CONTENT="oranges, lemons, limes">

2009-02-27 01:29:40 http://code-cookbook.com/entry/68/html-meta-tags
Wordpress Separate Trackbacks / Pingbacks from Comments http://code-cookbook.com/entry/66/wordpress-separate-trackbacks-pingbacks-from-comments This is a neat little Wordpress trick to separate real comments from trackbacks and pingbacks.

<?php if ( $comments ) : ?>
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>
 
<!-- It's a comment -->
<!-- Comment content goes here -->
 
<?php } else { $trackback = true; }?> 
<?php endforeach; ?>
<?php if ($trackback == true) { ?>
 
<!-- It's a trackback -->
  <ol id="trackbacks-ol">
	  <?php foreach ($comments as $comment) : ?>
	  <?php $comment_type = get_comment_type(); ?>
	  <?php if($comment_type != 'comment') { ?>
	  <li>
		<?php comment_author_link() ?>
	</li>
	  <?php } ?>
	  <?php endforeach; ?>
  </ol>
 
<?php } ?>
<?php else : ?>
<?php endif; ?>
2009-02-25 05:41:08 http://code-cookbook.com/entry/66/wordpress-separate-trackbacks-pingbacks-from-comments
Wordpress "Tweet This" Link http://code-cookbook.com/entry/65/wordpress-tweet-this-link

<a href="http://twitter.com/home?status=I just read <?php the_permalink(); ?>" title="Send this page to Twitter!" target="_blank">Tweet This!</a>
2009-02-25 05:37:15 http://code-cookbook.com/entry/65/wordpress-tweet-this-link