2010-10-19

网络终于好了

原来是网线问题,导致丢包,换了根网线,问题解决

2010-10-12

Using Google Reader “Send To” with WordPress

http://thingelstad.com/using-google-reader-send-to-with-wordpress/

To create this go to Google Reader and open Settings. Select the “Send To” tab and click on the “Create a custom link” button. Then fill it in similar to this picture:

google-reader-send-to-for-wordpress2

Also, if you want the nice WordPress icon next to the link put the Icon URL in as

http://s.wordpress.org/favicon.ico?3

 

C# Closures Explained

CodeThinked

via C# Closures Explained.

An Illustrated Guide to Git on Windows

http://nathanj.github.com/gitguide/tour.html

About

This document is designed to show that using git on Windows is not a difficult process. In this guide, I will create a repository, make several commits, create a branch, merge a branch, search the commit history, push to a remote server, and pull from a remote server. The majority of this will be done using GUI tools.

Although this guide is targeted for use on Windows, the git gui tool works the same on all platforms. Because of this, git users on other platforms may find useful information here as well.

If you have any comments about this guide, feel free to contact me.

Downloading PuTTY


Although you can use the SSH program that comes with git, I prefer to use the PuTTY Agent to keep track of my SSH keys. If you don't already have them, download putty.exe, plink.exe, pageant.exe, and puttygen.exefrom the PuTTY web site.

Later in this guide, we will use these programs for securely pushing our changes to a remote server.

Installing Git


First, download msysgit. This download is a single executable which installs the entire git system. While going through the installer, you will want to check the options to add Windows Explorer integration when you right click on a folder.



Because we will be using PuTTY as our SSH client, choose Use PLink and fill in the path to the downloadedplink.exe executable.



Continue clicking Next until the installation is complete.

Creating a Repository




To create a repository, first create the folder you want the project to live under. Next, right click on the folder and choose Git GUI Here. Because there is no git repository in this folder yet, you will be presented with the git gui startup dialog.



Choosing Create New Repository brings us to the next dialog.



Fill in the path to your new directory and click Create. You will then be presented with the main interface of git gui, which is what will be shown from now on when you right click on your folder and click Git GUI Here.



Now that the repository has been set up, you will need to tell git who you are so that commit messages will have the correct author. To do this, choose Edit → Options.



In the options dialog, there are two versions of each preference. On the left side of the dialog are options that you want for this repository only, while the right side contains the global options which apply to all repositories. The defaults for these options are sensible so just fill in the user name and email for now. If you have a favorite font, you may want to set it now as well.

Committing


Now that the repository has been created, it is time to create something to commit. For this example, I created a file called main.c with the following content:
#include <stdio.h>

int main(int argc, char **argv)
{
 printf("Hello world!\n");
 return 0;
}

Clicking the Rescan button in the git gui will cause it to search out new, modified, and deleted files in the directory. In the next screenshot, git gui has found our new file (amazing, I know).



To add the file for committing, click the icon to the left of the filename. The file will be moved from theUnstaged Changes pane to the Staged Changes pane. Now we can add a commit message and commit the change with the Commit button.



Saying hello to the world is all well and good, but I would like my program to be more personal. Let's have it say hello to the user. Here's my code for that:
#include <stdio.h>
#include <string.h>

int main(int argc, char **argv)
{
 char name[255];

 printf("Enter your name: ");
 fgets(name, 255, stdin);
 printf("length = %d\n", strlen(name)); /* debug line */
 name[strlen(name)-1] = ''; /* remove the newline at the end */

 printf("Hello %s!\n", name);
 return 0;
}

I had some trouble figuring out why a newline was printed after the user's name, so I added a debugging line to help me track it down. I would like to commit this patch without the debug line, but I want to keep the line in my working copy to continue debugging. With git gui, this is no problem. First, click Rescan to scan for the modified file. Next, click the icon to the left of the filename to stage all modifications for commit. Then, right click on the debug line and chose Unstage Line From Commit.



Now, the debug line has been unstaged, while the rest of the changes have been staged. From here, it is just a matter of filling in the commit message and clicking Commit.


Branching


Now let's say that we want to start adding new features for our next big version of the program. But, we also want to keep a stable, maintenance version of the program to fix bugs on. To do this, we will create a branch for our new development. To create a new branch in git gui, choose Branch → Create. The big feature that I would like to add is to ask the user for their last name, so I am calling this branch lastname. The default options in the Create Branch dialog are all fine, so just enter the name and click Create.



