Increase battery life of ubuntu 14.04

Check how much watts of power battery consuming every second

$ sudo apt-get install powerstat
$ powerstat -d 1

And check watts option how much power consuming every second.

Now install TLP

$ sudo add-apt-repository ppa:linrunner/tlp
$ sudo apt-get update
$ sudo apt-get install tlp tlp-rdw smartmontools ethtool

Now start TLP. Note: You have to run this command only once, it will start automatically whenever system reboot or start

$ sudo tlp start

Check TLP status whether it is enable or disable

$ sudo tlp-stat


You see something like
 
+++ System Status
TLP power save = enabled
power source   = ac

Again check powerstat -d 1 and see the difference. Before power consumption and new power consumption.

Misson Mac Accomplished

Don’t know what to write in this post. Frankly speaking from last 2-3 days I’m no doing work properly, output that I’m producing is about 10% or less which stand nothing for me. Don’t know what I’m doing, what’s running in my mind :-/. Everytime I tried to do something ( code and all), something stops me to do that thing. Unable to concentrate on one particular thing. I wish I could program my mind

#ifndef _do_work_with_concentration_
#define _do_work_with_concentration_
#elseif

Day-before-yesterday I was assigned by a task of librehatti. I have to work on 1st April problem not very much cleared what he said while assigning task but I know what to do. Flow chart is in my mind. I tried to dive direct onto work/task but no luck because I don’t know even a single word of python code. I have done work in Django but year before, need to revise everything. But it will take little time now it’s like turning book pages.

From last 2 or 3 days what work I have done here it is in brief.

1). MAC OS X installation :P
Few days before I posted that I successfully installed MAC OS X. Well that OS is 10.5.6 version which snow leopard. Why I want to use apple OS? Basically I want itunes, it is there is 10.5.6 but older version as it is not compatible with iOS 7 for this we have to use 11.0 or higher version of itunes. Secondly, I want to develop iPhone app me myself. Can say for learning purpose and for enjoyment so I have to use Xcode which is only available for apple OS. Thirdly, Swift programming language, they claimed it is damn faster let’s see how fast it is. Right now Xcode beta 6 version support it.
I tested 10.8 version, 10.8.2 version 10.8.5 version but nothing worked huh!. I wasted almost 13 or 14 GB of data on downloading these OS. Each OS stop booting whenever I tries to boot them. Why?. Damn UEFI huh!.
I tested various tools, I never hear about them before like iBoot-ivy-1.1.0, FakeSMC, Clover, Kexts, few patches for kernel like voodoo’s, HWsensor and many more. Feels good while using them but I have very less idea what I’m doing as everything seems like What kind of  heck! is that.
Finally after 2 days of searched I found MAC OS X Maverick 10.9.0.iso file, while downloading I was little afraid what if this produce same error, what should I do then. I have to take risk but I already used 15GB of data so now internet speed slows down. I requested Chanpreet to download that iso for me. Today she handover me that 5.85GB of .iso file. God bless her. I start installation process, No! no! no! not again :( it stuck at ” boot: ” screen. Why this happens to me? I search about this error while searching i’m just praying that I get solution for this. Hopefully I read on someone’s blog that he face same. After reading his long blog post I came to know that, that was not an error that is how it start :P You have to boot it by using boot flags. I used -v flag and hit enter. After 10 minutes I was on cloud9 as it successfully boot up and apple logo is there. I created partition disk and all other requirements and 42 minutes later in successfully installed MAC OS X 10.9. Hurray!

2). Python
I’m have started reading python from yesterday onwards and I completed first 3 chapters which is OK. Not too slow not too fast. What I love about python is that it’s a straight forward english language eg:
>>>i = 4
>>>print i
>>>i
>>>4
That’s it you got an output, not like C/C++ that we need to include header files and that cout, printf. Every abstracted in python and encapsulated which is good for newbie programmer or bad don’t know but it’s good ;).

