Tuesday, December 15, 2009

Breaking Firewalls with OpenSSH and PuTTY

Mike Chirico (mchirico@users.sourceforge.net) or (mchirico@gmail.com)

Copyright (c) 2005 (GNU Free Documentation License)


Last Updated: Sun Jan 27 09:40:26 EST 2008



http://souptonuts.sourceforge.net/sshtips.htm







Breaking Firewalls with OpenSSH and PuTTY

If the system administrator deliberately filters out all traffic except
port 22 (ssh), to a single server, it is very likely that you can still
gain access other computers behind the firewall. This article shows how
remote Linux and Windows users can gain access to firewalled samba, mail,
and http servers. In essence, it shows how openSSH and PuTTY can be used
as a VPN solution for your home or workplace, without monkeying with
the firewall. This article is NOT suggesting you close port 22. These
step are only possible given valid accounts on all servers. But, read on, you
may be surprised what you can do, without punching additional holes through
the firewall -- punching additional holes is a bad idea.


OpenSSH and Linux


From the Linux laptop 192.168.1.106, it is possible to get access
to the resources behind the firewall directly, including SAMBA
server, HTTP Server, and Mail Server which are blocked from the
outside by the firewall. The firewall only permits access to
the SSH Server via port 22; yet, as you will see, it is possible
to get access to the other servers.




The SSH Server is seen as 66.35.250.203 from the outside. To tunnel
traffic through the SSH Server, from the Linux laptop 192.168.1.106, create
the following "~/.ssh/config" file, on the Linux laptop.
~/.ssh/config
## Linux Laptop .ssh/config ##
Host work
HostName 66.35.250.203
        User sporkey
        LocalForward 20000 192.168.0.66:80
        LocalForward 22000 192.168.0.66:22
        LocalForward 22139 192.168.0.8:139
        LocalForward 22110 192.168.0.5:110

Host http
HostName localhost
        User donkey
        Port 22000
        HostKeyAlias localhosthttp

This file must have the following rights.
$  chmod 600 ~/.ssh/config
Take a look again at the file above. Note the entry
for "LocalForward 22000 192.168.0.66:22", and compare this
to the network diagram. The connection to the SSH Server
is made by running the command below, from the Linux laptop (192.168.1.106).
$ ssh -l sporkey 66.35.250.203

Quick hint: the above command can be shortened, since the user name "sporkey"
and the "HostName" are already specified in the config file. Therefore, you
can use "ssh work" as shown below.
$ ssh work

After this connection is made, it is possible to access the
HTTP Server directly, assuming the account donkey has access to
this server. The following command below is executed on the
Linux laptop (192.168.1.106). Yes, that is on the Linux laptop in
a new window. Again, this will be executed from 192.168.1.106 in a
new session. So note here the Linux laptop is getting direct access to
(192.168.0.66). Reference the diagram above. This is the "localhost" of
the Linux laptop -- you got this, right? The ssh sessions are initiated
from the Linux laptop.
$ ssh -l donkey localhost -p 22000
Since the config file maps "http" to localhost port 2200, the above command
can be shortened to the following:
$ ssh http
Wait, there is a better way. Instead of creating two terminal sessions, one
for "ssh work", then, another one for "ssh http", why not put it all together
in one command.
$ ssh -N -f -q work;ssh http
The above command will establish the connection to work, forwarding the necessary
ports to the other servers. The "-N" is for "Do not execute remote command", the
"-f" requests ssh to go to the background, and "-q" is to suppress all warnings
and diagnostic messages. So, still not short enough for you? Then create an
alias, alias http='ssh -N -f -q work;ssh http' and put that in your "~.bashrc"
file, which is about as short as you can get, since typing http on the
command line would get you to the HTTP server.


To copy files to this server, the command below is used. Note
uppercase "-P" follows "scp". If you are in the ".ssh" directory you will see
an "authorized_keys2" and maybe an "authorized_keys",
which you may want to append to the like files on the destination server. These
files are only listed as an example. Any file could be copied; but, if you copy
these files to the remote server and append the contents to the remote server's
authorized_key* files, then, you will not be prompted for a password the next time
you make a connection. See Tip 12 in
Linux Tips
.
You will need to create an authorized_keys2 and authorized_keys file with all the public
keys of the computers that will connect. Below, assume you have these keys in the
currently directory on the laptop, and you want to copy this to the HTTP Sever [192.168.0.66].
The keys go in "~/.ssh/authorized_keys2" for ssh2. Again, take a look at
Linux Tips

. You
do not want to write over any existing keys.
$ scp -P 22000 authorized_keys* donkey@localhost:./.ssh/.
But, because you have everything in the "config" file, you can shorten the above
command to the following:
$ scp authorized_keys* http:./.ssh/.

The following command, executed from the Linux laptop, will download
the web page from the remote server (192.168.0.66).
$ wget http://localhost:20000/

Linux Laptop becomes Company Web Server -- Power of RemoteForward


Suppose the Linux laptop is running a web server. Is it possible for the
people in the company to view this, the web server on the laptop (192.168.1.106), when
they attach to HTTP Server (192.168.0.66)? Absolutely. Think about this because what
is being suggested here is that a laptop, with no direct access to the HTTP server, is
actually going to take over the company web server. Yes, that is exactly what will be shown
here; although, instead of taking over the company web server, which is running on port 80 of
(192.168.0.66), you will see how to add an additional web server on port 20080. However, if
you are intent upon taking over the company web server, you would have to perform similar steps
as root, since only root has the ability to take over the privileged ports. But, start with
this example first, then, you'll see how to do this on port 80. To perform this magic,
the "/etc/ssh/sshd_config", on the company web server (192.168.0.66), must have the
variable "GatewayPorts" set to "yes", otherwise, only the users logged into HTTP Server will
be able to see the laptop's web page. Instead, we want everyone in the company to have direct
access to the added port.
GatewayPorts yes
After making the change, you will need to restart sshd.
$ /etc/init.d/sshd restart
In the Linux laptop's "~/.ssh/config" add the following entry
RemoteForward 20080 localhost:80 so that
the complete "~/.ssh/config" is shown below.
## Updated Linux Laptop .ssh/config  ##
Host work
HostName 66.35.250.203
        User sporkey
        LocalForward 20000 192.168.0.66:80
        LocalForward 22000 192.168.0.66:22
        LocalForward 22139 192.168.0.8:139
        LocalForward 22110 192.168.0.5:110

Host http
HostName localhost
        User donkey
        Port 22000  
        RemoteForward 20080 localhost:80
        HostKeyAlias localhosthttp
