Tuesday, March 22

A bug in Outlook RSS Feeds... or is it Firefox's bug?

Last week I blogged about how hard to find a good RSS notifier. Microsoft Outlook 2007 has RSS Feeds functionality, but when there is new items in the feed, it is not notifying the user like new email arrival.

What I want to say in this blog is, when I tried to subscribe one feed, which is using HTTPS connection, the Microsoft Outlook 2007 made a mistake. The link is like https://xxxx.xxx.com/rss.xml, then you should be able to click "Subscribe" to add it into Microsoft Outlook 2007:

(Firefox 4.0)

But when you click, you will see :

The "http://" is added in front of "https://" .

I'm not sure if that is a bug of Firefox or Outlook.
IE 8 only has has the ability to add to its own Active Feed list. I don't think it is actually useful.

Labels:

Monday, March 21

Win7 Wireless connection drops

I have an old IBM Thinkpad T42p with Intel(R) PRO/Wireless LAN 2100 3B Mini PCI Adapter. Yes, it is in 801.11b, very old. But since it can copy files in 180KB/second, why should I replace it?

The router is Linksys WRT54G with original firmware. The computer can dual boot into Ubuntu 10.4, and the connection is very stable. But when it is boot into Win 7, the connection keeps dropping.

I googled "Win7 wireless drops" and literally tried all solutions but failed. The last method that works is:
In the connection property, uncheck QoS, File and Printer Sharing, IPv6, Link-Layer Driver and Responder (I have no idea what the last 2 are):

Then the connection is great! As I mentioned at the very beginning, it is copying files in the speed of 180KB/second now!

I don't know which one of the settings (QoS, File and Printer Sharing, IPv6, Link-Layer Driver and Responder) did the trick, but as long as the network is good, I'm happy. If you have the same problem, try it.

Re: Console Output from a Winforms Application

This is a reply from C#411. Tim shows how to AttachConsole for a WinForms Application. One problem is that the standard output and error output are not correctly handled so they can't be redirected. The comments has some useful hint about this.

After reading it and testing in Visual Studio (2008), here is my initial solution:

Right click the project and select "Property", in the Application tab, you can see "Output Type:" is "Windows Application" in default for Form application. Change it to Console Application, there is no modification needed in your source code. All problem solved. The output can be redirected to text file, and the command prompt is not messed up.

After doing so, there are always 2 windows, 1 for console and 1 for WinForm. What I really want is:

If the application is started with parameters, then start console window (only)
If the application is started without parameter, such as clicking the icon from Explorer, then start the WinForm.


I found FreeConsole WinAPI from Tim's solution, so my final solution is , in addition to the initial solution:

1. In Program.cs, separate the 2 cases, has parameter or not:
[DllImport("kernel32.dll")]
static extern bool FreeConsole();

[STAThread]
static void Main(string[] args)
{


Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length != 0)
Application.Run(new Form1(args));
else
{
FreeConsole();
Application.Run(new Form1());
}
}

2, In the Form1, add a new construction function to deal with parameters:
Boolean CloseAfterCommandLine;
public Form1(string[] commands)
: this()
{
Work with the parameters
CloseAfterCommandLine = true;
}
3, Modify the original Form1(void) to have CloseAfterCommandLine = false;
4, In Form1.Load, close the WinForm if necessary:
private void Form1_Load(object sender, EventArgs e)
{
if (CloseAfterCommandLine == true)
{
Console.Out.WriteLine("Bye. ");
this.Close();
return;
}
...process the form.....
}

Now this application has both Console and Winform.

Labels:

thanks, nicer and simpler solution!
 

Friday, March 18

Friday 星期五

对,就是日本地震那天。三月11日,2011年。
本来娱乐界正在关注《好汉两对半》主角Charlie Sheen被解雇的事,有人关注了Rebecca Black的《星期五》这首歌,发现它无比难听;整个娱乐界就转向它了:


Rebecca Black是谁?她是个13岁的中学生,看到网上一个广告:$2000,成为歌星!就按价付了钱,那个公司给了她两首已经写好的歌曲挑选,她挑中了这首《星期五》,然后公司为她制作了MTV,并放到youtube, iTune上。

由于骂声如潮,她已经被评为后一代天王巨星了(Next Justin Bieber)。

