Entries Tagged 'linux' ↓

howto: version control of your home directory

Well this is something I have been wanting to do for a LONG time. But so far I didn’t found a good alternative.

I’m a long time svn user but doing this with svn presented the following issues.

  • having one .svn in each folder is not an option it’s just too much hidden things everywhere plus it will cause some weird clashes
  • .svn is a pain, specially when you are grepping the source and you get double results (although I fixed this with a bash alias)
  • svn urls are confusing and long
  • ignoring files is directory based so svn status will show a ton of things

Today for some reason I started reading the mercurial documentation and it just hit me, this is what I needed. Why? well…

  • one folder with all the versioning info
  • sane ignores which are file based not path based
  • super easy backup. as the distributed version system will let me clone the repository or even better use a Bundle
  • in-place import this is a great feature svn is lacking*
  • non-intrusive

So lets get dirty first create the repository. And lets add a basic .hgignore, I got the .hgignore file tip from here which means I’m not the first one to come up with this idea. And lets commit that.


$ cd
$ hg init
$ printf "syntax: glob\n*\n" > .hgignore
$ hg commit

Now we need to figure out which files we want to get into the repository so lets figure that out.


$ ls -a1 >> .hgignore

note, that’s a “one” it will output the file in columns, if you didn’t knew that go read the man page, you will love all the switches.

Now we need to edit the .hgignore file a bit delete the following lines

*
syntax: regexp

