Wednesday, March 21, 2012

Cycling with Jinga

I was tweaking the layout.html file for Python's Sphinx and found the following random tit-bit of use when using Jinga:


{%- for rellink in rellinks[1:]|reverse %}
  <div class="{{ loop.cycle('buttonPrevious', 'buttonNext') }}">
   <a href="{{ pathto(rellink[0]) }}">
    {{loop.cycle('Previous', 'Next')}}
  </a>
{%- endfor %}




With loop.cycle you can cycle through strings or divs
as the loop iterates..

In the above example, a div is created first for buttonPrevious and then
the next iteration for buttonNext. The same applies to the strings that determine what gets
printed on the button.

Tuesday, March 20, 2012

Stashing in Git

If you're working on a branch and which to switch to another for some reason without committing,
or you wish to try out something on the current branch, you can save your current state to the
stash .
Use
git stash save


When you're ready to continue what you were working on, go back to the branch that you used
stash on and use:
git stash apply

If you don't want to use your stash anymore, and just work from your last commit, use
git stash clear

For a more thorough run-through on git-stashing , check out
http://ariejan.net/2008/04/23/git-using-the-stash

Monday, March 5, 2012

doctest_mode in iPython

If you want to import code into iPython that has been copied from the python console
or code that is to be run as a doctest in Python Sphinx, a useful trick to use in iPython
is

%doctest_mode

For example:

>>> import numpy as np
>>> some_value = 35
>>> np.sqrt(some_value)


You can copy this directly into iPython and it will treat it like normal python code.
No need having to copy every line of code after >>>

Thursday, February 23, 2012

Fix slow connection (ubuntu 11.10 - Oneiric Ocelot)

If your wireless internet is damn slow after installing ubuntu 11.10,
here's one way to try and fix it:

This method involves forcing iwlagn to not use n, the commands will disable n on the device without making it a permanant change, check first if this work for you, if you notice that the speed improved then continue to make the change permanant. If this solution didn`t work for you, then reboot your computer to revert the chnages.


sudo rmmod -f iwlagn
sudo modprobe iwlagn 11n_disable=1


If you notice that the wifi speed improved, then make the change permanent :

gksudo gedit /etc/modprobe.d/iwlagn-disable11n.conf

and add this line to the file:

options iwlagn 11n_disable=1

save & quit
Important: The above method has been quoted from www.unixmen.com, a site that I've found very useful in the past. The method was the one that worked for me and hence why I want it here. To see the full original post that containts two other methods, please go to the Unixmen post that I am quoting from

Removing tick-labels from an axis in Matplotlib

If you want a make a 3D plot for which you don't want any text on the axis-ticks,
the following should do that (pl = pylab):


fig = pl.figure(1, figsize=(4, 3))
pl.clf()
ax = Axes3D(fig, elev=43.5, azim=-110)
....
....
ax.set_xlabel('X_1')
ax.set_ylabel('X_2')
ax.set_zlabel('Y')
ax.w_xaxis.set_ticklabels([])
ax.w_yaxis.set_ticklabels([])
ax.w_zaxis.set_ticklabels([])

An example plot:



for python with pylab, matplotlib & Axes3D