Wednesday, March 16

RSS Notifier

I'm looking for an RSS Notifier to monitor some feeds. I have Bloglines and GReader account, and I read some feeds from Bloglines everyday. But what I need is a "real-time" notification when the feeds have new items, so the Bloglines or GReader doesn't fit into my need.

I thought that was an easy task. Microsoft actually has widgets call "Feed Headlines", but it only has 10 feeds, doesn't allow you to input the feed you want. The default IE RSS Bookmark and Firefox Active Bookmark can not provide notification when a new item is available. Event the Microsoft Outlook 2007 doesn't show notification.

Feed Notification is the best I can find. It is even better that Michael Fogleman open sourced this program. Thank you. When a new item is detected, this program will show up a balloon for 1~60 seconds, configurable. I would like the option to keep the balloon until user click it. Since the source code is available, yes it can be done.

First, line 1123 of view.py:
duration = wx.SpinCtrl(parent, -1, '1', min=1, max=60, size=(64, -1))
Modify it as:
duration = wx.SpinCtrl(parent, -1, '1', min=0, max=60, size=(64, -1))
Second step, line 141, 142 of popup.py was:
141 duration = settings.POPUP_DURATION * 1000
142 self.timer = wx.CallLater(duration, self.on_timer)
Add 2 lines in between:
141 duration = settings.POPUP_DURATION * 1000
142+ if duration == 0:
143+ return
144 self.timer = wx.CallLater(duration, self.on_timer)

It is easy!

PS, after downloading the source code, you have to install:
  • python-2.7.1
  • py2exe-0.6.9.win32-py2.7
  • ply-3.4
  • feedparser-5.0.1
  • wxPython2.8.11.0-py27
  • pywin32-216

copy 1. Icons 2. Sounds 3. Microsoft.VC90.CRT into ./dist folder
copy ./Microsoft.VC90.CRT/msvcp90.dll into C:/Python27/DLLs folder.

before succussfully compile it.

Labels:

Tuesday, March 15

Nuclear Plants核电站的历史

1956年,新中国决定发展自己的原子能事业。1964年10月16日下午三时,我国西部地区新疆罗布泊上空。中国第一次将原子核裂变的巨大火球和蘑菇云升上了戈壁荒漠,第一颗原子弹爆炸成功了。中国人终于迈进了原子核时代。

秦山核电站是我国自行设计、建造和运营管理的第一座30万千瓦压水堆核电站,地处浙江省海盐县。一期工程1984年开工,1991年建成投入运行。年发电量为17 亿千瓦时。

广东深圳的大亚湾核电站是中国第一座大型商用核电站,1987年8月7日工程正式开工,1994年2月1日和5月6日两台单机容量为984MWe压水堆反应堆机组先后投入商业营运。

看看世界上核电站的历史:

世界上第一座核电站:奥布灵斯克核电站(Obninsk)1954年6月 27日运作,2002年停止。
英国第一座核电站:考尔德豪尔(Calder Hall)1956年8月运作,2003年停止。
美国第一座民用核电站:希平港核电站(Shippingport)1958年5月运作。1982年停止。

日本原子力発電Japan Atomic Power Co (JAPC) 在 1957成立,于60年代初建设東海発電所Tōkai Nuclear Power Plant ,在1966年开始发电,后于1998年停止运作。
现在出事的福岛核电站之1号核电站于1971年3月26日启用,共6个发电机组;2号核电站于1982年启用,共4个机组。如果不是这次地震,福岛1号核电站就应该安全度过了核电站所设计的40年寿命,到了退休的年龄了。

Friday, March 11

A lightweight XML Database

When you create an enterprise application, assume it requires database support, you can choose from MS SQL Server, Oracle, Open Source MySQL, PostgressSQL... But if you are creating a desktop application, you have to consider what kind of database engine/driver that your users already installed in their desktop.

MS Access database was a good choice, because most (but not all) users have it installed. I am always curious why they need MS Access.

Anyway, a lightweight database is crucial for desktop developer. One option is to use plain text file to store and search data. That is pathetic, if your data is complicate. I am thinking to have an XML Database, that data can be stored in structured XML file. Google tells me about XML Database:

1, Most of the XML Database projects are no longer exist.
2, Most of them use XPath, XSLT or XQuery to search data.