./
../
also delete (or comment with a #) all the lines of the files you want to version (remember this is an ignore file)

then just start adding files and when you are done commit. And now you have full history of all your changes, Which is awesome for managing your config files, remembering all the tricks in your .vim or .bashrc and exporting them to other machines.

EDIT:

* in-place import means that the original code you import into the versioning system becomes a working copy.

In SVN when you do an import the original tree does not become a working copy of the code, so you have to do an import then a checkout into the same dir from which you imported. It’s very tricky and most people don’t know about it. Although There is a way to trick svn into doing it but most people don’t know about it.

Diff tools, WinMerge & Meld

WinMerge is wonderful for those souls that are still trap developing in windows.

Their “main” site is currently down but you can check it out later at winmerge.org.

Meld is another great app which I found ones I moved 100% to linux.

I really like them both but there is one feature that WinMerge has that I haven’t been able to reproduce in Meld. WinMerge has keyboard shortcuts for everything, so you do something like alt-down, alt left (can’t recall the exact commands) and that will go to the next diff and replace the right file with the left file. In Meld you have (or at least as far as I know) to do the same but with the mouse which makes it slower.

A smaller thing is that WinMerge is faster and I believe it’s both because it’s more mature and because it’s C++ while meld is python+GTK .

And of course Meld gets extra points for the cool effect to reflect changes.

MPX multitouch driver for X server

This is something very cool, someone named Peter has been working on a driver for X to support multi touch, some of you may be saying 2006 call it want’s it’s really cool multitouch screen back, but let me tell you why this is different.

We don’t need gesture support in X. Gestures depend a lot on the context. A gesture in one context can mean something different in a different context. And the only thing that knows the context is the application. This is very similar to a button press. Pressing a mouse button can mean a zillion different things, depending where and when it happens. That’s why all X does is relay the button press to a client application, which then does the right thing.

Which in short means the X server will just send an event to the client, remember that in X terms the client is the Desktop Environment (gnome,kde,enlightenment) or the window manager (fluxbox,w3m, etc.).

To your multi-touch driver all this doesn’t matter. It sends blob events, the server takes care of the rest. You’re guaranteed to be able to interact with any X application. X doesn’t care about the hardware. You can use your DiamondTouch, your FTIR table or - if you can afford one - your MS Surface table.

which means that ANY application can work with multi-touch, in fact ones GTK gets support for BlobEvents all your program has to do is support one more event and process it.

Even better you can use the mouse and keyboard and multitouch all together as MPX is just another driver!

Full article here which is the cool part which is the reason why I’m not liking the video from here, so go read the artcle and watch it in action.

This is like xgl for multi touch displays!!

never run @rm -rf $(PREFIX)/bin/deluge

There are time when being ovidient bytes you in the ass.

For example the shell and rm, yes you know where I’m going. It turns out that the following command inside a makefile @rm -rf $(PREFIX)/bin/deluge does something really extrange. And yes it’s all my fault because I force it twice.

For some reason the r flag went to $(PREFIX)/bin and deleted everything, which I’m stil confused as to why.

ohh yes and $(PREFIX) was set to /usr, lovely isn’t it?

any ideas of how can I restore those files? I assume if I get the basic binaries for installing .deb it will show me the broken packages (read: all packages) then I could reinstall them all?

update:  So I got a liveCD and reinstalled my / keeping intact the home, this is one of the things I love about unix, even my windows positions where intact all I had to do was use the same username.

with: the lazy programmer CLI tool.

The other day Ricardo came up with an idea which I found great, so we went and implement it. Since then it has grown a nice set of features and I think it’s ready to test the world (well it was a week ago but I haven’t had the time to make the post).

In general the idea is to reduce the ammount of typing you do in the CLI.

I wrote a nice “extensive” readme file, which also showed me the very cool mime type “text/x-trac-wiki” so the link before is directly into SVN with trac wiki syntax formatting, sweet!

Since it’s a one file program there is no need for a installer, so just download it from here. If you are lazy enough the Makefile has a install target, and in case you where wondering the build.xml is just a sample. Although I could make it install the python code just for fun (evil laugh).

Last but not least I finally got my trac up (I’ll add another post for that) but if you find a bug please submit the patch here

Enjoy!

Why upgrade when it’s not needed?

Because we like it.

Programmers love to be “in the edge”. I love to do that; on my gentoo system I’m constantly doing emerge -u world, and in ubuntu I’m always clicking the little orange icon. Now i’m fine with it if it affects me… but we live in a bigger world.

I remember one of the mottos of servers administration is “DO NOT UPGRADE”. Why? Simple. you don’t need it because what’s there now it’s working; and this is why you see production systems running OS versions from 2-3 or more years ago, and eventually they do upgrade but sysadmins know it’s a problem and try to avoid it.

Now if your working with other people you need to think before upgrading and more important ASK before doing it so you don’t break everyone’s code.

The reason I’m blogging  about this is that it has happen twice in the past month, ironically with the same platform. Without going into the details of why I disagree with your upgrade it’s a matter of form rather then the fact itself. In both cases I have had the same two answers:

  1. because it’s better
  2. because I had that installed (one admit it the other left it implicit)

When confronted for a explanation of #1 both gave a fussy reason, mostly linked to all the hype around how great it’s performance is, now in both cases this was premature optimization because the system hasn’t been run ones. No really neither system is in production and it needs at least 2 months of work before it can even hope to.

So what piss me off was #2 your imposing on me your “in the edge” without looking at the consequences in the last case. I’m100% sure the overall project lost at least 10 hours of productivity because of this, this is because they are all newbie, so think about the first time you ran some code compiled for JVM 1,x,y and ran it on JVM 1,x,w and you will see how it adds up correctly. Add to that having to re-target all your tools to run on top of the new JVM, or you forgot about your tomcat instance? yes you did since your email says classpath.

Now I’m fine from you running the kernel off Andrew Morton tree, compiling everything by hard (using -o9 if you still think that’s good), that’s fine I do it on some of MY stuff. but I do not expect everyone to keep up, and you shouldn’t too.

SVN goodies, and a call for a nice repo browser

So I was looking around in the collab.net site and found some things that SVN users may find usefull.

in no particular order

  • bash completion
  • Delete all files that are not versioned, although I recentryl found out that “svn revert” will doI think does the same
  • grep without the cruft I find this one very nice, it is a grep that will filter all .svn files so your can actually find stuff on svn checkouts
  • and of course emacs integration that seems like a svn-mode whatever that is supposed to do.
  • and since for each use of emacs in a sentence I must say vi here is a vi’s syntax file there 2 to 1.

now about the repobrowser…

First don’t take me wrong I love svn CLI interface but sometimes you just want to browse the code see the changesets or just read the commit comments, in those cases I totally miss tortoiseSVN it’s windows explorer interface seem to me the best feature of the windows explorer.

So on linux I have found a couple of tools but none have given me the love of tortoise, currently I’m living with rapidSVN, while writting this post I found about some set of svn scripts for the gnome thru something call G-Script.

show_stock buttons in pygtk

So I’m learning pygtk to write a small program inspired by my last post.

and I wrote this to see if I really undestand how the tookit worked.

I’m reading http://www.pygtk.org/pygtk2tutorial/index.html which seems to be the official tutorial and it’s written very well and/or gtk is a very handy tool.

I personally like a lot the way they do the table layout it’s much more simplier then it’s java cousing. Since you can actually make a mind map on how big each component is based on it’s numbers instead of having to add them up and see if they collide.

The funniest part of all is that I wrote this in about 30min this morning before going to work and I have spend 15 more minutes making it “presentable”, after that I spend almost 2-3 hours figuring out how to post the damn thing to wordpress, but that is the topic of my next post. for now enjoy the code.

Bonus points if you tell me why lines 48-49 screw up the layout.

[python]

#!/usr/bin/env python

import pygtk
pygtk.require(’2.0′)
import gtk

#this will generate the list of all the stock options
stock_options = [option for option in dir(gtk) if option.startswith(”STOCK”)]

class Stock_Buttons:

def createButton(self,stock_option):

#ugly but this is a test.
button = gtk.Button(stock=eval(”gtk.”+stock_option))
button.connect(”clicked”, self.clicked,stock_option)
button.show()
return button

def clicked(self,widget,data=None):

print “gtk.Button(stock=gtk.%s))” % data

