2014-03-25

Debugging Tools on Windows

Windows Error Reporting (WER): Collecting User-Mode Dumps
http://msdn.microsoft.com/en-us/library/bb787181%28VS.85%29.aspx

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps
  • DumpFolder, REG_EXPAND_SZ, %LOCALAPPDATA%\CrashDumps
  • DumpCount, REG_DWORD, 10
  • DumpType, REG_DWORD, 1 (1: mini dump; 2: full dump;)

Per-application setting:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Windows Error Reporting\LocalDumps\MyApplication.exe

* Need to restart (or log out and log in again) to make the change effective.


Enabling Postmortem Debugging - register a debugger (WinDBG, CDB, ntsd)
http://msdn.microsoft.com/en-us/library/windows/desktop/ff542967%28v=vs.85%29.aspx


Tools comparision matrix (ADPlus; WER; CDB/WinDbg; UserDump)
http://msdn.microsoft.com/en-us/library/windows/desktop/ff539117%28v=vs.85%29.aspx


More tools in the toolset
http://msdn.microsoft.com/en-us/library/windows/desktop/ff543998%28v=vs.85%29.aspx


Application Verifier
http://msdn.microsoft.com/en-us/library/windows/desktop/dd371695%28v=vs.85%29.aspx

Restart of the application is needed - after it is added into AppVerifier.

WinDbg

2014-01-08

bank security token - reverse engineering

The original source is obviously unavailable now.
Just saved for later reading/reference.

2013-08-20

Busy wait, Sleep(0), Sleep(1), Sleep(1000)

* Busy wait, or spin wait: not required for most of the cases
* Sleep(0): fairly good choice
  * if you don't know how long to "sleep", or need to "sleep" less than 1ms
  * if it's not constraint to a single CPU/core
  * if you don't care about the "high" CPU usage
  * if you need an immediate response
* Sleep(1): "sleep" a little bit, but normally more than 1ms
  * if you don't need immediate response
  * if you'd like give out the time slice anyway
  * if you want a "lower" CPU usage than Sleep(1)
* Sleep(1000): just an arbitrary selected number
  * if it's not likely to happen
  * if you are waiting for another time consuming counter part

"Sleep()" is not sleep, but tells the scheduler "Don't bother me for at least some time".

Sleep(0) has a special meaning and handled differently than other values.

WaitOnAddress() seems promising, but:
* seems cause more CPU usage
* with more wall time
Compared to my Sleep(0) version.

Will check the testing/benchmark code later. But, it seems so now.
And the document on MSDN seems at least not reflecting the implementation.

I already sent comments with questions on the documentation and the underlying tech, via email by clicking the bottom link.
I don't expect any (immediate) response. But, before I get any response, I will stop there, no using/testing WaitOnAddress anymore.

Some obvious questions:
* Parameter dwMilliseconds
  * What does "indefinite" mean? If given 0.
  * An optional parameter?
* The example code
  * Why not check the return value?
  * Have you noticed a race condition of using CapturedValue?

Sleep(0) might be further improved, both the performance/speed and power consumption. I'm not sure about the first claim, neither have any knowledge on power consumption.
I'm sure of the implementation of ReaderWriterLockSlim (C#):
* Why not use existing WIN API, like AcquireSRWLockExclusive?
* Why busy wait, then Sleep(0), then Sleep(1)?
* And how to choose the arbitrary numbers for busy wait and Sleep(0)?
* It is with the best performance, or has some compromises?

Anyway, it seems the same approach as the guys from Intel did.
I will give it a try, when I have time.
But, actually, I don't care about performance too much. So, if there is no big improvement (like 10x), I will still use the simple Sleep(0).

Just now, it is only tested against wall time (CPU instruction).
Maybe I'll test it against wall time (performance counter), and analysis the stdev besides just avg.

2013-01-24

利用政策漏洞,套钱买房

利用政策漏洞,套钱买房

