Pages

Wednesday, December 30, 2020

c# events

1) Create the event in Customer class. The <TYPE> can be string, decimal, bool, class, etc. 

public event EventHandler<decimal> OverdraftEvent; 


2) Place code to trigger the event.

public void MakePayment (decimal amount)

    if (amount < accountFunds)   // Not enough. Create event trigger. 

           OverdraftEvent?.Invoke(this, amount);

}


3) Create listeners for the event. Attached methods to run when event is triggered. You can place the event listeners in different classes/places as needed. 

private void WireUpForm()

{

    customer.Checking.OverdraftEvent += CheckingAccount_OverdraftEvent;

}


4) Create method that is run when event is triggered. 

private void CheckingAccount_OverdraftEvent(object sender, decimal e)

{

    // do something to handle event ... for example:

    errorMessage.Text = $"Not enough funds available for your {string.Format("{0:C2}", e)} transaction";

}


5) Remove listeners when app is closing. Else, the app may not fully close and get stuck in memory with no garbage collect. This leads to memory leaks !

customer.Checking.OverdraftEvent -= CheckingAccount_OverdraftEvent;

Friday, August 14, 2020

Rebase steps

 Terminal > 

git rebase -i HEAD~3

> GIT window comes up to make changes

[[[ > If I want to cancel, without changes, use # to comment out all lines and "wq!". No changes will be made.

> OR another way is to use "q!" to quit. Then use "git rebase --abort". ]]]

replace "pick" with s or f

ESC > : > wq! > press ENTER

git push -f origin feature/test-9999_sampleBranch    (force push will completely overwrite the origin branch)

Thursday, September 5, 2019

Resolve merge conflicts

SourceTree > rebase branch on top of Develop > Merge Conflicts !


Go to Visual Studio > Team Explorer > Changes > Conflicts

Click each conflict and click MERGE button.
Resolve (left side) by adding both changes.
Click "Accept Merge" top left.


Conflicts are resolved.


Go to SourceTree. Will not be on a branch. Stage all changes.
> Terminal > git rebase --continue






This will finish rebase and go to correct branch. If all looks good, then do a final push:
> Terminal > git push -f origin feature/3100_NewFeatureBranch

Saturday, January 12, 2019

React JS notes

- ES7 to generate quick template

In VS Code, go to 1) Extensions tab  2) Install ES7



This makes creating new JS files easy.

Create new file:  TestFile.js
Type "rce" and press Tab (rcf for function template)
It auto creates this template code:




- UUID (unique id generator)

> CNTL - C to stop dev server
> npm i uuid  (to install package)
> npm start (restart dev server)

import uuid from 'uuid';

id: uuid.v4();   < this will generate the ID


- React Router

> npm i react-router-dom


- HTTP API library (Axios) - can use instead of jQuery or fetch

> npm i axios





Saturday, December 22, 2018

SOLID - Liskov Substitution Principle

If S is a subtype of T, then objects of type T can be substituted by objects of type S without breaking the program.

public class Employee {
    public string Firstname {get; set;}
    public string Lastname { get; set;}

    public virtual void AssignManager (Employee Manager)
    {
          // set manager for employee
    }
}


Employee emp = new Employee();
emp.AssignManager();


Above, Employee type is T.


public class Staff : Employee {
    public string Dept {get; set;}
    public string Manager {get; set;}
}

Above, Staff (S) is a subtype of T (Employee). Liskov says that since S is a subtype of T, then this should work:


Employee emp = new Staff();
emp.AssignManager();


Let's create another subtype of Employee (T).

public class CEO : Employee{
       public string Rating {get; set;}
       public override void AssignManager(Employee manager)
       {
               throw new Exception("CEO does not have a manager");
       }
}


Above, CEO is subtype of Employee. However, this does not work and thus, it violates the Liskov Principle:

Employee emp = new CEO();
emp.AssignManager();

This code throws an exception because 1) CEO does not have a manager  2) code is set to throw error for invalid method.

Liskov Sub Principle states that Staff() should be a TRUE Employee().
CEO should be a TRUE Employee(), but it is not. So LSP is violated.

How to fix so that even CEO (subtype object of T) can be substituted for the objects of T? So that above code works?

Wednesday, December 19, 2018

Agile Methodology

2 week sprints.

Weekly PAR review. Small group reviews new defects.

BACKLOG GROOMING (every 2 weeks):
- Stories: discuss story and using pointingPoker.com to point. Goal is to create a score to help estimate relative complexity. Stories are items that add value for customer (e.g., product feature, performance improvements, etc.)
- Tasks do not get pointed. Tasks are items good things to do, but does not correlate directly to a benefit for a customer.
- Review defects (high level)
- Move priority items to top of backlog

SPRINT PLANNING (every 2 weeks):
- Occurs at the start of a sprint. 4 hrs allocated and then we officially start the sprint.
- Assess total team hours available
- Add items to sprint and check team hours remaining
- For stories, create sub-tasks
- For defects, set hours

START SPRINT
- Tickets are prioritized
- Tickets are not assigned so anyone can take
- If a bug is found during a story, create a BUG subtask and take hours from the story's time bank.

SPRINT RETROSPECTIVE (when sprint ends):
- Discuss good and bad points
- Action items (past and future)

Monday, December 17, 2018

GIT Cheat sheet

REBASE:

git rebase -i HEAD~3     > pulls up the latest 3 commits

[INSERT] Edit the interactive screen
[ESC]
[Shift :]
wq!         > saves and exits

git log    view new rebased log

git push -f origin bug/sample-1000   > pushes latest changes to origin



RESET:

git reset --hard HEAD~1    > undo prior commit and delete it
git reset --soft HEAD~1     > undo prior commit and keep changes