Archive for July, 2006

Firefox tricks

Saturday, July 29th, 2006

I’ve been using firefox for a number of years now, and I keep discovering new ways to browse more efficently. I often accumulate all of the tabs with things I may be interested in looking at in the near future, but which don’t merit bookmarking. Just recently, I discovered that the browser history can be used to this end much more effectively. Say I’m looking for page with all the options for Apache’s mod_rewrite. I know that I was looking at it yesterday, but I’ve closed the tab. Ctrl-H to open the history sidebar, start typing “mod_rewrite” in the search field, and I find it. Approximate time, start to finish: 4 seconds.

The other trick I’ve been using recently is the shortcut key to get to the Google search box in the top right: Ctrl-K. Try it. Want to search for something on Google? Ctrl-K, type, enter. (If you know exactly where you want to go, Ctrl-L will take your cursor to the location bar.

onetencommunications.com is live!

Friday, July 28th, 2006

I just finished a long, productive week of work. The highlight of the week was getting the website for one:ten communications up on the web. It was really a whirlwind project. I think we started seriously thinking about it last week and didn’t start putting things together till early this week.

My primary contribution was the implementation: html, css, and a bit of Django. I’ve mostly seen—and mostly used—Django in the context of dynamic websites. In this case, we have a website that is pretty much just sits there. While it’s probably overkill, it turns out that Django can make your life easier when it comes to making web sites that are traditionally done with just html or maybe a smattering of php.

The flatpages is the key app here. With Django’s admin, I can add, remove, and edit pages easily. Then, I put together a couple templates to abstract out the common elements between the standard pages and the profile pages. That made me happy. Having to make header or footer changes across a bunch of pages is not a good way to do things.

Fun with the Django ORM API

Friday, July 21st, 2006

I’ve had the good fortune of getting to learn and use Django for my job this past couple months. One of the really nice things about Django is the ORM and the API that allows me to do things such as this:

I’ve been working on the product database. One of the things that needed to be done was to take a bunch of products from the old site and put them on our site so that we can get a feel for what it will look like. Books like “Test book 1″ by “someone” only go so far.

One thing that is associated with each product is a thumbnail picture of the product and a bigger picture of the product. So, for the product ltpr-18758, there are two pictures: ltpr-18758_n.jpg and ltpr-18758_t.jpg. Last night I had a directory full of pictures and an excel file full of product information. So I played with it a bit and was able to pull all of the information into the database. It was cool. To save time, I just randomly added two picture to each product. This morning, I think it would be better to have the pictures be correct, as well as to associate picture and products correctly.

Django has a spiffy API to access data.
This will get all of the products:
>>> product_list = Product.objects.all()
Then, I could do something like this to get the title for the 10th book:
>>> product_list[9].title
'Some Random Book'

What I want to do is for all products, take their product code, add a “_t.jpg” or “_n.jpg” and set that to the image1 and image2 fields. Like so:


for product in product_list:
   product.image1 = "item-images/" + product.internal_code.lower() + "_t.jpg"
   product.image2 = "item-images/" + product.internal_code.lower() + "_n.jpg"
   product.save()

So, you’ll get an image1 like item-images/ltpr-18758_t.jpg

From the Archives 5

Friday, July 21st, 2006

From January 26, 2005:

So I’ve been thinking lately about organizing data. I know a lot and I’ve done a lot. In fact, I’ve consumed so much information and figured out so much stuff that I don’t remember half of it. That’s unfortunate. For work, I’ve been playing with a Wiki to manage what’s going on and help communication with the team. It’s going pretty well I think. I’ve used it more than anyone. So I was thinking, what if I could put together a website or a program or something to just put information? It would be a nice central place to store links, for example. I always end up deleted all my bookmarks/links/favorites and starting over whenever I reload the OS or change computers or whatever. So, what if I had a website to manage those? Then, what about a sort of project notebook? A place to store all my thoughts as I’m trying to figure something out, and then what I discover works. It’d be like my own personal repository of tutorials. Another idea is a place to mirror webpages. Now, this would be a bit sticky, legally, if I made them availible to the public, but I’m thinking more of a place to archive really useful sites that may cease to exist at some point. Which brings up another point. It might be interesting to have it publically availible. It might even be worth doing a Wiki sort of thing. But I definitely need to have some access control. I think something a little more flexible than public and private is also a good idea. Extensibility is critical. What about an address book? RSS agregation of other stuff I’m interested in? Google search box? Ranking sites by how often I go to them. Can I do that? something like www.mysite.com/linktrack.php?www.google.com or something like that. The key thing here is having the data accesible. Presentation of information is very important. Searchability is key. *very* dynamic. A Firefox extension, or maybe a bookmark would work like “blog this”. Ok, out of ideas. We’ll see what comes of this.

From the Archives 4

Friday, July 21st, 2006

From March 15, 2005:

One of these days I’m going to create a separate site for all my computer related writing. In the mean time, I found a couple new cool things about vim, my text editor of choice.

[Ha!  I just did that.]

First, because it has all sorts of cool autoindent features and comment continuation stuff, pasting can be a pain. It usually ends up totally messing up the formatting. There is a solution. It’s the ‘paste’ setting. Who would have thunk it? Before pasting, :set paste. After pasting, :set nopaste. Piece of cake and it works like a charm.

Next, I don’t like how vim does indenting. Eight spaces is way too much. Also, when editing code that has an existing standard, it would be nice to maintain that standard. How? The relevant settings are ’shiftwidth’, ‘tabstop’, ’softtabstop’, and ‘expandtab’. I’m not sure 100% how these all work together but here’s a stab at getting things to work:
expandtab: either on or off. When it’s on, it doesn’t insert tab characters. Just spaces.
shiftwidth: The width in characters that the auto-indent should be.
tabstop: The width in characters that the tab character displays as.
softtabstop: By default set to 0, aka off. When on, it is the number of spaces that are inserted with the tab key. Say you set it to 6, with tabstop set to 4. Then pressing tab would result in a tab character and two spaces being inserted. I think I can do evertyhing I want to without using this.

So, I think the way I want things is tabs to be 3 characters. So, set tabstop=3'and set shiftwidth=3 should do it.

What about files where it is all spaces, with a 2 character indent? :set tabstop=2 and :set shiftwidth=2 and :set expandtab does the trick quite nicely.

From the Archives 3

Friday, July 21st, 2006

From December 3, 2005:

More Eterm. I haven’t figured out the End key, but I figured out how to toggle between black-on-white and white-on-black.

This involves ANSI escape sequences. Tricksy things. \e]2;TITLEBAR\a is an example of an escape sequence. (See the previous entry) Here are the two lines that do the job:
bind ctrl alt b to string ‘^[]39;#aaaaaa^G^[]49;black^G’
bind ctrl alt w to string ‘^[]39;black^G^[]49;white^G’
I’m not sure how to explain them, so I’ll leave it at that. Here is the site where I found the escape sequences to use.