If you perform a "netstat -l" from 192.168.0.66, the remote company
web server, you should see the following:
tcp  0  0 *:20080 *:*  LISTEN
This means that anyone, in the company, can view this webpage http://192.168.0.66:20080/ on
port 20080. If you wanted port 80, the default http port, the connected
user would have to have root privileges.
If you did not change the "/etc/ssh/sshd_config" file, "GatewayPorts" defaults
to "no". And executing a "netstat -l" (that's an ell), would return the following:

tcp   0 0 ::1:20080 *:* LISTEN
With the above restrictions, only users on the computer 192.168.0.66 would see the webpage on
192.168.1.106 from port 20080. This is what happens by default, since "GatewayPorts" is set to no.
By the way, did you figure out what the HostKeyAlias command does? If you make multiple
localhost entries in your config file without HostKeyAlias, .ssh/known_hosts will contain
multiple entries for "localhost" with different keys. Try it without HostKeyAlias and it
should bark at you.
For references on generating ssh key pairs, securing an ssh server from
remote root access, and samba mounts through an ssh tunnel see (TIP 12, TIP 13,
and TIP 138) in
Linux Tips
listed at the end of this article. In addition,if you are a system administrator, may want to take note of
(TIP 14), keeping yearly logs, and (TIP 26), which shows how to kill a user
and all their running processes. In addition, the following (TIP 10, TIP 11, TIP 15, TIP 24,
TIP 47, TIP 52, TIP 89, TIP 104, TIP 148, and TIP 150) may help with system security.







PuTTY for WindowsXP



From your Windows XP laptop, you want access to the following
resources behind a firewall "SSH server", "Mail Server", and
"HTTP Server". The only port allowed in is ssh, port 22, to
the "SSH Server". So, how do you get access, from the
laptop to the other resources using an ssh tunnel?






Step 1: (Download PuTTY)

Download putty.exe and

plink.exe. Although
plink.exe is not needed, it provides some handy features you may end up using later.
I normally put the files in "c:/bin", then, add this directory to the path.




Step 2: (Load the IP Address of Your Server)


Substitute the IP address 66.35.250.203 for the IP address of your ssh server
and save it. Note 66.35.250.203 really is sourceforge, so unless you're access
projects on sourceforge, you probably want a different IP address.







Step 3: (Create the Necessary Tunnels)

There are 2 additional servers you need access to. The "HTTP server" 192.168.0.66,
and "Mail server" 192.168.0.5. Click on Tunnel and fill in the following values.
The HTTP server works on port 80, so enter 80 in the Source port. The destination
is 192.168.0.60:80. Hit "Add" to commit this entry.



Your listing should be similar to the following. Make sure each entry has an
"L" listed in front of it. Local port 25 will now go to server 192.168.0.5
on port 25. But, ports 110 and 25 will go to server 192.168.0.5.








Step 4: (Testing the Connection)


If you now open your ssh connection, click on "Sourceforge", or whatever you
name it, then, you can browse the data on the "HTTP Server" by filling
in local host at the browser. It makes sense to "Check" the connection at
this stage -- remember to put in the correct IP addresses for your server.








Step 5: (Setting up Mail)


Mozilla Thunderbird is an excellent mail package. It will work in place
of Microsoft Outlook, when connect to your work's Exchange, Postfix, or Sendmail server.
The server location is localhost. And notice the option below to "Leave messages on server". If you have another email client
on your workstation at work, then, you might want to keep the mail on the server.








Step 6: (Getting Access to Samba Shares -- Loopback Adapter)


From the Windows XP computer, you want to add a Micosoft loopback Adapter. From the
control panel, follow the steps below. By the way, it is possible to add more than
one adapter.
1.  Yes, I already connected the hardware 
  2.  Add a new hardware device (bottom of menu)
  3.  Install the hardware that I manually select from a list (Advanced)
  4.  Select Network Adapters
  5.  Micosoft Loopback Adapter




Once the adapter is added, you must assign an IP address. The first adapter will
be assigned 10.0.0.1, the second will be assigned 10.0.0.2, etc. DO NOT enter a "Default gateway".



The second adapter will have the IP address 10.0.0.2. Remember, there are two
samba servers in the network diagram. Both the HTTP server and the SAMBA server
have samba shares. Again, DO NOT enter a "Default gateway".



The loopback Adapters should appear in the control panel








Step 7: (Getting Access to Samba Shares -- SSH Configuration Settings)

Now you want to go back into the Putty configuration. In the "Source port"
text box, yes it is small, enter 10.0.0.1:139; but note, the image below
only shows 0.0.1:139 because it has scrolled to the left. Also, enter 192.168.0.66:139
for the destination address. When done, click "Add".




The completed entry should look like the following:



You can repeat the same procedure above for more samba shares, if you want. Although not
shown, the same procedure is used for 10.0.0.2:139; but, it will have a destination
of 192.168.0.8. Again, there are two samba shares in the network diagram.






Step 8: (Getting Access to Samba Shares -- View It)

To view the samba share, click Start/Run and type in \\10.0.0.1\








Special Note

You will probably have to reboot. Also, read and download the
following

patch from Microsoft.
Also, disable File and Printer Sharing for Microsoft Networks for both
adapters.
Disable NetBIOS over TCP/IP; but, make sure LMHosts Lookup is enabled.








DOWNLOADS


OpenSSH

http://www.openssh.org/

PuTTY


http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html








ADDITIONAL TUTORIALS



Linux System Admin Tips

There are over 200 Linux tips and tricks in this article. That is over 150 pages covering topics from setting
and keeping the correct time on your computer, permanently deleting documents with shred, making
files "immutable" so that root cannot change or delete, setting up more than one IP address on a
single NIC, monitering users and processes, setting log rotate to monthly with 12 months of backups
in compressed format, creating passwords for Apache using the htpasswd command, common Perl commands,
using cfengine, adding users to groups, finding out which commands are aliased, query program text segment
size and data segment size, trusted X11 forwarding, getting information on the hard drive including the
current temperature, using Gnuplot, POVRAY and making animated GIFs, monitoring selective traffic with
tcpdump and netstat, multiple examples using the find command, getting the most from Bash, plus a lot more.
You can also down this article as a text document here

for easy grepping.



Linux Quota Tutorial

This tutorial walks you through implementing disk quotas for both users
and groups on Linux, using a virtual filesystem, which is a filesystem created from a disk file. Since quotas
work on a per-filesystem basis, this is a way to implement quotas on a sub-section, or even multiple subsections
of your drive, without reformatting. This tutorial also covers quotactl, or quota's C interface, by way of an example
program that can store disk usage in a SQLite database for monitoring data usage over time.




Google Gmail on Home Linux Box using Postfix and Fetchmail

If you have a Google Gmail account, you can relay mail from your home linux system. It's a good exercise in
configuring Postfix with TLS and SASL. Plus, you will learn how to bring down the mail safely, using
fetchmail with the "sslcertck" option, that is, after you have verify and copied the
necessary certificates. You'll learn it all from this tutorial. And you'll have Gmail running on your local Postfix MTA.




Create your own custom Live Linux CD

These steps will show you how to create a functioning Linux system,
with the latest 2.6 kernel compiled from source, and how to integrate
the BusyBox utilities including the installation of DHCP. Plus, how
to compile in the OpenSSH package on this CD based system.
On system boot-up a filesystem will be created and the
contents from the CD will be uncompressed and
completely loaded into RAM -- the CD could be removed
at this point for boot-up on a second computer. The remaining
functioning system will have full ssh capabilities.
You can take over any PC assuming, of course, you have
configured the kernel with the appropriate drivers and the
PC can boot from a CD.



MySQL Tips and Tricks


Find out who is doing what in MySQL and how to kill the process,
create binary log files, connect, create and select with Perl and Java,
remove duplicates in a table with the index command, rollback and how to apply,
merging several tables into one, updating foreign keys, monitor port 3306 with the tcpdump command,
creating a C API, XML and HTML output, spatial extensions, complex selects, and much more.



SQLite Tutorial

This article explores the power and simplicity of sqlite3,
first by starting with common commands and triggers, then the attach statement with the union operation is introduced in a way that allows multiple tables, in separate databases, to be combined as one virtual table, without the overhead of copying or moving data. Next, the simple sign function and the amazingly powerful trick of using this function in SQL select statements to solve complex queries with a single pass through the data is demonstrated, after making a brief mathematical case for how the sign function defines the absolute value and IF conditions.


Lemon Parser Tutorial
Lemon is a compact, thread safe, well-tested parser generator written by D. Richard Hipp. Using a parser generator, along with a scanner like flex, can be advantageous because there is less code to write. You just write the grammar for the parser. This article is an introduction to the Lemon Parser, complete with examples.





Errata
Special thanks to the following people who pointed out needed corrections.
[Sun Oct 9 13:32:01 EDT 2005] Kent West





Chirico img




Mike Chirico, a father of triplets (all girls) lives outside of
Philadelphia, PA, USA. He has worked with Linux since 1996, has a Masters
in Computer Science and Mathematics from Villanova University, and has
worked in computer-related jobs from Wall Street to the University of
Pennsylvania. His hero is Paul Erdos, a brilliant number theorist who was
known for his open collaboration with others.





Mike's notes page is souptonuts. For
open source consulting needs, please send an email to




mchirico@gmail.com
. All consulting work must include a donation to
SourceForge.net.

必要的“馬後炮”該放

河南大平礦特大礦難事故牽動著人們的心,成為人們街談巷議,茶余飯後關注的熱點。從事故原因到吸取事故教訓,從安全機制到追究事故責任等話題,人們各抒己見,而有人對此評價:“這是‘馬後炮’”。



一個人、一個單位出了事故,總會引來不少人的議論,而這些議論往往被說成是“馬後炮”,認為是“事後諸葛亮”,似乎其意義和所起的作用並不大。但是,筆者卻以為,必要的“馬後炮”不僅要放,更要放好、放響,讓大家都記住。



出事故總是有原因的,不是主觀上的,就是客觀上的,這就很有必要查找“病因”,進行“醫治”。常言道:旁觀者清,當局者迷。這時旁人的“馬後炮”往往能“打”到“靶子”上,“轟”在要害上,對查找事故原因,吸取事故教訓,減少和避免再度發生事故,從而達到“前事不忘,後事之師”有著積極的意義。



說實在的,人們多麼希望少放和不放“馬後炮”。但是,事與願違,事故不絕。既然出了事故,就要面對現實,冷靜、虛心地接受事故教訓,要有任憑“馬後炮”“打”和“轟”的姿態。如果這時還不讓說,不讓人講,不讓人議,還拒絕“馬後炮”、反對“馬後炮”、害怕“馬後炮”,談何查找事故原因?談何吸取事故教訓?談何減少和避免事故重演?



當然,筆者在這裏並不是讚美“馬後炮”,我也同樣希望少聽到和不聽到“馬後炮”。這是因為,“馬後炮”畢竟是在事故發生以後,已經給國家、人民的生命財產造成了不可挽回的損失。如果,能把事故消滅在萌芽狀態,杜絕了事故,沒有了“馬後炮”豈不更好。這就需要我們盡量把預防事故的工作做在前頭,思想認識到位,各項規章制度落實到位,把該放的“炮”放在前面。這樣“馬”行在前面,“炮”打在前頭,自然要比“馬後炮”作用大、效果好。但是,事故不絕,“馬後炮”不絕。這也是事實。



“馬後炮”在不少人的眼裏和心目中的形象及“名聲”並不怎麼好,也不受歡迎。這裏,恐怕一個很重要的原因,就是有些“馬後炮” “亂打”、“瞎轟”。有的“馬後炮”專揭別人之短,出他人之醜,說風涼話,甚至捕風促影,添油加醋,說三道四。這樣的“馬後炮”敗壞了“馬後炮”的名聲,非但不該放,而且要堵“炮眼”、封“炮口”。對有利于總結經驗,吸取教訓;有利于幫助提高,取長補短,把事情辦好的客觀公正的“馬後炮”,不僅要放,而且還應該給予提倡和鼓勵其放。

(責任編輯:華明)

本欄目稿件為新華網專稿,媒體轉載請注明稿件來源。
歡迎廣大網友投稿(comments@xinhuanet.com)

馬後炮

馬後炮

--------------------------------------------------------------------------------

  現時愛下象棋的人很多,象棋中的用語也就往往變成人們日常的口頭用語了。「馬後炮」便是屬於這種日常的口頭用語之一。有幾位讀者來信問道:馬後炮怎麼會變成了口頭語呢?馬後炮的原意究竟是什麼?現在我們說的馬後炮與它的原意是相符的嗎?
  要回答這些問題,首先必須弄清楚:人們口頭上常說的馬後炮,到底盡包括些什麼意思呢?我沒有進行普遍的調查,似乎也不需要甚至不可能對這一類問題進行普遍的調查,因此要想對以上問題,做出完全肯定的回答還有困難。但是,大體說來,人們日常所謂馬後炮,主要是指的人們主觀認識和行動落後於客觀實際的某些情況。
  當著一件事情發生以後,如果我們沒有及時地採取必要的措施,而是過了許久才採取一些措施,那麼,照一般人的口頭語,這就叫做馬後炮。如果我們對於這件事情發生的原因、經過等等,也是在很久以後才弄清楚,那就更要被批評為馬後炮了。這就可見,馬後炮在一般人的口頭語中,總是帶著消極的涵義。這一點似乎是很明顯的了。
  然而,馬後炮原來的意思是否果真如此,卻還需要再做一番查考。從何處去查考呢?這又是一個難題。在歷史上象棋出現的時間可能稍晚,起先人們只下圍棋,而不下象棋。據漢代許慎的《說文解字》載:「奕,圍棋也。」這就可見圍棋出現的時間最早,所以凡是下棋都指的圍棋。又據晉代張華的《博物誌》說:「堯造圍棋,以教子丹朱。或云:舜以子商均愚,故作圍棋以教之。」把圍棋說成是堯舜所創造,這當然是荒唐的;但是,張華此書至少可以證明圍棋在晉代以前就出現了。其他類似這樣的說法還很多。周秦諸子及《山海經》上也都有關於弈棋的記載,大概圍棋早在春秋戰國時代已經很流行,當無疑義。
  不過,圍棋只有黑白之分,無法運用什麼馬後炮之類的戰法。馬後炮只能用於象棋,這也是毫無疑問的。而象棋的出現,據漢代劉向的《說苑》所載,也在戰國時代。這是否可信還待考。至於有人說象棋也是創始於舜,那是杜撰。還是劉向說的創於戰國時代較有可能性,他說:「雍門周謂孟嘗君曰:足下燕居斗象棋,亦鬥戰之事乎?」又說:「燕則斗象棋而舞鄭女。」照這個說法,戰國時代已經有了象棋。不過,當時的象棋究竟是什麼樣子就不得而知了。
  根據多數古籍的記載,象棋被公認為北周武帝所創。如明代的楊慎、胡文煥、謝肇淛等人都抱這樣的看法。而且北周庚信有《象戲賦》《進象經賦表》兩篇作品可以作證。所謂象戲指的就是下象棋的遊戲,所謂象經乃是講解像棋的圖經。
  有了象棋的以後,馬後炮也就出現了。
  古代的象棋當然和我們現在的象棋還不一樣。按明代胡文煥的《事物紀原》所載:「象棋乃周武帝所造,有日月星辰之象,與今象棋不同。」這裡雖然提到日月星辰之象,實際上什麼樣子還不能確切知道。而明代上距北周,歷時太久,傳述也未必可靠。倒是宋代司馬光的《古局象棋圖》頗有參考的價值。此圖以戰國七雄並峙之局,列為象戲。七國各有一主將、一偏將、一裨將、一行人、一炮、一弓、一弩、二刀、四劍、四騎。這就是說,一盤棋分七個部分,代表七國,下棋的人可以七個,也可以六個、五個、四個、三個、採取合縱連橫的方法;每一國有十七個棋子,其中四騎等於四個馬,但是只有一個炮。這個炮的行動規律與現在象棋中的炮差不多。圖中說明:
  「一炮,直行無遠近,前隔一棋乃可擊物;前無所隔,及隔兩棋以上,則不可擊。」
  這個規定顯然與現在象棋中的炮基本相同。至於馬的行動規律,圖中又說明:
  「四騎,曲行四路,謂直一斜三。」
  不難設想,有四個馬,可以曲行四路,那末,儘管只有一個炮,而馬後炮的出現機會一定要比在今日的象棋中更多一些。因此,我們無妨下一個斷語,就是說:馬後炮是隨著古象棋的出現而同時出現的。
  但是,在古象棋中出現的馬後炮,是很厲害的一著,它往往可以「將死」對方,正如現在象棋中的馬後炮也常常是能致對方於死地的絕招一樣。這們看來,馬後炮原來的涵義是積極的,根本不同於現時人們口頭所說的馬後炮的那種消極的涵義。
  從積極的涵義轉為消極的涵義,這個變化太大了。然而,這類事情卻也是常有的,豈隻馬後炮而已哉?

Monday, December 14, 2009

concurrent Screen sessions shared

Advanced use of Screen

As mentioned earlier, you can create multiple, concurrent Screen sessions, where each session can manage a suite of windows. Each session has a unique identifier; use screen -list to catalog all available sessions. As with a window, you can name a session to refer to by its handle. Use screen -S label to assign a label to the new session.

Sharing is one of the best uses of a named Screen session. If permitted, you can connect to an existing session and collaborate with other users within any of the session's windows. You can even switch to another window within the session independently! If you're in the same window as another, anything typed or displayed is reflected to all partners. Let's try it:

1. Choose a machine to work on, and log in.

2. Type screen -S sharing -t one> to create a new Screen session named, aptly, sharing, and a new window named one.

3. Create a second window with screen -t two.

4. If you like, check your work with Ctrl-a, then d, screen -list, screen -r sharing, and Ctrl-a, then ".

5. Emit some output in the window named one by typing echo in that window.


6. On the same machine, open a second login window.

7. Within that window, type screen -x -r sharing -p one.
The -x option specifies multi-user mode; -p one attaches directly to the window named one. You should immediately see the same output as the other login session, as shown in Figure 9.

Using each login window, run UNIX® commands to produce output, click Screen keyboard shortcuts to switch among the windows in the shared session, and watch the results.

安裝 memcache for php 多重伺服器共享 Session

今天來玩看看 memcache 看看,話說 memcache 是個非常好用的東西,可以參考官網作法 連結,其實我在前一個工作,就有老闆問我說,像公司作這麼多網站,有沒有辦法統整成一個,然後底下各種服務,只需要登入過一次就好,而不必重複登入,畢竟會讓使用者覺得很煩,所以就有了 memcache 這東西出來,底下就來介紹 FreeBSD 的安裝方式

* 安裝方法:

安裝 ports 的套件 memcache 跟 pecl-memcache
cd /usr/ports/databases/memcached; make install clean
cd /usr/ports/databases/pecl-memcache; make install clean

然後他會把 extension=memcache.so 寫到 /usr/local/etc/php/extensions.ini
然後你只需要重新啟動 apache 即可,還有把 memcached 服務打開
所以請下底下指令
echo "memcached_enable=\"YES\"" >> /etc/rc.conf
/usr/local/etc/rc.d/memcached start
/usr/local/etc/rc.d/apache22 restart

* 測試方法:

寫一個php檔案,然後在執行他,範例檔如下
<?php
$memcache = new Memcache; //Star memcache
$memcache->connect('localhost', 11211) or die ("Could not connect"); //Connect Memcached
$memcache->set('uname', 'appleboy');
$get_value = $memcache->get('uname'); //
echo $get_value;
print "
";
$b = $memcache->getStats();
print_r($b);exit;
?>

如果你需要用 session 寫法,就如下了,這是別人寫好的範例
<?php
$mem_cache_obj = new Memcache;
$mem_cache_obj->connect('localhost', 11211) or die ("Could not connect");
class Shared_Session
{
  function init()
  {
    ini_set("session.gc_maxlifetime", 3600);
    ini_set("session.use_cookies", 1);
    ini_set("session.cookie_path", "/");
    ini_set("session.cookie_domain", ".wu-boy.com");

    session_module_name("User");
    session_set_save_handler(
        array("Shared_Session", "open"),
        array("Shared_Session", "close"),
        array("Shared_Session", "read"),
        array("Shared_Session", "write"),
        array("Shared_Session", "destroy"),
        array("Shared_Session", "gc")
        );
  }

  function open($save_path, $session_name) {
    return true;
  }

  function close() {
    return true;
  }

  function read($sesskey) {
    global $mem_cache_obj;
    return $mem_cache_obj->get($sesskey);
  }

  function write($sesskey, $data) {
    global $mem_cache_obj;
    $mem_cache_obj->set($sesskey, $data, 3600);
    return true;
  }

  function destroy($sesskey) {
    global $mem_cache_obj;
    $mem_cache_obj->delete($sesskey);
    $mem_cache_obj->flush_all();

    return true;
  }

  function gc($maxlifetime = null) {
    return true;
  }
}

Shared_Session::init();

?>

這是利用 memory 存取資料,所以想必一定比妳用 database 或者是檔案存取更快了,但是如果一台機器已經用完記憶體了,所以我們必須新增另一台 memcache server了,所以新增方法如下
<?php

/* OO API */

$memcache = new Memcache;
$memcache->addServer('memcache_host', 11211);
$memcache->addServer('memcache_host2', 11211);

/* procedural API */

$memcache_obj = memcache_connect('memcache_host', 11211);
memcache_add_server($memcache_obj, 'memcache_host2', 11211);

?>

在網路上找到一篇,有人寫好的 memcache class php-memcached-client 官網:點我

範例:
<?php
//  包含 memcached 类文件
require_once('memcached-client.php');
//  选项设置
$options = array(
    'servers' => array('192.168.1.1:11211'), //memcached 服务的地址、端口,可用多个数组元素表示多个 memcached 服务
    'debug' => true,  //是否打开 debug
    'compress_threshold' => 10240,  //超过多少字节的数据时进行压缩
    'persistant' => false  //是否使用持久连接
    );
//  创建 memcached 对象实例
$mc = new memcached($options);
//  设置此脚本使用的唯一标识符
$key = 'mykey';
//  往 memcached 中写入对象
$mc->add($key, 'some random strings');
$val = $mc->get($key);
echo "n".str_pad('$mc->add() ', 60, '_')."n
";
var_dump($val)."
";
//  替换已写入的对象数据值
$mc->replace($key, array('some'=>'haha', 'array'=>'xxx'));
$val = $mc->get($key);
echo "n".str_pad('$mc->replace() ', 60, '_')."n
";
var_dump($val)."
";
//  删除 memcached 中的对象
$mc->delete($key);
$val = $mc->get($key);
echo "n".str_pad('$mc->delete() ', 60, '_')."n
";
var_dump($val)."
";
?>

不過大家可以把 debug mode 關掉,不然畫面會比較亂一點。
再來大家可以跟資料庫連接,然後把SQL讀出來的資料寫到 memcache中
範例:
<?php
$sql = 'SELECT * FROM users';
$key = md5($sql);   //memcached 对象标识符
if ( !($datas = $mc->get($key)) ) {
    //  在 memcached 中未获取到缓存数据,则使用数据库查询获取记录集。
    echo "n".str_pad('Read datas from MySQL.', 60, '_')."n";
    $conn = mysql_connect('localhost', 'test', 'test');
    mysql_select_db('test');
    $result = mysql_query($sql);
    while ($row = mysql_fetch_object($result))
        $datas[] = $row;
    //  将数据库中获取到的结果集数据保存到 memcached 中,以供下次访问时使用。
    $mc->add($key, $datas);
} else {
    echo "n".str_pad('Read datas from memcached.', 60, '_')."n";
}
var_dump($datas);
?>

reference

非mmcache!Memcached的應用:多網站伺服器 PHP 共享 Session
PHP & memcached
http://blog.johnpupu.tw/?p=62

博觀而約取,厚積而薄發

理論和觀念都有淘汰的一日,頭腦和思考則永不淘汰。

博觀而約取,厚積而薄發

◎ 施保旭

照相機圖片留意日本書籍出版或是對日文翻譯書有興趣的人便會發現,日本人對於「備忘錄」或是「記事本」的應用研究有著非比尋常的執著,幾乎每年都會有新的著作問世,有時也會有銷售數十萬本並進入排行榜的暢銷書出現。

日本人是個拘謹的民族,常受到的批評是抄襲的多、原創的少。但是,如果靜下心來觀察,一再強調過往印象的此類批評如今幾乎已淪為盲目的攻擊。現今不論影視、電玩、電子家電等等,哪一個領域看不到日本人的創作與發明?其影響甚至在社會中形成了「哈日族」之術語。從管理面而言,其最令人矚目的,便是從小地方發現改進之道所下的功夫了。記事本的研究,便是此一思維下的產物。

日本人運用記事本,最重要的精神便是鉅細靡遺地紀錄工作或生活上的所見、所思、所為,並於紀錄之後,進行彙整與分析。例如:    

*綜合相關報導,以整理出目前的熱門話題以及社會大眾生活上的困擾。

*分類整理日常飲食紀錄,研究出身心平衡與飲食習慣的關係。

可以看出,蒐集大量的資料,再由資料中整理出獨特的體系;以此體系為出發點,加以解讀、分析、創新,進而提出適當的方案,這便是日本人逐步改良的秘密。

北宋大文豪蘇東坡總結自己為學與做人的基本觀點所提出的「博觀而約取,厚積而薄發」,實在是知識管理的不傳心法。也就是說,廣博地學習知識並加以研判,藉由長期的積累而淬煉出自己的獨特見解。因此,由資料的蒐集,直至創新智慧的發光,中間顯然存在一些工具與方法,值得我們深入探討。

個人知識庫的建置是基本功夫

所謂「資料」,代表彼此間無多大相關的原始材料,這些材料必須經過整理與篩選之後,理出其結構性關係,才能稱為「資訊」。即便是最簡單的資料蒐集,也有需要注意之處。因為,在大部分情況下,資料乃來自於他人,這些資料在發布時,設定的讀者類型可能與我們不同;此外,同樣的資料面對不同的需要時,資料間的自變數與因變數會隨著目的之不同而有所不同。而許多零散的資料在累積至一定的量之前,並不容易觀察出其間的結構性關係。因此,蒐集資料或資訊的要訣便在於:只要將來可能有用的資料或資訊、個人再小的靈感,都立即加以紀錄寫下。書寫或紀錄本身其實即伴隨有思考的過程;我們往往發現,在抄錄資訊或是記錄他人意見的同時,自己的意見也跟著自然湧現。

蒐集的資訊必須經過有目的、有系統的整理(包括:篩選、評估、標示、分類、歸納、組合等等),並保證能於需要時很方便地檢索到所需的部分之後,才能稱為「知識」。總而言之,這便是個人知識庫的建置與維護。為了使整個過程能更有效率,進行資訊蒐集時,便該有明確的方向與目標;有了明確的目標之後,Google Alerts或是RSS閱讀器之類的工具軟體都可以用來幫助我們,不致錯失可能有用的最新資訊。

淬煉自己的體系,方能將資訊內化為知識

將知識庫中的概念或重要字詞不斷地加以分割、排列、重新組合,便可以從其中的變化尋得新的靈感、新的知識。因此,建置於個人知識庫中的資訊最好不要長篇大論的存在,而要讓它們經過切割,維持夠小的規模個別存在、更多組合的彈性,因為沒有一定的結論,便可以容納更多自己的思考空間。當然,知識庫內容也需隨時審視其是否過時,並判斷其保存價值。事實上,在資訊氾濫的時代,大部分的人或多或少都犯了資訊焦慮症,深怕自己漏掉了些什麼。然而,盲目蒐集資料而未整理的結果,將因自己的錯誤安全感而更加失去資訊掌握的能力。

這邊所談的是個人知識管理的心法,而個人知識庫的建置,則需要好的工具方能維持。在今(96)年8月號《清流月刊》的〈從維基百科談知識管理〉一文中,我們介紹了維基寫作的做法以及相關免費軟體的功能簡介,建議您不妨一讀。

知識需經實踐方能昇華為智慧

知識庫的建立,讓您成為特定領域的專家。但是,它仍無法直接提供您智慧。智慧無法言傳,只能靠自我發現與成長。擁有可觀的知識,並不代表具有等量的智慧。法國思想家蒙田甚至說過,「初學者的無知是因為沒學過,學者的無知是因為學得太多。」各類的知識必須經過思考、綜合、應用、調適、創新之後,才能變成可以活用的「智慧」。趨勢專家大前研一曾說,「理論和觀念都有淘汰的一日,頭腦和思考則永不淘汰。」換成我們的話便是,知識必須昇華為智慧才不會被時代所淘汰。

「厚積而薄發」的精神在於累積了深厚的知識之後,應該觀察、思考,並尋求適當的機會來加以發揮,而非僅是憑藉知識淵博而自滿傲人。《論語》開卷便是「子曰:學而時習之,不亦悅乎!」真是一語道破知識昇華為智慧的不二法門。老夫子說,隨時將胸中的學問拿出來實證、應用,經由發現理論與實務間的差距,而不斷地自我成長,這是一種無法言喻的快樂。只可惜,多年來的國文教育將它解讀成「學習新知而時時溫習」,強調舊知識的反覆記誦而將實踐的精神給埋沒了。金氏世界紀錄最高智商紀錄保持人瑪麗蓮‧薩凡特(Marilyn vos Savant)便曾表示,「要獲得知識,人必須學習;但要獲得智慧,人必須觀察。」

在實務的訓練上,選定特定主題作為自己努力的目標,待知識庫紀錄至一定的量時,便加以綜合整理成企劃書,然後具體去實現它。企劃書以及實行的結果與經驗,同樣回饋至知識庫中成為往後的參考。「前事不忘,後事之師」,這些經驗其實便是智慧。在現今的社會中,整理紛雜的資訊以提出方案的企劃能力已經是上班族的必備條件。企劃個案的累積,甚至常用格式的整理,將使個人的企劃能力快速提昇。而智慧便在逐漸累積的知識庫內容與經驗中浮現。

不論是知識庫的建置或是理論的實踐,持之以恆的努力與點點滴滴的累積是最主要的關鍵。有人估計,達文西一生總共撰寫了一萬多頁的筆記!這種終生不懈的努力,終於讓科學家、發明家、藝術家、……等等的頭銜都不足以形容其成就的偉大,並千古不衰。

結語

人工智慧(Artificial Intelligence, AI)是電腦科學發展中相當具有戲劇性的一個學門。早期大家對其期望甚殷,甚至認為發展出「會思考的電腦」指日可待。這些過高的期待不斷地破滅之後,這門學問進入了發展的空前低潮,大家終於承認,電腦只能依照人類交給它的規則與事實來做推論。根據這個經驗,人工智慧學者改而研究將特定領域專家的知識輸入電腦,並藉由電腦的高速與大容量進行推論的「專家系統」終獲得相當大的成功。同樣的,面對不斷快速膨脹的資訊,我們必須善用各種工具整理出自己的知識體系,以作為思考與創新的基礎,並以之與外界環境做對照,如此方能結合知識與經驗以創造出無價的智慧。

(作者是世新大學數位多媒體設計學系副教授)

Advice for Computer Science College Students

Advice for Computer Science College Students
by Joel Spolsky
Sunday, January 02, 2005

Despite the fact that it was only a year or two ago that I was blubbering about how rich Windows GUI clients were the wave of the future, college students nonetheless do occasionally email me asking for career advice, and since it's recruiting season, I thought I'd write up my standard advice which they can read, laugh at, and ignore.

Most college students, fortunately, are brash enough never to bother asking their elders for advice, which, in the field of computer science, is a good thing, because their elders are apt to say goofy, antediluvian things like "the demand for keypunch operators will exceed 100,000,000 by the year 2010" and "lisp careers are really very hot right now."

I, too, have no idea what I'm talking about when I give advice to college students. I'm so hopelessly out of date that I can't really figure out AIM and still use (horrors!) this quaint old thing called "email" which was popular in the days when music came on flat round plates called "CDs."

So you'd be better off ignoring what I'm saying here and instead building some kind of online software thing that lets other students find people to go out on dates with.

Nevertheless.

If you enjoy programming computers, count your blessings: you are in a very fortunate minority of people who can make a great living doing work they enjoy. Most people aren't so lucky. The very idea that you can "love your job" is a modern concept. Work is supposed to be something unpleasant you do to get money to do the things you actually like doing, when you're 65 and can finally retire, if you can afford it, and if you're not too old and infirm to do those things, and if those things don't require reliable knees, good eyes, and the ability to walk twenty feet without being out of breath, etc.

What was I talking about? Oh yeah. Advice.

Without further ado, then, here are Joel's Seven Pieces of Free Advice for Computer Science College Students (worth what you paid for them):

1. Learn how to write before graduating.
2. Learn C before graduating.
3. Learn microeconomics before graduating.
4. Don't blow off non-CS classes just because they're boring.
5. Take programming-intensive courses.
6. Stop worrying about all the jobs going to India.
7. No matter what you do, get a good summer internship.

Now for the explanations, unless you're gullible enough to do all that stuff just because I tell you to, in which case add: 8. Seek professional help for that self-esteem thing.

Learn how to write before graduating.

Would Linux have succeeded if Linus Torvalds hadn't evangelized it? As brilliant a hacker as he is, it was Linus's ability to convey his ideas in written English via email and mailing lists that made Linux attract a worldwide brigade of volunteers.

Have you heard of the latest fad, Extreme Programming? Well, without getting into what I think about XP, the reason you've heard of it is because it is being promoted by people who are very gifted writers and speakers.

Even on the small scale, when you look at any programming organization, the programmers with the most power and influence are the ones who can write and speak in English clearly, convincingly, and comfortably. Also it helps to be tall, but you can't do anything about that.

The difference between a tolerable programmer and a great programmer is not how many programming languages they know, and it's not whether they prefer Python or Java. It's whether they can communicate their ideas. By persuading other people, they get leverage. By writing clear comments and technical specs, they let other programmers understand their code, which means other programmers can use and work with their code instead of rewriting it. Absent this, their code is worthless. By writing clear technical documentation for end users, they allow people to figure out what their code is supposed to do, which is the only way those users can see the value in their code. There's a lot of wonderful, useful code buried on sourceforge somewhere that nobody uses because it was created by programmers who don't write very well (or don't write at all), and so nobody knows what they've done and their brilliant code languishes.

I won't hire a programmer unless they can write, and write well, in English. If you can write, wherever you get hired, you'll soon find that you're getting asked to write the specifications and that means you're already leveraging your influence and getting noticed by management.

Most colleges designate certain classes as "writing intensive," meaning, you have to write an awful lot to pass them. Look for those classes and take them! Seek out classes in any field that have weekly or daily written assignments.

Start a journal or weblog. The more you write, the easier it will be, and the easier it is to write, the more you'll write, in a virtuous circle.
Learn C before graduating

Part two: C. Notice I didn't say C++. Although C is becoming increasingly rare, it is still the lingua franca of working programmers. It is the language they use to communicate with one another, and, more importantly, it is much closer to the machine than "modern" languages that you'll be taught in college like ML, Java, Python, whatever trendy junk they teach these days. You need to spend at least a semester getting close to the machine or you'll never be able to create efficient code in higher level languages. You'll never be able to work on compilers and operating systems, which are some of the best programming jobs around. You'll never be trusted to create architectures for large scale projects. I don't care how much you know about continuations and closures and exception handling: if you can't explain why while (*s++ = *t++); copies a string, or if that isn't the most natural thing in the world to you, well, you're programming based on superstition, as far as I'm concerned: a medical doctor who doesn't know basic anatomy, passing out prescriptions based on what the pharma sales babe said would work.

Learn microeconomics before graduating

Super quick review if you haven't taken any economics courses: econ is one of those fields that starts off with a bang, with many useful theories and facts that make sense, can be proven in the field, etc., and then it's all downhill from there. The useful bang at the beginning is microeconomics, which is the foundation for literally every theory in business that matters. After that things start to deteriorate: you get into Macroeconomics (feel free to skip this if you want) with its interesting theories about things like the relationship of interest rates to unemployment which, er, seem to be disproven more often than they are proven, and after that it just gets worse and worse and a lot of econ majors switch out to Physics, which gets them better Wall Street jobs, anyway. But make sure you take Microeconomics, because you have to know about supply and demand, you have to know about competitive advantage, and you have to understand NPVs and discounting and marginal utility before you'll have any idea why business works the way it does.

Why should CS majors learn econ? Because a programmer who understands the fundamentals of business is going to be a more valuable programmer, to a business, than a programmer who doesn't. That's all there is to it. I can't tell you how many times I've been frustrated by programmers with crazy ideas that make sense in code but don't make sense in capitalism. If you understand this stuff, you're a more valuable programmer, and you'll get rewarded for it, for reasons which you'll also learn in micro.
Don't blow off non-CS classes just because they're boring.

Blowing off your non-CS courses is a great way to get a lower GPA.

Never underestimate how big a deal your GPA is. Lots and lots of recruiters and hiring managers, myself included, go straight to the GPA when they scan a resume, and we're not going to apologize for it. Why? Because the GPA, more than any other one number, reflects the sum of what dozens of professors over a long period of time in many different situations think about your work. SAT scores? Ha! That's one test over a few hours. The GPA reflects hundreds of papers and midterms and classroom participations over four years. Yeah, it's got its problems. There has been grade inflation over the years. Nothing about your GPA says whether you got that GPA taking easy classes in home economics at Podunk Community College or taking graduate level Quantum Mechanics at Caltech. Eventually, after I screen out all the 2.5 GPAs from Podunk Community, I'm going to ask for transcripts and recommendations. And then I'm going to look for consistently high grades, not just high grades in computer science.

Why should I, as an employer looking for software developers, care about what grade you got in European History? After all, history is boring. Oh, so, you're saying I should hire you because you don't work very hard when the work is boring? Well, there's boring stuff in programming, too. Every job has its boring moments. And I don't want to hire people that only want to do the fun stuff.

I took this course in college called Cultural Anthropology because I figured, what the heck, I need to learn something about anthropology, and this looked like an interesting survey course.

Interesting? Not even close! I had to read these incredibly monotonous books about Indians in the Brazilian rain forest and Trobriand Islanders, who, with all due respect, are not very interesting to me. At some point, the class was so incredibly wearisome that I longed for something more exciting, like watching grass grow. I had completely lost interest in the subject matter. Completely, and thoroughly. My eyes teared I was so tired of the endless discussions of piling up yams. I don't know why the Trobriand Islanders spend so much time piling up yams, I can't remember any more, it's incredibly boring, but It Was Going To Be On The Midterm, so I plowed through it. I eventually decided that Cultural Anthropology was going to be my Boredom Gauntlet: my personal obstacle course of tedium. If I could get an A in a class where the tests required me to learn all about potlatch blankets, I could handle anything, no matter how boring. The next time I accidentally get stuck in Lincoln Center sitting through all 18 hours of Wagner’s Ring Cycle, I could thank my studies of the Kwakiutl for making it seem pleasant by comparison.

I got an A. And if I could do it, you can do it.

Take programming-intensive courses.

I remember the exact moment I vowed never to go to graduate school.

It was in a course on Dynamic Logic, taught by the dynamic Lenore Zuck at Yale, one of the brightest of an array of very bright CS faculty.

Now, my murky recollections are not going to do proper credit to this field, but let me muddle through anyway. The idea of Formal Logic is that you prove things are true because other things are true. For example thanks to Formal Logic, "Everyone who gets good grades will get hired" plus "Johnny got good grades" allows you to discover the new true fact, "Johnny will get hired." It's all very quaint and it only takes ten seconds for a deconstructionist to totally tear apart everything useful in Formal Logic so you're left with something fun, but useless.

Now, dynamic logic is the same thing, with the addition of time. For example, "after you turn the light on, you can see your shoes" plus "The light went on in the past" implies "you can see your shoes."

Dynamic Logic is appealing to brilliant theoreticians like Professor Zuck because it holds up the hope that you might be able to formally prove things about computer programs, which could be very useful, if, for example, you could formally prove that the Mars Rover's flash card wouldn't overflow and cause itself to be rebooted again and again all day long when it's supposed to be driving around the red planet looking for Marvin the Martian.

So in the first day of that class, Dr. Zuck filled up two entire whiteboards and quite a lot of the wall next to the whiteboards proving that if you have a light switch, and the light was off, and you flip the switch, the light will then be on.

The proof was insanely complicated, and very error-prone. It was harder to prove that the proof was correct than to convince yourself of the fact that switching a light switch turns on the light. Indeed the multiple whiteboards of proof included many skipped steps, skipped because they were too tedious to go into formally. Many steps were reached using the long-cherished method of Proof by Induction, others by Proof by Reductio ad Absurdum, and still others using Proof by Graduate Student.

For our homework, we had to prove the converse: if the light was off, and it's on now, prove that you flipped it.

I tried, I really did.

I spent hours in the library trying.

After a couple of hours I found a mistake in Dr. Zuck's original proof which I was trying to emulate. Probably I copied it down wrong, but it made me realize something: if it takes three hours of filling up blackboards to prove something trivial, allowing hundreds of opportunities for mistakes to slip in, this mechanism would never be able to prove things that are interesting.

Not that that matters to dynamic logicians: they're not in it for useful, they're in it for tenure.

I dropped the class and vowed never to go to graduate school in Computer Science.

The moral of the story is that computer science is not the same as software development. If you're really really lucky, your school might have a decent software development curriculum, although, they might not, because elite schools think that teaching practical skills is better left to the technical-vocational institutes and the prison rehabilitation programs. You can learn mere programming anywhere. We are Yale University, and we Mold Future World Leaders. You think your $160,000 tuition entititles you to learn about while loops? What do you think this is, some fly-by-night Java seminar at the Airport Marriott? Pshaw.

The trouble is, we don't really have professional schools in software development, so if you want to be a programmer, you probably majored in Computer Science. Which is a fine subject to major in, but it's a different subject than software development.

If you're lucky, though, you can find lots of programming-intensive courses in the CS department, just like you can find lots of courses in the History department where you'll write enough to learn how to write. And those are the best classes to take. If you love programming, don't feel bad if you don't understand the point of those courses in lambda calculus or linear algebra where you never touch a computer. Look for the 400-level courses with Practicum in the name. This is an attempt to hide a useful (shudder) course from the Liberal Artsy Fartsy Administration by dolling it up with a Latin name.

Stop worrying about all the jobs going to India.

Well, OK, first of all, if you're already in India, you never really had to worry about this, so don't even start worrying about all the jobs going to India. They're wonderful jobs, enjoy them in good health.

But I keep hearing that enrollment in CS departments is dropping perilously, and one reason I hear for it is "students are afraid to go into a field where all the jobs are going to India." That's so wrong for so many reasons. First, trying to choose a career based on a current business fad is foolish. Second, programming is incredibly good training for all kinds of fabulously interesting jobs, such as business process engineering, even if every single programming job does go to India and China. Third, and trust me on this, there's still an incredible shortage of the really good programmers, here and in India. Yes, there are a bunch of out of work IT people making a lot of noise about how long they've been out of work, but you know what? At the risk of pissing them off, really good programmers do have jobs. Fourth, you got any better ideas? What are you going to do, major in History? Then you'll have no choice but to go to law school. And there's one thing I do know: 99% of working lawyers hate their jobs, hate every waking minute of it, and they're working 90 hour weeks, too. Like I said: if you love to program computers, count your blessings: you are in a very fortunate minority of people who can make a great living doing work they love.

Anyway, I don't think students really think about this. The drop in CS enrollment is merely a resumption of historically normal levels after a big bubble in enrollment caused by dotcom mania. That bubble consisted of people who didn't really like programming but thought the sexy high paid jobs and the chances to IPO at age 24 were to be found in the CS department. Those people, thankfully, are long gone.

No matter what you do, get a good summer internship.

Smart recruiters know that the people who love programming wrote a database for their dentist in 8th grade, and taught at computer camp for three summers before college, and built the content management system for the campus newspaper, and had summer internships at software companies. That's what they're looking for on your resume.

If you enjoy programming, the biggest mistake you can make is to take any kind of job--summer, part time, or otherwise--that is not a programming job. I know, every other 19-year-old wants to work in the mall folding shirts, but you have a skill that is incredibly valuable even when you're 19, and it's foolish to waste it folding shirts. By the time you graduate, you really should have a resume that lists a whole bunch of programming jobs. The A&F graduates are going to be working at Enterprise Rent-a-Car "helping people with their rental needs." (Except for Tom Welling. He plays Superman on TV.)

To make your life really easy, and to underscore just how completely self-serving this whole essay is, my company, Fog Creek Software, has summer internships in software development that look great on resumes. "You will most likely learn more about software coding, development, and business with Fog Creek Software than any other internship out there," says Ben, one of the interns from last summer, and not entirely because I sent a goon out to his dorm room to get him to say that. The application deadline is February 1st. Get on it.

If you follow my advice, you, too, may end up selling stock in Microsoft way too soon, turning down jobs at Google because you want your own office with a door, and other stupid life decisions, but they won't be my fault. I told you not to listen to me.

College students: my company has paid summer internships in New York City, including free housing, free lunch, and the chance to develop software people will really use, with great mentors on interesting projects. Don't miss this chance of a lifetime. We only have a few spaces and they always go fast, so apply today.

Next:

Colo Expansion Version 2.0


Want to know more?

You’re reading Joel on Software, stuffed with years and years of completely raving mad articles about software development, managing software teams, designing user interfaces, running successful software companies, and rubber duckies.


About the author.

I’m Joel Spolsky, founder of Fog Creek Software, a New York company that proves that you can treat programmers well and still be highly profitable. Programmers get private offices, free lunch, and work 40 hours a week. Customers only pay for software if they’re delighted. We make FogBugz, an enlightened project management system designed to help great teams develop brilliant software, and Fog Creek Copilot, which makes remote desktop access easy.