Posts

Showing posts from September 11, 2011

Emacs Lisp Function to Trim String

Emacs Lisp Function to Trim StringEmacs lisp does not have a function that removes space from the beginning and end of a string. You must use “replace-regexp-in-string” for that. Here's a function that does it. (defuntrim-string (string) "Remove white spaces in beginning and ending of STRING. White space here is any of: space, tab, emacs newline (line feed, ASCII 10)." (replace-regexp-in-string "\\`[ \t\n]*""" (replace-regexp-in-string "[ \t\n]*\\'""" string)) ) See also:Text Pattern Matching in Emacs (emacs regex tutorial)Emacs's Key Notations Explained (/r, ^M, C-m, RET, <return>, M-, meta)

roller coaster = calculus

Image
when i see a roller-coaster, i see calculus.Blue Fire roller-coaster. img src

Emacs: manipulate Column Text, string-rectangle, ASCII-Art

Perm url with updates: http://xahlee.org/emacs/emacs_string-rectangle_ascii-art.htmlEmacs: Manipulate Column Text, string-rectangle, ASCII-ArtXah Lee, 2011-09-14Some tips on manipulating a column of text.In my 12 years of using emacs daily, the most useful to me are these two. I use them few times a week.CommandKeyPurposekill-rectangle【Ctrl+xrk】Delete a column block of text (and put it in a special clipboard)replace-rectangle【Ctrl+xrt】Insert text in all lines. This is alias to “string-rectangle”.I use the above so often that in the past 2 years i gave them a shortcut such as 【Ctrl+8】 and 【Ctrl+9】.Here's a example of how to use it. In the following, put your cursor before the “1”, then mark 【Ctrl+Space】, then move it to end of “2”, then call “kill-rectangle” .............. ..1xxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxxx..oooo.. ..xxx2..oooo.. .............. The other emacs command i often want but always…

Programing Language: LISP Syntax Problem of Piping Functions

Perm url with updates: http://xahlee.org/comp/lisp_syntax_function_pipe.htmlPrograming Language: LISP Syntax Problem of Piping FunctionsXah Lee, 2011-09-16One of the annoying problem of the lisp nested syntax is the problem of creating a function chain (aka unix pipe, filtering, stream).Here's a example i frequently encounter in emacs lisp. I want to apply several different functions to a string, one after the other. Example: (setq fname (file-name-sans-extension (file-name-nondirectory fname))) (setq fname (replace-regexp-in-string "-"" " fname)) (setq fname (replace-regexp-in-string "_002d""-" fname)) fname Note the repeated reset of a variable. I don't want that. I want to avoid mutable variables; it's bad in functional programing. So, one should do like this: (replace-regexp-in-string "_002d""-" (replace-regexp-in-string "-"" " (file-name-sans-extension (file-name-nondirectory fname))…

the will to live

i have lost the will to live.for about 4 months back now.been wanting to write about it on and off, but every time i started to ramble and digress and wasn't too sure if i should post.so, what i want to know is, what do you think about this?

Why Doesn't Google Chrome Cache YouTube Videos?

being a efficiency nerd, i have this unhealthy obsession about the efficiency of internet bandwidth use.for example, if i'm watching a youtube video, and if it so happens that i don't want to watch it anymore, i usually take the trouble of right-click and stop downloading, even i still want to stay on the page (say, reading the comments), as some kinda sense to reduce “waste”. (even though my internet bandwidth is fast, unlimited, and far underused)as another example, when the tech of live audio broadcasting thru internet (aka internet radio) started to show up in ~1999, where people can listen to it just like radio, like, leaving it on all the time, my thought was that, “O my fucking god, who invented such a thing that is extremely inconsiderate in using resources”.of course, i know that these are extremely silly concerns, but i simply just have it in me, and continuously trying to brush such idiotic thoughts away. (i should know, cuz i wrote a ton despising those “hacker” co…

9/11, and Human Animal's Love for Excitement

Perm url with updates: http://xahlee.org/Periodic_dosage_dir/politics_love_for_excitement.html9/11, and Human Animal's Love for ExcitementXah Lee, 2011-09-11So, over there at social policy activist Lauren Weinstein's post about politicians and the media abusing 9/11 to manipulate populace or whatnot. Here's excerpts:With the media deeply engaged in an orgy of wall-to-wall 9/11 coverage today, one might imagine that the 10 year anniversary of another attack on the U.S. — the attack on Pearl Harbor — would have generated similar press reactions. Or is the media exploitation of such anniversaries a relatively new phenomenon?I spent some time looking over newspaper archives from December 7, 1951 to try find out. The contrast with today's media was striking. …In fact, you had to go to page 10 to find any mention — a brief editorial — regarding the anniversary, noting with confidence that there would never again be a similar attack on a well-prepared United States: …Full pos…

The Lonely Island - I Am On a Boat

Image
Perm url with updates: http://xahlee.org/music/i_am_on_a_boat.htmlRaw Spite, Motherfucker, I Am On a BoatXah Lee, 2011-09-10I'm on a Boat (2009), a silly rap song. The song is extremely popular. Quote from Wikipedia: «The music video reached number one on YouTube in February 2009 and was number one on the U.S. iTunes music video chart.».I'm On A Boat (ft. T-Pain)Love the song. Pure swagger delivered raw.shawty ⇒ or “shorty”. Young attractive female. Shawty (slang) five knots ⇒ one knot is 1.852 km per hour. 5 knots is thus 9.26 km/h. Knot (unit) (shawty) Aww shit Get your towels ready it's about to go down (yeah, shawty) Everybody in the place hit the fuckin deck (yeah, shawty) But stay on your motherfuckin toes We runnin this, let's go I'm on a boat (I'm on a boat) I'm on a boat (I'm on a boat) Everybody look at me cause I'm sailin on a boat (sailin on a boat) I'm on a boat (I'm on a boat) I'm on a boat Take a good hard look at the mot…