Tuesday, June 23, 2015

gitignore file repository

github hosts a repository for .gitignore files. C# developers are interested in VisualStudio template.
To make NCrunch ignored I had to add additional line:
*ncrunch*

Git remove files that were pushed but are added to .gitignore file

git rm -r --cached . 
git add .
git commit -am "Remove files ignored in .gitignore"

IEnumerable Sum extension for complex type

I was not able to find a simple/working example in internet. This is how to do it:
public static Money Sum<T>(this IEnumerable<T> data, Func<T, Money> selector)
        {
            var money = new Money(0);
            money = data.Select(selector.Invoke).Aggregate(money, (current, selectedMoney) => current + selectedMoney);
            return money;
        }

Saturday, April 18, 2015

WinDbg strikes back

Typical problems with winDbg:

.loadby sos mscorwks
Unable to find module 'mscorwks'


for .NET framework 4+ use
.loadby sos clr

SOS does not support the current target architecture.


I see this exception when I run multiple commands because dump was created on 64 bit arch for 32 bit process (I still recommend taking dump using 32 bit Task Manager that is located under C:\Windows\SysWOW64).
!wow64exts.sw
Helps to run some commands like
!clrstack

Tuesday, February 24, 2015

Universal Google Analytics Event Tracking Problems

I keep receiving a following error under Google GA Debugger plugin in Chrome:

Command ignored. Unknown target: undefined

In Google Analytics (GA) I do not see any events. I am using Universal Google Analytics and I attached it to a page thru Google Tag Manager (GTM).
When I change in GTM Tag Type from Universal Anaytics to Custom HTML Tag and paste manually GA code everything works.

Solution to the problem is to set a Tracker Name in GTM config

and raise events in a following way (Tracker Name is set to internalTrackerName):
ga('internalTrackerName.send', 'event', 'button', 'click', 'View Bookings');

Saturday, February 21, 2015

Python after years

Recently I've been installing python on Windows. I haven't done it for few years now. I was surprised that msi installer by default installs pip with its dependencies. It also comes with a basic IDE. This is really nice. Pip seams to be a standard now. But definitely there are few things that didn't change. A quick look at Django code:

def b85decode(b):
        _b85dec = [None] * 256
        for i, c in enumerate(iterbytes(_b85alphabet)):
            _b85dec[c] = i

        padding = (-len(b)) % 5
        b = b + b'~' * padding
        out = []
        packI = struct.Struct('!I').pack
        for i in range(0, len(b), 5):
            chunk = b[i:i + 5]
            acc = 0
            try:
                for c in iterbytes(chunk):
                    acc = acc * 85 + _b85dec[c]
            except TypeError:
                for j, c in enumerate(iterbytes(chunk)):
                    if _b85dec[c] is None:
                        raise ValueError(
                            'bad base85 character at position %d' % (i + j)
                        )
                raise
            try:
                out.append(packI(acc))
            except struct.error:
                raise ValueError('base85 overflow in hunk starting at byte %d'
                                 % i)

Ech, not much changed since I was looking at python programming style years ago. Its not language fault, it is more about how well people are writing open source code. How much does it take to understand what a method above is doing - the method name is a great help, but to understand implementation takes more than few minutes, and it is far more time than few seconds.

Wednesday, January 28, 2015

Latency Numbers Every Programmer Should Know

I am not sure if 1% of programmers know it, but it is a great reference, kudos to Jeff Dean and Peter Norvig: Latency Comparison Numbers
L1 cache reference                            0.5 ns
Branch mispredict                             5   ns
L2 cache reference                            7   ns             14x L1 cache
Mutex lock/unlock                            25   ns
Main memory reference                       100   ns             20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy              3,000   ns
Send 1K bytes over 1 Gbps network        10,000   ns    0.01 ms
Read 4K randomly from SSD*              150,000   ns    0.15 ms
Read 1 MB sequentially from memory      250,000   ns    0.25 ms
Round trip within same datacenter       500,000   ns    0.5  ms
Read 1 MB sequentially from SSD*      1,000,000   ns    1    ms  4X memory
Disk seek                            10,000,000   ns   10    ms  20x datacenter roundtrip
Read 1 MB sequentially from disk     20,000,000   ns   20    ms  80x memory, 20X SSD
Send packet CA->Netherlands->CA     150,000,000   ns  150    ms
 
Notes
-----
1 ns = 10-9 seconds
1 ms = 10-3 seconds
* Assuming ~1GB/sec SSD