<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Shantanuo's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 07:34:39 GMT</pubDate>
    <description>DZone Snippets: Shantanuo's Code Snippets</description>
    <item>
      <title>Compare Engines </title>
      <link>http://snippets.dzone.com/posts/show/5806</link>
      <description>// If you have 2 servers with identical database structure, and some of the tables have different engine type, then create a federated table to connect to the original server and compare the engines type with the current table's engine.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;CREATE TABLE test.`TABLES2` (&lt;br /&gt;`TABLE_CATALOG` varchar(512) default NULL,&lt;br /&gt;`TABLE_SCHEMA` varchar(64) NOT NULL default '',&lt;br /&gt;`TABLE_NAME` varchar(64) NOT NULL default '',&lt;br /&gt;`TABLE_TYPE` varchar(64) NOT NULL default '',&lt;br /&gt;`ENGINE` varchar(64) default NULL,&lt;br /&gt;`VERSION` bigint(21) default NULL,&lt;br /&gt;`ROW_FORMAT` varchar(10) default NULL,&lt;br /&gt;`TABLE_ROWS` bigint(21) default NULL,&lt;br /&gt;`AVG_ROW_LENGTH` bigint(21) default NULL,&lt;br /&gt;`DATA_LENGTH` bigint(21) default NULL,&lt;br /&gt;`MAX_DATA_LENGTH` bigint(21) default NULL,&lt;br /&gt;`INDEX_LENGTH` bigint(21) default NULL,&lt;br /&gt;`DATA_FREE` bigint(21) default NULL,&lt;br /&gt;`AUTO_INCREMENT` bigint(21) default NULL,&lt;br /&gt;`CREATE_TIME` datetime default NULL,&lt;br /&gt;`UPDATE_TIME` datetime default NULL,&lt;br /&gt;`CHECK_TIME` datetime default NULL,&lt;br /&gt;`TABLE_COLLATION` varchar(64) default NULL,&lt;br /&gt;`CHECKSUM` bigint(21) default NULL,&lt;br /&gt;`CREATE_OPTIONS` varchar(255) default NULL,&lt;br /&gt;`TABLE_COMMENT` varchar(80) NOT NULL default ''&lt;br /&gt;)&lt;br /&gt;ENGINE=FEDERATED DEFAULT CHARSET=latin1&lt;br /&gt;CONNECTION='mysql://root@172.172.172.172/information_schema/TABLES';&lt;br /&gt;&lt;br /&gt;SELECT b.TABLE_SCHEMA as remote_database, b.TABLE_NAME as remote_tableName, b.ENGINE as remote_engine, a.ENGINE AS local_engine &lt;br /&gt;FROM test.TABLES2 AS a INNER JOIN information_schema.TABLES as b &lt;br /&gt;ON a.TABLE_SCHEMA = b.TABLE_SCHEMA AND a.TABLE_NAME = b.TABLE_NAME AND a.ENGINE != b.ENGINE;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 22 Jul 2008 05:47:46 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5806</guid>
      <author>shantanuo (shantanu oak)</author>
    </item>
    <item>
      <title>server monitoring</title>
      <link>http://snippets.dzone.com/posts/show/5611</link>
      <description># servers.sh&lt;br /&gt;export MAILSERVERS="server1 server2 server3"&lt;br /&gt;export WEBSERVERS="www1 www2 www3 www4"&lt;br /&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;### Assess disk space on mail servers&lt;br /&gt;source ./servers.sh&lt;br /&gt;for i in ${MAILSERVERS} ; do&lt;br /&gt;       echo =========${i} =============&lt;br /&gt;       ssh root@${i} "df"&lt;br /&gt;       echo ============ =============&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;# min   hour    dom     month   dow     command&lt;br /&gt;&lt;br /&gt;grep &#8220;###&#8221; *</description>
      <pubDate>Sat, 07 Jun 2008 14:43:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5611</guid>
      <author>shantanuo (shantanu oak)</author>
    </item>
    <item>
      <title>Querystring variables</title>
      <link>http://snippets.dzone.com/posts/show/4947</link>
      <description>&lt;code&gt;&lt;br /&gt;// Add Querystring Variable&lt;br /&gt;// A PHP function that will add the querystring variable $key with a &lt;br /&gt;// value $value to $url. If $key is already specified within $url, &lt;br /&gt;// it will replace it.&lt;br /&gt;&lt;br /&gt;function add_querystring_var($url, $key, $value) {&lt;br /&gt;$url = preg_replace('/(.*)(\?|&amp;)' . $key . '=[^&amp;]+?(&amp;)(.*)/i', '$1$2$4', $url . '&amp;');&lt;br /&gt;$url = substr($url, 0, -1);&lt;br /&gt;if (strpos($url, '?') === false) {&lt;br /&gt;return ($url . '?' . $key . '=' . $value);&lt;br /&gt;} else {&lt;br /&gt;return ($url . '&amp;' . $key . '=' . $value);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Remove Querystring Variable&lt;br /&gt;// A PHP function that will remove the variable $key and its value &lt;br /&gt;// from the given $url.&lt;br /&gt;&lt;br /&gt;function remove_querystring_var($url, $key) {&lt;br /&gt;$url = preg_replace('/(.*)(\?|&amp;)' . $key . '=[^&amp;]+?(&amp;)(.*)/i', '$1$2$4', $url . '&amp;');&lt;br /&gt;$url = substr($url, 0, -1);&lt;br /&gt;return ($url);&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 05 Jan 2008 07:07:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4947</guid>
      <author>shantanuo (shantanu oak)</author>
    </item>
    <item>
      <title>delete empty directories</title>
      <link>http://snippets.dzone.com/posts/show/4742</link>
      <description>&lt;code&gt;&lt;br /&gt;// commands to recursively delete empty directories below the current one&lt;br /&gt;// (use at your own risk, as the slightest mistake WILL destroy &lt;br /&gt;// all of your data - Linux) &lt;br /&gt;find -depth -type d -empty -exec rmdir {} \;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Thu, 08 Nov 2007 13:00:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4742</guid>
      <author>shantanuo (shantanu oak)</author>
    </item>
    <item>
      <title>Unicode words from online dictionary</title>
      <link>http://snippets.dzone.com/posts/show/4708</link>
      <description>// list words from unicode dictionary &lt;br /&gt;// you need to add this line in the head section&lt;br /&gt;//   &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;for ( $i = 1; $i &lt;= 45; $i++) {&lt;br /&gt;$url="http://dsal.uchicago.edu/cgi-bin/romadict.pl?page=$i&amp;table=molesworth&amp;display=utf8";&lt;br /&gt;$text=file_get_contents($url);&lt;br /&gt;$myarray = preg_match_all('#&lt;font size="\+1"&gt;(.*?)&lt;/font&gt;#i', $text, $matches);&lt;br /&gt;echo implode(' ',$matches[1]); &lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 28 Oct 2007 08:55:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4708</guid>
      <author>shantanuo (shantanu oak)</author>
    </item>
    <item>
      <title>extract table names from sql log file</title>
      <link>http://snippets.dzone.com/posts/show/4639</link>
      <description>&lt;code&gt;&lt;br /&gt;grep "from " /var/log/mysql/mysqld.log | awk -Ffrom '{print $2}' | awk '{print $1}' | cat &gt; /home/shantanu/testing.txt&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 12 Oct 2007 08:23:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4639</guid>
      <author>shantanuo (shantanu oak)</author>
    </item>
    <item>
      <title>Password Protection</title>
      <link>http://snippets.dzone.com/posts/show/4614</link>
      <description>// Bare Bones demo of password protection&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$password = "abc123";&lt;br /&gt;if ($_POST[doddle] == $password) {&lt;br /&gt;        $tell = 1;&lt;br /&gt;} else {&lt;br /&gt;        $tell = 2;&lt;br /&gt;}&lt;br /&gt;if (! is_string($_POST[doddle])) $tell = 0;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;&lt;head&gt;&lt;title&gt;A Page that is password protected&lt;/title&gt;&lt;/head&gt;&lt;br /&gt;&lt;body&gt;&lt;br /&gt;&lt;?php if ($tell == 1) { ?&gt;&lt;br /&gt; &lt;br /&gt;&lt;h1&gt;The page with all the secrets revealed &lt;/h1&gt;&lt;br /&gt; &lt;br /&gt;This is the information that has been revealed to you because you&lt;br /&gt;got the password right!&lt;br /&gt;&lt;br /&gt;Although this is a very simple&lt;br /&gt;demo it shows what you can do with just a few lines of PHP.&lt;br /&gt; &lt;br /&gt;&lt;?php } else { ?&gt;&lt;br /&gt; &lt;br /&gt;&lt;h1&gt;A Header page&lt;/h1&gt;&lt;br /&gt; &lt;br /&gt;There is a page hidden under a password at this URL. For this demo only&lt;br /&gt;I will tell you that the password is "abc123" so you can try it out!&lt;br /&gt;&lt;br /&gt;&lt;?php if ($tell == 2) print ("&lt;br /&gt;YOU GOT THE PASSWORD WRONG&lt;br /&gt;"); ?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;form method=post&gt;&lt;br /&gt;Please enter password &lt;input type=password name=doddle&gt;&lt;br /&gt;&lt;input type=submit value=go&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt; &lt;br /&gt;&lt;?php } ?&gt;&lt;br /&gt; &lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;a href=http://www.wellho.net&gt;Well House Consultants&lt;/a&gt;, 2007&lt;br /&gt;&lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 04 Oct 2007 09:52:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4614</guid>
      <author>shantanuo (shantanu oak)</author>
    </item>
    <item>
      <title>tinyurl explode</title>
      <link>http://snippets.dzone.com/posts/show/4603</link>
      <description>// check where tinyurl.com is headed to&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    &lt; ?php&lt;br /&gt;&lt;br /&gt;    // tinyurl.php?c=&lt;br /&gt;&lt;br /&gt;    $num = $_GET['c'];&lt;br /&gt;&lt;br /&gt;    if($fp = fsockopen ("tinyurl.com", 80, $errno, $errstr, 30))&lt;br /&gt;    {&lt;br /&gt;    if ($fp) {&lt;br /&gt;    fputs ($fp, "HEAD /$num HTTP/1.0\r\nHost: tinyurl.com\r\n\r\n");&lt;br /&gt;    while (!feof($fp)) {$headers .= fgets ($fp,128);}&lt;br /&gt;    fclose ($fp);&lt;br /&gt;    }&lt;br /&gt;    $arr1=explode("Location:",$headers);&lt;br /&gt;    $arr=explode("\n",trim($arr1[1]));&lt;br /&gt;    echo trim($arr[0]);&lt;br /&gt;    }&lt;br /&gt;    ?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 02 Oct 2007 08:03:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4603</guid>
      <author>shantanuo (shantanu oak)</author>
    </item>
    <item>
      <title>mysql dump to another server</title>
      <link>http://snippets.dzone.com/posts/show/4602</link>
      <description>// Using UNIX pipe concept one can dump database to another server securely using ssh protocol. &lt;br /&gt;// All you need remote execution rights for the &#8216;dd&#8217; command, over SSH.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;mysqldump -u USERnAME -p'PASSWORD' YOUR-DATABASE-NAME | ssh user@remote.server.com "dd of=/mysql/$(date +'%d-%m-%y')"&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 02 Oct 2007 07:57:05 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4602</guid>
      <author>shantanuo (shantanu oak)</author>
    </item>
    <item>
      <title>email addresses using egrep</title>
      <link>http://snippets.dzone.com/posts/show/4582</link>
      <description>// email addresses&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;egrep "\w+([._-]\w)*@\w+([._-]\w)*\.\w{2,4}"&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 28 Sep 2007 03:19:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4582</guid>
      <author>shantanuo (shantanu oak)</author>
    </item>
  </channel>
</rss>