Seems like I have done nothing in these past days, tries to cover in coming days. Hope for best.

Replaying Django

After acquiring the knowledge of three functions used in Felt I
started to learn them out. The function intialize problem is used to
read the .dxf file. At the same time I also explored pathwork.h file.
It was just 15-20 lines of code and I took it lightly expecting that I
could understand it in very few time. But I forgot that it was a
header file and 15-20 lines of code means heavy linkage :(.

While studying the header file I went through the function node
<node-name>(double x, double y, double z, force Force, constrain Constraint). I
kept on reading but was not getting what is it. Blank! Couldn’t
understand where this function came from and what was it meant to do.
Then in the doucumentation there was fe.h header file in the include
directory where I found typedef for node and for its parameters, and
even for the angular displacement

After a lunch break, continued with my work. Also, there was a
presentation by Jasvir on Django. As the release date for LibreHatti
is quite near, it was decided that now every traniee needs to
contribute a little in it. First, I was not ready to work on it. I
went to Sir asking for his decision and he advised me devote little
little time to each project. Now I have decided to work 4 hours each
on Felt, Souvenir and LibreHatti. I will re-experience Django and
Python once more after my last year’s Project :).

I have assigned to work on Vouchers in Librehatti. I have started my
tour with it. I have installed MAC on my system which does not have
compatibility with itunes due some version problem so I needed to
install it again, and it has created many problems. I lost my terminal
and system crashed :( Due to that I couldn’t devote much time on
Librehatti but will accomplish my task very soon :)

Lil bit more MAC

I reached at 9:30 and continued with my Felt work. It was Kamal’s birthday today
that made my day enjoyable. We had a great party and that too two times.

After the Birthday celebration there were presentations:
1) Muskan on Natural coordinates which was her GD Re-entry task.
2) Two Electronics Students on PCB’s and gesture control.
3) Sanjeet on MathPiper as GD Re-entry task.

After coming home I  installed MAC on virtual box but there was little
problem with itunes. Although itunes work well on Windows but yet I
wanted to have it in MAC OS X. There was some problem with UEFI
mode settings, but I was stuck with my decision that I want to have it
in Ubuntu only and didn’t wanted to operate in Windows. I don’t know
how I will do it, but by hook or crook I will.

Merriment Sunday :D

Ah! finally Sunday, obviously I woke up late  around 1:00 P.M :P. I had no plan how to make my Sunday awesome, what code should I do. Around 3:00 P.M I started working on FElt.  I’m looking into FElt code and everything bouncing over mind OMG! what’s going on no idea. I took a lil bit break and searched about FElt finite element analysis. First link, second, third and so on didn’t find anything useful.  After an hour later I searched again and I can’t believe that I found master piece, it’s FElt dxf.c workflow image. FElt patchwork dxf.c

Awesome I know how to search haha!. I dive into code and start exploring each and every file, what I found is that I have to go through each and every file. As in some there is function definition and same function declaration is in another file. So I start reading file from bottom to up. After spending 2-3 hours on it I found that there are three main function on which dxf.c is working ( Maybe I’m wrong but I found these functions )

Functions :-
int     InitializeProblem ()      // Definition at line 44 of file util,.c.
int     ReadDXFFile (char *name)     //Definition at line 41 of file dxf.c.
int     WriteDXFFile (char *name)     //Definition at line 135 of file dxf.c.

Now my main target is to find out out how these function work, which one is using which header file and why, how to co-relate with each other and so on. It’s a small cum big achievement for me.  It’s about 10:00 P.M, ah! can’t read anymore code, fed up, totally fed up. It’s been 6 hours that I’m continuously working on FElt, now can’t take it anymore Phew!. Want to taste something else, something more tastier than FElt, something that I never experienced. Hmm what to do, what to do, YES! install MAC OS X  in ubnutu. Wait it was tried before by gagan but it will not run. After few weeks later I found Vigas able to install Hackintosh on this machine. I asked him how he did it he said he changed kernel blah! blah! everything jumped over my mind. But I always want to use MAC OS X, i’m big fan of Apple. I want means I want :D.

