Wednesday, March 27, 2013

Oracle inline view and global temporary table

Tom indicates that global temporary table is not used to improve the performance, it can only be used to use as the interface table. While in the real case, it's not true. Insert into two dates data into GTT and then calculate based on the GTT only needs 5 seconds. Inline view option needs 299 seconds.

Sunday, March 24, 2013

English vocabulary

Nerd / Nerd life satisfaction
Otaku

Wednesday, March 20, 2013

Friday, March 15, 2013

Netflix WildChina

Netflix Wild China
beautiful

欲购图书

随遇而安
去,你的旅行
贝贝熊系列丛书(英汉对照)(共30册)
折纸大全(欧洲折纸协会推荐最佳折纸用书)
五天学会绘画(苹果、IBM、迪斯尼等500强企业创造力培训用书第22版,送专业绘画笔+练习挂图+显像板)

Thursday, March 14, 2013

American English Pronunciation 2


node
nancy
pad
jaw
two
eight
nine
math
tooth
mouth
through
beyond
think
with
I will eat anything healthy with my teeth
back
forth
month
Thank you for driving back & forth this month.
I think Beth is traveling north on the path.
this
good

get files through ftp


ftp site
epsv  --to disable Extended Passive Mode
prompt --to disable interactive mode
ascii
mget *.csv --to get multiple files

Monday, March 11, 2013

American English Prounciation