http://www.newsmth.net/bbstcon.php?board=SchoolEstate&gid=45221

发信人: evangy (望月寻音), 信区: SchoolEstate
标  题: 超级攻略:你没钱,还想再买个学区房,我来告诉你办法.
发信站: 水木社区 (Tue Jan 22 21:36:57 2013), 站内

竟然到十大了.本文纯属茶余饭后的讨论贴.

一个外地人,在北京需要多少套房子?
答案是4套起,自己住一套,父母住一套,岳父母一套,再给孩子准备一套,当然,再有一套郊区度假的最好.
但太多的人只有一套房,父母接来北京后,明显不够住.
可以参考以下的方法.

条件
1.夫妻名下有房屋(最好全款,能估高一点)
2.夫妻至少一方有公积金或商贷资格,都要有购房资格.
3.房屋最好满5年,唯一(非必要)

流程如下:
一,假离婚,将已有房屋过到一方名下(如只有一方可用公积金,需过户到无公积金的一方身上)

二,假离婚后,假设LP为无房户,LG为有房户,无房户LP"购买"有房户LG的房屋,如满5且唯一,税非常低,按照指导价过户即可.无房户LP交易中要申请公积金或商业贷款.这里假设申请80w公积金.

三,现在,仍然一房为无房户,一方为有房户(注意,换过来拉,LG无房,LP有房),此时,无房LG手中神奇的多出了80w,80w耶,来自步骤二!无房LG再去购买住房(注意:这个是学区房,不是刚才自己买卖的那套,那套房本已经盖银行抵押章了.),此时我们假设买新房,算首套,再申请80w的公积金!(商贷可申请更多)

四,现在LG买到了80w+80w的新房,当然要复婚了,现在二套房入手,贷款只要8K多,房租4K+,毫无压力的日子啊~~

五,如愿意,可重复以上步骤(成本会增加)

课后作业:
160万不够买学区房怎么办??
提供的思路是:丈夫娶丈母娘,老婆嫁公公。。。。。。。

--
※ 修改:·evangy 于 Jan 23 19:25:01 2013 修改本文·[FROM: 123.112.166.*]
※ 来源:·水木社区 http://www.newsmth.net·[FROM: 123.112.152.*]

2012-12-29

2013 精简日历

在 Compact Calendar 2013 基础上:
  • 页面"Tables",增加了倒休日期功能
  • 页面"12-Month",以背景色区分工作日和节假日(休息日灰背景)
其他还有些小改动,主要是根据个人喜好修改了部分界面显示。

节假日安排依据国务院办公厅通知。

=====8<=====8<=====8<=====8<=====8<=====8<=====8<=====8<=====8<=====

Based on Compact Calendar 2013:
  • On worksheet Tables, added Workday Lookup Table for workday shift
  • On worksheet 12-Month, distinguish workdays and holidays with different background color (white for workdays)
There might be some small changes on the display according to my own preference.

The holidays and workday shift are according to the government's announcement.

2012-09-13

退税,以及欧盟、欧元区、申根国的区别

主要参考:[實用資訊] 歐盟.歐元區.申根國傻傻分不清楚 暨 各種退稅方式

退税(有多种渠道和方式,我估计也就只会涉及下面两种):
* Global Blue 机场退税
* Amazon.de 网购退税
送货地址和账单(RECHNUNG)地址可以分开,账单地址需要为欧盟外国家或地区,邮寄地址可以为欧盟境内(免费送货)的地址。
拿着RECHNUNG在机场海关盖章。(机场海关还会再夹一张表格?)
将以下东西寄给Amazon.de:
原件:海关盖章的RECHNUNG
复印件:护照的首页、签证页、出入境页
地址如下:
Amazon.de
Umsatzsteuererstattung
Im Gewerbepark D 55
93059 Regensburg
Deutschland

申根(签证)主要是和出入境相关的。
欧盟主要和退税相关。
欧元区是指当地主要流通货币是欧元。

