Saturday, May 9, 2015

File compresson and decompression using terminal in Linux

"Most commonly encountered archive files in linux and unix distros. Tutorial to compress and decompress them in terminal. Finally, a wonderful software is named which will handle most of the archive file systems..."

This article has been published into my new blog.
https://cryptofables.wordpress.com/2015/05/08/archive-file-systems/

CryptoFables

Wednesday, April 22, 2015

$find - The Beauty of Linux Terminal

This article has been published in my new blog CryptoFables.

Part 1: Beauty of Linux Terminal - $find
Part 2: 8 basic example of $find command, useful for beginners

Short Story: Cured by Obsession


Short story about being obsessed with a girl.

"Have you ever been obsessed about any human being? Have you ever felt satisfied about your obsession? Have you been dreaming about her?..."

Read full story published in my new blog.

CryptoFables

Monday, January 26, 2015

How to clear cache memory in Ubuntu

Since my Ubuntu 14.04 was storing a lot of cache in memory (as far as I remember it was 1.5 GB, or maybe more than that), I was looking for a solution. For those computers having a limited memory below 4 GB and used heavily, caching a lot may cause trouble. Though it becomes more faster, but for me it made my computer ran slowly.

I was looking for a permanent solution. Then I made a script which will make a soft link indicating itself and will drop cache. No need to write "sudo sync; sudo echo 3 > /proc/sys/vm/drop_caches" every time in terminal, which I found complex to memorize.

Below script will download an script, save it in '/usr/local/share/' directory and then execute it. Actually the downloaded script will make a soft link in '/usr/local/bin/' directory to make it more easier and interactive. It can be deployed in any machine which supports BASH such as UNIX or Linux. Additionally the machine must be connected to the internet as it downloads original script from github.

Copy and paste it into terminal


Original source code is available in my github account:
https://github.com/Nabid/Shell_Scripts/tree/master/Drop_Cache

Tested in Ubuntu 14.14 Trusty Tahr.



The scripts in this post and in the github link given above, can be used, modified or changed for only educational purposes. The author is not responsible for any kind of damage or data loss.

Friday, January 23, 2015

Creating responsive multiple <div> of same height

Sometimes we need to apply two or multiple <div> as they all contain same height, beside we want them responsive i.e their height will remain same if the window size changes. An example has been shown in the given image below, how they mismatch of their height when the inner contents are of different depth.

Different height of two <div>

We can easily solve this problem using javaScript. But for I am going to use jQuery (a javaScript library). If you are not familiar with jQuery, be sure you get yourself familiar with it. jQuery is very easy to learn and fun to use.[jQuery - w3schools]

First, we need to download jQuery file from here and add this into our html file [how to].

Next, we will give our <div> tags unique id. In our case, I will use "div_a" and "div_b" for left div and right div respectively.

Now, we will add a small script inside <head> tag. We need to consider two jQuery events. $(document).ready() for when the page loading is completed and $(window).resize() for whenever window size is changed. We will then take another function which take two div's height, check which one is largest and adjust other one's height. Ta da! We have done this!!

Both <div> has same height

Source code:
<!Doctype HTML>
<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script>
        /*works when page loading complete, this is important
          because you want your divs' match height from the beginning.*/
        $(document).ready(function(){
            //alert("ready");
            changeDivHeight();
        });
        /*whenever browser window size changes, this function is being called
          and it fixed div height.*/
        $(window).resize(function(){
            //alert("resize");
            changeDivHeight();
        });
        /*here we place our logic
          we take each sizes, compares which one is largest and then
          set other's height.*/
        function changeDivHeight() {
            // .innerHeight() returns height of an element
            var a = $("#div_a").innerHeight();
            var b = $("#div_b").innerHeight();
            //alert(a + " " + b);
            // .height() sets height of an element
            // we can pass an integer value, which will be converted into px
            // otherwise we can pass a string, mentioning the unit such as px or in or cm or dp
            if( a > b ) {
                $("#div_b").height( a );
            } else {
                $("#div_a").height( b );
            }
        }
    </script>
