2010-08-14

Unabomber

Discovered that the unabomber has recently published a collection of his writings.
Technological Slavery: The Collected Writings of Theodore J. Kaczynski, a.k.a. "The Unabomber" (2010), by Theodore Kaczynski. amazon.


For his 1995 Manifesto, see: Unabomber Manifesto (Industrial Society and its Future).

2010-08-13

Matching Brackets in Unicode

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

Matching Brackets in Unicode

Xah Lee, 2010-08-13

This page collects matching brackets in Unicode.

ASCII: () [] {}

Common quotation: “” ‘’ ‹› «»

Asian: 「」『』 〈〉 《》 【】 〖〗 〔〕 ⦗⦘ 〘〙

Full width variant: [] {}

Half width variant: 「」

Math: ⟮⟯ ⟨⟩ ⟪⟫ ⟦⟧ ⦉⦊ ⦇⦈ ⟬⟭

Decorative: ❛❜ ❝❞ ❨❩ ❪❫ ❬❭ ❮❯ ❰❱ ❲❳ ❴❵

White variants: ⦅⦆ 〚〛 ⦃⦄

Vertical: ⏜⏝ ⎴⎵ ⏞⏟ ⏠⏡

Vertical representation forms: ﹁﹂ ﹃﹄ ︹︺ ︻︼ ︗︘ ︿﹀ ︽︾ ﹇﹈ ︷︸

Other: ﹛﹜ ﹝﹞ ⸢⸣ ⸤⸥ ⦋⦌ ⦍⦎ ⦏⦐ ⁅⁆ 〈〉 ⦑⦒ ⦓⦔ ⦕⦖ ⧼⧽ ⸂⸃ ⸄⸅ ⸉⸊ ⸜⸝ ⸌⸍ 󠁛󠁝 󠁻󠁽

What Chars Are Included

The chars here must be a matching bracket pair with respect to their semantics, as indicated in the char's Unicode name.

In particular, the following chars are not considered a matching bracket:

  • Chars that merely have the appearance of a matching bracket. For example, the ASCII <> are not included.
  • Char pair that are simply mirrors images of each ohter (e.g. many math operators ⊆ ⊇).
  • Chars that are positioned together to form a large bracket, are not included. e.g. those often used in typesetting math.
  • Proper math operators in the form of matching brackets as indicated in unicode char's name are not included here neither. e.g. ⌈ ⌉ ⌊ ⌋ ⦇ ⦈ ⦉ ⦊. See: Math Symbols in Unicode for those.

For a plain text file of unicode brackets, see: unicode_brackets.txt.

The chars collected here is not complete. I estimate there are maybe 20 pairs more that should be added here.

For a guide on how many of these brackets are used in Chinese, see: Intro to Chinese Punctuation with Computer Language Syntax Perspectives.

2010-08-12

Fasting, Religion, Mind Control

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

Fasting, Religion, Mind Control

Xah Lee, 2010-08-12

Ramadan. Quote:

Ramadan is the ninth month of the Islamic calendar. It is the Islamic month of fasting, in which participating Muslims refrain from eating, drinking and sexual activities from dawn until sunset.[1] Fasting is intended to teach Muslims about patience, humility, and spirituality. It is a time for Muslims to fast for the sake of God and to offer more prayer than usual.

Wonder why religion always has hunger/food (fasting) stuff? It is a form of mind control. Because, food is the essential item for human survival. By controlling food, or tying it to the sect's name, such as prayer before meal, it reinforces your thought process with the sect.

Before eating, you are tought by your religion that this food is given to you by your sect's idol. Practically speaking, that is not reality. The food came from your work. In religious fasting, you are taught to thank the teachings of your sect.

