2010-10-09

poll result: what content would you like to see more?

Last week's poll result:

What content would you like to see more?

emacs
  5
other programing/computing/webdev topics
  6
math
  0
random pop, social, art, sex, politics
  2

 
more technical (e.g. emacs, comp lang tutorial)
  2
more rant/essay/opinion style writing
  2
 

prefer longer (e.g. 1 or 2 pages essay/tutorial)
  3
prefer short (1 paragraph emacs tips, etc)
  0

Check out this week's poll:

With regards to swearing, do you prefer my writing style to be:

  • (1)True Xah Lee style; (e.g. I don't really give a flying fuck if people can't read my article due to fucking words in it. Those “constructive criticism” thinking ignoramuses, go study philosophy and fuck off. At times, my copious copulative expletives littered thru-out makes alliterative art, and that's the worth by itself, besides solid content behind them. (google my essay on Constructive Criticism))
  • (2)Criticize as usual, be honest, don't overswear; some swearing conveys needed altitude.
  • (3)Swearing distracts. I prefer less or no swearing. Maybe once in a while.
  • (4)Try to convery the same point, with expressions that are not so offensive or confrontational. Vulgarities are never really necessary in writing.

Vote on the sidebar.

Stupid poll widget made me split the first item cause it's too long. What the fuck is with the web these days? Must we all just tweet 5 words blurbs? Fucking twits. What happened to eloquence? harangue?

emacs: what's eshell? eshell vs shell

Perm url with updates: http://xahlee.org/emacs/eshell.html

Emacs: What's eshell? “eshell” vs “shell” Difference?

Xah Lee, 2010-10-09, 2011-01

I've always thought that eshell was just a toy, and never really tried to use it other than knowning it's written entirely in elisp. But over the past few years i learned from emacs community, that apparently many people do use it. Also, because eshell is written in emacs lisp, that means you can enter elisp code or call any of the 3000+ elisp commands or functions directly in the eshell command line.

For example, try typing “(+ 3 4)” in the prompt, and it returns “7”.

What's eshell? how's it different from shell?

eshell is written entirely in elisp.

Practically speaking, that means when you are on Windows and don't have Cygwin installed, you can still use all the common unix ls, cd, mkdir, cp, grep, ... stuff, in eshell.

How to set environment variable FOR eshell?

you can get and set environment variables for emacs use only by:

; show env var named path
(getenv "PATH")

; example of setting env var named “path”
; by prepending new paths to existing paths
(setenv "PATH"
  (concat
   "C:/cygwin/usr/local/bin" ";"
   "C:/cygwin/usr/bin" ";"
   "C:/cygwin/bin" ";"
   (getenv "PATH") ; inherited from OS
  )
)

Put in your emacs init file. Restart emacs, or, select the code then call “eval-region”.

This will effect environment variable within emacs only. It won't change the real environment variables used by OS.

When you call a command such as “perl” that's not in eshell, eshell will try to find it in the env var PATH. Also, emacs do inherit your PATH environment variable from OS. For detail, see: Emacs and Microsoft Windows Tips.

Advantages of Eshell Over a Regular Shell

NikkiA at reddit gave some very useful tips:

  • Platform agnostic - it works the same on unix based OSes and Windows
  • tramp integration - if you start an eshell while default-directory is pointing at a buffer that is served over tramp, then eshell will use the same connection, and allow manipulation of the remote filesystem without using dired.
  • find-file ... It's just so much easier being able to type 'find-file blah' as a command it open blah in an emacs buffer (even over tramp, see above)
  • consistancy - eshell uses its own method of colouring the output of ls and thus is consistant across platforms and shell configurations, which can be important if you ever have to use it on accounts that you don't have authority to modify .bashrc/.profile on.
  • /dev/clip and /dev/kill - you can redirect shell commands to the emacs clipboard and killring
  • redirect to buffers - along with the above, you can also do things like ls >> #<buffer *scratch*> to output the result from ls to the scratch buffer

Here's a more in-depth tutorial about eshell. Mastering Eshell by Mickey @ Source www.masteringemacs.org

Eshell is written by John Wiegley. Thanks John.

Women Don't Want To Run Startups Because They'd Rather Have Children

Perm url with updates: http://xahlee.org/Periodic_dosage_dir/women_and_Penelope_Trunk.html

Women and Penelope Trunk

Xah Lee, 2010-10-09, 2010-10-11

TechCrunch is running a article:

Penelope is a entrepreneur, in today's online websites business (e.g. SEO, twitter, Facebook, blogging to richdom, and all that buzz). In the article, she basically tells the story of how she's now moving and going off to run a family with her man.

The article so far has over 300 comments, and more than half are women, complaining about the article. Here's my comment (slightly edited):

lol. this post gets a flood of angry girls who flame the author, with comments that indicates they speak for men too. (e.g. “this post is not only insulting to women but insulting to men TOO!”)

the sex fight is eternal to human animals. Some chide the author for not having done research or statistics. Well, you have done study in the general behavior pattern of this in human history?

this article, just like many others, simply speaks the author's mind, without needing to dress it up. But due to the sensitive topic, of course you get a flood of women complaining (and btw, perhaps less that 10% of all the business men, or entrepreneurs, are women in the first place, because, women, are simply not interested, generally speaking.)

so, thumbs down to the bitchers. But one sympathizes with these people cause their reaction are typical to all human animals: defending their self-interests, with less regard to what is true or fair.

as some of these seems young ladies grew to mid-age, perhaps like Camille Paglia have expressed, they in flocks left the feminism scene to establish families, and the ambitions became stories of “when i was young...”.

As with respect to marketing in our web 2.0 age, bravo for the title.

PS who's this “Penelope Trunk” anyway? Apparently, she's a pretty, smart, feminine, chick. She's got 56k subscribers, 59k twitter followers, and makes $150k a year. Just look at this her blog, and look at her skirt:

〈how to do damage control〉 @ http://blog.penelopetrunk.com/2010/09/24/how-to-do-damage-control/

She sure know how to title her articles, and she has a way with words.

Such a successful queen. Don't you want her?

2010-10-08

tea in Taiwan, US, and Babelcarp

Lew Perin, a programer, who fixed a Windows Vista VirtualStore Problem for FSF Emacs with C code, has written a web app that translate tea names in Chinese to English, with good explanations. The app is called BabelCarp at: http://www.panix.com/~perin/babelcarp.html. Quote:

I've been drinking tea, for want of a better word, *seriously* for a dozen years. Obviously Chinese tea is the majority of all the world's tea of any interest. After a few years, I realized that I would learn something about Chinese tea and then forget it, so I started thinking about how I'd memorialize what I learned. Then I said to myself "Hey dummy, you're a computer programmer - create a web application!" Hence Babelcarp.

If you don't know... tea in China is quite involved, with all sorts of knowledge and culture. Similar to, say, coffee and wine making. You know? the types, techniques to process, locations, brewing knowledge and secrets, etc, with aficionados, competitions, exhibitions, expert tasters etc. Some old masters, can take a whiff of your tea (baked dry leaves) and tell you how much it's worth (in wholesale level trading).

Personally i know quite a bit about tea, more so than a typical Chinese, because my dad is a tea merchant, he bakes tea. (and as a teen, i was beaten, etc, to learn and do the processing, delivery, etc in the family business.)

You can read Wikipedia to learn more: Tea.

One thing funny is that, in Taiwan (where i grew up), you never put sugar in tea. Unless it's bottled commercial iced tea, but even bottled tea is rare (it's like, as rare as bottled ice coffee in US). Nor have i ever heard of putting milk in tea. So, when in US, when people drop some sugar or milk in tea, it's like LOL, what a idiotic practice! That's like, hey let's put some sugar or lemon juice in red wine to enhance the taste. Also, there's never such things as lemon tea, or whatnot orange tea or herb tea or de-caff tea.

