<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: check code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 09:09:36 GMT</pubDate>
    <description>DZone Snippets: check code</description>
    <item>
      <title>Simple way to check command line arguments in a C program</title>
      <link>http://snippets.dzone.com/posts/show/5175</link>
      <description>A simple way to check command line arguments.&lt;br /&gt;&lt;br /&gt;Author: &lt;a href="http://www.inf.ufrgs.br/~jmftrindade"&gt;Joana Matos Fonseca da Trindade&lt;/a&gt;&lt;br /&gt;Date: 2008.02.25&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;stdlib.h&gt;&lt;br /&gt;#include &lt;string.h&gt;&lt;br /&gt;&lt;br /&gt;/* minimum required number of parameters */&lt;br /&gt;#define MIN_REQUIRED 2&lt;br /&gt;&lt;br /&gt;/* display usage */&lt;br /&gt;int help() {&lt;br /&gt;   printf("Usage: myprogram [-s &lt;arg0&gt;] [-n &lt;arg1&gt;] [-true]\n");&lt;br /&gt;   printf("\t-s: a string a\n");&lt;br /&gt;   printf("\t-n: a number\n");&lt;br /&gt;   printf("\t-true: a single parameter\n");&lt;br /&gt;&lt;br /&gt;   return 1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* main */&lt;br /&gt;int main(int argc, char *argv[]) {&lt;br /&gt;   if (argc &lt; MIN_REQUIRED) {&lt;br /&gt;      return help();&lt;br /&gt;   }&lt;br /&gt;   int i;&lt;br /&gt;&lt;br /&gt;   /* iterate over all arguments */&lt;br /&gt;   for (i = 1; i &lt; (argc - 1); i++) {&lt;br /&gt;       if (strcmp("-s", argv[i]) == 0) {&lt;br /&gt;          /* do something with it */ &lt;br /&gt;          printf("string = %s\n", argv[++i]);&lt;br /&gt;          continue;&lt;br /&gt;       }&lt;br /&gt;       if (strcmp("-n", argv[i]) == 0) {&lt;br /&gt;          /* do something with it. for example, convert it to an integer */&lt;br /&gt;          printf("number = %i\n", atoi(argv[++i]));&lt;br /&gt;          continue;&lt;br /&gt;       }&lt;br /&gt;       if (strcmp("-true", argv[i]) == 0) {&lt;br /&gt;          printf("true activated\n");&lt;br /&gt;          continue;&lt;br /&gt;       }&lt;br /&gt;       return help();&lt;br /&gt;   }&lt;br /&gt;   return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 25 Feb 2008 22:49:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5175</guid>
      <author>jmftrindade (Joana M. F. da Trindade)</author>
    </item>
    <item>
      <title>PHP : Comprobar e-mail v&#225;lido / Check valid e-mail</title>
      <link>http://snippets.dzone.com/posts/show/4346</link>
      <description>Comprobar e-mail v&#225;lido / Check valid e-mail&lt;br /&gt;C&#243;digo fuente / Source code :&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function esEmailValido($email)&lt;br /&gt;{&lt;br /&gt;    if (ereg("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([_a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]{2,200}\.[a-zA-Z]{2,6}$", $email ) )&lt;br /&gt;	{&lt;br /&gt;       return true;&lt;br /&gt;    }&lt;br /&gt;	else&lt;br /&gt;	{&lt;br /&gt;       return false;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Jul 2007 11:11:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4346</guid>
      <author>Ricardo (Ricardo m. Garc&#237;a)</author>
    </item>
    <item>
      <title>Check email in html form</title>
      <link>http://snippets.dzone.com/posts/show/4290</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; &lt;script type="text/javascript"&gt;&lt;br /&gt;        function check_email(email_id,err_id){&lt;br /&gt;            emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;&lt;br /&gt;            var err_mail='Email addres incorect!';&lt;br /&gt;            if(emailRegExp.test(document.getElementById(email_id).value)){&lt;br /&gt;                alert('true');&lt;br /&gt;                return true;&lt;br /&gt;            }else{&lt;br /&gt;                document.getElementById(err_id).innerHTML=err_mail;&lt;br /&gt;                alert(err_mail);&lt;br /&gt;                return false;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    &lt;/script&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span id="err_msg" style="color: red;"&gt;&lt;/span&gt;&lt;br /&gt;    &lt;form id="myForm" name="myForm" action="./register.php" method="post" onsubmit="return check_email('email','err_msg');"&gt;&lt;br /&gt;        &lt;input type="text" name="email" id="email"/&gt;&lt;br /&gt;        &lt;input  type="submit" name="send" value="Send" /&gt;&lt;br /&gt;    &lt;/form&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 12 Jul 2007 10:04:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4290</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
    <item>
      <title>PHP variable check</title>
      <link>http://snippets.dzone.com/posts/show/3235</link>
      <description>ugh&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$page = isset($_GET['page']) ? $_GET['page'] : 'home';&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 03 Jan 2007 13:09:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3235</guid>
      <author>alexwilliams (Alex Williams)</author>
    </item>
    <item>
      <title>Is Date //JavaScript Function</title>
      <link>http://snippets.dzone.com/posts/show/2204</link>
      <description>&lt;a href="http://jsfromhell.com/geral/is-date"&gt;&lt;br /&gt;Checks if a date is valid and returns error codes described bellow.&lt;br /&gt;&lt;br /&gt;[UPDATED CODE AND HELP CAN BE FOUND HERE]&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com/geral/is-date [v1.0]&lt;br /&gt;&lt;br /&gt;isDate = function(y, m, d){ //v1.0&lt;br /&gt;        if(typeof y == "string" &amp;&amp; m instanceof RegExp &amp;&amp; d){&lt;br /&gt;            if(!m.test(y)) return 1;&lt;br /&gt;            y = RegExp["$" + d.y], m = RegExp["$" + d.m], d = RegExp["$" + d.d];&lt;br /&gt;        }&lt;br /&gt;        d = Math.abs(d) || 0, m = Math.abs(m) || 0, y = Math.abs(y) || 0;&lt;br /&gt;        return arguments.length != 3 ? 1 : d &lt; 1 || d &gt; 31 ? 2 : m &lt; 1 || m &gt; 12 ? 3 : /4|6|9|11/.test(m) &amp;&amp; d == 31 ? 4&lt;br /&gt;        : m == 2 &amp;&amp; (d &gt; ((y = !(y % 4) &amp;&amp; (y % 1e2) || !(y % 4e2)) ? 29 : 28)) ? 5 + !!y : 0;&lt;br /&gt;};&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Usage&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;&lt;br /&gt;getDateMsg = function(x){&lt;br /&gt;    return x == 0 ? "Valid Date"&lt;br /&gt;    : x == 1 ? "Invalid date format"&lt;br /&gt;    : x == 2 ? "Invalid day"&lt;br /&gt;    : x == 3 ? "Invalid month"&lt;br /&gt;    : x == 4 ? "In April, June, September and November there's no 31 day"&lt;br /&gt;    : x == 5 ? "February has only 28 days"&lt;br /&gt;    : x == 6 ? "In leap years, February has 29 days": "nothing =]";&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;var x = [&lt;br /&gt;    isDate("22/07/1984", /^([0-9]{1,2})[\/]([0-9]{1,2})[\/]([0-9]{1,4})$/, {d: 1, m: 2, y: 3}),&lt;br /&gt;    isDate("1984-07-22", /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/, {d: 3, m: 2, y: 1}),&lt;br /&gt;    isDate("07-22-1984", /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/, {d: 3, m: 2, y: 1}),&lt;br /&gt;    isDate(2000, 1, 32),&lt;br /&gt;    isDate(2000, 0, 1),&lt;br /&gt;    isDate(2000, 4, 31),&lt;br /&gt;    isDate(2001, 2, 29),&lt;br /&gt;    isDate(2004, 2, 30)&lt;br /&gt;];&lt;br /&gt;&lt;br /&gt;for(var i = -1, l = x.length; ++i &lt; l; document.write(getDateMsg(x[i]), "&lt;br /&gt;"));&lt;br /&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Help&lt;br /&gt;&lt;code&gt;&lt;br /&gt;isDate(y: Integer, m: Integer, d: Integer): Integer&lt;br /&gt;    Checks a date and returns 0 if it's valid or one of the error codes bellow.&lt;br /&gt;    y year&lt;br /&gt;    m month&lt;br /&gt;    d day&lt;br /&gt;&lt;br /&gt;	&lt;br /&gt;isDate(date: String, matcher: RegExp, map: Object): Integer&lt;br /&gt;    Checks a date and returns 0 if it's valid or one of the error codes bellow.&lt;br /&gt;    date date in a string form&lt;br /&gt;    matcher regular expression responsible to find and store the day, month and year&lt;br /&gt;    			&lt;br /&gt;    map object containing the position where each date component is localized inside the regular expression. Its format is the following: {d: positionOfTheDay, m: positionOfTheMonth, y: positionOfTheYear}								&lt;br /&gt;Return codes&lt;br /&gt;    * 0 = Valid date&lt;br /&gt;    * 1 = Date format invalid (regular expression failed or amount of arguments != 3)&lt;br /&gt;    * 2 = Day isn't between 1 and 31&lt;br /&gt;    * 3 = Month isn't between 1 and 12&lt;br /&gt;    * 4 = On April, June, September and November there isn't the day 31&lt;br /&gt;    * 5 = On February the month has only 28 days&lt;br /&gt;    * 6 = Leap year, February has only 29 days&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 15 Jun 2006 20:12:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2204</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
    <item>
      <title>Check the syntax of a bunch of PHP files all at once</title>
      <link>http://snippets.dzone.com/posts/show/2063</link>
      <description>Will find all files ending with 'php' and execute the syntax check of php for every found file. Useful if you quickly want to see which php file contains a parse error.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;find ./ -type f -name \*.php -exec php -l {} \;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 18 May 2006 00:19:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2063</guid>
      <author>yoghoyogho ()</author>
    </item>
    <item>
      <title>Thai election ID checking</title>
      <link>http://snippets.dzone.com/posts/show/1716</link>
      <description>The online service &lt;a href=http://www.dopa.go.th/online/inqelect.htm&gt;here&lt;/a&gt; aims to help people&lt;br /&gt;check where they are to vote. However, it can be&lt;br /&gt;used as ID certification as well.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# nnnn is the id to be checked&lt;br /&gt;http://www.dopa.go.th/cgi-bin/inqelect.sh?pid=nnnn&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here I make it into a function call.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import urllib, re&lt;br /&gt;def getname(id):&lt;br /&gt;  url = 'http://www.dopa.go.th/cgi-bin/inqelect.sh?pid=' + str(id)&lt;br /&gt;  src = urllib.urlopen(url).read()&lt;br /&gt;  pat = '&lt;H3&gt; *(.*?) *&lt;'&lt;br /&gt;  name = re.findall(pat, src)[0]  # don't use other info&lt;br /&gt;  return name&lt;br /&gt;&lt;br /&gt;print getname(5100900050063)  # show a name (one of my relatives)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 19 Mar 2006 16:30:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1716</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
