Text

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Saturday, January 4, 2020

Unix Notes

netstat -i
shows what network are connected

tail /var/adm/syslog
shows tail end of specified file.

head <filename>
shows head of a file

man CC
online manual, topic CC

ls
List. like dir /w

ls -l
list with details

ls -l |more
page the output

du
Disk utilization.  Like a tree.

mv <old> <new>
move.  rename.

pwd
print working directory

$HOME
holds home directory

find / -name socket -print
find topic socket, print to screen

cc <name.cxx> <name2.cxx>
ANSI C compile

CC <name.cxx> -g
C++ compile with debugger info

ps -e
list all running processes with process ids

ps -e |grep swi
list all running processes starting with swi

kill <proc id>
stop a running process

cmod 777 <filename>
gives permission to all (wildcards allowed)

rm <filename>
removes file, wildcards allowed

cat <filename>
Dumps file contents to screen.

cat *.csv | filename
Concatenates all csv files in current folder to a single file.

cat *.csv | hdfs dfs -put - target filename
Concatenates all csv files in current folder to a file within Hadoop distributed file system (starting from edge node).

wc -l *.csv
Word Count for all CSV files in current folder.




Thursday, October 24, 2019

Visual Studio Remote Debugging 2019

There is more than one way to do this.  Here is a summary of what has worked best for me.

One time SERVER MACHINE setup:

The remote debugger needs to be installed

They are constantly changing where to find it, but here is where to find it today:


One time DEVELOPER MACHINE setup

Visual Studio settings

Under tools / options then debugging / symbols:

  • If the debug mode PDB files for your projects are set up to be placed to a central symbols location then make sure that location is represented in the "symbol files locations" area.
  • For manageable performance:  Check "Load only symbols for specified components" but do not actually specify any in the "specify include modules" window.  This will only load the symbols for the components you have built and placed symbol files next to.  Otherwise it can take a VERY long time to load up symbols when starting to debug.

One time EACH PROJECT settings change


  • Do these changes under debug mode only.
  • If a project is usually maintained by engineers who debug it on their own machines then consider not checking in these project settings changes into source control.
  • If your debugging symbols PDB files get places in many different locations specific to each project, then do the steps in the previous "One time DEVELOPER MACHINE setup" section, for the project in question.
  • The working directory must be set to a location that has the target components on both the local and remote machines.  Research item:  This might only be true for unmanaged C++.
  • Within your solution, make sure the project you want to debug is set up as the "startup project", just like when debugging locally.  It will give a confusing error message if you have the wrong project set for startup.
  • The rest of the considerations are different for unmanaged C++ or managed C#.NET projects.

Unmanaged C++

  • For debug mode unmanaged C++:  Link with static libraries instead of the DLL versions.  This avoids the need to install debug mode runtime libraries on the server.  You may need to undefine _AFXDLL.  It is unlikely your component is truly an "AFX Extension".

Under properties / configuration / debug


  • Fill in the remote debugging fields to point to the server and port displayed by the remote debugger.
  • I’ve had the most luck with attach set to NO, but this is because I often work on processes that run multiple instances of the same component from different processes, in which case the debugger tries to attach to ever single one of them.  Unhelpful and takes a VERY long time.
  • Make sure the copy of the executable you want to run is not already running on the server.
  • Let the remote debugger launch your executable.

Managed C#.NET

Under properties / debug


  • Check the Use Remote Machine box and fill in the machine name and port as seen in the remote debugger window on the server.  E.g. servername:4024
  • Set whichever command line arguments necessary.

One time GETTING READY FOR DEBUGGING steps


  • Launch remote debugger
    • Search "Remote Debugger" on the server.
    • Make note of the machine name and port it displays.
  • Set breakpoints
  • Be ready to to copy components to the remote machine
    • Be this post-build steps, an XCOPY script, or manually copying with file explorer.  But you could be doing this over and over, so plan accordingly.
    • C++
      • Copy component plus the PDB file from the same build.
    • C#
      • Make sure all dependencies are present on the remote machine.  Assemblies, config files, etc.
      • Copy component.  No need to copy the PDB file, it can successfully use the local one.

DEBUGGING steps

Place code to be debugged on remote machine


  • Build in debug mode
  • Copy components to remote machine

Start debugging

It will work like usual except:

  • Choose the Remote Windows Debugger
  • Some parts will take longer, especially loading symbols.





Friday, September 13, 2019

Play it straight

It's sometimes hard to satisfy a sense of humor when programming.  But remember that the joke wears thin after a while, so it is almost never worth including a joke within production code.  It's hard to tell what circumstances it will come up in later, or with whom it will come up.