From the Archives 2

Friday, July 21st, 2006

From December 2, 2005:

More Eterm. Turns out the next item on the agenda is not to get the End key working, but to get something more helpful than “Eterm” to appear in the title bar. This is where we start to get into some dark magic. Here’s the prompt I’m using right now, after some hair pulling and tweaking:
PS1=”\[\e]2;\u@\h \W\a\][\u@\h \W]\$ “
That’s just craziness. How do we decipher this and bend it to our will? I found a very helpful site by IBM here.

Just for grins, I shall unravel this statement. first, let’s expand some thing.
\u = your username
\h = first part of your hostname
\W = the name of the the current working directory
\$ = $ if you are not root, # if you are.

Basically what we have here is the same prompt twice. First it is wrapped in \[\e]2; and \a\]. Then we have the same thing again, plus the \$. I’ll get back to this, but what we basically get is “[username@hostname current-dir]$”. For example, “[josterpi@gandalf docs]$ “

Get back to the first part: \[\e]2;TITLEBAR\a\] puts TITLEBAR in the title bar of the terminal. Exactly what I wanted to do. I ran into a very wierd problem though. As I was typing commands, it would wrap around onto the same line, so that I was writing over what I had just writting. Very annoying. It turns out that the problem I had was that I wasn’t wrapping the title bar section in \[ and \]. What the escaped brackets do is indicate to the shell that what is in the brackets should no be considered when calculating word wrapping, which is what I was having trouble with. That is, the stuff between the brackets is non-printing. We would have to use brackets if if we were using escape sequences for color or whatever else.

Next I’ll have to explain how I was able to use escape sequences to dynamically toggle my Eterm from black-on-white to white-on-black using escape sequences and key bindings.

Also, I’ve done some neat stuff with key bindings in fluxbox and figuring out the keycodes for a couple of my IBM thinkpad specific keys. More later…or not.

From the Archives 1

Friday, July 21st, 2006

Going to copy-paste some posts I want to keep from the old blog. Finding that blog is left as an exercise for the reader.

From December 1, 2005:

I’ve started using Eterm and Fluxbox. One thing that annoys me about Eterm is that it scrolls one page at a time when when I scroll with the mouse. I just figured out how to change this. It took far longer than it should have, and Google was no help. So, hopefully this should be of help to whoever finds this

It’s simple, really. In your user.cfg file (probably in .Eterm/themes/Eterm/user.cfg) Go the the actions section and add these two lines:
bind button5 to script ’scroll(2l)’
bind button4 to script ’scroll(-2l)’
This will have Eterm scroll two lines instead of one page. I like two lines. You can change it to whatever you want. Here’s my whole action section, for context:
begin actions
bind ctrl shift button3 to string ‘^[]6;14^G’
bind ctrl button3 to menu “Eterm”
bind ctrl button2 to string ‘^[[?30t’
bind ctrl button1 to string ‘^[]5;^G’
bind button5 to script ’scroll(2l)’
bind button4 to script ’scroll(-2l)’
end actions

Next on the agenda, figure out how to make my End key work.

(For those who are familiar with my blog, you won’t be interested in this. I’m just writing this in the hopes that someone will stumble across it and be saved the frustration I went through in getting this to work.)

kick-off

Friday, July 21st, 2006

Turns out installing a Wordpress blog is a piece of cake. Why didn’t I do this before? Of course, now I need to take the time to come up with a less generic template.