Pages

26 February, 2013

Removing secrets from git's history

If you are ever going to do as stupid thing as I did last time -- commit username and password to public git, here is a short demonstration how to get rid of it:
Remove all the lines that contains "string" [1]:
git filter-branch -f --tree-filter "find . -type f -exec sed -i -e '/$*string/d' {} \;"

Reference

[1] -- tutorial for usage of git filter-branch
[2] -- official article on github

03 February, 2013

My favorite gnome-shell extensions

When I first started using gnome shell I was pretty disappointed. It lacked customization and several design decisions were not my cup of tea. Idea of extensions was pretty straightforward. Extensions are actually pretty common nowadays (browsers, compilers, editors, etc.). Since I installed Fedora 18 (with gnome shell 3.6) I had to find replacements for several extensions. Sadly.
Over time I have discovered several that I cannot live without. Without these:

System Monitor

Display graphs related to usage of system resources like cpu, memory, swap, network, etc. Handy. You know what is your computer up to without touching htop, ps or system monitor application.

Task Bar

Convert left part of top bar to little dock, or better said, to list currently launch applications.

CPU Temperature Indicator

Closely related to System Monitor. This one displays temperature of your CPU.

Message Notifier

This is a must have. Since gnome shell does not display notifications permanently (which is a huge design flaw IMO) you have no way out to find out number of new messages if you access computer after a break.

Advanced Volume Mixer

Control volume level of each application separately. Really nice.

20 January, 2013

Installing nvidia's proprietary drivers on Fedora 18 (with bumblebee)

I've recently updated my Fedora to release 18. (I'm not gonna say how awesome it is -- it is, but I rather stick to the guide)
The first thing after install I wanted to make my Optimus nvidia card useful -- bumblebee & nvidia's proprietary drivers. Internet is full guides for this task, but unfortunately I couldn't find "the one".
At first I wanted to download latest driver from nvidia's site -- huge mistake. I found nice install script on this site. Everything went well except for the fact that after reboot GUI didn't show up. So I tried to uninstall the driver: it segfaulted. Bummer! Thing to learn from this is if installer tries to create file /etc/X11/xorg.conf you have to delete it (rename is fine also). Fedora does not use xorg.conf to set up X, this just mess up everything. You'll most likely get message in /var/log/Xorg.<\d>.log:
[ 26.891] (EE) No devices detected.
[ 26.891] Fatal server error:
[ 26.891] no screens found
My next option was package kmod-nvidia from RPMFusion. This didn't go well also. X launched, but optirun didn't work (it expected nouveau). Thing to note here is that you should use package for your version of kernel. Otherwise X will complain about fact that it can't find nvidia kernel module.
So what did I do to make it work?
First thing to do is blacklist nouveau and create new initramfs (save old one if something goes wrong):
echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf
cd /boot
mv initramfs-$(uname -r).img initramfs-$(uname -r)-nouveau.img
dracut /boot/initramfs-$(uname -r).img $(uname -r) --omit-drivers nouveau
Use this awesome repository, which contains bumblebee related packages:
yum install -y http://install.linux.ncsu.edu/pub/yum/itecs/public/bumblebee-nonfree/fedora18/noarch/bumblebee-nonfree-release-1.0-1.noarch.rpm --nogpgcheck
yum install -y VirtualGL bbswitch bumblebee --nogpgcheck
Now is time to install package which contains nvidia's proprietary driver:
yum install -y --nogpgcheck bumblebee-nvidia
Reboot and everything should be fine.

Troubleshooting

If you are stuck in command line after reboot you may try to launch X (and see result & logs):
service gdm start
X-server complains about "no screen found"? Check this command:
xrandr -q

Reference

I didn't make this up just like that. I used these links:
[1] -- awesome tutorial that explains how to install bumblebee on Fedora and how to use it
[2] -- official Fedora guide
[2] -- install bumblebee from sources and configure it
[2] -- information about bumblebee-nvidia package

05 November, 2012

Setting up SSL on Apache web server

I was setting up secure connection on django application running on Apache on my devel instance. I wanted to have access via both ways: secure and insecure. I struggled a bit, but after some time I found & figured out the most suitable configuration.

I created one file with general configuration: routing, directories, wsgi alias etc. The other contained VirtualHosts with first file linked. VirtualHost for secure connection contained also SSL configuration (naturally). Using this way I didn't violated DRY principle.

Sample TBA

23 August, 2012

Installing VirtualBox on Fedora 17

Great part of this guide is just copy of this awesome guide. I am just leaving here a script:
## Fedora 17/16/15/14/13/12 users
wget http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo
mv ./virtualbox.repo /etc/yum.repos.d/
yum update

echo "consider reboot if kernel has been updated"

yum install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms

#we don't want to install vbox from rpm-fusion
yum --disablerepo "*" --enablerepo "virtualbox" install VirtualBox

#change user most likely usermod -a -G vboxusers $USER

yum install kernel-headers-$(uname -r)
Script that checks if your installed kernel-headers match your kernel
module="kernel-headers"
if [ $(rpm -q kernel-headers) == $module-$(uname -r) ];
then
    echo 'headers are equal';
else
    echo "headers are not equal:";
    echo "> rpm -q: $(rpm -q kernel-headers)"
    echo "> uname -r: $module-$(uname -r)"
fi

06 April, 2012

Red Hat Open House 2012

