Wednesday, October 11, 2017

Agile Austin, Oct 10, 2017 - Rage, Disorder, and Your Agile Team

At Agile Austin this month Matt McBride from Genesis10 talked about Agile team culture at Kasasa.com headquarters.
He wrote Leadership Patterns for Software and Technology Professionals.


My random notes:
* Rage, Stress, and Its Impact
Rage is one specific behavior that our teams are exposed to in their daily lives.
Rage and anger are types of stress.  Rage and anger are specific instantiations of the "abstract class" named stress.

What is impact of stress?: Health, Behavior, and relationships with our team members.
Stress can be a good thing for short periods.

Cortisol is the chemical produced during stress.  Long-term Cortisol can shrink your brain.
Sources of Anger: disappointment, frustration, judgement, rejection fear.

Anger make people indiscriminately punitive.

* Threat of Architectural Disorder
complexity grows at an exponential pace
Nonfunctional features (security, testing ...) tend to get lost or ignored
Grady Booch on characteristics of successful projects: strong architectural vision and well-managed iterative cycle (scrum).

Major Classes of Program Features to  Think about At the Beginning
1. Significant features for business/customer
   We look for functional features with a high business risk
2. Architecturally significant features
    We look for functional and non-functional features with high technical risk.

From Agile we need to embrace these:  commitment, courage, focus, openness and respect.

Missing in college education is leadership skills.  How to educate non-technical customers.


Leadership:
1. Leaders are avid learners.
Leaders try, fail, learn, and grow.
2. Leadership is a choice.
We have to change the way we think about ourselves, careers, and work.

* Tactics for reducing anger, rage, and stress
Have everyone take one deep breadth
Then followup with a specific goal

Partnership Pattern - moving forward from newbie to Trusted Partner
1. Performance - establish record of success
2. Credibility - be trusted based on performance
3. Trust -
4. Become a Trusted Partner

* The resolute pattern
Recast problems as assumptions to be questioned

Invest in your team and in development of leadership and interaction skills.




Monday, October 09, 2017

Continuous Integration and Delivery with Visual Studio and Azure - Austin .Net Users Group October 9, 2017