Now that I am on the lastname branch, I can make my new modifications:
#include <stdio.h>
#include <string.h>

int main(int argc, char **argv)
{
 char first[255], last[255];

 printf("Enter your first name: ");
 fgets(first, 255, stdin);
 first[strlen(first)-1] = ''; /* remove the newline at the end */

 printf("Now enter your last name: ");
 gets(last); /* buffer overflow? what's that? */

 printf("Hello %s %s!\n", first, last);
  return 0;
}

And then I can commit the change. Note here that I am committing using a different name. This is to show off something later. Normally you would always use the same name when committing.



Meanwhile, a user informs us that not displaying a comma when directly addressing someone is a serious bug. In order to make this bug fix on our stable branch, we must first switch back to it. This is done usingBranch → Checkout.



Now we can fix our major bug.



If we choose Repository → Visualize All Branch History, we can see how our history is shaping up.


Merging


After days of work, we decide that our lastname branch is stable enough to be merged into the master branch. To perform the merge, use Merge → Local Merge.



Because the two different commits made two different modifications to the same line, a conflict occurs.





This conflict can be resolved using any text editor. After resolving the conflict, stage the changes by clicking the file icon and then commit the merge by clicking the Commit button.


Viewing History


The main.c file is starting to get a bit big, so I decided to move the user prompting portion of the code into its own function. While I was at it, I decided to move the function into a separate file. The repository now contains the files main.c, askname.c, and askname.h.
/* main.c */
#include <stdio.h>

#include "askname.h"

int main(int argc, char **argv)
{
 char first[255], last[255];

 askname(first, last);

 printf("Hello, %s %s!\n", first, last);
  return 0;
}

/* askname.c */
#include <stdio.h>
#include <string.h>

void askname(char *first, char *last)
{
 printf("Enter your first name: ");
 fgets(first, 255, stdin);
 first[strlen(first)-1] = ''; /* remove the newline at the end */

 printf("Now enter your last name: ");
 gets(last); /* buffer overflow? what's that? */
}

/* askname.h */
void askname(char *first, char *last);



The history of the repository can be viewed and searched by choosing Repository → Visualize All Branch History. In the next screenshot, I am trying to find which commit added the last variable by searching for all commits which added or removed the word last. Commits which match the search are bolded, making it quick and easy to spot the desired commit.



A few days later, someone looks through our code and sees that the gets function could cause a buffer overflow. Being the type to point fingers, this person decides to run a git blame to see who last modified this line of code. The problem is that Bob is the one who committed the line, but I was the one who last touched it when I moved the line into a different file. Obviously, I am not to blame (of course). Is git smart enough to figure this out? Yes, it is.

To run a blame, select Repository → Browse master's Files. From the tree that pops up, double click on the file with the line in question which in this case is askname.c. Hovering the mouse over the line in question shows a tooltip message that tells us all we need to know.



Here we can see that the line was last modified by Bob in commit f6c0, and then I moved it to its new location in commit b312.

Pushing to a Remote Server


Before pushing to a remote server, you must first create a SSH public and private key pair. By using SSH, you will be able to securely authenticate to the server that you are who you say you are. Creating the key pair is a simple process. Begin by running the puttygen.exe program downloaded earlier. Next, click theGenerate button to generate the keys. After processing for a few seconds, click the Save private key button to save your new private key. Copy the public key to the clipboard in preparation for the next step. I would recommend not clicking the Save public key button because the saved file is in a non-standard format; trying to use it with other software might be problematic.



Now that the keys are generated, the remote servers need to know about it. If you would like to use githubto host your code, just go to your account page and paste in the public key.



Now github has our public key, but we do not yet have github's. To remedy this, launch putty.exe, connect togithub.com, and click Yes to accept github's public key. You can safely close the login window that opens up after accepting the key.





We need our private key to be loaded up to use with our public key, so launch pageant.exe. This program will create an icon in your system tray. Double clicking on the icon will open up a window into which the private key can be added. Once the private key is added, the agent will sit in the background and provide authentication when needed.



Now that our client and server can authenticate each other, it is time to push! Remote → Push will open up the push dialog. Typing in the commit address for the project and clicking Push will send the changes on their way.