After searching I found we can install MAC OSX by using qemu. All we need is “iPC_OSx86″ special OSX iso file. After downloading that iso file (hush! 3.8 GB in size) I dive into it’s installation. After 3 hours magic happen, ultimate magic happen. I can’t believe that MAC OS X running on my machine. It’s like oh! my gosh I did it :D. But in qemu OS X runs slow it will take 2-3 seconds to move mouse cursor from one point to another. I planned to deploy it in virtualbox. And in virtualbox it runs like, like i’m using MAC pro :P. It will take 20 minutes to install and configuration. That’s how my personal MAC OS X looks like in virtualbox

MAC OS X

Always want to use Apple’s OS but never get a chance. Now chance is mine, machine is mine and OS X is mine :D.

Time to dive into sea of “C”

Yesterday, 14-August-2014 I didn’t even taste single word of code. I just focus on sleep, sleep and sleep. Don’t know why I slept all day (approx.). As I wasted my whole day so next day i.e 15-August-2014 I planned that I have to complete what I left behind no matter how.
Day being, wait wait, first of all Happy Independence Day. Today my target is to complete my C-lang concepts ASAP, as i’m running out to time to meet my deadline which I set for myself for FElt project. Don’t know how other understand any programming language so fast without leaning it’s concepts and all. I can’t do it like this, in my case firstly I revise all concept of language (basics ones) so that I can deal with them easily.

Today I learned great concepts of C-programming like memory allocation, typecasting etc. I want to share few with you.

  1. Dynamic Memory allocation :
    DMA is the process of allocating memory during program execution. That means at run time. Memory size can be modified while execution like linked list.In C language there are 4 type of memory allocation namely : malloc, calloc,  realloc and free.Here is the syntax of each memory allocation scheme.

    S.no
    Function
    Syntax
    1 malloc () malloc (number *sizeof(dataType));
    2 calloc () calloc (number, sizeof(dataType));
    3 realloc () realloc (pointerName, number * sizeof(dataType));
    4 free () free (pointerName);
  2. Type Casting functions :
    Typecasting concept in C language is used to modify a variable from one date type to another data type. New data type should be mentioned before the variable name or value in brackets which to be typecast.Under type casting I have learned few things till now like how to typecast string to float, string to int, string to long, int to string and long to string. I just go through all of them in brief not in detail. C language has pre-defined typecaste function for example if I want to typecaste from string to float, then there is pre-define function called atof(). For eg:

    #include <stdio.h>
    #include <stdlib.h>
    
    int main() {
        char a[20] = "3.14";
        float pi = atof(a);
        printf("Value of pi = %f\n", pi);
        return 0;
    }

    The output of this program will be 3.140000. In this char a[] is typecasting to float.

    It feels awesome while working on C, I got a feeling that FElt gonna be infinity time awesome. Objective-C rocks (y).  I almost done with my C concepts, from tomorrow onwards FElt i’m all yours :D.

Compiler Design

This post is about compiler design, it’s phases and it’s working :

Let’s have a look on simple C program of adding two numbers.

#include<stdio.h>
int main() {
  int a = 5;
  int b = 3;
  int c = a + b;
  printf("Sum = %d\n",c);
  return 0;
}

Now this C program what we call as “High level language program“. It can be C. java. python and so on. Why they called as high level language because they are written in more abstract manner and we can directly put our thoughts directly into them. Say if you want to add two number one is in float type and another is in int type, so what you do, you just write your thoughts like

float a = 3.25;int b = 10;

A normal computer cannot understand that high level language. I it can understand is called as “Machine Code“. It is damm difficult to write our thought in Machine Code which is usually in 0’s and 1’s. There is an intermediate which is one level up to machine code which we call it as “Assembly level language”.

