IMPORTANT NOTICE: This blog is discontinued in favor of retroubuntu.blogspot.com.
Sunday, August 21, 2016
One Liners
System in use: Ubuntu with Unity, 64-bit
FREQUENTLY USED COMMANDS
# Find file with partial name in current folder
find . -iname "*report*"
NUISANCE / IRRITATION CONTROL
# Stop all sorts of notifications
dbus-monitor "interface='org.freedesktop.Notifications'" | xargs -I '{}' pkill notify-osd&
# Tiny font size? No problem.
gsettings set org.gnome.desktop.interface font-name 'Ubuntu 14'
FILE FORMAT AND DOCUMENT CONVERSION
# Create a pdf file from a bunch of png images
convert *.png -gravity South output.pdf
# Convert newline character from dos to unix
dos2unix infile outfie
PROGRAMMING AND COMPILERS
# Show default defines of GCC
echo | gcc -dM -E -
FREQUENTLY USED COMMANDS
# Find file with partial name in current folder
find . -iname "*report*"
NUISANCE / IRRITATION CONTROL
# Stop all sorts of notifications
dbus-monitor "interface='org.freedesktop.Notifications'" | xargs -I '{}' pkill notify-osd&
# Tiny font size? No problem.
gsettings set org.gnome.desktop.interface font-name 'Ubuntu 14'
FILE FORMAT AND DOCUMENT CONVERSION
# Create a pdf file from a bunch of png images
convert *.png -gravity South output.pdf
# Convert newline character from dos to unix
dos2unix infile outfie
PROGRAMMING AND COMPILERS
# Show default defines of GCC
echo | gcc -dM -E -
Monday, June 2, 2014
Create your own web server in C/C++
Here I'll outline steps to create basic web server on Linux in C/C++ using sockets.
Let's begin with list of ingredients:
1. We need to open a socket for listening purpose by calling following function:
int socket(int domain, int type, int protocol);
2. Next we need to bind the homeless socket just created to some address (port) using call to this function:
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
3. The trap is set. Now wait for the game.
int listen(int sockfd, int backlog);
4. Accept a connection as it comes and receive the data:
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
5. Send your response
ssize_t send(int sockfd, const void *buf, size_t len, int flags);
6. Shutdown the connection and close the client socket
int shutdown(int sockfd, int how);
int close(int fd);
Here's the client code:
#include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SERVER_PORT 12345 /* arbitrary, but client and server must agree */
#define BUF_SIZE 4096 /* block transfer size */
#define QUEUE_SIZE 10
void fatal(const char *string)
{
printf("%s", string);
exit(1);
}
int main(int argc, char *argv[])
{
int s, b, l, fd, sa, bytes, on = 1;
char buf[BUF_SIZE]; /* buffer for outgoing file */
struct sockaddr_in channel; /* hold's IP address */
/* Build address structure to bind to socket. */
memset(&channel, 0, sizeof(channel)); /* zero channel */
channel.sin_family = AF_INET;
channel.sin_addr.s_addr = htonl(INADDR_ANY);
channel.sin_port = htons(SERVER_PORT);
/* Passive open. Wait for connection. */
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); /* create socket */
if (s < 0) fatal("socket failed");
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on));
b = bind(s, (struct sockaddr *) &channel, sizeof(channel));
if (b < 0) fatal("bind failed");
l = listen(s, QUEUE_SIZE); /* specify queue size */
if (l < 0) fatal("listen failed");
/* Socket is now set up and bound. Wait for connection and process it. */
while (1) {
sa = accept(s, 0, 0); /* block for connection request */
if (sa < 0) fatal("accept failed");
read(sa, buf, BUF_SIZE); /* read file name from socket */
printf("[%s]\n", buf );
/* Get and return the file. */
fd = open(buf, O_RDONLY); /* open the file to be sent back */
if (fd < 0) fatal("open failed");
while (1) {
bytes = read(fd, buf, BUF_SIZE); /* read from file */
if (bytes <= 0) break; /* check for end of file */
write(sa, buf, bytes); /* write bytes to socket */
}
close(fd); /* close file */
close(sa); /* close connection */
}
}
Let's begin with list of ingredients:
1. We need to open a socket for listening purpose by calling following function:
int socket(int domain, int type, int protocol);
2. Next we need to bind the homeless socket just created to some address (port) using call to this function:
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
3. The trap is set. Now wait for the game.
int listen(int sockfd, int backlog);
4. Accept a connection as it comes and receive the data:
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
5. Send your response
ssize_t send(int sockfd, const void *buf, size_t len, int flags);
6. Shutdown the connection and close the client socket
int shutdown(int sockfd, int how);
int close(int fd);
Here's the client code:
/* This page contains the client program. The following one contains the
* server program. Once the server has been compiled and started, clients
* anywhere on the Internet can send commands (file names) to the server.
* The server responds by opening and returning the entire file requested.
*/
#include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
void fatal(const char *string)
{
printf("%s\n", string);
exit(1);
}
#define SERVER_PORT 12345 /* arbitrary, but client and server must agree */
#define BUF_SIZE 4096 /* block transfer size */
int main(int argc, char **argv)
{
int c, s, bytes;
char buf[BUF_SIZE]; /* buffer for incoming file */
struct sockaddr_in channel; /* holds IP address */
if (argc != 2) fatal("Usage: client file-name");
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s < 0) fatal("socket");
memset(&channel, 0, sizeof(channel));
channel.sin_family= AF_INET;
inet_pton ( AF_INET, "localhost", &channel.sin_addr );
channel.sin_port= htons(SERVER_PORT);
c = connect(s, (struct sockaddr *) &channel, sizeof(channel));
if (c < 0) fatal("connect failed");
/* Connection is now established. Send file name including 0 byte at end. */
write(s, argv[1], strlen(argv[1])+1);
/* Go get the file and write it to standard output. */
while (1) {
bytes = read(s, buf, BUF_SIZE); /* read from socket */
if (bytes <= 0) exit(0); /* check for end of file */
write(1, buf, bytes); /* write to standard output */
}
}
And the server code: #include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SERVER_PORT 12345 /* arbitrary, but client and server must agree */
#define BUF_SIZE 4096 /* block transfer size */
#define QUEUE_SIZE 10
void fatal(const char *string)
{
printf("%s", string);
exit(1);
}
int main(int argc, char *argv[])
{
int s, b, l, fd, sa, bytes, on = 1;
char buf[BUF_SIZE]; /* buffer for outgoing file */
struct sockaddr_in channel; /* hold's IP address */
/* Build address structure to bind to socket. */
memset(&channel, 0, sizeof(channel)); /* zero channel */
channel.sin_family = AF_INET;
channel.sin_addr.s_addr = htonl(INADDR_ANY);
channel.sin_port = htons(SERVER_PORT);
/* Passive open. Wait for connection. */
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); /* create socket */
if (s < 0) fatal("socket failed");
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on));
b = bind(s, (struct sockaddr *) &channel, sizeof(channel));
if (b < 0) fatal("bind failed");
l = listen(s, QUEUE_SIZE); /* specify queue size */
if (l < 0) fatal("listen failed");
/* Socket is now set up and bound. Wait for connection and process it. */
while (1) {
sa = accept(s, 0, 0); /* block for connection request */
if (sa < 0) fatal("accept failed");
read(sa, buf, BUF_SIZE); /* read file name from socket */
printf("[%s]\n", buf );
/* Get and return the file. */
fd = open(buf, O_RDONLY); /* open the file to be sent back */
if (fd < 0) fatal("open failed");
while (1) {
bytes = read(fd, buf, BUF_SIZE); /* read from file */
if (bytes <= 0) break; /* check for end of file */
write(sa, buf, bytes); /* write bytes to socket */
}
close(fd); /* close file */
close(sa); /* close connection */
}
}
Based on Tanenbaum, "Computer Networks"
Clang vs GCC
Yes, Clang is definitely more focused and colorful at error reporting than GCC.
It might compile faster than GCC (though I didn't observe that).
Running my own graphics program showed Clang generated executable to be slightly slower than GCC generated executable. Frame-rate was 0.22% less and CPU utilization was 4.37% less for Clang generated executable.
Here's the raw data for those who are interested:
Clang generated executable:
44.151 FPS
Consumed 1 second of CPU time every 9.544 seconds
GCC generated executable:
44.247 FPS
Consumed 1 second of CPU time every 9.980 seconds
It might compile faster than GCC (though I didn't observe that).
Running my own graphics program showed Clang generated executable to be slightly slower than GCC generated executable. Frame-rate was 0.22% less and CPU utilization was 4.37% less for Clang generated executable.
Here's the raw data for those who are interested:
Clang generated executable:
44.151 FPS
Consumed 1 second of CPU time every 9.544 seconds
GCC generated executable:
44.247 FPS
Consumed 1 second of CPU time every 9.980 seconds
Sunday, April 6, 2014
Scientific vs Non-scientific claims
There's no easy way to distinguish between scientific and not-scientific claims but it will be interesting to know what fraction of academic research passes the following tests:
Check the system
Check the complementary system (alternate contending models)
Test the system
Finally, ensure that the effect of D used to support R and subsequently statement S has been correctly identified by removing the ingredients from D one or two or many at a time and trying to predict the outcome S' in absence of those sets of ingredients. If predictions match the actual outcome S' it is very likely that the effects of ingredients in D have been correctly understood.
The overall result will be a probability value indicating how correct claim S is. This value is subject to improve or diminish or fluctuate when more observations, data and analysis tools are made available over time. For example, if the number of strongly contending models increases, truthfulness of S should diminish.
Comments:
Theory of Evolution
Biological evolution is not a 100% fact. It is 99.9% fact and hence it is a mere theory.
- Let the claim statement be S.
- Let entire set of reasoning used to prove that S is true be R.
- Let the entire set of data used to obtain inferences R be D.
Check the system
- Ensure that D is free from instrument or observer error.
- Make sure that R is obtained by performing mathematically and physically sound analysis of D.
- Verify that S can be concluded from R.
Check the complementary system (alternate contending models)
- Find out if there are no hidden D' in the system that will lead to (or falsify) conclusions R because D might itself be a side-effect of D' and hence not being the cause of R.
- Make sure there are no hidden R' which are in fact responsible for possible truthfulness (or falsification) of S and R merely being side-effect of R'. (Here D' and R' together form alternate contending models proving or disproving S)
Test the system
Finally, ensure that the effect of D used to support R and subsequently statement S has been correctly identified by removing the ingredients from D one or two or many at a time and trying to predict the outcome S' in absence of those sets of ingredients. If predictions match the actual outcome S' it is very likely that the effects of ingredients in D have been correctly understood.
The overall result will be a probability value indicating how correct claim S is. This value is subject to improve or diminish or fluctuate when more observations, data and analysis tools are made available over time. For example, if the number of strongly contending models increases, truthfulness of S should diminish.
Comments:
- Where do all the data come from?
- Every belief is false unless there's no better explanation available.
Theory of Evolution
Biological evolution is not a 100% fact. It is 99.9% fact and hence it is a mere theory.
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.
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.
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.
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.
Tuesday, November 19, 2013
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.
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
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.
Friday, August 30, 2013
Some essential remapping of shortcut keys on Ubuntu
Since Ctrl-W is most widely used shortcut to close tabs I find it was a very short sighted decision to map Super-W to launch window picker in Ubuntu.
Hence I have mapped window picker to Alt-E key combination as follows:
1. Install Compiz Config Settings Manager:
# apt-get install compizconfig-settings-manager
2. Launch compiz config settings manager as "normal" user:
$ ccsm
In the panel that pops up, follow
Advanced Search >> Scale >> Binding >> Initiate Window Picker
Remap the key binding to Alt-E
Using Super-Q to close a window rather than Alt-F4
Execute following command (Ubuntu 13.04 or Fedora 19)
gsettings set org.gnome.desktop.wm.keybindings close "['<Super>Q']"
Hence I have mapped window picker to Alt-E key combination as follows:
1. Install Compiz Config Settings Manager:
# apt-get install compizconfig-settings-manager
2. Launch compiz config settings manager as "normal" user:
$ ccsm
In the panel that pops up, follow
Advanced Search >> Scale >> Binding >> Initiate Window Picker
Remap the key binding to Alt-E
Using Super-Q to close a window rather than Alt-F4
Execute following command (Ubuntu 13.04 or Fedora 19)
gsettings set org.gnome.desktop.wm.keybindings close "['<Super>Q']"
Installing Ubuntu on a fresh system
Ubuntu 13.04
1. Download the iso file and create a live bootable USB stick (http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-windows).
2. Boot the system using the USB stick and install Ubuntu in a 50 GB or 15% of total capacity of your hard disk, whatever is greater. Create a swap equal to installed memory but do not create any partitions at present. Leave rest of the disk free.
3. Log on to new user and create two (or more) encrypted partitions.
4. Open software center and uninstall useless software.
5. I also remove unity lenses by executing following commands as root:
apt-get autoremove unity-lens-shopping
apt-get autoremove unity-lens-music
apt-get autoremove unity-lens-photos
apt-get autoremove unity-lens-video
6. Execute following command as root:
apt-get update && apt-get upgrade
7. Install essential software:
apt-get install geany g++ vlc gimp ghex
8. Now open "Disks" utility and create two (or more) encrypted partitions.
1. Download the iso file and create a live bootable USB stick (http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-windows).
2. Boot the system using the USB stick and install Ubuntu in a 50 GB or 15% of total capacity of your hard disk, whatever is greater. Create a swap equal to installed memory but do not create any partitions at present. Leave rest of the disk free.
3. Log on to new user and create two (or more) encrypted partitions.
4. Open software center and uninstall useless software.
5. I also remove unity lenses by executing following commands as root:
apt-get autoremove unity-lens-shopping
apt-get autoremove unity-lens-music
apt-get autoremove unity-lens-photos
apt-get autoremove unity-lens-video
6. Execute following command as root:
apt-get update && apt-get upgrade
7. Install essential software:
apt-get install geany g++ vlc gimp ghex
8. Now open "Disks" utility and create two (or more) encrypted partitions.
Saturday, August 17, 2013
Transition from Gnome 3 to LXDE
1. Install LXDE as root
# yum install @lxde-desktop
2. Log on as standard user in LXDE mode
3. Edit the file ~/.config/openbox/lxde-rc.xml and change font size for ActiveWindow and InactiveWindow from 10 to 1. This will finally make title bars completely vanish.
4. To enable clicking by tapping on touchpad, add following line to /etc/xdg/lxsession/LXDE/autostart:
@synclient TapButton1=1
5. (Optional) If you want to adjust font size create file ~/.Xresources and add following line to it (default value 96):
Xft.dpi: 163
6. Right click the "panel" and click on "panel settings" and set them as follows:
Geometry
Edge: Top
Alignment: Left
Width: Dynamic
Height: 18
Icon Size: 16
Panel Applets
Menu
Application Launch Bar
Select "Application Launch Bar" and clik on "Edit".
Then add following items to Application Launch Bar:
Files
Firefox
Terminal
Sound
System Tray
Battery Monitor
7. Skip to step 9 if you don't want Mac-Expose/Gnome-3 style window switching.
Edit the file ~/.config/openbox/lxde-rc.xml again and add following lines:
<keybind key="A-grave">
<action name="NextWindow"/>
</keybind>
Change key bindings for A-Tab to follows:
<keybind key="A-Tab">
<action name="Execute"><command>skippy-xd</command></action>
</keybind>
8. Skippy-xd installation:
Install mercurial
# yum install mercurial
Install dependencies:
# yum install libX11-devel libXmu-devel libXfixes-devel libXdamage-devel
Install skippy-xd.
$ hg clone https://code.google.com/p/skippy-xd/
$ cd skippy-xd
$ make
If make command results in error, verify if all dependencies given on the following link are installed : http://code.google.com/p/skippy-xd/wiki/Installation
Copy skippy-xd executable to /usr/bin as root:
# cp skippy-xd /usr/bin
9. Log out and log in again
How to survive the above configuration:
1. Use icons in the panel on the top to launch various applications.
2. Some applications can be launched by pressing Win-r key.
3. Since no window has title bar you can close a window by pressing Alt-F4
You can replace Alt-F4 with some other value like Alt-q or Ctrl-q in the lxde-rc.xml file.
4. Use Alt-Tab or Alt-` to switch between applications (Mac-Expose/Gnome-3 style).
# yum install @lxde-desktop
2. Log on as standard user in LXDE mode
3. Edit the file ~/.config/openbox/lxde-rc.xml and change font size for ActiveWindow and InactiveWindow from 10 to 1. This will finally make title bars completely vanish.
4. To enable clicking by tapping on touchpad, add following line to /etc/xdg/lxsession/LXDE/autostart:
@synclient TapButton1=1
5. (Optional) If you want to adjust font size create file ~/.Xresources and add following line to it (default value 96):
Xft.dpi: 163
6. Right click the "panel" and click on "panel settings" and set them as follows:
Geometry
Edge: Top
Alignment: Left
Width: Dynamic
Height: 18
Icon Size: 16
Panel Applets
Menu
Application Launch Bar
Select "Application Launch Bar" and clik on "Edit".
Then add following items to Application Launch Bar:
Files
Firefox
Terminal
Sound
System Tray
Battery Monitor
7. Skip to step 9 if you don't want Mac-Expose/Gnome-3 style window switching.
Edit the file ~/.config/openbox/lxde-rc.xml again and add following lines:
<keybind key="A-grave">
<action name="NextWindow"/>
</keybind>
Change key bindings for A-Tab to follows:
<keybind key="A-Tab">
<action name="Execute"><command>skippy-xd</command></action>
</keybind>
8. Skippy-xd installation:
Install mercurial
# yum install mercurial
Install dependencies:
# yum install libX11-devel libXmu-devel libXfixes-devel libXdamage-devel
Install skippy-xd.
$ hg clone https://code.google.com/p/skippy-xd/
$ cd skippy-xd
$ make
If make command results in error, verify if all dependencies given on the following link are installed : http://code.google.com/p/skippy-xd/wiki/Installation
Copy skippy-xd executable to /usr/bin as root:
# cp skippy-xd /usr/bin
9. Log out and log in again
How to survive the above configuration:
1. Use icons in the panel on the top to launch various applications.
2. Some applications can be launched by pressing Win-r key.
3. Since no window has title bar you can close a window by pressing Alt-F4
You can replace Alt-F4 with some other value like Alt-q or Ctrl-q in the lxde-rc.xml file.
4. Use Alt-Tab or Alt-` to switch between applications (Mac-Expose/Gnome-3 style).
Wednesday, June 26, 2013
Advanced Yum
Yum History
Sometimes after an update you may want to revert to an older version of a package.
Following command shows you summary of last few yum transactions:
yum history
If you want to see more details, use the command:
yum history info 26
where 26 is to be replaced with the ID of the particular transaction you are interested in.
Search for a particular package
Try
yum search libXss
Happy yumming!
Sometimes after an update you may want to revert to an older version of a package.
Following command shows you summary of last few yum transactions:
yum history
If you want to see more details, use the command:
yum history info 26
where 26 is to be replaced with the ID of the particular transaction you are interested in.
Search for a particular package
Try
yum search libXss
Happy yumming!
Wednesday, June 12, 2013
Making Gome 3 Usable ( 11 Tips and a Confession)
After installing the latest version of Gnome 3 if you were shocked by the lack of usability and wondered how hard or impossible it was to configure small things, say, window font size then I have to confess that this is exactly what I also felt when I installed a fresh copy of Gnome 3 flavored Fedora.
Still, I'm a fan of Gnome 3 and after relevant customization I find it more usable than Windows 7 or OS X 10.8.
Here's a list of important changes I make. You may have to change the values of parameters so that they work well on your hardware.
1. Install custom fonts:
mkdir ~/.local/share/fonts
Dump your favorite fonts in this folder. My favorite are Verdana and Arial.
2. Improve the interface:
gsettings set org.gnome.desktop.interface text-scaling-factor '1.7'
gsettings set org.gnome.desktop.wm.preferences titlebar-font 'Arial Narrow Bold 0'
gsettings set org.gnome.desktop.interface font-name 'Arial Narrow 11'
gsettings set org.gnome.desktop.wm.keybindings close "['<Alt>Q']"
You might have noticed that now I have no way of closing a window with mouse. Only way to do is to press Alt-Q.
3. In mouse and touchpad settings enable "two finger scroll" and "tap to click"
4. Resize Gnome panel
http://useful-linux-tips.blogspot.in/2013/02/resize-gnome-panel.html
5. Remove unwanted entries from Nautilus
http://useful-linux-tips.blogspot.in/2013/02/modify-places-menu-in-nautilus-file.html
6. Remove all favorite apps from gnome panel except firefox, nautilus and one or two other apps that you frequently use.
7. I generally clear my home folder and tell browsers to directly download in my home folder from where I transfer important data (if any) to a different partition which is fully organized.
rmdir Public/ Documents/ Music/ Pictures/ Videos/ Templates/ Desktop/ Downloads/
8. Disable recent documents:
rm .local/share/recently-used.xbel; mkdir .local/share/recently-used.xbel
9. Remove all default bookmarks by erasing all contents of
vi .config/gtk-3.0/bookmarks
Rather, manually bookmark folders that you frequently visit.
10. Disable auto update from all accounts by command
gpk-prefs
11. Make fonts smooth if needed:
http://useful-linux-tips.blogspot.in/2013/01/smooth-font-rendering-on-fedora-18.html
That should make it usable enough.
Tuesday, June 4, 2013
Convert mp3 to wav format using mpg123
Audacity that comes from Fedora's repository, by default, does not support loading and saving mp3 files.
Using mpg123 (you may need to install mpg123), mp3 files can be easily converted to wav files for further editing.
mpg123 -w music.wav music.mp3
I recommend saving your work in lossless compressed format like flac rather than mp3.
Using mpg123 (you may need to install mpg123), mp3 files can be easily converted to wav files for further editing.
mpg123 -w music.wav music.mp3
I recommend saving your work in lossless compressed format like flac rather than mp3.
Saturday, June 1, 2013
Temporarily disable built-in camera
To disable:
# modprobe -r uvcvideo
To enable:
# modprobe uvcvideo
# modprobe -r uvcvideo
To enable:
# modprobe uvcvideo
Fedora Wallpaper
Got the original image from http://blog.desdelinux.net/23-excelentes-wallpapers-de-y-para-fedora/ and a bit tweaking on GIMP resulted in this.
Subscribe to:
Posts (Atom)