我在amazon.de(据说和.uk, .us是一个账户;但和.cn的账户是用不了的)上注册了个账号,然后就退税提问,下面是回答的主体——应该是同一模版,没有细节,也没有回答我的具体问题。结合网上的一些中文信息,可以有个大体了解,可能实际操作也很简单、没有各种坑,就没有人有动力提供详细攻略了。

From: cs-reply@amazon.de
To qualify for the refund, the following legal deadline must be met: the item must be exported before the third calendar month following the month in which the goods were received has expired.

For legal reason, we require proof that:

*your residence is abroad (*non*EU) as far as this is not evident from the export certificate, and
*that the items you purchased from Amazon.de have been declared at the customs

Please send both documents as well as the original invoice (essential!) to the following address:

Amazon.de
Umsatzsteuererstattung
Im Gewerbepark D 55
93059 Regensburg
Deutschland

We will keep the original invoice and the confirmation for our records. If you need a copy of your invoices, please tell us the respective order numbers and we will send you the copies.

2012-07-17

Time sync issues - SQL Server login

There is weird problem occurred just yesterday: in the same domain, using the same domain account (Windows Authentication), but on two different computers, everything is fine on the first computer (which is the domain controller); but, one the other computer it is impossible to connect to SQL Server DB (which is also in the same domain).

We doubted our own program first, so we tried SQL Server Management Studio, and it also failed, mentioning "Failed to generate SSPI context".
Then, we switched from FQDN to IP address, succeeded but seems a little bit slower than normal.
So, we doubted the DNS server - running nslookup - but it's fine.

We compared every possible differences might exist between the two, finally there is the one: the second computer has the year as 2010 instead of 2012!
As it is a shared testing environment, it is hard to know and remember who did the change and why.

The reason is that for security the time is critical and a much longer one which is knowledge oriented not problem concentrated.
And this could be in a more subtle: different time zone showing the same time.

2012-06-25

Another time related issue - leap seconds

It is NTP, again.
Besides the integer overflow issue, not VM oriented, there is also leap seconds issue.

2012-06-15

Command Parameters and special characters

An elaborated article: http://www.autohotkey.net/~deleyd/parameters/parameters.htm

Howto change file ownership in command line or by programming

Q: Changing file Ownership with PowerShell 2.0
A: Setting the owner on an ACL in Powershell

A tool is also provided by MS: takeown. But the latest comment is very interesting: he/she ended up with Cygwin's chown.
Next time, I would try both :)

And Copy&Pasted the blog from cosmoskey.blogspot.com for reference:

==================================================================================================================

I was trying to set the owner of an ACL in powershell using the following code:

PS C:\Users\Johan> $acl = get-acl c:\temp\acltest
PS C:\Users\Johan> $principal = New-Object Security.Principal.NTAccount "$env:computername\ownertestaccount"
PS C:\Users\Johan> $acl.psbase.SetOwner($principal)
PS C:\Users\Johan> set-acl -Path C:\Temp\acltest -AclObject $acl
Set-Acl : The security identifier is not allowed to be the owner of this object.
At line:1 char:8
+ set-acl <<<<  -Path C:\Temp\acltest -AclObject $acl
    + CategoryInfo          : InvalidOperation: (C:\Temp\acltest:String) [Set-Acl], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.SetAclCommand


PS C:\Users\Johan>

So setting this ACL doesn't work. Why? I am an administrator! OK, what happens when I start the shell with Run As Administrator?... The same result.

So now we go to google and search a bit and I found the following KB article. What it says is that we need to have the rights to do the deed. Hey, not too surprising. By default Administrators and Backup Administrators have the Restore files and directories (SeRestorePrivilege) User Right. To set the owner we need to have this right, but in the scenario above I was executing the code with a account with all this privilege.

