Saturday, February 5, 2011
How to Mind Map a project experience
Recently I have read a book about preparing for programmer interview, And there was this thing, The book author says, As a developer we should have a picture of each project we have done in terms of what we have learnt, what is the hardest bug... etc These days I am very involved in Mind Mapping, using XMind, I got this: This is about a project I have worked in last December, I have mind mapped what I have learnt from it.
Wednesday, August 11, 2010
Linux: Find command
1) You are doing some serious things with your local svn trunk and after some point you go to know that you have to delete all .svn directories in a specific location. What will you do?
2) The ABC application is running 24/7 and creating gigs of log files, You have been assigned to clean the mess every day, How can you delete all 2 days older log files every day?
Add a crontab for
3) You have a collection of e books which are already put in to a big tree of directories(.pdf) and you want to know the list of books you have . (I have thousands of them :))?
find /home/jestan/pet-project/trunk/evil-sim/src/main -type d -name ".svn" -exec rm -rf {} \;
2) The ABC application is running 24/7 and creating gigs of log files, You have been assigned to clean the mess every day, How can you delete all 2 days older log files every day?
Add a crontab for
find /home/xuser/abc-app/logs -type f -name "*.log*" -mtime +2 -exec rm {} \;
3) You have a collection of e books which are already put in to a big tree of directories(.pdf) and you want to know the list of books you have . (I have thousands of them :))?
find /media/data/Ebooks -type f -name "*.pdf" -fprintf ``ebooks.txt`` %f'\r\n'
Friday, July 2, 2010
Speedup Maven builds (snapshot dowloads)
Any one uses snapshot dependencies from public snapshot repositories and bothered when Maven download snapshots all the time. Here is the remedy. Snapshot downloads can be controlled by adding update policy (never,daily,interval). This would be very useful when your using snapshot repositories heavily
never: download only if the dependency does not exist
daily: download only once a day
interval: interval in minutes
<repositories>
<repository>
<id>>clojure-snapshots</id>
<url>http://build.clojure.org/snapshots/</url>
<snapshots>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
<repository>
<id>Netty</id>
<url>http://repository.jboss.org/maven2</url>
<snapshots>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
</repositories>
never: download only if the dependency does not exist
daily: download only once a day
interval: interval in minutes
Sunday, February 14, 2010
Begining Scala
Hi all! recently I have started learning Scala and :). Since I am coming from Java world, it was difficult to catch up functional style and use the language effectively. When I have started the Hello world in Scala, I asked myself what is so special about functions in Scala? How do they differ from methods in Java program and why are we going back to functional programming which was introduced before OOP. Before answer these questions, there is a big questions which should be answered first is “What is functional programming?”..
Functional programming is about treating computation as the evaluation of mathematical functions and avoids state and mutable data [Wikipeadia]. For example y = log(x) is a function. Here output of the function depends only on input . In other words, if we call this function with x=10 for thousands times, it will return same value. It does not depends on global state or mutable variable. We can call this function anywhere without worrying about the context which is bound to. This property simplifies debugging, analyzing a function and support concurrent execution also.
Oh this is also can be achieved in a Java method, isn't it? What is special about functions in Scala? Functions are first class construct in functional programming like object/primitive types in Java. Functions can be stored in a variable, it can be passed to another function , moreover functions can return a function. So in Scala we can do above operations with functions. So “How do they differ from Java methods?”. Java methods can act like functions if it does not have a reference to a shared state but they do not have other properties of pure functions.
“why are we going back to functional programming ….?”. This is a trickier question than other ones. By using Scala, we are not going to loose any OOP features. Since it is a hybrid object oriented functional language , it is going to make things easier.. Here is an example of power of functions and this would require more lines of code in Java .Following Scala program reads a text file line by line and ignore the commented lines start with #.
Functional programming is about treating computation as the evaluation of mathematical functions and avoids state and mutable data [Wikipeadia]. For example y = log(x) is a function. Here output of the function depends only on input . In other words, if we call this function with x=10 for thousands times, it will return same value. It does not depends on global state or mutable variable. We can call this function anywhere without worrying about the context which is bound to. This property simplifies debugging, analyzing a function and support concurrent execution also.
Oh this is also can be achieved in a Java method, isn't it? What is special about functions in Scala? Functions are first class construct in functional programming like object/primitive types in Java. Functions can be stored in a variable, it can be passed to another function , moreover functions can return a function. So in Scala we can do above operations with functions. So “How do they differ from Java methods?”. Java methods can act like functions if it does not have a reference to a shared state but they do not have other properties of pure functions.
“why are we going back to functional programming ….?”. This is a trickier question than other ones. By using Scala, we are not going to loose any OOP features. Since it is a hybrid object oriented functional language , it is going to make things easier.. Here is an example of power of functions and this would require more lines of code in Java .Following Scala program reads a text file line by line and ignore the commented lines start with #.
import io.Source
object Runner {
def main(arg: Array[String]) {
val path = "data.txt"
val lns = Source.fromFile(path).getLines.map(_.stripLineEnd).filter(l => !l.isEmpty && !(l.trim startsWith "#"))
for (line <- lns) {
println(line)
}
}
}
Here .getLines returns an Iterator with Strings. After that map function is invoked in that Iterator . Map function is a higher order function (Higher order function is a function which accept another function as a input) which applies stripLineEnd on all strings in the Iterator. Likewise filter function applies validation logic on all strings in the newly return Iterator. Finally, we get an Iterator with strings..
What are the other advantages Scala can give us ;).Functional programming languages provides concurrency by message passing and make easier to write concurrent programs with out worrying about shared states and locks. Scala provides actor based message passing to write concurrent applications. Nowadays we have processors with multiple cores in a single chip. Most of the mainstream languages concurrency models are working with locks. Lock based concurrency will require additional complex synchronization logic to work with multi core processors where Scala like languages can make it easier. Other than these advantages we get things done with less lines of code ;).
What are the other advantages Scala can give us ;).Functional programming languages provides concurrency by message passing and make easier to write concurrent programs with out worrying about shared states and locks. Scala provides actor based message passing to write concurrent applications. Nowadays we have processors with multiple cores in a single chip. Most of the mainstream languages concurrency models are working with locks. Lock based concurrency will require additional complex synchronization logic to work with multi core processors where Scala like languages can make it easier. Other than these advantages we get things done with less lines of code ;).
Subscribe to:
Posts (Atom)