web design: fixed-layout vs flowed-layout

Perm url with updates: http://xahlee.org/js/fixed-layout_flowed-layout.html

Fixed-Layout vs Flowed-Layout

Xah Recommends:
Kindle
Amazon Kindle. Read books under the sun. Review

Xah Lee, 2010-10-08

Many sites, when you increase the font size, part of the text went off window. It forces you to enlarge the window. Fucking idiot design. If you gonna do that, goto stupid PDF or TeX fuck.

Here's a example: 〈Compare JavaScript frameworks〉 (2010-02-02) By Joe Lennon. At: ibm.com

It's a nice article however.

The biggest transgressor of this, is apple.com. However, Apple.com is quite well designed, and i never had to enlarge font.

In web design or document design, there's flowed layout vs fixed-layout design. Both have advantages. Fixed-layout is especially important for print media, such as newspaper, magazine, books. These, you need efficient use of space, and no white gaps between columns or any large white gap. That usually requires you to have tight control down to pixels of every element. But as digital documents, fixed-layout is not suitable because you need your document to be displayed on screens of various size, from palm sized devices to huge cinema screens. And with screens, you have the concept of scroll instead of fixed pages. There isn't a worry of white gaps as in printed media, in fact gaps make the doc's structure more clear, and you have links, buttons, etc that can do pop-ups, frames, tabs, and windows can be positioned side by side or resized, moved, which gives user much better control in reading the document. So, flowed makes much more sense.

Was this page useful? If so, please do donate $3, thank you donors!

emacs lisp bounds-of-thing-at-point and function chaining