vowel
heat
hit
chip
gin
reach
steal/still
bathe
thing
telephone
radar
soap
knob
ballon
week (ruan'e)
hour
about/down/town/downtown/ground/

aunt
favorite
his
him
pround

Friday, March 8, 2013

Pronounication


money
banana
car
pork
law
year
down
town
downtown
bite
noun
phonetic

AutoIt and AutoHotKey


AutoIt strength:
1. AutoIt Window Info
much powerful than AutoHotKey's Spy
2. Embedded Editor
3. Better unicode support
4. Log
No ClipWait, tool
AutoHotKey:
1. Smaller than AutoIt
2. View and check the script from the tray icon
3. Many useful tools set

Thursday, March 7, 2013

Cleaning up a schema in Oracle


It's very useful, even for the partition table and partition index.
After purge recyclebin, the partition binXXXX would go away.

BEGIN
  FOR cur_rec IN
  (SELECT table_name,
    constraint_name
  FROM user_constraints
  WHERE constraint_type = 'R'
  )
  LOOP
    EXECUTE IMMEDIATE 'ALTER TABLE ' || cur_rec.table_name || ' DROP CONSTRAINT ' || cur_rec.constraint_name;
  END LOOP;
  FOR cur_rec IN
  (SELECT object_name, object_type FROM user_objects
  )
  LOOP
    BEGIN
      IF cur_rec.object_type != 'DATABASE LINK' THEN
        EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' ' || cur_rec.object_name;
        EXECUTE immediate 'purge recyclebin';
      END IF;
    EXCEPTION
    WHEN OTHERS THEN
      NULL;
    END;
  END LOOP;
END;
/

From http://ahsan-javed.blogspot.ca/2008/07/cleaning-up-schema-in-oracle.html

Friday, March 1, 2013

Olive
Snail
Fail
Feel
File

Java concurrency in practice


Benefits of Threads
Threads are useful in GUI applications for improving the responsiveness of the user interface, and in server applications for improving resource utilization and throughput.
Because threads share the same memory address space and run concurrently, they can access or modify variables that other threads might be using. This is a tremendous convenience, because it makes data sharing much easier than would other inter-thread communications mechanisms. But it is also a significant risk: threads can be confused by having data change unexpectedly.
UnsafeSequence illustrates a common concurrency hazard called a race condition.
@NotThreadSafe
public class UnsafeSequence {
    private int value;

    /** Returns a unique value. */
    public int getNext() {
        return value++;
    }
}

Writing thread-safe code is, at its core, about managing access to state, and in particular to shared, mutable state.
Whether an object needs to be thread-safe depends on whether it will be accessed from multiple threads. This is a property of how the object is used in a program, not what it does. Making an object thread-safe requires using synchronization to coordinate access to its mutable state; failing to do so could result in data corruption and other undesirable consequences.
Whenever more than one thread accesses a given state variable, and one of them might write to it, they all must coordinate their access to it using synchronization.
If multiple threads access the same mutable state variable without appropriate synchronization, your program is broken. There are three ways to fix it:
Don't share the state variable across threads;
Make the state variable immutable; or
Use synchronization whenever accessing the state variable.

a class is thread-safe when it continues to behave correctly when accessed from multiple threads. with no additional synchronization or other coordination on the part of the calling code.
Thread-safe classes encapsulate any needed synchronization so that clients need not provide their own.
Since the actions of a thread accessing a stateless object cannot affect the correctness of operations in other threads, stateless objects are thread-safe.
A race condition occurs when the correctness of a computation depends on the relative timing or interleaving of multiple threads by the runtime; in other words, when getting the right answer relies on lucky timing. [4] The most common type of race condition is check-then-act, where a potentially stale observation is used to make a decision on what to do next.
LazyInitRace has race conditions that can undermine its correctness.

A synchronized block has two parts: a reference to an object that will serve as the lock, and a block of code to be guarded by that lock. A synchronized method is a shorthand for a synchronized block that spans an entire method body, and whose lock is the object on which the method is being invoked. (Static synchronized methods use the Class object for the lock.)

Reentrancy means that locks are acquired on a per-thread rather than per-invocation basis.the JVM records the owner and sets the acquisition count to one. If that same thread acquires the lock again, the count is incremented, and when the owning thread exits the synchronized block, the count is decremented. When the count reaches zero, the lock is released.

For each mutable state variable that may be accessed by more than one thread, all accesses to that variable must be performed with the same lock held. In this case, we say that the variable is guarded by that lock.

The fact that every object has a built-in lock is just a convenience so that you needn't explicitly create lock objects.
Avoid holding locks during lengthy computations or operations at risk of not completing quickly such as network or console I/O.

In general, there is no guarantee that the reading thread will see a value written by another thread on a timely basis, or even at all. In order to ensure visibility of memory writes across threads, you must use synchronization. Unless synchronization is used every time a variable is accessed, it is possible to see a stale value for that variable.

The Java Memory Model requires fetch and store operations to be atomic, but for nonvolatile long and double variables, the JVM is permitted to treat a 64-bit read or write as two separate 32-bit operations. If the reads and writes occur in different threads, it is therefore possible to read a nonvolatile long and get back the high 32 bits of one value and the low 32 bits of another.[3] Thus, even if you don't care about stale values, it is not safe to use shared mutable long and double variables in multithreaded programs unless they are declared volatile or guarded by a lock.

When a field is declared volatile, the compiler and runtime are put on notice that this variable is shared and that operations on it should not be reordered with other memory operations. A read of a volatile variable always returns the most recent write by any thread.

Locking can guarantee both visibility and atomicity; volatile variables can only guarantee visibility.

There's nothing wrong with creating a thread in a constructor, but it is best not to start the thread immediately. Instead, expose a start or initialize method that starts the owned thread. Calling an overrideable instance method (one that is neither private nor final) from the constructor can also allow the this reference to escape.

Since JDBC connections may not be thread-safe, a multithreaded application that uses a global connection without additional coordination is not thread-safe either. By using a ThreadLocal to store the JDBC connection, each thread will have its own connection.

private static ThreadLocal<Connection> connectionHolder
    = new ThreadLocal<Connection>() {
        public Connection initialValue() {
            return DriverManager.getConnection(DB_URL);
        }
    };

public static Connection getConnection() {
    return connectionHolder.get();
}
If you are porting a single-threaded application to a multithreaded environment, you can preserve thread safety by converting shared global variables into ThreadLocals.


An object whose fields are all final may still be mutable, since final fields can hold references to mutable objects.

If the Date values are not modified after they are placed in the Map, then the synchronization in the synchronizedMap implementation is sufficient to publish the Date values safely, and no additional synchronization is needed when accessing them.
public Map<String, Date> lastLogin =
    Collections.synchronizedMap(new HashMap<String, Date>());

Collections.synchronizedXxx factory methods. These classes achieve thread safety by encapsulating their state and synchronizing every public method so that only one thread at a time can access the collection state.


Because it has so many advantages and so few disadvantages compared to Hashtable or synchronizedMap, replacing synchronized Map implementations with ConcurrentHashMap in most cases results only in better scalability. Only if your application needs to lock the map for exclusive access [3] is ConcurrentHashMap not an appropriate drop-in replacement.
CopyOnWriteArrayList is a concurrent replacement for a synchronized List that offers better concurrency in some common situations and eliminates the need to lock or copy the collection during iteration. (Similarly, CopyOnWriteArraySet is a concurrent replacement for a synchronized Set.)


































Learning Perl


If you’re looking for the best way to spend your first 30 to 45 hours with the Perl
programming language, you’ve found it.
Rather than copying by hand, however, we
encourage you to download the code from http://www.learning-perl.com.

Perl is easy to use, but sometimes hard to learn. Like any language, Perl can be “write-only”—it’s possible to write programs that are
impossible to read.
Most statements are an expression followed by a semicolon;

perl hello.pl

Like many other programming languages, Perl allows you to specify numbers in other
ways than base 10 (decimal). Octal (base 8) literals start with a leading 0, hexadecimal
(base 16) literals start with a leading 0x, and binary (base 2) literals start with a leading
0b.

If you want to use Unicode literally in your program, you need
to add the utf8 pragma:§
use utf8;

\x{2744} Any hex Unicode code point (here, U+2744 = snowflake)
\cC A “control” character (here, Ctrl-C)
\l Lowercase next letter
\L Lowercase all following letters until \E
\u Uppercase next letter
\U Uppercase all following letters until \E
\Q Quote nonword characters by adding a backslash until \E

"hello" . ' ' . "world" # same as 'hello world'
"barney" x (4+1) # is "barney" x 5, or "barneybarneybarneybarneybarney"

Trailing
nonnumber stuff and leading whitespace are discarded, so "12fred34" * " 3" will also
give 36 without any complaints.
At the extreme end of this, something that isn’t a
number at all converts to zero. This would happen if you used the string "fred" as a
number.

The trick of using a leading zero to mean an octal value works for literals, but never for
automatic conversion, which is always base-10:#
0377 # that's octal for 255 decimal
'0377' # that's 377 decimal

you can turn on warnings with a pragma
#!/usr/bin/perl
use warnings;
You can use the -w option on the command line, which turns on warnings everywhere
in your program:§
$ perl -w my_program

If you get a warning message you don’t understand, you can get a longer
description of the problem with the diagnostics pragma.
#!/usr/bin/perl
use diagnostics;

Scalar variable names begin
with a dollar sign

$str = $str . " "; # append a space to $str
$str .= " "; # same thing with assignment operator

You can give print a series of values, separated by commas:
print "The answer is ", 6 * 7, ".\n";

$fred = 'hello';
print "The name is \$fred.\n"; # prints a dollar sign

$alpha = chr( hex('03B1') );
$omega = chr( 0x03C9 );
You can go the other way with the ord() function, which turns a character into its code
point.
That might be more work than interpolating them directly by putting the hexadecimal
representation in \x{}:
"\x{03B1}\x{03C9}"

if ($name gt 'fred') {
print "'$name' comes after 'fred' in sorted order.\n";
} else {
print "'$name' does not come after 'fred'.\n";
print "Maybe it's the same string, in fact.\n";
}

$is_bigger = $name gt 'fred';
if ($is_bigger) { ... }

Perl doesn’t have a
separate Boolean datatype, like some languages have. Instead, it uses a few simple
rules:‡
• If the value is a number, 0 means false; all other numbers mean true.
• Otherwise, if the value is a string, the empty string ('') means false; all other strings
mean true.
• Otherwise (that is, if the value is another kind of scalar than a number or a string),
convert it to a number or a string and try again.§
the string
'0' is the only non-empty string that is false.

$line = <STDIN>;
if ($line eq "\n") {
print "That was just a blank line!\n";
} else {
print "That line of input was: $line";
}
But in practice, you don’t often want to keep the newline, so you need the chomp()
operator.

chomp($text = <STDIN>); # Read the text, without the newline character
$text = <STDIN>; # Do the same thing...
chomp($text); # ...but in two steps

you may write chomp() with or without the parentheses. This is another
general rule in Perl: except in cases where it changes the meaning to remove them,
parentheses are always optional..
If a line ends with two or more newlines,† chomp() removes only one. If there’s no
newline, it does nothing, and returns zero.

To tell whether a value is undef and not the empty string, use the
defined function, which returns false for undef, and true for everything else:
$madonna = <STDIN>;
if ( defined($madonna) ) {
print "The input was $madonna";
} else {
print "No input available!\n";
}

A list is an ordered collection of scalars. An array is a variable that contains a list. The list is the data
and the array is the variable that stores the data.

For the array of
rocks, the last element index is $#rocks
That’s not the same as the number of elements,
though, because there’s an element number zero

If you have three elements in
the array, the valid negative indices are –1 (the last element), –2 (the middle element),
and –3 (the first element).

a list may have any scalar values, like this typical list of strings:
("fred", "barney", "betty", "wilma", "dino")
The qw shortcut makes it easy to generate them without typing a lot
of extra quote marks:
qw( fred barney betty wilma dino ) # same as above, but less typing

In much the same way as you can assign scalar values to variables, you can assign list
values to variables:
($fred, $barney, $dino) = ("flintstone", "rubble", undef);

Just use the
at sign (@) before the name of the array (and no index brackets after it) to refer to the
entire array at once. You can read this as “all of the,” so @rocks is “all of the rocks.”

When an array is copied to another array, it’s still a list assignment. The lists are simply
stored in arrays. For example:
@copy = @quarry; # copy a list from one array to another

The pop operator takes the last element off of an array and returns it:
@array = 5..9;
$fred = pop(@array); # $fred gets 9, @array now has (5, 6, 7, 8)
$barney = pop @array; # $barney gets 8, @array now has (5, 6, 7)
pop @array; # @array now has (5, 6). (The 7 is discarded.)

push @array, 8; # @array now has (5, 6, 0, 8)
push @array, 1..10; # @array now has those 10 new elements

Similarly, the unshift and shift operators perform the corresponding actions on
the “start” of the array

The push-pop and shift-unshift operators work with the ends of the array, but what if
you need to remove or add elements to the middle? That’s where the splice operator
comes in. It takes up to four arguments, two of which are optional. The first argument
is always the array and the second argument is the position where you want to start. If
you only use those two arguments, Perl removes all of the elements from your starting
position to the end and returns them to you

$email = "fred@bedrock.edu"; # WRONG! Tries to interpolate @bedrock
$email = "fred\@bedrock.edu"; # Correct
$email = 'fred@bedrock.edu'; # Another way to do that

foreach (1..10) { # Uses $_ by default
print "I can count to $_!\n";
}

reverse @fred; # WRONG - doesn't change @fred
@fred = reverse @fred; # that's better

@numbers = sort 97..102; # gets 100, 101, 102, 97, 98, 99

Scalar and List Context
@people = qw( fred barney betty );
@sorted = sort @people; # list context: barney, betty, fred
$number = 42 + @people; # scalar context: 42 + 3 gives 45
Even ordinary assignment (to a scalar or a list) causes different contexts:
@list = @people; # a list of three people
$n = @people; # the number 3

@backwards = reverse qw/ yabba dabba doo /;
# gives doo, dabba, yabba
$backwards = reverse qw/ yabba dabba doo /;
# gives oodabbadabbay

@betty = ( ); # A correct way to empty an array