Of course, typing in the remote url would become quite annoying if we had to do it with every push. Instead, git allows us to alias the long urls using remotes. Git gui currently does not have a way to add a remote, so the command line must be used. Right click on the repository folder and choose Git Bash Here. In the prompt, enter the following command:
git remote add github git@github.com:nathanj/example.git

Note: After adding a remote, close and reopen git gui for it to recognize the new remote.

Now the remote github is aliased to the url git@github.com:nathanj/example.git. When viewing the push dialog in git gui, a convenient drop down list of remotes is shown.


Pulling from a Remote Server


Because our code is so useful, dozens of people have downloaded and now use our program. One person in particular, Fred, has decided to fork our project and add his own commits. Now that he's added his code, he would like us to pull those commits from him into our repository. To do this, first create another remote.
git remote add fred ssh://fred@192.168.2.67/home/fred/example

Now we can fetch Fred's changes using Remote → Fetch from → fred.



After the fetch, Fred's commits have now been added to our local repository under the remotes/fred/masterbranch. We can use gitk to visualize the changes that Fred has made.



If we like all of Fred's changes, we could do a normal merge as before. In this case though, I like one of his commits but not the other. To only merge one of his commits, right click on the commit and choose Cherry-pick this commit. The commit will then be merged into the current branch.





We can now push a final time to send Fred's patch to our github tree for everyone to see and use.


Conclusion


In this guide, I have shown how to do many common tasks in git using GUI tools. I hope that this guide has shown that it is not only possible but easy to use git on Windows without having to use the Windows shell for most operations.

If you have any comments about this guide, feel free to contact me.

2010-10-08

解决windows xp 卡死在登陆界面的问题

问题描述:
一台在域中的计算机,开机,出现登陆界面,输入用户名,密码,选择域后点登陆,一直停留在此界面,不能登陆。少则几秒,多则几分钟才能登入账户,登陆后网速极慢

问题解决:
事件查看器中报40960,40961错误。和同事的计算机设置对比后,原来没有设置DNS。在Advanced TCP/IP Setting ,DNS tab 中加入 DNS Server,DNS Suffixes,登陆正常了一天,第二天一早又出现此问题,仔细检查了一边,发现DNS Suffixes中有一项有拼写错误,改正之,正常了好几天,又出现问题,试了一对dns相关的命令,貌似有点作用

looking for DNS entries (nslookup -q),
checked Network speed, flushed DNS Chache (ipconfig /flushdns)
registered new on DNS Server (ipconfig /registerdns)
do netdom reset (netdom reset COMPUTERNAME /Domain:DOMAINNAME.net)

从网上查了一下,将设备管理器=》网卡=》电源管理中的允许计算机关闭此设备取消勾选,又坚持了好几天,结果今早来了又出现此问题,试着降网络禁用再启用,问题解决

不知明天什么情况

Event ID 40960 Source LSASRV

2010-10-07

install ack on windows

ack is a great searching tool, especially for large source code tree, on windows, it is very simple to install and config

1)Installing perl http://strawberryperl.com/

2)(in a windows command shell)

Install App::Ack by typing

C:\>cpan App::Ack

3)Then enable color highlights:

cpan Win32::Console::ANSI

4)Let ack support more filetypes aspx for example

Add .ackrc file under C:\Documents and Settings\[yourname],with content
---type-set=aspx=.aspx

basic usage:
ack PopTree
ack "Latest News"
ack #body --css //only search css files
ack #body --nocss // not search css files

More on http://search.cpan.org/dist/ack/ack-base

vim with visual studio 2008

在visual studio 2008中使用vim
1.安装vim
2.tool->external tools->add
(1)title里填 &gvim
(2)Command里填 C:\Program Files\Vim\vim73\gvim.exe
(3)Arguments里填 $(itempath)
(4)Initial Dirtory里填 $(itemdir)
另外附上vim 和平visual studio shortcut对比
Gvim Visual-Studio Purpose
* Ctrl + F3 Search for current word under cursor
# Ctrl + Shift + F3 Search for previous word under cursor
Ctrl + o Ctrl + '-' Go to previous location
Ctrl + i Ctrl + Shift + - Go to next location
/ Ctrl + i Incremental search
gg Ctrl + Home Go to the beginning of the file
G Ctrl + End Go to the end of the file
n F3 Find again
Ctrl + P Ctrl + right arrow Autocomplete
qx Ctrl + Shift + R Record a temporary macro
@x Ctrl + Shift + P Play a temporary macro
% Ctrl + ] Go to matching braces
mx Ctrl K + Ctrl K Make a bookmark
'x Ctrl K + Ctrl N Move to (next) bookmark
~ Ctrl K + Ctrl U Change the text to UPPERCASE
zf% Ctrl M + Ctrl M Fold a section

