Categories
firefox

delicious and vimperator

I’ve been trying to figure out how to use delicious with vimperator. I installed the delicious vimperator plugin and now I have the :delicious command, which doesn’t seem to do anything as far as I can tell. I asked a couple of times on the freenode/#vimperator channel, which is very nice, but nobody seemed to know.

However I recently rediscovered :set guioptions+=mTB, which shows that, indeed, the regular Firefox is back there. And then it occured to me how to do it. CTRL-v is the pass-through to Firefox, and so CTRL-v CTRL-d opens the delicious bookmark page, and CTRL-v CTRL-b opens the delicious sidebar (if you have the regular delicious plug-in). This occured to me because, though I liked y for yanking the current address, I had to lookup CTRL-v CTRL-v to paste it since p doesn’t work. So:

Firefox Passthrough

CTRL-v

Paste from Clipboard

CTRL-v CTRL-v

Toggle Delicious Sidebar

CTRL-v CTRL-b

Add Bookmark to Delicious

CTRL-v CTRL-d
Categories
bash git

bash scripts for using git to sync laptops

I have 3 Debian laptops which I use daily. One at home, one at school, and one which I carry in my backpack. I’m also a backup nut. I have 4 external drives totaling 3.25T of storage which are for storing and backing each other up. For years I used rsync with linked files, which was alright but always had issues — sometimes the links wouldn’t propagate back properly for no apparent reason. I’d have the impression that things were working well when … really there was just the latest snapshot available.

Recently I’ve switched to unison for backing up things like photos and videos, which works great and has a nice GUI. It makes snapshots and just synchronizes the drives, with minimal muss and fuss.

But for my daily work, I want something with some history, like I had hoped to get from rsync, so I can revert a file to its previous state. I wanted something which wouldn’t have a ‘main’ copy and then child copies but rather where each laptop could function stand-alone and then quickly synchronize with the others whenever they were available. I wanted something which could run over ssh. I suspected git might do some of it, but I am surprised now how much of what I wanted, git does, and does well.

So I tried out git for while, but git has a steep learning curve. So steep that its the kind of thing which I abandon if I don’t get traction quickly, since I have little time to learn technical tools like this, especially tools which are not documented for beginners. (I’ve had that issue with OpenBSD, which seems like a nice OS, and which I’ve installed, but I’ve run into issues within the first day and then had to reformat over with Debian testing.)

However git has something which is an absolutely remarkable solution to this problem. There is an excellent, friendly git IRC channel at irc.freenode.net/#git. Several people there have given me such valuable advice specific to my situations that came up in the beginning that I’ve learned git to the point where it’s a tool that helps me so much I can’t do without it. There’s lots of primers and introductions out there, but I didn’t find one that really cut it for me; it is sorely needed, but the IRC channel makes up for its absence.

One key piece of advice I got was to avoid git push and pull in the beginning, and rather use git fetch and merge only. This was good advice, since you get a better sense of what each piece is doing, and it works.

So I wrote a couple of bash scripts which I use everyday and which I like. First I have in my .bashrc a line like

export GITDIRS=~/proj1:~/proj2:~/proj3

Whenever I need to sync up laptops I run the following bash script I call gitac (for git-add commit):

#!/bin/bash

IFS=: 
for gitdir in $GITDIRS; do 
    echo $gitdir 
    pushd $gitdir 
    git add .  
    git commit 
    popd 
done

and then I ssh to the target laptop and run gitfr (for gitfrom):

#!/bin/bash

IFS=: 

for gitdir in $GITDIRS; do
    echo $gitdir 
    pushd $gitdir 
    git fetch $1:$gitdir HEAD 
    git merge FETCH_HEAD 
    popd 
done

These work superfast and sync my laptops better than I could’ve asked for from rsync. I can see the commits graphically using gitk which is nice.

When I’m syncing my laptops it isn’t always a sensible time to do a significant commit on all my projects, but with git you can have several branches, one for daily working commits and another for significant commits — I’ve yet to completely work that out and also find out how to propagate such branch information. git is flexible about how you use it, and if it works, then it works. Another thing I like is that none of the machines is “central”; in fact, I view them all as backing each other up. In particular, I don’t need the external drives for backing up my daily work anymore, they’re only for photos, videos, and things like that.

The only obvious issue is if I edit the same file on 2 different laptops and then sync, then I get merge conflicts, as would be expected. At first this was a problem, but now I generally remember to start a work session by gitfr from my backpack laptop to keep everything sync’d up.

Categories
python

