Google, Chrome, SPDY

Google is quite powerful today. Not only having own browser, OS (Google Chrome OS), mobile OS (Android), and gazillion web services, but invents its own protocols.

This is probably old news, but see SPDY. SPDY is a protocol intended to replace HTTP. The interesting part is that it's not just a proposed protocol, but actually used daily when you use Google Chrome to access Google's websites and services. What this means is that, probably sooner or later, others will adopt. Quote:

SPDY is a research project in TCP-based application-level protocol for transporting web content. It is proposed by Google as a replacement for HTTP.

The goal of SPDY is to reduce web page load time. This is achieved by prioritizing and multiplexing the transfer of several files so that only one connection per client is required. All transmissions are SSL encrypted and gzip compressed by design (in contrast to HTTP, the headers are compressed too). Moreover, servers may hint or even push content instead of awaiting individual requests for each resource of a web page.

Google Chrome utilizes SPDY when communicating with Google services, such as Google Search, Gmail, Chrome sync and when serving Google's ads. Google acknowledges that the use of SPDY is enabled in the communication between Chrome and Google's SSL-enabled servers. SPDY sessions can be inspected in Chrome at the special URL 〔chrome://net-internals/#events&q=type:SPDY_SESSION%20is:active〕.

Check out that special url in Chrome.

It's not a wonder, that Google Chrome is faster in general. (among quite a few other reasons.)

I predict that Google Chrome will be the most popular browser before the end of 2012.

I use 5 browsers DAILY. I'll have to say, Google Chrome today is already the best, all things considered. (i rate Firefox second, Opera 3rd, Safari 4th, IE8 last. (all rating based on my experience on Windows versions))

naked nimba girl

this page's content is removed due to possible incompatibilities with Google's AdSense. For the content, goto http://xahlee.org/Periodic_dosage_dir/naked_nimba_girl.html


Emacs Lisp: Using thing-at-point

Perm url with updates: http://xahlee.org/emacs/elisp_thing-at-point.html

Emacs Lisp: Using thing-at-point

Xah Lee, 2011-02-16, 2011-03-01

This page shows you how to use emacs lisp's thing-at-point function, and discuss some of its problems, and with a suggested solution.

Purposes of Elisp Code

In coding emacs lisp, there are 2 major types of purpose.

  • ① Writing major/minor modes. (language modes, dired, bookmark, org-mode, irc, ftp, shell, etc.)
  • ② Text Processing.

For text processing, i also see 2 major categories:

  • ① Interactive commands.
  • ② Batch style scripts. (similar to typical Perl & Python scripts and sys admin jobs.)

Many emacs commands that are used every few minutes are for interactive text processing. Examples: “comment-dwim”, “fill-paragraph”, “query-replace”, “kill-rectangle”, “sort-lines”, “reverse-region”, “list-matching-lines”, “delete-trailing-whitespace”, “indent-region”, “just-one-space”, “delete-blank-lines”, “downcase-region”, “find-file-at-point” ….

Writing interactive commands are probably the most useful for beginning elisp coders. I have 100+ personal commands for interactive text processing. Typically, i press a key, then the text under cursor changes to another form. (See: Emacs Lisp Power! Transform Text Under Cursor.)

thing-at-point & bounds-of-thing-at-point

When writing interactive commands, one of the most useful function is “thing-at-point”. Here's a excerpt from its online doc:

Return the THING at point. THING is a symbol which specifies the kind of syntactic entity you want. Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', `email', `word', `sentence', `whitespace', `line', `page' and others.

“thing-at-point” basically lets you get the string of the current word, current line, current sentence, paragraph, file, url, etc, that's under cursor. Without it, you typically have to code about 5 to 10 lines, using functions like “looking-at”, “search-forward”, “skip-chars-forward” to find the boundary. Then you need to set the positions to variables. Then call “buffer-substring-no-properties” to get the string. Also, you need to wrap the whole thing with “save-excursion” so that the cursor does not jump to unexpected places when your command is called.

A associated function is “bounds-of-thing-at-point”. This is useful because, sometimes you also need to know a thing's boundary, because you may need to delete it (using (delete-region ‹point1› ‹point2›)) and replace it with some transformed string.

Problems of thing-at-point

After using “thing-at-point” for several years, i started to get slightly annoyed by some of its problems. Here's the problems i see:

Behavior Dependent on Syntax Table