http://hi.baidu.com/freying/blog/item/478b0ea6269ca892d0435803.html

If you end a sentence with an abbreviation, do you place an additional period after it?

When an abbreviation with a period ends a sentence, that period will suffice to end the sentence. For example:

Jane Doe lives in Washington, D.C.

When a question ends with an abbreviation, end the abbreviation with a period and then add the question mark.

Didn't he use to live in Washington, D.C.?

The Period

Let ack search more filetypes

ack does not support aspx by default, to let ack search aspx files, simple add .ackrc file under C:\Documents and Settings\[yourname],with content

--type-set=aspx=.aspx



2010-10-06

Getting Good with Git - eBooks - Tuts+ Marketplace‎

So, you want to learn about Git, the fast version control system? Then you’ve come to the right place!

In this eBook (free for the month of October! Usually $10), I’ll be guiding you through the sometimes-confusing waters of using Git to manage your development projects. The eBook clocks in at a solid 104 pages.

What’s Inside?


Chapter 1: Introduction to Git

  1. What is Git? 7

  2. Why Should I Use a Version Control System? 9

  3. Where did Git Come From? 10

  4. Why Not Use Another Source Code Manager? 10

  5. Summary, 11


Chapter 2: Commands

  1. A Warning, 14

  2. Another Warning, 14

  3. Opening the Command Line, 15

  4. What You’re Looking At, 16

  5. Commands, 17

  6. Advanced Command Line Skills, 24

  7. Summary, 25


Chapter 3: Configuration

  1. Installing Git, 28

  2. Configuring Git, 33

  3. Using Git, 34

  4. Referencing Commits: Git Treeishes, 51

  5. Summary, 52


Chapter 4: Beyond the Basics

  1. Git Add Revisited, 55

  2. Git Commit Revisited, 65

  3. Git Reset, 66

  4. Git Checkout Revisited, 67

  5. Git Diff, 68

  6. Git Stash, 70

  7. Working with Remote Repositories, 71

  8. Git Rebase, 78

  9. Summary, 81


Chapter 5: GitHub

  1. What is GitHub? 84

  2. Signing Up, 84

  3. Tour of the Tools, 87

  4. Creating a GitHub Repository, 92

  5. Forking a Repository, 96

  6. Summary, 101


Appendix A: More Git Resources, 102

Appendix B: Git GUIS , 104

About the Author


I’m a Canadian web developer, the Associate Editor at Nettuts+, and a review on the Tuts+ Marketplace. I prefer JavaScript and Ruby. Soon, I’ll be doing some writing on my personal site; of course, you can follow me on Twitter.

http://marketplace.tutsplus.com/item/getting-good-with-git/128738

search ignore case

Use “\c” anywhere in a search to ignore case (overriding your ignorecase or smartcase settings).
e.g. “/\cfoo” or “/foo\c” will match foo, Foo, fOO, FOO, etc.

Use “\C” anywhere in a search to force case matching.
e.g. “/\Cfoo” or “/foo\C” will only match foo.

2010-08-26

Removing Deleted Files from your Git Working Directory

我们知道git rm file 命令是删除一个文件,文件就进入了暂存区,之后就可以用git commit 来提交删除。但有时候我们从资源管理器中删除了某个文件,再用git st查看状态,git显示文件被删除,但是不在暂存区,这时,用git add .是无法将文件加入暂存区的,因为 git add .只会把当前目录里那些已更改,或者没有被忽略的新文件加入暂存区,对已删除的文件不起作用。那怎么办呢?答案是用 git add -u。它的作用是把工作区内已跟踪文件里更改或的,或者删除了的文件加入暂存区,但对新文件不起作用,它针对的是已跟踪文件。
git add -A = git add -u + git add .
注意A是大写的


Difference of “git add -A” and “git add .”

Removing Deleted Files from your Git Working Directory

2010-08-24

git 笔记