How the python logger works in a few simple examples

this had also been a mystery to me. the python docs on the logger were pretty unintelligible, and i’ve used print statements for years, and i could see that the python logger seemed to be doing something, its just i couldn’t figure out what. so now the mystery is partially resolved. i think some examples might be the best way to learn about it. they added examples to the latest python docs which helped me alot, but i think some more might be useful.

the python logger is pretty intense, it’s designed to scale up to a project with multiple packages and modules. there’s a lot going on. to begin with, lets focus on a case with a single module


import logging
if __name__ = '__main__':  
    logging.basicConfig()
    mylogger = logging.getLogger('myfirstlogger')
    mylogger.debug('hello world')

this should setup a simple logger which does the equivalent of print. since mylogger is defined in the global scope, you can use it where you’d use a print statement. but it doesn’t give you any advantage over print. the first new thing you can do with logging is set the level. there’s predefined levels logging.DEBUG==10, logging.INFO=20, logging.WARNING=30, logging.ERROR=40, and logging.CRITICALERROR=50. you can generate a log entry at any of these levels with mylogger.info(‘whatever’) or mylogger.criticalerror(‘whatever’). however i use print statements mostly for debugging, so i am focused on logging.DEBUG and logging.INFO only. in fact, there’s inner loops which i sometimes want to debug but not always, and so i need levels lower than 10 for example. that’s easy, you can use mylogger(1, ‘whatever’) to have a level 1 message. and what would you do with a level 1 message? you can set the minimum level of the logger using setLevel:


import logging
if __name__ == '__main__':  
    logging.basicConfig()
    mylogger = logging.getLogger('myfirstlogger')
    mylogger.debug('hello world')
    mylogger.setLevel(5)
    mylogger.log(6, 'this will be printed')
    for i in range(10): mylogger.log(4, 'these will not since their level is too low')
    mylogger.setLevel(3)
    for i in range(10): mylogger.log(4,'but these will since we lowered the level')

pretty straightforward. however there’s one more feature of the logging system which makes it truly useful, which is that loggers form a hierarchy based on their names. notice the line mylogger=logging.getLogger(‘myfirstlogger’). this defines a top-level logger. we can create child loggers using mychildlogger = logging.getLogger(‘myfirstlogger.child’) for example. the level of the child logger, if unset, is inherited from the parent. but it can be set independently also.

each function in your module can have its own child logger, so you can turn on and off logging within each function, or have them relay the log messages up to the parent whenever you like.


import logging
def dothis():
    dothislogger = logging.getLogger('myfirstlogger.dothis')
    dothislogger.debug('wont be printed since we\'re inheriting the level from myfirstlogger')
    dothislogger.setLevel(logging.DEBUG)
    dothislogger.debug('will be printed')

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    myfirstlogger = logging.getLogger('myfirstlogger')
    myfirstlogger.debug('wont be printed since the level is INFO')
    dothis()

so you can set whatever levels you need in all your child loggers, and they will relay relevant messages up to the parent loggers.

what i’ve covered so far gives us a lot of functionality over print statements — but there’s quite a lot more to explore in the logging system. it’s a full-industrial-strength system with quite a bit more features, some of which i don’t think i’ll ever need, but others which may come in handy.

Categories
html

wordpress charges for custom css

so i discovered this when i posted some python code to my other blog, and it came out too small. i found a blog with nicer code on it, and figured it must be the css, which i viewed and found what to do, it was to add


code, pre {
	font-size       : 11px;
	color             : #682;
}

to the stylesheet. so i went to appearance on my wordpress and tried to change it… but no… it says i can preview (and the preview looks nice) but i can’t save this css. so i’m putting it here in case one day i have a way to have css.

btw this is a very nice summary of html

Categories
bash

bash completion for vim and latex

I want bash to complete .tex whenever I type vim file. and there’s a file.tex in the directory. This was driving me nuts since it was completing all the LaTeX aux files etc whenever I did it, but I found (again) /etc/bash_completion which has the line

complete -f -X ‘*.@(o|so|so.!(conf)|a|rpm|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)’ vi vim gvim rvim view rview rgvim rgview gview

which is obviously the line in question. all i did was add (aux|out|log to these filetypes and put that line in my bashrc and its working much better. frankly this was just lucky, since i dont think more than about 50-200 people in the world really understand bash completion very well.

there’s an incredible programmer i came across who wrote something interesting called compleat.

also i rediscovered FIGNORE, which is a list of file extensions for bash to ignore on all completions. just export it from your .bashrc.