Thursday, November 26, 2015

Algorithm : Maximal possible sum of some consecutive items in an integer array


Lets think of an array like,
[ 2, 3, 8, 1, 12, 2, 4, 5]

In this array maximum sum of any 2 consecutive numbers is 14(12+2) and maximum sum of any 3 consecutive numbers is 21(8+1+12).

Here is a simple algorithm using Java for find the maximum sum of some consecutive numbers in an integer array. This is just a simple solution for this problem.

Feel free to add a comment if anyone has a optimized solution or anything hard to understand.

static int  arrayMaxConsecutiveSum(int[] inputArray, int k) {
 int result = 0; 
 int currentSum = 0; 
 for (int i = 0; i < k - 1; i++) { 
  currentSum += inputArray[i]; 
 } 
 for (int i = k - 1; i < inputArray.length; i++) {
  currentSum += inputArray[i] ; 
  if (currentSum > result) {
   result = currentSum; 
  } 
  currentSum -= inputArray[i - k + 1]; 
 } 
 return result; 
}


Go to this link to find out how to implement this code in Java

Wednesday, November 25, 2015

Useful and Elegant Terminal Emulators for Linux

terminal emulator is a program that emulates a video terminal within some other display architecture. Though typically synonymous with a shell or text terminal, the term terminal covers all remote terminals, including graphical interfaces.
That is how Wikipedia  define what a terminal emulator is.
It allows the user access to a text terminal and all its applications such as command-line interfaces (CLI) and text user interface (TUI) applications. On Unix-like operating systems, it is common to have one or more terminal windows connected to the local machine.
So people use different types of Terminal Emulators according to their performances and preference of users.
Lets see some of different terminal emulators that can be used in Linux operating systems.

  1. Tilda
    Tilda is a GTK+ Terminal emulator and it is based on the VTE terminal emulator widget underlying GNOME terminal. They say that its design was inspired from consoles which was in computer games like Quake. Running Tilda can be faster than launching a new terminal with a keyboard shortcut because the program is already loaded into memory. So it can be useful to people who frequently find themselves opening and closing terminals.
    It has a nice interface with highly customization options and excellent built in color schemes.

    It is a free software licensed under the terms of the GNU general public license.

    Tilda home page

  2. Guake
    Guake is a drop-down terminal made for the GNOME desktop environment. Guake's style of window is based on an FPS game, and one of its goals is to be easy to reach.
    Guake is mostly written in python and has a little piece in C. Guake is packaged by a number of distributions, among which are Fedora, Debian, Ubuntu or ArchLinux.
    special Features
    • Multi tab.
    • Lightweight
    • Open URL to your browser
    • Save terminal content to a file
    Guake Screenshots

    Guake home page

Tuesday, November 24, 2015

Log into a website using a IP address from another country



Today we are going to talk about very interesting topic and that is how we fake our real IP address and log into a web site.

First let me briefly explain how this happen.

Normally when we surfing the web what we do is we send our HTTP or HTTPS requests to a particular server. In that case server can know our real IP and someone in our path can block requests goes to a particular server if that person want.

In this approach we send our request to a special type of server called proxy servers. After that that proxy server sends our request and send the response to us. What end server notice is request coming from proxy server and some one on the way to proxy server will think that we are going to proxy server, but actually we are going to proxy server to ask that server to do some thing for us  that is go to website we want.. :)



That is how it happens lets get into work,

  1. Type "http free proxy" and search in google
  2. you will find many site that give free proxy server addresses.
  3. Choose a good proxy server according to your needs.
    • different servers are in different countries.
    • some servers does't allow HTTPS connections.
  4. Change your proxy settings in your browser using proxy server IP and port obtain from a site
That's it and now you can use a proxy server from another country to get web sites for you.

NOTE:  Be careful If you are going to use proxy servers for login Facebook, G mail or other sites which you have to provide your secret credentials. Those servers will direct you to wrong pages and steal your credentials.

Sunday, November 22, 2015

Shutdown computers running Linux using Terminal




Some times you might want to shutdown your computer which runs linux using terminal because of several reasons. GUI of your operating system might not work or you just want to be a smart user of linux. what ever it is, lets see how we can shutdown our computer using linux command line.

It is easy,

  1.    Press Ctrl+Alt+T for get in to the terminal.
  2.    Enter the code sudo shutdown -h now and press Enter.
  3.   Type in your password (if prompted) press Enter again.
There are some other methods to do the same task and mainly two commands.
  1. Shutdown command
    • this command will bring the system down with a warning message
  2. Poweroff command
    • this command will stop the system
So you can use these two commands as well,

  • poweroff
  • shutdown -h +0


Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...