Remember Remember

jueves, 22 de abril de 2010

test

lunes, 15 de junio de 2009

Screen -X

I found here a nice use of screen I didn't know about:

screen -X stuff

You can send a sequence of chars to any screen!,

example

screen -S 9962.pts-0.ursa -p 4 -X stuff 'ls^M'


Side note: I knew the ESC * and the ESC ESC meaning on bash, but I didn't know the ESC . That's useful!.

martes, 2 de junio de 2009

Reinstalling...

As I mentioned before, I almost broke my system :P. Even though the system is running well, this (and vacation time) suggested me to reinstall my laptop using debootstrap, lets see how does it go.

lvcreate VolumeGroup -L 5G -n root
/sbin/mkfs.ext3 /dev/VolumeGroup/root
mount /dev/VolumeGroup/root /mnt/
debootstrap --arch=i386 jaunty /mnt

wow, that was easy! ~350Mb (including the packages) and includes many usefull packages.

The system is installed, now we need to make it bootable:

cp /etc/apt/sources.list /mnt/etc/apt
edit edit edit
cp /etc/fstab /mnt/fstab
edit edit edit
mount -o bind /dev/ /mnt/dev/
mount -o bind /proc/ /mnt/proc/
chroot /mnt
apt-get update
apt-get install linux-image-2.6.28-11-generic lvm2 wpagui


Finally I edited the grub conf (menu.lst) and now I am gonna reboot the machine.


A couple of errors, both it booted. I forgot to copy the microcode (firmware) of my wireless card, but once I copied it and configured the wpa, I could connect to my wireless network.

Now

aptitude install firefox-3.5 openbox vim-full mc xserver-xorg-core x11-xserver-utils xinit

and startx :)

Home server ct'ed

The package debootstrap looks interesting

Home server

So I got bored of thinking on serving from my home laptop. Let's do it:

I don't want to think too much, so I am gonna install the webserver in a chrooted slack

lvcreate VolumeGroup -L 1G -n JailRoot

From a previous post, I know that a good base for a chrooted Slack are the following packages
attr
coreutils
grep
pkgtools
aaa_base
bash
etc
gzip
tar
acl
bin
glibc
libtermcap

then



a="attr
coreutils
grep
pkgtools
aaa_base
bash
etc
gzip
tar
acl
bin
glibc
libtermcap"

wget http://slackware.cs.utah.edu/pub/slackware/slackware-12.2/FILELIST.TXT

for j in $(for i in $a; do grep "/$i-" FILELIST.TXT ; done | gawk -F ' [.]/' '/tgz$/{print $2}'); do wget http://slackware.cs.utah.edu/pub/slackware/slackware-12.2/$j; done


Now we can go and check slashdot for a while :.

Yes, there are some spurious packages, with a quick glance, we can do
rm bash-completion-20060301-noarch-1.tgz


As we are not necessarily inside a Slack to begin with, we will have to install the packages the good-ol' way:

mkreiserfs /dev/VolumeGroup/JailRoot
mount /dev/VolumeGroup/JailRoot /mnt/
mv *tgz /mnt
cd /mnt


NOTE, from now use a non super user account (I used root and almost crashed my system :) rm -Rf anyone?)

tar xf pkgtools-12.1.0-noarch-7.tgz
sbin/installpkg -root /mnt *tgz



now, back in business with root
chroot /mnt/

and we are in!

By now we have a ~250Mb bareboned installation of slack (I know, it can be done better, but this times disk space is not a big deal), now we can install the moin wiki:
wget http://slackware.mirrors.tds.net/pub/slackware/slackware-12.2/slackware/d/python-2.5.2-i486-4.tgz
cd opt
wget http://static.moinmo.in/files/moin-1.8.3.tar.gz
tar xf moin-1.8.3.tar.gz


try to run, and...

Traceback (most recent call last):
File "wikiserver.py", line 38, in
MoinScript().run()
File "/opt/moin-1.8.3/MoinMoin/script/__init__.py", line 138, in run
self.mainloop()
File "/opt/moin-1.8.3/MoinMoin/script/__init__.py", line 240, in mainloop
from MoinMoin import wikiutil
File "/opt/moin-1.8.3/MoinMoin/wikiutil.py", line 25, in
from MoinMoin.support.python_compatibility import rsplit
File "/opt/moin-1.8.3/MoinMoin/support/python_compatibility.py", line 90, in
import sha
File "/usr/lib/python2.5/sha.py", line 6, in
from hashlib import sha1 as sha
File "/usr/lib/python2.5/hashlib.py", line 133, in
md5 = __get_builtin_constructor('md5')
File "/usr/lib/python2.5/hashlib.py", line 60, in __get_builtin_constructor
import _md5
ImportError: No module named _md5