git 的强大就不用说了,目前在windows下使用git,先装 msysgit,再装tortoisegit
msysgit带git命令行 git bash
git init 初始化版本库
git add filename 添加新文件到版本库或者添加修改的文件到提交列表(暂存区)
git add . 同上,所有文件
git commit 提交,回车后会弹出默认文本编辑器以输入 commit message
git commit -a = git add + git commit
git commit -m "fix issue 15252" 直接提供commit message
git diff 比较当前工作目录和暂存区
git diff --cached 比较暂存区和上次提交
git diff HEAD 比较当前工作目录和上次提交

将 Current working directory 记为 (1)
将 Index file 记为 (2)
将 Git repository 记为 (3)
他们之间的提交层次关系是 (1) -> (2) -> (3)
git add完成的是(1) -> (2)
git commit完成的是(2) -> (3)
git commit -a两者的直接结合
从时间上看,可以认为(1)是最新的代码,(2)比较旧,(3)更旧
按时间排序就是 (1) <- (2) <- (3)
git diff得到的是从(2)到(1)的变化
git diff –cached得到的是从(3)到(2)的变化
git diff HEAD得到的是从(3)到(1)的变化
                                                                                                        --Lee.MaRS

git checkout -- filename 丢弃某个文件的更改(如果文件在暂存区,则丢弃添加到暂存区之后的更改,如果不在暂存区,则丢弃上次提交之后的更改)
git reset --hard 丢弃所有更改
git reset -- filename 从待提交列表中移除
git revert HEAD revert上一次的提交,并提交本次操作。
git rm filename 从磁盘删除文件,并添加到暂存区
git rm -r folder 从磁盘删除文件夹(内所有文件),并添加到暂存区,,对于文件, 也可以加上 -r
git rm --cached filename 保留文件,取消对文件的跟踪
git commit --amend 修正上一次提交。比如提交之后发现某个单词写错了,就可以用此命令来  修改上次的 commit message。或者提交后才发现没有把某个修改后的文件add 到暂存区,隐藏没有提交,这是就可以先git add xxx.txt 把文件添加到暂存区,然后运行此命令,把此文件加到上次提交中

2010-07-22

C#中用DllImport调用非托管代码

基本用法:调用系统的messagebox(位于user32.dll中)

using System;
using System.Runtime.InteropServices;
class Example
{    // Use DllImport to import the Win32 MessageBox function.
    [DllImport("user32.dll", CharSet = CharSet.Unicode)]
    public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);

    static void Main()
    {
        // Call the MessageBox function using platform invoke.
        MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
    }
}
至少要制定要导入的dll名称,可选字段:

  • CharSet:制定字符集
  • EntryPoint:制定入口点

     入口点用于标识函数在 DLL 中的位置。 在托管对象中,目标函数的原名或序号入口点将  标识跨越交互操作边界的函数。 此外,您可以将入口点映射到一个不同的名称,这实际上是将函数重命名。

以下列出了重命名 DLL 函数的可能原因:
  1. 避免使用区分大小写的 API 函数名
  2. 符合现行的命名标准
  3. 提供采用不同数据类型的函数(通过声明同一 DLL 函数的多个版本)
  4. 简化对包含 ANSI 和 Unicode 版本的 API 的使用
下面的示例演示如何使用 EntryPoint 字段将代码中的 MessageBoxA 替换为 MsgBox。

using System.Runtime.InteropServices;

public class Win32 {
    [DllImport("user32.dll", EntryPoint="MessageBoxA")]
    public static extern int MsgBox(int hWnd, String text, String caption,
                                    uint type);
}

2010-07-19

捷通华声面试

时间:2010-7-19 下午
地点:中关村软件园10号楼(great road)
本来让我上周六下午去,有事情没去成,改成了今天下午,事先去他们网站上了解了一下,做语音识别,手写识别的。进去前台有两个mm,桌子上有祝xxx生日快乐的小牌子,比较人性化,右边边白板上贴着竞赛排名,测试的居多,右边摆放这很多奖牌,奖状,荣誉证书,有一个是“副主任奖”,当然这都是做完题在那儿等着的时候看到的。去了先做题,技术一份,非技术一份
技术题:多选,填空
实现二分查找

软件开发中,术语 架构,模式,过程,框架都是什么意思

聚簇索引和非聚簇索引

一张表ppp,找出id最大的一行

asp.net页面周期

httphandler 和 httpmodule

一段重写多态程序的输出结果
。。。
A a = new A();
B b = new B();
a.Fun2(b);
b.Fun1(a);

写出三种设计模式,说明其中一种的使用场景及实现的关键点

职业规划,最近关注的技术


非技术题
希望有什么样的同事和领导

