Sunday, January 19, 2014

Having trouble with laptop brightness settings on Ubuntu or Fedora?

Simple, yet effective method. Has been tested on many older HP and Lenovo systems.

1. Open the file /etc/default/grub and look for GRUB_CMDLINE_LINUX="quiet splash".

2. Change it to:
GRUB_CMDLINE_LINUX="quiet splash acpi_backlight=vendor"

3. Save the file and reboot.

Your First JavaScript Animation

You can create a quick animation using JavaScript in about 10 lines of code. All you need are Gedit and Firefox, both being available by default on your system.

Create an html file, say test.html, with the following contents:

<!-- test.html -->

<!--
This animation uses two boxes, one big and another small. The small box moves inside the big box. These two boxes are created using following two "div" objects:
-->

<div style="width:1000;height:550;border-style:solid;border-width:2" />
<!--This div element is 1000 pixels wide and 550 pixels heigh. It has got a solid border of 2 pixel thickness.-->

<div id="square" style="width:100;height:100;border-style:solid;border-width:2;border-color:purple;background-color:yellowgreen;">
</div>
<!--This div object is a 100 pixel wide square. Its name/id has been set to the word "square" for easy identification. It also has a solid border of 2 pixel thickness. This border is purple and the box is shaded with yellow-green color. -->

<script>
//This small script describes the interaction between the two boxes declared above.

//First we create a javascript variable called "box" which actually refers to the second div object (whose id was manually set to the word "square").

var box = document.getElementById("square");

//We create a variable "dist" which stores the distance moved by the box along X and Y axis during each frame of animation. The higher this distance, the faster will the small box move.
var dist = 2;

//posX and posY are meant to store the x and y coordinates of the top left corner of the small box. 
//dirX indicates if the small box is moving in positive or negative X direction. If the value of dirX is +dist, posX is increasing and if the value of dirX is -dist then posX is decreasing. Initially both dirX and dirY are +dist.
var posX=0, posY=0, dirX=dist, dirY=dist;

//Function move() will move the small box and then set a timer to call itself again.
function move()
{
  
  //Update the position variables by distance stored in dirX and dirY
    posX += dirX;
    posY += dirY;
  
  //If posX is 0, it means small box is touching LEFT edge of the big box.
  //If posX is 1000-100 then the small box is touching the RIGHT edge of the big box.
    if( posX < 0 ) dirX = dist; else if( posX > 1000-100 ) dirX = -dist; 
  
  //If posY is 0, small box is touching TOP edge of the big box.
  //If posY is 550-100 then small box is touching BOTTOM edge of the big box.
    if( posY < 0 ) dirY = dist; else if( posY > 550-100 ) dirY = -dist; 
  
  //Assign the position stored in posX and posY as the actual position of the small box.
    box.style.marginLeft = posX;
    box.style.marginTop = posY;
   
  //To continue animation execute the function move() again after 10 milliseconds.
  setTimeout( move, 10 );  //milliseconds
}

//So far we have only defined what the function move() is. Now we should call move() so that it starts running. Once move() starts running it will never stop because move() is calling itself recursively. The animation will continue forever until the browser window is closed.
move();

</script>

Open the file test.html in Firefox.

That's it.

Tuesday, December 24, 2013

What to do during and after Ubuntu 13.10 installation

Here's the complete workflow I use to set up Ubuntu 13.10:

A. GENERAL CONSIDERATIONS DURING FRESH INSTALLATION
  1. Allocate a 50GB partition and install the system there.

  2. After installation immediately set the root password and create a new user with limited access.
 
  3. Log on as the new limited user and utilize all free disk space to create multiple encrypted partitions.

  4. Restore all backed up data to the encrypted partitions.

B. FIGHTING UBUNTU'S IDIOSYNCRASIES:
  1. Visit fixubuntu.com and copy and execute commands from there. This will disable automatic online search and make several privacy enhancements.

  2. Remap HUD Key which is "left alt" by default to something else
    System settings -> Keyboard > Shortcuts > Launchers -> HUD key -> ctrl-alt-h  

  3. Open Software & Updates and disable multiverse to keep updates light.
 
  4. Modify "security and privacy" settings to your requirements.

  5. Disable paid software as described in another post.
 
  6. Uninstall useless software to keep updates light.
    apt-get autoremove gnome-contacts ubuntuone-control-panel-qt gnome-mines unity-lens-photos aisleriot gnome-mahjongg gnome-sudoku empathy remmina thunderbird vino unity-scope-gdrive rhythmbox totem gnome-control-center-signon gnome-user-share landscape-client-ui-install gnome-orca onboard deja-dup  

C. INSTALL UPDATES AND ESSENTIAL SOFTWARE
  apt-get update && apt-get upgrade
 

  apt-get install geany g++ vlc gimp ghex alarm-clock-applet compizconfig-settings-manager