Compiler :

Compiler is nothing, it is a software or a program whose input is a high level program and output can be an Assembly Level Program then assembler convert it into Machine Code or it can directly give us what we call as Machine Code. In short we can say that “Compiler is a program that can convert hight level language into machine code.

We can now say that machine code is much faster than assembly level program and assembly level program is much faster than high level program.

Machine Code > Assembly level program > High level program

What functionality should present in compiler :

  1. Correctness :
    • Correct output on execution.
    • Report error correctly if the programmer is not following the language syntax.
  2. Efficiency :
    • How efficiently the compiler is generating the code.
    • How efficient the generated code is.
  3. Debugging/Usability
    if you write say : floatt a = 5;
    undefined variable ” floatt “. It should tell that, that thing is undefined and line number where possible error should be and file name.

Stages of compiler

Front-end of compiler :

  1. Lexical Analysis :
    It act like a scanner, which means when we write any high level code and when it move through this phase it read the file a text stream and tries to convert it into tokens. Rules for defining these tokens are predefined for a given language. If a say
    float a = 5;
    For this statement

    " Float = Keyword "
    " a = indetifier / Variable "
    " = = operator / Assignment operator "
    " 5 = Decimal Number "
    " ; = Delimiter. It can be new line, can be comma, semi-colon and so "
    
  2. Syntax Analysis :
    After lexical analyser next stage comes syntax analysis. We get list of tokens from lexical analyser. So syntax analyser (also called parser) accept that tokens.  What it does it tires to follow the rules of given language / grammar and tries to create abstract syntax tree or parse tree.What is Grammar 
    Grammar is the set of non-terminals, terminals, rules or productions and starting of non-terminal .
    G = (V, T, P,S)
    Graph start from S i.e starting of non-terminal then comes set of non-terminals then the leaf nodes are set of terminals.
    Syntax checker tries to read the rules of grammar and tries to create parse tree. It also removes ambiguity by following the association and presidency rule.
  3. Semantic Analysis :
    Also called semantic checker. This phase of the compiler tries to follows the semantic rules of given language. If I say that  :
    var a;
    If a variable is used but it is not defined then it is called as semantic error. Synatically it is correct like x = 5; but if x is not defined then it is semantic error.
    or if I create

    int function(int);
    int function (int) {
    char c;
    return c;
    }

    In this i’m creating a function which has to return a int value but i’m returning char value, which is semantically wrong. Whether I have to change char to int or another way is to type case it.

Back-end of compiler :

  1. Intermediate code generator :
    Intermediate code is a machine independent code which is more close to machine instruction. Different kind of compiler use different type of ICG.
    Some people use :

    • AST
    • Control and data flow graph
    • Three address codeMost widely used is three address code. How three address code looks like say if I have
      c = a +b
      then three address code should be : ” add a b c “. It has three variable a and b, three variable where it stores the result. And add is the operator. So it also know as quadruple.Some languages like java has its own intermediate code generator capability. Like java has specific kind of code called Byte code. What it do exactly, we install JVM or java virtual machines which take byte code as input and runs the program.
  2. Register Allocation :
    Suppose I have intermediate representation like this

    add a   b   c
    sub c   b   d
    add b   a   c

    Now problem comes out how to store value in registers. As there are limited number of register in our computer. So we use specific algorithm, one of the algorithm called as Graph colouring algorithm.

    Graph colouring algorithm :-

    If I have graph with three vertices say V1, V2, V3 and arranged them in the triangle shape such that V1 is adjacent to V2 and V2 is adjacent to V3 and V3 to V1. So what is states that colour the vertices of a graph such that no two adjacent vertices are of same colour.

  3. Machine code generation :
    Given the intermediate code we use the translator that takes input as intermediate code and output is assembly level code. This assembly level code is machine dependent. Job of the compiler is to decide the architecture  ( whether unix, windows or else ) then generates the assembly level code.
  4. Assembly and Linking :
    Finally, after creating assembly level code. Assembler and linker takes input as assembly code and generates the binary representation for execution. That is why we called final out as binary.