a quick google points to openssl, then
wget http://slackware.cs.utah.edu/pub/slackware/slackware-12.2/slackware/a/openssl-solibs-0.9.8i-i486-1.tgz
installpkg openssl-solibs-0.9.8i-i486-1.tgz


now another try and

2009-06-02 20:08:02,283 INFO MoinMoin.log:126 using logging configuration read from "/opt/moin-1.8.3/wikiserverlogging.conf"
2009-06-02 20:08:02,530 INFO MoinMoin.server.server_standalone:72 ThreadPoolServer serving on 127.0.0.1:8080
Traceback (most recent call last):
File "wikiserver.py", line 38, in
MoinScript().run()
File "/opt/moin-1.8.3/MoinMoin/script/__init__.py", line 138, in run
self.mainloop()
File "/opt/moin-1.8.3/MoinMoin/script/__init__.py", line 255, in mainloop
plugin_class(args[2:], self.options).run() # all starts again there
File "/opt/moin-1.8.3/MoinMoin/script/__init__.py", line 138, in run
self.mainloop()
File "/opt/moin-1.8.3/MoinMoin/script/server/standalone.py", line 131, in mainloop
run(Config)
File "/opt/moin-1.8.3/MoinMoin/server/server_standalone.py", line 636, in run
switchUID(config.uid, config.gid)
File "/opt/moin-1.8.3/MoinMoin/server/__init__.py", line 31, in switchUID
raise RuntimeError('will not run as root!')
RuntimeError: will not run as root!


Ok, this looks easier to fix.
Two options here: create users in the jail or use users from the machine. I am lazy (and I think it can be safer [citation needed :P], lets face it, I am lazy), therefore I am gonna create users inside:

wget http://slackware.cs.utah.edu/pub/slackware/slackware-12.2/slackware/a/shadow-4.0.3-i486-15.tgz
adduser user
su - user
python wikiserver.py


And PRESTO!, it is working now.

viernes, 22 de mayo de 2009

MoinMoin XMLRPC

Sweeet.

http://moinmo.in/WikiRpc

viernes, 15 de mayo de 2009

While "I'm compiling..." project?

"Smart playlist" generation based on last.fm

This may help
http://www.stats.ox.ac.uk/~davison/software/dbm/

miércoles, 13 de mayo de 2009

Escaping quotes in bash

A common problem I have.
The solution is (from here):

To single quotes work you need to break out of the single quoted string then escape your single quote. Like so:

sed -e 's/'\''a/b/g'

Because \' is not inside of single quotes the single-quote is properly escaped and the output is as we’d expect:

Passing variables to gawk

It can be necessary to pass a variable from the shell to a gawk session. I found three different ways of doing so:

echo message: | gawk '{print $0, var}' var=1234

echo message: | gawk -v var=1234 '{print $0, var}'

var=1234; echo message: | gawk '{print $0, "'"$var"'"}'

More tricks here

Incredible oneliner

This oneliner is incredibly useful:
gawk '{avg=avg+$2; sd2=sd2+($2*$2)} END{avg=avg/NR;sd2=sd2/NR; print avg" "sqrt(sd2-avg*avg)}'

It calculates the average and the standard deviation of a column in a set.

I know it may sound trivial, but I didn't know that you can calculate the sd by adding the square of each term (I always calculate it by adding the square of the difference with the average).

lunes, 11 de mayo de 2009

vim integration with MoinMoin

This allows gf to follow a link,
NOTE: I just realized that blogger doesnt like the greater than and lower than, (makes sense), I am gonna correct this later.

if !exists("loaded_moin")
set autowrite
let loaded_moin = 1
set isk=a-z,A-Z,/,-,_

autocmd BufWritePost * !editmoin -c ""

function! Moin_EditPage()
let url = "http://localhost:8000/".expand("")
"let url = strpart(getline(1),8).expand("")
new
execute "read !editmoin -f ".url
let filename = getline(".")
quit!
execute "edit ".filename
endfunction

map gf :call Moin_EditPage()

endif

ToDo: maybe a stack to navigate forward and backward

Personal wiki

So I want a personal wiki. First, I started using vim and plain-text files with the gf magic, the main problem arrives when you want (or need) to use non plain-text files (pics, plots, pdfs, etc).


As my main concern is to be able to track my research, the fact of being able to attach a pdf is very useful. Is this why I ended up with the idea of using a more powerful wiki. My first shoot is something called MoinMoin. Installation in standalone mode is pretty straightforward. It looks OK so far, it is written in python and seems very extensible (there are many plugins available).


After a couple of tests, I found myself writing too much. This made me wonder if it were possible to use an external editor to modify the pages. I tried the It's all text firefox extension, a extension that enables using any external program to edit HTML textareas. The extension work fine (I am using it actually to write this post), but I still wanted something I could edit directly from the command line.