Perm url with updates: http://xahlee.org/emacs/thing-at-point_chaining_functions.html

Emacs thing-at-point and Chaining Functions

Xah Recommends:
Kindle
Amazon Kindle. Read books under the sun. Review

Xah Lee, 2010-10-08

The elisp function 「(thing-at-point 'line)」 is quite annoying.

It is used to grab the current line. Like this:

(defun xxtest ()
  "test"
  (interactive)
  (let (myline)
    (setq myline (thing-at-point 'line) )
    (message "got this: 「%s」" myline)
    ) )

It grabs the line including the line return at the end. However, if the line is the end of file then it does not include the end of line char.

This means, you have to do manual checking after you grab the line.

Use “line-beginning-position” and “line-end-position” instead. (See: All About Processing Lines in Emacs Lisp)

Functional Programing: Chaining Functions

This issue is actually common in programing langs, in Perl, Python, unix shells, all fuck up on this. In Mathematica, there's a principle, that any function always return the same form. For example, a function that solves equation or filters a list, it normally returns a list 「{...}」. But what if the input has no solution? In other langs, they might return nil, null, none, undef, or whatnot fuck. In Mathematica, it simply returns the same form (same tree structure), in this case a empty list. (and in type-ful langs: it should return the same form and same type)

The point is, the programer do not have to do extra checks, or extra “if” statement, when chaining functions. When chaining functions, the functions do not have to break out into a little extra “if” statement or form/type checking. Imagine, water is flowing thru pipes. If no water, or bad water, your filter or checkpoint doesn't have to cut the pipe open to exam it.

This principle is especially important in functional programing. In imperative programing and languages, it matters less, because programer don't chain functions that much (cause often the lang can't), and basically the entire source code is just miscellaneous blocks to do this and that.

In functional programing, overall you simply have 2 blocks in your source code. One for function definitions. And the other, is abstractly one single line of chained functions. Even lisps, usually fail grasping this fundamental idea. (and due to the cumbersome nested paren, which effectively stop the chaining paradigm. (See: Fundamental Problems of Lisp.) )

The following articles are all relevant:

Was this page useful? If so, please do donate $3, thank you donors!

2010-10-07

twitter follow icon me

was looking for a new twitter icon.

Found it!

twitter followTwitter@xah_lee

n if u r a pepsi drinker, hook up at fb2 http://www.facebook.com/xahlee. (with fb, please say u r not a bot.)

Also, you can subscribe article by topic at Subscribe To XahLee.org Site Feed

The twitter icon is designed by Jeeremie at http://web-kreation.com/all/freebies-2-awesome-twitter-icons/

Mathematician Marijke Van Gans Died (1956?-2009)

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

Mathematician Marijke Van Gans Died (1955-2009)

Xah Lee, 2010-10-07

Just discovered that a long time acquaintance is dead. She is a mathematician, her name is Marijke Van Gans. Here's the obituary from London Mathematical Society at lms.ac.uk newsletter. Quote:

Dr Marijke van Gans, who was elected a member of the London Mathematical Society on 18 February 2003, died on 21 April 2009, aged 53.

Robert Curtis writes: Marijke was a highly original and exceptionally talented scholar and mathematician, who had become known internationally as a solver of demanding mathematical problems on the internet. She was a brilliant computer programmer and an inspirational mathematical expositor, as is witnessed by the many accolades to her on the web from people who have been enlightened by her insight.

She was born at Harns or Harlingen in the Netherlands but studied at the University of London from 1987–90, and later lived in Ireland, England and Scotland. Indeed, at one point she was one third of the winning Compuserve SCIMATH Forum Team whilst living on the Isle of Bute. One imagines her in a croft with a state-of-the-art laptop computer, but few other creature comforts! The other two members of her team lived in Wigan and in Memphis, Tennessee, and no two of the trio had ever met face to face.

Encouraged and commended by the many people she had impressed through her problem-solving online, she came to the University of Birmingham in 2004 to research into combinatorics under the supervision of Robert Curtis. Her thesis was entitled Topics in trivalent graphs and she was awarded the PhD degree in 2007.

She fell ill earlier this year and, sadly, the seriousness of her condition was not immediately recognised. The disease proved particularly virulent and she died rapidly; thus a unique mathematical talent is lost to us.

I “met” her online, in CompuServe, in around 1991 to 1994. At those time, i was a college student, and just started to learn math, at calculus level. In fact, was obsessed with math, and in particular enamored with recreational mathematics. I spend several hours online daily in CompuServe's math forum. At the time, internet as we know it today isn't really there. Instead, there are few popular online services such as CompuServe in the era of BBS (Bulletin boards systems). (others popular at the time includes Delphi, Prodigy, AppleLink, and later on AOL.) In those times, you connect to the service by phone modem. I think my first modem is 300 baud rate. (roughly 300 bit/s.)

CompuServe has a Math forum. Basically, all math enthus gather and discuss math, of any sorts in all levels. Marijke is there all the time, one of the top poster (contributor) in the forum. I learned many things from her, and have exachanged many personal writings with her. (there's no email as we know it today) I'll have to dig up my CompuServe archive to post some of her writings.

After 1994, i moved to Illinois to work as a intern at Wolfram Research. By 1995 the internet started in earnest, and BBS and CompuServe waned. I have not used CompuServe since about 1994. But have exchanged a email or two with Marijke once every few years. The last of our email exchange is in mid 2000s (will dig up and possibly put here later.)

Marijke is a very idiosyncratic person, and she is a genius, in the sense that she is extremely intelligent, and diligent at solving hard problems, and completely love her subjects. She is the first person, in early 1990s, that i've seen to consistently use lower case “i” for “I”. (See: On “I” versus “i”)

In 2002, she solved a numerical analysis problem published by Society for Industrial and Applied Mathematics (SIAM). Here's a quote from her page:

This "Hundred Digit" Challenge consisted of ten numerical analysis problems, each having a single real number answer. For each, a maximum of ten points were available (one per correct significant digit).

The problems were published in SIAM News of Jan/Feb 2002, and later in Science and elsewhere. The answers and winners have now been announced by the Challenge's organiser, Prof. L. N. Trefethen of Oxford Univ., and a write-up will appear in the July/Aug 2002 issue of SIAM News.

94 teams (of one to six members each, and from all across the world) entered. Of these, 20 teams became joint winners by scoring a full hundred points. Among those is the team that was formed in the CompuServe SCIMATH forum, an online discussion message board, and consisted of Brian Medley (front, in the picture), Bernard B. Beard (centre), and Marijke van Gans (me, at the back).

I don't know Marijke really well, but from what i know of her, she does not seem to have strong formal math background at least during early 1990s, but is rather a persistent and inventive lone genius who can solve hard professional math problems on her own, at age 40 or so. She is also a exert in physics.

Of what i know of her personally, she is a expert in Windows DOS/80x86 programing with the C language. I would estimate that her expertise here is probably within the world's top 1000 programers in this area. She has written several DOS programs. As usual with her works, her software is usually very idiosyncratic, however, is the most efficient. For example, when in late 1990s, DOS is practically obsolete, but she would still write her Windows software in DOS mode, with text based graphical user interface.

She has 2 websites. One is 〔silicon-alley.com〕, started in 1996. It hosts her software. I started my website in 1997, using the same hosting service known as best.com at the time. And in 1999 she started 〔maxwellian.demon.co.uk〕, which is her personal site with her writings about math, physics, software. You can see her sites at archive.org:

Some of her pages on archive.org seem to have been hacked by sex site spammers. Just disable background image.

Here's a screenshot of her silicon-alley site as i remember it.

Marijke Van Gans silicon alley site-s

Marijke's Silicon Alley website.

Two particular programs i've use are 〈rotate〉 Source and one called neganaut i think.

Was this page useful? If so, please do donate $3, thank you donors!

Unicode Support in Ruby, Perl, Python, Emacs Lisp

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

Unicode Support in Ruby, Perl, Python, javascript, Java, Emacs Lisp, Mathematica

Xah Lee, 2010-10-07, 2011-02-06

This page exams several language's support for unicode. In particular, whether variables or function names can have unicode characters in them.

Ruby

I looked at Ruby 2 years ago. (See: Why Not Ruby? ) One problem i found is that it does not support Unicode well. I just checked today, it still doesn't. Just do a web search on blog and forums on “ruby unicode”. e.g.:

Perl

Perl's exceedingly lousy unicode support hack is well known. In fact it is the primary reason i switched to python for my scripting needs in 2005.

However, perl might have improved over the years. It can, in fact, use unicode in var or function names. For code examples, see: Unicode in Perl and Python.

Python

Python 2.x's unicode support is also not ideal. You have to declare your source code with header like #-*- coding: utf-8 -*-, and you have to declare your string as unicode with “u”, e.g. u"α β λ". In regex, you have to declare unicode with a flag e.g. re.search(r'\.html$',child,re.U). And when processing files, you have to read in with unicode(inF.read(),'utf-8'), and printing out unicode you have to do outF.write(outtext.encode('utf-8')). If you are processing lots of files, and if one of the file contains a bad char or doesn't use encoding you expected, your python script chokes dead in the middle, you don't even know which file it is or which line unless your code print file names. If you are processing a few thousand files in a dir with all sub-dirs, good luck in finding out which files have already been processed.

Python 2.6.x does not support unicode char for var or function names.

Python 3 supposedly fixed the unicode problem, but i haven't used it. I do not know if Python 3 support unicode in var names.

Last time i looked into whether i should adopt python 3, but apparently it isn't used much. (See: Python 3 Adoption) (and i'm quite pissed that Python is going more and more into OOP mumbo jumbo with lots ad hoc syntax (e.g. “views”, “iterators”, “list comprehension”. (See: What's List Comprehension and Why is it Harmful?.)))

Not related to Python lang but a related problem is, if the output shell doesn't support unicode or doesn't match with the encoding specified in your python print, you get gibberish. It is often a headache to figure out the locale settings, what encoding the terminal support or is configured to handle, the encoding of your file, the which encoding the “print” is using. It gets more complex if you are going thru a network, such as ssh. (most shells, terminals, as of 2010-10, in practice, still have problems dealing with unicode. (e.g. Windows ConsolePuTTY. Exception being Mac's Apple Terminal.))

javascript

Javascript support unicode in var name and function name, but it really depends on the browser. As of today (2011-02-06), all browsers support it.

My test is done with the following browser versions: IE8, Firefox 3.6.13, Chrome 8.0.552.237, Safari 5.0.3 , Opera 11.00. All on Windows Vista.

Here's a page you can test yourself. javascript unicode support test.

Emacs Lisp

I'll have to say, as far as text processing goes, the most beautiful lang with respect to unicode is emacs lisp. In elisp code (e.g. Generate a Web Links Report with Emacs Lisp ), i don't have to declare none of the unicode or encoding stuff. I simply write code to process string or files, without even having to know what encoding it is. Emacs the environment takes care of all that.

Emacs Lisp also support unicode in var/function names. For example:

(defun insert-β ()
  "alpha!"
  (interactive)
  (let ((α "β"))
    (insert α)  
    )
  )

Mathematica

Mathematica support unicode extensively, in variable names, function names, or as operators. (but, technically, it does not even use unicode.)

Java

Java supports unicode fully, including use in var/class names. See: Java Tutorial: Unicode in Java

2010-10-06

More Than One Class for HTML Tag

Perm url with updates: http://xahlee.org/js/html_more_than_one_class.html

More Than One Class for HTML Tag

Xah Lee, 2010-10-06

This page is a tutorial on HTML.

You can specify more than one class for a html tag, using space as separators, like this:

<span class="bk1 bk2">Alice In Wonderland</span>

You should not use multiple “class” attributes.

<span class="bk1" class="bk2">INCORRECT! INVALID! WRONG!</span>

The order of your class values does not matter.

If you have styles that conflict, such as:

.bk1 {color:blue}
.bk2 {color:red}

The last css takes priority. (in general, css conflicts are resolved by complicated CSS priority rules)

Here's code you can test yourself:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Test HTML</title>
<style type="text/css">
.bk1 {color:blue}
.bk2 {color:red}
</style>
</head>
<body>
<p class="bk1 bk2">Something</p>
</body>
</html>
Was this page useful? If so, please do donate $3, thank you donors!

Emacs Lisp: Cycle Replace Space Hyphen Underscore

Perm url with updates: http://xahlee.org/emacs/elisp_change_space-hyphen_underscore.html

Emacs Lisp: Cycle Replace Space Hyphen Underscore

Xah Recommends:
Kindle
Amazon Kindle. Read books under the sun. Review

Xah Lee, 2010-10-05

This page shows a example of writing a emacs lisp command that changes space to underscore of the current line, or among hypen, underscore, space. If you don't know elisp, first take a look at Emacs Lisp Basics.

The Problem

I often need to change all underscore “_” characters to space, or hypen “-” to underscore, or any combination between them.

This is most often used on file name, or moving file name to article title.

Solution

In the beginning, i simply wrote these commands:

(defun space2underscore-region (start end)
  "Replace space by underscore in region."
  (interactive "r")
  (save-restriction
    (narrow-to-region start end)
    (goto-char (point-min))
    (while (search-forward " " nil t) (replace-match "_")) ) )

(defun underscore2space-region (start end)
  "Replace underscore by space in region."
  (interactive "r")
  (save-restriction
    (narrow-to-region start end)
    (goto-char (point-min))
    (while (search-forward "_" nil t) (replace-match " ")) ))

The code is very simple to understand.

replace-underscore-space-toggle

After a few months, i find it annoying that i have to choose which command to call. So, i thought: why not create a function that simply toggles? So, i wrote this:

(defun replace-underscore-space-toggle ()
  "Replace underscore/space in the current region or line.
If the current line contains more “_” char than space,
then replace them to space, else replace space to _.
If there's a text selection, work on the selected text."
  (interactive)
  (let (li bds)
    (setq bds
          (if (region-active-p)
              (cons (region-beginning) (region-end))
            (bounds-of-thing-at-point 'line)))
    (setq li (buffer-substring-no-properties (car bds) (cdr bds)))
    (if (> (count 32 li) (count 95 li))
        (progn (replace-string " " "_" nil (car bds) (cdr bds)))
      (progn (replace-string "_" " " nil (car bds) (cdr bds))))))

The code is smart. If you have a text selection, it works on the text selection, else the current line. Also, it looks at your text and count the number of occurrence of “_” and “ ”. If there are more “_” than “ ”, then it replaces it that way, else it does the other direction.

cycle-hyphen-underscore-space

After using this for 1 year, today i also find that sometimes i need to replace hypen “-” to underscore. At first i just quickly wrote a “hypen2space-region”, but quickly realized that i've got too many special case functions. It would be great, to have a function that cycle between these chars. Here it is:

(defun cycle-hyphen-underscore-space ()
  "Replace underscore to space, or hypen, in region or current line.
If there's a text selection, apply on that, else, the current line.
When called repeatedly, this command cycles the “ ”, “_”, “-” characters."
  (interactive)
  ;; this function sets a property “state”. Possible values are 0 to length of charList.
  (let (meat charList p1 p2 currentState nextState changeFrom
             changeTo startedWithRegion-p )

    (if (region-active-p)
        (progn
          (setq startedWithRegion-p t )
          (setq p1 (region-beginning))
          (setq p2 (region-end))
          )
      (progn (setq startedWithRegion-p nil ) 
             (setq p1 (line-beginning-position))
             (setq p2 (line-end-position)) ) )

    (setq charList (list " " "_" "-" ))

    (setq currentState
          (if (get 'cycle-hyphen-underscore-space 'state) 
              (get 'cycle-hyphen-underscore-space 'state) 0))
    (setq nextState (% (+ currentState (length charList) 1) (length charList)))

    (setq changeFrom (nth currentState charList))
    (setq changeTo (nth nextState charList))

    (setq meat (replace-regexp-in-string changeFrom changeTo (buffer-substring-no-properties p1 p2)) )
    (delete-region p1 p2)
    (insert meat)
    
    (message "Changed “%s” to “%s”" changeFrom changeTo )
    (put 'cycle-hyphen-underscore-space 'state nextState)

    (when startedWithRegion-p 
      (goto-char p2)
      (set-mark p1)
      (setq deactivate-mark nil) ) ) )

Here's the gist of how this function works.

The function sets up a state. So when called repeatedly, it knows which to cycle to.

The state is done in elisp as “properties”. In htm/xml, a tag can have several pairs of name/value attributes. This is similar to lisp's “properties”. Any elisp function can have a property. A property is basically name/value pairs. A function can have any number of properties, each with any name. The name's type can be a elisp “symbol”, “string”, or others. You can get and set properties using “get” and “put”. (info "(elisp) Property Lists")

In our function, first we set a character list like this 「(setq charList (list " " "_" "-" ))」. Our property name is “state”, and possible values are integers, 0, 1, 2, corresponding to the index of charList.

To cycle thru states, we just use modular arithmetics. For example, if current state is “n”, then next state is “mod(n+1,2)”. Here's the corresponding code:

(setq currentState
      (if (get 'cycle-hyphen-underscore-space 'state) 
          (get 'cycle-hyphen-underscore-space 'state) 0))
(setq nextState (% (+ currentState (length charList) 1) (length charList)))

The rest of the code is easy to understand.

When this command is called with a text selection, by default emacs will de-activate the text selection after a command is finished. However, for this command, we want the text selection to stay, because user might call the command again to cycle replace. So, if region is active, we set “startedWithRegion-p” to true. At the end of the code, we restore the region's active status. Emacs has a global variable “deactivate-mark” used to control whether the mark is automatically de-activated when a command is called (when “transient-mark-mode” is on). When emacs invokes a command, it sets this variable to true. When the command is finished, emacs checks this variable to see if it should de-activate the mark. So, in our code, at the end we put: 「(setq deactivate-mark nil)」.

You can define a hotkey for any of the above commands. See: How to Define Keyboard Shortcuts in Emacs.

Without these commands, the quickest way to replace underscore to space is by selecting a region then 【Alt+x replace-string】 then “_” Enter, “ ”, Enter. However, this is several keystrokes more, and requires that half a second of brainwork. When you need do this daily many times a day, a custome command with a brainless push of button makes it easier.

Emacs is fantastic!

Uses

How about writing a function that cycles your favorite fonts? (answer: How to Quickly Switch Fonts in Emacs). How about cycling among your most frequently used files? or perhaps your several org-mode files?

Was this page useful? If so, please do donate $3, thank you donors!

2010-10-05

Why Does Google Give Info About SEO?

Perm url with updates: http://xahlee.org/js/why_google_helps_seo.html

Why Does Google Give SEO Advice?

Xah Recommends:
Kindle
Amazon Kindle. Read books under the sun. Review

Xah Lee, 2010-10-05

I have been wondering in the past 2 years, why Google spend much effort to tell webmasters about how they rank web sites etc. For example, Google's

What Google is doing is creating a whole market of SEO gaming, resulting bad search results, lots of bad sites with lots of ads that are returned as top results in web search, and the perpetual tech escalation fight between search engines and quick money schemers. (See: Tech Geekers vs Spammers and Spy vs Spy.)

Why doesn't Google shut up about how how their search engine works? After all, it's not something relevant to consumers or web site creators. If a site wants to be popular, there's the universal method, just like books, art, film: make it a good quality site.

This way, people who run questionable business with underhand tactics, have less clue on what to do. Google and other search engines have less to worry about site ranking manipulation, link manipulation, link spamming, cloaking, hidden css, obfuscated javascript, and lots of underhand techniques.

Today, Google's Matt Cutts talks about it.

“Why does Google give SEO advice?”

Google's point of view is that, by giving SEO advices, Google helps webmasters create quality websites. So, when more sites are quality, people enjoy the web more, and it also helps Google in making money as well.

A good perspective. Though, am not sure, that the overall effect of this approach is better.

Was this page useful? If so, please do donate $3, thank you donors!

2010-10-04

The Harm of Active Voice in Online Dating

Perm url with updates: http://xahlee.org/Periodic_dosage_dir/bangu/use_passive_voice.html

The Harm of Active Voice in Online Dating

Xah Recommends:
Kindle
Amazon Kindle. Read books under the sun. Review

Xah Lee, 2010-10-04

Been fret with the issues of “active voice vs passive voice” of English grammar in the past days. (See: What's Passive Voice? What's Aggressive Voice?). A thought occurred to me while i was trying to concoct a true definition of passive voice for our infomation era. I wrote, that passive voice can be likened to the opposite of aggressive voice. It is then, at that moment, i realized a problem besieging the countless young girls today.

Whenever i go to facebook, i am inundated with all these attractive chicks all seeking me — a man. (See: Facebook Girls.) You know, women, the loving and gentle half of mankind. Why do they have problems in finding a mate these days? I think the ultimate answer is that they've been screwed, bad, by the writing guilds. It all has to do with bad advice of “active voice”.

You see, when you write your profiles in facebook or matebook using active voice, men may mistake you to be a aggressive butcher dyke. Y'know, hirsute, brawny, and can bench press 500 pounds. And real man get scared off thinking you are like that. In order to show your true self, you need to use passive voice. Here are some examples.

For example, when filling out what movies you like. Don't say “I like Sex In The City”; that's active voice. Instead, say “Sex In The City made me like it.” When asked what color you like, “I like pink” will convey the wrong image. Instead, say: “Pink dictates the color of me”. When describing sexual orientation, don't just put “men” or “women” or “men and women”. Put down “i submit to men”, “i submit to women”, or you submit to both. When stating relationship status, say “taken” or “yet to be taken”. But don't stop at your profiles. Spread passiveness all over your chats and blogs. In all seriousness, this is a aspect of marketing, and psychology, topics that are studied in academia for thousands of years, and big corporations spend billions on advertising research. You want to advertise yourself in the most effective way. Imagine, the ultimate efficiency is that when a man happened upon your blog, he immediately succumbs to your charm, and start to send you gift cards for shoes amazon.

I would like to give you a example on this passive voice writing style. If you have a blog article, show it me, and i can show you a passive voice version personalized just for you. My fee is very reasonable, at $5 a piece. (your article must be less that 500 words) Paypal me at my email address, and lonely no more.

(legal disclaimer: money back guaranteed within 1 week after service.)

online privacy, Flash cookies, security

Google introduced encrypted search: https://www.google.com/.

It keeps hackers from knowing what you are searching and results.

If you don't know already, when you use the browser, anything sent and received by your browser is sent in the open. That means, any hacker can trivially listen in. Unless the url is “https”, which means its encrypted (typically the login/password page is https, or banking sites).

This means your facebook, blog, are all sent in the open. Some IM chat such as AOL, MSN, Yahoo offer encryption, but you have to turn it on. Skype skype.com chat is ALWAYS encrypted. (See: Skype Chat Encryption and Screen Sharing.)

Also, if you are worried about privacy, you can turn off cookies in your browser. Or, in your browser start Privacy mode. Though, note that all it does is things like turning off cookies and stop saving browsing history. These are useful if you are in a public computer such as library. But at your own computer at home, it is basically not relevant.

Note that if you use Flash (e.g. youtube, movie sites, games sites), the Flash will store cookies separate from your browser's cookies. Sites with Flash can track you. You can turn it off here: macromedia.com, but it is a pain to do. I really hate Flash. Don't use it if you can.

Also, today there are so many technologies that even if your are a pro web programer, none actually knows well all these techs. For example, html5 and tech on mobile devices, see: http://arstechnica.com/apple/news/2010/09/rldguid-tracking-cookies-in-safari-database-form.ars.

If you are really paranoid, one thing you can do is to turn off javascript (besides cookies). Turning off javascript will prevent vast majority of privacy problems, but it also means that many interactive sites will not work.

2010-10-03

connect Twitter, Blogger, Facebook

How to automatically post from Twitter tweets to Facebook?

Twitter to Facebook: http://twitter.com/widgets/facebook.

How to automatically post from Blogger to Twitter?

If you are using Google's FeedBurner, then just go to FeedBurner, click on the one of your feed, then Publicize tab on top, then “Socialize” on the left.

If not, just signup at http://feedburner.google.com/.

See also: Advantages Of FeedBurner And Some Web Feed History

Advanced Windows Customization Setup

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

Windows Flip3D, Instant Viewer, window Auto-raise, Secure Login... Setups

Xah Lee, 2009-06, 2010-10, 2011-01-22

This pages gives some advanced tips on Windows customization for power users. The tips are tested in Windows Vista, but should work for Windows 7 too.

See All Your Windows in a Glance

Flip 3D

Press 【Win+Ctrl+Tab】 to go into Flip 3D. You get a preview of your windows and you can switch among them with scroll wheel or arrow keys.

Windows Flip 3D-s

Flip 3D.

If you have a Microsoft mouse or keyboard, you can use the bundled software IntelliPoint or IntelliType to set a mouse button or keyboard key to activate it.

Instant Viewer

Press 【Alt+Ctrl+Tab】 to start Instant Viewer.

Windows instant view

Windows Instant View

Instant Viewer lets you see all your windows in a glance. This feature is available since 2002. This is better than Flip 3D, because: ① See all windows at the same time. ② Each window also shows the app's icon for quick recognization. ③ Faster to activate the window you want by mouse. (no need to flip thru)

Microsoft and Logitech mouse also has bundled software to let you set a button to activate Instant Viewer.

Windows Auto Raise & Single Click to Open File

How to Turn Caps Lock Off

How to Swap Caps Lock, Alt, Control Keys On Windows

Show File Extensions and Full Path

For programers, you probably want to show file extensions and full path.

This is under Control Panel, Folder Options. In particular, uncheck the “Hide extensions for known file types”, “Display the full path in the title bar”, “Show hidden files and folders”.

Secure Login

You can set you system to require pressing 【Ctrl+Alt+Delete】 to start the login screen. The advantage is that this prevent the possibility of some rogue program spoofing as the login screen and steal your password. For some detail, see: Secure attention key.

To set it up, press 【Win+r】, then type “netplwiz” in command prompt to start the Advanced User Accounts control panel. Then, check the box “Require users to press Ctrl+Alt+Delete”.

google ice cream; dont be evil

Perm url with updates: http://xahlee.org/funny/Google_ice_cream.html

Google Ice Cream; Can Google Be Trusted?

Xah Recommends:
Kindle
Amazon Kindle. Read books under the sun. Review

〈"Don't Be Evil?" video - beta version〉

This ad is from a non-profit organization in USA, called Consumer Watchdog. It's home page is at consumerwatchdog.org.

This video, can be seen at their site at: insidegoogle.com.

I'm a programer in web dev industry. I've been watching google grow up, so to speak, from the very early days when google started in 1998, and over the past 10+ years, from one single web search product to tens of services ( gmail, orkut (social networking), google news, blogger, google groups (online forum), Google Video and YouTube, google sites and google doc, picasa (image hosting), gTalk (IM, chat), adSense and AdWords, Google webmaster tools and Google Analytics, Google Code (code hosting), Google Chrome (browser), ... ). Today, i use almost all of them, gradually over the years.

I'm quite picky and sensitive about which company's products and services i choose, and i've followed closely about Google's practices and news. I must say, Google is pretty safe, their products are usually much better than competitors, and Google is more trust-worthy than competitors, all things considered.

When you attack companies, you really need to think about, are you attacking them just because they are big and successful? Or are you attacking them because some specific issues? I think it is true that any company, however ethical, when becoming one of the biggest in the industry, gets attacked. Or, in other words, any ethical company, when you are so successful to become number 1, you get attached the “monopoly” label, and you became the target of fear and hate.

It was IBM, then it was Microsoft, now, it's Google's turn.

I'm sure Google has some issues here and there, but we need to look at the big picture, not grabbing a pigtail and blame. Whether Google is trust-worthy tomorrow, we'll have to see.

See also:

Was this page useful? If so, please do donate $3, thank you donors!