Saturday, January 21, 2012

tell Git to do ignore your changes to some files

Normally Git is so powerful with its branching capabilities, that you seldom need this feature. But sometimes it can be handy if you can simply tell Git to "pretend" that you have not changed some files, even they have really been changed.

If you are using Git as a SVN client, like I do, you will know that Git refuses sync with SVN with local changes. In a large project, it can be that there is a common development environment with a common deployed application server so the client developers can connect and debug without worrying about setup their own instances. So it's also common that when you checkout codes out of the server, in my case it's a SVN repository, the config file contains URL pointing to that common server. If you are the server side developer, then you have to start your own instance and use a client to connect to it. Then you have to change the config file to point the URL to your instance and remember never commit the changes ,otherwise your colleague will kill you :)

There are a bunch of ways to overcome this. You can first only check in your changes without the config files, then stash the config files and then commit to SVN. Or you can create your own local branch with your config files, checkout and rebase the branch each time you want to debug with your config, which is what I'm doing now.

A new way I realized today while reading this post was, I can tell Git simply ignore the changes you have made to some files, with below command:
git update-index --assume-unchanged somefile.txt
this way Git will assume the file is never changed and will perform happily whatever command you want that can normally only be performed to a clean copy. So what happens that the file is changed in upstream repository? By manual, "Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually."

Friday, January 20, 2012

Trick to make LiveMeeting addon for Outlook 2007 automatically connected.

Yes, my company uses Microsoft Office and related tools to handle normal communication. But some times it happens that the add-on is loaded but not really activated. You'll still see the LiveMeeting toolbar in outlook toolbar, but just one button "Enable LiveMeeting" there. This is annoying since you have to remember to push it each time you start outlook.

There is a simple solution to it: go to "start->all programes->microsoft office->microsoft office tools" and select the "microsoft office 2007 language settings", change the language to some other value, save it. Then open it again and change it back to your preferred language. Then start outlook again, you'll find the add-on is activated automatically with 3 buttons.

Tuesday, January 17, 2012

Simple.Data, is it really a good idea?

I've been keeping an eye on micro ORMs for a while. Yesterday I decided to give Simple.Data a try. From the introduction, it looks brilliant, the fluent API, the briefness, the simplicity,..., everything seems to be perfect... well, until I started coding.

Once I'm in VS, I immediately realized that Simple.Data might not be the one I wanted. Its magical syntax heavily depends on .NET's new dynamic feature (yes, it's .NET 4 and above only). That means you loose the static language's best capability: compile time checking. And also you loose the productivity from your tool, there is almost no intellisense provided by VS. You might say, what's the big deal, the syntax is cool. Yes, it's cool. But the problem is, if you make an accident typing or a normal typo (who doesn't?), then compiler won't be there for you and you'll only get the null at runtime. Maybe through unit test coverage may resolve this. But from where I stand, it seems to be just a better alternative of HQL dressed with a new cloth named fluent API.

But I did find some part that really make me happy. It seems Simple.Data recognizes fields separated by underscore. I've got a table with columns like CUSTOMER_ID, and Simple.Data can happily map it to a property named CustomerId. If I rename CUSTOMERID, then Simple.Data still works fine. This is clever!

There is a tool, Simple.Data.Pad, to address this issue. So far I haven't been able to make it work with sqlite yet.

In general, I'm not so convinced yet, but I'll continue on the project to work with it, let's see where I'm going to end with.

Sunday, January 15, 2012

.Net code contracts

I knew there is something new in .NET 4 called code contracts and I also saw some simple code snippets about it. Without digging in, I though it was just some fluent code sugar to help you replace assertions like
if (input_int > 0) throw new ArgumentException("some msg");
with
Contracts.Requires<argumentexception>(input_int > 0);
and come on, this fluent sucks, requires an exception? I would have written a better one!

But I was wrong!

I had some free time today and I opened a long bookmarked url and took a look at it. After reading through the first section, I knew I was wrong. There was post compile code weaving and checking. Without it, there is not much virtual inside, but with the post process, everything can happen. And it turns out to be a very much valuable technology than I thought. Kudos!

Some simple googling led me to this blog that provides some analysis I would also do, using Reflector on the generated code, to see the magic there. Also in their home page, there is a video at the bottom(?!) of the page, after some random comments!

Wednesday, January 11, 2012

Differences between event and delegate in C#

I did not realized some of them until I came across this article. In short,

  1. event is a modifier and delegate is a normal type declaration
  2. thus event can be used in interfaces and delegates can not
  3. event can only be accessed by the class defines it, not even the child classes (an in-direct access through protected method is possible), while delegate is more like a member
  4. normally event follows a convention on signature: foo(object source, EventArgs e)

Sunday, January 8, 2012

Start on Python

It's being quite a while since my last blog and I would like to have something really new to start the new year, Python.

Recently I started teaching my son Python. I don't know Python before. So I have to learn it while teaching him. I intended to learn Python for quite some time, but time has always been my biggest enemy, together with my memory: it's getting worse every year. If I learn something and don't use it immediately, then it's quite possible after 3 months, I'm new to it again. So I start blogging it, trying to make my memory last longer.

Python is an elegant language, it's very expressive and has very brief syntax - though this can be a double side sword - to a experienced programmer with long time Java/C#/C++/C experience, it takes some time to be used to it.

Some points about Python I'd like to note down:

  1. Python started at 1989, and first public appeared at 1991
  2. CPython is the C implemented version of Python, then standard Python
  3. Python generally has 2 kinds of primary types: numbers and strings, though array/list and hashtable/dictionary is first class member of the language.
  4. Python use space indention to indicate sub-scope. The indent does not have to be unified within program, but must be the same for the same scope
  5. like most script languages, variables do not need to be pre-claimed before being used
  6. Python can be compiled into byte codes, like Java class files, with extension .pyo or .pyc
  7. using '''/""", you can have multiple line strings
  8. raw string starts with a 'r': r"c:\a\path\file"
  9. unicode string starts with a 'u': u"this is unicode"
  10. raw_input() will return anything you input as a string, while input() will try to evaluate your input as Python code! For example:
    >>> a = 3
    >>> b = input()
    a+11
    >>> b
    14
  11. Python as +=, -=, *=, /=, similar to other languages, but no i++, ++i, i-- or --i. But ++i or --i won't give you any syntax error, since the +/- are treated two time sign prefix!