Just watched James Cameron's Avatar last Jan 8 with my eldest Son(18).
It's an experience.
This was on the big, big screen, with the full 3d effects. And it really felt different. The whole movie was built to make people feel immersed into the world of Pandora. I enjoyed it. Over two and a half hours, no breaks, and action, stereotypes, action, wonderful effects, fine actors, action, and action.
Blunt spoilers ahead after the jump...
Showing posts with label scripts. Show all posts
Showing posts with label scripts. Show all posts
2010-01-09
2008-08-05
lplist - show solaris "lp-lite" queues matching pattern
This is something I've been using for years in various variations. "lp lite" was introduced as an alternative for the complexity of the sysv lpsched printer daemon. Instead of directories with printer filters and interface scripts, the assumption was that you'd be talking to a remote BSD print spooler.
For that, you needed the printer address and printer name, nothing more. Paper is typically A4 or Letter, depending on geography. What we print is typically postscript, or plain text. All of those are assumed to be preset on the other end.
This little script will scan your printers.conf (using lpget list) and dump all printer definitions matching your supplied regular expression pattern one line at a time, giving the queue name first, followed by all 'lpset -a' keyword=value settings for that queue.
By putting the queue name first in the output, this makes it easy input for the next script in a pipe, as you can simply say
lplist hp | while read hpq more; do ...; doneto process all print queues with "hp" in their name.
The empty pattern will just dump all queue names.
#!/bin/ksh -p
#
# usage: lplist [pattern]
#
#
PATH=/usr/bin
lpget list |
nawk -F: -v pattern=$1 '\
/:/ {
if (!pattern || q~pattern) {
print q, def
}
q=$1
def=""
next
}
!pattern || q ~ pattern {
def=def" -a "$0
}
END { if (def) print q,def }'
Exercise for the reader: Rewrite in pure awk. That is, drop the shell.
2007-12-18
ksh93 performance through builtins - a small example
I recently held a presentation for the Dutch OpenSolaris Users Group about the work of Roland Mainz on integrating ksh93. I focused on the history of unix shells, how ksh93 was accepted in the OpenSolaris project, specifically highlighting the OpenSolaris ARC process.
I did not discuss the relative merits and reasons for getting ksh93 included, but today I'll mention one reason in particular: shell script performance. Ksh93 is faster than any other POSIX conforming shell in executing code, not in the least because many standard unix commands have been included as builtins in the shell, allowing scripts to bypass fork() and exec().
Here is a comparison of two lines of code in ksh93. Their effect is exactly the same: Ten thousand times, they create and remove a unique directory. The difference is that the second time around, the ksh builtins for mkdir and rmdir are used.
glorantha 10 $ time for i in {0..9999}; do /bin/mkdir $i; /bin/rmdir $i; done
real 0m35.63s
user 0m1.44s
sys 0m1.65s
glorantha 11 $ time for i in {0..9999}; do mkdir $i; rmdir $i; done
real 0m1.44s
user 0m0.33s
sys 0m1.09s
But there are other ways of improving the above bit of code, if you're satisfied with a slightly different sequence of actions, and non-POSIX code due to the compact {start .. end } notation.
What I like about this code is that it's compact, and quite clear in its intention.
glorantha 12 $ time mkdir {0..9999} && rmdir {0..9999}
real 0m0.53s
user 0m0.02s
sys 0m0.51s
glorantha 13 $ time /bin/mkdir {0..9999} && /bin/rmdir {0..9999}
real 0m0.53s
user 0m0.03s
sys 0m0.48s
More later
I did not discuss the relative merits and reasons for getting ksh93 included, but today I'll mention one reason in particular: shell script performance. Ksh93 is faster than any other POSIX conforming shell in executing code, not in the least because many standard unix commands have been included as builtins in the shell, allowing scripts to bypass fork() and exec().
Here is a comparison of two lines of code in ksh93. Their effect is exactly the same: Ten thousand times, they create and remove a unique directory. The difference is that the second time around, the ksh builtins for mkdir and rmdir are used.
glorantha 10 $ time for i in {0..9999}; do /bin/mkdir $i; /bin/rmdir $i; done
real 0m35.63s
user 0m1.44s
sys 0m1.65s
glorantha 11 $ time for i in {0..9999}; do mkdir $i; rmdir $i; done
real 0m1.44s
user 0m0.33s
sys 0m1.09s
And this explains why a builtin matters. Both the internal and external command are just as efficient if they're only invoked once. When you have to invoke an external command inside an inner loop, the unix fork()/exec() overhead add up.
But there are other ways of improving the above bit of code, if you're satisfied with a slightly different sequence of actions, and non-POSIX code due to the compact {start .. end } notation.
What I like about this code is that it's compact, and quite clear in its intention.
glorantha 12 $ time mkdir {0..9999} && rmdir {0..9999}
real 0m0.53s
user 0m0.02s
sys 0m0.51s
glorantha 13 $ time /bin/mkdir {0..9999} && /bin/rmdir {0..9999}
real 0m0.53s
user 0m0.03s
sys 0m0.48s
More later
2007-12-05
Document the why in your code
This article in ACM Queue reminded me of the most valuable
argument I once heard in favor of code comments.
You don't explain what the code does, you tell why it does it.
I'm all for the concept of self-documenting code, and except
for the obvious iterator i and counter n, I do try to find descriptive
names for my data structures.
The strongest argument against comments is that they can be wrong.
There's nothing as frustrating as a comment that contradicts the code.
Especially when you believe it.
So yes, comments are good, but let them tell why.
argument I once heard in favor of code comments.
You don't explain what the code does, you tell why it does it.
I'm all for the concept of self-documenting code, and except
for the obvious iterator i and counter n, I do try to find descriptive
names for my data structures.
The strongest argument against comments is that they can be wrong.
There's nothing as frustrating as a comment that contradicts the code.
Especially when you believe it.
So yes, comments are good, but let them tell why.
2007-11-22
26400 hits and counting... 'beowulf uncanny-valley'
I saw the trailers for beowulf yesterday, and the first thing that sprang to mind was 'uncanny valley'.
The characters as a whole look larger than life, but all personality has been removed from their expression.
A real waste of talent.
I'm far from the first to realise this, as a quick search shows.
26,400 and counting, I'm sure...
The characters as a whole look larger than life, but all personality has been removed from their expression.
A real waste of talent.
I'm far from the first to realise this, as a quick search shows.
26,400 and counting, I'm sure...
Subscribe to:
Posts (Atom)