int MaxSumSubArray(int *a, int len, int *start, int *end) { int max = INT_MIN; int min = 0; int sum = 0; *start = -1; *end = -1; for (int i = 0, j = 0; i < len; i++) { sum += a[i]; if (sum > max) { *start = j; *end = i; max = sum; } if (sum < 0) { j = i + 1; sum = 0; } } return max; } we can call this api as follows: int a[]={-3, -2, -10, -4, -7, -8, -10, -10, -100, -12, -3}; int s1 = 0; int s2 = 0; int sum = MaxSumSubArray(a, sizeof(a)/sizeof(int), &s1, &s2);
Saturday, July 31, 2010
Program to find Maximum sum of a subset in an array
I came up with the efficient O(n) solution for this problem. If you have better solution to this problem; Please post your solution as comment.
Also remember that, the largest sum could also be among all negative numbers as well, the sum is not necessarily a positive sum.
Saturday, January 9, 2010
Capacitive vs Resistive touch screens
Are you confused with all this fuss on resistive and capacitive touch screens coming with the smart phones these days? Here is an article that helps you understand both the technologies.
First of all, here is the explanation as to what a Capacitive touch screen and a Resistive touch screen is, in scientific terms.
Capacitive touch screen:
The capacitive touch screen is made up of a glass panel that is coated with a material. The property of this material is that it can store electrical charge. So the capacitive touchscreens basically stores electrical charge.
But for good, Human body can also store charge. So, when you touch this screen with your finger, some of these charges on the screen gets transferred to your finger. The oscillator circuits located at the corner of your system will then sense this decrease in the charge on screen and spot the exact location where touch occurred, and then transfers this specified information to the touchscreen driver software.
Example: Apple iPhone uses a Capacitive touch screen
Pros: * Multi-touch support available * Visibility good even in sunlight * Highly sensitive to finger touch leading to ease of use * Not prone to dust particles * Glossy look and feel Cons: * Need to have at least 5% humidity to achieve capacitive effect * More expensive than Resistive touch screen * Doesn't work with inanimate objects/fingernails/gloved fingers * Latest technology, may need to evolve a bit more!
Resistive touch screen:
Resistive touch screen, on the other hand is again made up of normal glass panel. However, this glass panel in this case is coated with three layers.
Two of these layers being conductive and resistive are kept apart using spacers while the third scratch-resistant layer covers the whole setup.
When the resistive touch screen system is running, current flows through these layers. On a finger touch, the two layers get connected and change in electrical field occurs. The system calculates the coordinates of point of contact and passes them to touch screen driver software.
Example: Nokia N97, Nokia 5800 Express Music uses Resistive touch screen
Pros: * Relatively cheaper * Can operate with any pointing devices like stylus, pen, nail etc * Can operate at any level of humidity * Ease of use, as it could be used even with your winter gloves on! * Very useful for people using handwriting recognition system, due to ease of use with a stylus! * More accurate than capacitive touch screen! * Old technology and hence more reliable! Cons: * Multi-touch support not available. Though technology did evolve after some modifications with the existing resistive touch screen circuitry, its still not 100% developed yet! * Highly sensitive. As it can operate with almost any sort of pointing devices, can be more vulnerable with dust particles! * Poor visibility in sunlight, mostly due to multiple layers reflecting light! * Screen, being sensitive at the upper layer, can be more vulnerable to scratches!
Friday, December 25, 2009
How Visa, Master and American Express Credit cards works, and their differences
American Express Credit cards made their presence known in the financial jungle in the early 50’s. Visa and Master Card also came into the scene around the same time and served the same market segment – Credit. There soon developed their own model for serving the market and established themselves as leaders in the credit card providers the world over.
While American Express or AMEX as it is popularly known in the European countries has grown to be the most widely recognizable of credit cards and is a name that describes exclusivity in a way. However, not many credit card holders throughout the world know the difference in the three major players in the credit card industry. Actually there is no difference between Visa and Master Card, the main difference is between these two players and American Express credit cards – The major difference is in their style of operation.
Visa Card and Master Card are primarily methods of making payments. These are tow financial companies that have grown into institutions by themselves. They negotiate and setup payment systems at different merchant locations across the globe but never issue any credit cards themselves. Visa and Master Card set up business partnerships with merchant establishments where customers can use the credit cards and banks or financial institutions that actually issue credit cards to their customers. Visa and Master Card make the payment to the merchant establishments where the cards are used and charge the company that actually issued the card to the customer a fee for making the up front payment on their behalf. The card issuing company on its part charges a fee for issuing the card, an annual rental for the card and an interest on the amount of payment paid out to the merchant establishment.
These credit card companies are billed by Visa or Master Card and they in turn bill the card holder. The holder never pays any cash directly to Visa or Master Card.
American Express is different in that they have an entirely private setup. They issue their credit cards under their own name and logo. They also directly make payments to merchant establishments where the card is used. American Express do their own marketing of services to merchant establishments and card customers. The other difference is that American Express has a limited usage through the world while Visa and Master Card are accepted at over 20 million merchant establishments in over a hundred and fifty countries.
Sunday, August 2, 2009
Bash shell Command line editing
Note that these commands are not case sensitive. Ctrl + A Go to the beginning of the line you are currently typing on Ctrl + E Go to the end of the line you are currently typing on Ctrl + L Clears the Screen, similar to the clear command Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line. Ctrl + H Same as backspace Ctrl + R Let’s you search through previously used commands (type few letters of the command) CTRL + O Executes the found command from research Ctrl + C Kill whatever you are running Ctrl + D Exit the current shell Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it. Ctrl + W Delete the word before the cursor Ctrl + K Clear the line after the cursor Ctrl + T Swap the last two characters before the cursor Esc + T Swap the last two words before the cursor ALT + F (forward) moves forward the cursor of one word. ALT + B (backward) moves backward the cursor of one word. ALT + del cuts the word before the cursor. ALT + D cuts the word after the cursor. ALT + U capitalizes every character from the cursor's position to the end of the current word. ALT + L lowers the case of every character from the cursor's position to the end of the current word. ALT + C capitalizes the character under the cursor and moves to the end of the word. ALT + R Cancels the changes and put back the line as it was in the history. Tab Auto-complete files and folder names CTRL + X CTRL + X (because x has a crossing shape) alternates the cursor with its old position. CTRL + X CTRL + E (editor because it takes the $EDITOR shell variable) edits the current line in vi. Shift + Insert Paste the content from Clipboard to current cursor position
Sunday, May 24, 2009
C++ Placement New/Delete Operator
In C++, operators new/delete mostly replace the use of malloc() and free() in C. For example:
allocates storage for an A object and arranges for its constructor to be called, later followed by invocation of the destructor and freeing of the storage. You can use the standard new/delete functions in the library, or define your own globally and/or on a per-class basis.
There's a variation on new/delete worth mentioning. It's possible to supply additional parameters to a new call, for example:
A *p = new (a, b) A;
where a and b are arbitrary expressions; this is known as "placement new". For example, suppose that you have an object instance of a specialized class named Alloc that you want to pass to the new operator, so that new can control allocation according to the state of this object (that is, a specialized storage allocator):
class Alloc {/* stuff */};
Alloc allocator;
...
class A {/* stuff */};
...
A *p = new (allocator) A;
If you do this, then you need to define your own new function, like this:
The first parameter is always of type "size_t" (typically unsigned int), and any additional parameters are then listed. In this example, the "a" instance of Alloc might be examined to determine what strategy to use to allocate space. A similar approach can be used for operator new[] used for arrays.
This feature has been around for a while. A relatively new feature that goes along with it is placement delete. If during object initialization as part of a placement new call, for example during constructor invocation on a class object instance, an exception is thrown, then a matching placement delete call is made, with the same arguments and values as to placement new. In the example above, a matching function would be:
With new, the first parameter is always "size_t", and with delete, always "void*". So "matching" in this instance means all other parameters match. "a" would have the value as was passed to new earlier.
Here's a simple example:
Placement delete may not be in your local C++ compiler as yet. In compilers without this feature, memory will leak. Note also that you can't call overloaded operator delete directly via the operator syntax; you'd have to code it as a regular function call.
In addition to the language providing this general capability, the C++ standard library also provides a specific instance for void*:
These functions are defined to do nothing (though new returns its argument). Their purpose is to allow construction of an object at a specific address, which is often useful in embedded systems and other low-level applications:
Based on a fairly recent decision of the standards committee, this definition of placement new/delete for void* is reserved by the library, and cannot be replaced by the user (unlike the normal global operator new, which can be). The library also defines a similar placement new/delete for allocating arrays at a specific address.
class A
{
public:
A();
~A();
};
A *p = new A;
...
delete p;
allocates storage for an A object and arranges for its constructor to be called, later followed by invocation of the destructor and freeing of the storage. You can use the standard new/delete functions in the library, or define your own globally and/or on a per-class basis.
There's a variation on new/delete worth mentioning. It's possible to supply additional parameters to a new call, for example:
A *p = new (a, b) A;
where a and b are arbitrary expressions; this is known as "placement new". For example, suppose that you have an object instance of a specialized class named Alloc that you want to pass to the new operator, so that new can control allocation according to the state of this object (that is, a specialized storage allocator):
class Alloc {/* stuff */};
Alloc allocator;
...
class A {/* stuff */};
...
A *p = new (allocator) A;
If you do this, then you need to define your own new function, like this:
void* operator new(size_t s, Alloc& a)
{
// stuff
}
The first parameter is always of type "size_t" (typically unsigned int), and any additional parameters are then listed. In this example, the "a" instance of Alloc might be examined to determine what strategy to use to allocate space. A similar approach can be used for operator new[] used for arrays.
This feature has been around for a while. A relatively new feature that goes along with it is placement delete. If during object initialization as part of a placement new call, for example during constructor invocation on a class object instance, an exception is thrown, then a matching placement delete call is made, with the same arguments and values as to placement new. In the example above, a matching function would be:
void operator delete(void *p, Alloc &a)
{
// stuff
}
With new, the first parameter is always "size_t", and with delete, always "void*". So "matching" in this instance means all other parameters match. "a" would have the value as was passed to new earlier.
Here's a simple example:
int flag = 0;
typedef unsigned int size_t;
void operator delete(void *p, int i)
{
flag = 1;
}
void* operator new(size_t s, int i)
{
return new char[s];
}
class A
{
public:
A() {throw -37;}
};
int main()
{
try
{
A *p = new (1234) A;
}
catch (int i)
{
}
if (flag == 0)
return 1;
else
return 0;
}
Placement delete may not be in your local C++ compiler as yet. In compilers without this feature, memory will leak. Note also that you can't call overloaded operator delete directly via the operator syntax; you'd have to code it as a regular function call.
In addition to the language providing this general capability, the C++ standard library also provides a specific instance for void*:
void* operator new(size_t, void*);
void operator delete(void*, void*);
These are accessed by saying:
#include
These functions are defined to do nothing (though new returns its argument). Their purpose is to allow construction of an object at a specific address, which is often useful in embedded systems and other low-level applications:
const unsigned long MEMORY_MAP_IO_AREA = 0xf008;
...
Some_Class* p = new ((void*) MEMORY_MAP_IO_AREA) Some_Class();
Based on a fairly recent decision of the standards committee, this definition of placement new/delete for void* is reserved by the library, and cannot be replaced by the user (unlike the normal global operator new, which can be). The library also defines a similar placement new/delete for allocating arrays at a specific address.
Saturday, May 9, 2009
Useful one-line scripts for SED(Unix Stream EDitor)
Most of these commands take file name as input and result is displayed on the screen.
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
# triple space a file
sed 'G;G'
# undo double-spacing (assumes even-numbered lines are always blank)
sed 'n;d'
# insert a blank line above every line which matches "regex"
sed '/regex/{x;p;x;}'
# insert a blank line below every line which matches "regex"
sed '/regex/G'
# insert a blank line above and below every line which matches "regex"
sed '/regex/{x;p;x;G;}'
NUMBERING:
# number each line of a file (simple left alignment). Using a tab (see
# note on '\t' at end of file) instead of space will preserve margins.
sed = filename | sed 'N;s/\n/\t/'
# number each line of a file (number on left, right-aligned)
sed = filename | sed 'N; s/^/ /; s/ *\(.\{6,\}\)\n/\1 /'
# number each line of file, but only print numbers if line is not blank
sed '/./=' filename | sed '/./N; s/\n/ /'
# count lines (emulates "wc -l")
sed -n '$='
TEXT CONVERSION AND SUBSTITUTION:
# IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format.
sed 's/.$//' # assumes that all lines end with CR/LF
sed 's/^M$//' # in bash/tcsh, press Ctrl-V then Ctrl-M
sed 's/\x0D$//' # works on ssed, gsed 3.02.80 or higher
# IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format.
sed "s/$/`echo -e \\\r`/" # command line under ksh
sed 's/$'"/`echo \\\r`/" # command line under bash
sed "s/$/`echo \\\r`/" # command line under zsh
sed 's/$/\r/' # gsed 3.02.80 or higher
# IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format.
sed "s/$//" # method 1
sed -n p # method 2
# IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format.
# Can only be done with UnxUtils sed, version 4.0.7 or higher. The
# UnxUtils version can be identified by the custom "--text" switch
# which appears when you use the "--help" switch. Otherwise, changing
# DOS newlines to Unix newlines cannot be done with sed in a DOS
# environment. Use "tr" instead.
sed "s/\r//" infile >outfile # UnxUtils sed v4.0.7 or higher
tr -d \r
# delete leading whitespace (spaces, tabs) from front of each line
# aligns all text flush left
sed 's/^[ \t]*//' # see note on '\t' at end of file
# delete trailing whitespace (spaces, tabs) from end of each line
sed 's/[ \t]*$//' # see note on '\t' at end of file
# delete BOTH leading and trailing whitespace from each line
sed 's/^[ \t]*//;s/[ \t]*$//'
# insert 5 blank spaces at beginning of each line (make page offset)
sed 's/^/ /'
# align all text flush right on a 79-column width
sed -e :a -e 's/^.\{1,78\}$/ &/;ta' # set at 78 plus 1 space
# center all text in the middle of 79-column width. In method 1,
# spaces at the beginning of the line are significant, and trailing
# spaces are appended at the end of the line. In method 2, spaces at
# the beginning of the line are discarded in centering the line, and
# no trailing spaces appear at the end of lines.
sed -e :a -e 's/^.\{1,77\}$/ & /;ta' # method 1
sed -e :a -e 's/^.\{1,77\}$/ &/;ta' -e 's/\( *\)\1/\1/' # method 2
# substitute (find and replace) "foo" with "bar" on each line
sed 's/foo/bar/' # replaces only 1st instance in a line
sed 's/foo/bar/4' # replaces only 4th instance in a line
sed 's/foo/bar/g' # replaces ALL instances in a line
sed 's/\(.*\)foo\(.*foo\)/\1bar\2/' # replace the next-to-last case
sed 's/\(.*\)foo/\1bar/' # replace only the last case
# substitute "foo" with "bar" ONLY for lines which contain "baz"
sed '/baz/s/foo/bar/g'
# substitute "foo" with "bar" EXCEPT for lines which contain "baz"
sed '/baz/!s/foo/bar/g'
# change "scarlet" or "ruby" or "puce" to "red"
sed 's/scarlet/red/g;s/ruby/red/g;s/puce/red/g' # most seds
gsed 's/scarlet\|ruby\|puce/red/g' # GNU sed only
# reverse order of lines (emulates "tac")
# bug/feature in HHsed v1.5 causes blank lines to be deleted
sed '1!G;h;$!d' # method 1
sed -n '1!G;h;$p' # method 2
# reverse each character on the line (emulates "rev")
sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'
# join pairs of lines side-by-side (like "paste")
sed '$!N;s/\n/ /'
# if a line ends with a backslash, append the next line to it
sed -e :a -e '/\\$/N; s/\\\n//; ta'
# if a line begins with an equal sign, append it to the previous line
# and replace the "=" with a single space
sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D'
# add commas to numeric strings, changing "1234567" to "1,234,567"
gsed ':a;s/\B[0-9]\{3\}\>/,&/;ta' # GNU sed
sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' # other seds
# add commas to numbers with decimal points and minus signs (GNU sed)
gsed -r ':a;s/(^|[^0-9.])([0-9]+)([0-9]{3})/\1\2,\3/g;ta'
# add a blank line every 5 lines (after lines 5, 10, 15, 20, etc.)
gsed '0~5G' # GNU sed only
sed 'n;n;n;n;G;' # other seds
SELECTIVE PRINTING OF CERTAIN LINES:
# print first 10 lines of file (emulates behavior of "head")
sed 10q
# print first line of file (emulates "head -1")
sed q
# print the last 10 lines of a file (emulates "tail")
sed -e :a -e '$q;N;11,$D;ba'
# print the last 2 lines of a file (emulates "tail -2")
sed '$!N;$!D'
# print the last line of a file (emulates "tail -1")
sed '$!d' # method 1
sed -n '$p' # method 2
# print the next-to-the-last line of a file
sed -e '$!{h;d;}' -e x # for 1-line files, print blank line
sed -e '1{$q;}' -e '$!{h;d;}' -e x # for 1-line files, print the line
sed -e '1{$d;}' -e '$!{h;d;}' -e x # for 1-line files, print nothing
# print only lines which match regular expression (emulates "grep")
sed -n '/regexp/p' # method 1
sed '/regexp/!d' # method 2
# print only lines which do NOT match regexp (emulates "grep -v")
sed -n '/regexp/!p' # method 1, corresponds to above
sed '/regexp/d' # method 2, simpler syntax
# print the line immediately before a regexp, but not the line
# containing the regexp
sed -n '/regexp/{g;1!p;};h'
# print the line immediately after a regexp, but not the line
# containing the regexp
sed -n '/regexp/{n;p;}'
# print 1 line of context before and after regexp, with line number
# indicating where the regexp occurred (similar to "grep -A1 -B1")
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
# grep for AAA and BBB and CCC (in any order)
sed '/AAA/!d; /BBB/!d; /CCC/!d'
# grep for AAA and BBB and CCC (in that order)
sed '/AAA.*BBB.*CCC/!d'
# grep for AAA or BBB or CCC (emulates "egrep")
sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d # most seds
gsed '/AAA\|BBB\|CCC/!d' # GNU sed only
# print paragraph if it contains AAA (blank lines separate paragraphs)
# HHsed v1.5 must insert a 'G;' after 'x;' in the next 3 scripts below
sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;'
# print paragraph if it contains AAA and BBB and CCC (in any order)
sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;/BBB/!d;/CCC/!d'
# print paragraph if it contains AAA or BBB or CCC
sed -e '/./{H;$!d;}' -e 'x;/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d
gsed '/./{H;$!d;};x;/AAA\|BBB\|CCC/b;d' # GNU sed only
# print only lines of 65 characters or longer
sed -n '/^.\{65\}/p'
# print only lines of less than 65 characters
sed -n '/^.\{65\}/!p' # method 1, corresponds to above
sed '/^.\{65\}/d' # method 2, simpler syntax
# print section of file from regular expression to end of file
sed -n '/regexp/,$p'
# print section of file based on line numbers (lines 8-12, inclusive)
sed -n '8,12p' # method 1
sed '8,12!d' # method 2
# print line number 52
sed -n '52p' # method 1
sed '52!d' # method 2
sed '52q;d' # method 3, efficient on large files
# beginning at line 3, print every 7th line
gsed -n '3~7p' # GNU sed only
sed -n '3,${p;n;n;n;n;n;n;}' # other seds
# print section of file between two regular expressions (inclusive)
sed -n '/Iowa/,/Montana/p' # case sensitive
SELECTIVE DELETION OF CERTAIN LINES:
# print all of file EXCEPT section between 2 regular expressions
sed '/Iowa/,/Montana/d'
# delete duplicate, consecutive lines from a file (emulates "uniq").
# First line in a set of duplicate lines is kept, rest are deleted.
sed '$!N; /^\(.*\)\n\1$/!P; D'
# delete duplicate, nonconsecutive lines from a file. Beware not to
# overflow the buffer size of the hold space, or else use GNU sed.
sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P'
# delete all lines except duplicate lines (emulates "uniq -d").
sed '$!N; s/^\(.*\)\n\1$/\1/; t; D'
# delete the first 10 lines of a file
sed '1,10d'
# delete the last line of a file
sed '$d'
# delete the last 2 lines of a file
sed 'N;$!P;$!D;$d'
# delete the last 10 lines of a file
sed -e :a -e '$d;N;2,10ba' -e 'P;D' # method 1
sed -n -e :a -e '1,10!{P;N;D;};N;ba' # method 2
# delete every 8th line
gsed '0~8d' # GNU sed only
sed 'n;n;n;n;n;n;n;d;' # other seds
# delete lines matching pattern
sed '/pattern/d'
# delete ALL blank lines from a file (same as "grep '.' ")
sed '/^$/d' # method 1
sed '/./!d' # method 2
# delete all CONSECUTIVE blank lines from file except the first; also
# deletes all blank lines from top and end of file (emulates "cat -s")
sed '/./,/^$/!d' # method 1, allows 0 blanks at top, 1 at EOF
sed '/^$/N;/\n$/D' # method 2, allows 1 blank at top, 0 at EOF
# delete all CONSECUTIVE blank lines from file except the first 2:
sed '/^$/N;/\n$/N;//D'
# delete all leading blank lines at top of file
sed '/./,$!d'
# delete all trailing blank lines at end of file
sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' # works on all seds
sed -e :a -e '/^\n*$/N;/\n$/ba' # ditto, except for gsed 3.02.*
# delete the last line of each paragraph
sed -n '/^$/{p;h;};/./{x;/./p;}'
SPECIAL APPLICATIONS:
# remove nroff overstrikes (char, backspace) from man pages. The 'echo'
# command may need an -e switch if you use Unix System V or bash shell.
sed "s/.`echo \\\b`//g" # double quotes required for Unix environment
sed 's/.^H//g' # in bash/tcsh, press Ctrl-V and then Ctrl-H
sed 's/.\x08//g' # hex expression for sed 1.5, GNU sed, ssed
# get Usenet/e-mail message header
sed '/^$/q' # deletes everything after first blank line
# get Usenet/e-mail message body
sed '1,/^$/d' # deletes everything up to first blank line
# get Subject header, but remove initial "Subject: " portion
sed '/^Subject: */!d; s///;q'
# get return address header
sed '/^Reply-To:/q; /^From:/h; /./d;g;q'
# parse out the address proper. Pulls out the e-mail address by itself
# from the 1-line return address header (see preceding script)
sed 's/ *(.*)//; s/>.*//; s/.*[:<] *//'
# add a leading angle bracket and space to each line (quote a message)
sed 's/^/> /'
# delete leading angle bracket & space from each line (unquote a message)
sed 's/^> //'
# remove most HTML tags (accommodates multiple-line tags)
sed -e :a -e 's/<[^>]*>//g;/
# extract multi-part uuencoded binaries, removing extraneous header
# info, so that only the uuencoded portion remains. Files passed to
# sed must be passed in the proper order. Version 1 can be entered
# from the command line; version 2 can be made into an executable
# Unix shell script. (Modified from a script by Rahul Dhesi.)
sed '/^end/,/^begin/d' file1 file2 ... fileX | uudecode # vers. 1
sed '/^end/,/^begin/d' "$@" | uudecode # vers. 2
# sort paragraphs of file alphabetically. Paragraphs are separated by blank
# lines. GNU sed uses \v for vertical tab, or any unique char will do.
sed '/./{H;d;};x;s/\n/={NL}=/g' file | sort | sed '1s/={NL}=//;s/={NL}=/\n/g'
gsed '/./{H;d};x;y/\n/\v/' file | sort | sed '1s/\v//;y/\v/\n/'
# zip up each .TXT file individually, deleting the source file and
# setting the name of each .ZIP file to the basename of the .TXT file
# (under DOS: the "dir /b" switch returns bare filenames in all caps).
echo @echo off >zipup.bat
dir /b *.txt | sed "s/^\(.*\)\.TXT/pkzip -mo \1 \1.TXT/" >>zipup.bat
TYPICAL USE: Sed takes one or more editing commands and applies all of
them, in sequence, to each line of input. After all the commands have
been applied to the first input line, that line is output and a second
input line is taken for processing, and the cycle repeats. The
preceding examples assume that input comes from the standard input
device (i.e, the console, normally this will be piped input). One or
more filenames can be appended to the command line if the input does
not come from stdin. Output is sent to stdout (the screen). Thus:
cat filename | sed '10q' # uses piped input
sed '10q' filename # same effect, avoids a useless "cat"
sed '10q' filename > newfile # redirects output to disk
For additional syntax instructions, including the way to apply editing
commands from a disk file instead of the command line, consult "sed &
awk, 2nd Edition," by Dale Dougherty and Arnold Robbins (O'Reilly,
1997; http://www.ora.com), "UNIX Text Processing," by Dale Dougherty
and Tim O'Reilly (Hayden Books, 1987) or the tutorials by Mike Arst
distributed in U-SEDIT2.ZIP (many sites). To fully exploit the power
of sed, one must understand "regular expressions." For this, see
"Mastering Regular Expressions" by Jeffrey Friedl (O'Reilly, 1997).
The manual ("man") pages on Unix systems may be helpful (try "man
sed", "man regexp", or the subsection on regular expressions in "man
ed"), but man pages are notoriously difficult. They are not written to
teach sed use or regexps to first-time users, but as a reference text
for those already acquainted with these tools.
QUOTING SYNTAX: The preceding examples use single quotes ('...')
instead of double quotes ("...") to enclose editing commands, since
sed is typically used on a Unix platform. Single quotes prevent the
Unix shell from intrepreting the dollar sign ($) and backquotes
(`...`), which are expanded by the shell if they are enclosed in
double quotes. Users of the "csh" shell and derivatives will also need
to quote the exclamation mark (!) with the backslash (i.e., \!) to
properly run the examples listed above, even within single quotes.
Versions of sed written for DOS invariably require double quotes
("...") instead of single quotes to enclose editing commands.
USE OF '\t' IN SED SCRIPTS: For clarity in documentation, we have used
the expression '\t' to indicate a tab character (0x09) in the scripts.
However, most versions of sed do not recognize the '\t' abbreviation,
so when typing these scripts from the command line, you should press
the TAB key instead. '\t' is supported as a regular expression
metacharacter in awk, perl, and HHsed, sedmod, and GNU sed v3.02.80.
VERSIONS OF SED: Versions of sed do differ, and some slight syntax
variation is to be expected. In particular, most do not support the
use of labels (:name) or branch instructions (b,t) within editing
commands, except at the end of those commands. We have used the syntax
which will be portable to most users of sed, even though the popular
GNU versions of sed allow a more succinct syntax. When the reader sees
a fairly long command such as this:
sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d
it is heartening to know that GNU sed will let you reduce it to:
sed '/AAA/b;/BBB/b;/CCC/b;d' # or even
sed '/AAA\|BBB\|CCC/b;d'
In addition, remember that while many versions of sed accept a command
like "/one/ s/RE1/RE2/", some do NOT allow "/one/! s/RE1/RE2/", which
contains space before the 's'. Omit the space when typing the command.
OPTIMIZING FOR SPEED: If execution speed needs to be increased (due to
large input files or slow processors or hard disks), substitution will
be executed more quickly if the "find" expression is specified before
giving the "s/.../.../" instruction. Thus:
sed 's/foo/bar/g' filename # standard replace command
sed '/foo/ s/foo/bar/g' filename # executes more quickly
sed '/foo/ s//bar/g' filename # shorthand sed syntax
On line selection or deletion in which you only need to output lines
from the first part of the file, a "quit" command (q) in the script
will drastically reduce processing time for large files. Thus:
sed -n '45,50p' filename # print line nos. 45-50 of a file
sed -n '51q;45,50p' filename # same, but executes much faster
References:
http://sed.sourceforge.net/sed1line.txt
Friday, January 23, 2009
New Techonogies coming in 2009
OLED
Short for organic light-emitting diode, this Kodak-developed display technology is being touted as the next big thing from the likes of Panasonic, LG, and more. If the term sounds familiar, that's because it's not a new technology — cell phones and MP3 players have been using OLED screens for several years. However, those screens were small and often only a single color display; new uses for OLEDs will be for products like smartphones, digital photo frames, and HDTVs.
Unlike LCDs, OLED displays emit light organically and do not require a backlight to function. As a result, they're significantly thinner, lighter, and more energy efficient than LCDs, with noticeably brighter colors. Sony's OLED TVs are already out on the market; larger models are expected to roll out later this year. However, because OLEDs are still niche, expect to pay a major premium on products that use OLEDs.
LED backlight
Unlike LCD displays with Cold Cathode Fluorescent Lamps (CCFL) backlighting, LCDs with light-emitting diodes (LEDs) allow for darker black levels and a wider range of colors along with better contrasts. However, not all LED-backlit LCDs are made the same. Samsung uses two styles of LED. First there's "full frame" LED sets, which evenly distribute white LEDs across an LCD's panel. The LEDs can be controlled independently, which lets some parts of the screen go very dark, while others remain bright. (This is called "local dimming.") As a result, you'll see brighter bright colors and darker blacks. Thinner LCDs use an "edge-lit" structure wherein the LEDs are placed only around the perimeter of the display. However, this layout prevents local dimming so the contrast ratio might not be as high as it is on the "full frame" LED sets. The trade off is that edge-lit LED-based TVs are the thinnest LCDs you'll find.
Sony, LG, and Sharp, on the other hand, are using RGB LED-backlit TVs (also known as Triluminous LED.) RGB LED LCDs use red, green, and blue LEDs to improve color purity in conjunction with local dimming. (Traditionally, only white LEDs are used.) Theoretically, this technology provides the best of both worlds, although you can expect to pay a high premium for it.
MIDs
Smaller than both netbooks and laptops, Mobile Internet Devices (MIDs) are handheld computers designed for multimedia and wireless connectivity. They're based on Intel's Centrino Atom processor and will feature either built-in keyboards or touch screen displays. Although they appear closely related to Ultra Mobile PCs (UMPCs), they're actually smaller and run Linux, Windows XP, or even Windows Mobile, as we saw with Mio's MID prototype. Screen sizes on MIDs will vary (there are no set standards yet), but at CES 7" to 9" appeared to be the sweet spot. In addition to extended battery life, models are expected to include built-in GPS, HD support, and WiMax.
240Hz
Originally, all LCD HDTVs refreshed at 60Hz, or 60 frames per second. However, to reduce motion blur (the streaks and artifacts displayed during a fast-action sequence), many manufacturers created a new line of higher-end HDTVs with refresh rates of 120Hz. These new sets claimed to provide a better viewing experience than their 60Hz counterparts. Now that 120Hz sets are common, manufacturers are pushing LCDs with 240Hz refresh rates, which further improve motion resolution. LG has even created an LCD with a 480Hz refresh rate. While there is a visual difference between 120Hz and 240Hz, it's subtle and may not be worth the extra money. It's worth noting that each manufacturer refers to this technology differently: Sony Motionflow, Samsung Auto Motion Plus, Toshiba ClearFrame, Panasonic Motion Picture Plus, Sharp Fine Motion Enhanced, and LG TruMotion.
Quad HD
With a maximum resolution of 3840x2160, Quad HD is the next leap for HDTVs. The technology is also referred to as "4k x 2k." The TVs use a special version of the Cell processor to upscale content to Quad HD resolutions. Toshiba, which had a Quad HDTV at CES, expects to roll out these sets in Japan later this year. They're expected to hit the United States next year.
Netbooks
These miniature notebooks are a cheaper variant of the traditional laptop. Originally developed by ASUS, netbooks were made for simple tasks like accessing the Internet, e-mail, and word processing. With screen sizes that max out at 10", netbooks are generally under powered when compared to their larger counterparts. They lack an optical drive, carry fewer USB ports, and some models substitute a hard disk drive with a solid state drive. In addition, many run either Linux/Ubuntu or Windows XP. Most netbooks are built around Intel's Atom processor, which currently taps out at 1.6GHz. Currently, most manufacturers from Dell to Lenovo carry a netbook model in their lineup, although pricing ranges from just over $200 to $1,000 and more.
Intel Centrino Atom Processor
Last year, Intel introduced its 45nm Atom processor, the company's smallest CPU. Designed specifically for small devices with low power consumption, it reaches speeds of up to 1.6GHz with a 533MHz front-side bus. Like its brother, the Centrino Atom processor was designed for small devices with low power consumption. However, this CPU will be exclusively available for MIDs.
3D TV
Although the concept has been around for years, today's top TV manufacturers are revisiting 3D technology in the hopes of laying the groundwork for future HDTVs. Sony, Panasonic, Samsung, and RCA were among the top manufacturers displaying 3D-based HDTVs at CES. With the exception of RCA's Lenticular TV, most models require that the user wear 3D goggles. Unfortunately, there's no standardized format for 3D technology. In addition, various movie studios are making the push for 3D theaters and movies. Even NVIDIA has joined the 3D craze with its 3D Vision for GeForce, a home 3D kit designed for gamers which includes a pair of 3D glasses that work in tandem with new Samsung, ViewSonic, and Mitsubishi displays.
Internet-connected TVs
Practically every TV on the CES floor had some form of Internet connectivity, whether it was the ability to stream from Netflix or access to Yahoo's Widgets gallery. Each manufacturer has a different name for this feature and not all of the TVs can access the same content. Here are a few terms you will see in the very near future:
* Panasonic VIERA Cast IPTV: Access to Amazon VOD, Google, news, weather, and YouTube.
* Samsung Internet@TV: Access to Yahoo Widgets, YouTube, eBay, Twitter, and more.
* Toshiba TV Widgets: Access to Yahoo Widgets with news, sports, and stock updates. In addition, some models will integrate Extender for Windows Media Center, letting you access media stored on your Media Center PC.
* LG NetCast: Access to Yahoo Widgets, YouTube, Flickr, and Netflix.
* Sony Bravia Internet Video Link: Access to Amazon VOD, Dailymotion, YouTube, CBS, Yahoo, Sony Pictures' Crackle, FEARnet, Sports Illustrated, and more.
Energy Star 3.0 Certification
Practically every TV at CES met Energy Star's 3.0 certification, which means the newer models will be even more energy efficient than today's. This is particularly important for plasma TVs, which provide a better viewing experience than their LCD counterparts, but also use up more energy. New plasma TV sets with Energy Star's 3.0 certification will use as much as 50% less power than traditional sets.
tru2Way
This technology lets you receive programming from your cable company without having to rent a cable box. Unlike it's predecessor, CableCard, tru2Way supports Video On Demand and Pay Per View. Panasonic has been the first manufacturer to get tru2way TVs on the market with its VIERA TH-42PZ80Q and VIERA TH-50PZ80Q. Other companies supporting this technology include Sony, LG, Comcast, Time Warner Cable, and Cox Communications.
Short for organic light-emitting diode, this Kodak-developed display technology is being touted as the next big thing from the likes of Panasonic, LG, and more. If the term sounds familiar, that's because it's not a new technology — cell phones and MP3 players have been using OLED screens for several years. However, those screens were small and often only a single color display; new uses for OLEDs will be for products like smartphones, digital photo frames, and HDTVs.
Unlike LCDs, OLED displays emit light organically and do not require a backlight to function. As a result, they're significantly thinner, lighter, and more energy efficient than LCDs, with noticeably brighter colors. Sony's OLED TVs are already out on the market; larger models are expected to roll out later this year. However, because OLEDs are still niche, expect to pay a major premium on products that use OLEDs.
LED backlight
Unlike LCD displays with Cold Cathode Fluorescent Lamps (CCFL) backlighting, LCDs with light-emitting diodes (LEDs) allow for darker black levels and a wider range of colors along with better contrasts. However, not all LED-backlit LCDs are made the same. Samsung uses two styles of LED. First there's "full frame" LED sets, which evenly distribute white LEDs across an LCD's panel. The LEDs can be controlled independently, which lets some parts of the screen go very dark, while others remain bright. (This is called "local dimming.") As a result, you'll see brighter bright colors and darker blacks. Thinner LCDs use an "edge-lit" structure wherein the LEDs are placed only around the perimeter of the display. However, this layout prevents local dimming so the contrast ratio might not be as high as it is on the "full frame" LED sets. The trade off is that edge-lit LED-based TVs are the thinnest LCDs you'll find.
Sony, LG, and Sharp, on the other hand, are using RGB LED-backlit TVs (also known as Triluminous LED.) RGB LED LCDs use red, green, and blue LEDs to improve color purity in conjunction with local dimming. (Traditionally, only white LEDs are used.) Theoretically, this technology provides the best of both worlds, although you can expect to pay a high premium for it.
MIDs
Smaller than both netbooks and laptops, Mobile Internet Devices (MIDs) are handheld computers designed for multimedia and wireless connectivity. They're based on Intel's Centrino Atom processor and will feature either built-in keyboards or touch screen displays. Although they appear closely related to Ultra Mobile PCs (UMPCs), they're actually smaller and run Linux, Windows XP, or even Windows Mobile, as we saw with Mio's MID prototype. Screen sizes on MIDs will vary (there are no set standards yet), but at CES 7" to 9" appeared to be the sweet spot. In addition to extended battery life, models are expected to include built-in GPS, HD support, and WiMax.
240Hz
Originally, all LCD HDTVs refreshed at 60Hz, or 60 frames per second. However, to reduce motion blur (the streaks and artifacts displayed during a fast-action sequence), many manufacturers created a new line of higher-end HDTVs with refresh rates of 120Hz. These new sets claimed to provide a better viewing experience than their 60Hz counterparts. Now that 120Hz sets are common, manufacturers are pushing LCDs with 240Hz refresh rates, which further improve motion resolution. LG has even created an LCD with a 480Hz refresh rate. While there is a visual difference between 120Hz and 240Hz, it's subtle and may not be worth the extra money. It's worth noting that each manufacturer refers to this technology differently: Sony Motionflow, Samsung Auto Motion Plus, Toshiba ClearFrame, Panasonic Motion Picture Plus, Sharp Fine Motion Enhanced, and LG TruMotion.
Quad HD
With a maximum resolution of 3840x2160, Quad HD is the next leap for HDTVs. The technology is also referred to as "4k x 2k." The TVs use a special version of the Cell processor to upscale content to Quad HD resolutions. Toshiba, which had a Quad HDTV at CES, expects to roll out these sets in Japan later this year. They're expected to hit the United States next year.
Netbooks
These miniature notebooks are a cheaper variant of the traditional laptop. Originally developed by ASUS, netbooks were made for simple tasks like accessing the Internet, e-mail, and word processing. With screen sizes that max out at 10", netbooks are generally under powered when compared to their larger counterparts. They lack an optical drive, carry fewer USB ports, and some models substitute a hard disk drive with a solid state drive. In addition, many run either Linux/Ubuntu or Windows XP. Most netbooks are built around Intel's Atom processor, which currently taps out at 1.6GHz. Currently, most manufacturers from Dell to Lenovo carry a netbook model in their lineup, although pricing ranges from just over $200 to $1,000 and more.
Intel Centrino Atom Processor
Last year, Intel introduced its 45nm Atom processor, the company's smallest CPU. Designed specifically for small devices with low power consumption, it reaches speeds of up to 1.6GHz with a 533MHz front-side bus. Like its brother, the Centrino Atom processor was designed for small devices with low power consumption. However, this CPU will be exclusively available for MIDs.
3D TV
Although the concept has been around for years, today's top TV manufacturers are revisiting 3D technology in the hopes of laying the groundwork for future HDTVs. Sony, Panasonic, Samsung, and RCA were among the top manufacturers displaying 3D-based HDTVs at CES. With the exception of RCA's Lenticular TV, most models require that the user wear 3D goggles. Unfortunately, there's no standardized format for 3D technology. In addition, various movie studios are making the push for 3D theaters and movies. Even NVIDIA has joined the 3D craze with its 3D Vision for GeForce, a home 3D kit designed for gamers which includes a pair of 3D glasses that work in tandem with new Samsung, ViewSonic, and Mitsubishi displays.
Internet-connected TVs
Practically every TV on the CES floor had some form of Internet connectivity, whether it was the ability to stream from Netflix or access to Yahoo's Widgets gallery. Each manufacturer has a different name for this feature and not all of the TVs can access the same content. Here are a few terms you will see in the very near future:
* Panasonic VIERA Cast IPTV: Access to Amazon VOD, Google, news, weather, and YouTube.
* Samsung Internet@TV: Access to Yahoo Widgets, YouTube, eBay, Twitter, and more.
* Toshiba TV Widgets: Access to Yahoo Widgets with news, sports, and stock updates. In addition, some models will integrate Extender for Windows Media Center, letting you access media stored on your Media Center PC.
* LG NetCast: Access to Yahoo Widgets, YouTube, Flickr, and Netflix.
* Sony Bravia Internet Video Link: Access to Amazon VOD, Dailymotion, YouTube, CBS, Yahoo, Sony Pictures' Crackle, FEARnet, Sports Illustrated, and more.
Energy Star 3.0 Certification
Practically every TV at CES met Energy Star's 3.0 certification, which means the newer models will be even more energy efficient than today's. This is particularly important for plasma TVs, which provide a better viewing experience than their LCD counterparts, but also use up more energy. New plasma TV sets with Energy Star's 3.0 certification will use as much as 50% less power than traditional sets.
tru2Way
This technology lets you receive programming from your cable company without having to rent a cable box. Unlike it's predecessor, CableCard, tru2Way supports Video On Demand and Pay Per View. Panasonic has been the first manufacturer to get tru2way TVs on the market with its VIERA TH-42PZ80Q and VIERA TH-50PZ80Q. Other companies supporting this technology include Sony, LG, Comcast, Time Warner Cable, and Cox Communications.
Subscribe to:
Posts (Atom)