Skip to main content

Posts

Showing posts from February, 2015

Disk Usage for Directories in Linux

The Linux command du -h --block-size=MiB --max-depth=3 | sort -rn shows the disk usage for each directory upto a depth of 3. MiB is required to avoid showing all those long bytes numbers. -h is for human readable format. sort -rn sorts on the reverse numeric order, i.e. the most disk usage first

Signal Handling - Linux

A program running always face unexpected situations, running out of memory, lost network connectivity, losing permissions, read write errors etc. Therefore a robust program should be resilient to these conditions and should gracefully exit if the program cannot continue. Signals should be handled.... I found this to be extremely resourceful and I'll just give a summary of what the author Alex says..... Signal is a notification, a message sent by either operating system or some application to your program (or one of its threads). In addition to informative nature of signals, they also interrupt your program. I.e to handle a signal, one of the threads in your program, stops its execution and temporarily switches to signal handler. Signals, as their name implies, used to signal something. There are several types of signals, each indicating something of its own. For instance SIGINT that I already mentioned, tells your program that someone tries to interrupt it with CTRL-C.

Vaadin vs GWT

From Chapter 1 of book of Vaadin I quote the following. Vaadin Framework is a Java web application development framework that is designed to make creation and maintenance of high quality web-based user interfaces easy. Vaadin supports two different programming models: server-side and client-side . The server-driven programming model is the more powerful one . It lets you forget the web and program user interfaces much like you would program a desktop application with conventional Java toolkits such as AWT, Swing, or SWT. But easier. While traditional web programming is a fun way to spend your time learning new web technologies, you probably want to be productive and concentrate on the application logic. The server-side Vaadin framework takes care of managing the user interface in the browser and the AJAX communications between the browser and the server . With the Vaadin approach, you do not need to learn and deal directly with browser technologies, such as HTML or JavaScript.

What is GWT ? Google Web Toolkit

The GWT project states that, GWT is a development toolkit for building and optimizing complex browser-based applications. Its goal is to enable productive development of high-performance web applications without the developer having to be an expert in browser quirks, XMLHttpRequest, and JavaScript. GWT is used by many products at Google, including AdWords, AdSense, Flights, Hotel Finder, Offers, Wallet, Blogger. It’s open source, completely free, and used by thousands of developers around the world. I quote the development lifecycle of GWT App from the project site as well. Write : The GWT SDK provides a set of core Java APIs and Widgets. These allow you to write AJAX applications in Java and then compile the source to highly optimized JavaScript that runs across all browsers, including mobile browsers for Android and the iPhone. Constructing AJAX applications in this manner is more productive thanks to a higher level of abstraction on top of common concepts like DOM

Dynamic Web Content - From HTML to Servlets and beyond (Part II)

Towards Servlets  From the earlier post I've discussed about the techniques of dynamic web content loading. This post is about servlets, java servlet pages (jsps) and java. Java Servlets are an efficient and powerful solution for creating dynamic content for the Web. Over the past few years Servlets have become the fundamental building block of mainstream server-side Java. The power behind Servlets comes from the use of Java as a platform and from interaction with a Servlet container. The Java platform provides a Servlet developer with a robust API, object-orientated programming, platform neutrality, strict types, garbage collection, and all the security features of the JVM. Complimenting this, a Servlet container provides life cycle management, a single process to share and manage application-wide resources, and interaction with a Web server. Together this functionality makes Servlets a desirable technology for server-side Java developers.  Serv

Dynamic Web Content - From HTML to Servlets and beyond (Part I)

Web development involves a typical client server model. Client Server communications is built on the OSI stack and different communication protocols exist at each layer. Internet is built upon TCP/IP as the transport and internet layer and HTTP/HTTPS as the application layer. A client communicating with a web server via a web browser needs to establish a TCP connection on the listening port of the serer. After establishing a TCP connection, the client communicates over HTTP. HTTP requests in the form of GET/POST are sent to the server and the server responds with metadata and HTML content. This HTML content is interpreted by the web browser to render web pages on client's browser. Web development is a vast field with thousands of libraries, frameworks, protocols and technologies. It's impossible to study all of them but the important thing to realize is that there are many ways to accomplish a similar outcome. All these techniques can be grouped into 2 aspects, Cl

RAII and Smart Pointers - Resource Management in C++

RAII stands for Resource Acquisition Is Initialization. What is it and why it is needed? We used different resource in out software such as file streams, network pipes, database connections and even locks are considered as resources. The standardized procedure of using a resource is to acquire the resource, use it and then release it. Holding onto resources is bad practice and starves other processes for resources slowing down the entire system in multicore systems. OK, what's the big deal? So we want to open a file, write some stuff to it and then close it. We just do. file.open(); file.write("test"); file.close(); Caution here. If it's a trivial task where you don't have anything in between opening and closing the file (or any other resource) this seems fine but this is often not the case. You have many other things that you do between you opening the file and closing the file. Chances are these operations might fail, or worse throw. In such case

C++ Callbacks using function pointers vs boost bind +boost function

In C, the most common uses of callbacks are as parameters to library functions like qsort , and as callbacks for Windows functions, etc. For example you might have a library that provides some sorting functions but you want to allow the library user to provide his own sorting function. Since the arguments and the return values do not change depending on the sorting algorithm, this can be facilitated in a convenient manner using function callbacks. Callbacks are also used as event listeners. onMouseClick(), onTerminalInput(), onData(), onConnectionStatus(), onRead() are probably some examples you've already seen in different libraries. The libraries have these callback functions and the users of the library are supposed to implement them. The library has a function pointer to these functions and calls them on their event loop which will invoke the code of the inherited classes of the library user. The implementation of function pointers is simple: they are just "code p

Detaching a process from terminal - exec(), system(), setsid() and nohup

Linux processes are created by fork() and exec(). The very first process of POSIX systems is init and subsequent processes are derived from the init as parent. These subsequent processes are child processes. During forking the parent process copies itself - with all I/O, address space, stack, everything. The only thing that is different is the process ID. The parent and child will have 2 different process IDs. The system() library function uses fork(2) to create a child process that executes the shell command specified in command using execl(3) as follows: execl("/bin/sh", "sh", "-c", command, (char *) 0); system() returns after the command has been completed. system() executes a command specified in command by calling /bin/sh -c command , and returns after the command has been completed. During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored.  system() calls are often made within programs to execut