def __init__(self):

#setting some defaults.
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title(”Sample stock buttons”)
self.window.set_border_width(10)#this will handle both gui events (click the X) and system events like
#the kill command.
self.window.connect(”destroy”, lambda wid: gtk.main_quit())
self.window.connect(”delete_event”,lambda a1,a2:gtk.main_quit())

#small trick to get the the size if the grid
#93 boxes fit into a 10×10 grid
#45 boxes fit into a 5×5 grid and so on.
import math
length = math.ceil(math.sqrt(len(stock_options)))

#pasing floats to gtk is deprecated so to avoid that we make sure it’s an int
length = int(length)
print len(stock_options)
#we set false so gtk will strink the buttons.
table = gtk.Table(length,length,False)
#set one widget on each 1×1 slot until we run out of widgets
for index,option in enumerate(stock_options):
i=index / length
j=index % length
#~ why this shows a weird layout?
#~ i=index % length
#~ j=index / length
table.attach(self.createButton(option),i,i+1,j,j+1)

self.window.add(table)
table.show()
self.window.show()

def main():

gtk.main()
return 0

if __name__ == “__main__”:

Stock_Buttons()
main()

[/python]

I’ll post a screenshot but the upload thing doesn’t wants to work unless I give 777 to the dir so no way, same goes with the raw code, ones I’ll figure out how to do it I’ll update this.

Linux wallpaper changer

First of all let me say I’m not a fan of wallpapers I’m more a “black background guy”.

But I have been hearing a friend complain about needing a program with this simple spec.

“take in a dir, randomly look for a wallpaper there and set it.”

I’m impress that gnome doesn’t has this so simple functionality same with fluxbox (although you can use feh, but I have yet to learn how). On the other hand KDE seems to have one that’s very nice it even has wallpapers on each desktop but it’s KDE.
Then they are lots of programs with a huge ammount of “functionality” like gradients and solid backgrounds and a bunch of stuff and yet they forgot something so simple as a random chooser.

Anyway I was about to fire up my editor and code something but i decided to google around and I found many:

all the relevant ones are in this thread, ironically they are all implementations of the same program in different languages.

The one that is a bit more complex is the C code which implements it’s own counter, the shell one, perl and python are just something that reads all files in dir and randomly gets one after that they all call gconftool-2 with the correct options to set the wallpaper; after that they all say set a cron job.

The one written in C goes hardcode loading a gconf instance and setting the property there ( /desktop/gnome/background/picture_filename if someone is interested.) after that it created a mainloop and sleeps for X seconds, oh did I forget it needs to be compile and depends on 2 external libraries? good luck ubuntu users getting that build.
Anyway I could say which one I think it’s the best but as I said I don’t have any wallpapers to try them….

If only a friend of mine will lend me his huge list of wallpapers, which I’ll love to have but he refuses until I stop caling it “your huge pile of crap”
side note, check out this “true story” about openbox wallpapers why executable code is not a good idea :)

Come on click it it’s just one paragraph.

I’m sick of programs not running on WMs I’m going to gnome

I have been around some wm mainly fluxbox, lately I have been working with a great small wm (tiny some will say) call dynamic window manager, by the way dwm is also some new crap from our best friends Desktop Window Manager.

I love them both dwm is great at not getting on your way and fluxbox is super fast but there is always this program that you love that doesn’t respects X and then you have trouble.for example try running rox inside fluxbox it will grafully take control of your desktop and then there is no way to get a menu, I know you can pass in params to stick it at north or south or nodesktop but then what’s the point of rox if it has no desktop? as another example take gaim or any other IM client and try to run it inside dwm it will threat it as a full screen app and I’m not up for tagging everyone as “float” and starting to patch the code is not a good idea.

the best part of all is that this is not dwm or fluxbox fault is the fault of whoever designed the program to just do what they want. not what X tells them too. But I’m just tired of having to choose between

  • throwing out the program
  • finding a workaround
  • just complain about how bad it is.

Why gnome?

well to start I don’t like kde, never did and never will (note to self, if you ever run kde unpublish this post :D) other then the fact that it has way too much crap, it’s slow and reminds me windows and I don’t know why kde developers want to make everything and stick a k in front of it. it’s just flustrating.

On the other hand gnome is more flexible and less intrusive, i find that a couple of kde apps that I do like (amarok, kdiff3, etc) work without problems on gnome.

And of course xgl and beryl, since this is actually usefull eye candy (aka F12).

The biggest problem I see here is that the gnome that comes with gentoo is very ummm crappy? so I’ll sit down with the gnome beautifier guide as bonus points I’m going to migrate to gnome 2.16. (ones it gets out of hardmask )