Monthly Archives: November 2007

A few examples of how to use :g in vim

This vim tip of the day is really good. I use the :g/pattern/d command occasionally, but there is a lot more possible. Here’s the tip:


VimTip 227: Power of :g
http://vim.sourceforge.net/tip_view.php?tip_id=

:g is something very old and which is very powerful. I just wanted to illustrate the use of it
with some examples. Hope, it will be useful for someone.

Brief explanation for ":g"
-------------------------
Syntax is:
    :[range]:g/<pattern>/[cmd]
You can think the working as, for the range (default whole file), execute
the colon command(ex) "cmd" for the lines matching <pattern>. Also, for all
lines that matched the pattern, "." is set to that particular line (for
certain commands if line is not specified "." (current line) is assumed).

Some examples
-------------
Display context (5 lines) for all occurences of a pattern
    :g/<pattern>/z#.5
    :g/<pattern>/z#.5|echo "=========="
    << same as first, but with some beautification >>
Delete all lines matching a pattern
    :g/<pattern>/d
Delete all blank lines (just an example for above)
    :g/^s*$/d
Double space the file
    :g/^/pu ="n"
    :g/^/pu _
    << the above one also works >>
Copy all lines matching a pattern to end of file
    :g/<pattern>/t$
Yank all lines matching a pattern to register 'a'
    0"ay0:g/<pattern>/y A
Increment the number items from current line to end-of-document by one
    :.,$g/^d/exe "normal! <c-a>"
Comment (C) lines containing "DEBUG" statements
    g/^s*DEBUG/exe "norm! I/* <Esc>A */<Esc>"
A Reverse lookup for records
(eg: An address book, with Name on start-of-line and fields after a space)
    :g/<patern>?^w?p               "if only name is interested
    :g/<patern>/ka|?^w?p|'ap       "if name and the lookup-line is interested
    :g/<patern>/?^w?|+,/^[^ ]/-1p  "if entire record is interested
Reverse a file (just to show the power of 'g')
    :g/^/m0

Foot note 1: use :v to negate the search pattern
Foot note 2: Some explanation of commonly used commands with :g
 :2,8co15 => Copy lines 2 through 8 after line 15
 :4,15t$  => Copy linesa 4 through 15 towards end of document (t == co)
    :-t$  => Copy previous line to end of document
     :m0  => Move current line to the top of the document
:.,+3m$-1 => Move current line through cur-line+3 to the last but one line
             of the document
Foot note 3: Commands used with :g are ex commands, so a help search should
             be,
                :help :<help-topic>
                eg. :help :k

Response to SEO video blog by Sage Lewis

Sage Lewis runs a website marketing firm in Akron and he posts video commentaries on YouTube. I really like how candid he is in his posts.

Anyhow, he made one post called “Search Engines Optimization Expectations”.

I typed out what I believe are his main points below.

  1. A brand-new domain takes six months to a year to start showing up in Google.
  2. Getting good positions in Google is really hard. The key is links pointing into your site from external sites, and that happens when you have good content.
  3. Google owes you nothing, and you can’t buy your way to the top of the rankings.
  4. You have to have content and lots of it. You have to be a resource and you have to be relevant.
  5. You have to use phrases in your content. If you want to appear in searches for the term “franchise” you need to be talking about franchises in your site.
  6. It takes as long as it takes. The more competitive, the longer the delay.
  7. You do it until. Keep working it until works.
  8. Kill off multiple domains.
  9. Don’t hide content. No white-on-white content, no hidden DHTML, etc. The key is good content.
  10. Trust SEO for at least a year. It takes a while to get results.

I agree with most of this. There doesn’t seem to be any secret shortcut to the top of search ranks. The most reliable way there is by hosting content that other people want to find, and presenting it in a search-engine friendly format. I feel like his remarks support my belief that search engine ranking is an efficient market.

However, I don’t think I really understand what he means by “you do it until”. Does he mean that you must keep shoveling money into the SEO consultants accounts indefinitely? That seems a little self-serving.

Additionally, I also don’t know if it is really true that Google time-delays new domains. I started up this blog recently, and I nearly immediately started showing up at the bottom of the first page for Google searches on certain terms. Go do a search on lua metatable examples or python logging or cleveland heights hookah bar and you’ll likely find this blog somewhere high up there.

All the search engines publish descriptions of what any web designer should do to maximize chances of getting a premium spot. What else can an honest SEO consultant offer me besides holding my hand while I implement these practices?