你是否知道相对论?简单写一下你了解的

如果你家水龙头坏了,你怎么办

你和你的朋友开了一家饭店,职位有财务,大堂主管,厨房主管,保安,前台,采购,等职位,你想干什么?

让你在荒岛上待一年,带3本(种)书,2个CD,你希望带什么书和CD?
我写的是24史,算法,经济,CD是雅尼和许巍

估算常年每年流入长江多少吨水?
365*24*60*60  *  100*3  *0.2

假如你来公司上班,你认为什么样的绩效考核对员工有帮助

你有什么优势,能为公司做出什么贡献

背景调查,写出以前公司的人力姓名,联系方式
我开始填了一个,另一人的电话没写,人力面的时候让我回来找到在发给他们,我就在技术二面之前上msn找到,临走的时候让前台mm写上了

之后是技术面试,两个人,问的问题都比较简单,人也比较和蔼
c#有结构体么
c#的访问修饰符?都是什么意思?
介绍他们除了做语音识别,手写识别,还做无限运营,和三大运营商都有合作,特别是电信,排名前三,现在也开设做手机社区

人力面试
介绍了他们共is
技术二面
傲慢

CEO面试?
貌似进的的是总裁办公室,又问了我一遍工作经历,夫人干什么的,在哪儿住等等。。说这一行需要加班,后台出了什么问题,需要马上解决,小伙子你行么?我说IT就是这样的,我没问题

2010-07-18

静态构造,单例模式,和beforefieldinit


http://smartypeeps.blogspot.com/2007/03/beforefieldinit.html
"beforeFieldInit" is a special flag marked by compiler to the types which doesn't have static constructor.
This special flag tells "calling a static method does not force the system to initialize the type." Means that calling a static method does not make sure the static variables are initialized in the type.
public class ResourceClass
{
      private static StreamWriter sw = new StreamWriter();
      public static StreamWriter GetInstance()
      {
          return sw;
      }
}
In the above type it is not guranteed that when you call GetInstance the static variable "sw" would be created. Because of the reason the class is marked as "beforeFieldInit".
public class ResourceClass
{
    private static StreamWriter sw = new StreamWriter();
    static ResourceClass() { };
    public static StreamWriter GetInstance()
    {
         return sw;
    }
}
In the above type it is guranteed that when you call GetInstance the static variable "sw" would be created. Because of the reason the class contains "static constructor".
Properties of static constructor
Static constructors are not inherited, and cannot be called directly.
The exact timing of static constructor execution is implementation-dependent, but is subject to the following rules:
The static constructor for a class executes before any instance of the class is created.
The static constructor for a class executes before any of the static members for the class are referenced.
The static constructor for a class executes after the static field initializers (if any) for the class. The static constructor for a class executes, at most, one time during a single program instantiation.
The order of execution between two static constructors of two different classes is not specified.
But CLI does insist that all of the field variables will be initialized as soon as one of the static fields is accessed. So if we are depending on some side effects based on static variable initialization, then we may be waiting for a long time that to happen.
---------------------------------------------------------------
http://www.yoda.arachsys.com/csharp/singleton.html
Fourth version - not quite as lazy, but thread-safe without using locks
public sealed class Singleton
{
    static readonly Singleton instance=new Singleton();


    // Explicit static constructor to tell C# compiler
    // not to mark type as beforefieldinit
    static Singleton()
    { }
    Singleton() { }
    public static Singleton Instance
    {
       get
       {
           return instance;
       }
    }
}

As you can see, this is really is extremely simple - but why is it thread-safe and how lazy is it? Well, static constructors in C# are specified to execute only when an instance of the class is created or a static member is referenced, and to execute only once per AppDomain. Given that this check for the type being newly constructed needs to be executed whatever else happens, it will be faster than adding extra checking as in the previous examples. There are a couple of wrinkles, however:
  • It's not as lazy as the other implementations. In particular, if you have static members other thanInstance, the first reference to those members will involve creating the instance. This is corrected in the next implementation. 
  • There are complications if one static constructor invokes another which invokes the first again. Look in the .NET specifications (currently section 9.5.3 of partition II) for more details about the exact nature of type initializers - they're unlikely to bite you, but it's worth being aware of the consequences of static constructors which refer to each other in a cycle. 
  • The laziness of type initializers is only guaranteed by .NET when the type isn't marked with a special flag called beforefieldinit. Unfortunately, the C# compiler (as provided in the .NET 1.1 runtime, at least) marks all types which don't have a static constructor (i.e. a block which looks like a constructor but is marked static) as beforefieldinit. I now have a discussion page with more details about this issue. Also note that it affects performance, as discussed near the bottom of this article. 