When you call (thing-at-point 'word), what string you get exactly depends on the syntax table of the current mode.

For example, if you always want your “word” to mean any alphanumeric plus hyphen, you can't rely on “thing-at-point” to give you the right thing, because it may include underscore, or may not include hyphen, or may include apostrophe, depending on the current major mode's syntax table.

This problem also applies for “'sentence”, “'paragraph”.

Inconsistent Behavior for 'line

When you call (thing-at-point 'line), it will return the line with the end of line (eol) character. However, if the line is at the end of buffer, then there is no eol.

This means you have to do extra code to add or truncate the last char of the line.

It's actually simpler if you just write your own code to grab the line, like this: (buffer-substring-no-properties (line-beginning-position) (line-end-position)).

test code

Here's a simple test code to see what “thing-at-point” returns.

(defun xx ()
  "temp function for testing what thing-at-point returns"
  (let (myresult)
    (setq myresult (thing-at-point 'url))
    (message "〔%s〕" myresult)

Get Text Selection or Unit at Current Cursor Position

Starting with emacs 23.x, text selection is highlighted by default. (this means: transient-mark-mode is on by default. See: Emacs: What's Region, Active Region, transient-mark-mode?.) There's a new user interface idiom. When there is a text selection, the command will act on the text selection. Otherwise, the command acts on the current word, line, paragraph, buffer, …, whichever is appropriate for the command. This is great because users don't have to think about whether he has to call the “-region” version of the function. (See: New Features in Emacs 23.)

When you write a command to do this, the code typically looks like this:

;; get current selection or word
(let (bds p1 p2 inputStr resultStr)

  ;; get boundary
  (if (region-active-p)
      (setq bds (cons (region-beginning) (region-end) ))
      (setq bds (bounds-of-thing-at-point 'word)) )
  (setq p1 (car bds) )
  (setq p2 (cdr bds) )

  ;; grab the string
  (setq inputStr (buffer-substring-no-properties p1 p2)  )

  ;; do something with inputStr here

  (delete-region p1 p2 ) ; delete the region
  (insert resultStr) ; insert new string

It takes about 6 lines to get the boundary and the string. If you are grabbing line, then you need few more lines to check eol.

Alternative Solution

Because i need to grab the text so often, i got tired of repeatedly writing these 10 or so lines. I wrote a function that does this. Here it is.

(defun get-selection-or-unit  (unit)
  "Return the string and boundary of text selection or UNIT.

Returns a vector [text a b], where text is the string and a and b are its boundary.

If `region-active-p' is true, then the region is the unit.
Else, it depends on the UNIT.
UNIT can be
'word — sequence of 0 to 9, A to Z, a to z, and hyphen.
'glyphs — sequence of visible glyphs. Useful for file name, url, …, that doesn't have spaces in it.
'line — delimited by “\\n”.
'block — delimited by “\\n\\n” (todo: or beginning/end of buffer.)
'buffer — whole buffer. (respects `narrow-to-region')

Example usage:
    (setq bds (get-selection-or-unit 'line))
    (setq myText (elt bds 0) pBegin (elt bds 1) pEnd (elt bds 2)  )

This function is similar to `bounds-of-thing-at-point'.
They are different in the following ways:
• this function takes a text selection if there's one.
• 'line always returns the line without end of line character, avoiding inconsistency when the line is at end of buffer.
• 'word does not depend on syntax table.
• 'block does not depend on syntax table.

  (let (p1 p2)
    (if (region-active-p)
          (setq p1 (region-beginning))
          (setq p2 (region-end))
         ( (eq unit 'word)
             (skip-chars-backward "-A-Za-z")
             (setq p1 (point))
             (skip-chars-forward "-A-Za-z")
             (setq p2 (point)))

         ( (eq unit 'glyphs)
             (skip-chars-backward "[:graph:]")
             (setq p1 (point))
             (skip-chars-forward "[:graph:]")
             (setq p2 (point)))

         ( (eq unit 'buffer)
             (setq p1 (point-min))
             (setq p2 (point-max))

         ((eq unit 'line)
            (setq p1 (line-beginning-position))
            (setq p2 (line-end-position))))
         ((eq unit 'block)
            (if (re-search-backward "\n\n" nil t)
                (progn (forward-char 2)
                       (setq p1 (point) ) )
              (setq p1 (line-beginning-position) )

            (if (re-search-forward "\n\n" nil t)
                (progn (backward-char)
                       (setq p2 (point) ))
              (setq p2 (line-end-position) ) ) )) ) )

(vector (buffer-substring-no-properties p1 p2) p1 p2 )
    ) )

Here's some conveniences of this function.

  • This function takes a text selection if there's one.
  • It returns a vector, containing the string and also its boundary. So, it saves 3 lines of manually extracting the string when you also need the boundary.
  • 'line always returns the line without end of line character, avoiding inconsistency when the line is at end of buffer.
  • 'word does not depend on syntax table.
  • 'block does not depend on syntax table. It's always delimited by 2 blank lines or beginning/end of file. Similar to the concept of 'paragraph.
  • 'glyphs is a sequence of visible glyphs. Useful for getting file path, url, ….

This is a initial version. There are probably a lot features and fixes to be done. The code for 'word needs to improved so it will also take words with accented character (e.g. passé). Possibly, the word semantic can be the same as glyph.

I'm gradually replacing all my ~100 personal command to use this function.


what info your browser sends out?

Today, your browser sends all sort of information. Even if you turn cookies off, or flash cookies off, you can still be identified. For example, your browser send out what font you have installed, your screen dimension, what plugins you have. Wanna know what sort of info it sends? See: https://panopticlick.eff.org/index.php.

4chan — Internet Culture

this page's content is removed due to possible incompatibilities with Google's AdSense. For the content, goto http://xahlee.org/funny/4chan.html


Problems of Symbol Congestion in Computer Languages (ASCII Jam; Unicode; Fortress)

Perm url with updates: http://xahlee.org/comp/comp_lang_unicode.html

Problems of Symbol Congestion in Computer Languages (ASCII Jam; Unicode; Fortress)

Xah Lee, 2011-02-05, 2011-02-15

Vast majority of computer languages use ASCII as its character set. This means, it jams multitude of operators into about 20 symbols. Often, a symbol has multiple meanings depending on contex. Also, a sequence of chars are used as a single symbol as a workaround for lack of symbols. Even for languages that use Unicode as its char set (e.g. Java, XML), often still use the ~20 ASCII symbols for all its operators. The only exceptions i know of are Mathematica, Fortress, APL. This page gives some examples of problems created by symbol congestion.

Symbol Congestion Workarounds

Multiple Meanings of a Symbol

Here are some common examples of a symbol that has multiple meanings depending on context:

In Java, [ ] is a delimiter for array, also a delimiter for getting a element of array, also as part of the syntax for declaring a array type.

In Java and many other langs, ( ) is used for expression grouping, also as delimiter for arguments of a function call, also as delimiters for parameters of a function's declaration.

In Perl and many other langs, : is used as a separator in a ternary expression e.g. (test ? "yes" : "no"), also as a namespace separator (e.g. use Data::Dumper;).

In URL, / is used as path separators, but also as indicator of protocol. e.g. http://example.org/comp/unicode.html

In Python and many others, < is used for “less than” boolean operator, but also as a alignment flag in its “format” method, also as a delimiter of named group in regex, and also as part of char in other operators that are made of 2 chars, e.g.: << <= <<= <>.

Examples of Multip-Char Operators

Here are some common examples of operators that are made of multiple characters: || && == <= != ** =+ =* := ++ -- :: // /* (*

Fortress & Unicode

The language designer Guy Steele recently gave a very interesting talk. See: Guy Steele on Parallel Programing. In it, he showed code snippets of his language Fortress, which freely uses Unicode as operators.

For example, list delimiters are not the typical curly bracket {1,2,3} or square bracket [1,2,3], but the unicode angle bracket ⟨1,2,3⟩. (See: Matching Brackets in Unicode.) It also uses the circle plus ⊕ as operator. (See: Math Symbols in Unicode.)

Problems of Symbol Congestion

I really appreciate such use of unicode. The tradition of sticking to the 95 chars in ASCII of 1960s is extremely limiting. It creates complex problems manifested in:

All these problems occur because we are jamming so many meanings into about 20 symbols in ASCII.

See also:

Most of today's languages do not support unicode in function or variable names, so you can forget about using unicode in variable names (e.g. α=3) or function names (e.g. “lambda” as “λ” or “function” as “ƒ”), or defining your own operators (e.g. “⊕”).

However, there are a few languages i know that do support unicode in function or variable names. Some of these allow you to define your own operators. However, they may not allow unicode for the operator symbol. See: Unicode Support in Ruby, Perl, Python, javascript, Java, Emacs Lisp, Mathematica.

XahLee.org updates

misc updates

Wikileaks, Bank of America, Anonymous, US Government, Espionage (politics; news; video; commentary)

Some funny 4chan Picts


What's a Year? Why Not Just 100 Days?

Perm url with updates: http://xahlee.org/math/how_long_is_one_year.html

What's a Year? Why Not Just 100 Days?

Xah Lee, 2011-02-14

How long is a year? What makes a season? What's Equinox? What's “Tropic of Cancer” and “Tropic of Capricorn” you see on maps such as Google Earth.

Why is there so many different calendars from so many old civilizations? For example, you hear about Chinese year, Gregorian calendar, Hebrew calendar, islamic calendar. They all disagree with each other, seems annoying. Can't we just have days starting from 1 and define a year by 100 days? That would make life much simpler.

These are age old questions. The seasons, is the most important thing that started science and mathematics, since ancient civilizations. Why is it important? Because, successful crop raising depends on knowing the seasons well. Without which, you have hunger.

And, to know the seasons, means knowing the pattern of when the weather will be cold, hot, snow, rain. Because, the plants go by that. And to know the seasons, our ancestors observed that it depends on the paths of the sun, the moon, the stars. Once you know the seasons well, then you can device calendars, which is essentially a easy way to mark the seasons by day. There are so many different calendars because, as we now know, that the seasons came from earth's orbit, and it is very, very, complex.

Here's a fantastic video that introduces the subject.

“Year on Earth”

ain't it a wonder? Now, that's why you study geometry. More specifically, analytic geometry, usually part of your calculus.

earth tilt

“earth's tilt” image source Dennis Nilsson

Here's some Wikipedia links for further reading.

  • Calendar. You have sun-based (solar calendar), moon-base (lunar calendar), and others.
  • Equinox “An equinox occurs twice a year, when the tilt of the Earth's axis is inclined neither away from nor towards the Sun, the center of the Sun being in the same plane as the Earth's equator.”
  • Tropic of Cancer “The Tropic of Cancer, also referred to as the Northern tropic, is the circle of latitude on the Earth that marks the most northerly position at which the Sun may appear directly overhead at its zenith. This event occurs once per year, at the time of the June solstice, when the Northern Hemisphere is tilted toward the Sun to its maximum extent.”

In modern day, when we think of calendars, we think of weekends, holidays, appointments. We forgot, that the primary purpose of calendar isn't about keeping dates, but tracking seasons. Because in modern society, most of us never have thought about crops and its connection to seasons. When you are hungry, you just order a pizza or lamb chop.

google search going down the drain

misc updates from my web dev blog.


Google's search is going down the drain. Α new article from N Y Times describes a big incidence of SEO gaming involving J C Penney. Detail, examples, summary at: Google Search Problems & Alternative Search Engines.


Funny! Microsoft Bing Ads


Steven Levy, who writes books about Apple, now came out a book of Google

In The Plex: How Google Thinks, Works, and Shapes Our Lives (2011) By Steven Levy. amazon


Lady Gaga, Beyonce, US Flag Dress

Lady Gaga Beyonce Telephone

Singers Lady Gaga and Beyonce, in Gaga's music video “Telephone” (2010).

See: Banners & Damsels & Mores

ErgoEmacs v1.9.2 for Windows Released

ErgoEmacs version 1.9.2 binary for Windows is out. Download at ErgoEmacs 1.9.2 Setup.exe.

ErgoEmacs 1.9.x release notes

Thanks to David Capello for the build.

How to make youtube video play repeatedly

Perm url with updates: http://xahlee.org/mswin/youtube_video_repeat_play.html

How to Make YouTube Play a Video Repeatedly

Xah Lee, 2011-02-13, 2011-03-04

How to make youtube video play repeatedly?

If you use youtube to listen to music a lot, sometimes you want to listen to just one song repeatedly. Here's how.

The easiest way is just to click the “Add to” button. The button is right below the video. That will add the video to a queue, shown at the bottom of window. Then, at the bottom, click on the video to play it there. And there's a repeat button on the right.

Alternative Method

Following is a altenative way, but does not always work.

Suppose the url is this:


After the v=, there should be 11 random characters, that's the video's ID. Anything after that you can ignore.

Then, change the url to this:


That's it.