tag:blogger.com,1999:blog-83963795743725608662024-03-12T19:41:53.051-07:00Nerdy Sermonsby Vamsi EmaniVamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.comBlogger50125tag:blogger.com,1999:blog-8396379574372560866.post-3766140936198989032016-03-14T22:20:00.001-07:002016-03-14T22:20:59.558-07:00Getting Started with Apache Spark: Find maximum commits by an author in a git log file<div dir="ltr" style="text-align: left;" trbidi="on">
- Install sbt. (scala build tool)<br />
- Install apache-spark.<br />
- Go to the unzipped apache-spark directory and in command line run<br />
<span style="font-family: "courier new" , "courier" , monospace;">sbt assembly</span><br />
<br />
(this takes a while, one may have to increase the memory allocated to run this in config file)<br />
<i><br /></i>
- Clone some git project<br />
<span style="font-family: "courier new" , "courier" , monospace;">git clone https://github.com/apache/groovy</span><br />
<br />
- Save the log into a text file<br />
<span style="font-family: "courier new" , "courier" , monospace;">git log > C:\\temp\\log.txt</span><br />
<br />
- Launch spark terminal and execute :<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">scala> val file = sc.textFile("C:\\temp\\log.txt")</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">file: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[21] at textFile at <console>:27</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">scala> val authorLines = file.filter(line => line.contains("Author"))</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">authorLines: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[22] at filter at <console>:29</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">scala> var maxAuthorTuple = authorLines.countByValue().maxBy(_._2)</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">maxAuthorTuple: (String, Long) = (Author: Paul King <paulk@asert.com.au>,2991)</span><br />
<br />
- Verify that maxAuthorTuple has the author who made maximum commits in that branch with the number of commits.<br />
<br />
<br /></div>
Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-70560101778128674072015-09-15T02:48:00.002-07:002015-09-15T02:48:42.553-07:00Basic Authentication using Groovy <div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial, Helvetica, sans-serif;">Here is a very minimal groovy based Basic Authentication Client which can come handy whilst talking to APIs.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">def jsonBody = '{"day" : "11", "month" : "03", "year" : "2010", "hour" : "09", "min" : "08", "lat" : "18.9750", "lon" : "72.8258", "tzone" : "5.5", "gender" : "male"}'</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">new BasicAuthClient(</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> userName:"xyzzy",</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> password:"ba4d90e133ad76b103fcedcd00ab5681", </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> address:"https://api.vedicrishiastro.com/v1/basic_panchang/"</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">).doPost(jsonBody)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;">class BasicAuthClient{</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Arial, Helvetica, sans-serif;"> def userName, password, address, conn</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> def getAuthHeader(){</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> def authHeader = "$userName:$password".getBytes().encodeBase64().toString()</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> println(authHeader)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> return authHeader</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> def getConnection(){</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> this.conn = address.toURL().openConnection()</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> conn.setDoOutput(true)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> conn.setRequestMethod("POST")</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> conn.setRequestProperty("Authorization", "Basic ${getAuthHeader()}")</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> return conn</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> def doPost(body){</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> def out = getConnection().getOutputStream(); </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> out.write(body.getBytes()) </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> out.close();</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> return getResponse()</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> def getResponse(){</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> def responseCode = conn.getResponseCode();</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> println(responseCode)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> def instream = responseCode < 207 ? conn.getInputStream() : conn.getErrorStream() </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> int i = instream.read()</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> while (i != -1) {</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> print((char)i)</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> i = instream.read()</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> } </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> instream.close()</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> conn.disconnect()</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;">} </span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span>
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"> </span></div>
Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-51487907445869777782015-06-16T23:57:00.003-07:002015-06-16T23:59:32.806-07:00ConEmu for developer productivity<div dir="ltr" style="text-align: left;" trbidi="on">
For the last one and half years, I have been a loyal user of <a href="http://sourceforge.net/projects/console/" target="_blank">Console 2</a>, an alternative to command prompt on windows. Now, I have moved on to <a href="http://sourceforge.net/projects/conemu/" target="_blank">ConEmu </a>for better productivity at workplace. It comes with many settings for customization. What I really love in ConEmu is its split screen support. At times when one is even lazy to shift between tabs/windows. In conjunction with vim, it is a breeze.<br />
<br />
Say, you have an executable jar that also produces a log file. To hell with notepad and other UI editors - You could simply split your ConEmu screen to open up two or more console windows and spare one to skim through the output log file (using vim) simultaneously as and when you run the executable through an other.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-id_ldvH1eHk/VYEZkAzaVeI/AAAAAAAABic/eIKJa5I92wk/s1600/ConEmu.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="356" src="http://1.bp.blogspot.com/-id_ldvH1eHk/VYEZkAzaVeI/AAAAAAAABic/eIKJa5I92wk/s640/ConEmu.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The only caveat that I see with conEmu is that it eats up a tad bit more of memory than Console2 does (around 40 MB). But I guess I can live with that considering the fact that my laptop is powered with 16 GB of RAM. :)</div>
<br /></div>
Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-29574290073761928922015-06-03T02:49:00.001-07:002015-06-03T02:49:10.230-07:00VIM - first things first<div dir="ltr" style="text-align: left;" trbidi="on">
Install theme :<br />
<br />
https://benaiah41.wordpress.com/2012/01/17/customizing-gvim-in-windows-7/<br />
<br />
Append the following lines in ../.vimrc (Startup Settings)<br />
<br />
set guifont=Consolas:h11:cDEFAULT<br />
color wombat<br />
set guioptions-=T<br />
set nu<br />
let g:netrw_liststyle=3<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-DXBGBMhfI-s/VW7NB92LKDI/AAAAAAAABhw/8nbXkcHBumw/s1600/test.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="336" src="http://3.bp.blogspot.com/-DXBGBMhfI-s/VW7NB92LKDI/AAAAAAAABhw/8nbXkcHBumw/s400/test.png" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com1tag:blogger.com,1999:blog-8396379574372560866.post-36874255368116934462014-12-22T23:14:00.000-08:002014-12-22T23:14:53.590-08:00Command Pattern in java/groovy<div dir="ltr" style="text-align: left;" trbidi="on">
Command pattern encapsulates a request. A command pattern maybe used whenever there is a Sender, Receiver who communicate via a request (let's call it command). Assume, we simulate the game of cricket via a Simulator class which sends commands to the Batsman objects to play certain shots. Each shot is a command given by the simulator to a batsman.<br />
<br />
interface Shot{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void execute();<br />
}<br />
<br />
class CoverDrive implements Shot{<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private Batsman batter;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void execute(){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>batter.playCoverDrive()<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
}<br />
<br />
class straightDrive implements Shot{<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private Batsman batter;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void execute(){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>batter.playStraightDrive();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
}<br />
<br />
class Batsman{<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>def playCoverDrive(){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>println("Cover drive")<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>def playStraightDrive(){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>println("Cover drive")<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
}<br />
<br />
class BatSimulator{<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Shot shot<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>def play(){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>shot.execute()<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
}<br />
<br />
// main - groovy script start<br />
<br />
def sachin = new Batsman()<br />
def command = new CoverDrive(batter : sachin)<br />
def simulator = new BatSimulator(shot : command)<br />
simulator.play()</div>
Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-45946135446132607722014-12-15T06:31:00.002-08:002014-12-15T06:37:17.041-08:00Write a custom event handler in groovy/java<div dir="ltr" style="text-align: left;" trbidi="on">
One may write a couple of classes and an interface to achieve event handling without having to implement the Observable/Observer interface. Assume, we have a computer that runs several processes. If it receives a shutdown command, we fire an event to let the running process handle its own clean up method to release resources and halt execution.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">interface ShutdownListener{</span><br />
<span style="font-family: Courier New, Courier, monospace;"> public void handle();<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">public class Computer{</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Courier New, Courier, monospace;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace;"> private def listeners = []</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> def addShutdownListener(ShutdownListener l){</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>listeners.add(l)</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> def shutdown(){<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(ShutdownListener l : listeners)</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>l.handle()</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> def compute(){ // whatever }</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">public class Process implements ShutdownListener{</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Courier New, Courier, monospace;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace;"> public void handle(){<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// release resources of "this" Process </span><br />
<span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// halt execution of self</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>println("Process ended.");</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">//groovy script start </span><br />
<span style="font-family: Courier New, Courier, monospace;">def computer = new Computer()</span><br />
<span style="font-family: Courier New, Courier, monospace;">def process = new Process()</span><br />
<span style="font-family: Courier New, Courier, monospace;">computer.addShutdownListener(process)</span><br />
<span style="font-family: Courier New, Courier, monospace;">computer.compute()</span><br />
<span style="font-family: Courier New, Courier, monospace;">computer.shutdown()</span><br />
<div>
<br /></div>
</div>
Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-27221899529821501312014-10-20T01:47:00.002-07:002014-10-20T01:47:38.051-07:00Simple way to implement find(select) and collect block closures in java<div dir="ltr" style="text-align: left;" trbidi="on">
Languages like ruby, groovy, smalltalk have language constructs for blocks and closures. Java 8 now has feature to evaluate lambda expressions. But here is one simple and straight way to implement the same:<br />
<br />
<b>In groovy :</b><br />
<br />
[1, 2, 3, 10, 20, 30].findAll { num -> num > 5 }<br />
=> yields a new list [10, 20, 30]<br />
<br />
[ 1, 2, 3, 4 ].collect{ num -> num * num}<br />
=> yields a new list [1, 4, 9, 16]<br />
<br />
The above code for those more familiar with the smalltalk syntax will be:<br />
<br />
#(1 2 3 10 20 30) select: [ :num | num > 5 ]<br />
==> displays [10, 20, 30]<br />
<br />
#( 1 2 3 4 ) collect: [:i | i * i ].<br />
==> displays [1, 4, 9, 16]<br />
<br />
In java, the same could be implemented with a set of abstract classes as a collection utility that mandate implementation of method which returns the boolean condition to add or transform the element under iteration :<br />
<div>
<br /></div>
<div>
<div>
<b><span style="font-family: Courier New, Courier, monospace;">Find.java</span></b></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">abstract class Find extends ArrayList{ </span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> /** let the default constructor worry about iteration **/</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> public Find(List list){ </span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> Iterator it = list.iterator();</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> while(it.hasNext()){</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> Object element = it.next(); </span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> if(all(element)) </span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> this.add(element); </span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> }</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> }</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> </span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> /** This defines the boolean condition for find/select **/</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> public abstract Boolean all(Object obj);</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"> </span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">}</span></div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><div>
<b>FindDemo.java<br /></b></div>
<div>
// find all elements in the list that are greater than 5</div>
<div>
List list = Arrays.asList(1, 2, 3, 10, 20, 30);</div>
<div>
selected = new Find(list) {</div>
<div>
public Boolean all(Object num) { </div>
<div>
return (int) num > 5;</div>
<div>
}</div>
<div>
};</div>
<div>
// => yields a new list [10, 20, 30]</div>
<div>
<br /></div>
<div>
<div>
<div>
<b>Collect.java</b></div>
<div>
abstract class Collect extends ArrayList{ </div>
<div>
/** let the default constructor worry about iteration **/</div>
<div>
public Collect(List list){</div>
<div>
Iterator it = list.iterator();</div>
<div>
while(it.hasNext()){</div>
<div>
Object element = it.next();</div>
<div>
Object transformed = transform(element);</div>
<div>
this.add(transformed);</div>
<div>
}</div>
<div>
}</div>
<div>
/** This defines the transformation logic for collect **/</div>
<div>
public abstract Object transform(Object obj);</div>
<div>
}</div>
</div>
</div>
<div>
<br /></div>
<div>
<div>
<b>CollectDemo.java</b></div>
<div>
// collect the squares of all elements in the list</div>
<div>
List list = Arrays.asList(1, 2, 3, 4);</div>
<div>
collected = new Collect(list) { </div>
<div>
public Object transform(Object num) {</div>
<div>
return (int) num * (int) num;</div>
<div>
}</div>
<div>
};</div>
<div>
// => yields a new list [1, 4, 9, 16]</div>
</div>
</span></div>
</div>
Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-69070718303980218252014-10-11T02:05:00.000-07:002014-10-11T02:05:44.177-07:00Gauss Circle Problem<div dir="ltr" style="text-align: left;" trbidi="on">
Can do better without two loops :-|<br />
<div>
<br /></div>
<div>
<br /></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;">latticePoints = 0<br />radius = 3.2<br />mod = int(radius) + 1<br /><br />def isInCircle(x, y):<br /> return x*x + y*y <= radius*radius<br /><br />def calc(x, y):<br /> global latticePoints<br /> if x == 0 and y == 0:<br /> latticePoints = latticePoints + 1<br /> print((x, y))<br /> elif x == 0 and y != 0:<br /> latticePoints = latticePoints + 2<br /> print((x, y),(x, -y)) <br /> elif x != 0 and y == 0:<br /> latticePoints = latticePoints + 2<br /> print((x, y),(-x, y)) <br /> else :<br /> latticePoints = latticePoints + 4<br /> print((x, y), (-x, -y), (x, -y), (-x, y)) <br /><br />for i in range(mod) :<br /> for j in range(mod) :<br /> if(isInCircle(i,j)):<br /> calc(i,j)<br /> <br />print(latticePoints)</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-mXZJ5O_HuBc/VDjygdTPtTI/AAAAAAAABdA/NX3vB5JnE6o/s1600/gauss%2Bcircle.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Courier New, Courier, monospace;"><img border="0" src="http://3.bp.blogspot.com/-mXZJ5O_HuBc/VDjygdTPtTI/AAAAAAAABdA/NX3vB5JnE6o/s1600/gauss%2Bcircle.jpg" height="179" width="320" /></span></a></div>
<div>
<br />
<div>
<br /></div>
<div>
<br /></div>
</div>
</div>
</div>
Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-2439647570850678902013-11-06T10:51:00.003-08:002015-07-21T05:00:15.272-07:00Fun with Git<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Baby steps : </b><br />
<br />
1) create an account on github<br />
2) create a git repository. Note down the repo URL.<br />
<br />
<b>Install git from terminal : </b><br />
<br />
sudo apt-get install git<br />
<br />
<b>Code Upload :</b><br />
cd Scripts (or any new folder)<br />
git init (local initialization. creates a local .git folder)<br />
mkdir YourProjectDirectory (and add all source files under it).<br />
git add .<br />
git commit (commits the added source files to the local repository)<br />
git remote add origin yourRepoURL (ex: https://github.com/vamsi-emani/pythonscripts.git)<br />
git pull origin master (to sync with remote copy)<br />
git push origin master (commits all the local changes to remote repository)<br />
<br />
<b>To delete a directory: </b><br />
git rm -r local-directory-name (recursively remove all local directory files)<br />
git commit (commits to local repo)<br />
git push origin master (commits to remote repo)<br />
<br />
<b>Checkout a branch : </b><br />
git checkout -b dev_temp origin/test<br />
(creates a local branch dev_temp from remote branch named test)<br />
<br />
<b>List local branches only :</b><br />
git branch<br />
<br />
<b>List local and remote branches : </b><br />
git branch -a<br />
<br />
<b>List all commits on all branches that aren't pushed yet</b><br />
git log --branches --not --remotes<br />
<br />
<b>View commits on a branch (lists out the commits with their hashes)</b><br />
git log dev_temp<br />
<br />
<b>View what's in a specific commit </b><br />
git log commit-hash<br />
<br />
<b>Remove untracked files</b><br />
git clean -f --dry-run (to know the damage before doing the action)<br />
git clean -f (to actually delete the untracked files)<br />
<br />
<b>Remove untracked files and directories</b><br />
git clean -f -d</div>
Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-17007565655012253432013-07-04T06:28:00.002-07:002013-07-04T06:28:27.015-07:00SVN checkout and Sonar Ant Task Run<div dir="ltr" style="text-align: left;" trbidi="on">
The ant script below checks out a java project from a given svn url and runs the downloaded source files against sonar.<br /><br /><b>Prerequisites: </b><br />
<br />
SVN Client installed<br />
Included jars on classpath : ant.jar, sonar-ant-task-2.1.jar, svnjavahl.jar, svnClientAdapter.jar, svnant.jar<br />
<br />
<b>build.xml (Highlighted portions in red are to be set by user/setup dependent)</b><br />
<b><br /></b>
<?xml version="1.0" encoding="UTF-8"?><br />
<br />
<project name="Update" basedir="." default="update" xmlns:sonar="antlib:org.sonar.ant"><br />
<br />
<path id="svnant.classpath"><br />
<fileset dir="lib"> <br />
<include name="**/*.jar" /><br />
</fileset><br />
</path><br />
<br />
<property name="project.svn.url" <span style="color: red;">value="your-svn-url-of-project"</span> /><br />
<br />
<!-- <taskdef resource="svntask.properties" /> --><br />
<taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpathref="svnant.classpath"/><br />
<br />
<target name="update"><br />
<svn><br />
<checkout url="${project.svn.url}" revision="HEAD" <span style="color: red;">destPath="MyProject"</span> /><br />
</svn><br />
</target><br />
<br />
<property name="sonar.jdbc.url" <span style="color: red;">value="jdbc:h2:tcp://localhost:9092/sonar"</span> /><br />
<property name="sonar.jdbc.username" value="sonar" /><br />
<property name="sonar.jdbc.password" value="sonar" /><br />
<property name="sonar.projectKey" value="org.codehaus.sonar:example-java-ant" /><br />
<property name="sonar.projectName" value="Sonar Sample Project Ant Run" /><br />
<property name="sonar.projectVersion" value="1.0"/><br />
<property name="sonar.language" value="java" /><br />
<property name="sonar.sources" <span style="color: red;">value="MyProject/src"</span> /><br />
<!-- <property name="sonar.binaries" value="build/*.jar" /><br />
--><br />
<property name="sonar.host.url" <span style="color: red;">value="http://localhost:9000"</span> /><br />
<br />
<target name="sonar" depends="update"><br />
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml" classpathref="svnant.classpath"> <br />
</taskdef><br />
<br />
<sonar:sonar/> <br />
</target><br />
<br />
</project><br />
<br />
<br /></div>
Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-49768099199134301802012-11-16T10:45:00.002-08:002012-11-16T19:37:35.172-08:00Kernel Upgrade Issue, Uninstalling 3.6.6 kernel from Ubuntu 12.10<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
<span style="font-family: inherit;">I've upgraded my 12.04 to 12.10 and strangely, I've observed that the kernel version 3.5.x that ships as default with 12.10 has not been upgraded from 3.2.x which I was using in 12.04 LTS version. </span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><b>uname -a</b> (for kernel details)</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Hence I've tried to do a manual install of latest kernel version 3.6.x, which also failed with an error reporting unmet package dependencies. Not just with the manual kernel upgrade but I've been facing problems with the usual system updates too, that get pushed on a regular basis.<br /><br />I've tracked this for a while and then realized that I had once made an edit to the default grub configuration file adding an additional "quite splash" line to boost up battery performance. The problem was that after the OS upgrade was done, somehow the simple double quote(") got messed up and was replaced by a smarter double quote (``) which was causing all the errors during my upgrades and updates. I've reverted back the double quotes </span></div>
<div>
<span style="font-family: inherit;"><br /></span></div>
<div>
<b><span style="font-family: inherit;">sudo gedit /etc/default/grub</span></b></div>
<div>
<span style="font-family: inherit;"><br /></span></div>
<div>
<span style="font-family: inherit;">and I have done an update grub. </span></div>
<div>
<span style="font-family: inherit;"><br /></span></div>
<div>
<b><span style="font-family: inherit;">sudo update-grub </span></b></div>
<div>
<span style="font-family: inherit;"><br /></span></div>
<div>
<span style="font-family: inherit;">..only to realize that 3.6.x, 3.5.x and other older kernel versions were all present and installed but failed to show up because of the grub configuration file error. Moreover, I had realized that 3.6 being the latest didn't work that great at least on MY machine (perhaps because it is not as customized as 3.5 for 12.10) as it was consuming 42W of power as shown on powertop which was too damn high. Hence I've removed the 3.6 kernel using </span></div>
<div>
<span style="font-family: inherit;"><br /></span></div>
<div>
<b><span style="font-family: inherit;">sudo apt-get purge linux-image-3.6.*</span></b></div>
<div>
<span style="font-family: inherit;"><br /></span></div>
<div>
<span style="font-family: inherit;">and I've reverted back to the default 3.5.x kernel that is shipped with 12.10 and everything seems fine now. </span></div>
<div>
<span style="font-family: inherit;"><br /></span></div>
<span style="font-family: inherit;">Things I've learnt in the process:</span><br />
<div>
<ul style="text-align: left;">
<li><span style="font-family: inherit;">It is ideal not to upgrade a kernel version that is more latest than the one shipped with the latest OS version. Even if you wish to do so, compile the kernel separately and then proceed.</span></li>
<li><span style="font-family: inherit;">Installing and uninstalling a kernel. </span></li>
</ul>
</div>
</div>
Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-11148281191329383252012-08-09T04:57:00.002-07:002012-11-07T00:08:24.493-08:00A stupid hack to open short urls blocked by proxy via Launchy<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
This script will be useful when short urls are blocked by a proxy within a network.<br />
<br />
For example: <br />
<br />
Lets say the link to an article or blog on the web is this: <br />
<br />
LongUrl : <span style="font-family: Courier New, Courier, monospace;"><b>http://something.com/somethingelse</b></span><br />
<br />
Your friend reads the above article and mails the link to you in its shortened form:<br />
<br />
ShortUrl : <span style="font-family: Courier New, Courier, monospace;"><b>http://bit.ly/s1</b></span> or <span style="font-family: Courier New, Courier, monospace;"><b>http://t.co/se1</b></span><br />
<br />
Now when you are on a company network or a protected network, there is a good chance that bit.ly or t.co services are blocked by the proxy though the original site itself (something.com in this case) might not be blocked.<br />
<br />
For such cases this silly vbscript can be handy. It basically talks to a longurl.org which lengthens the shortened url and opens it up on the browser.<br />
<br />
<b>lurl.vbs</b></div>
<div>
<br /></div>
<div>
<div>
<span style="color: #0b5394; font-family: Courier New, Courier, monospace;"><b>set ws = CreateObject("WScript.Shell")</b></span></div>
<div>
<span style="color: #0b5394; font-family: Courier New, Courier, monospace;"><b>siteUrl = "http://longurl.org/expand?url=" & Wscript.Arguments.Named("u")</b></span></div>
<div>
<span style="color: #0b5394; font-family: Courier New, Courier, monospace;"><b><br /></b></span></div>
<div>
<span style="color: #0b5394; font-family: Courier New, Courier, monospace;"><b>Dim objHttp</b></span></div>
<div>
<span style="color: #0b5394; font-family: Courier New, Courier, monospace;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span>Set objHttp = CreateObject("Msxml2.ServerXMLHTTP")</b></span></div>
<div>
<span style="color: #0b5394; font-family: Courier New, Courier, monospace;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span>objHttp.Open "GET", siteUrl, False</b></span></div>
<div>
<span style="color: #0b5394; font-family: Courier New, Courier, monospace;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span>objHttp.Send</b></span></div>
<div>
<span style="color: #0b5394; font-family: Courier New, Courier, monospace;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span>page = objHttp.ResponseText</b></span></div>
<div>
<span style="color: #0b5394; font-family: Courier New, Courier, monospace;"><b>Set objHttp = Nothing</b></span></div>
<div>
<span style="color: #0b5394; font-family: Courier New, Courier, monospace;"><b><br /></b></span></div>
<div>
<span style="color: #0b5394; font-family: Courier New, Courier, monospace;"><b>longUrl = Split(Split(page,"Long URL:")(1),"""")(1)</b></span></div>
<div>
<span style="color: #0b5394; font-family: Courier New, Courier, monospace;"><b>ws.Run(longUrl)</b></span></div>
<div>
<br />
I have saved the above lurl.vbs file under C:\Temp\Scripts.</div>
<div>
<br /></div>
<div>
From command prompt, running the below command will open up the link in the browser.<br />
<br />
<b>lurl /u:</b><span style="color: #45818e;"><i><b>your-short-url</b></i> </span>
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-6EX0Qe9qo-w/UCOkqbHzJdI/AAAAAAAAArc/EofBl6jK5lk/s1600/launchy1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="271" src="http://2.bp.blogspot.com/-6EX0Qe9qo-w/UCOkqbHzJdI/AAAAAAAAArc/EofBl6jK5lk/s320/launchy1.JPG" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<span style="text-align: left;"> </span></div>
<div>
Further more, you can even configure it via the Launchy Runner plugin which makes it more fun.<br />
<br />
<a href="http://1.bp.blogspot.com/-vtmV4RYLH00/UCOkAkztElI/AAAAAAAAArU/Hpx81-u0KYw/s1600/launchy.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="242" src="http://1.bp.blogspot.com/-vtmV4RYLH00/UCOkAkztElI/AAAAAAAAArU/Hpx81-u0KYw/s320/launchy.JPG" width="320" /></a>
<br />
<br />
Within launchy, typing lurl (tab) followed by site's short url will launch the site directly.<br />
<br />
<a href="http://2.bp.blogspot.com/-iCMQsWkw5-o/UCOlXZroyvI/AAAAAAAAArk/BoJPV-PIgaE/s1600/launchy.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="80" src="http://2.bp.blogspot.com/-iCMQsWkw5-o/UCOlXZroyvI/AAAAAAAAArk/BoJPV-PIgaE/s320/launchy.JPG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<br />
<br /></div>
<br /></div>
</div>
Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com3tag:blogger.com,1999:blog-8396379574372560866.post-68118295674623310202012-06-20T05:34:00.001-07:002012-06-26T06:09:43.053-07:00Design Patterns: Factory Method Pattern<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: 'Courier New', Courier, monospace;"><b>/**</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>* A simple implementation of Factory Method Pattern</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>* using a real time CricketPlayer example</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>*/</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b><br /></b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>//Base</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>public interface CricketPlayer{</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> public String play();</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>}</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b><br /></b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>//Subclass</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>class Bowler implements CricketPlayer{</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> public String </b></span>
<b style="font-family: 'Courier New', Courier, monospace;">play</b> <span style="font-family: 'Courier New', Courier, monospace;"><b>(){</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> return "takes a wicket";</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> }</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>}</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b><br /></b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>//Subclass</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>class Batsman implements CricketPlayer{</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> public String </b></span>
<b style="font-family: 'Courier New', Courier, monospace;">play</b> <span style="font-family: 'Courier New', Courier, monospace;"><b>(){</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> return "hits a six";</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> }</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>}</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b><br /></b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>//Factory class - contains the logic of instatiating players</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>public class CricketPlayerFactory{</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> CricketPlayer player;</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> </b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> public CricketPlayer getPlayerWho(String does){</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> if(does.equals("bats"))</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> player = new Batsman();</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> else if(does.equals("bowls"))</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> player = new Bowler();</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> return player; </b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> }</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>}</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b><br /></b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>//Factory method implementation</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>public class FactoryImplementation{</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> public static void main(String args){</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> //create a factory</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> CricketPlayerFactory factory = new CricketPlayerFactory();</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> //ask factory to instantiate the player</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> CricketPlayer player = factory.getPlayerWho("bats");</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> //use the player</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> System.out.prinln(player.</b></span>
<b style="font-family: 'Courier New', Courier, monospace;">play</b> <span style="font-family: 'Courier New', Courier, monospace;"><b>());</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> }</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>}</b></span><br />
<div>
<br /></div>
</div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com2tag:blogger.com,1999:blog-8396379574372560866.post-21770693648529309632012-06-20T05:10:00.000-07:002012-06-20T06:50:10.383-07:00Design Patterns: Singleton Pattern<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; font-family: 'Courier New', Courier, monospace;"><b>/**</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>* A simple Implementation of a singleton</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>*/</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>class MySingleton{</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> </b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> static MySingleton singletonInstance;</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> </b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> //****** instantiation ******</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b><br /></b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> static MySingleton getInstance(){</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> if(singletonInstance == null)</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> singletonInstance = new MySingleton();</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> return singletonInstance;</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> }</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> </b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> private MySingleton(){</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> //cannot be called public with new</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> }</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b><br /></b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b><span style="background-color: white;"> //****** logic ******</span> </b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> ....</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b> ....</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>}</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span style="background-color: white; font-family: 'Courier New', Courier, monospace;"><b>MySingleton.getInstance();</b></span><br />
<br />
<br />
FYI, Points to remember<br />
<br />
<ul style="text-align: left;">
<li>Singletons are bad. </li>
<li>They are just glorified statics and hence against OOP principles. </li>
<li>They should be rarely used. A classic example: for logging purposes.</li>
<li>Singletons are hard to unit test.</li>
<li>Also bad because it is NEVER a good practice to mix instantiation and logic in a single class. </li>
</ul>
<br />
<br />
<br />
<br /></div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-52307856770911541242012-06-09T04:09:00.000-07:002012-06-20T05:42:30.308-07:00How to know HBOOT version and S-ON or S-OFF on HTC phones<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<ul style="text-align: left;">
<li>Switch off the mobile completely.</li>
<li>Hold the volume down button and simultaneously click the power-on button. This will login to the boot menu and display details like this:<br /><br /><span style="text-align: -webkit-auto;"><span style="font-family: 'Courier New', Courier, monospace;"><b>BUZZ PVT SHIP S-ON</b></span></span><br />
<div style="text-align: -webkit-auto;">
<span style="font-family: 'Courier New', Courier, monospace;"><b>HBOOT-1.01.0002</b></span></div>
<div style="text-align: -webkit-auto;">
<span style="font-family: 'Courier New', Courier, monospace;"><b>MICROP-0622</b></span></div>
<div style="text-align: -webkit-auto;">
<span style="font-family: 'Courier New', Courier, monospace;"><b>TOUCH PANEL-ATMELC03_16ac</b></span></div>
<div style="text-align: -webkit-auto;">
<span style="font-family: 'Courier New', Courier, monospace;"><b>RADIO-3.35.20.10</b></span></div>
<div style="text-align: -webkit-auto;">
<span style="font-family: 'Courier New', Courier, monospace;"><b>Dec 2 2010, 17:14:26</b></span><br />
<br />
<div style="text-align: left;">
The first line displays the security flag status. For being able to play around with sudo root access on HTC phones the flag must be turned off (shows S-OFF if turned off). </div>
</div>
</li>
<li>Click power off button and next hold the volume down button to reboot again into normal menu.
</li>
</ul>
<br />
<div style="text-align: -webkit-auto;">
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span></div>
<div style="text-align: -webkit-auto;">
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">To be continued.. </span></div>
<br />
<div style="text-align: -webkit-auto;">
<span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span></div>
<br />
<div style="text-align: -webkit-auto;">
<span style="font-family: 'trebuchet ms', sans-serif; font-size: x-small;"><br /></span></div>
<br /></div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com1tag:blogger.com,1999:blog-8396379574372560866.post-10516359901632718642012-05-09T02:54:00.000-07:002012-06-20T05:42:16.140-07:00Currying in Groovy<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Currying is a process of transforming a function of n arguments into n partial functions of one argument each.<br />
<br />
Although I was acquainted with the math part of it. I found it hard to implement it in code. I<br />
couldn't help but posting <a href="http://twitter.com/tim_yates" target="_blank">Tim Yate's</a> sample snippet to <a href="http://stackoverflow.com/questions/10511779/need-help-understanding-currying-using-groovy-closures" target="_blank">my question on SO</a> about a simple implementation for currying in groovy.<br />
<br />
<br />
<blockquote>
<span style="font-family: 'Courier New', Courier, monospace;">def greet = { greeting, person -> "$greeting $person" }</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">// This takes a closure and a default parameter</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">// And returns another closure that only requires the</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">// missing parameter</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">def currier = { fn, param -></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> { person1 -></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> fn( param, person1 )</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> }</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">}</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">// We can then call our currying closure</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">def hi = currier( greet, 'Hi' )</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">// And test it out</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">hi( 'Vamsi' )</span></blockquote>
<br />
<br />
<a href="http://www.slideshare.net/arturoherrero/functional-programming-with-groovy/32" target="_blank">Here's an other pointer</a> for doing functional programming in groovy. </div>
</div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-39649477833604708212012-05-04T03:41:00.002-07:002012-06-20T05:41:35.015-07:00Setting up Conky & Lua-Widgets<div dir="ltr" style="text-align: left;" trbidi="on">
<b><span style="font-size: large;">Installing Conky-Lua widget/theme on Ubuntu</span></b><br />
<br />
1) Install <i>conky </i>and <i>conky-all</i> from Ubuntu Software Center or via apt-get on terminal.<br />
<br />
2) Unzip the contents of the tar.gz or zip of Conky/Lua theme submitted by the developer into some folder named <b>Scripts</b>.<br />
<br />
Most importantly, the unzipped file will have a conky text file and a <b>.lua</b> file in it.<br />
<br />
3) Ensure <i>Nautilus Browser -> View -></i> <i>Show hidden files</i> option is enabled and create a hidden folder in your <span style="font-family: 'Courier New', Courier, monospace;">/home/Your_Username directory</span> with the name <b>.conky</b><br />
<br />
4) Within the <b>Scripts</b> folder, search for file with <b>.lua</b> extension. This file contains the widget script. Copy the <b>.lua</b> file into the <b>.conky</b> folder.<br />
<br />
5) Rename the left over text file in the <b>Scripts </b>folder to a hidden file named <b>.conkyrc</b> and place it in <span style="font-family: 'Courier New', Courier, monospace;">/home/Your_Username directory</span>.<br />
<b><br /></b><br />
6) Open the <b>.conkyrc </b>file in <i>gedit </i>and edit the portion of the <b>.conkyrc</b> file which refers to the widget location path i.e the <b>.lua</b> script path. In this case should point to<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">/home/Your_Username/.conky/someWidgetScript.lua</span><br />
<br />
On terminal run command<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">conky</span><br />
<br />
which will start the Conky theme/widget.<br />
<br />
<br />
<b><span style="font-size: large;">Installing Multiple Conky-Lua widget/themes on Ubuntu</span></b><br />
<br />
By default, Running the conky command will invoke the <b>.conkyrc</b> text file at <span style="font-family: 'Courier New', Courier, monospace;">/home/Your_Username location</span> and checks for lua scripts placed in the<b> .conky</b> folder.<br />
<br />
In case of setting up multiple widgets you need to have multiple conky text files and multiple lua scripts.<br />
<br />
Place all the <b>.lua</b> files in the <b>.conky </b>folder in the <span style="font-family: 'Courier New', Courier, monospace;">/home/Your_Username </span><span style="font-family: inherit;">directory</span>.<br />
<br />
Let the text files remain in the <b>Scripts </b>folder but ensure that the configuration path in them points to their corresponding .lua scripts in the .conky folder. (as shown in step 6 above)<br />
<br />
In terminal, run<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">conky -c /home/Your_Username/Scripts/ConkyTextFileScript1</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">conky -c /home/Your_Username/Scripts/ConkyTextFileScript2</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">conky -c /home/Your_Username/Scripts/ConkyTextFileScript3</span><br />
<br />
Each of these will take the conky text file path with -c option and individually start the widgets.<br />
<br />
<br />
PS: You might face issues if any of the above actions, like the path configuration (in step 6) is not done correctly. Also, This requires little bit of scripting knowledge to work your way around. In a nutshell, these are the minimal steps required to setup Conky-Lua Widgets on Ubuntu.<br />
<br />
<br />
<br />
<br class="Apple-interchange-newline" /></div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-7940448833567506672012-04-28T08:07:00.002-07:002012-06-20T05:41:35.023-07:00Power Saving Tips on Ubuntu<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: inherit; text-align: left;">If you are running 11.10 and suffering from excessive power consumption on your laptop/netbook, I insist upgradation to 12.04 </span><span style="text-align: left;">immediately</span><span style="font-family: inherit; text-align: left;">. In the latest 12.04 LTS release, the kernel bug relating to the excess power consumption has been fixed.</span></div>
<div style="text-align: justify;">
<span style="font-family: inherit;"><br /></span></div>
<span style="font-family: inherit;">On 11.10, my laptop consumed a whooping 31 to 33 W of power. On 12.04, it has fallen down to 24 W. </span><span style="font-family: inherit;">Further more, I've installed these three utilities which seem to have reduced the power consumption from 24 W to 16 W, which is pretty cool.</span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">1) From Ubuntu software center, search for <b>laptop-mode-tools</b> and install it.</span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">2) Install <b>powertop </b>which helps you assess the power consumption details and configure some of the processes. (sudo powertop on terminal to run it after installation)</span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">3) Install <b>jupiter</b>, a tiny applet that runs on startup, a very useful utility that lets you set the mode to power consumption and also lets you configure the bluetooth and wireless options which typically consume a lot of power.</span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">Installation of jupiter :</span><br />
<pre class="linux-code" style="background-attachment: scroll; background-clip: initial; background-color: #f8ecec; background-image: url(http://www.netupd8.com/webupd8/2.0/lincode2.gif); background-origin: initial; background-position: 0px 0px; background-repeat: no-repeat no-repeat; border-bottom-color: rgb(155, 5, 5); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(155, 5, 5); border-left-style: solid; border-left-width: 20px; border-right-color: rgb(155, 5, 5); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(155, 5, 5); border-top-style: solid; border-top-width: 1px; font-size: 13px; line-height: 20px; margin-bottom: 10px; margin-left: 10px; margin-top: 10px; max-height: 500px; min-height: 16px; overflow-x: auto; overflow-y: auto; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 28px; text-align: -webkit-auto; width: 522px; z-index: 10000;"><span style="font-family: inherit;"><code style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">sudo add-apt-repository ppa:webupd8team/jupiter
sudo apt-get update
</code>sudo apt-get install jupiter
sudo apt-get install jupiter-support-eee</span></pre>
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">4) If you are on a hybrid-graphics laptop, you can turn off your graphic card. In my case, this worked like a charm. </span><br />
<span style="font-family: inherit;"><br /></span><span style="background-color: #e0e0e0; color: #222222; font-family: 'Ubuntu Mono', 'Ubuntu Beta Mono A', Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 14px; line-height: 17px;">echo OFF | sudo tee /sys/kernel/debug/vgaswitcheroo/switch</span><span style="font-family: inherit;"> </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">However, the above command is not persistent and needs to run on every startup. </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">Standard tips like keeping the brightness low, turning off wireless/bluetooth when not needed would also help.</span><br />
<span style="font-family: inherit;">I have abandoned using Ubuntu 11.10 from the past 3 to 4 months because of its excessive power consumption on my Dell Inspiron. Thanks to Precise Pangolin and these three utilities, I am back on Ubuntu now. :) </span><br />
<span style="font-family: inherit;"><br /></span><br />
<span style="font-family: inherit;">Hope this helps some of you battling with power consumption issues on laptops and netbooks running Ubuntu.</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-VKVf2aeC3CQ/T5wGvzTjobI/AAAAAAAAAbg/oAEk2SvMsLk/s1600/powersaving.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><span style="font-family: inherit;"><img border="0" height="223" src="http://2.bp.blogspot.com/-VKVf2aeC3CQ/T5wGvzTjobI/AAAAAAAAAbg/oAEk2SvMsLk/s400/powersaving.png" width="400" /></span></a></div>
<br /></div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com2tag:blogger.com,1999:blog-8396379574372560866.post-47469829309502637122012-04-23T05:12:00.003-07:002012-06-20T05:41:51.258-07:00Why Groovy over java?<div dir="ltr" style="text-align: left;" trbidi="on">
Some reasons why java developers should consider adapting groovy.<br />
<br />
<b>Groovy is married to java </b><br />
<div>
<br /></div>
<div>
Groovy's seamless integration with java makes it possible to use all frameworks and libraries available for java, without any hassles regarding language compatibility. Groovy is so much compatible with java that one can merely change the .java extension to .groovy and run it. After all, groovy is just dynamic java with some add-ons and wrappers.<br />
<br />
<b>Dynamic typing</b></div>
<div>
<br />
Unlike java, groovy does not throw compilation errors on your face. One of the biggest pleasure when compared to java, groovy doesn't impose explicit type casting which is a pain in the butt while programming in java. Groovy is a programmer friendly language and doesn't go out of control as long as the programmer is sure about his own code. It also supports optional typing, the native java syntax can be retained. </div>
<div>
<br /></div>
<div>
<b>Blocks and closures </b><br />
<br />
One of the best aspects of groovy is that it provides higher level constructs like blocks and closures found in languages like Smalltalk and Ruby. Block closures are handy powerful features which java lacks.<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>//To extract the first letter out of each element of a list.</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>def words = ['animal', 'bird' , 'cat', 'fly', 'dog']</b></span></div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>def letters = words.collect{ it[0] }</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>println letters</b></span><br />
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b><br /></b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>//easy iterations</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>words.eachWithIndex{ word, index -></b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b> println "$word at $index"</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>}</b></span><br />
<br /></div>
<div>
</div>
<div>
The list goes on. Further refer : find{}, findAll{}, sort{}, each{}, contains{} et als, all of which make programming a breeze. </div>
<div>
<b><br /></b></div>
<div>
<b>Reflection in hand</b></div>
<div>
<br />
As in smalltalk, Groovy has a concept of metaclass while initializing objects. This metaClass provides wrappers around the native Reflection API of java which enable the programmer to change the behavior of a class at run time.<br />
<br />
For example : When compared to java, inspecting the methods of a class at runtime is as simple as :</div>
<div>
<br /></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>class Test{</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>def one = 1</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b> def getOne(){</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b> return one</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b> }</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>}</b></span></div>
<br />
<div>
println Test.metaClass.methods //prints getOne() and all methods default methods of the class.<br />
<br /></div>
<div>
Likewise to inspect the properties of a class at runtime, </div>
<div>
<br /></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>println Test.metaClass.properties //prints one and other properties if any</b></span></div>
<div>
<br /></div>
<div>
Likewise, injecting a method called getTwo() is as simple as :<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;"><b>Test.metaClass.getTwo = { return 2 }</b></span><br />
<br class="Apple-interchange-newline" /></div>
<div>
<b>Sugar Syntax</b></div>
<div>
<b><br /></b></div>
<div>
Besides addition of new language constructs, Perhaps this is one other aspect of groovy which hugely differentiates it with java.<br />
<br />
Here I display two good examples that would make groovy an obvious win w.r.t to its sugar syntax.<br />
<br />
ex: 1) A program to fetch the contents of a file in java would add up to around 10 - 15 lines. In groovy :</div>
<div>
<br /></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>new File('C:\Temp\input.txt').getText()</b></span><br />
<br />
Or further more, Parsing it is as simple as<br />
<br /></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>new File('C:\Temp\input.txt').eachLine{ line -></b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b> //parsing logic</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>}</b></span></div>
<div>
<br /></div>
<div>
ex: 2) Given a url, to read the contents of a webpage, in java there is all this crap of opening streams, buffered readers and piping the contents, handling the exceptions etc. In groovy it is as simple as</div>
<div>
<br /></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>'http://nerdysermons.blogspot.in'.toUrl().text</b></span><br />
<br />
<b>Further more...</b></div>
<div>
<br />
Groovy has excellent wrappers around basic java functionalities. For example: With SwingBuilder, building swing UIs becomes darn simple.<br />
<br />
For example: To built a swing application with a click me button and text area that prints hello message upon button click, a java program for the same would extend to more around 30 - 40 lines of code with initialization, building UIs, writing an actionListener etc. In groovy, this four liner script would suffice. </div>
<div>
<br /></div>
<div>
<a href="http://1.bp.blogspot.com/-jpiLoZUuxus/T5VDcBYL1kI/AAAAAAAAAZQ/uYDjG_eT0so/s1600/demo.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" src="http://1.bp.blogspot.com/-jpiLoZUuxus/T5VDcBYL1kI/AAAAAAAAAZQ/uYDjG_eT0so/s1600/demo.JPG" /></a><br />
<br />
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>new groovy.swing.SwingBuilder().edt{</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b> frame(show:true, size:[200,270]){</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b> panel(){</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b> button(label:'Click Me', actionPerformed :{ta.setText('Hello')})</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b> ta = textArea(columns:20, rows : 10)</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b> }</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b> }</b></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><b>}</b></span></div>
</div>
<br />
<div>
<br /></div>
<br />
<div>
Another great feature of groovy is its ability to build, create and parse XMLs with its XmlParser and XmlSlurper facilties. Some other include inbuilt assertions, GPath expressions, String interpolations, etc.</div>
<div>
<br /></div>
<div>
I can go on like this for some time. This post is an introduction to depict groovy goodness comparing it to java which is strict and verbose. The more emphasis w.r.t the groovy vs java argument is on writing less code which possesses the java-ish flavor but is a lot elegant.</div>
<div>
<b><br /></b></div>
<div>
<br /></div>
<div>
<br /></div>
</div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com19tag:blogger.com,1999:blog-8396379574372560866.post-10451863526004102992012-04-04T04:23:00.002-07:002012-06-20T05:42:06.452-07:00Redirecting log4j and Print streams to Custom Console<div dir="ltr" style="text-align: left;" trbidi="on">
This is a custom JTextArea that I've coded for that can redirect and display all the print streams onto it including apache's log4j statements.<br />
<br />
<span style="font-size: large;"><br /></span><br />
<code>
class MyConsole {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>static outArea, consoleScroll, consoleTab<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>static log = Logger.getLogger(MyConsole.class)</code><br />
<code><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//redirect the current println and err streams onto custom Stream </code><br />
<code><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>static setUpStreams(){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>outArea = JTextArea(10,100)<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.setErr(new PrintStream(new MyStream(outArea)));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.setOut(new PrintStream(new
MyStream (outArea)));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>WriterAppender logAppender = new WriterAppender(new PatternLayout(), new MyStream (outArea));</code><br />
<code><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Logger.getRootLogger().addAppender(logAppender);<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public MyConsole(){<span class="Apple-tab-span" style="white-space: pre;"> </span></code><br />
<code> setUpStreams()<span class="Apple-tab-span" style="white-space: pre;"> </span><span style="white-space: pre;"><br /></span>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
}<br />
<br />
//custom stream to which the standard streams are redirected<br />
public class
MyStream extends OutputStream {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>JTextArea ta;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>def str = ''<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>def buffer = []</code><br />
<code><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>
MyStream (JTextArea t) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>super();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>ta = t;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//detects \n and stores the line in a buffer and then prints the whole line..<br /><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public synchronized void write(int i) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>buffer.add(Character.toString((char)i))<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if(buffer.last()=='\n'){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>buffer.each{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>str = str + Character.toString((char)it);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</code><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<code>
<span class="Apple-tab-span" style="white-space: pre;"> </span>ta.append(str)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>str = ''<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>buffer.clear()<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</code><br />
<code><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//ta.append(Character.toString((char)i));<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public synchronized void write(char[] buf, int off, int len) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String s = new String(buf, off, len);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>ta.append(s);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
}
<br />
</code><br />
<code><br /></code><br />
PS : I tried to keep the java-ish syntax alive in the snippet. Albeit that I guess I might have resorted to groovy's sugar syntax in a couple of places. Please make the changes accordingly. </div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com1tag:blogger.com,1999:blog-8396379574372560866.post-11708154015971854482012-04-03T01:54:00.003-07:002012-04-03T02:19:41.895-07:00Creating Windows Shortcuts for your Application Programatically<div dir="ltr" style="text-align: left;" trbidi="on">
Here is a 10 liner vbscript that can dump shortcuts for your application on desktop and All Programs menu in windows.<br />
<br />
<br />
<code><span style="font-size: large;">
set WshShell = WScript.CreateObject("WScript.Shell" )<br />
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")<br />
<br />
pathToDesktop = WshShell.SpecialFolders("Desktop")<br />
set desktopShortcut = WshShell.CreateShortcut(pathToDesktop & "\<span style="color: red;">MyApp.lnk</span>")<br />
desktopShortcut.TargetPath = Wscript.Arguments.Named("target")<br />
desktopShortcut.WindowStyle = 1<br />
desktopShortcut.IconLocation = WinDir & "\system32\SHELL32.dll,43"<br />
desktopShortcut.Save<br />
<br />
pathToStartMenu = WshShell.SpecialFolders("StartMenu")<br />
set startMenuShortcut = WshShell.CreateShortcut(pathToStartMenu & "\Programs\<span style="color: red;">MyApp.lnk</span>")<br />
startMenuShortcut.TargetPath = Wscript.Arguments.Named("target")<br />
startMenuShortcut.WindowStyle = 1<br />
startMenuShortcut.IconLocation = WinDir & "\system32\SHELL32.dll,43"<br />
startMenuShortcut.Save</span><br />
</code><br />
<code><span style="font-size: large;"><br /></span></code><br />
<br />
<b>Execution from Command Line: </b><br />
<br />
cd to the directory where the above script is saved as <b><i>mkshortcut.vbs</i></b>.<br />
<br />
Here I create a shortcut to a directory F:\Temp or any other file (even batch files or exe files which launch your application).<br />
<span style="font-size: large;"><br /></span><br />
<span style="font-size: large;"><code>mkshortcut /target:"F:/temp"</code>
</span><br />
<span style="font-size: large;"><code><br /></code></span><br />
The above command will create a shortcut called MyApp.lnk on your start menu >> Programs and on Desktop.<br />
<br />
<b>Execution from groovy program :</b><br />
<br />
Prefix the above command with "cmd /c" and execute.<br />
<br />
<code><span style="font-size: large;">"cmd /c $command".execute()</span></code> where in the <i>command </i>variable stores the mkshortcut line above as string.<br />
<br />
Like wise, the same can also be extended to java using the Process Object.<br />
<b><br /></b><br />
<br />
<br />
<br class="Apple-interchange-newline" /></div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-41576241285018759662012-03-18T11:57:00.000-07:002012-04-03T02:03:52.330-07:00TicTacToe Game in Pharo Smalltalk<div dir="ltr" style="text-align: left;" trbidi="on">
For an absolute pharo/smalltalk beginner, I think this would be a good place to start with. This is a simple TicTacToe implementation with just three classes : TicTacToe, TicTacToeCell and TicTacToeModel using Morphs. Works on MVC based architecture with view and model separate (no specific class for controller though).<br />
<code><span style="font-size: large;"><br />
<b>Object subclass: #TicTacToe</b><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>instanceVariableNames: 'container model'<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>classVariableNames: ''<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>poolDictionaries: ''<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>category: 'VK-Games'<br /><br />
<b>initialize </b><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>container := Morph new </span></code><br />
<code><span style="font-size: large;"> layoutPolicy: TableLayout new; </span></code><br />
<code><span style="font-size: large;"> color: Color transparent.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>model := TicTacToeModel new:3.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>self addRows.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>self addControls.<br />
^self.<br />
<br />
<b>addRows</b><br />
| rowMorph aCell rowCol |<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>1 to:3 do:[ :row |<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>rowMorph := Morph new layoutPolicy: RowLayout new.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>1 to: 3 do: [ :col |<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>aCell := TicTacToeCell new.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>aCell setModel: (model) row: row col: col.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>rowMorph addMorph: aCell.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>].<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>container addMorph: rowMorph.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>]<br />
<br />
<b>addControls</b><br />
| rowMorph newGameButton exitGameButton |<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>rowMorph := Morph new </span></code><br />
<code><span style="font-size: large;"> layoutPolicy: RowLayout new; </span></code><br />
<code><span style="font-size: large;"> color: Color transparent.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>newGameButton := self createCtrlLabelled: 'New' onClickExecutes: [self restart].<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>exitGameButton := self createCtrlLabelled: 'Exit' onClickExecutes: [container delete].<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>rowMorph addMorph: exitGameButton.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>rowMorph addMorph: newGameButton.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>container addMorph: rowMorph.<br />
<br />
<b>createCtrlLabelled: aString onClickExecutes: aBlock</b><br />
| aCtrlButton |<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>aCtrlButton := SimpleButtonMorph new label: aString.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>aCtrlButton color: (Color black alpha: 0.2).<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>aCtrlButton extent: 60@30.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>aCtrlButton on: #click send: #value to: aBlock.<br />
^aCtrlButton.<br />
<br />
<b>open </b><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>container openInWorld.<br />
<br />
<b>restart</b><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>container delete.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Smalltalk garbageCollect.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>TicTacToe new open.<br />
<br />
*****************************************<br />
<br />
<b>SimpleButtonMorph subclass: #TicTacToeCell</b><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>instanceVariableNames: 'parentModel rowNum colNum'<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>classVariableNames: ''<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>poolDictionaries: ''<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>category: 'VK-Games'<br />
</span></code><br />
<div>
<code><span style="font-size: large;"><br /></span></code></div>
<code><span style="font-size: large;">
</span></code><br />
<div>
<div>
<code><b><span style="font-size: large;">initialize </span></b></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>super initialize.</span></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self label: ''.</span></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self extent: 40@40.</span></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self on: #click send: #value to: (self onClickExecutionBlock).<span class="Apple-tab-span" style="white-space: pre;"> </span></span></code></div>
<div>
<code><span style="font-size: large;">^self.</span></code></div>
</div>
<code><span style="font-size: large;">
</span></code><br />
<div>
<code><span style="font-size: large;"><br /></span></code></div>
<code>
</code><br />
<div>
<div>
<code><b><span style="font-size: large;">setModel: ticTacToeModel row: aRow col: aCol</span></b></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>parentModel := ticTacToeModel.</span></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rowNum := aRow.</span></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>colNum := aCol.</span></code></div>
</div>
<code>
</code><br />
<div>
<code><span style="font-size: large;"><br /></span></code></div>
<code>
</code><br />
<div>
<div>
<code><b><span style="font-size: large;">onClickExecutionBlock</span></b></code></div>
<div>
<code><span style="font-size: large;">^[</span></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>(self label size) == 0</span></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ifTrue:[</span></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self label: (parentModel updateAtRow: rowNum </span></code><br />
<code><span style="font-size: large;"> Col: colNum).</span></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>parentModel checkWinCondition.</span></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self extent: 40@40.</span></code></div>
<div>
<code><span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>].</span></code></div>
<div>
<code><span style="font-size: large;"> ]</span></code><br />
<code><span style="font-size: large;"><br /></span></code></div>
</div>
<code>
</code><br />
<div>
<code><span style="font-size: large;">***************************************** </span></code><br />
<code><span style="font-size: large;"><br /></span></code></div>
<code>
<div>
<div>
<b><span style="font-size: large;">Matrix subclass: #TicTacToeModel</span></b></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>instanceVariableNames: 'filledCellCount currentFill winner'</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>classVariableNames: ''</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>poolDictionaries: ''</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>category: 'VK-Games'</span></div>
</div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<div>
<b><span style="font-size: large;">initialize </span></b></div>
<div>
<span style="font-size: large;">super initialize.</span></div>
<div>
<span style="font-size: large;">filledCellCount := 0.</span></div>
<div>
<span style="font-size: large;">currentFill := nil.</span></div>
<div>
<span style="font-size: large;">winner := nil.</span></div>
</div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<div>
<b><span style="font-size: large;">updateAtRow: r Col: c</span></b></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>currentFill == nil</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ifTrue:[ currentFill := 'X'. ]</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ifFalse:[</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>currentFill == 'X'</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ifTrue: [ currentFill := 'O'. ]</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ifFalse: [ currentFill := 'X'. ]</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>].</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self at: r at: c put: currentFill.<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>filledCellCount := filledCellCount + 1.<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div>
<span style="font-size: large;">^currentFill.</span></div>
</div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<div>
<b><span style="font-size: large;">checkWinCondition</span></b></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>filledCellCount >= 5 "for optimization. Win can occur minimum at 5th turn"</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ifTrue: [</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Transcript show: 'Yes'.</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>1 to: 3 do: [:idx |</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self checkWinConditionInRow: idx.<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self checkWinConditionInColumn: idx.</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>].</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self checkWinConditionInDiagonals.</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>].</span></div>
<div>
<span class="Apple-tab-span" style="font-size: large; white-space: pre;"> </span></div>
</div>
<div>
<div>
<b><span style="font-size: large;">checkWinConditionInRow: rowNum</span></b></div>
<div>
<span style="font-size: large;">|set|</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>winner isNil</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ifTrue: [</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>set := (self atRow: rowNum) asSet.</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self checkWinConditionInSet: set<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>].</span></div>
<div>
<span style="font-size: large;">^winner.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<div>
<b><span style="font-size: large;">checkWinConditionInColumn: colNum</span></b></div>
<div>
<span style="font-size: large;">|set|</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>winner isNil</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ifTrue: [</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>set := (self atColumn: colNum) asSet.</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self checkWinConditionInSet: set.</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>].</span></div>
<div>
<span style="font-size: large;">^winner.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<div>
<b><span style="font-size: large;">checkWinConditionInDiagonals</span></b></div>
<div>
<span style="font-size: large;">|set1 set2 |</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>winner isNil</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ifTrue: [</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>set1 := (self diagonal) asSet.</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>set2 := Set newFrom: {(self at: 1 at: 3). (self at: 2 at: 2). (self at: 3 at: 1)} asOrderedCollection.</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self checkWinConditionInSet: set1.</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>self checkWinConditionInSet: set2.</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>].</span></div>
<div>
<span style="font-size: large;">^winner.</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<div>
<b><span style="font-size: large;">checkWinConditionInSet: aSet</span></b></div>
<div>
<span style="font-size: large;">aSet size == 1</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ifTrue: [</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>(aSet includes: 'X')</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ifTrue: [winner := 'P1'. Transcript open. Transcript show: 'Player 1 is the winner!!'.].</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>(aSet includes: 'O')<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ifTrue: [winner := 'P2'. Transcript open. Transcript show: 'Player 2 is the winner!!'.].</span></div>
<div>
<span style="font-size: large;"><span class="Apple-tab-span" style="white-space: pre;"> </span>].</span></div>
</div>
</div>
</div>
</div>
<br />
</code>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-rEy0GuwIc44/T2YyBJryeOI/AAAAAAAAAWU/vIR27cbAATA/s1600/Untitled.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="356" src="http://4.bp.blogspot.com/-rEy0GuwIc44/T2YyBJryeOI/AAAAAAAAAWU/vIR27cbAATA/s640/Untitled.jpg" width="640" /></a></div>
<div>
<code><br /></code></div>
</div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com9tag:blogger.com,1999:blog-8396379574372560866.post-38487837644397558752012-03-08T05:33:00.002-08:002012-04-03T02:04:07.384-07:00Coffee with Linux #2 - The Shell<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Generally, users interact with the Operating System by clicking on icons, menus and buttons. This is called Graphical User Interface (GUI). Apart from this, there is also an other way to interact with the computer using a command line interface (CLI) which is purely by typing in commands to get the task done. Think of it the DOS command prompt in the world of Windows. One can open Notepad application either by selecting it from the start menu or by simple typing in notepad on the windows prompt. In a parallel context, the command line interface on Linux that enables human-machine interaction is called 'The Shell'. That being said, it is not technically correct to draw a comparison between the Windows DOS prompt and the Linux shell because the shell is capable of doing much much much more than what can be done from a regular dos prompt on windows.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The shell has many variants, some of which are </div>
<div>
<ul style="text-align: left;">
<li style="text-align: justify;">C Shell</li>
<li style="text-align: justify;">Korn</li>
<li style="text-align: justify;">Bash</li>
<li style="text-align: justify;">Z shell</li>
</ul>
<div style="text-align: justify;">
Bash is used as a default for many Linux distros that are available today. In almost all Linux distros you find an option called terminal emulator (or simply the terminal). The terminal is merely a window that runs the shell program within it.<br />
<br />
<b>Standard input & Standard output</b></div>
<div style="text-align: justify;">
<b><br /></b>What you type in to the terminal on Linux is called the standard input and the output of the command typed in is called the standard output. This happens via streams. Whatever is typed in, is taken onto a stream (<b>stdin</b>) which is a continuous set of bytes, likewise the output is also written onto a stream (<b>stdout</b>) that is by default shown on the screen. You can redirect this stream, the standard output on screen onto a file or anywhere else. Example :</div>
</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<code><span style="font-size: large;">$ ls > outputOfLSCommand.txt</span></code>
<br />
<code><span style="font-size: large;"><br /></span></code><br />
Speaking of streams there is a separate stream for carrying the error output (<b>stderr</b>). Likewise you can also redirect the standard input from a file instead of defaulting it to the keyboard.<br />
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Pipeline.svg/280px-Pipeline.svg.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="304" src="http://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Pipeline.svg/280px-Pipeline.svg.png" width="320" /></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<b>Piping the output</b></div>
<div style="text-align: justify;">
<br />
Just the way the output is redirected, the user can also pipe the output. Piping generally happens when the output of one command is given as input to an other command. Example<br />
<br /></div>
<div style="text-align: justify;">
<code><span style="font-size: large;">$ ls | rev</span></code>
<br />
<code><span style="font-size: large;"><br /></span></code><br />
In this command the output of list directories command as a String is given as an input to the rev (the reverse) command which displays the output text in a reversed way.<br />
<br />
<div style="text-align: center;">
*********** End of Tutorial 2 ***********</div>
<br />
<br />See Introduction <a href="http://nerdysermons.blogspot.in/2012/02/coffee-with-linux-1-head-start.html">Tutorial 1: Coffee with Linux #1 - Head Start</a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
</div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-80383280607186316242012-03-02T05:30:00.002-08:002012-03-09T23:51:06.677-08:00Find RSS Feed URL of a Webpage<div dir="ltr" style="text-align: left;" trbidi="on">
Given a URL of a web page, one can programatically search through the meta tags of the webpage's content for alternate URL links (like atom or RSS feed links for the same) to thereon further use them to parse and process the content of the webpage. Typically this is the way Google Reader works. Here I present a very simple implementation of the same in pharo smalltalk.<br />
<br />
<br />
<code><span style="font-size: large;">
Object subclass: #RSSReader<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>instanceVariableNames: ''<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>classVariableNames: ''<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>poolDictionaries: ''<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>category: 'VamsiExperiments'<br />
<br />
<br />
getURLContent: url<br /> "## Comment : Supply the url String of the webpage,</span></code><span style="font-size: large;"> </span><br />
<code><span style="font-size: large;"> ## example: http://nerdysermons.blogspot.in"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>| urlContent |<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>urlContent := (url asUrl retrieveContents contents asString).<br />
^urlContent<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br />
findAlternateLinksInUrlContent: urlContent<br /> "## Comment : The above fetched page content to </span></code><br />
<code><span style="font-size: large;"> ## be passed here to get an ordered collection </span></code><br />
<code><span style="font-size: large;"> ## of alternate links" <br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>| links|<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>links := OrderedCollection new.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>urlContent linesDo: [:line |<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>(line findString: '<link rel="alternate"') > 0<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>ifTrue: [<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>links add: (line findTokens:'"' includes: 'http://').<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>]. <br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>].<br />
</span><code><span style="font-size: large;">
^links.</span><span style="white-space: pre;"><br /></span>
</code></code></div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com0tag:blogger.com,1999:blog-8396379574372560866.post-46609091908532861532012-02-29T10:46:00.002-08:002012-03-02T07:43:49.289-08:00Bypass the Linux Grub to retrieve Windows Bootloader<div dir="ltr" style="text-align: left;" trbidi="on">
Rececntly I had messed up with the Linux partitions on my laptop because of which the grub rescue wasn't letting me login to any of my operating systems. This is a simple step that I came across to bypass the Linux grub to retrieve back my Windows Boot screen back. Simple yet helpful.<br />
<br />
1) Insert a Windows 7 upgrade disc.<br />
2) Enter boot menu to boot from CD/DVD.<br />
2) Proceed to repair Windows. (Caution : Do not reinstall Windows)<br />
3) Open command prompt<br />
4) Type in<br />
Bootrec.exe /FixMbr<br />
which reports a quick reply reporting, "operation ended successfully"<br />
5) Remove disc and Reboot from HDD.</div>Vamsi Emanihttp://www.blogger.com/profile/16352053454037088016noreply@blogger.com3