I once had a manager encourage me to slightly rename a component named with an acronym.  It was to become the "File Update Control Module".  I called it something else.  Which made it easier to not add insult to injury later during customer support issues.

Another time, I had a program that had some functionality that included doing two complicated calculations that culminated in comparing the two results with each other.  Although I named the functions well to self-document what each calculation result was, I still called the two final variables "apples" and "oranges".  It was apparently a slow day, so I amused myself by having it then compare apples to oranges at the end.  The code reviewer was amused as well, but their advice to name the variables more appropriately was good.  The joke wears thin, and any amusement is more than offset by even a little extra cognitive load on anyone else years later trying to determine what that code was doing.

One co-worker liked setting flag variables to a value of -666.  He would name a constant "HellFreezesOver" just so he could have code containing "do...until" loops that included "until (HellFreezesOver)."  One time that value bled out into an error message reporting error code -666.  A customer already impacted by the error expressed not being amused by the error code.  Will a customer to feel an issue is being taken seriously if the error message itself appears to include a joke?

Monday, August 19, 2019

Numpy array multiplication


Dot product

  • Applies to one dimensional arrays, aka vectors.
  • The sum of the products of the components of the vectors.
  • The result supposedly represents “how similar the two vectors are”.
  • The first elements of each vector multiplied, then the second, third, etc.  Then add them all together.
  • Aka inner product
  • Aka scalar product.  Since the result is a scalar.
  • Notation is the two vector names next to each other with a superscripted T above the first.
  • In Numpy, the dot method of the first vector is called, passing the second vector as an argument. 

Hadamard product

  • Can do this on vectors of the same size.
  • Result is a vector also that same size.
  • The first elements of each vector multiplied and become the first element of the answer. Repeat for all elements.
  • Notation is a very small centered circle between the elements.
  • In Numpy, the * operator is used.

Matrix multiplication

  • Applies to arrays with dimensions higher than one.  
    • Technically when there is only one dimension in either or both arrays, it is the same process described here, but each row and/or column have only one element, so it can be simpler to think of it only in terms of the "Dot Product" description above.
  • In Numpy, a matrix will be an array of arrays
  • Can multiply two matrices A and B if the number of [rows, columns] in matrix A is equal to the number of [columns, rows].
  • Result is another matrix with the width of B and the height of A.
  • Each element of the result is a scalar.
  • Each element of the result is the dot product of corresponding rows of A with columns of B.
  • The first row of the result is the dot product of the first row of A with each of the columns of B.
  • The second row of the result is the dot product of the second row of A with each of the columns of B.
  • And so on.
  • Notation is the names of the two matrices next to each other.
  • In Numpy, the dot method of the first array is called, passing the second array as an argument.


Friday, August 16, 2019

Recommended process for process document distribution

Picture a "process" document that describes how a group of people will need to do some part of their ongoing work from that point forward.  At some point that group needs to become aware of it.  Such times include:
  • When it is first created.
  • When it is updated.
  • Introducing a new hire to it.

Should you send them the document?

No.  It's not the end of the world if you do, but, there is a better way.

Why not send the document?

Basically it wastes little slices of time multiplied by the number of recipients.
  • Everyone who receives it is now responsible for curating their own private copy every time a new revision is sent out.  This wasted time is multiplied every time another update is sent.
  • The document is just a snapshot of the actual document and will be out of date the moment any other modification is made.  There will always be doubt about whether any given copy is the most recent update, and possibly time wasted making sure.
  • New hires will need to obtain a copy.  Usually after confusion caused by not knowing that the document exists.  Usually wasting their time searching and the time of other people as they are forced to ask around about it.
  • Sending a copy of the document attached to a mass e-mail also wastes space in the e-mail system.
So then how to provide the document to the group?

Recommended Process

Get ready

Establish an official location for the document if one does not already exist.  If an effective broader official location for such documents does not exist, that is a larger problem to be solved separately, but if that is the case, don't let it stop you.  Work around the problem for now.  Pioneer a location.  Be a voice for positive ongoing improvement.  If this step is done properly, it will only need to be done the very first time.

Get set

Store the document there.  This shouldn't take much time.  Presumably you've saved the document "somewhere" before you want to send it, right?

Go

When attention is needed, send people of a LINK to the document along with any introduction or comments about what was just changed.

This process works even better if

  • The "official location" of the document is within a broader "official location" for all similar documents, and that location is in the form of something that the audience can be subscribed to receive notifications when something is updated.
  • New hires are given the location of the broader "official location", so they automatically have any new documents as they are added.