If I remember my theory correctly, a firm operating in an efficient, perfectly competitive marketplace should expect to earn no better (and no worse) than any use of the same labor and capital. In other words, ZERO ECONOMIC PROFIT.

Like I said at the beginning, Sage Lewis seems like a cool guy. I think this post is brilliant.

Found a possible error in chapter 7 of the TurboGears book

I bought the TurboGears book about two weeks ago, and I have been working through it. I like the book in general, but I agree with the reviewers on Amazon that complain about the number of errors. I can’t think of another programming book that I’ve read with this many errors.

All of the errors I noticed are little glitchy typographical errors, rather than incorrect theory. The authors really do a good job of illustrating the MVC approach to web design, so I’m glad I bought it.

Anyway, this page lists mistakes found after publication, and the community of readers seems to be doing a good job of helping each other out.

I think I might have found another tiny error. This code appears at the bottom of page 109:


class ProjectFields(widgets.WidgetsList):
    title = TextField(label="project", validator=validators.NotEmpty())
    client_revenue = widgets.TextField(validator=validators.Number())
    project_form = widgets.TableForm(fields=ProjectFields(), action="save_project_test")

I don’t see the point in using both TextField and widgets.TextField. But more importantly, I think the indentation is wrong in the last line. I don’t think project_form is supposed to be an attribute of the ProjectField class.

I think the code should look more like this:


class ProjectFields(widgets.WidgetsList):
    title = widgets.TextField(label="project", validator=validators.NotEmpty())
    client_revenue = widgets.TextField(validator=validators.Number())

# Moved outside the class.
project_form = widgets.TableForm(fields=ProjectFields(), action="save_project_test")

But maybe I’m missing something. I posted to the TurboGears Book mailing list, so hopefully I’ll find out.

That American Apparel dude has gone mad with power

One explanation for this is that he is trying to prove to his oligarch friends that he can make people buy anything. Or maybe he built some kind of matter / anti-matter thing, where he can harness all the irony released by people walking around wearing these.

The site has a few pictures and this one is my favorite:

Fanny Pack + stretch pants

I especially like how the guy individual modeling the fanny pack for us is also wearing gray stretch pants. Well, at least now he or she has a place to put his or her wallet and/or car keys.

Sidenote: this blog required a new category. I can’t think of any other points to make about fanny packs, so it might be a while before I write anything else on this subject.

becontrary.com is a neat site built with TurboGears

BeContrary.com is a very clever idea for a site. This debate on going dutch illustrates how the site works. And this is a good discussion of different styles of python templates.

The site’s author, Will McGugan, wrote up a blog post describing his experience with turbogears here. He says he chose TurboGears partially because he had already worked with CherryPy and really liked it. Will made this remark after talking about SQLObject:

Incidently, I don’t like the way that Python ORMs specify the database schema as Python code. Since the schema doesn’t change when the application is running, I would prefer a simple xml definition that would be used by the ORM to dynamically build classes for each table that could be derived from in the model code.

I like this idea, but instead of writing XML, I would prefer to write SQL and have python parse that to build classes.

Why write me a response back at all?

I wrote this email to Samsung technical support a few days ago:

SUBJECT: Need Hayes commands (AT commands) for phone

Hi —

I own a Samsung A707 phone with AT&T service.

I can make a serial port connection to my phone via bluetooth. However, it seems like my phone doesn’t understand most AT commands.

Is there a list anywhere with all the AT commands that this phone supports?

Thanks for the help.

Matt

And here’s the reply I got back:

Dear Matthew,

Thank you for your inquiry. We suggest searching the internet for Hayes AT commands.

Do you have more questions regarding your Samsung Mobile Phone? For 24 hour information and assistance, we offer a new FAQ/ARS System (Automated Response System) at http://www.samsungtelecom.com/support It’s like having your very own personal Samsung Technician at your fingertips.

Thank you for your continued interest in Samsung products.

Sincerely,
Technical Support
Renee

WOW. Is Renee a chatbot or did a real human being actually spend time writing this response? I especially like that they link to the tech support section of the website. This is where I sent the email in.

Fortunately for me, the people on the gnokii mailing list are helping me out.

We’re presenting at the Jump Start Angel Fair!

The First Annual Cleveland Angel Fair picked us to present. This is fantastic news.

In other news, spent the day writing code in the house by myself. The wind is howling outside, and my fingers are shaking because I refuse to turn on the heater. I haven’t gotten so many hours of consecutive geek time in years.

This is the life. I can’t believe that I used to take a shower, put on clean clothes, and interact with humans every day.