</head>
<body width="75%" align="center">
    <div id="div_a" style="border: 1px solid red; float: left; width: 30%;">
        <p>hello div A hello div A hello div A hello div A hello div A hello div A.<br>div A has large height. Will div B be able to achieve same height??</p>
    </div>
    <div id="div_b" style="border: 1px solid green; float: left; width: 30%">
        <p>hello div B<p/>
    </div>
</body>
</html>

Or you can use Bootstrap library to solve this problem.

Monday, December 1, 2014

ব্যর্থতা

"স্কুলে পড়ে কিছু শিখি নাই, এটা আমার ব্যর্থতা।"
--- কথাটা অনেক গুরুতপূর্ণ। নতুন করে চিন্তা করলাম। পারসপেক্টিভ বদলে দিয়েছে কথাটা।

Friday, September 19, 2014

Install Bangla Fonts in Linux based OS

To install bangla fonts in any Linux based operating system, select the script below, paste into terminal and press enter:

The followed bangla fonts will be installed:
  • Kalpurush
  • BanSen
  • BanSenHandWriting
  • Lohit
  • SolaimanLipi
  • AdorshoLipi
  • Bangla
  • SutonnyMJ
File size: 1.1 MB
Tested in Ubuntu 14.04

Thursday, September 18, 2014

ইথারের কালো (ইথার ৫)

১
আমরা বাদাম খেয়ে খোসা গুলো প্যাকেট করে ডাস্টবিনে ফেলি না কেন?

২
চকলেট এর প্যাকেট তো প্যান্টের পকেটে নিয়ে আসতে পারি বাসার ডাস্টবিন ভর্তি করার জন্য।

৩
বাসের টিকেট রাস্তায় ফেলি কেন?

৪
- আপনার পরিচয়?
- আমই মানুষ।
- মানে কী করেন?
- লেখি।
- মানে লেখক? কী লিখেন?
- কোড লেখি।

৫
কাঁপা হাতে ত্রিদিব সিগারেটটা নিভিয়ে দেয়। তার চিন্তা হয় চিন্তা নিয়া। আচ্ছা চিন্তাধারা কী অসীম ধারা নাকি সসীম ধারা? চিন্তা কী ভেক্টর রাশি নাকি স্কেলার? চিন্তার গতিপথ কী সরলরৈখিক নাকি বক্রতায় প্যাঁচানো??
৬
ইন্টারনেটের স্পিড বাড়ানোর কোন অ্যামপ্লিফায়ার নাই?

৭

জ্যোৎস্না = রোদ এর ডেরিভাটিভ।

ইথারের সবুজ (ইথার ৪)

১
বিবেকের গ্রাফ কী সাইন ওয়েভ নাকি x2 এর ডেরিভেটিভ?
২
ব্যর্থতার দায় ক্রেমারের, নিচে শূন্য হলে অনির্ণেয়।
৩
পেজা তুলোর মেঘ ছোঁব...
৪
মেঘেদের রাজ্যে রাজা নেই? মহারাজাও নেই??
৫
ত্রিদিবের এই মূহুর্তে জ্যোৎস্না দেখতে ইচ্ছে করছে। আর ইচ্ছে করছে বৃষ্টিতে ভিজতে। বৃষ্টিতে ভিজতে ভিজতে জ্যোৎস্না দেখতে ইচ্ছে করছে।
৬
আচ্ছা, বৃষ্টিতে ভিজতে ভিজতে জ্যোৎস্না দেখা যায় না?
৭
রোদ্দুর মাপার যন্ত্র নেই।

sine wave
f(x) = x^2;
d/dx f(x) = 2x

2x + 4y = a ------ (i)
5x + 10y = b ------- (ii)
ক্রেমারের রুল দিয়ে এটা সমাধান করা যায় না। 
কারণ 
|2   4|
|5  10|
এটা শূন্য।

Thursday, September 4, 2014

ইথারের লাল (ইথার ৩)


১
শিশিরের গা ভিজে যায় বৃষ্টিতে।

২
কল্পনায় রঙ নেই?

