2011-11-07

Emacs Lisp Exercise: insert-random-uuid

Solution to last week's elisp exercise: Emacs Lisp Exercise: insert-random-uuid.

Big thanks to yurivkhan and Jon Snader for discussion about UUID. See their comments at bottom of: http://xahlee.blogspot.com/2011/11/emacs-lisp-exercise-insert-random-uuid.html.

2011-11-05

brain hat

brain hat 4 medium2
“brain hat” by lani-rae. Source www.ravelry.com

emacs math symbol input mode, v1.3.2

New major version of math symbol input mode is out, at v1.3.2.

Feature additions:

  • Added support of input using unicode names. For example: greek small letter alpha
  • Added support of input using decimal forms, for examples: {955, #955} or hexadimal forms {x3bb, #x3bb}. XML entities forms such as {λ, λ, alpha} are still supported.
  • Added about 5 more subscript symbols, e.g. {ₐ ₑ ₕ ᵢ ⱼ ₖ ₗ ₘ ₙ ₒ ₚ ᵣ ₛ ₜ ᵤ ᵥ ₓ}. Their abbrev start with “_”.
  • When no valid input are found, list of valid abbrevs shows in a separate pane.

Buy it at: Emacs Unicode Math Symbols Input Mode (xmsi-mode).

If you have bought this package before, just email me with subject line “xmsi-mode update”, then i'll email it to you. Your support is much appreciated.

2011-11-04

Emacs Lisp Exercise: insert-random-uuid

This week's exercise is to write a function “insert-random-uuid”. When called, it should insert a UUID. Here's some examples of UUID:

0a1cd3bc-96fa-71d1-4338-27092ca4cfa5
1e27a053-60a4-af61-f38d-9f1f123740d6
115024d2-7c74-326e-c9ec-064f42d08b31
070f1f0b-2454-3ffa-4aa2-d6e0652d03fe

basically, it's a random string of symbols 0 to 9 and a to f, arranged in 8-4-4-4-12 blocks. There are many ways to implement this. I'll post a solution in a couple of days.

If you really don't know elisp, this weekend is a good time to learn as any. This article might get you started: Emacs Lisp Basics.

2011-11-08 solution at http://xahlee.org/emacs/elisp_generate_uuid.html

Emacs Lisp Programing: Beware of Region Boundary Change

Got stung by region in emacs, wasted about 4 hours. Here's what i learned:

Whenever you work in a region, remember that the boundaries of the text that you are interested is changed when you add or remove text in that region. For example, suppose p1 and p2 is the boundary of some text you are interested. After doing some change there, suppose you want to do some more change. Don't just call (something-region p1 p2) again, because p2 is no longer the correct boundary (of the region you are interested).

Use “save-restriction” and “narrow-to-region”, like this:

(save-restriction
  (narrow-to-region pos1 pos2)
  (something1-region (point-min) (point-max))
  (something2-region (point-min) (point-max))
  …
)

I got stung by this. Last week, i re-implemented some of my personal commands, and today found that it behaved incorrectly: it deleted text outside of a region!

Few days ago, i updated the article Emacs Lisp: Syntax Color Source Code in HTML. There's a function “dehtmlize-span-region” effected by this. It's corrected now. Here's a example:

;; WRONG! INCORRECT! DO NOT USE
(defun dehtmlize-span-region (p1 p2)
  (interactive "r")
  (replace-regexp-pairs-region p1 p2 '(["<span class=\"[^\"]+\">" ""]))
  (replace-pairs-region p1 p2 '( ["</span>" ""] ["&amp;" "&"] ["&lt;" "<"] ["&gt;" ">"] ) )
  )

Note how innocuous it looks. I have p1 and p2 as region, and i work on them. Here's the correct code:

;; correct
(defun dehtmlize-span-region (p1 p2)
  (interactive "r")
  (save-excursion
    (save-restriction
      (narrow-to-region p1 p2)
      (replace-regexp-pairs-region (point-min) (point-max) '(["<span class=\"[^\"]+\">" ""]))
      (replace-pairs-region (point-min) (point-max) '( ["</span>" ""] ["&amp;" "&"] ["&lt;" "<"] ["&gt;" ">"] ) ) ) ) )

Looks so trivial a thing, but i spent 4 hours checking and testing and rewriting to finally realize this. I remember, few years ago, i also spent half a day on region problems and wrongly concluded that “narrow-to-region” should be avoided in elisp program.

2011-11-03

Unicode Symbols for Space

Here's some unicode chars to represent Space:

CharUnicode NameCode PointComment
·MIDDLE DOTU+00B7Useful when you want to show space as visible chars
OPEN BOXU+2423Useful when indicating keystrokes
SYMBOL FOR SPACEU+2420Useful in programing contexts. This usually indicates the ASCII 32.
BLANK SYMBOLU+2422

For more proper symbols to represent tabs, return, cursor pointer, …, in contexts of keyboard input, keyboard key symbol, visible glyph in text, programing character set, etc, see:

Klein Bottle Opener by Bathsheba

klein bottle opener klein bottle opener 2
klein bottle opener.

These are made by Bathsheba. You can buy it on her site, at: www.bathsheba.com.

Klein bottle is a exotic math surface that has only one side. That is, a ant crawling on the surface can get to the other side without crossing any edge. (the natural space of Klein bottle is 4th dimension. In 3-dimension, as in the picture, the ant would have to pass wall. For more about Klein bottle and a app for interactive rotation, see: Klein Bottle.)

Note: Bathsheba has also been creativen in Second Life.

ammonite 75
Flying Ammonite in Second Life by Bathsheba.

She has also made a Seaslug Ride. To see more pics of her Second Life creation and location to buy, see: Seaslug RideFlying Ammonite.

tip for geeks: seeing an attractive girl

Today's tip for geeks.

Q: What to do when you see an attractive girl?

A: Rush out of sight quietly.

a Choker Romance

cloisonne enamel choker
“Cloisonne Enamel Choker” Source etsy.com

a Choker Romance

2011-11-02

Samba's New Logo

Samba
Samba's old logo.
Samba Logo
Samba's new logo, 2011-05

The old logo is a much better design. It got spunk. The new is boring and lame.

For collection of logos of software, see: Logo Design & Software Industry.

emacs align and sort solutions

Emacs: solutions for last week's align and sort problem. See: http://xahlee.blogspot.com/2011/10/emacs-golf-align-and-sort.html

Big thanks to Jon Snader and “jm” for the excellent solutions.

feminism = modern scumbag

feminism, and those who advocate it, are scumbags of modern society.

What could you possibly have against feminism? It's the bestest thing since rainbow kitten cupcakes!

For starters: “feminism” doesn't have anything close to a singular meaning, so you can't even discuss it without a hundred qualifiers and caveats; the feminist pendulum in the West has run its course and too often turns into pointless misandry; feminism used to be about women's right to be more than just barefoot and pregnant, and now it fights for the “right” of women to be barefoot and pregnant and be given a ton of government and corporate handouts for churning out babies; feminism is commonly embraced by people whose underlying beliefs are that women are stupid, feeble creatures who need to be controlled and saved; feminism these days focuses way too much on imaginary first-world problems like women who choose to feel badly about themselves because they think they're not pretty enough; some feminist leaders are obsessed with fanning and exploiting insecurities in women in order to indoctrinate them to their style of victim feminism, rather than being positive and helping women see that they can be strong and powerful. Last but not least: it's REALLY FUCKING DIFFICULT to spend your entire life being picked on by girls and women for various reasons, then swallow the idea that women are your true sisters and that men are the cruel enemy that oppresses you. Bitches be crazy, yo.

above quote is from: Biography of a pornographic polemic (an FAQ) (2011-05-13) By Furry Girl. @ Source www.feminisnt.com.

'tis of the age
of Gender Feminists
hitting the American stage
questioning she and he
extols the queer and weird
axing the womanly and manly
upon a glittering postmodernity
    –Xah Lee, 2004-04

2011-11-01

never date a girl who wears a choker

Have you heard this ghost story? The guy met a ravishingly beautiful girl, slept with her, then next day, waking up, she's not moving. When he unclasped the band-styled necklace she's wearing, her head rolled off on the floor?

Moral: never date a girl who wears a chocker.

The Adventure of the German Student by Washington Irving, 1824.

and, check out on Google Map the places where the public execution by guillotine was.

PS is there a name for the style of necklace that covers around the neck? Collar-styled necklace?

am looking for the correct word, e.g. the term used among necklace merchants, fashion critics, or among Haute Couture community.

For this Halloween, thou shall read horror! My other favorite is: The Masque of the Red Death , by Edgar Allan Poe, 1842.

Remember to have a dictionary installed in your browser so you can lookup words freely. See: Online English Dictionary Tools.

Math: ID System, Number Base vs Number of Digits

plot digits vs base
δ = Log[10^10]/Log[β]. Number Base β vs Number of digits δ. id_system_number_base_vs_number_of_digits.nb

see: http://xahlee.org/math/id_system_number_base_vs_number_of_digits.html