One shortcut you can take with this implementation (and only this one) is to just make instance a public static readonly variable, and get rid of the property entirely. This makes the basic skeleton code absolutely tiny! Many people, however, prefer to have a property in case further action is needed in future, and JIT inlining is likely to make the performance identical. (Note that the static constructor itself is still required if you require laziness.)

Fifth version - fully lazy instantiation
public sealed class Singleton
{
Singleton()
    {
    }
    public static Singleton Instance
    {
        get
        {
            return Nested.instance;
        }
    }


    class Nested
    {
        // Explicit static constructor to tell C# compiler
        // not to mark type as beforefieldinit
        static Nested()
        {
        }
        internal static readonly Singleton instance = new Singleton();
    }
}

Here, instantiation is triggered by the first reference to the static member of the nested class, which only occurs in Instance. This means the implementation is fully lazy, but has all the performance benefits of the previous ones. Note that although nested classes have access to the enclosing class's private members, the reverse is not true, hence the need for instance to be internal here. That doesn't raise any other problems, though, as the class itself is private. The code is a bit more complicated in order to make the instantiation lazy, however.

2010-07-17

用友面试

时间:2010-7-16 星期五
地点:用友软件园
用友软件园的环境没的说,优雅安静,除了门口有门卫,研发中心都是自动门,不需要刷卡进入。

需要的人员是性能调优方面的,比如sql优化,调试工具的使用,自己在这方面的经验不足。。。
sql 表 物理连接的三种方式

风软面试

时间:2010-7-17 星期六
地点:中关村南大街韦伯时代中心C座702
这是一家做期货,风控的金融公司,规模不大,进门居然需要换鞋
首先做题:
一块豆腐切三刀,最多能切成几块?
一个电饼铛,每次能烙两张饼(单面),现有三张饼,每面烙一分钟,要求三分钟烙完,如何烙?
过河问题:现有男主人,女主人,两个仆人,一条狗要过河,船只能容纳两个人(狗),而且女主人和仆人在一起的话,女主人会杀死仆人,仆人和狗在一起的话,狗会咬死仆人,仆人在一起的话,仆人会逃跑,如何过河?
用类图描述文件夹,文件,快捷方式的关系
简述.net的异常处理机制,并举例
datareader 和dataset 的区别
编程实现冒泡排序
编程实现输出N以下的质数
多线程编程中lock,monitor,mutex 的区别
int a =5;
int b=5;
if(object.ReferenceEquals(a, b) == true)
   Console.WriteLine("equal");
esle
   Console.WriteLine("not equal");

当然是输出not equal,引文值类型会被装箱