৩
আচ্ছা, সংখ্যা কী কখনো মিথ্যে হয়?

৪
কেন? সংখ্যা যদি বাস্তব হতে পারে, সংখ্যা যদি জটিল হতে পারে তবে মিথ্যে হতে দোষ কি?

৫
ত্রিদিব একটি অত্যাধুনিক হাঁদা কম্পিউটার নিয়ে এসেছে। বোকাটা কথার জবাব দেয় না। কিচ্ছু খায় না। ঈশ, হাঁদাটা যদি কথা বলতে পারতো ত্রিদিব এর সাথে...

৬
কল্পনার ডানায় কী ইঞ্জিন লাগানো নাকি পাখিদের মত ডানা মেলে ঘুরে বেড়ায়?

৭
অনুভুতি কী রঙ্গিন? নাকি রঙেদের অনুভূতি নেই?


ইথারের নীল (ইথার ২)


১
ঘুমের বর্গমূল কী অলসতা?

২
বিল্ডিং গুলো সেন্ট্রির মত পাথরের শহরটাকে পাহারা দিচ্ছে, নেটওয়ার্ক টাওয়ারের বেয়োনেট উঁচিয়ে ।

৩
সেন্ট্রিদের গা ধুয়ে দিচ্ছে বৃষ্টি।

৪
এক ঘন এককে বৃষ্টির ফোঁটা কতগুলো?

৫
আবেগকে গণিতের ছকে ফেলা যায় না? ওজনও করা যায় না? যেমন এইমুহুর্তে ত্রিদিবের এক কিলো রাগ আর হাফ কিলো অভিমান হচ্ছে।

৬
এক পৃষ্ঠার বইও কী হয় না? ফ্রন্ট কাভার আর ব্যাক কাভার এর মাঝখানে একটা মাত্র পাতা থাকবে, যেখানে একটাই গল্প থাকবে, ইথারের গল্প।

৭
ইথারের গল্প এতো ছোটো কেন?

ইথারের রঙ (ইথার ১)

১
শূন্য ভিত্তির অংক কয়টি??
দশ ভিত্তির অংক দশটি (০-৯), আট ভিত্তির অংক আটটি(০-৭), এক ভিত্তির অংক ১টি (০)। তাহলে শূন্য ভিত্তির অংক কয়টি??
২
অসম্ভব । কোন সংখ্যাকে শূন্য দিয়ে ভাগ করলে ভাগফল সবসময় শূন্য এর চেয়ে বড় হবে যদি না সংখ্যাটি শূন্য হয়।

৩
আচ্ছা এলিয়েনদের সংখ্যা পদ্ধতির ভিত্তি কত?

৪
এলিয়েনরা যোগ বিয়োগ করতে পারে?

৫
ত্রিদিব ছেলেটার মাথায় দুটো জিনিস ঘুরে, এক গণিত আর এলিয়েন। এলিয়েনরা গণিতের কতটুকু জানে, ক্যালকুলাস করতে পারে নাকি, অসীম এর ধারণা জানে নাকি - এইসব চিন্তায় তার দিন রাত শেষ হয়ে যায়। 
 
ঈশ, খুব ভালো হত যদি ভূত প্রেত দের কোন সমীকরণ দিয়ে প্রকাশ করা যেতো। আসলেই কি যায়?  
এমনটাও তো হতে পারে আমাদের বুদ্ধি ততদুর যায়নি।

৬
তবে কি মানুষেরও ভিত্তি আছে? এক ভিত্তিতে আমরা একরকম আর এক ভিত্তিতে আমরা অন্য জগতে বাস করছি?  
সব ভিত্তি সমান্তরাল ভাবে চলছে, কেউ কারো সাথে ছেদ করছে না?
সম্ভব নাকি অসম্ভব?
অসম্ভব হলে কতটুকু অসম্ভব? কিছুটা নাকি পুরোটাই?

৭
ঘুম। হ্যাঁ, ঘুমেরও কী গণিত আছে? ঘুমের গণিত কী নাম্বার থিওরি নাকি প্রবাবিলিটি? নাকি ইমাজিনারি নাম্বার?