The problem here is that the privilege is not enabled in the access token, we need to call a function called AdjustTokenPrivileges() to adjust the current access token of our process. So we need to call this function, pass in a variable saying that we need to enable a privilege and pass in the privilege we want to enable. To call this function we need to do a little bit of PInvoke. I borrowed the base of my code from pinvoke.net.

So here is my little Set-Owner function.


function Set-Owner {
param(
[System.Security.Principal.IdentityReference]$Principal=$(throw "Mandatory parameter -Principal missing."),
$File=$(throw "Mandatory parameter -File missing.")
)
if(-not (Test-Path $file)){
throw "File $file is missing."
}
if($Principal -eq $null){
throw "Principal is NULL"
}


$code = @"
using System;
using System.Runtime.InteropServices;


namespace CosmosKey.Utils
{
public class TokenManipulator
{


[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);


[DllImport("kernel32.dll", ExactSpelling = true)]
internal static extern IntPtr GetCurrentProcess();


[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr
phtok);


[DllImport("advapi32.dll", SetLastError = true)]
internal static extern bool LookupPrivilegeValue(string host, string name,
ref long pluid);


[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
}


internal const int SE_PRIVILEGE_DISABLED = 0x00000000;
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
internal const int TOKEN_QUERY = 0x00000008;
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;


public const string SE_ASSIGNPRIMARYTOKEN_NAME = "SeAssignPrimaryTokenPrivilege";
public const string SE_AUDIT_NAME = "SeAuditPrivilege";
public const string SE_BACKUP_NAME = "SeBackupPrivilege";
public const string SE_CHANGE_NOTIFY_NAME = "SeChangeNotifyPrivilege";
public const string SE_CREATE_GLOBAL_NAME = "SeCreateGlobalPrivilege";
public const string SE_CREATE_PAGEFILE_NAME = "SeCreatePagefilePrivilege";
public const string SE_CREATE_PERMANENT_NAME = "SeCreatePermanentPrivilege";
public const string SE_CREATE_SYMBOLIC_LINK_NAME = "SeCreateSymbolicLinkPrivilege";
public const string SE_CREATE_TOKEN_NAME = "SeCreateTokenPrivilege";
public const string SE_DEBUG_NAME = "SeDebugPrivilege";
public const string SE_ENABLE_DELEGATION_NAME = "SeEnableDelegationPrivilege";
public const string SE_IMPERSONATE_NAME = "SeImpersonatePrivilege";
public const string SE_INC_BASE_PRIORITY_NAME = "SeIncreaseBasePriorityPrivilege";
public const string SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege";
public const string SE_INC_WORKING_SET_NAME = "SeIncreaseWorkingSetPrivilege";
public const string SE_LOAD_DRIVER_NAME = "SeLoadDriverPrivilege";
public const string SE_LOCK_MEMORY_NAME = "SeLockMemoryPrivilege";
public const string SE_MACHINE_ACCOUNT_NAME = "SeMachineAccountPrivilege";
public const string SE_MANAGE_VOLUME_NAME = "SeManageVolumePrivilege";
public const string SE_PROF_SINGLE_PROCESS_NAME = "SeProfileSingleProcessPrivilege";
public const string SE_RELABEL_NAME = "SeRelabelPrivilege";
public const string SE_REMOTE_SHUTDOWN_NAME = "SeRemoteShutdownPrivilege";
public const string SE_RESTORE_NAME = "SeRestorePrivilege";
public const string SE_SECURITY_NAME = "SeSecurityPrivilege";
public const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
public const string SE_SYNC_AGENT_NAME = "SeSyncAgentPrivilege";
public const string SE_SYSTEM_ENVIRONMENT_NAME = "SeSystemEnvironmentPrivilege";
public const string SE_SYSTEM_PROFILE_NAME = "SeSystemProfilePrivilege";
public const string SE_SYSTEMTIME_NAME = "SeSystemtimePrivilege";
public const string SE_TAKE_OWNERSHIP_NAME = "SeTakeOwnershipPrivilege";
public const string SE_TCB_NAME = "SeTcbPrivilege";
public const string SE_TIME_ZONE_NAME = "SeTimeZonePrivilege";
public const string SE_TRUSTED_CREDMAN_ACCESS_NAME = "SeTrustedCredManAccessPrivilege";
public const string SE_UNDOCK_NAME = "SeUndockPrivilege";
public const string SE_UNSOLICITED_INPUT_NAME = "SeUnsolicitedInputPrivilege";        


public static bool AddPrivilege(string privilege)
{
try
{
bool retVal;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
return retVal;
}
catch (Exception ex)
{
throw ex;
}


}
public static bool RemovePrivilege(string privilege)
{
try
{
bool retVal;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_DISABLED;
retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
return retVal;
}
catch (Exception ex)
{
throw ex;
}


}
}
}
"@


$errPref = $ErrorActionPreference
$ErrorActionPreference= "silentlycontinue"
$type = [CosmosKey.Utils.TokenManipulator]
$ErrorActionPreference = $errPref
if($type -eq $null){
add-type $code
}
$acl = Get-Acl $File
$acl.psbase.SetOwner($principal)
[void][CosmosKey.Utils.TokenManipulator]::AddPrivilege([CosmosKey.Utils.TokenManipulator]::SE_RESTORE_NAME)
set-acl -Path $File -AclObject $acl -passthru
[void][CosmosKey.Utils.TokenManipulator]::RemovePrivilege([CosmosKey.Utils.TokenManipulator]::SE_RESTORE_NAME)
}


