<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: code code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 12 Oct 2008 15:23:12 GMT</pubDate>
    <description>DZone Snippets: code code</description>
    <item>
      <title>IP Range To Cidr Convertor C Code</title>
      <link>http://snippets.dzone.com/posts/show/6209</link>
      <description>// C Code to convert a given Ip range to CIDR notation.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/* rangeToCidr.c - Convert Ip ranges to CIDR */&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;modification history&lt;br /&gt;--------------------&lt;br /&gt;01a,17sep08,karn written&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* includes */&lt;br /&gt;&lt;br /&gt;#include&lt;stdio.h&gt;&lt;br /&gt;#include&lt;unistd.h&gt;&lt;br /&gt;#include&lt;string.h&gt;&lt;br /&gt;#include&lt;math.h&gt;&lt;br /&gt;#include&lt;errno.h&gt;&lt;br /&gt;#include &lt;sys/socket.h&gt;&lt;br /&gt;#include &lt;netinet/in.h&gt;&lt;br /&gt;#include &lt;arpa/inet.h&gt;&lt;br /&gt;&lt;br /&gt;/* defines */&lt;br /&gt;//#define DBG&lt;br /&gt;#ifdef DBG&lt;br /&gt;#define DEBUG(x) fprintf(stderr,x)&lt;br /&gt;#else&lt;br /&gt;#define DEBUG&lt;br /&gt;#endif /* DBG */&lt;br /&gt;&lt;br /&gt;#define IP_BINARY_LENGTH 32+1  /* 32 bits ipv4 address +1 for null */&lt;br /&gt;#define IP_HEX_LENGTH    10   &lt;br /&gt;#define MAX_CIDR_MASK    32&lt;br /&gt;#define MAX_CIDR_LEN     18+1   /*255.255.255.255/32*/&lt;br /&gt;&lt;br /&gt;/* Forward declaratopms */&lt;br /&gt;void rangeToCidr(uint32_t from ,uint32_t to,&lt;br /&gt;                 void (callback)(char *cidrNotation));&lt;br /&gt;int ipToBin(uint32_t ip , char * pOut);&lt;br /&gt;&lt;br /&gt;void printNotation(char *cidrNotation);&lt;br /&gt;&lt;br /&gt;/* Globals */&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*******************************************************************************&lt;br /&gt;*&lt;br /&gt;* ipToBin - convert an ipv4 address to binary representation &lt;br /&gt;*           and pads zeros to the beginning of the string if &lt;br /&gt;*           the length is not 32 &lt;br /&gt;*           (Important for ranges like 10.10.0.1 - 20.20.20.20 )&lt;br /&gt;*&lt;br /&gt;* ip   - ipv4 address on host order&lt;br /&gt;* pOut - Buffer to store binary.&lt;br /&gt;*&lt;br /&gt;* RETURNS: OK or ERROR &lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;int ipToBin(uint32_t ip , char * pOut)&lt;br /&gt;    {&lt;br /&gt;    char hex[IP_HEX_LENGTH];&lt;br /&gt;    int i;&lt;br /&gt;    int result=0;&lt;br /&gt;    int len;&lt;br /&gt;    char pTmp[2];&lt;br /&gt;    int tmp;&lt;br /&gt;    /*&lt;br /&gt;     * XXX: Could use bit operations instead but was easier to debug&lt;br /&gt;     */&lt;br /&gt;    char binMap[16][5] = { &lt;br /&gt;                        "0000","0001","0010","0011", "0100",&lt;br /&gt;                        "0101","0110","0111","1000", "1001",&lt;br /&gt;                        "1010","1011","1100", "1101","1110","1111",&lt;br /&gt;                        };&lt;br /&gt;    pTmp[1]=0x0;&lt;br /&gt;    memset(hex,0x0,sizeof(hex));&lt;br /&gt;    len=sprintf(hex,"%x",ip);&lt;br /&gt;&lt;br /&gt;    for(i=0;i&lt;len;i++)&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;        /* Ugly but to use strtol , we need the last byte as null */&lt;br /&gt;        pTmp[0]=hex[i];&lt;br /&gt;&lt;br /&gt;        errno = 0;&lt;br /&gt;        tmp = strtol(pTmp, 0x0, 16);&lt;br /&gt;&lt;br /&gt;        /* Should not happen */&lt;br /&gt;        if (errno != 0)&lt;br /&gt;            {&lt;br /&gt;            memset(pOut,'0',IP_BINARY_LENGTH -1);&lt;br /&gt;            DEBUG ("strtol failed for hex 0x%s\n",pTmp);&lt;br /&gt;            return -1;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;        result+=sprintf(pOut+result,"%s",binMap[tmp]);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        DEBUG("bits %u printed for ip address for hex len %u\n",result,len);&lt;br /&gt;        /* if length is not 32 , pad the start with zeros*/&lt;br /&gt;&lt;br /&gt;    if(result &lt; IP_BINARY_LENGTH-1)&lt;br /&gt;        {&lt;br /&gt;        char pSwap[IP_BINARY_LENGTH];&lt;br /&gt;        strncpy(pSwap,pOut,IP_BINARY_LENGTH);&lt;br /&gt;        memset(pOut,'0',IP_BINARY_LENGTH);&lt;br /&gt;        strncpy(pOut+IP_BINARY_LENGTH-1-result,pSwap,result);&lt;br /&gt;        DEBUG("corrected length to 32\n");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    else if (result &gt; IP_BINARY_LENGTH-1)&lt;br /&gt;        return -1;&lt;br /&gt;&lt;br /&gt;    /* Success */&lt;br /&gt;    return 0;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;/*******************************************************************************&lt;br /&gt;*  main : &lt;br /&gt;* &lt;br /&gt;*  arg1 : Start Ip Address&lt;br /&gt;*  arg2 : End Ip address&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;int main (int argc,char **argv)&lt;br /&gt;    {&lt;br /&gt;    long fromIp, toIp;&lt;br /&gt;    struct in_addr addr;&lt;br /&gt;    if(argc !=3 )&lt;br /&gt;        {&lt;br /&gt;        printf("Usage: %s &lt;from&gt; &lt;to&gt;\n",argv[0]);&lt;br /&gt;        return(0);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    /* All operation on host order */   &lt;br /&gt;    if (inet_aton(argv[1],&amp;addr) == 0)&lt;br /&gt;        goto error;&lt;br /&gt;    fromIp = ntohl(addr.s_addr);&lt;br /&gt;&lt;br /&gt;    if (inet_aton(argv[2],&amp;addr) ==0)&lt;br /&gt;        goto error;&lt;br /&gt;    toIp = ntohl(addr.s_addr);&lt;br /&gt;&lt;br /&gt;    rangeToCidr(fromIp,toIp,printNotation);&lt;br /&gt;&lt;br /&gt;    return 0;&lt;br /&gt;error:&lt;br /&gt;    printf("Invalid Argument\n");&lt;br /&gt;    return -EINVAL;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*******************************************************************************&lt;br /&gt;*&lt;br /&gt;* rangeToCidr - convert an ip Range to CIDR, and call 'callback' to handle&lt;br /&gt;*               the value. &lt;br /&gt;*&lt;br /&gt;* from     - IP Range start address&lt;br /&gt;* to       - IP Range end address&lt;br /&gt;* callback - Callback function to handle cidr.&lt;br /&gt;* RETURNS: OK or ERROR &lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;void rangeToCidr(uint32_t from ,uint32_t to,&lt;br /&gt;                 void (callback)(char *cidrNotation))&lt;br /&gt;    {&lt;br /&gt;    int     cidrStart = 0;&lt;br /&gt;    int     cidrEnd = MAX_CIDR_MASK - 1;&lt;br /&gt;    long    newfrom;&lt;br /&gt;    long    mask;&lt;br /&gt;    char    fromIp[IP_BINARY_LENGTH];&lt;br /&gt;    char    toIp[IP_BINARY_LENGTH];&lt;br /&gt;    struct  in_addr addr;&lt;br /&gt;    char    cidrNotation[MAX_CIDR_LEN];&lt;br /&gt;&lt;br /&gt;    memset (fromIp,0x0,sizeof(fromIp));&lt;br /&gt;    memset (toIp,0x0,sizeof(toIp));&lt;br /&gt;&lt;br /&gt;    if ( ipToBin(from,fromIp) != 0 ) &lt;br /&gt;        return;&lt;br /&gt;    if ( ipToBin(to,toIp) != 0 )&lt;br /&gt;        return;&lt;br /&gt;&lt;br /&gt;    DEBUG ("from %lu to %lu\n", from,to);&lt;br /&gt;    DEBUG("from %s\n",fromIp);&lt;br /&gt;    DEBUG("to   %s\n",toIp);&lt;br /&gt;&lt;br /&gt;    if(from &lt; to )&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;        /* Compare the from and to address ranges to get the first&lt;br /&gt;         * point of difference&lt;br /&gt;         */&lt;br /&gt;&lt;br /&gt;        while(fromIp[cidrStart]==toIp[cidrStart])&lt;br /&gt;            cidrStart ++;&lt;br /&gt;        cidrStart = 32 - cidrStart -1 ;&lt;br /&gt;        DEBUG("cidrStart is %u\n",cidrStart);&lt;br /&gt;&lt;br /&gt;        /* Starting from the found point of difference make all bits on the &lt;br /&gt;         * right side zero &lt;br /&gt;         */&lt;br /&gt;&lt;br /&gt;        newfrom = from &gt;&gt; cidrStart +1  &lt;&lt; cidrStart +1 ;        &lt;br /&gt;&lt;br /&gt;        /* Starting from the end iterate reverse direction to find &lt;br /&gt;         * cidrEnd&lt;br /&gt;         */ &lt;br /&gt;        while( fromIp[cidrEnd] == '0' &amp;&amp; toIp[cidrEnd] == '1')&lt;br /&gt;            cidrEnd --;&lt;br /&gt;&lt;br /&gt;        cidrEnd = MAX_CIDR_MASK - 1 - cidrEnd;&lt;br /&gt;        DEBUG("cidrEnd is %u\n",cidrEnd);&lt;br /&gt;&lt;br /&gt;        if(cidrEnd &lt;= cidrStart)&lt;br /&gt;            {&lt;br /&gt;            /* &lt;br /&gt;             * Make all the bit-shifted bits equal to 1, for&lt;br /&gt;             * iteration # 1.&lt;br /&gt;             */&lt;br /&gt;            &lt;br /&gt;            mask = pow (2, cidrStart ) - 1;&lt;br /&gt;            DEBUG("it1 is %lu \n",newfrom | mask );&lt;br /&gt;            rangeToCidr (from , newfrom | mask, callback);&lt;br /&gt;            DEBUG("it2 is %lu \n",newfrom | 1 &lt;&lt; cidrStart);&lt;br /&gt;            rangeToCidr (newfrom | 1 &lt;&lt;  cidrStart ,to ,callback);&lt;br /&gt;            }&lt;br /&gt;        else&lt;br /&gt;            {&lt;br /&gt;            addr.s_addr = htonl(newfrom);&lt;br /&gt;            sprintf(cidrNotation,"%s/%d", &lt;br /&gt;                    inet_ntoa(addr), MAX_CIDR_MASK-cidrEnd);&lt;br /&gt;            if (callback != NULL)&lt;br /&gt;                callback(cidrNotation);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    else&lt;br /&gt;        {&lt;br /&gt;        addr.s_addr = htonl(from);&lt;br /&gt;        sprintf(cidrNotation,"%s/%d",inet_ntoa(addr),MAX_CIDR_MASK);&lt;br /&gt;        if(callback != NULL)&lt;br /&gt;            callback(cidrNotation);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;/*******************************************************************************&lt;br /&gt;*&lt;br /&gt;* printNotation - This is an example callback function to handle cidr notation. &lt;br /&gt;*&lt;br /&gt;* RETURNS:&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;void printNotation(char *cidrNotation)&lt;br /&gt;    {&lt;br /&gt;    printf("%s\n",cidrNotation);&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 07 Oct 2008 09:21:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/6209</guid>
      <author>teamfone (karn)</author>
    </item>
    <item>
      <title>tidy up copy'n'paste code snippets from DZone</title>
      <link>http://snippets.dzone.com/posts/show/6137</link>
      <description>// remove the line numbers from DZone's copy'n'paste code snippets&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;#&lt;br /&gt;#  usage :  dzone.pl copy_and_paste_file&lt;br /&gt;#           copy_and_paste_file - file which contain the code snippet from DZone website&lt;br /&gt;&lt;br /&gt;sub dzone_tidy {&lt;br /&gt;  my ($infile) = @_;&lt;br /&gt;  open(FILE, "&lt; $infile") || die "ERROR: failed to open file: '$infile'";&lt;br /&gt;  while (my $line = &lt;FILE&gt;) {&lt;br /&gt;    $line =~ s/^[ ]*[0-9]*  //;&lt;br /&gt;    print "$line";&lt;br /&gt;  }&lt;br /&gt;  close(FILE);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if ( $#ARGV ne 0 )&lt;br /&gt;{&lt;br /&gt;  print "ERROR: wrong number of parameters\n\n";&lt;br /&gt;  exit(1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;my $infile = $ARGV[0];&lt;br /&gt;dzone_tidy(${infile});&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 24 Sep 2008 09:01:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/6137</guid>
      <author>SubOptimal (F. Dietrich)</author>
    </item>
    <item>
      <title>Wrapping a Ruby line statement over multiples of lines</title>
      <link>http://snippets.dzone.com/posts/show/6006</link>
      <description>&lt;code&gt;a = "123" \&lt;br /&gt;"456"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;=&gt; "123456"&lt;br /&gt;&lt;code&gt;a = 1 + 2 + \&lt;br /&gt;3 +4&lt;/code&gt;&lt;br /&gt;=&gt; 10&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Sun, 31 Aug 2008 13:31:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/6006</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Strip the line numbers from code snippets</title>
      <link>http://snippets.dzone.com/posts/show/5929</link>
      <description>Source: &lt;a href="http://saaridev.blogspot.com/2007/12/ruby-one-liner-to-strip-line-number.html"&gt;Saari Development: Ruby: One liner to strip the line number from code posted&lt;/a&gt; [blogspot.com]&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ruby -lne 'puts $_.gsub(/^\s+?\d+\s/,"")' ali.rb &gt; ali.rb&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here's a page that allows you to &lt;a href="http://rorbuilder.info/r/strip-line-numbers/index.html"&gt;strip line numbers without any script&lt;/a&gt; [rorbuilder.info] or here http://rubyurl.com/umxP .</description>
      <pubDate>Sat, 16 Aug 2008 11:49:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5929</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Trivial ternary operator in Scala</title>
      <link>http://snippets.dzone.com/posts/show/5887</link>
      <description>//Just a quick test/exploration of Pimp My Library to reproduce the syntax of the C++ et al ternary operator &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;object TernaryOp {&lt;br /&gt;  implicit def fakeTernary[A](a:(A,A)) = new{&lt;br /&gt;    def ?:(p:Boolean)=if(p) a._1 else a._2&lt;br /&gt;  }  &lt;br /&gt;  //Before adding the Tuplicator class the compiler got very confused&lt;br /&gt;  // between anonymous classes&lt;br /&gt;  class Tuplicator[A](a:A){&lt;br /&gt;    def ~:(b:A) = (b,a)&lt;br /&gt;  }&lt;br /&gt;  implicit def tuplicate[A](a:A) = new Tuplicator(a)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;object TernaryTest {&lt;br /&gt;  import TernaryOp._&lt;br /&gt;  def main(args: Array[String]) = {&lt;br /&gt;    println( (1&gt;3) ?: 1 ~: 3 )&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 08 Aug 2008 00:00:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5887</guid>
      <author>Snut (Daniel Watts)</author>
    </item>
    <item>
      <title>Only allow numbers in textbox</title>
      <link>http://snippets.dzone.com/posts/show/5718</link>
      <description>// This can be expanded to limit the key pressed to whatever you want&lt;br /&gt;//In this scenario it only allows digits&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; void textBox_KeyPress(object sender, KeyPressEventArgs e)&lt;br /&gt;{&lt;br /&gt;e.Handled = !(Char.IsDigit(e.KeyChar) || e.KeyChar == '\b');&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 02 Jul 2008 11:43:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5718</guid>
      <author>dubby (Dave)</author>
    </item>
    <item>
      <title>Code 2 HTML</title>
      <link>http://snippets.dzone.com/posts/show/5330</link>
      <description>This is a simple python program that reads a file (code), and replaces line breaks and spaces with appropriate tag and entity.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import sys&lt;br /&gt;&lt;br /&gt;line_break='&lt;br&gt;'&lt;br /&gt;nb_space='&amp;#160;'&lt;br /&gt;&lt;br /&gt;def toHtml(f,out):&lt;br /&gt;    try:&lt;br /&gt;        fo=open(out,'w')&lt;br /&gt;    except IOError:&lt;br /&gt;        print 'output file error!'&lt;br /&gt;    else:&lt;br /&gt;        for line in f:&lt;br /&gt;            line=line.replace('\t',nb_space*8)&lt;br /&gt;            line=line.replace(' ',nb_space)&lt;br /&gt;            line=line.replace('\n',line_break)&lt;br /&gt;            fo.write(line)&lt;br /&gt;        fo.close()&lt;br /&gt;        &lt;br /&gt;&lt;br /&gt;if len(sys.argv) == 1:&lt;br /&gt;    print("at least one argument / input filename / required")&lt;br /&gt;    sys.exit()&lt;br /&gt;if len(sys.argv) &gt; 3:&lt;br /&gt;    print"too many arguments"&lt;br /&gt;    sys.exit()       &lt;br /&gt;try:&lt;br /&gt;    f=open(sys.argv[1],'r')&lt;br /&gt;except IOError:&lt;br /&gt;    print 'cannot open file ', sys.argv[1]&lt;br /&gt;else:&lt;br /&gt;    if len(sys.argv) == 2:&lt;br /&gt;        out=f.name + '.html'&lt;br /&gt;    else:&lt;br /&gt;        out=sys.argv[2]&lt;br /&gt;    toHtml(f, out)&lt;br /&gt;    f.close()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 07 Apr 2008 07:59:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5330</guid>
      <author>Tvrtko (Tvrtko)</author>
    </item>
    <item>
      <title>Reference of keyCodes </title>
      <link>http://snippets.dzone.com/posts/show/5320</link>
      <description>&lt;code&gt;&lt;br /&gt;    switch (oEvent.keyCode) {&lt;br /&gt;       case 38: //up arrow  &lt;br /&gt;       case 40: //down arrow&lt;br /&gt;       case 37: //left arrow&lt;br /&gt;       case 39: //right arrow&lt;br /&gt;       case 33: //page up  &lt;br /&gt;       case 34: //page down  &lt;br /&gt;       case 36: //home  &lt;br /&gt;       case 35: //end                  &lt;br /&gt;       case 13: //enter  &lt;br /&gt;       case 9: //tab  &lt;br /&gt;       case 27: //esc  &lt;br /&gt;       case 16: //shift  &lt;br /&gt;       case 17: //ctrl  &lt;br /&gt;       case 18: //alt  &lt;br /&gt;       case 20: //caps lock&lt;br /&gt;       case 8: //backspace  &lt;br /&gt;       case 46: //delete&lt;br /&gt;           return true;&lt;br /&gt;           break;&lt;br /&gt;&lt;br /&gt;       default: &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Note: When capturing combination keys there is dedicated boolean attributes for each of the special keys (CTRL, SHIFT, ALT).&lt;br /&gt;Reference: &lt;a href="http://www.sitepoint.com/article/life-autocomplete-textboxes/3"&gt;Make Life Easy With Autocomplete Textboxes [JavaScript &amp; AJAX Tutorials]&lt;/a&gt; [sitepoint.com]</description>
      <pubDate>Wed, 02 Apr 2008 22:31:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5320</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Adding new files to your github repository</title>
      <link>http://snippets.dzone.com/posts/show/5280</link>
      <description>Here is a set of instructions to apply new files to my github repository which is called projectx.&lt;br /&gt;&lt;br /&gt;Before you start make sure you don't already have the repository name listed as a directory in the local current directory.&lt;br /&gt;&lt;br /&gt;1) copy the remote repository to your local machine&lt;br /&gt;syntax: git clone [uri] # eg. &lt;code&gt;git clone git@github.com:jrobertson/projectx.git&lt;/code&gt;&lt;br /&gt;1.5) cd into the newly created local repository eg.&lt;code&gt;cd projectx&lt;/code&gt;&lt;br /&gt;2) copy the local file to the local repository directory&lt;br /&gt;eg. &lt;code&gt;cp ../projectx2/feed.rb .&lt;/code&gt;&lt;br /&gt;3) add the local files to the local repository&lt;br /&gt;syntax: git add [file] # eg. &lt;code&gt;git add feed.rb&lt;/code&gt;&lt;br /&gt;4) Inform the git system that you have completed the required changes for this session.&lt;br /&gt;&lt;code&gt;git commit -a # add a message associated with this file revision&lt;/code&gt;&lt;br /&gt;5) copy the new local repository files back to the remote repository.&lt;br /&gt;&lt;code&gt;git push # updates the changes back to the server&lt;/code&gt;&lt;br /&gt;Note: The text with the square-brackets should be replaced with your own values.&lt;br /&gt;&lt;br /&gt;Reference: &lt;a href="http://cworth.org/hgbook-git/tour/"&gt;A tour of git: the basics&lt;/a&gt; [cworth.org]</description>
      <pubDate>Tue, 25 Mar 2008 15:16:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5280</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Format Ruby code in HTML</title>
      <link>http://snippets.dzone.com/posts/show/5178</link>
      <description>This code uses the Ruby gem 'syntax' to create an XML file containing the HTML tags around the code, which is then transformed into an HTML file. The working example was first built using coding examples from &lt;a href="http://blog.wolfman.com/articles/2006/05/26/howto-format-ruby-code-for-blogs"&gt;Howto format ruby code for blogs&lt;/a&gt; [wolfman.com] and &lt;a href="http://brentrubyrails.blogspot.com/2007/12/formatting-ruby-and-html-code-for-blog.html"&gt;Formatting Ruby and HTML code for blog posting&lt;/a&gt; [blogspot.com]&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/ruby&lt;br /&gt;&lt;br /&gt;#file: ruby2html.rb &lt;br /&gt;&lt;br /&gt;require 'rubygems'&lt;br /&gt;require 'syntax/convertors/html'&lt;br /&gt;require 'projxslt' # &lt;- this is my own class to do an XSLT transform &lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;class Ruby2Html&lt;br /&gt;  def initialize(rubyfile, htmlfile)&lt;br /&gt;    code = File.read(rubyfile)&lt;br /&gt;    convertor = Syntax::Convertors::HTML.for_syntax "ruby"&lt;br /&gt;    code_html = convertor.convert(code)&lt;br /&gt;    &lt;br /&gt;    tempfile = '../temp/ruby2html.xml'&lt;br /&gt;    xslfile = '../ruby2html/ruby2html.xsl'&lt;br /&gt;    save_file(tempfile, code_html)&lt;br /&gt;    &lt;br /&gt;    px = Projxslt.new(tempfile, xslfile)&lt;br /&gt;    buffer = px.transform()&lt;br /&gt;    save_file(htmlfile, buffer)&lt;br /&gt;    &lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  def save_file(filename, buffer)&lt;br /&gt;    file = File.new(filename, 'w')&lt;br /&gt;    file.puts buffer&lt;br /&gt;    file.close&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;if __FILE__ == $0&lt;br /&gt;  r2h = Ruby2Html.new('ruby2html.rb', '../temp/ruby2html.html')&lt;br /&gt;  puts 'completed'&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;file: ruby2html.xsl&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&lt;br /&gt;                xmlns="http://www.w3.org/1999/xhtml"&lt;br /&gt;                version="1.0"&gt;&lt;br /&gt;&lt;br /&gt;  &lt;xsl:output method="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;br /&gt;          doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;br /&gt;          encoding="ISO-8859-1"/&gt; &lt;br /&gt;&lt;br /&gt;	&lt;xsl:template match="/"&gt;&lt;br /&gt;	&lt;xsl:element name="html"&gt;&lt;br /&gt;&lt;br /&gt;        &lt;head&gt;&lt;br /&gt;          &lt;title&gt;Sample code&lt;/title&gt;&lt;br /&gt;          &lt;link rel="stylesheet" type="text/css" href="ruby2html.css" /&gt;&lt;br /&gt;	&lt;/head&gt;&lt;br /&gt;&lt;br /&gt;	&lt;body&gt;&lt;br /&gt;          &lt;div id="wrap"&gt;&lt;br /&gt;          &lt;xsl:apply-templates /&gt;&lt;br /&gt;          &lt;/div&gt;&lt;br /&gt;	&lt;/body&gt; &lt;br /&gt;&lt;br /&gt;	&lt;/xsl:element&gt;&lt;br /&gt;	&lt;/xsl:template&gt;&lt;br /&gt;&lt;br /&gt;	&lt;xsl:template match="pre"&gt;&lt;br /&gt;	  &lt;xsl:copy-of select="."/&gt;&lt;br /&gt;	&lt;/xsl:template&gt;&lt;br /&gt;&lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here's the output from the &lt;a href="http://www.twitxr.com/image/7628/"&gt;formatted Ruby HTML code&lt;/a&gt; [twitxr.com]&lt;br /&gt;&lt;br /&gt;Referemce: &lt;a href="http://syntax.rubyforge.org/"&gt;Syntax Manual&lt;/a&gt; [rubyforge.org]</description>
      <pubDate>Tue, 26 Feb 2008 15:43:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5178</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
  </channel>
</rss>