I was looking forward to date April 5th for quite some time. Red Hat scheduled its Open House for this date.
Event itself was pretty similar, by means of organisation, to previous years. There were lots of presentations related to Open Source, linux and Red Hat of course. Unfortunately I attended only two of them -- Deltacloud and Gnome Shell. The first one was really interesting: talking about cloud technology, cloud API and the product itself, which is API between cloud provider and customer's application.
I was pretty disappointed about Gnome Shell presentation. I expected some advanced information about this "controversial" UI, but presentation itself was based on some well known facts. On the other hand I can imagine that if other viewers wasn't familiar with this shell, they could enjoy the presentation. Presenter showed some really good extensions at least, which I installed immediately after I arrived home, so I have to thank him that my Fedora is more usable now.
I attended Bug Hunt contest for the first time. I have been avoiding it for all these years (because I wasn't good at any scripting language or C/++ at that times) and this time, I just couldn't resist, since I started learning Python. Contest was organised very well. It really impressed me -- but should I wonder? It is Red Hat. The thing which impressed me even more, was that I ended on second place. I earned it just by correcting some python sources and finding some bugs in provided, "bugfull" program.
That's it. This was Red Hat Open House 2012 from my point of view.
Wait.
But there's more!
View from the top of the building was perfect. Chilly breeze was just the thing what I needed. Also buffet was full of tasty yummies, just like every year. I attended server room, which fascinates me more and more every year. Guys answered all of our questions. That gave me really good feeling, how nice and chatty these guys were.
I would like to thank Red Hat for this spectacular event -- awesome as always.

31 March, 2012

Post Correspondence Problem

I found out that one of topics on my final exam will be Post Correspondence Problem. Definition of this problem is pretty straightforward. I am not going to write down formal definition, since it is available on Internet.
You have given two lists A = (a1, a2, a3,...) and B = (b1, b2, b3,...) with same number of items. Each list contains strings. The task is to determine if exists sequence of indexes -- integers i1, i2, i3,... such that ai1, ai2, ai3,... = bi1, bi2, bi3,....

Example

A = (abb, a, bab)
B = (bba, aab, b)
So our task is to make one word with one list of indexes using A and B.
In the first step we have to pick wisely, because we might end pretty early. Using index 1 would be a bad choice because abb and bba can't be prefix of the same word. Indexes 2 and 3 are far better choices. Let's say I pick 2. So our word looks like this right now:
A: a
B: aab
It's easy to see, that we have to find string with prefix ab in list A. We are lucky! Index number 1 fulfills our condition:
A: aabb
B: aabbba
Similar situation, but prefix to be found is ba in A. Index 3 fits:
A: aabbbab
B: aabbbab
Both strings match, we have found a solution: (2, 1, 3).

Programming

I couldn't understand, how come that this problem is undecidable (I haven't read proof proving undecidability). So I tried to program it using python. Basicly the problem could be seen as a graph problem (from the brute force perspective) -- searching for correct path in a tree. Actual code might be buggy since I didn't test it much:
def returnSuffix(a, b):
 result = ''
 aLen = len(a)
 bLen = len(b)
 if aLen > bLen:
  if a[:len(b)] == b:
   return a[len(b):]
  else:
   return None
 else:
  if b[:len(a)] == a:
   return b[len(a):]
  else:
   return None

def getStr(a):
 return ''.join([''.join(v[1]) for v in a]) 

a = ['bba', 'abb', 'bb', 'a']
b = ['bb', 'b', 'abba', 'ba']

depth = 0 
aString = []
bString = []
indexes = []
choices = []
firstRun = True
found = False

while firstRun or len(choices) > 0 or len(aString): 
 firstRun = False 
 deadEnd = True 
 #pdb.set_trace()
 for idx, val in enumerate(a):
  if returnSuffix(getStr(aString) + val, getStr(bString) + b[idx]) != None:
   print 'adding %d to choices' % idx
   choices.append([depth, idx])
   deadEnd = False
 print 'choices: %s' % choices
 if not deadEnd:
  lastItem = choices.pop() 
  indexes.append(lastItem[1])
  aString.append([lastItem[0], a[lastItem[1]]])
  bString.append([lastItem[0], b[lastItem[1]]])
  if (getStr(aString) == getStr(bString)):
   print 'Solution found! %s' % indexes
   found = True   
   break
  depth = lastItem[0] + 1
  print getStr(aString)
  print getStr(bString)
 elif len(choices) == 0:
  break;   
 elif deadEnd:
  if (aString[-1][0] == 0):
   aString.pop()
   bString.pop()
   indexes.pop()
  else:   
   while choices[-1][0] <= aString[-1][0]:
    aString.pop()
    bString.pop()
    indexes.pop()
    depth = depth - 1
  if len(choices) > 0:
   lastItem = choices.pop()   
   indexes.append(lastItem[1])
   aString.append([lastItem[0], a[lastItem[1]]])
   bString.append([lastItem[0], b[lastItem[1]]])
   depth = lastItem[0] + 1
 if depth > 10:
  print 'depth is bigger than 10'
  break;
if not found:
 print 'Solution not found'
So what does this code do? Variables aString and bString represents actual path in a tree, while variable choices contains pointers to alternative branches. Variable depth represents the level in a tree. Function getStr just returns the actual state of building the string. Function returnSuffix returns suffix of word built from a which differs from b and vice versa. If the two words are invalid, it returns None.
And now the actual algorithm. For current vertex program computes all the branches and add them to choices. If the branch is dead end, it will return back to the last crossroad and tries alternative branch. If it's not, it pops last item from choices and continues. So basically it's Depth-first search. The only problem is that we are not searching one tree, but more of them. These are specified as depth=0 items in choices. So if you walk whole tree there has to be different routine to jump to another three -- if (aString[-1][0] == 0):.
So why is the problem undecidable? Because the tree may contain infinite paths and there is no way out how to decide whether the path is infinite or just "too long" -- depth variable. That's the exact definition of undecidability:
A problem is undecidable if it cannot be solved by any Turing machine that halts on all inputs.