erasure not reified

erasure not reified

1   public class T {

2       public static void main(String[] args) throws Exception {

3           A<String,B> a = new A<String,B>();

4           B b = a.get("hello");

5       }


7       static class B {}


9       static class A<K,V> {

10          V get(K k) {

11              Object obj = get_object_for(k);

12              V v = (V)obj;

13              return v;

14          }

15          Object get_object_for(K k) {

16              return flipcoin() ? new Object() : new B();

17          }


19          boolean flipcoin() {

20              return (Math.random()*10)%2 < 1;

21          }

22      }

23  }

This will fail at line number 4 whenever flipcoin returns true, (and one would

hope it to fail at line number 12 so at least we can catch ClassCastException

and handle it), what if I want to check in A.get if object retured from

get_object_for is an instanceof B or not and handle accordingly but

I can’t do that due to generic type erasure might have worked if it were reified.



    C-x   Ctrl+x
    M-x   Alt+x
    C-M-x Ctrl+Alt+x
    SPC   Spac
    ESC   escape or C-[

  Used for commands that are specific to particular modes, so they are free
  to be used for different commands depending on context. These are the
  most variable of Emacs commands.

  Used for Help commands.

  This prefix is used mostly for commands that manipulate files, buffers and windows.

Files, Buffers and Windows

  A file is the actual Unix file on disk. You are never editing this file.
  Rather, you can read a copy into Emacs to initialize a buffer, and
  write a copy of a buffer out to a file to save it.

  A buffer is the internal data structure that holds the text you
  actually edit. Emacs can have any number of buffers active at any
  moment. Most, but by no means all, buffers are associated with a file.
  Buffers have names; a buffer that has been initialized from a file is
  almost always named for that file, and we say that the buffer is
  visiting the file. This means, in particular, that when you save the
  buffer, it's saved to the proper file. At any given time exactly one
  buffer is selected: this is the buffer that your hardware cursor is
  in, and this is where commands you type take effect (including
  self-insert commands). Buffers can be deleted at will; deleting a
  buffer in no way deletes the file on disk (though you may lose any
  editing changes you made if you don't save first).

  A window is your view of a buffer. Due to limited screen real-estate,
  you may not have room to view all your buffers at once. You can split
  the screen, horizontally or vertically, into as many windows as you
  like (or at least have room for), each viewing a different buffer.
  It's also possible to have several windows viewing different portions
  of the same buffer. Windows can be created and deleted at will;
  deleting a window in no way deletes the buffer associated with the
  window. Each window has its own Mode Line, but there's still only
  one minibuffer.

  A frame is like a window, but is treated as a separate entity under a
  windowing system like X. I won't be discussing frames.

Commands to Manipulate Files

C-x C-f
  find-file. This is the main command used to read a file into a
  buffer for editing. It's actually rather subtle. When you execute
  this command, it prompts you for the name of the file (with completion).
  Then it checks to see if you're already editing that file in some
  buffer; if you are, it simply switches to that buffer and doesn't
  actually read in the file from disk again. If you're not, a new
  buffer is created, named for the file, and initialized with a copy
  of the file. In either case the current window is switched to
  view this buffer.

C-x C-s
  save-buffer. This is the main command used to save a file, or, more
  accurately, to write a copy of the current buffer out to the disk,
  overwriting the buffer's file, and handling backup versions.

C-x s
  save-some-buffers. Allows you to save all your buffers that are
  visiting files, querying you for each one and offering several
  options for each (save it, don't save it, peek at it first then
  maybe save it, etc).

Commands to Manipulate Buffers

C-x b
  switch-to-buffer. Prompts for a buffer name and switches the buffer of the
  current window to that buffer. Doesn't change your window configuration.
  This command will also create a new empty buffer if you type a new name;
  this new buffer will not be visiting any file, no matter what you name it.

C-x C-b
  list-buffers. Pops up a new window which lists all your buffers, giving
  for each the name, modified or not, size in bytes, major mode and the
  file the buffer is visiting.

C-x k
  kill-buffer. Prompts for a buffer name and removes the entire data structure
  for that buffer from Emacs. If the buffer is modified you'll be given an
  opportunity to save it. Note that this in no way removes or deletes
  the associated file, if any.

C-x C-q
  vc-toggle-read-only. Make a buffer read-only (so that attempts to modify it
  are treated as errors), or make it read-write if it was read-only. Also,
  if the files is under version control, it will check the file out for you.

Commands to Manipulate Windows

  scroll-up. The basic command to scroll forward (towards the end of the file)
  one screenful. By default Emacs leaves you two lines of context from the
  previous screen.

  scroll-down. Just like C-v, but scrolls backwards.

C-x o
  other-window. Switch to another window, making it the active window.
  Repeated invocation of this command moves through all the windows,
  left to right and top to bottom, and then circles around again.
  Under a windowing system, you can use the left mouse button to switch windows.

C-x 1
  delete-other-windows. Deletes all other windows except the current one,
  making one window on the screen. Note that this in no way deletes the
  buffers or files associated with the deleted windows.

C-x 0
  delete-window. Deletes just the current window, resizing the others appropriately.

C-x 2
  split-window-vertically. Splits the current window in two, vertically. This
  creates a new window, but not a new buffer: the same buffer will now be
  viewed in the two windows. This allows you to view two different parts of the
  same buffer simultaneously.

C-x 3
  split-window-horizontally. Splits the current window in two, horizontally.
  This creates a new window, but not a new buffer: the same buffer will now be
  viewed in the two windows. This allows you to view two different parts of the
  same buffer simultaneously.

  scroll-other-window. Just like C-v, but scrolls the other window. If you
  have more than two windows, the other window is the window that C-x o
  would switch to.

The state of the buffer,
  one of modified (indicated by a pair of asterisks **),
  unmodified (hyphens --), or
  read-only (indicated by a pair of % signs)

The Minibuffer
  The blank line below the mode line is the minibuffer. The minibuffer is used
  by Emacs to display messages, and also for input when Emacs is prompting
  you to type something.

  keyboard-quit (like escape in normal editors)

C-h a
  command-apropos. Prompts for a keyword and then lists all the commands with
  that keyword in their long name.

C-h k
  describe-key. Prompts for a keystroke and describes the command bound to
  that key, if any.

C-h i
  info. Enters the Info hypertext documentation reader.

C-h m
  describe-mode. Describes the current major mode and its particular key bindings.

C-h p
  finder-by-keyword. Runs an interactive subject-oriented browser of Emacs packages.

C-h t
  help-with-tutorial. Run the Emacs tutorial. This is very helpful for beginners.

C-_ (control underbar)
C-x u

To invoke completion, you usually type TAB.
  Emacs offers various forms of completion:

To give a command a numeric argument of, say, 12, type C-u 12 before typing the command.

  Since one often isn't interested in precisely how many times a command is repeated,
  there's a shorthand way to get numeric arguments of varying magnitudes.
  C-u by itself, without any subsequent digits, is equal to a numeric argument of 4.
  Another C-u multiplies that by 4 more, giving a numeric argument of 16.
  Another C-u multiplies that by 4 more, giving a numeric argument of 64, etc.
  For this reason C-u is called the universal-argument.

  Sometimes one needs to insert control characters into a file. But how can you
  insert an ESC, say, when it's used as a prefix command? The answer is to use
  the command quoted-insert, which is bound to C-q. C-q acts like a prefix command,
  in that when you type it it waits for you to type another character. But this
  next character is then inserted into the buffer, rather than being executed as
  a command. So C-q ESC inserts an Escape.

  forward-char. Moves forward (to the right) over a character.

  backward-char. Moves backward (to the left) over a character.

  forward-word. Moves forward over a word.

  backward-word. Moves backward over a word.

  next-line. Moves down to the next line.

  previous-line. Moves up to the previous line.

  beginning-of-line. Moves to the beginning of the current line.

  end-of-line. Moves to the end of the current line.

  backward-sentence. Moves to the beginning of the current sentence.

  forward-sentence. Moves to the end of the current sentence.

C-x [
  backward-page. Moves to the beginning of the current page.

C-x ]
  forward-page. Moves to the end of the current page.

  end-of-buffer. Moves to the end of the buffer.

  backward-sexp. Moves backward over the next sexp. If your cursor is just
  to the right of a left paren, C-M-b will beep, because there's no sexp
  to the left to move over: you have to move up.

  forward-sexp. Moves forward over the next sexp. Same deal if your cursor
  is just to the left of a right paren.

  backward-up-list. Move backward up one level of parens. In other words,
  move to the left paren of the parens containing the cursor, skipping balanced sexps.

  down-list. Move down one level of parens. In other words, move to the right
  of the next left paren, skipping balanced sexps. E.g., if your cursor
  is sitting on the return type of a C function declaration, C-M-d moves to
  the inside of the formal parameter list.

Emacs has commands to move over functions. Like the sexp commands, these commands
work appropriately in most programming language modes. Emacs calls this generic
notion of function or procedure defun, again after Lisp.

  beginning-of-defun. Move to the beginning of the current defun.

  end-of-defun. Move to the end of the current defun.

  Kill means Cut
  Delete means Delete

  delete-char. Deletes the character to the right of (under, if the cursor is
  a block that covers a character) the cursor.

  delete-backward-char. Deletes the character to the left of the cursor.

  kill-word. Kills to the end of the word to the right of the cursor (forward).

  backward-kill-word. Kills to the beginning of the word to the left of the cursor (backward).

  kill-line. Kills to the end of the current line, not including the newline.
  Thus, if you're at the beginning of a line it takes two C-k's to kill the
  whole line and close up the whitespace.

C-u 0 C-k
  kill-line. Kills to the beginning of the current line, not including the newline.

  kill-sentence. Kills to the end of the current sentence, including any newline
  within the sentence.

C-u -1 M-k
  kill-sentence. Kills to the beginning of the current sentence, including any
  newlines within the sentence.

  kill-sexp. Kills the sexp (balanced parentheses) after the cursor.

C-u -1 C-M-k
  kill-sexp. Kills the sexp (balanced parentheses) before the cursor.

C-y (yank)

To get back previous kills, you move around the kill ring. Start with C-y to
get the most recent kill, and then use M-y to move to the previous spot in the
kill ring by replacing the just-yanked text with the previous kill.
Subsequent M-y's move around the ring, each time replacing the yanked text.
When you reach the text you you're interested in, just stop. Any other command
(a motion command, self-insert, anything) breaks the cycling of the kill ring,
and the next C-y yanks the most recent kill again.

Searching and Replacing

C-s isearch-forward incremental search
  To stop searching, you can either hit RET or type any other Emacs command
  (which will both stop the search and execute the command).

C-r isearch-backward, incremental searche backward.
  (Use C-r to search for the next match and C-s to reverse the search.)

To invoke word search, type C-s RET C-w word word word RET.


Replacing text is called query-replace (bound to M-%).

  Perform this replacement.
  Don't perform this replacement.
  Terminate query-replace without performing this replacement.
  Same as RET.
  Perform this replacement but then terminate the query-replace.
  Perform this replacement and all the rest in the buffer without querying (ie unconditionally).

  replace-string (simple unconditional replacement),
  query-replace-regexp (which use regular expressions),
  tags-query-replace, which replaces all identifiers in a collection of source code files.

query-replace and the other replacement commands are, by default, smart about case.
For example,
if you're replacing foo with bar and find Foo, Emacs replaces it with Bar;
if you find FOO, Emacs replaces it with BAR, etc.

The Mark and The Region

Emacs can manipulate arbitrary chunks of text as well as distinct textual objects.
The way this is done is to define a region of text; many commands will operate
on this region.

The region is the text between point and mark. Point is actually the Emacs term
for what we've been calling the cursor up to now.

C-@ set-mark-command
  The mark is set with a special command C-@ (set-mark-command). This sets the
  mark exactly where point is, but now you can move point elsewhere and
  you have: the region.

Many commands that move point a significant distance (like M-< and C-s, for
example) leave the mark set at the spot they moved from. You'll see "Mark set"
in the echo area when this happens.

  mark-word. Sets the region around the next word, or from point to the end of
  the current word, if you're in the middle of one.
  mark-paragraph. Sets the region around the current paragraph.
  mark-sexp. Sets the region around the same sexp that C-M-f would move to.
  mark-defun. Sets the region around the current defun.
C-x C-p
  mark-page. Sets the region around the current page.
C-x h
  mark-whole-buffer. Sets the region around the entire buffer.

C-x C-x
  exchange-point-and-mark. Swaps mark and point. Repeated rapid execution of
  this command makes it easy to see the extent of the region.

  kill-region. Kills the region. It goes on the kill ring, of course.

  kill-ring-save. Saves the region to the kill ring without removing it from
  the buffer. This is exactly equivalent to typing C-w C-y.

C-x C-i
  indent-rigidly. Rigidly indents the region by as many characters (columns)
  as you provide as a numeric argument (default is 1 column).

C-x C-l
  downcase-region. Convert the entire region to lowercase. This command is
  disabled by default.

C-x C-u
  upcase-region. Convert the entire region to uppercase. This command is
  disabled by default.

M-x fill-region
  fill-region. Fills, i.e., justifies with a ragged right margin, all the
  paragraphs within the region.

  In programming language modes, Emacs uses the TAB key to indent a line
  automatically, in accordance with indentation rules for your programming
  language. For example, in C Mode Emacs understands if, while, do, for,
  functions, switch, etc and indents appropriately. Of course, there are no
  hard and fast rules for indentation in most languages, so Emacs allows you
  to customize the indentation for your own style.

The main way Emacs customizes commands for different kinds of text is through
major and minor modes. Every buffer has a major mode, and may have zero or more
minor modes. Sometimes Emacs chooses a major mode for you automatically,
typically based on a file extension (e.g., files ending in .c will automatically
be in C Mode; files ending in .tcl will automatically be in Tcl Mode). But you
can always set the mode explicitly.

Some Major Modes

Fundamental Mode
  The basic mode in reference to which all specialized modes are defined.
  Perfectly fine for editing any kind of text, just doesn't provide
  any special features.

Text Mode
  For editing text. Has special commands for spell-checking,
  centering lines, etc.

Outline Mode
  For editing a stylized type of outline. Implements folding of
  outline levels, etc.

Lisp Mode
  For editing Common Lisp source code. Has an interactive link to a
  Common Lisp interpreter in another buffer.

Tcl Mode
  For editing Tcl source code. Has an interactive link to a Tcl
  interpreter in another buffer.

C Mode
  For editing C source code. Has special indentation, etc.

There are many other major modes, some very specialized (e.g., modes for
editing sending email, reading Usenet news, browsing directories,
browsing the World Wide Web, etc).



good music let you stay quiet and focused, it grows on you, it has layers that you discover as you listen to it again and again, and at one point you are so focused that you don’t remember to listening it anymore and it seems to be coming with in you and becomes part of you. Lezz, Indian Ocean

what process has a socket open

netstat -Aan|grep -v CLOSED|while read cb
    echo $cb | cut -d' ' -f1 | xargs -i rmsock {} tcpcb 2>/dev/null |
    perl -ne 'print $1,"\n" if /proccess (\d+)/' |
    xargs -i ps -fp {}|grep -v UID|
    awk '{printf "%s\t%s\t%s\n",$1,$2,$NF}'|
    sed -e "s|$|    $cb|"
done | awk '
    #print $0;
    print "--------------------"
    for (i in count){
        if(i!="")print count[i], i;
    print "--------------------"
    print tot, "total";

tcpip state

Three-Way Handshake

  1. server get prepared to accept an incoming connection (passive open) by
    calling socket, bind, and listen.

  2. client opens connection (active open) by calling connect. This causes
    the client TCP to send a “synchronize” (SYN) segment, which tells the
    server the client’s initial sequence number for the data that the
    client will send on the connection. Normally, there is no data sent
    with the SYN; it just contains an IP header, a TCP header, and
    possible TCP options.

  3. server must acknowledge (ACK) the client’s SYN and the server must also
    send its own SYN containing the initial sequence number for the data that
    the server will send on the connection. The server sends its SYN and
    the ACK of the client’s SYN in a single segment.

  4. The client must acknowledge the server’s SYN.

The minimum number of packets required for this exchange is three; hence,
this is called TCP’s three-way handshake.

        TCP A                                              TCP B

    1.  CLOSED                                                LISTEN
    2.  SYN-SENT    --> <SEQ=100><CTL=SYN>                --> SYN-RECEIVED
    3.  ESTABLISHED <-- <SEQ=300><ACK=101><CTL=SYN,ACK>   <-- SYN-RECEIVED
    4.  ESTABLISHED --> <SEQ=101><ACK=301><CTL=ACK>       --> ESTABLISHED

          Basic 3-Way Handshake for Connection Synchronization

TCP Connection Termination

  1. One application (client or server) calls close first, and we say that this
    end performs the active close. This end’s TCP sends a FIN segment,
    which means it is finished sending data.

  2. The other end that receives the FIN performs the passive close. The
    received FIN is acknowledged by TCP. The receipt of the FIN is also passed
    to the application as an end-of-file (after any data that may have already
    been queued for the application to receive), since the receipt of the FIN
    means the application will not receive any additional data on the connection.

  3. Sometime later, the application that received the end-of-file will close
    its socket. This causes its TCP to send a FIN.

  4. The TCP on the system that receives this final FIN (the end that did the
    active close) acknowledges the FIN.

      TCP A                                                TCP B
    1. ESTABLISHED                                          ESTABLISHED
    2. (Close)
       FIN-WAIT-1  --> <SEQ=100><ACK=300><CTL=FIN,ACK>  --> CLOSE-WAIT
    3. FIN-WAIT-2  <-- <SEQ=300><ACK=101><CTL=ACK>      <-- CLOSE-WAIT
    4. TIME-WAIT   <-- <SEQ=300><ACK=101><CTL=FIN,ACK>  <-- LAST-ACK
    5. TIME-WAIT   --> <SEQ=101><ACK=301><CTL=ACK>      --> CLOSED
    6. (2 MSL)
                    Normal Close Sequence
    CLIENT                                                  SERVER
                       |                                  | socket, bind, listen
                       |                                  | LISTEN (passive open)
                       |                                  | accept (blocks)
socket                 |                                  |
connect (blocks)       |                                  |
(active open) SYN_SENT |>>>>>>>>>>>>> SYN J, MSS=536      |
                       |             >>>>>>>>>>>>>>>>>>>>>| SYN_RCVD
                       | SYN K, ACK J+1, MSS=1460<<<<<<<<<|
ESTABLISHED            |<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>       ACK K+1     |
                       |               >>>>>>>>>>>>>>>>>>>| ESTABLISHED
                       |                                  | accept return
                       |                                  | read (blocks)
                       |                                  |
write                  |>>>>>>>>>>>>>>>  data (request)   |
read (blocks)          |               >>>>>>>>>>>>>>>>>>>| read returns
                       |                                  |
                       |                                  |
                       | date (reply), ACK (request)<<<<<<| write
read returns           |<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>> ACK reply     |
                       |                   >>>>>>>>>>>>>>>|
close                  |                                  |
(active close)         |>>>>>>>>>>>>>>>>>>>               |
FIN_WAIT_1             |                  > FIN M         |
                       |                  >>>>>>>>>>>>>>>>| CLOSE_WAIT (passive close)
                       |                 <<<<<<<<<<<<<<<<<| read returns 0 (eof)
                       | ACK M+1         <<               |
FIN_WAIT_2             |<<<<<<<<<<<<<<<<<                 |
                       |                                  | close
                       | FIN N           <<<<<<<<<<<<<<<<<| LAST_ACK
TIME_WAIT              |<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| CLOSED
                       |                                  |

SSH Public Key Authentication


    client$ mkdir ~/.ssh

    client$ chmod 700 ~/.ssh

    client$ ssh-keygen -q -f ~/.ssh/id_rsa -t rsa

    Enter passphrase (empty for no passphrase): ...

    Enter same passphrase again: ...

    # first, upload public key from client to server

    client$ scp ~/.ssh/

    # next, setup the public key on server

    mkdir ~/.ssh

    chmod 700 ~/.ssh

    cat ~/ >> ~/.ssh/authorized_keys

    chmod 600 ~/.ssh/authorized_keys

    rm ~/


after trying many thing and going thru django (1.3) files, here is how we set

static files on django dev server

in add absolute path of your static files dirs to STATICFILES_DIRS


# Put strings here, like "/home/html/static" or "C:/www/django/static".

# Always use forward slashes, even on Windows.

# Don't forget to use absolute paths, not relative paths.



dont forget trailing comma

FileZilla passwords

FileZilla stores server passwords in plain text,
see Filezilla Password File

on Windows machine passwords are stored in following files

  1. to stop filezilla to store password, you need to enable “Kiosk mode”

    c:\your\filezilla\installtion\dir>cp FileZilla-3.3.3\docs\fzdefaults.xml.example fzdefaults.xml
  2. update fzdefaults.xml–

          <!-- <Setting name="Config Location">$SOMEDIR/filezilla/</Setting> -->
          <Setting name="Kiosk mode">1</Setting> <!-- donot store passwds -->
          <Setting name="Disable update check">0</Setting>