XPath, XSLT and XQuery have a steep learning curve, and they are not following the design of standard SQL language. What I would like to have is like the description of Ashpool project
It's goal is to use standard SQL92 syntax to query, add, update, and delete XML documents.
Unfortunately, this project is dead as well.


BTW, a compact version, sometimes call mobile version, of MS SQLSERVER is installed in all WindowsCE device. So if you are developing software for WinCE device, you don't need to worry about this.

DateTime.Kind, and SetLastModified problem (C#)

I'm using Response.Cache.SetLastModified to set the time of last modified entry in the database to the affected webpage, so that web browser knows when to cache and when to refresh for new page.

The SetLastModified gives "ArgumentOutOfRangeException" because it thinks the given time is newer than current time, and that is not allowed. The problem is, the given time was saved into database 2 minutes ago, how can it be greater (newer) than current time? I checked the sql server which is sitting in another server, and figured out they are using the same time, same timezone. The database time entry was saved as "LastModDateTimeGMT=getutcdate()".


After carefully checking all the possibilities (that means 2 hours), I focus on the DateTime.Kind property. When the DateTime entry is retrieved from database
DateTime LastModified = (DateTime)(row["LastModDateTimeGMT"])

The value of LastModified has the value of UTC time (that means 7PM, when it is 12PM local time), and the LastModified.Kind is "Unspecified".

DateTime.Kind property tells us, when the .Kind value is "Unspecified", you can call .ToLocalTime() to get LocalTime, assuming the current value is in UTC, or you can call .ToUniversalTime() to get UTC time, assuming the current value is in Local. So, in my case, SetLastModified(LastModified) calls the LastModified.ToUniversalTime() and gets 2PM of tomorrow, when this time is compared with the current time (7PM UTC, 12PM local), it prompts error because the given time is newer than current time.

After setting the .Kind to the UTC because I know the datetime in database is in UTC:
DateTime LastModified = (DateTime)(row["LastModDateTimeGMT"])
LastModified = DateTime.SpecifyKind(LastModified , DateTimeKind.Utc);
everything is good.

So the error actually comes from Sql Server: When a datetime is saved, there is no way to know what timezone it is in:
Time zone offset aware and preservation No
Daylight saving aware No
(datetime (Transact-SQL))
So C# can only give "Unspecified" to the .Kind value when the value is retrieved.

The "Unspecified" is a very dangerous status. The system (or the Microsoft Programers) tries very hard to guess what timezone that is or what timezone you want to have and gives you a wild guess result. Each time you retrieve a datatime from database or from other sources, you should always specify a .Kind for it to prevent this kind of uncertainty.

Another suggestion is: Always use UTC time (getutcdate) in database and in programing, so that you don't have trouble if your server is physically moved into to another timezone, or your program is deployed by another team that you don't know where they are.

Note: By default, the "Cache-Control" is "Private". In this status, the Response.Cache.SetETag will fail. There is no ETag output to client. So Response.Cache.SetCacheability(HttpCacheability.Public or PublicOrPrivate); must be enforced before setting ETag.

Labels: ,

You saved my time, thanx
 

Thursday, March 10

老外公/老外婆的采访录像

昨天下午丫丫不知道在哪里翻出一张光盘要播放。我放进去之后,发现居然是半年前爸爸带来的当地电视台对老外公/老外婆的采访,我还没有看过!

录像是2008年的, 老外公还在世,坐在轮椅上,精神不错。我听他们说过好几次这次采访,现在才终于看到了。

老外婆思路清晰,在录像头面前侃侃而谈:谢谢政府,我们才能寿(在这里是动词)这么老。
采访人员问,政府有没有送给你们什么东西啊?
老外婆斩钉截铁地说“有!”
采访人员很高兴,极力诱导她:“政府送了些什么?”
老外婆说:“旧时...”
采访人员赶紧打断她,因为她要是说出旧时,就不知道是80年代还是50年代了。“已今,已今。”
老外婆跟上思路,说“已今啊,政府给过我1次,给过他(指旁边的老外公)两次。”
采访人员打破沙锅问到底:“给了什么?”
老外婆说:“两块钱。”

这些是电视台送给我们的采访录像,当然这段没有在电视上正式播放了。

时年,老外婆96岁,老外公99岁。