Thursday, May 31, 2018

Classic Python Gotch - * on List of Lists - No No!!

[0] * 10 

is okay.

But,

initializing using

[ [0] ] * 10
So you get [ [0] , [0], ... [0] ] 
is NOT okay - you've built a list of copies of the SAME list!!!

You wouldn't guess would you? This is where Larry Wall would have dumped out a nice warning. Why can't python marry with Perl?

Tuesday, May 29, 2018

Contrasting Styles - Inverting an Adjacency Graph

Mine :

def inverse_graph(graph):
    invG = []
    for i,row in enumerate(graph) :
        sieve = [1] * len( row )
        sieve[i] = 0
        invG.append( [xor(x[0], x[1]) for x in zip(row, sieve)] )
    return invG

Instructor :

def inverse_graph(graph):
    n = len( graph )
    invG = []
    for i in range( n ) :
        invG.append( [] )
        for j in range( n ) :
             if i != j :
                   invG[i].append( 1 - graph[i][j] )
             else :
                   invG[i].append( 0 )
    return invG

Which do you feel is more idiomatic?

Here's a handy hack - if you had a list of ints, which is a subset of the first n non-negative ints (0,1,2,.. n-1), how do you build yourself a list of ones and zeros such that the entry is a one when the ordinal number representing that entry is in the list of ints? ( [0,1,4], 5 ) --> [ 1, 1, 0 , 0 , 1] )

sieve = list(map(lambda x: 1 if x in cover else 0, range(len(graph))))

Like?

Wednesday, May 16, 2018

Visual Studio Code Setup for Simple Build In Local Directory No Frills

Assuming :

You're okay with a.out, then :

{
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Generated task by Debugger"
        }
    ],
    "version": "2.0.0"
}

Tuesday, May 15, 2018

Python : Access Your Own Docstring

You have a function in a file and you want to view the docstring. You're in the python shell. What's the quickest way?

> Cheat - assume you're in the same directory :)

>>> from basename import * # file is basename.py
>>> func_name.__doc__     # will show it to you

Saturday, May 12, 2018

Python Assign Characters of a String to a List

Or, convert a string to a list :

type( a )
<class 'str'>

b = list( a )
# is all you need :)

Thursday, May 03, 2018

Python Sorting Two Lists Together

I don't get it either, but it works..

https://codereview.stackexchange.com/questions/138702/sorting-two-lists

s = sorted( zip( a, b) )    # a is master, b is slave
a,b = map( list, zip(*s) )
# and that's it! The genius of Guido Van Rossum

Highlight Selected Cell or Row in Excel - Aus Tom Urtis

It's literally this easy, if you know how.

To highlight the selected cell (automatically that is.. not doing something each time you select something :) :

Get to the Visual Basic editor (might have to enable the Developer tab and then hit View Code -- google this for the way, it's not here)
Then, paste (thanks TU) :

Private Sub Worksheet_SelectionChange(ByVal Target As Range) Application.ScreenUpdating = False ' Clear the color of all the cells Cells.Interior.ColorIndex = 0 ' Highlight the active cell Target.Interior.ColorIndex = 8 Application.ScreenUpdating = True End Sub

That's it. You just paste this and File > Close and Return to Excel and MAGIC happens! Sufficiently advanced technology!!

And for highlighting the entire row AND column (tweak the code as necessary if you want only..) :

Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub Application.ScreenUpdating = False ' Clear the color of all the cells Cells.Interior.ColorIndex = 0 With Target ' Highlight the entire row and column that contain the active cell .EntireRow.Interior.ColorIndex = 8 .EntireColumn.Interior.ColorIndex = 8 End With Application.ScreenUpdating = True End Sub

And how do you know what number to use for the ColorIndex?

http://dmcritchie.mvps.org/excel/colors.htm

Friday, April 27, 2018

Scrum and Jeff Sutherland


Priorities

"He who will defend everything defends nothing." -- Frederick the Great of Prussia

Product Development

Whenever you're making something, you want to put in in the hands of those who are actually going to use it as fast as possible. You want to do this even before you make 20 percent of the features. You want to do this with something that delivers at least a tiny bit of value. I call this a "Minimum Viable Product," or MVP.

Risk

The three most common types are market risk, technical risk and financial risk. Or, to put it another way : Do people want what we're building? Can we actually build it? Can we really sell what we build?

Medco case study (Pg 114) :

It took the company nearly six months to figure out that they couldn't do it in time. Their calculations showed that, in the best-scenario, they'd deliver the system at least one year late. Probably more.

Why it took them six months to figure out that they couldn't do it in time is something that bears examination. It wasn't that they weren't smart, or didn't have the right teams in place, or even the right tech. It wasn't that they weren't working hard or being competitive. You don't get to be the biggest company in your sector without doing all that.

It was because they made a very basic mistake. They thought they could plan everything ahead of time. They spent months of effort making the sort of detailed plans that seem plausible - that are laid out in pretty charts and include carefully precise steps and almost always describe a fictional reality.

As I've said before, the very act of planning is so seductive, so alluring, that planning itself becomes more important than the actual plan. And the plan becomes more important than reality.

Wednesday, April 25, 2018

How Can I Go To A Sharepoint Directory Through the Cygwin Terminal (konsole)?

First, like a good person, map the Sharepoint site to a network drive like so :


  1. Open a File Explorer (aka Windows Explorer).
  2. Right click on "This PC" and select Map Network Drive..
  3. On the resulting dialog, click the underlined link for "Connect to a Web site that you can use to store your documents and pictures." This pops up a new dialog "Add Network Location".
  4. On this new dialog, click Next.
  5. You'll see an option (that may be already selected; if not, select it) that says "Choose a custom network location". Click Next.
  6. Now, paste the "https://whatever.sharepoint.com.." and click Next.
  7. Now, it asks you to name your new network location. Give it a name. You'll be able to go here easily from the File Explorer from now on.

Excellent.


  1. Now, right click on the new folder name you'll see under This PC in File Explorer.
  2. You'll notice that the Target shows you the familiar URL while the "Comment" shows you the real deal : \\whatever.sharepoint.com@SSL\DavWWWRoot\whatever..
  3. Believe it or not, you can click here, then do Home to go to the beginning and do Shift+End to select all of it and then, in a command prompt, just do :


net use r: \\whatever.sharepoint.com@SSL\...

(you get the idea - you can just do a right-click to paste from clipboard)

Verdict - Cygwin is *the* best - easily whacks Windows Subsystem for L / Ubuntu and Git Bash as well. All you get with Git bash is some cute colouring. What you get with Cygwin/xterm that you don't get with the others :

easy font re-size with CTRL+/-. Of course, you have to put up with the annoying /cygdrive thing, but hey, pick your poison :)