If we run this function then we will see a very different result:

PS C:\Users\Johan> get-acl C:\Temp\acltest

    Directory: C:\Temp

Path               Owner                Access
----               -----                ------
acltest            MyLaptop\OldTest     BUILTIN\Administrators Allow  FullCo...


PS C:\Users\Johan> set-owner $(new-object security.principal.ntaccount "$env:computername\NewTest") C:\Temp\acltest

    Directory: C:\Temp

Path              Owner                Access
----              -----                ------
acltest           MyLaptop\NewTest     BUILTIN\Administrators Allow  FullCo...


PS C:\Users\Johan>

In the end we got there but it took me some time... :)

2012-06-06

琐事23

上周六,取草稿。

上周日,天色不好,窝家里。下午果然暴雨,持续时间倒是不长。
吃完晚饭,审美理发。
一则,一直没空去常去的理发店理发,头发太长了;二则,走到审美不过50m;三则,有一个优惠券,洗剪吹18.00。
指定理发店,自2007年就常去。算上这次,5年间,只有3次是在其他地方理发的。
一次是在育新花园路北的小理发店;剩下两次都是在这家审美,上次似乎花了38.00,只是稍稍剪短,所谓发型随便他折腾,没什么好,也没什么不好。
这次,很有吐槽点:据说是欧莱雅的师傅主刀,然后加上一个小姐,围着我疯狂推销欧莱雅的某款(滋养头皮、防治脱发、调理)产品(药品?)……
开始时,他们也没有直接推销,然后在附和他们的过程中,就被绕进去了。然后就一直不得安宁了:估计是暴雨的余威,加上时间比较晚了,再没有其他目标了。
不过理发倒是很给力:和平常一样,只要求耳朵上和脖颈处剪短一点,结果还真的往短了剪,理着理着,搞得我都有点恐慌了——不会搞成平头、板寸了吧……

周一,新sprint开始。
凌晨,老鼠在暖气片的复合板罩子里啃掉进去的报纸,把我吵醒了。轰不出来,只好在外面再用报纸粘的严严实实,把出路堵死。
晚上,看草稿。
老鼠继续在里面啃,还想钻出来,响动很大。半夜起来好几次……于是,亚马逊上定粘鼠板。