Shawn Weisfeld (Shawn is also founder of http://UserGroup.tv) created and deployed a project from scratch at the Austin .Net Users Group. VisualStudio.com gives us a free repository. You can create a project stored in the cloud. Team Services is free for teams under 5 people. Visual Studio online and VS local easily share a repository by default. ms.portal.azure.com will host. You chose how many machines and the size of the machines. Azure will create a load-balancer for the cluster. Azure will automatically collect telemetry. Changing the environmental variables on production is easy - you don't have to create multiple versions of the web.config for each environment. Shawn showed how it really is insanely easy to deploy an app in Azure to cluster using VisualStudio.com, Azure.com and a local copy of Visual Studio 2017.

Saturday, September 23, 2017

How to Embed a JavaScript Script in a Handlebars Template

While working on the next generation of ThePresidentsOftheUnitedStates.com, a site I'm working on with my 10yr old daughter, we needed to add a little bit of JavaScript in the template to add the ordinal suffix to a number (e.g., "3rd President").

It's easy enough to do by registering a Handlebars helper and calling it with "{{{nth number}}}". Here's the code in context:

<header>
<h1>The Presidents Of The United States</h1>
</header>
<script>
Handlebars.registerHelper('nth', function(n) {
  return new Handlebars.SafeString(
    ["st","nd","rd"][((n+90)%100-10)%10-1]||"th"
  );
});
</script>
<script id="entry-template" type="text/x-handlebars-template">
{{#each presidents}}
<div class="row" itemscope itemtype="http://schema.org/Person">
  <div class="col-sm-4 centered" > <!-- left panel -->
  <h2 class="name" itemprop="name">{{fname}} {{mname}} {{lname}}</h2>
  <p class="ordinal">{{number}}{{{nth number}}} President of the United States</p>
Special thanks to Tomas Langkaas from stackoverflow for the "nth" algorithm in JS.

Tuesday, September 12, 2017

Git Examples and Notes


Git Notes and Examples

What is Git?

Git is a distributed version control system written by Junio Hamano and Linus Torvalds. Linus said the name came from British slang for an argumentative pig headed person.

Where to Get Git?

You can download Git from git-scm.com/downloads

Tools

You can download a visual GUI for Git at www.atlassian.com/software/sourcetree.

"gitk" is a handy GUI tool installed with some systems.

Documentation

Scott Chacon's and Ben Straub's book, ProGit is downloadable for free at git-scm.com/book/en/v2

Atlassian has a great tutorial at www.atlassian.com/git/tutorials

An interesting interactive visual demo of Git is at https://onlywei.github.io/explain-git-with-d3/#push

Git from the Bottom Up: https://jwiegley.github.io/git-from-the-bottom-up/

Getting Started

git init
creates .git directory and machinery to create a git repository
git clone https://github.com/jquery/jquery.git
clones (copies) repo and creates a local repository with all the commits, trees, blobs, branches, and tags, but not the remotes. For that use the "-mirror" switch.
git clone presidents presidents1
copies repo "presidents" to "presidents1".

config

"git config" allows you to put information into the "~/.gitconfig" file for future sessions. This tells "git" things like your name and favorite editor.

git config --global user.name "Mitch Fincher"
git config --global user.email "me@myhost.org"
git config --global core.editor vim
git config --global help.autocorrect 1
git config --global color.ui auto
git config --global --list

checkout

git checkout -b {newBranch}
create a new branch from the current branch. It is equal to doing a "git branch newBranch" and then a "git checkout newBranch"
git checkout MyBranch
set the current branch to "MyBranch"
git checkout -- my-file.txt
checkout a copy of "my-file.txt" from the current branch and overwrite the current copy.
git checkout 661d5fd32
detach the HEAD and set directly to a commit
git checkout -
checkout previous branch used

What's Going On?

git status
shows your current branch and any interesting files
git status --short
shorter list with first two cols significant
git config --list
show all settings; and from ~/.gitconfig
git log
see the changes
git log --oneline
to show quick one line summary
git log -2
see last two changes
git log --pretty=oneline
will not show commits that are reset over
git branch
shows all your local branches
git branch -r
shows all remote branches
git branch -a
shows all remote and local branches
git branch -vv
shows a verbose last commit on each branch
git branch --merged
shows all branches that have been merged
git branch --no-merged{hashid}
lists branches that have not been merged i.e., list branches whose tips are not reachable from the hashid (HEAD is used if hashid not specified)
git branch newBranch
create new branch named "newBranch"

Deep Magic Commands

git cat-file -t 5f831d630dd0
returns the type of the object, like "blob","commit","tree", or "tag"
git cat-file type hash id
shows the contents of the file pointed to by the hash id
   git cat-file blob 5f831d630dd069aca58b3a164ff526b53c142456
'Hello, world!'
   
git cat-file commit a7cc8785c5bd3594c9659b779ed56487097281b4 //shows the contents of a commit with two files, "texas" and "greeting":
tree a822836950b935d16f8ee572429dd1d754a85a73
parent 640f3af9f9e883a5ed0102154e453170f04267b7
author Mitchell Fincher <mitchf@fincher.org> 1505507251 -0500
committer Mitchell Fincher <mitchf@fincher.org> 1505507251 -0500

texas greeting
  
git ls-tree {hashid}
show all the objects in the commit pointed to by a tree.
$ git ls-tree master
100644 blob 5f831d630dd069aca58b3a164ff526b53c142456    greeting
100644 blob b6d99afd00cffebbd33e6a99c946e4bf54319ec4    texas
   
git hash-object file1.txt
show the SHA1 hash created by the contents of file1.txt. Use the "-w" option to write the object to the filesystem with a name of its hash.
git ls-files
show info about the files on the stage (index)
git rev-parse HEAD
HEAD is usually a reference to a branch which contains a pointer to a commit. "rev-parse" derefences the branch and shows the hash id of the commit without having to go through the intermediate branch.
git rev-parse HEAD
3a9aae03b78bb617e9ec7822289e4a991ea7c2d8

cat .git\HEAD
ref: refs/heads/master

$ cat refs/heads/master
3a9aae03b78bb617e9ec7822289e4a991ea7c2d8
git write-tree
takes the contents of the index (staging area) and creates a tree.
echo "My comment" | git commit-tree {hashid}
commit-tree takes a tree hashid and creates a commit from it. By suppling the comment, git can do its work without asking you for it.
git update-ref refs/heads/master {hashid}
writes the hashid into the file refs/heads/master, making that commit hashid the current one for the branch master. This could be done manually:
echo {hashid} > .git/refs/heads/master
You can also use update-ref to create a branch manually. To create a new branch pointing to a hash you enter:
git update-ref refs/heads/rel2 eafd8ea4563a802f6ad9dd65bf1222689785af26
git symbolic-ref HEAD refs/heads/master
sets the value in .git/HEAD to be "refs/heads/master". You can try to do it manually with "echo", but it may put a space at the end of the line. To do this manually you should edit in your fav editor.
echo ref: refs/heads/branch1> .git\HEAD
C:\Users\mfincher\gittest (master ) #notice space at the end

What's in them files?

When you create a new repo with "git init", git will create a new directory, ".git" with these files:
$ ls -F
HEAD         description  info\        refs\
config       hooks\       objects\
HEAD
This file typically contains one line of text. It points to the branch currently checked out. Usually a symbolic link pointing to a friendly name like "ref: refs/heads/develop", but can point directly to a commit hash.
description
you can edit this file to name your repo
config
contains project specific settings and the URLs for your remotes, e.g., where does "orgin" point.
info
keeps a list of file patterns to ignore.
C:\Users\mitchf\gitdemo2\.git (master)
$ cd info

C:\Users\mitchf\gitdemo2\.git\info (master)
$ ls
exclude

C:\Users\mitchf\gitdemo2\.git\info (master)
$ cat exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
hooks
contains hook scripts
index
a single file which is a mini-file system containing all the staged changes
objects
stores all the contents of your repo objects in "blobs". The files do not have names. Their SHA hash id is their name. The file's real name is stored elsewhere in the tree. So, if two files have the identical contents, the contents will be stored only once. The two trees will point to the exact same file.

Inside the objects directory is the top layer of subdirectories named the first two characters of the SHA hash. Underneath that directory are files named with the remaining 38 character hash.

$ ls objects
1f    48    5e    76    81    93    ab    ce    f3    pack
3f    4a    64    7a    8a    99    bb    d6    f4
47    58    6f    7c    8e    a6    cd    ea    info

$ ls objects/lf
025359eec40ca200dc800f72ff78f6153a502a  82622d17e916d82b3badc38fbe8e025cd4a7d9
1621638abb2fbf888eef4e5a9314e74e055e99  8d7e0431e16b7f03856a5a9ac874d1bea13bcb
1af4d5ff8194432203d4bfd7b78f07426d8362  905c34c72391fa21571b54dd1a8d2711186975
refs
stores reference pointers to objects like heads, remotes, stashes and tags.

Misc

git remote update origin --prune
removes from your local list the branches that have been deleted in origin
git ls-files
show all the files in the repo

Help Me

git help
get general help
git help config
get help on the "config" command

Adds and Commits

git rm '*.txt'
stage the removal of all the txt files
git add file1.txt
adds file to the stage
git add file1.txt file2.txt
adds files to the stage
git add '*.txt'
adds wildcards, but must have single quotes
git add --all
adds all new, deleted or modified files
git add -A
stages All
git add .
stages new and modified, without deleted
git add -u
stages modified and deleted, without new
git commit -m "my commit message"
commit staged files to repo

Remoting

git remote
returns the name of the current remote site
$ git remote
origin
git remote -v
use the verbose option to see the URLs for reading and writing
$ git remote -v
origin  https://mysite.com/myproject (fetch)
origin  https://mysite.com/myproject (push)
git remote show origin
shows the URL for "origin" and remote branches.
git remote add origin https://github.com/try-git/try_git.git
adds a remote location with the name of "origin" and points it to the URL. This creates a shorthand name, "origin", for the URL.
git remote set-url origin git@github.com:User/UserRepo.git
changes a remote location's value
git push -u origin master
pushes your code to the master branch of the repo defined by "origin"
git remote rename {oldName} {newName}
renames the remote
git remote remove {branchName}
removes branchName from your list of remotes
git remote add {remoteName} https://github.com/try-git/try_git.git
adds a new remote. This will add a section in your "config" file to map the name to the URL. For example after adding "trygit", "config" contains:
 [remote "trygit"]
   url = https://github.com/try-git/try_git.git
   fetch = +refs/heads/*:refs/remotes/trygit/*

What's Changed

git diff
see changes you've made, defaults to HEAD
git diff HEAD
see changes you've made
git diff {branchName}
see changes between current branch and {branchName}
git diff --staged
what has changed in the staged area
git diff commitid
see changes from commitid

Reset

"reset" is confusing because it can edit the references, the index (stage), and trees. Note: "--mixed" is the default.

What do the reset options affect?

reset optionworking treeindexHEAD
--softX
--mixedXX
--hardXXX
git reset HEAD
remove changes in the index aka "the stage" and resets the HEAD pointer. (default option is "--mixed")
git reset file1.txt
removes file1.txt from the staging area
git reset --soft HEAD^
moves HEAD to its parent, leaving the index and working directory files untouched.
git reset --mixed HEAD^
moves HEAD to its parent, and resets the index, but leaves the working directory files untouched.
git reset --hard HEAD^
moves HEAD to its parent, and resets the index and the working files. (You should do a "git stash" before doing this reset)
git reset --hard eb70244
sets HEAD to specific commit and erases all changes in current working tree. Use "git checkout eb70244" to preserve changes.
git reset --hard eb70244
sets HEAD to specific commit and erases all changes in current working tree. Use "git checkout eb70244" to preserve changes.
git update-ref HEAD HEAD^
same as "git reset --soft HEAD^"
git reset HEAD^
undoes last commit and leaves files ready to be staged
git reset origin/master
restore to origin's version

Merge

git merge feature1
merges changes from feature1 into current branch. The current branch is updated, but the target branch, "feature1", is unaffected. Typical flow to merge changes from a feature branch into master with no conflicts:
  git checkout master
  git checkout -b feature1
  # make edits and commits on feature1
  git checkout master
  git merge feature1
  git branch -d feature1 #cleanup by deleting feature1 branch

Deleting

git branch -d feature3
delete branch feature3
git clean -df
delete untracked files

Push

git push
pushes local changes to origin
git push -f
forces local changes to origin overwriting others changes. Not recommended except in extreme cases.

Rebase

git rebase branchName
make branchName the "base" of the current branch. Conflicts will need to be resolved.

    
git rebase -i HEAD~3
to go back three commits, note lines in reverse order now
git rebase --abort
stop the rebase and roll back

Stash - store changes off to the side

"stash" saves your changes into a genuine commit that can be used like any other commit.

git stash save
stashes staged and unstaged changes onto stash queue and revert current branch to last commit
git stash save "message"
stash to a name
git stash
appends "save" at the end for you
git stash apply
brings back the stash

if you enter "git stash && git stash apply", it will create a snapshot of your system.

git stash list
shows list of stashes with previous commit
git stash list --stat
show more info, log options can be used e.g., "--oneline"
git stash apply stash@{1}
brings back stash 1. Does not pop off the top of the queue - leaves it there
git stash drop
removes top stash frame in queue
git stash pop
gets top stack and drops it
git stash save --save-index
keeps staged files, but stashes unstaged
git stash show
shows info on last stash
git stash show stash@{2}
info on 2
git stash clear
removes all stashes
jwiegley recommends this clever use of stash for linux systems:
$ cat <<EOF > /usr/local/bin/git-snapshot
#!/bin/sh
git stash && git stash apply
EOF
$ chmod +x $_
$ git snapshot  

Cherry Picking

git cherry-pick 52312e5
will pick that commit into our current branch
git cherry-pick --edit 52312e5
allows changing message
git cherry-pick --no-commit 5321235 55aed374
pulls in changes to staging
git cherry-pick -x 5321
adds in previous sha number in comments
git cherry-pick --signoff 5321
adds picker's id

Genealogy, Searching the Family Tree

a3d5fca12
to reference a commit you only need to type enough characters to make it unique, usually 6 or 7 characters are enough.
name^
the parent commit, if more than one parent, the first is used
name^^
the grandparent
name~8
the eighth ancestor, or name^^^^^^^^
name^2
If more than one parent this will get the second parent.
--grep=pattern
matches all commits whose message matches this pattern.
git log --grep puppies
--author=pattern
matches all commits whose author matches this pattern
git log --author=Linus
--no-merges
matches all commits which have only one parent, i.e., no merged commits

Reflog

"Reflog" is a backup system that keeps track of all our commits, even if we delete branches. The commits will stay around for about 30 days and then get really deleted.

git reflog
shows commits. Only local to user
   54eb749 HEAD@{0}: checkout: moving ...             
   54eb749 HEAD@{1}: checkout: moving ... 
   eb70244 HEAD@{2}: checkout: moving from ...
   54eb749 HEAD@{3}: pull: Fast-forward
   

let's accidentally delete a branch

git branch -d zoo //generates error, not fully merged
git branch -D zoo //overrides and deletes
git log --walk-reflogs //gives more info
git branch zoo 54eb749 //creates new branch pointing to deleted branches' last SHA
git branch zoo HEAD@{1}//same as above
git checkout zoo

Squash multiple commits into one tidy commit

You can group your commits into a meaningful one before the merge.

  git rebase -i HEAD~n //where n is a number of commits to merge (squash)

The "i" option is for interactive. Git will present you with a text file like this:

pick 8a18f54 one
pick 64156a7 two
pick f4a9307 3

# Rebase cd97cab..f4a9307 onto cd97cab (3 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit

Leave the first line as is, but in the following lines change "pick" to "squash". Then save, and exit the editor. [In vim, ESC -> :wq! (save changes)]

Git will then present a message file where you can delete all the checkin comments and replace with a new one for all commits. Save and exit. Enter "git log" to see the change.

Notes

HEAD is usually a symbolic reference to the last commit in the currently checked-out branch. HEAD points to the current branch. In the .git directory, the file "HEAD" contains a pointer to the current branch, which in turn references a commit hash id. Example:

cat .git/HEAD
ref: refs/heads/Mitch_895553_MyBranchName

 cat .git/refs/heads/Mitch_895553_MyBranchName
a3d5fc559d4ba4183964ca6d17e658812eafb141

The HEAD can be set directly to a commit. This is called a "detached head".

A directory named "index" holds all the files to be committed. This is called the "stage", where files are staged before being committed. Files do not go from the working tree to the repository, they have to be added to the staging area first with a "git add " command.

The "working tree" is where the normal files are kept on your filesystem. It has a ".git" directory which contains all the .git objects.

A "commit" is a snapshot of the working tree. It contains a tree hash, usually a parent, an author and committer info, date info, a blank line, and finally a commit message.

git cat-file commit 107b22915830203ff40d0d8dfbf8e950961bc490
tree 21e1ce7f2888871854a6a54e7f37853626331eb9
parent cedfd274bc5fc6ed23baf7eb93d81a5f0e8416e8
author Mitchell Fincher  1507926633 -0500
committer Mitchell Fincher  1507926633 -0500

adding spanish

You can try this yourself, use "git log" to get the hash.

The parent of the commit is the SHA-1 value of the reference that HEAD points to.

A "tag" points to a commit, has a description, but unlike a branch it never moves.

A "blob" is a compressed file with no meta-data. All the meta-data like name are stored in the tree. It may, and probably is, referenced by many trees.

A blob has a header record consisting of it's type, "blob", a space, the number of bytes, followed by a null byte. Git prepends this to the contents of the actual file and then calculates it's SHA-1 hash value. Git then compresses the contents using zlib and writes it to the file system using the hash value as the name.

A "hash id" is a SHA-1 hash, a 40 character hex hash. SHA-1 takes text and reduces it down to 40 characters. See "git hash-object file".

A "tree" contains references to blobs and other trees.

$ git ls-tree master
100644 blob 1f0d9c362b635efe4f321a92d6715f00530ed2b2    greetings.txt
100644 blob 586d7ab779c9fcd2d171ca012a6186144beea379    one.txt
040000 tree 584d1a5650d8b2f5d7c71f1373c884569cad0cbf    spanish
100644 blob 4adbf7c8f4d643d31800f4b3780c602ed455f993    three.txt

Each line contains a mode, hashid, and filename.

Git uses three modes for blobs, 100644 is a normal file, 100755 is an executable file, and 120000 is a symbolic link.

commits only reference parents, never children.

Almost all operations in Git add data to the db, it doesn't delete or change the database, so it's very forgiving

~/.gitconfig has my local config options like username

For passwords setup in Visual Studio, see: https://www.visualstudio.com/docs/git/set-up-credential-managers

Emacs Examples and Notes

Emacs Examples and Notes

This is the start of my Emacs notes - more to come.

Keyboard Macros

C-x C-k n
names last keyboard macro only for session
C-x C-k b
bind to key sequence
M-x insert-kbd-macro CR macroname CR
inserts named keyboard macro into current file, e.g., .emacs

Tuesday, July 18, 2017

Windows 7 is Not Recognizing a USB Keyboard


My Windows 7 box has not been recognizing my awesome USB Das Keyboard when I dock my workstation in the morning.  The solution was to update the power settings so Windows would not ignore USB devices after powering down.

Steps to Fix:
1. From the Start Button, select "Control Panel" and then "Power Options"



2. Select "Change plan settings" from your favorite power plan.

3.  Select "Change advanced power settings"

4. And finally set the "USB selective suspend setting" to "Enabled".

5.  This should force Windows to keep the USB ports active and recognize your devices.  It may take a minute when you dock your laptop for it to recognize the keyboard.  Please be patient.  This is windows.

Wednesday, July 05, 2017

iPhone "Cannot Connect to App Store"

My iPhone could not connect to the App Store this morning.  I checked Apple Supports answer, but that didn't solve it.

I got these two errors  "Cannot Connect to App Store" and "Loading":

The problem turned out to be my local Wi-Fi provider was blocking ports.   The solution is to switch off your Wi-Fi and access the App Store via cellular - assuming you have enough data in your plan.