Monday, April 21, 2014

Mount a ntfs partion in Ubuntu, Linux

Generally no file can be executed at a pendrive or at a separate partition in Linux, unless it is mounted with proper permissions. The default mount (clicking on a pendrive or partition mounts automatically) does not provide necessary permission due to security issue.
This problem can be override by the following commands.

  1. First we need to find out our media to be mounted.
    fdisk -l
    This command gives a list of devices currently connected. Prompting this command at my terminal gives output:
    Disk /dev/sda: 500.1 GB, 500107862016 bytes
    255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disk identifier: 0xfa61dadb
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *   376006656   976773119   300383232    7  HPFS/NTFS/exFAT
    /dev/sda2            2046   376006655   188002305    5  Extended
    Partition 2 does not start on physical sector boundary.
    /dev/sda5            2048   360380415   180189184   83  Linux
    /dev/sda6       360382464   376006655     7812096   82  Linux swap / Solaris
    
    Partition table entries are not in disk order
    
    Suppose we are going to mount /dev/sda1.

  2. Now we have to define a mount point where that partition is going to be mounted. I will mount it into /media/Partition directory. The following command will create that directory.
    mkdir -p /media/Partition

  3. Finally, the following command will mount our partition.
    sudo mount -t ntfs -o nls=utf8,umask=000 /dev/sda1 /media/Partition
    We are mounting ntfs type partition or device, full list of supported type can be found at manual page of "mount" command. Umask = 000 means it allows read, write and execute permission for all (security risk).
Thats it. We have just mounted an ntfs file system into readable, writable, and executable mode.

Sunday, April 20, 2014

Software list for my new Ubuntu 14.04 Trusty Tahr

Just finished installation of Ubuntu 14.04 in my laptop, making only OS of my computer system. I think I'll make a review later, but right now I'll make a list of new softwares I am installing now.
  • VIM
  • VLC Player
  • Codeblocks
  • Terminator - a command interpreter
  • Ubuntu Restricted Extras
  • Google Chrome - my secondary browser
  • Oracke JDK
  • Xampp
  • Php-Storm
  • Eclipse
  • Android Studio
  • Avro
  • Shutter - Screen Capture
  • Gimp - Image Editor
  • qBitTorrent
  • Dropbox
  • Google Drive Ocamlfuse - Google Drive Client for Linux [Currently using Grive]
  • Grive (Google drive client)
  • Okular (Document Viewer, Specially for PDF)
  • todo-indicator (task manager)
  • Texmaker (LaTex Editor)
  • Weka (Data Analysis Tool)

Monday, January 13, 2014

Installing JDK, JRE in Ubuntu

Installation of "default-jdk" using "apt-get" was perfect though in my system it was showing that OpenJdk 6 was installed. I did not wanted it and deleted it from Software Manager. Unfortunately, uninstalling OpenJdk 6 installs OpenJdk 7!!!
I was searching for a solution on the web. Then I found the following link. It describes how to install Oracle Jre and Jdk. This link is so helpful.

http://www.wikihow.com/Install-Oracle-Java-JDK-on-Ubuntu-Linux

Friday, December 20, 2013

Roadway to Ubuntu

This post is neither a solution nor a suggestion. This is what I experienced during installation of ubuntu in my system.
    Since the first day I used a computer, I was using MS Windows as default and primary operating system. Though, its important for a student to cope with different operating systems. During this time, I have used different Unix/Linux based live OS. Deciding which OS I should use is pretty tough decision because there are bunch of choices and all of those are free. :P
    My first attempt to install Linux was on a AMD A55 machine. It was a failure because of hardware configuration. ( I have tried it with both 32bit and 64bit different OSs. )