Though, religious fasting also seems to teach you to do a bunch of good deeds, such as helping the poor as in Ramadan cited from Wikipedia. The goodness of these is open to debate in moral philosophy. But taken them as good for granted, you wonder, why didn't any Abrahamic religion teach you to thank the gods of other religion, or your enemies? Wouldn't that, be some form of ultimate good? Say, if you are Islamic, during fasting, you should thank the Christian God. If you are Christian, your prayer before meal can go to Christian haters. Better yet, during your fasting, you should make friends with your enemies. Not abstractly thanking some god, but go to the co-worker who almost got you fired, and buy him a gift card, go to your abusive step-dad and say thank you for loving my mom, or, say to your underlings that they can leave one hour earlier and still get full pay.

See also: Abrahamic Religions as Aggressive Cults.

Though, i'll have to say, that fasting certainly is a very effective form of meditation. Self-imposed long durations of hunger makes you think, feel yourself, your presence, in this world, because it essentially deprives your survival. When a animal's survival is deprived, anything goes. For human animals, that means argument, aggression, robbery, insanity, murder. (you can see it when your your job is threatened, or your landlord who's about to kick you out) But when in a safe controlled form, it just makes you think more, on your future strategies, behavior.

html kbd tag tips

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

Discovered the “<kbd>” tag. It's similar to the “i”, “b”, “strong”, tags, but for keyboard input. It is also supported in html5. I now used it to markup keyboard keys, e.g. “Ctrl+x”.

I used to use:

<span class="key">Ctrl</span>

But that's more verbose. Now i use emacs to make the change on about 100 files on my site. (See: Emacs Interactively Find and Replace String Patterns on Multiple Files)

The css i use is this:

kbd {border:solid 1px #c2c2c2;background-color:#f0f0f0;
padding-left:.3ex;padding-right:.3ex;font-family:monospace}

Defraggler, Recuva, Partimage

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

Discovered excellent defrag software Piriform Defraggler. Also, Piriform's Recuva for file recovery is also excellent, i've used in the past. Also, discovered Partimage, for cloning disk partitions to as disk image to dvd. These are recommended to me from a expert PC friend “9 volt chicken”. These are added to: List of Great Windows Software. (all software listed there are highest quality)

2010-08-11

How to Disable the F-Lock Key

Perm url with updates: http://xahlee.org/emacs/ms_keyboard/f-lock_key_problem.html

How to Disable the F-Lock Key

Xah Lee, 2006-06, 2009-08-24, 2009-11-26, 2010-08-10

Many Microsoft keyboards now has a “F lock” key. This page discuss its problems, and how to disable it.

nek 4000 home cluster2

The F-Lock key, above the Backspace key.

Microsoft introduced a F Lock key. It functions as a toggle. When it is off, the keys F1 to F12 will behave by the following pre-set definition:

Definitions when F Lock is Off
F1F2F3F4F5F6F7F8F9F10F11F12
HelpUndoRedoNewOpenCloseReplyFwdSendSpellSavePrint

How to Disable the F-Lock Key

It's is very easy to disable it. Just redefine the special functions to type F keys. So that, doesn't matter F-Lock is on or off, the F keys always send normal function signals.

  • 1. Open your IntelliType software, under “Start‣Control Panel‣Keyboard”. Click on the “Key Settings” tab.
  • 2. Now, go to the item named “Help”, double click it (or click the “Configure...” button) You'll get a pop up dialog that lets you redifine the key.
  • 3. Choose “Choose from a list of commands”. Then click “Next”.
  • 4. Choose the item named “Keystroke...”, double click it. (or click the “Next” button)
  • 5. Now, press the F1 key. Click OK.
  • 6. Now, repeat the above for each of the “Undo”, “Redo”, ... definitions.
  • 7. Click OK to exit the Keyboard Properties dialog.

That's it.

Problems of The F-Lock Key

This F Lock key is a pain because the behavior of a function key depends on the state of the F Lock, so that a user often pressed a function key only to find it do something unexpected.

For example, when the F-lock is off, F5 does Open. In a web browser, the Open command is almost never used, and F5 is normally Refresh, much more useful. So, while in a browser, you want F Lock to be on.

This means, when you work on your computer, you have to remember which application you are in, and whether your F Lock is on or off.

Many applications make use of the function keys heavily. For example: programers's text editor (Emacs), terminal emulators, 3D Modeling software, Google Earth, 3D Games (Second Life), PhotoShop, Inkscape (vector drawing program).

The need of F Lock as a improvement is itself questionable, because the function keys themselves are already intended to be programable, so the pre-programed behavior with F Lock off is a redundant step. For example, with F Lock off, F4 is Open Document. The same Open Document can be programed into F4 without a altered state of the key.

Theoretically, F Lock being a toggle for the function keys, doubles the function key's purpose as if adding another row of function keys. But, in practice, few people actually need more than 12 shortcuts provides by function keys. If they need more, it can be done by holding one of the modifier keys (Ctrl, Alt, Shift) with function keys. (e.g. Alt+F4 to close window) Holding down a modifier key while pressing a function key, is easier to remember as well as operate, than trying to toggle F Lock to the right state followed by pressing a the function key.

Emacs Lisp's print, princ, prin1, format, message

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

Emacs Lisp's print, princ, prin1, format, message

Xah Lee, 2010-08-07

This is a short tutorial on printing in emacs lisp. If you don't know elisp, first take a look at Emacs Lisp Basics.

Simple Printing with “message”

The most basic printing function is “message”. Here's a example:

; printing
(message "hi")

; printing variable values
(message "Her age is: %d " 16)        ; %d is for number
(message "Her name is: %s " "Vicky")  ; %s is for string
(message "Her mid init is: %c " 86)   ; %c is for character in ascii code

Note: You can see all past output from “message” in the buffer named “*Messages*”. You can switch to it by “Alt+x switch-to-buffer”.

The “message” function prints to the special buffer “*Messages*”. That buffer is special, because it is the general output destination for any messages from emacs, designed to be read by human.

For example, it automatically truncate the top entries when the buffer reaches some size. Also, when a message is repeated many times, it automatically condense the repeated lines. And if the a message is a huge line, the line is truncated automatically.

;; print a line many times
(setq xx 1)
(while (< xx 20)
  (message "yay")
  (setq xx (1+ xx))
  )
(switch-to-buffer "*Messages*")

In the above example, you'll just see: “yay [19 times]”.

(info "(elisp)Displaying Messages")

Print to Your Own Buffer

When writing a elisp script that does batch processing, it's best to print to your own buffer.

For example, suppose you have a elisp batch script that do find and replace on all files in a dir. For each file visited, it prints out the file path. If you use “(message ...)”, it prints to the “*Messages*” buffer, which automatically roll off the top if you have more than a hundred lines. Also, it may intermix your script's output with output from other emacs activities.

Here's a example of printing to your own buffer:

(with-output-to-temp-buffer "*my output*" 
  (mapc 'my-process-file (find-lisp-find-files inputDir "\\.html$"))
  (princ "Done.\n")
  (switch-to-buffer "*my output*")
  )

“print” function

Elisp provides the “print” function. The basic syntax is this:

(print OBJECT)

The “OBJECT” is any elisp object you want to print. It can be any lisp datatype, such as string, number, list, ...

“format” function

How a lisp object is converted to string for printing is done by the “format” function. Use describe-function to lookup its docs.

For example, if you want better control on how your numbers are formatted, you can do:

(print (format ...))

“princ” and “prin1”

Elisp provide several other convenient functions to control printing. Here's a summary of their differences:

Function NamePurposeComment
printprint with newline.output can be read back by “read”.
prin1like print, but does not add newline.output can be read back by “read”.
princprint without newline nor delimiters.For human reading. Output can not be read back

(info "(elisp) Output Functions")

2010-08-10

Subversion Basics (svn tutorial)

Perm url with updates: http://xahlee.org/UnixResource_dir/svn.html

SubVersion (svn) Tutorial

Xah Lee, 2009-08-28, 2010-08-10

This page is a quick start tutorial of using Subversion (SVN), a version control system.

Basic Check Out, Commit

What commands are available?

Type “svn help”.

How to checkout a project?

cd to a directory where you want the files to be. Then do for example:

svn checkout svn://example.com/transvections
svn checkout svn://example.com/
svn checkout https://ergoemacs.googlecode.com/svn/trunk/ ergoemacs --username xahlee

How to commit a change?

Once you checked out, made your modifications, then you can check back in (commit your changes). To commit, cd to the working dir, then do:

# commiting all files in current dir
svn commit . -m "one-line summary of what you changed"

# commit one file
svn commit init.py -m "one-line summary of what you changed"

How to Add or Remove a dir or file?

If you created new files in your working copy and committed it, that won't work. You will need to run a svn command first to add or remove a file or dir, then commit.

To add a file or dir, use the add command:

svn add ‹file/dir name›

To remove a file or dir, use the rm command first. Then, svn will delete the file or dir for you. Do not delete the file/dir yourself.

svn delete ‹file/dir name›

Once you are done adding or removing, then you need to do a commit.

How to update your working dir?

“cd” to your working dir and use the “svn update” command. Changes made by others will now show in your working copy.

svn update .

Updating won't erase changes you made. When there's a conflict, svn will tell you.

How to erase your local edits?

If you made some changes (and have not committed yet), and decided it's all bad, you want a clean copy from the repository. You can revert (and discard all your edits):

svn revert . --force

How to revert to a previous version?

If you want to revert a version to a previous version, here's what to do. Note that there's a “revert” command, but that's not what you want. The “revert” command simply erase your local edits. What you want is actually the “merge” command. (yes, it is very unintuitive)

Suppose you have this file “xyz.ml”, and the current version is 161, you want the version 107. These are the commands you need to run:

svn merge -r161:107 xyz.ml
svn commit -m "Reverted to revision 107." xyz.ml

The “merge” command will change that file on your machine to revision 107. The “commit” actually makes that change back to the central repository.

How to find which files changed on your disk?

svn status .

For explanation of the output, see: “svn help status”.

Creating Projects

Here are some tips for svn admins.

How to create a project?

First, create the svn root dir using this command:

sudo svnadmin create /usr/local/svn_rooty

You need do the above. It is not merely creating a dir with “mkdir”.

The “/usr/local/svn_rooty” is the dir you want svn to hold the repository.

To import a project, do:

sudo svn import /Users/xahlee/mysourcecode file:///usr/local/svn_rooty -m "Initial import of my lovely project"

The path “/Users/xahlee/mysourcecode” is the path of your source code folder, the “file:///usr/local/svn_rooty” is a path for the svn root path, in a url format. The “-m” is a comment.

Then, modify the file

/usr/local/svn_rooty/conf/passwd

To contain for example these lines:

[users]
xahlee=xyz
dick=xyz
bob=xzy

The left side is user's login name, the right side is password. This is for running svn as a stand-alone server.

modify the file “/usr/local/svn_rooty/conf/svnserve.conf” to contain these lines:

[general]
anon-access = read
auth-access = write
password-db = passwd
realm = transvections

What should be the file permissions?

The following dir needs to be owned by “svn” user.

db/
db/revprops
db/revs
db/transactions
db/write-lock

How to start the stand-alone server?

First, change to svn user.

sudo su svn

Then, run the following command to launch it, while you are “svn” user.

svnserve --daemon --listen-port=3091 --root=/usr/local/svn_rooty 

The “--daemon” is for stand-alone, the “--root=” specifies root, so that in the checkout command it doesn't need to specify the full path. The “--listen-port=3091” can be omitted. The default port for svn is 3690.

Once you did this, a client can checkout with these commands:

svn checkout svn://example.com:3091/trunk
svn checkout svn://example.com:3091/transvections

# if using default port
svn checkout svn://example.com/transvections

Importing Your Source Code Into Google Code

If you host your project at Google Code, they have svn built-in. Here's instruction on how to import your source code dir into google code. (we assume that your source code dir is brand new, and is not already under a svn.)

By default, a svn repository is created for you as soon as you filled out the form for a google code project.

Now, you need to do a svn checkout, even though there's nothing to check out. The purpose to checkout is to create those svn internal files on youl local disk.

To checkout, first create a dir on your local disk where you want the local mirror to be. Then, cd to the dir, then do:

svn checkout https://xyz.googlecode.com/svn/trunk/ xyz --username xahlee

Once you have checked out, you'll see that your current dir has a “.svn” dir. That's svn's internal files.

Stay in the dir. Now, you can use the “import” command to actually create stuff in your svn repository at google code.

Suppose your source code dir is at “c:/Users/xah/xyz”. You want to import this dir to google code's svn. Type the following in your command line:

svn import "c:/Users/xah/xyz"  https://xyz.googlecode.com/svn/trunk/ -m"first import of the project."

CSS “first-letter” and “first-line” Example

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

CSS “first-letter” and “first-line” Example

Xah Lee, 2005-11, 2010-08-10

This page is a tutorial of using CSS “first-letter” and “first-line”, to make the first letter of a paragraph stand out.

Here's a example:

O toiler through the glooms of night in peril and in pain,
Thy toiling stint for daily bread comes not by might and main!
Seest thou not the fisher seek afloat upon the sea
His bread, while glimmer stars of night as set in tangled skein?
Anon he plungeth in despite the buffet of the waves,
The while to sight the bellying net his eager glances strain,
Till joying at the night's success, a fish he bringeth home
Whose gullet by the hook of Fate was caught and cut in twain.
When buys that fish of him a man who spent the hours of night
Reckless of cold and wet and gloom in ease and comfort fain,
Laud to the Lord who gives to this, to that denies, his wishes
And dooms one toil and catch the prey and other eat the fishes.

From: The Fisherman And The Jinni.

Here's the HTML markup:

<div class="xx">
<p>O toiler through the glooms of night in peril and in pain,<br>
Thy toiling stint for daily bread comes not by might and main!<br>
...
</p>
</div>

Here's the CSS markup:

div.xx > p:first-letter {color:red;font-size:xx-large}
div.xx > p:first-line {color:blue}

In the CSS, the “div.xx > p” means all “p” tags under the “div” tag of class “xx”.

Shoot'em Up Video Games

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

Shoot'em Up Video Games

Xah Lee, 2006-09, 2010-08-10

The following are a type of video game called “shoot'em up.”

These games are extremely mathematical. In the sense that the core concept is to predict projectile direction.

R-type doppelganger

R-Type (1987)

The “shoot'em up” died out due to 3D games of course. But There are a few new ones released after 2000.

Geometry wars 2

Geometry Wars: Retro Evolved 2. Released on Xbox Live Arcade on 2008-07-30.

Geometry Wars is like a modern version of R-Type.

Space Harrier (1985)


Some fascinating readings:

A highly recommended book for game programing is: 《Game Engine Architecture》 (2009), by Jason Gregory, et al. amazon.

Goto page: 1, 2

2010-08-09

Problems of Emacs's Manual; Examples

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

Problems of Emacs's Manual; Examples

Xah Lee, 2010-08-08

This page gives some examples of outdated text in Emacs Manual.

I ran into a Chinese blog article on emacs today. 〈GNU Emacs on Windows〉 (2010-06-25), by 葉難 (Yeh Nan). At: yehnan.blogspot.com.

It's written in a “Question & Answer” format in a humorous way. Very well done. There's a interesting section about emacs documentation. Here's my translation.


Q: These docs [emacs's manual] seem odd?

A: I think Emacs's official docs are all odd and wordy, because:

(1) The writer presumes all users are beginners, with no experience in using a editor, even no experience in using a computer. Look at this sentence:

Files are named units of text which are stored by the operating system for you to retrieve later by name.

O please, do i need to be told what's a file?

(2) The author seems to have stopped in the 1980s, lots of tech terms have gone obsolete. Look at this:

We use the term frame to mean the entire terminal screen or graphical window used by Emacs.

The main area of the frame, below the tool bar (if one exists) and above the echo area, is called the window.

Wow, your “frame” is my “window”, then what the heck is your “window”?

(3) Author is nostalgic of the past era; some advanced features of the past are no longer advanced. Example:

You are reading about GNU Emacs, the GNU incarnation of the advanced, self-documenting, customizable, extensible editor Emacs.

Huh? “self-documenting”? What editor doesn't have documentation? “extensible, customizable”? Nowadays many editors all can be extended or customized to various degrees.

(4) Some features are too powerful, so explanation would be cumbersome:

You can yank text from the kill ring into any position in a buffer, including a position in a different buffer; the kill ring is shared by all buffers.

The “yank & kill” here is like “cut & paste”, then what's “kill ring”? Perhaps that means when you cut many times, it won't leave just the last cut text, previous cuts are all still in “kill ring”.

(5) Because Emacs uses keyboard as its primary input, although these days we have mouse, but the core design philosophy still requires all functionalities be operable with a keyboard. For example, “selecting a text” can be easily done with a mouse, but the manual must use lots words to explain how this is done with keyboard. Example:

Setting the mark at a position in the text also activates it. When the mark is active, Emacs indicates the extent of the region by highlighting the text within it, using the region face. After certain non-motion commands, including any command that changes the text in the buffer, Emacs automatically deactivates the mark; this turns off the highlighting.

What the hell? A mouse click'n'drag, be done with it.


Here's the original.

問:這些文件怎麼看起來怪怪的?

答:我覺得Emacs官方寫的文件都很奇怪很囉嗦,因為:

第一,寫的人把用的人都當做初學者,沒有使用編輯器的經驗、甚至沒有使用電腦的經驗。看看這段話: "Files are named units of text which are stored by the operating system for you to retrieve later by name.",拜託,我還需要你教我“檔案”是什麼東西嗎?

第二,寫文件的人似乎停留在1980年代,裡面很多術語都很老舊了,看看這個: " We use the term frame to mean the entire terminal screen or graphical window used by Emacs."、"The main area of the frame, below the tool bar (if one exists) and above the echo area, is called the window.",哇哩咧,你的frame是我的window,你的window又是什麼鬼?

第三,寫文件的人還在緬懷以前的時光,有些在以前算特殊的功能,已經不再特殊了,例如: "You are reading about GNU Emacs, the GNU incarnation of the advanced, self- documenting, customizable, extensible editor Emacs.",啥?self-documenting?哪個編輯器沒有說明文件啊?extensible, customizable?現在很多編輯器多多少少都可以客製化了。

第四,有些功能太過強大,所以解釋起來很麻煩: "You can yank text from the kill ring into any position in a buffer, including a position in a different buffer; the kill ring is shared by all buffers.",yank&kill在這裡等於cut&paste,而kill ring呢?大概是指你cut好幾次後,不會只剩下最後一次cut的東西,之前的都還在kill ring裡面。

第五,因為Emacs以鍵盤為主,雖然現在有滑鼠可以用了,可是其中心思想還是要求所有的功能動作都要能用鍵盤達到,以至於像“把一段文字圈選”這種以滑鼠可以輕易達到的功能,手冊要用好多篇幅講解鍵盤的指令。譬如說: "Setting the mark at a position in the text also activates it. When the mark is active, Emacs indicates the extent of the region by highlighting the text within it, using the region face. After certain non-motion commands, including any command that changes the text in the buffer, Emacs automatically deactivates the mark; this turns off the highlighting. ",什麼鬼啊,滑鼠點一點拉一拉就好了啦。


For a overall discussion of Emacs Manual problems, see: Problems of Emacs's Manual.

2010-08-08

PowerShell for Unixers

Perm url with updates: http://xahlee.org/powershell/PowerShell_for_unixer.html

PowerShell for Unixers

Xah Lee, 2009-07-26, 2010-08-08

This pages shows the equivalent of PowerShell for common unix commands related to text processing, such as grep, head, find, sort, uniq, wc etc. The version of unix tool used here are Bash and GNU. (that's most linuxes, but not BSDs, Solaris, Mac OS X.)

For simpler things such as “cd”, “mkdir”, “ls”, etc, see PowerShell as Bash.

Quick Mirror

Here is a quick table of constructs that are roughly of the same purpose.

DescbashPowerShell
create new filetouch ffni ff -type file
cat ffcat ff
cat f1 f2 > new.txtcat f1, f2 > new.txt
Display first n lineshead -n 50 ffcat ff | select -first 50
tailcat file | select -last 50
split?
list dirsfind . -type dGet-ChildItem . -Recurse -name
find . -type f?
find . -name "*html"Get-ChildItem . -Recurse -name -include *html
find . -size 0ls . -recurse | where {$_.length -eq 0}
find . -type f -size 0 -exec rm {} \;?
grep xyz f.txtselect-string f.txt -pattern xyz -CaseSensitive
grep xyz *htmlselect-string *html -pattern xyz -CaseSensitive
grep's --ignore-case or -iselect-string without -CaseSensitive
grep's --invert-matchselect-string with -NotMatch
grep's --files-with-matches
cmpCompare-Object
compare file differencediff f1 f2diff (cat f1) (cat f2)
sed?
print nth columnawk '{print $12 , $7}'?
sortsort
uniqsort -Unique
wcmeasure-object
tr
basename
dirname

Work In Progress

Note: this page is a mess. It's work in progress. (started when i wished to convert my log processing bash script to PowerShell)

todo, shew PowerShell equivalent of this:

find . -print0 | xargs -0 -l -i echo "{}";
find . -name "*bmp" -print0 | xargs -0 -l -i basename -s ".bmp" "{}" | xargs -0 -l -i convert "{}.bmp" "{}.png". 

Detail

touch
# creating a new file in current dir
touch myfile.txt
# creating a new file in current dir
new-item -name myfile.txt -type "file"
Redirect “>”
# put content in a file
echo "some" > myfile.txt
echo "some more" >> myfile.txt # append
# put content in a file
"some" > myfile.txt
"some more" >> myfile.txt # append

Note that, by default, the PowerShell redirect operator ">" creates files with little endian utf-16 encoding, and lines are hard-wrapped at 80 chars, and line ending uses Windows convension of "\r\n" (ascii 13 and 10).

On unixes, the conventional file encoding is utf-8, and lines are not hard-wrapped (sometimes truncated (deleted) silently), and line ending uses "\n" (ascii 10).

To create unix style output, use out-file, like this:

"1'n2'n3" | out-file -Encoding utf8 -width 999000 myfile.txt

However, the line ending used is still "\r\n". To create unix line ending of just "\n", use:

... | Out-String | %{ $_.Replace("`r`n","`n") } | out-file ...

However, the end of the file will still contain a "\r".

cat

Unix “cat” can be used to read a file, or join several files. PowerShell equivalent is “get-content” with alias “cat” too.

# display a file content. (cat is alias of get-content)
cat myfile.txt

Note that by default, PowerShell assumes ascii. You can set your $OutputEncoding like this:

# set $OutputEncoding to utf-8
$OutputEncoding = New-Object -typename System.Text.UTF8Encoding

Thanks to Shivashis Saha for addition on “cat”. He also sends the following:

split

For example, if you want to split a line based on ":", you can use the following line:

(given $str is a line with different fields separated by ":")
$temp=@($str -split ":"); 

Super thanks to Jeffrey Snover of Microsoft for helping on about 10 of the items. (he's the inventor of PowerShell)

Gisele Bundchen in US Flag Swimwear

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

Gisele Bundchen in US Flag Swimwear

Xah Lee, 2004-06, 2010-08-07

George mag cover Gisele Bundchen

Cover of 〈George〉 magagize (2000-06). Featuring supermodel Gisele Bundchen, in star'n'stripes swimwear and backdrop.

〈George〉is a American magazine on politics. This issue features a article 〈Why women are DYING to look this good〉. George magazine became defunct in 2001-01.

Gisele Bundchen (b1980) is a Brazilian citizen but German blood.

Photos taken by fashion photographer David LaChapelle.

Here's what seems to be the un-edited photo:

Gisele Bundchen flag 2

Gisele Bundchen

Amica mag cover Gisele Bundchen flag

German magazine 〈Amica〉 cover (2000-08)