Least Action

Nontrivializing triviality..and vice versa.

Article: How to Learn Emacs: A Hand-drawn One-pager for Beginners » sacha chua :: living an awesome life

How to Learn Emacs: A Hand-drawn One-pager for Beginners » sacha chua :: living an awesome life

http://sachachua.com/blog/2013/05/how-to-learn-emacs-a-hand-drawn-one-pager-for-beginners/

Written by Vivek

May 19, 2013 at 10:56 AM

Posted in Linux, Programming

An evolving .vimrc – VIM with Python

I’ve switched almost completely to Python for my Master’s thesis. The question that comes up when you use Python is…what IDE to use? There seem to be a whole bunch of them but none of them worked for me, for one reason or another. So for now, I am using vim, and will explore different ways of customizing it for use with Python. For now here is a minimalist ~/.vimrc.

filetype off

set nu
filetype plugin indent on
syntax on
set modeline
set background=dark
autocmd FileType python set complete+=k~/.vim/syntax/python.vim isk+=.,(

map <buffer> <S-e> :w<CR>: !/usr/bin/env python % <CR>

I’ll explain and elaborate in due course of time.

For now, you might want to ignore the line containing autocmd (just put a # before it). Also, for starters ~/ refers to your home directory. And files beginning with a dot (.) are hidden by default so an “ls -l” won’t show them, but an “ls -aCF” will. So just use your favorite editor and copy paste the above text into a file called “.vimrc” which is placed in your home directory (~/.)

Written by Vivek

April 29, 2013 at 3:18 PM

Posted in Uncategorized

Tagged with , , , ,

Gnuplot with C/C++

Sometimes, it is convenient to call gnuplot from within your own C/C++ code rather than having the code create a data file, and manually execute gnuplot every time to re-plot using the contents of the file. This is easy if you use Linux: just use a pipe. For instance:

 #include <iostream> #include <stdio.h> #include <cstdlib>

 using namespace std; int main(){ // Code for gnuplot pipe FILE *pipe = popen("gnuplot -persist", "w"); fprintf(pipe, "\n"); // Your code goes here 

 // Don't forget to close the pipe fclose(pipe); return 0; }

Note that we have had to use C routines to call gnuplot. But there’s a problem with this code: gnuplot will generate the plot only when the pipe is closed. So if you have multiple plot statements, or if you want to refresh the same plot (as for instance, in an animation scenario) you will find that the above approach will result in the plots getting asynchronously updated right at the end.

So how does one ensure that after every plot command, a plot is actually generated (or an existing one refreshed) Immediately? The key is to flush the buffer using fflush. Simply insert

 fflush(pipe); 

below every plot call to gnuplot. If you have an animation, then in order to make the transitions smoother, you might want to include a delay subroutine. A simple one can be built using the clock routines in time.h. For an example, click here.

Thanks to Vidushi Sharma for bringing these issues to my attention.

Written by Vivek

June 22, 2012 at 2:13 PM

Why V(x) = -1/x^2 has no bound state

Here we present a scaling-based argument to show that the attractive potential

$V(x) = -\frac{\lambda}{x^2}$

($\lambda > 0$), has no bound states (i.e. states with energy E < 0). Consider the Time Independent Schrodinger equation for this potential, which is the eigenvalue equation for the corresponding Hamiltonian,

$-\frac{\hbar^2}{2m}\frac{d^2\psi}{dx^2} - \frac{\lambda}{x^2}V(x)\psi = E\psi$

This can be rearranged as

$\frac{d^2\psi}{dx^2} + \frac{2m\lambda}{\hbar^2}\frac{1}{x^2}\psi = -\frac{2mE}{\hbar^2}\psi$

Now, it is easy to see that the quantity

$\frac{2m\lambda}{\hbar^2}$

is dimensionless. So, this problem has no independent scale, even though naively one might think that $\lambda$ specifies a scale for this problem. We claim that for such a system, there can be no bound state. This is proved below.

Suppose we perform the scale transformation $x \rightarrow \alpha x$ where $\alpha$ is some nonzero real number, we see from the equation above that if $E$ is an eigenvalue, then so is $\alpha^2 E$.

Suppose now that a bound ground state exists, with energy $E_{G}$. By definition $E_{G} < 0$. Then scale invariance implies that $\alpha^2 E_{G}$ must also be the energy of some bound state. But

$\alpha^2 E_{G} < E_{G}$

as multiplying the negative ground state energy by a positive number only makes it more negative. This contradicts the fact that the ground state has energy $E_{G}$. In fact, we can make a stronger statement, viz. the ground state energy can be made as small as we want. Therefore, there is no finite energy ground state for this system, and consequently there can be no bound states.

Note that there is no such problem with scattering states, i.e. states with positive energy. One can take an arbitrarily small positive energy scattering state and from it obtain valid energies of the continuum of higher energy scattering states by performing a scale transformation.

Incidentally, this is why potentials like $-\lambda[\delta(x)]^2$ and $-\lambda\delta(x)/x$ also have no bound states.

Written by Vivek

February 8, 2012 at 8:48 AM

Customizing GNOME3

The purpose of this post is to help you configure GNOME3 and make it look more ‘zazzy’ than it is. Most of these tweaks have been inspired by the archlinux forums and FP Murphy’s blog, which is the source for learning how to customize GNOME3. I thought it would be a good idea to put it all in one place, mostly for my own reference. Note that I have tested all this on Natty 64-bit. I also thank Charles Bowman for his help and inputs over the past few weeks.

The gnome-tweak-tool does not let you change much, unless you add extensions to the gnome-shell, which really open up the world for a tweaker. I won’t go into the anatomy of an extension, as FP Murphy does an excellent job in explaining it. I will just assume that you know enough about it. If you don’t, you will still be able to get all these tweaks to work, but you won’t understand how they work, and believe me, it won’t be quite as much fun!

Extensions are installed in

~/.local/share/gnome-shell/extensions

but if they are to be made accessible to all users, then they should go in

/usr/share/gnome-shell/extensions

You can pick either configuration. I will work with ~/.local/share/gnome-shell/extensions from now on, because I am running all this on a single user system. Remember that ~/ is a mnemonic for your home directory. Instead of using the long /home/user_id/, I will just refer to it as ~/ from now on.

One way to play with extensions is to get hold of Charles Bowman’s gnatty pack. It is available from http://cid-32ec6e89f4aa803b.office.live.com/self.aspx/Linux/gNatty%20Pack.tar.gz?wa=wsignin1.0&sa=92561471. Since several extensions seem to be around, with different names, I will just go over the ones I have gotten to work one by one.

Some words of caution before we begin the expedition: some extensions are not compatible with others, and if you install two mutually incompatible extensions, it is possible that the Gnome Shell will not load, and you will be asked to log out. This can be fixed by moving the bad extension out of ~/.local/share/gnome-shell/extensions or simply renaming it:

mv ~/.local/share/gnome-shell/extensions/bad_extension ~/.local/share/gnome-shell/extensions/bad_extension.old

It turns out that this works because each extension has a file inside called ‘metadata.json’ with a field called a unique id (uuid) which must match the name of the directory. Changing the directory name using the mv command above will create a disparity between uuid and the directory name, which will prevent the extension from loading.

If you install a whole bunch of extensions together, it will obviously be hard to debug any problem, because you don’t know which extension is the culprit. So it is best to install one extension at a time, and restart the GNOME Shell. This can be achieved either by logging out and logging back in, or pressing Alt + F2 and typing r and pressing Enter. This restarts the shell. Sometimes though, restarting the shell this way results in spurious errors which may suggest that the extension is messing up something. So, I do prefer to double-check by logging out and logging back in again, though this is relatively cumbersome as it will close all open applications.

With this preliminary knowledge, we are ready to embark on the first step. The basic algorithm is to create two files, extension.js and metadata.json, for every extension. Each extension resides in its unique directory (folder) in ~/.local/share/gnome-shell/extensions/.

Extension #1: Move Clock

The default position of the clock in Gnome is in the center of the top bar. This is irritating for those of us who are used to the old Gnome2 interface where the clock would appear on the right. This is easily fixed.

cd ~/.local/share/gnome-shell/extensions
mkdir Move_Clock@rmy.pobox.com
cd Move_Clock@rmy.pobox.com


Now create two files using your favorite editor, extension.js and metadata.json with the following contents:

extension.js

const St = imports.gi.St;

const Main = imports.ui.main;

function main() {
let children = Main.panel._rightBox.get_children();

Main._nWorkspacesChanged = function() {};
Main._queueCheckWorkspaces = function() {};
Main._checkWorkspaces = function() {};
}



{
"shell-version": ["3.0"],
"uuid": "Move_Clock@rmy.pobox.com",
"name": "Move Clock",
"description": "Move clock to left of status menu button"
}


Restart the shell. The clock should now be visible on the right hand side of the top bar. We can customize it further, to display the time and date in a detailed fashion.

First start gnome-tweak-tool, and click on Shell. You should see a window which looks like this:

gnome-tweak-tool shell tab

You can toggle the ON/OFF switches for ‘Show date in clock’ and ‘Show week date in the calendar’.

Some more date and time settings can be changed using gnome-control-center. Type

gnome-control-center

in a terminal window and click on Date and Time. Note that this tool does not allow you to show a seconds counter in the clock. If you wish to display seconds, fire up a gnome-terminal window and type

gsettings set org.gnome.shell.clock show-seconds true

This will display a live ticking seconds counter.

Note that the status of presently installed gnome-shell-extensions can be determined from and changed within gnome-tweak-tool. Every time you install an extension manually and restart the shell, by default it is enabled.

Under Construction

Written by Vivek

June 1, 2011 at 3:09 PM

Posted in Linux, Programming

Ubuntu 11.04 Natty Narwhal 64-bit Guide Part 2 – Installing GNOME3

In this post, we are going to install GNOME3.

Step 1: Make sure you got Unity to work. This is very important. We don’t want to install Gnome3 on an ailing system.

Step 2: Update everything, if not already one in Part 1.

sudo apt-get update
sudo reboot


Step 3: Install GNOME3

sudo add-apt-repository ppa:gnome3-team/gnome3
sudo apt-get update
sudo apt-get install gnome-shell gnome-session
sudo apt-get -f install
sudo apt-get install gnome-shell
sudo apt-get install gnome-session
sudo apt-get remove gnome-accessibility-themes
sudo apt-get install gnome-themes-standard
sudo apt-get install -f

Step 4: Now, reboot your system.

sudo reboot

And then, log into the session named ‘GNOME’. If everything worked out alright, you should be in GNOME3.

The gnome-tweak-tool lets you make minor modifications to the way the Gnome Shell looks/interacts. In a subsequent post, we will look at various customizations that are possible.

References:

1. http://ubuntuforums.org/showpost.php?p=10734567&postcount=1. Read this for a detailed description of all the steps.

Written by Vivek

June 1, 2011 at 2:29 PM

Posted in Linux, Technology

Ubuntu 11.04 Natty Narwhal 64-bit Guide Part 1

This is meant to be a record of all that I did to customize Ubuntu 11.04 Natty Narwhal 64-bit on my self-assembled desktop (Core i7 920, 6 GB Corsair TR3X6G1600, Gigabyte EX58 Extreme, NVIDIA GTX295) and my laptop (Dell XPS 15 L501x: Core i7 740 QM, 6GB DDR3 RAM, NVIDIA GT435M, 1920×1080 dp HD screen). It is mostly unoriginal, and credits have been given where they are due to various sources on the internet.

First of all, I strongly recommend a fresh install. There are lots and lots of threads out there with people posting problems after problems with upgrades from Maverick Meerkat 10.10. Typically most of you will need to back up your home directory $HOME (or ~/). You can just create a tarball and save it to a USB drive or a CD. If you’re an expert/intermediate user who knows what the stuff in all those ‘hidden’ directories beginning with a . is, then you probably won’t need to do that either. After a fresh install, the first thing to do is to get the latest updates sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade sudo reboot  The first updates will take a long time. You can also use the update-manager. In this post, I will always provide command line interface (CLI) solutions, as I don’t care much for GUIs. But they have their advantages, and if you are more comfortable with GUIs use them instead. There will be some instances where you’ll need to be familiar with the CLI (e.g. if you’re installing accelerated NVIDIA drivers, or if X windows fails to load). Installing proprietary accelerated NVIDIA Drivers When you first boot into Natty, you will most likely get a message indicating that your hardware is not capable of running Unity, and that you will be taken to the classic GNOME interface. This is because by default, restricted drivers are not installed. To install restricted drivers, click on the System menu, and select ‘Additional Drivers’ under Administration (System -> Administration -> Additional Drivers). Your window will look a little like this: Additional Drivers - NVIDIA You will most likely see two entries – we’re interested in the first one. I have taken a screenshot after installing these drivers, and then switching to drivers downloaded directly from NVIDIA. Most people will not require this, unless they intend to program in CUDA. Anyway, activate the first entry on the list. This will download and install the restricted driver. Now, reboot your system. You should be able to boot into Unity. This will be our starting point. Installing Sun Java By default, Natty comes with Open JDK. I prefer Sun’s JDK/JRE. To install it, type sudo add-apt-repository ppa:ferramroberto/java sudo apt-get update sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts To use Sun’s Java, you’ll probably have to change the default java version using sudo update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode 1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode * 2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode Press enter to keep the current choice[*], or type selection number:  Pick option 2 (or the one which does not correspond to OpenJDK). To confirm that the change occurred, type java -version You should see something like  java -version java version "1.6.0_25" Java(TM) SE Runtime Environment (build 1.6.0_25-b06) Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)</pre>  Install JDownloader (optional) JDownloader is a Java-based download manager, which in my experience, is more reliable than many other download managers I’ve used. To download and install JDownloader, type sudo add-apt-repository ppa:jd-team/jdownloader sudo apt-get update sudo apt-get install jdownloader Installing proprietary NVIDIA drivers from http://www.nvidia.com Power users, especially programmers, will find it necessary to have support for additional libraries such as CUDA. The drivers we just installed above do not provide CUDA support (at the time of writing). But NVIDIA provides Linux drivers, and they can be downloaded from http://www.nvidia.com/Download/index.aspx?lang=en-us. To install this driver, log out of Gnome/Unity, and at the graphical log-in screen press Ctrl+Alt+F1 to switch to console mode. Then, type sudo service gdm stop Then, navigate to the directory containing the nvidia driver .sh file, and type sudo sh ./filename.sh Follow the on-screen instructions. Reboot the system. You should see an NVIDIA splash screen before the log-in screen. Note that you may have to do this a couple of times for it to work. Installing CUDA Download the CUDA toolkit and SDK from http://developer.nvidia.com/cuda-downloads or http://developer.nvidia.com/cuda-toolkit-40#Linux. Add the following lines to$HOME/.bashrc

export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH


You will most likely face a bunch of errors, which can be resolved by reading an earlier post of mine: http://leastaction.wordpress.com/2011/01/25/cuda-on-ubuntu-maverick-meerkat-10-10/.

You will also have to update symbolic links:

sudo ln -s /usr/lib/libGL.so.xx.xx.xx /usr/lib/libGL.so


Note: Recent updates to xserver-org-core and xserver-common are likely to crash your Gnome3 and/or OpenGL configuration. To fix this problem, you have to also restore another symbolic link:

sudo mv /usr/lib/xorg/modules/extensions/libglx.so /usr/lib/xorg/modules/extensions/libglx.so.orig
sudo ln -s /usr/lib/xorg/modules/extensions/libglx.so.270.41.06 /usr/lib/xorg/modules/extensions/libglx.so


The version 270.41.06 may have to be replaced by the version of the driver you are presently using. This can be determined by typing

nvidia-settings -v

References:

Written by Vivek

June 1, 2011 at 2:15 PM

Posted in Linux, Technology