<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: command code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 16 May 2008 17:51:54 GMT</pubDate>
    <description>DZone Snippets: command code</description>
    <item>
      <title>Twitter and Jaiku from the command line</title>
      <link>http://snippets.dzone.com/posts/show/5265</link>
      <description>The following instructions make it easy to post to Twitter and Jaiku from the command line. The instructions were copied from the article &lt;a href="http://snipr.com/22b38"&gt;"Ubuntu Unleashed: Howto Twitter From the Command Line in Ubuntu!"&lt;/a&gt;  [ubuntu-unleashed.com] and modified to post via Rorbuilder's ProjectX API.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;sudo apt-get install curl&lt;/code&gt;&lt;br /&gt;&lt;code&gt;sudo gedit /usr/bin/jaitwit&lt;/code&gt;&lt;br /&gt;Now Paste this in gEdit and simply replace "YourUsername" with your username and "YourPassword" with your twitter passwd, then replace the Jaiku variables (YourUsername, YourPassword, YourCity, YourAccessKey) and ctrl-s to save, then alt-F4 to exit!&lt;br /&gt;&lt;code&gt;&lt;br /&gt;curl http://rorbuilder.info/api/projectx.cgi?xml_project=%3Cproject%20name=%22micro_blog%22%3E%3Cmethods%3E%3Cmethod%20name=%22post2jaiku%22%3E%3Cparams%3E%3Cparam%20var=%22user%22%20val=%22YourUsername%22/%3E%3Cparam%20var=%22msg%22%20val=%22`echo $@|tr ' ' '+'`%22/%3E%3Cparam%20var=%22location%22%20val=%22YourCity%22/%3E%3Cparam%20var=%22apikey%22%20val=%22YourAccessKey%22/%3E%3C/params%3E%3C/method%3E%3Cmethod%20name=%22post2twitter%22%3E%3Cparams%3E%3Cparam%20var=%22user%22%20val=%22YourUsername%22/%3E%3Cparam%20var=%22msg%22%20val=%22`echo $@|tr ' ' '+'`%22/%3E%3Cparam%20var=%22password%22%20val=%22YourPassword%22/%3E%3C/params%3E%3C/method%3E%3C/methods%3E%3C/project%3E -o /dev/null&lt;br /&gt;echo Message Sent!&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Then chmod for exec privileges:&lt;br /&gt;&lt;code&gt;chmod +x /usr/bin/jaitwit&lt;/code&gt;&lt;br /&gt;Then from the CLI type jaitwit followed by your message.&lt;br /&gt;&lt;code&gt;jaitwit "message here without the quotes"&lt;/code&gt;</description>
      <pubDate>Fri, 21 Mar 2008 18:28:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5265</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <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>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>Using Ruby to delete a file directory </title>
      <link>http://snippets.dzone.com/posts/show/4913</link>
      <description>In this example the file we want to delete is a non-empty directory called sample. &lt;br /&gt;&lt;code&gt;&lt;br /&gt;  require 'fileutils' &lt;br /&gt;&lt;br /&gt;  FileUtils.rm_r 'sample'&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 22 Dec 2007 14:06:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4913</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Install vmware tools on ubuntu</title>
      <link>http://snippets.dzone.com/posts/show/4709</link>
      <description>Install vmware tools tar file on ubuntu from http://www.howtogeek.com/howto/ubuntu/install-vmware-tools-on-ubuntu-edgy-eft/&lt;br /&gt;The first thing that is important is that you will need to know is&lt;br /&gt;that you have to install the compilation utilities, which aren't &lt;br /&gt;installed by default. Run these commands to get you started:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;sudo apt-get install build-essential&lt;br /&gt;sudo apt-get install linux-headers-`uname -r`&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now you'll want to navigate to the VM \ Install VMware Tools menu:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;cp /cdrom/*.gz /tmp/&lt;br /&gt;cd /tmp&lt;br /&gt;tar xvzf VM*.gz&lt;br /&gt;cd vmware*&lt;br /&gt;sudo ./vmware-install.pl&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 29 Oct 2007 08:08:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4709</guid>
      <author>fatgy (fat)</author>
    </item>
    <item>
      <title>Parsing simple command line arguments in java, using the the Commons CLI library.</title>
      <link>http://snippets.dzone.com/posts/show/3504</link>
      <description>// Skeleton to read in two command line arguments, one mandatory, one optional&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;package snippets;&lt;br /&gt;&lt;br /&gt;import org.apache.commons.cli.*;&lt;br /&gt;&lt;br /&gt;/* &lt;br /&gt; * Stub program that reads command line arguments&lt;br /&gt; */&lt;br /&gt;public class CommandLineProgram {&lt;br /&gt;&lt;br /&gt;	private static Options options = null; // Command line options&lt;br /&gt;	&lt;br /&gt;	private static final String PROPERTIES_LOCATION_OPTION = "f";&lt;br /&gt;	private static final String OUTPUT_FILE_OPTION = "o";&lt;br /&gt;	private static final String DEFAULT_OUTPUT_FILE = "out.feed";&lt;br /&gt;	&lt;br /&gt;	private CommandLine cmd = null; // Command Line arguments&lt;br /&gt;	&lt;br /&gt;	private String outputFile = DEFAULT_OUTPUT_FILE;&lt;br /&gt;	&lt;br /&gt;	static{&lt;br /&gt;		options = new Options();&lt;br /&gt;		options.addOption(PROPERTIES_LOCATION_OPTION, true, &lt;br /&gt;				"Data file location");&lt;br /&gt;		options.addOption(OUTPUT_FILE_OPTION, false, "Output file. " + DEFAULT_OUTPUT_FILE + " by default ");&lt;br /&gt;		&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	/**&lt;br /&gt;	 * @param args&lt;br /&gt;	 */&lt;br /&gt;	public static void main(String[] args) {&lt;br /&gt;		&lt;br /&gt;		CommandLineProgram cliProg = new CommandLineProgram();&lt;br /&gt;		cliProg.loadArgs(args);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	/**&lt;br /&gt;	 * Validate and set command line arguments.&lt;br /&gt;	 * Exit after printing usage if anything is astray&lt;br /&gt;	 * @param args String[] args as featured in public static void main()&lt;br /&gt;	 */&lt;br /&gt;	private void loadArgs(String[] args){&lt;br /&gt;		CommandLineParser parser = new PosixParser();&lt;br /&gt;		try {&lt;br /&gt;			cmd = parser.parse(options, args);&lt;br /&gt;		} catch (ParseException e) {&lt;br /&gt;			System.err.println("Error parsing arguments");&lt;br /&gt;			e.printStackTrace();&lt;br /&gt;			System.exit(1);&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		// Check for mandatory args&lt;br /&gt;		&lt;br /&gt;		if (! cmd.hasOption(PROPERTIES_LOCATION_OPTION)){&lt;br /&gt;			HelpFormatter formatter = new HelpFormatter();&lt;br /&gt;			formatter.printHelp("java -jar this_jar.jar", options);&lt;br /&gt;			System.exit(1);&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		// Look for optional args.&lt;br /&gt;		&lt;br /&gt;		if (cmd.hasOption(OUTPUT_FILE_OPTION)){&lt;br /&gt;			outputFile = cmd.getOptionValue(OUTPUT_FILE_OPTION);&lt;br /&gt;			&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 13 Feb 2007 00:51:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3504</guid>
      <author>tunaranch (Haikal Saadh)</author>
    </item>
    <item>
      <title>Linux - command ls without color</title>
      <link>http://snippets.dzone.com/posts/show/3177</link>
      <description>// Elimina tutti i caratteri speciali che portano il colore&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ls --color=never&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 19 Dec 2006 22:55:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3177</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>yubnub.py</title>
      <link>http://snippets.dzone.com/posts/show/3120</link>
      <description>&lt;code&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;&lt;br /&gt;__author__="Andrew Pennebaker (andrew.pennebaker@gmail.com)"&lt;br /&gt;__date__="9 Dec 2006 - 10 Dec 2006"&lt;br /&gt;__copyright__="Copyright 2006 Andrew Pennebaker"&lt;br /&gt;__license__="GPL"&lt;br /&gt;__version__="0.0.1"&lt;br /&gt;__credits__="Based on Yubnub for Windows (http://www.opbarnes.com/blog/Programming/OPB/Utilities/yubnub.html)"&lt;br /&gt;__URL__="http://snippets.dzone.com/posts/show/3120"&lt;br /&gt;&lt;br /&gt;from html2txt import html2txt&lt;br /&gt;&lt;br /&gt;import webbrowser&lt;br /&gt;from urllib import urlopen&lt;br /&gt;import re&lt;br /&gt;&lt;br /&gt;import sys&lt;br /&gt;from getopt import getopt&lt;br /&gt;&lt;br /&gt;PARSER="http://yubnub.org/parser/parse?command="&lt;br /&gt;&lt;br /&gt;BROWSER_MODE="BROWSER"&lt;br /&gt;PLAIN_MODE="PLAIN"&lt;br /&gt;&lt;br /&gt;def space2plus(s):&lt;br /&gt;	return "+".join(s.split())&lt;br /&gt;&lt;br /&gt;def yubnub(command=""):&lt;br /&gt;	global PARSER&lt;br /&gt;&lt;br /&gt;	return PARSER+space2plus(command)&lt;br /&gt;&lt;br /&gt;def yubnubBrowser(command):&lt;br /&gt;	return webbrowser.open(yubnub(command))&lt;br /&gt;&lt;br /&gt;def cleanHTML(html):&lt;br /&gt;	h=html2txt()&lt;br /&gt;	h.feed(html)&lt;br /&gt;	h.close()&lt;br /&gt;&lt;br /&gt;	return h.output()&lt;br /&gt;&lt;br /&gt;def yubnubPlain(command, clean=True):&lt;br /&gt;	command=yubnub(command)&lt;br /&gt;&lt;br /&gt;	try:&lt;br /&gt;		url=urlopen(command)&lt;br /&gt;		lines=url.readlines()&lt;br /&gt;		url.close()&lt;br /&gt;&lt;br /&gt;		lines="".join(lines)&lt;br /&gt;&lt;br /&gt;		if clean:&lt;br /&gt;			return cleanHTML(lines)&lt;br /&gt;&lt;br /&gt;		return lines&lt;br /&gt;&lt;br /&gt;	except IOError, e:&lt;br /&gt;		return "Error connecting to "+command&lt;br /&gt;&lt;br /&gt;def usage():&lt;br /&gt;	print "Usage: "+sys.argv[0]+" [options] &lt;command&gt;"&lt;br /&gt;	print "-b --browser"&lt;br /&gt;	print "\n--plain (default)"&lt;br /&gt;	print "\t-c --clean (default)"&lt;br /&gt;	print "\t-d --dirty"&lt;br /&gt;	print "\n--parser &lt;parser&gt; (experimental)"&lt;br /&gt;	print "\n-h --help"&lt;br /&gt;&lt;br /&gt;	sys.exit()&lt;br /&gt;&lt;br /&gt;def main():&lt;br /&gt;	global PARSER&lt;br /&gt;&lt;br /&gt;	global BROWSER_MODE&lt;br /&gt;	global PLAIN_MODE&lt;br /&gt;&lt;br /&gt;	mode=PLAIN_MODE&lt;br /&gt;	parser=PARSER&lt;br /&gt;	clean=True&lt;br /&gt;&lt;br /&gt;	systemArgs=sys.argv[1:]&lt;br /&gt;	optlist, args=[], []&lt;br /&gt;	try:&lt;br /&gt;		optlist, args=getopt(systemArgs, "bhcd", ["browser", "plain", "clean", "dirty", "parser=", "help"])&lt;br /&gt;	except:&lt;br /&gt;		usage()&lt;br /&gt;&lt;br /&gt;	for option, value in optlist:&lt;br /&gt;		if option=="-h" or option=="--help":&lt;br /&gt;			usage()&lt;br /&gt;&lt;br /&gt;		elif option=="-b" or option=="--browser":&lt;br /&gt;			mode=BROWSER_MODE&lt;br /&gt;		elif option=="--plain":&lt;br /&gt;			mode=PLAIN_MODE&lt;br /&gt;		elif option=="-c" or option=="--clean":&lt;br /&gt;			clean=True&lt;br /&gt;		elif option=="-d" or option=="--dirty":&lt;br /&gt;			clean=False&lt;br /&gt;		elif option=="--parser":&lt;br /&gt;			parser=value&lt;br /&gt;&lt;br /&gt;	command=" ".join(args)&lt;br /&gt;&lt;br /&gt;	if mode==BROWSER_MODE:&lt;br /&gt;		yubnubBrowser(command)&lt;br /&gt;	elif mode==PLAIN_MODE:&lt;br /&gt;		for line in yubnubPlain(command, clean):&lt;br /&gt;			sys.stdout.write(line)&lt;br /&gt;		print ""&lt;br /&gt;&lt;br /&gt;if __name__=="__main__":&lt;br /&gt;	main()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 10 Dec 2006 08:16:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3120</guid>
      <author>mcandre (Andrew Pennebaker)</author>
    </item>
    <item>
      <title>Delete empty directories (UNIX)</title>
      <link>http://snippets.dzone.com/posts/show/3012</link>
      <description>// Shell command to delete empty directories. May have to run several times to get everything.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;find . -type d -empty | xargs rmdir -&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 18 Nov 2006 03:21:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3012</guid>
      <author>jasonbentley (Jason Bentley)</author>
    </item>
    <item>
      <title>UNIX tar Commands</title>
      <link>http://snippets.dzone.com/posts/show/1976</link>
      <description>// how the heck do you do the stuff you do with zip but with tar&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;create tar file&lt;br /&gt;tar cvf filename.tar monkey.txt monkey2.txt&lt;br /&gt;&lt;br /&gt;add a file&lt;br /&gt;tar uvf filename.tar monkey.txt&lt;br /&gt;&lt;br /&gt;extract tar file&lt;br /&gt;tar xvf filename.tar&lt;br /&gt;&lt;br /&gt;list contents&lt;br /&gt;tar tf monkey.tar&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 03 May 2006 20:37:24 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1976</guid>
      <author>offspinner ()</author>
    </item>
  </channel>
</rss>