Then I got my laptop, an Intel system with pre-installed Windows 7 in it. Well, I removed it with Windows 8 from DreamSpark account at 0.00$ cost. :D Living together with Windows 8 was quiet fun. xD However, when I took Operating System course at University, it was a necessity having a Linux OS in my system. But, I failed again. Ubuntu live OS ran fine, installation started every time, but it could not modify the karnel about installation! I tried with Fedora, OpenSuse, Ubuntu, BackTrack and LinuxMint. Each time it started fine, but ends with error. Error! Error!! Error!!! ( Now I have figured it why.. Windows hibernate/hybrid-shutdown option was not allowing any other OS to modify the storage. Later I turned it off using the following command. )
powercfg /h off
    Enough installing Linux for me! So, I kept it cool with Windows.
Meanwhile, my pc was attacked by SIREFEF virus. It turned off, turned off(!) Windows Defender permanently and converted system directories into junctions. Thats why I could not turn Windows Defender on. It ate all the website certificates on all browses. Whenever I turned on the pc, a VB script was creating executable file and some null processes on background. I got rid off this virus using HitmanPro.
    Another thing this virus did was making disk partitions undetectable in disk management tool or windows setup. So, I was thinking on a new set up. Why not Linux now? Yes, it was time for Ubuntu to take all the disk spaces. :D This time I was stuck with, UEFI abd Legacy Mode. Certainly I wanted Ubuntu in UEFI mode but did not find any option for Windows but Legacy mode. Oh, I surely wanted a duel boot.
    I created partitions, installed Ubuntu. Then another problem did arise! Windows could not format GPT partitions. I erased the whole disk using diskpart.
diskpart
list disk
select disk *
clean
convert gpt
exit
    Well, windows was installed. Finally, I installed Ubuntu by formatting unallocated spaces. Installation Finish! Restart!! Windows Boot!!!
    Ah, the MBR, windows boot manager. Again I inserted Ubuntu live USB to install GRUB.
sudo add-apt-repository ppa:yannubuntu/boot-repair && sudo apt-get update
sudo apt-get install -y boot-repair
sudo boot-repair
    At last... Got my dual boot system with Ubuntu 12.04.2 and Windows 8. Decided to use Ubuntu as primary and Windows as supporting OS.
Finally, Enjoying Ubuntu!!

Monday, December 16, 2013

Maximum Interval Product

Previously, I have posted about maximum interval sum. Now, unlike summation, product of an interval or segment is bit different.
Well, the problem is, from a given array of integers we have to determine the maximum product which can be found by any segment of the given array of integers.
Example:
Let, we have an array of these integers:
1 -2 4 -3 -1
So, the maximum interval product is 24 from 1 to -3 ( 1*-2*4*-3 ).
1 -2 4 0 -3 -1
Here, the maximum interval product is 4 from only 4.
Iteration:



initial

1

-2

4

-3

-1

mp

inf

1

inf

4

24

12

mn

inf

inf

-2

-8

-12

-24

mxProduct

-1

1

1

4

24

24

Code:
// Maximum Interval Product
// Complexity: O(n)
long long mxProduct  = -1;
// maximum product is stored. if unchanged, no valid product.
long long t1, t2;
long long mp = INF, mn = INF;
// two counters for maxPositiveProduct and maxNegativeProduct
for( i=0; i<N; i++ ) {
    scanf( "%d", &arr[i] );

    if( arr[i] == 0 ) {
        if( mp != INF ) mxProduct = MAX( mxProduct, mp );
        mp = mn = INF;
        continue;
    }

    if( mp==INF && mn==INF ) {
        arr[i] > 0 ? mp = arr[i] : mn = arr[i];
        if( mp != INF ) mxProduct = MAX( mxProduct, mp );
        continue;
    }

    if( mp == INF ) {
        if( arr[i] > 0 ) {
            mp = arr[i];
            mn = arr[i] * mn;
            mxProduct = MAX( mxProduct, mp );
            continue;
        }
        if( arr[i] < 0 ) {
            mp = arr[i] * mn;
            if( arr[i] >= mn ) mn = arr[i];
            else mn = INF;
            mxProduct = MAX( mxProduct, mp );
            continue;
        }
    }

    if( mn == INF ) {
        if( arr[i] < 0 ) {
            mn = arr[i] * mp;
            mp = INF;
            continue;
        }
        if( arr[i] > 0 ) {
            mp = arr[i] * mp;
            mn = INF;
            mxProduct = MAX( mxProduct, mp );
            continue;
        }
    }

    t1 = arr[i] * mp;
    t2 = arr[i] * mn;
    if( arr[i] > 0 ) mp = t1, mn = t2;
    if( arr[i] < 0 ) mp = t2, mn = t1;
    mxProduct = MAX( mxProduct, mp );
}