周二,one-one。
上午,收到粘鼠板。中午,饭后摆放粘鼠板,碗筷尚未收拾妥当,老鼠不知是被诱惑的,还是给吓到了,吱吱直叫,被轰到墙脚后,小命就玩完了。
晚上,探探网上别人的路线,骑了45km。天色暗下来才发现,尾灯拿去和老鼠斗阵后,忘了装回了。

2012-05-31

Hash algorithms

Either Murmur2 or FNV-1a would be a good fit, according to the answer on StackExchange.

2012-05-10

Syn Attack Protection

In a performance test, a bug was reported: a web application cannot handle clients' requests.

Server side:
  • more than 10k TIME_WAIT;
  • no error - no entry in Event Log or log files;
  • performance is OK (by measuring CPU, MEM, DISK, etc. using performance counter)
    • except the counts of received requests and processed requests are under expected
    • the count goes to 0 from certain time for certain clients in the order of test load (the most heavy working client gets blocked first)
  • the firewall is disabled
Client sides: all clients are running the same tests using the same test tool, except for the test data and test load
  • for certain client, if it fails, it fails forever
  • generates the following exception: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
There seems no obvious errors in source code, both server side and client side.

Finally, I figure out it could possibly be the Syn Attack Protection problem, which is enabled by default and cannot be changed since Windows Vista.
In our case it's not like a typical syn flood attack, but based on the Cause analysis of the "General Network Error" of BizTalk, it could possibly be a Syn Attack, and protected by Windows 2008 SP1.

Other resources:
Next Generation TCP/IP Stack (and especially the changes to registry)
WinNT TCP/IP May Reuse TIME-WAIT Connections Prior to 2MSL

Too many TIME_WAIT:
System.Diagnostics.Stopwatch/QueryPerformanceCounter not working on Amazon AWS, other symptoms, and the solution
The cost on server side
The socket also ties up that particular src/dst IP address and port so it cannot be reused for the duration of the TIME_WAIT interval. (This is the intended purpose of the TIME_WAIT state.) Tying up the port is not usually an issue unless you need to reconnect a with the same port pair. Most often one side will use an ephemeral port, with only one side anchored to a well known port. However, a very large number of TIME_WAIT sockets can exhaust the ephemeral port space if you are repeatedly and frequently connecting between the same two IP addresses. Note this only affects this particular IP address pair, and will not affect establishment of connections with other hosts.

HttpWebRequest related
Howto keep connection live
Timing out after awhile;

Worth a read
Avoiding TCP/IP Port Exhaustion: only the Cause section
A short explanation on TIME_WAIT
TIME_WAIT Effects on Busy Servers: maybe outdated, and tested on SunOS
64k ephemeral port limit is per IP address, not per machine

Outdated
Configure the max limit for concurrent TCP connections
How to harden the TCP/IP stack against denial of service attacks in Windows Server 2003
Registry Settings that can be Modified to Improve Network Performance
Exhaustion of the ephemeral ports
Problems when you make Web service requests from ASP.NET applications
TCP settings that can impact BizTalk Server
MaxUserPort and TcpTimedWaitDelay

2012-04-20

Byte order fallacy and optimization

In Rob Pike's The byte order fallacy, he advocates portability and simplicity, but failed to address the performance issue (wrong to modern processors).
"byte order doesn't matter" - for you local machine; but, should be taken care when handling IO.

The optimization is more interesting: that code block could be optimized by CLang, but not GCC.

Comments from Chris Lattner:
In general, optimizing the original code to a single 32-bit load on little endian targets is not safe: the pointer may not be aligned. However, even after marking the pointer aligned, clang still misses the optimization.
Clang can successfully forward loads and stores when the accessed object is known.
Finally, Clang also optimizes the opposite: turning this code into a "bswapl" on x86.

You won't missing ntohl/htonl, right?
And there is network types support!

2012-04-19

WOW64

Some time ago, I happened to know WOW64 is short for "Win 32 On Win 64" - WOW!

This time for a bug, I looked deeper.
  • Changes to file system are more visible
