<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: cli code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 02:53:05 GMT</pubDate>
    <description>DZone Snippets: cli 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://joanatrindade.wikidot.com"&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>ARGV Parser</title>
      <link>http://snippets.dzone.com/posts/show/5099</link>
      <description>This function parse ARGV and return a string.&lt;br /&gt;See exemples for more informations :&lt;br /&gt;&lt;br /&gt;// Go : http://blackh.badfile.net/wordz/&lt;br /&gt;&lt;br /&gt;Function :&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  def options(param)&lt;br /&gt;  &lt;br /&gt;	i = 0&lt;br /&gt;		ARGV.each  { |valeur|&lt;br /&gt;		&lt;br /&gt;    		if (valeur == '-' + param.to_s)&lt;br /&gt;				return ARGV[i+1]&lt;br /&gt;			elseif (valeur != '-' + param.to_s)&lt;br /&gt;				return false&lt;br /&gt;			end&lt;br /&gt;		i += 1&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;   end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Usage :&lt;br /&gt;&lt;br /&gt;// cmd&gt; ruby test.rb -o foo&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;	out =  self.options('o')&lt;br /&gt;&lt;br /&gt;	if (out != false and out.empty? == false)&lt;br /&gt;                   puts out # print -&gt; foo&lt;br /&gt;	end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 03 Feb 2008 20:24:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5099</guid>
      <author>Black_H (Black_H)</author>
    </item>
    <item>
      <title>MySQL Database Size</title>
      <link>http://snippets.dzone.com/posts/show/4117</link>
      <description>&lt;code&gt;mysql -uroot -D sfcnet_development -e "show table status\G"| egrep "(Index|Data)_length" | awk 'BEGIN { rsum = 0 } { rsum += $2 } END { print rsum }'&lt;/code&gt;</description>
      <pubDate>Fri, 08 Jun 2007 14:51:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4117</guid>
      <author>willcodeforfoo ()</author>
    </item>
    <item>
      <title>Mount SSH using MacFUSE</title>
      <link>http://snippets.dzone.com/posts/show/3342</link>
      <description>This will also list the voume in the Finder, thanks to the volname option (I think)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;mkdir -p ~/mnts/formandfx&lt;br /&gt;sshfs kmarsh@formandfx.com: ~/mnts/formandfx -oping_diskarb,volname=formandfx&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 21 Jan 2007 23:14:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3342</guid>
      <author>willcodeforfoo ()</author>
    </item>
    <item>
      <title>Bandwidth Monitoring From the Console Using 'pktstat'</title>
      <link>http://snippets.dzone.com/posts/show/1324</link>
      <description>Pktstat, http://www.adaptive-enterprises.com.au/~d/software/pktstat/, displays a real-time summary of packet activity on an interface. Each line displays the data rate associated with a particular class of packets. The class is determined by the packet header.&lt;br /&gt;&lt;br /&gt;For example, 'pktstat -w1' will refresh once per second showing the average bandwidth usage and active connections:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# pktstat -w1&lt;br /&gt;&lt;br /&gt;  interface: eth0 &lt;br /&gt;  load averages: 285.9k 167.3k 67.3k bps &lt;br /&gt;&lt;br /&gt;    bps    % desc &lt;br /&gt;  466.8   0% arp &lt;br /&gt;             tcp 205.188.1.192:5190 &lt;-&gt; c-24-21-74-176:1472 &lt;br /&gt;   6.0k   0% tcp c-24-21-74-176:3933 &lt;-&gt; host75:3724 &lt;br /&gt;  63.5k   1% tcp c-24-21-74-176:4662 &lt;-&gt; p50906304:61951 &lt;br /&gt;  27.4k   0% udp 10.141.192.1:bootps &lt;-&gt; 255.255.255.255:bootpc&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 01 Feb 2006 01:30:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1324</guid>
      <author>nihilist (David)</author>
    </item>
    <item>
      <title>Correcting a command</title>
      <link>http://snippets.dzone.com/posts/show/1323</link>
      <description>If you've run a command that you discover needs a path, you can do something like this on the following line:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$ psql -U postgres mydb_here&lt;br /&gt;bash: psql: command not found&lt;br /&gt;&lt;br /&gt;$ /usr/local/pgsql/bin/!!&lt;br /&gt;/usr/local/pgsql/bin/psql -U postgres mydb_here&lt;br /&gt;&lt;br /&gt;Welcome to psql 7.3.5, the PostgreSQL interactive terminal.&lt;br /&gt;mydb_here=#&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Or if you mistyped the path:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$ /usr/loca/pgsql/bin/psql -U postgres mydb_here&lt;br /&gt;-bash: /usr/loca/pgsql/bin/psql: No such file or directory&lt;br /&gt;&lt;br /&gt;$ ^loca^local&lt;br /&gt;usr/local/pgsql/bin/psql -U postgres mydb_here&lt;br /&gt;&lt;br /&gt;Welcome to psql 7.3.5, the PostgreSQL interactive terminal.&lt;br /&gt;mydb_here=#&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 01 Feb 2006 01:27:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1323</guid>
      <author>nihilist (David)</author>
    </item>
    <item>
      <title>Model, View, Controller HOWTO</title>
      <link>http://snippets.dzone.com/posts/show/1050</link>
      <description>MVC howto&lt;br /&gt;Original vrsion can be found at http://kbrooks.ath.cx/mvchowto/intro.py&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/python&lt;br /&gt;&lt;br /&gt;# MVC Howto - Introduction &amp; code&lt;br /&gt;# What is "MVC"?&lt;br /&gt;#   MVC stands for "Model", "View" &amp; "Controller", a way of seperating your code into&lt;br /&gt;#   manageable and independent chunks that can be changed easily.&lt;br /&gt;# Why use MVC?&lt;br /&gt;#   Because code is independent from each other, it becomes easier for you to change part of the code to do what you want.&lt;br /&gt;#   For example, you could change where data is shown without changing anything else!&lt;br /&gt;# Copyright (c) 2006 Kyle Brooks. Licensed under the Creative Commons Attribution License.&lt;br /&gt;# We will be creating a command line calculator in this HOWTO.&lt;br /&gt;import sys&lt;br /&gt;# Model: a object that interfaces with the real world and returns information.&lt;br /&gt;&lt;br /&gt;class Model:&lt;br /&gt;    def calculate(self, left, op, right):&lt;br /&gt;        if op == "+":&lt;br /&gt;            return left + right&lt;br /&gt;        elif op == "-":&lt;br /&gt;            return left - right&lt;br /&gt;# As you see in the code above, the model has the action "calculate".&lt;br /&gt;&lt;br /&gt;# View: a object that gets passed the result from the model via the controller. Displays data.&lt;br /&gt;class View:&lt;br /&gt;    def display_data(self, result):&lt;br /&gt;        print result&lt;br /&gt;# As you see in the code above, ALL the view does is display data from the controller.&lt;br /&gt;&lt;br /&gt;# Controller: a object that holds a reference to the model and view. Communicates with the model and view. Handles data from the user.&lt;br /&gt;class Controller:&lt;br /&gt;    operands = ["+", "-"]&lt;br /&gt;    def __init__(self, model, view):&lt;br /&gt;        self.model = model&lt;br /&gt;        self.view = view&lt;br /&gt;    def run(self):&lt;br /&gt;        sys.stdout.write("&gt;&gt; ")&lt;br /&gt;        sys.stdout.flush()&lt;br /&gt;        # read a line&lt;br /&gt;        line = sys.stdin.readline()&lt;br /&gt;        line = line.strip()&lt;br /&gt;        if line == "":&lt;br /&gt;            sys.stdout.write("\n&gt;&gt; ")&lt;br /&gt;            sys.stdout.flush()&lt;br /&gt;            return&lt;br /&gt;        for operand in self.operands:&lt;br /&gt;            larray = line.split(operand)&lt;br /&gt;            if larray[0] == line:&lt;br /&gt;                continue&lt;br /&gt;            else:&lt;br /&gt;                break&lt;br /&gt;        else:&lt;br /&gt;            sys.stdout.write("NaN\n")&lt;br /&gt;            sys.stdout.flush()&lt;br /&gt;            return&lt;br /&gt;        larray[0] = int(larray[0])&lt;br /&gt;        larray[2] = int(larray[0])&lt;br /&gt;        result = self.model.calculate(*larray)&lt;br /&gt;        self.view.display_data(result)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 04 Jan 2006 15:19:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1050</guid>
      <author>kbrooks ()</author>
    </item>
    <item>
      <title>Test&#227;?&#160;&#227;&#8218;&#710;&#239;&#189;&#382;</title>
      <link>http://snippets.dzone.com/posts/show/910</link>
      <description>arectwevw</description>
      <pubDate>Thu, 24 Nov 2005 16:13:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/910</guid>
      <author>test1111 (test1111)</author>
    </item>
    <item>
      <title>Mail a file as an attachment from the UNIX prompt</title>
      <link>http://snippets.dzone.com/posts/show/589</link>
      <description>&lt;code&gt;uuencode file.txt file.txt | mail email@address.com&lt;/code&gt;</description>
      <pubDate>Mon, 22 Aug 2005 03:34:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/589</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>Easy file encryption and decryption from the shell</title>
      <link>http://snippets.dzone.com/posts/show/341</link>
      <description>Works on OS X, Linux, anywhere with OpenSSL installed:&lt;br /&gt;&lt;br /&gt;To encrypt a file:&lt;br /&gt;&lt;code&gt;openssl des3 -salt -in infile.txt -out encryptedfile.txt&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;To decrypt the file:&lt;br /&gt;&lt;code&gt;openssl des3 -d -salt -in encryptedfile.txt -out normalfile.txt&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Do not specify the same file as input and output on encryption.. I have noticed weird effects on OS X (it eats the file). Remove the -in * stuff if you want to pipe data into it (e.g. a tarred folder). Omit the -out * stuff if you want it to pipe data out on STDOUT.</description>
      <pubDate>Fri, 27 May 2005 11:17:25 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/341</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
  </channel>
</rss>