Source:
http://acm.uva.es/board/viewtopic.php?f=33&t=11466&hilit=11059&sid=6ed77239e43f67e7ca9999e1412b0180

Tuesday, February 12, 2013

Step Ahead in JAVA

Hello everyone, this is my solution for "Life, the Universe, and Everyting" in SPOJ. It was my first submission in JAVA. Take here a look.

/*
Task: Life, the Universe, and Everything (SPOJ)
Code: TEST
*/

import java.io.*;   // java input\output library 
import java.util.*; // using for Scanner class

class LifeSPOJ {
    public static void main ( String [] args ) {
        Scanner ss = new Scanner(System.in);
        int num;
        num = ss.nextInt(); // nest intejar
        while( num != 42 ) {
            System.out.println( num ); // printing that number
            num = ss.nextInt();
        }
    }
}

Saturday, October 20, 2012

Longest Palindromic Subsequence or Maximum Length of Palindrome

Definition:
              A sequence is called "Palindrome" if it is read same left to right and right to left. The sequence remains same as before after reversing it. The sequence "MADAM" is a Palindrome.
More about Palindrome.

A sequence which is a Palindrome is called a Palindromic Sequence. In this problem, given any sequence (not necessarily palindromic sequence), and we have to determine the Longest Palindromic Sub-sequence of Maximum Length of Palindrome of it.
A dynamic approach is not mandatory for this problem, because there is no overlapping sub-problems and so no optimal sub-structure available for Longest Palindromic Sub-sequence.
But if we go recursively, it can be easily determined. How? Obviously there is no overlapping sub-problems but we can divide it into sub-problems (that how we do it :p).
Here is a C++ solution for LPS.


#include <iostream>
#include <string>

using namespace std;

template<class T>inline T MAX( T a, T b ){ return a>b ? a:b; } // Note: returns maximum of a and b

string A;

int LPS( int i, int j ) {
    if( i == j ) return 1; // A[i] & A[j] are same, cost is 1
    if( i > j ) return 0;
    if( A[i] == A[j] )
        return 2 + LPS( i+1, j-1 ); // A[i] & A[j] are different, cost is 2, 1 for each.
    else
        return MAX( LPS(i+1, j), LPS(i, j-1) );
}

int main( ){
    while( cin >> A ){
        int len = A.length( );
        int res = LPS(0, len);
        cout << "Longest Palindromic Subsequence is: " << res << endl;
    }
    return 0;
}

Obviously, a memoization make the procedure lot more faster. Here is a memoized faster version.

#include <iostream>
#include <string>
#include <cstring>

using namespace std;

template<class T>inline T MAX( T a, T b ){ return a>b ? a:b; } // Note: returns maximum of a and b
const int SIZ = 105;

#define mset2d(x,n) memset(x,n,sizeof(int [SIZ][SIZ]))

string A;
int memo[SIZ][SIZ];

int LPS( int i, int j ) {
    if( i == j ) return 1; // A[i] & A[j] are same, cost is 1
    if( i > j ) return 0;
    if( memo[i][j] != -1 ) return memo[i][j];
    if( A[i] == A[j] )
        memo[i][j] = 2 + LPS( i+1, j-1 ); // A[i] & A[j] are different, cost is 2, 1 for each.
    else
        memo[i][j] = MAX( LPS(i+1, j), LPS(i, j-1) );
    return memo[i][j];
}

int main( ){
    while( cin >> A ){
        mset2d( memo, -1 );
        int len = A.length( );
        int res = LPS(0, len);
        cout << "Longest Palindromic Subsequence is: " << res << endl;
    }
    return 0;
}
Thanks - Jajabor, 2014