File System Redirector
only system32 and most sub-folders are taken care of;
"Program Files" is not covered here, but by using environment variables;
for 32-bit and 64-bit programs, they use their own copies - redirected to different folders; the shared are bit regardless, like logfiles, hosts are plain text files;
  • Changes to Registry are more error prone
Registry Reflection - it was used, now deprecated; using the share model;
Registry Redirector - copy model, in most recently versions of OSs
Registry Keys Affected by WOW64 - finally, copy model and share model co-exist

And even worse, Wow6432Node could generate recursive path; regedit handles this correctly;

But, most of us developers are not going to learn all this, or read the Best Practices for WOW64. We'd rather write our own functions, like check the OS's version, and make up the file/registry path by hand, instead of OS APIs, like IsWow64Process(), or environment variables.

2012-04-10

Time related issues

* NTP was not designed to run inside of a virtual machine
* For long running applications, using 32-bit for timing could overflow; but, 64-bit could fail in another way

2012-04-05

My calculation on Yahoo's job cutting

Yahoo! Statement
Yahoo! expects to realize approximately $375 million of annualized savings upon completion of all employee transitions. The company currently expects to recognize the majority of an estimated $125 to $145 million pretax cash charge relating to employee severance...

Based on these numbers:
* Average yearly salary: 375*1000/2000 = 187.5 K$/year (so an average employee, to be cut, gets half of that in hand or paid - 93.75K$/year?).
* Average years in Yahoo: (375/145, 375/125) = (2.586206896551724, 3.0) Year, if all/most of them get a n+1 compensation.

The first average number maybe meaningless;
The second average number might be the common evaluation of employees from a company's business view.

As mentioned here (in Chinese): Yahoo has 14000 employees in total.
Then, this is a 14% cut off, and most of employees are serving Yahoo less than 2 years.
So, Yahoo has/had pretty much fresh blood?

两个估算——雅虎将裁员2000人

雅虎将裁员2000人,每年节省3.75亿美元,裁员成本约为1.25亿至1.45亿美元。

据此估算:
  • 平均年薪:3.75*10000/2000 = 18.75万 USD。
  • 平均工龄:(3.75/1.45, 3.75/1.25) = (2.586206896551724, 3.0) Year。
  • 员工分布:至少14%的员工,加入雅虎不超过2年。
第一个估算值,意义不大。
第二个估算值,如果高管也是按照 n+1 赔偿,还是有点参考意义——工龄对公司的意义,至少是财务上的。
第三个估算值,也没什么意义。或者说,雅虎(曾经)"生机勃勃",有很多新员工可裁?

2012-03-23

Reward or not, or how

It depends.

There is a story Thanks or No Thanks told be Joel Spolsky, happened between him and Noah Weiss.
I just get these few ideas:
  • Noah not only provided the idea, but also with precise charge for each AD, when Joel had no idea;
  • Noah implemented the first draft - sadly, this might be the least value-add and why Noah switch from Software Designer to Product Manager;
  • Joel thought others might think: a software business is basically an idea factory ... Why pay twice? (You know what I think? I just know my own thoughts, and not really.)
  • Joel himself thought:
    • I felt we needed to do something else to express our gratitude. Should we ... ? We were stumped.
    • And what about everybody else at Fog Creek?
    • How do you pay employees based on performance when performance is so hard to quantify? (Woo! Really Hard? Yes, I know, pretty hard to reward!)
    • The very act of rewarding workers for a job well done tends to make them think they are doing it solely for the reward;
    • We decided to give Noah 10,000 shares of stock -- conditional ... our stock is hard to value ... (Emm... Conditional and Hard to value ...)
    • Noah seemed pleased (Or negotiation is expected?) Google made him a better offer ... Thanks for the summer, Noah. We are keeping an empty office here in case you change your mind. (No Thanks and Fxxx Off!)
Anyway, it's still appreciated that Joel shared the story.