int i = 5; int j = 5;
if ( Object.
ReferenceEquals( i, j ))
Console.WriteLine( "Never happens." );
else
Console.WriteLine( "Always happens." );
if ( Object.
ReferenceEquals( i, i ))
Console.WriteLine( "Never happens." );
else
Console.WriteLine( "Always happens." );
再看引用类型
string literal1 = "a"; 
string literal2 = "a"; 
Console.WriteLine(object.ReferenceEquals(literal1, literal2));
literal1 = literal2; 
Console.WriteLine(object.ReferenceEquals(literal1, literal2));
两者都输出 true,这是因为.net的string interning机制,literal1 和 literal2指向相同的内存地址
参见
How to: Compare Strings (C# Programming Guide)
面试过程:首先可能是个项目经历面试的,让我介绍了一下项目经历,
用过那些框架,
最近去没去面试,结果如何,
去了上周去xxx面的
家住哪里,
XXX,
那边也有很多it公司,没去试试么?
去面了几个
结果怎么样,
我居然说没结果,
他问为什么?我很诚实的说可能自己开发经验不多吧。。。
问我数学怎么样,
还可以吧
平时读什么技术书,
我说编程珠玑,代码大全,c# 4 in a nutshell, 
都读完了么?
代码大全读了一遍
书里的内容都应用到工作中了么?
代码大全里的东西用上 了,代码重构什么的
。。。
你是不是特别?
特别什么?
就是别人问一句答一句
嗯,和别人交流方便不太主动
然后说想找一个人写一个自动化测试的东西,问我想不想做,我说可以,他让我等一下,一会回来让我去另一个老总的办公室。老总说我们想做一个自动化测试平台,你能做了么?我说能吧,然后又问了写测试方面的东西,说你做测试用的是别人的东西,核心东西没学到,开发经验也少,问我要多少,我说7000,他说专门测试的话有点多,低了考虑么?我说不考虑,他说那只能我们考虑了。。。。面试结束

万网面试

时间:2010-7-15 星期五 雨
地点:鼓楼外大街北站,万网大厦

(需带简历)周五下午去万网面试,先去的后楼,一楼进门就是前台,后面墙上是一个倒着的“网”字,可能类似于福倒(到)了的意思吧。照例还是填写应聘信息表,做题。由于来面试的人很多,期间被赶来赶去好多次,从进门的茶几到小会议室,从小会议室再回来。体量很大,居然让我30分钟做完。做完后前台把我填的应聘信息,简历,我做的题顶起来,让我去前楼六楼找杨得祥面试
题目
一、简述概念:
XML,云计算,SMTP,DNS,TCP/IP,虚拟主机,IIS,Http,

二、有一个文件,里面有一百万个域名,输出重复的

三、有两个表:Department(DeptID,DepartName),Employee(EmpID,DeptID,EmpName,Salary)
编写Sql语句,找出平均工资大于2000的部门及其平均工资

四、overriding 和 overload 的区别

五、datareader 和 dataset 的区别

六、如何阻止某一个ip访问你的网站

七、以下程序的输出:
    try{Console.WriteLine("aaa");return true;}
    catch{Console.WriteLine("bbb");return true;}
    finally{Console.WriteLine("ccc");return true;}
八、四个填空题

  1. 。。。
  2. 。。。
  3. 。。。
  4. 万网的网址是,此题我一开始答的是www.net.com,在去了前楼六楼找面试官的时候,在前台改成了www.net.cn
面试
招聘的岗位是自动化的创建站点,帮助客户排除故障,问的问题很多都和网络相关:子网掩码;阻止某个ip段;c#操作注册表;电脑不能上网,如何排除故障;如何用c#代码创建站点。。。。回答的不好,面试官说如有复试,五日内给大幅

2010-07-08

SQL Server 2005's new added Ranking functions

Ranking functions return a ranking value for each row in a partition. Depending on the function that is used, some rows might receive the same value as other rows. Ranking functions are nondeterministic.

Transact-SQL provides the following ranking functions:

The following shows the four ranking functions used in the same query. For function specific examples, see each ranking function.

USE AdventureWorks2008R2;
GO
SELECT p.FirstName, p.LastName
,ROW_NUMBER() OVER (ORDER BY a.PostalCode) AS 'Row Number'
,RANK() OVER (ORDER BY a.PostalCode) AS 'Rank'
,DENSE_RANK() OVER (ORDER BY a.PostalCode) AS 'Dense Rank'
,NTILE(4) OVER (ORDER BY a.PostalCode) AS 'Quartile'
,s.SalesYTD, a.PostalCode
FROM Sales.SalesPerson s
INNER JOIN Person.Person p
ON s.BusinessEntityID = p.BusinessEntityID
INNER JOIN Person.Address a
ON a.AddressID = p.BusinessEntityID
WHERE TerritoryID IS NOT NULL
AND SalesYTD <> 0;





Here is the result set.





FirstName



LastName



Row Number



Rank



Dense Rank



Quartile



SalesYTD



PostalCode



Michael



Blythe



1



1



1



1



4557045.0459



98027



Linda



Mitchell



2



1



1



1



5200475.2313



98027



Jillian



Carson



3



1



1



1



3857163.6332



98027



Garrett



Vargas



4



1



1



1



1764938.9859



98027



Tsvi



Reiter



5



1



1



2



2811012.7151



98027



Shu



Ito



6



6



2



2



3018725.4858



98055



José



Saraiva



7



6



2



2



3189356.2465



98055



David



Campbell



8



6



2



3



3587378.4257



98055



Tete



Mensa-Annan



9



6



2



3



1931620.1835



98055



Lynn



Tsoflias



10



6



2



3



1758385.926



98055



Rachel



Valdez



11



6



2



4



2241204.0424



98055



Jae



Pak



12



6



2



4



5015682.3752



98055



Ranjit



Varkey Chudukatil



13



6



2



4



3827950.238



98055