After googling a little, I reach the editmoin page. Editmoin allows you edit
MoinMoin pages directly from the CLI: it fetches, opens an editor and
commits when you close the editor if there were any changes in the file.


The only but I found, was the impossibility of following links inside the
editor (VIM in my case), so I modified the editmoin script to add the
JustFetch or JustCommit actions. The corresponding diff for the script in the editmoin-1.10.1.tar.gz tarball is



71c71
< def __init__(self, filename, id, has_moin_session):
---
> def __init__(self, filename, id, has_moin_session,url=None):
76a77
> self.url = url
150a152
> file.write("@@ URL: %s\n"%self.url)
305c307
< return MoinFile(filename, id, has_moin_session)
---
> return MoinFile(filename, id, has_moin_session,url=url)
381a384,392
> extra_options = {"f":"Fetch","r":"Release","c":"Commit"}
> action = None
> filename = None
> if argv[0][1] in extra_options.keys():
> action = extra_options[argv[0][1]]
> argv = argv[1:]
> if action == "Commit":
> filename = argv[0]
> argv[0] = open(argv[0]).readlines()[0].split()[-1]
394,395c405,411
< if editfile(moinfile):
< sendfile(urlopener, url, moinfile)
---
> if action:
> if action == "Fetch":
> print moinfile.write_raw()
> sys.exit(0)
> if action == "Commit":
> moinfile.read_raw(filename)
> sendfile(urlopener, url, moinfile)
397c413,416
< sendcancel(urlopener, url, moinfile)
---
> if editfile(moinfile):
> sendfile(urlopener, url, moinfile)
> else:
> sendcancel(urlopener, url, moinfile)



It is not an elegant hack, but it works. Just

editmoin -f ThePage


and it will print the filename. Edit the file as much as you want, and then

editmoin -c TheFile


and it will commit the page (Attention, it wont delete the file).


The next step is to integrate it into VIM.

jueves, 23 de abril de 2009

Calculate the standard deviation (and average as well) via awk

This nice oneliner is very handy for calculating the standard deviation
gawk '{avg=avg+$2; sd2=sd2+($2*$2)} END{avg=avg/NR;sd2=sd2/NR; print avg" "sqrt(sd2-avg*avg)}'

lunes, 13 de abril de 2009

SSH session without password

For connecting from machine_a to machine_b

ssh-keygen -t rsa
cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'

viernes, 7 de noviembre de 2008

I am too old for this shit

I mean, for me the biz was as clear as water. I was ready to stand for many things in order to be with her.

But she always misundestands me.

I am too old for this shit.

sábado, 1 de noviembre de 2008

Linux (UBUNTU) in an HP TC1100 tablet

I feel lazy today, so I am not going over all the configuration and such. I put all this together just as a reminder. If you need help with some specific problem, do not hesitate on contacting me.

NVidia

apt-get install envyng-gtk

Stylus
apt-get install wacom-tools

Section “InputDevice”
Driver “wacom”
Identifier “stylus”
Option “Device” “/dev/input/wacom”
Option “Type” “stylus”
Option “Button2″ “3″
Option “ForceDevice” “ISDV4″# Tablet PC ONLY
EndSection

Section “Device”
Identifier “Configured Video Device”
Driver “nvidia”
BoardName “vesa”
BusID “PCI:1:0:0″
Screen 0
Option “RandRRotation” “on” #Allows rotation
Option “NvAGP” “1″ #Helps to the suspend
EndSection

Section “ServerLayout”
Identifier “Default Layout”
Screen 0 “Default Screen” 0 0
InputDevice “Generic Keyboard” “CoreKeyboard”
InputDevice “Configured Mouse” “CorePointer”
InputDevice “Synaptics Touchpad”
InputDevice “stylus” “SendCoreEvents”
EndSection




map the rotate script
#!/bin/sh
if [ -n "$(xrandr | grep 768x1024)" ]; then
xrandr -o normal
xsetwacom set "stylus" Rotate NONE
else
xrandr -o left
xsetwacom set "stylus" Rotate CCW
fi

jueves, 23 de octubre de 2008

My best fall ever!!

This is funny, actually :P.

Hmm, let's get serious. Fall is a nice time I think. The colors in the trees are really nice, and usually have the strange side effect of making me feel better.

I think the answer of the question "Hey, how are you?" make sense for me right now:
"Good"

miércoles, 22 de octubre de 2008

Python web server

cd to a directory you want to serve and

python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"


Really nice!

sábado, 27 de septiembre de 2008

 

 
Posted by Picasa


China pendeja, por que carajos la quiero tanto?!

sábado, 13 de septiembre de 2008

Graduate Student's Recipes - Part III

Ok, There is a good site with useful information about recipes you can cook easy enough while you are a grad student.

The Graduate Student Cookbook