parsed.org

Tips by tag: syntax

Alias File by xinu on Sep 10, 2005 12:17 AM

Instead of poluting your otherwise pristine aliases file, include larger files using this syntax:

all_users: ":include:/filename"

This will allow you to email all_users@localhost and get all the users in the referenced file.

aliasesconfigurationmailmtasendmailserversyntax

Use the form ::type to ensure that a value is cast to the proper type:

SELECT * FROM table WHERE column = 5::bigint;

In this case, column is indexed and is a bigint. The index will not be used if the query planner doesn't encounter a value of the index type. Note: this only applies in PostgreSQL 7.x.

gotchaindexperformancepostgresqlsqlsyntaxtypes

If you like working with a dark background and enjoy syntax highlighting but hate the navy blue on black, try putting the following line in your ~/.vimrc:

set background=dark
backgroundconfigurationeditorshighlightingsyntaxvimvimrc
Dynamic Docstrings by Hawk-McKain on May 05, 2008 12:02 AM

Apparently Python only recognizes a doc string a litteral string placed after a function definition, meaning it won't accept an interpolated string, or even 'a'+'b', for whatever reason. For example:

>>> def doc():
...     '''Useful info. Note: %s''' % 'You'll never see this.'
...     print doc.__doc__
>>> doc()
None

To work around this you must explicitly set __doc__. Example:

>>> def doc():
...     doc.__doc__ = '''Useful info. Note: %s''' % 'Bacon is yummy!'
...     print doc.__doc__
>>> doc()
Useful info. Note: Bacon is yummy!
docstringpythonsemanticsstringssyntax
Eliminating Search Results by xinu on Oct 03, 2005 09:50 AM

You can eliminate matches on queries based on the name of the site. For example, to search on all sites except experts-exchange.com, use the following hyphen-prefixed site string:

-site:experts-exchange.com "outer join"

Conversely, you can search only on a specified site by omitting the hyphen prefix:

site:debian.org "network install"
googlesyntax
Order By Array Subscript by cygnus on Jan 12, 2005 10:25 AM

It is possible to order by an array element as follows:

SELECT * FROM (SELECT ARRAY[1, 2, 3] AS foo) sub ORDER BY foo[1];
arrayobscurepostgresqlsqlsyntax
Print Without Trailing Newline by cygnus on Aug 17, 2005 01:26 PM

To make print suppress its usual trailing newline, add a comma to the end of the statement:

print "Foo",
print "Foo %s" % (bar),
languagesprintprogrammingpythonsyntaxtrailing-newline
Raw Post Data by xinu on Jan 15, 2005 03:10 PM

Sometimes it's necessary to access raw post data. The easiest way to do this is by opening the php://input stream:

$fp = fopen('php://input', 'r');
httpiolanguagesphppostprogrammingsyntax
Remove Duplicates by xinu on Jan 13, 2005 08:50 AM

Remove duplicate elements from a list:

newList = dict([(item, 1) for item in oldList]).keys()

Or, if you have Python 2.3 or newer, you can use a Set object to collapse your list:

import sets
newList = list(sets.Set(oldList))
dataimportlanguagesprogrammingpythonsetsyntax
Removing Comments by xinu on Jan 15, 2005 03:09 PM

If you're having to match lines that start with # you can avoid using an expression if you do something like this:

foreach ($lines as $line) {
    if ($line{0} != '#') {
        // We have a non-comment, print it.
        echo $line . '<br />';
    }
}
foreachlanguagesphpprogrammingsyntax
Replace CR/LF with CR by xinu on Jun 07, 2005 11:21 AM

Given an array @slobber, replace all the CR-LF with CR:

foreach (@slobber) {
   s/\015\012$/\n/; print;
}
dosforeachlanguagesline-endingsperlprogrammingsyntaxunix
Search Highlighting by xinu on Nov 28, 2005 08:54 AM

If you're on a dark background terminal, the hightlighting after searching in vim can be maddening. To turn it off for the session, type :set nohls.

backgroundcommandeditorshighlightingsyntaxvim
Synonym Searches by xinu on Oct 03, 2005 09:48 AM

If you want to search for synonyms, use a tilde (~) in your search string. For example:

breakfast ~nutrition
googlesyntax
Syntax Highlighting by xinu on Dec 31, 2005 04:11 PM

If you would like to have syntax highlighting on a file that would otherwise not have any highlighting at all, you can symlink the file to the appropriate extension and open it:

$ ln -s example.lxp example.html
$ vi example.html # opened with pretty highlighting

*Note: This should be used sparingly and you should clean up your symlinks.

commandseditorshighlightingshellsymlinksyntaxvi
RSS