Finite ELemenT analysis (FElt) Installation. Version->3.0.5

Installation :

Install Dependencies :

$ sudo apt-get install cmake
$ sudo apt-get install flex
$ sudo apt-get install bison
$ sudo apt-get install libboost1.55-dev
$ sudo apt-get install libxt-dev
$ sudo apt-get install libxaw7-dev
$ sudo apt-get install libgl1-mesa-dev
$ sudo apt-get install libglu1-mesa-dev
$ sudo apt-get install libglw1-mesa-dev

Installation Steps :

$ git clone https://github.com/deepakkumarsharma/felt.git
$ cd felt
$ git checkout release-3.8
$ make all
$ sudo make install

Run Example:

$ cd felt
$ cd examples

For Command line stuff

$ felt <any-file>.flt  /* This will show stuff in command line */

For GUI 

$ velvet <any-file>.flt

 

11th of August

After guided by sir how to run FElt I dived into it. Version 3.7.1 is
throwing some error, even it has been installed well still it’s not
working.
I have pre-installed version of FElt which is 3.7.1. Sir claimed that
it was running on experimental (Version is 3.0.5 ) and he copied
master branch from https://github.com/pavossos/felt/tree/master and
when he installed that to his laptop, it worked well. Both versions
3.7.1 and 3.0.5 are present in his machine but when sir did

$felt -version (it gave output)
3.0.5

which is obvious that he recently installed pavossos master branch
which overwrite files of 3.7.1. Even velvet ( GUI part ) works well in
his machine.

1). After learning everything from this, I too installed pasvossos
master branch and after installation I got

$felt -version
3.0.5

But when I did “velvet <filename>” it opened but still threw same
error message (which we get in 3.7.1 v) i.e Aborted (core dumped).

2). I un-installed everything and now I installed 3.0.5v first then
3.7.1v. Now felt command working but not velvet again Aborted (core
dumped).

3). I uninstalled everything again ( this time even man pages :P ) and
installed one more time. Firstly 3.7.1v then 3.0.5. Now both felt and
velvet commands are running, and velvet is throwing no error message
but when I’m trying to open any other velvet file from GUI window it
does not open. No error nothing, just refreshed to old one. I need to
close it and run velvet once again for every particular file.

4). I cloned pavossos master from his github repo and download tar.gz
folder of FElt from sir’s experimental account plus 3.7.1v and merge
them to one, i.e pasvossos + sir’s + 3.7.1 into one. When I tried to
run cmake ../ it worked fine. But when I ran ” make  “command, it runs
upto 1% and then error message. Something array error that array is in
this file not declared.( Forgot to note that error :( )

5). Next I prepared myself to work on command line and don’t want GUI
and started reading about FElt. But [OT]  : ” Dil hai ke manta
nhi :P. ” back to installation and searching why GUI not working.

6). Finally I decided one more try. this time firstly I installed
3.7.1v then 3.0.5v. Viola! both GUI and felt command working now. But
this is short-cut method which is wrong.

7). I don’t know what came to my mind, again I deleted everything (
each and every singe file again ).  I tried 3.7.1v even 3.0.5 I was
thinking what should I do. “Release-3.8″ strike into my mind
immediately. I read it somewhere, I searched and searched. About half
an hour, I came to know that I saw this word here =>
https://github.com/pavossos/felt/tree/release-3.8

It’s a branch name in pavossos github repo. I cloned one more time his
FElt repo and this time I did checkout to release-3.8.

Steps:

1). git clone https://github.com/pavossos/felt.git
2). cd felt
3). make all
4). sudo make install

FElt installed with version 3.0.5
YES! both GUI and felt command are working.