D. TWEAK GNOME/UNITY 
  1. Get rid of folders cluttering the home folder. To store your personal files use encrypted partitions created earlier.
    rmdir ~/Public/ ~/Documents/ ~/Music/ ~/Pictures/ ~/Videos/ ~/Downloads/ ~/Templates/
    rm ~/examples.desktop
 

  2. If the system text is too small, scale it by an appropriate factor:
    gsettings set org.gnome.desktop.interface text-scaling-factor '1.35' 

  3. If F4 requires Fn+F4, remap close window key to Super-Q: 
    gsettings set org.gnome.desktop.wm.keybindings close "['<Super>Q']" 

  4. Highly recommended: Set bottom left screen corner to initiate window picker.
    $ ccsm
      Advanced Search >>  Scale >> Binding >> Initiate Window Picker >> Bottomleft


  5. Disable gedit as root (we'll be using geany instead):
    cd /usr/bin
    mv gedit gedit.backup
    Right click a .txt file and in its property dialog set default application as geany.
 
E. APPLICATION SPECIFIC MODIFICATIONS   
  1. Make geany more usable:
    Open geany and in preferences dialog:
      unselect interface->show sidebar
      unselect interface->show statusbar
      select editor->features->line wrapping
    In the main menu:
      unselect view->show message window
      unselect view->show toolbar

  2. Add adblock plus plug-in to firefox.
 

Friday, November 15, 2013

Complete Minimal SDL2 OpenGL Animation Program with no memory leaks


#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <iostream>
using std::cout;

int main()
{
  int width = 640, height = 480;
  SDL_Init(SDL_INIT_VIDEO);
  SDL_Window *window = SDL_CreateWindow( "Grapics Application", 0, 0, width, height, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
  SDL_GLContext glcontext = SDL_GL_CreateContext(window);
  cout << "OpenGL Version " << glGetString(GL_VERSION) << "\n";
  glClearColor(0,0,0,1);
  glViewport( 0, 0, width, height );
  glFrustum( -1, 1, -(float)height/width, (float)height/width, 1, 500 );
  SDL_Event event;
  while( 1 )
  {
    while( SDL_PollEvent( &event ) )
    {
      switch( event.type )
      {
        case SDL_WINDOWEVENT:
          if( event.window.event == SDL_WINDOWEVENT_RESIZED )
          {
            glViewport( 0, 0, event.window.data1, event.window.data2 );
            glLoadIdentity();
            glFrustum( -1, 1, -(float)event.window.data2/event.window.data1, (float)event.window.data2/event.window.data1, 1, 500 );
          }
          break;
        case SDL_QUIT: SDL_GL_DeleteContext(glcontext); SDL_DestroyWindow(window);SDL_Quit(); return 0;
      }
    }
  static float delta = 0;
  delta += 0.002;
  glClear(GL_COLOR_BUFFER_BIT);
  glBegin(GL_TRIANGLES);
  glVertex3f( delta, 0, -5 );
  glVertex3f( 1+delta, 0, -5 );
  glVertex3f( delta, 1, -5 );
  glEnd();
  SDL_GL_SwapWindow(window);
  SDL_Delay(20);
  }
}

Tuesday, October 22, 2013

Changing the world: Python and XML

Although I have occasionally used Python and I program in C++ 100% of time, if I were to rule the world I would issue an ultimatum to all programming languages to conform to Python syntax within 5 years after which all backward compatibility will be dropped! Python offers a terse human readable syntax.

Now for a verbose machine readable syntax which is still very human friendly, I would choose XML. So again, Latex gets five years to confom to Python (terse) or XML (verbose) or both flavors.

The idea is that we can keep on complicating things in the pretext of simplifying them.

For example, for all publishing needs we can rely on Python and XML syntax, syntax highlighting text editors (Vim for shell and Geany for GUI), PNG format for images and bzip2 to package all the stuff in a single file ready to be dispatched to a printer or a projector via a rendering application. This can unify and simplify hardware, software and application design.

Thursday, September 19, 2013

Show only "Free" software in Ubuntu Software Center

In other words, "How to prevent paid software from being listed in Ubuntu Software Center"


Follow three simple steps as root:

1. In the file
/usr/share/software-center/softwarecenter/db/update.py
 
somewhere near line 480 find the following lines and add the highlighted line:
 
        doc = self.make_doc(cache)
        if not doc:
            LOG.debug("%r.index_app_info: returned invalid doc %r, ignoring.",
                      self.__class__.__name__, doc)
            return
        name = doc.get_data()

        if doc.get_value(XapianValues.PRICE) not in (""): return
        if name in seen:
            LOG.debug("%r.index_app_info: duplicated name %r (%r)",
                      self.__class__.__name__, name, self.desktopf)
        LOG.debug("%r.index_app_info: indexing %r",
                  self.__class__.__name__, name)
        seen.add(name)
  
2. In the file 
/usr/share/software-center/softwarecenter/backend/channel_impl/aptchannels.py
 
find the following lines and commentize the highlighted lines:

        if partner_channel is not None:
            channels.append(partner_channel)
        #if get_distro().PURCHASE_APP_URL:
        #    channels.append(for_purchase_channel)
        if new_apps_channel is not None:
            channels.append(new_apps_channel) 
3. Issue the command:
# update-software-center
 
4. Also disable "multiverse" from "Software and Updates" settings panel.