Python 101 - Part 1


Python Enhancements Proposal (guidelines) PEP 8: Style Guide For Python Code PEP 20: Zen of Python


Used to mark blocks, curly braces no longer needed Recommendation is to use 4 spaces for indentation, be consistent and not to mix spaces with tabs


- Use modules available in Python
e.g.: import math
After importing use the module name to call functions:
math.sqrt(5) math.factorial(5)
from math import factorial -> factorial(5) # avoid using math from math import factorial as fac -> fac(5) #shorter name

Help (in REPL cmd)

- Get help on a module help(math)
- Get help on a function help(math.sqrt) help(math.factorial)

int, float

int(10), int(10.2), int(“10”)
float(10), float(10.2), float(“10.2”)

float(“nan”) # not a number float(“inf”) # infinity

Passed CFA Level 2

Now on to CFA Level 2 - June 3rd 2017.

I really love this period of preparing for something worthwhile - which requires your full dedication, focus and attention. It's almost as if you become one with your goal.

Edit [26-July-2017]:
And I cleared it !

Passed CFA Level 1

Happy to share that I cleared CFA Level 1.
Level 1 is supposedly the easiest one out of all level, but it does require time and effort. Thanks to my loving family for bearing with me :)

Moving a window to another monitor

I had done this so many times using mouse and every time I did, I wondered why isn't there a key board short cut to do it. Dragging it felt so slow and at times it hindered productivity.
In Windows 7, the short cut key is:   
Win+Shift+left: to move the selected window to left
Win+Shift+right: to move the selected window to right
If you have only two monitors then pressing left or right again will switch the window between the left and right monitors.
I need to test this on more than two monitors. If you have 3 monitors, then let me know how it works.

Task Library: Common Patterns

Creating a new task

void Main() { Console.WriteLine ("I'm the main thread, starting a new task. My ID: " + Thread.CurrentThread.ManagedThreadId); //the task is started immediately Task t = Task.Factory.StartNew(() => { Console.WriteLine ("I'm a task running concurrently with the thread that started me. My ID: " + Thread.CurrentThread.ManagedThreadId); }); Console.WriteLine ("I'm going away. My ID: " + Thread.CurrentThread.ManagedThreadId); }

I'm the main thread, starting a new task. My ID: 20 I'm going away. My ID: 20 I'm a task running concurrently with the thread that started me. My ID: 24

The method Task.Factory.StartNew() creates a task and immediately starts it. If we want to control when a task starts, we can instantiate a new Task object and call Start() on it.

For e.g.

void Main() { Console.WriteLine ("I'm the main thread, starting…

CruiseControl.NET: Trigger Project From its URL

Recently we had a requirement to trigger CCNet projects from a Nant file. I thought since Nant and CruiseControl work so well together it would be a piece of cake. But no, Nant doesn’t have anything to trigger projects.

The CCTray connects to CCNet server using Remoting, in days when WCF looks old there are still applications using Remoting :-). I could, in Nant, write C# code and use the library provided by CruiseControl and do exactly what CCTray does to trigger a project. Well, it’s possible, but there was still something missing.If I go to a project’s web dashboard and click on the ‘Force Build’ button – then what happens? I thought that since the dashboard is in, it might well make a Remoting call on the server-side. But to investigate I fired up Fiddler and this is what I saw:POST http://your-ccnet-server/ccnet/server/local/project/your-ccnet-project/ViewProjectReport.aspx HTTP/1.1
Host: your-ccnet-server
Connection: keep-alive
Content-Length: 16
Cache-Control: max-age=0

TPL: Parent-Child Tasks and Captured Variables

What do you think will be the return value of the Task named “parentTask”?voidMain()
Console.WriteLine ("Main start.");
//captured variable
int i = 100;

Task<int> parentTask = new Task<int>(()=>
Console.WriteLine ("In parent start");

Task childTask1 = Task.Factory.StartNew(() => {
Interlocked.Increment(ref i);
Console.WriteLine ("In child 1:" + i);
}, TaskCreationOptions.AttachedToParent);

Task childTask2 = Task.Factory.StartNew(() => {
Interlocked.Increment(ref i);
Console.WriteLine ("In child 2:" + i);
}, TaskCreationOptions.AttachedToParent );

Console.WriteLine ("In parent end");
return i;


Console.WriteLine ("Calling Result.");
//next statement will wait on the task
Console.WriteLine (parentTask.Result);

Console.WriteLine ("Main end.");

If a parent-child task hierarchy is set by using TaskCreationOptions.At…