Git how to add a comment and quit VIM

This happens to me from time to time. When you are trying to merge with some local branch and there are some conflicts you want to fix on the fly then this terminal asks you to add a comment so you do and you don’t know how to exit….

Terrifying stuff I know so here is how you close that VIM terminal. After adding your comment and looking lost enter this below:

:wp

For definitions and more detail check out this source

How to delete a branch locally

This is just a personal post on something ,I keep forgetting how to do.
So i am putting it where I know where to find it.

git branch -d <branch name>

For more information you can checkout the source

Optimising images

My previous post I got carried away and I wrote a novel about keypresses.

Anyway, I’ll continue to keep these posts short and helpful. I do apologise if i get carried away about a point.

Ok so you want to optimise your images and quick. Go to this site and download the PNGGuantlet for your OS of choice.

Chuck your images in and watch them go down to size whilst keeping most of its quality.

wait for the green bars to finish then check the kb sizes of your images again.

The way how i came across this app was by a client. A very senior full stack developer I had to do a piece of work for him finding some assets and look it took me a while and i got lazy and just grabbed the first few.

The images I found were different sizes (i.e. 525px X 525, 1025 X 1025 and so on). I was requested to optimise the images and reduce their size. I know how to reduce their size but not optimise them.. So my code did not pass his review and he shared with me this link and told me the steps to use it and why its good. So ya have fun optimising images with PNGGauntlet

<Update>
There are loads of image optimising applications. I made it sound like this was the only one it seems, so ya there are plenty I was just recommended this one.

JavaScript Keypresses keyup keydown keypress

As Always I try to make my blog cater for peeps that are just looking for concise answers, so if you scroll down there is a TL DR section below. If you are curious of my thoughts then keep reading.

My knowledge of keypresses consisted of the brief summary of “you press a key and you can make something happen”. Turns out there is a bit more to it.

Keypresses have three different trigger points. I’m going to put my naive understanding of them first, then what MDN says cause that is the best source of truth out there in my opinion. I also used StackOverflow.

First you have keydown

My understanding of a Keydown is the action of when the button is pressed, so as the key is pressed down you can set an action or trigger something from that point.

Unlike the keypress event, the keydown event is fired for all keys, regardless of whether they produce a character value.

from MDN

To sum keydown: Keydown will trigger for all keys pressed(odd ones being ctrl, shift. delete..etc). If you press any key thats a keydown.

Second you have keyup

My understanding of a key up is the “release” action of the keydown action. So you can set an action upon lifting your key from a pressed state.

The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase “a” will be reported as 65 by keydown and keyup, but as 97 by keypress. An uppercase “A” is reported as 65 by all events.

from MDN

To sum up keyup:. It trigger upon the release of a pressed key. Don’t worry MDN can be intimidating at times. It took me a while, but they are saying a keyup will trigger with a value of what key was pressed. Also, I think MDN has already moved on tooo..

Thirdly the keypress

My understanding: Keypress is the full action of just typing a key. so hit a key and let go and you have yourself a keypress buddy.

The keypress event is fired when a key that produces a character value is pressed down. Examples of keys that produce a character value are alphabetic, numeric, and punctuation keys. Examples of keys that don’t produce a character value are modifier keys such as Alt
, Shift
, Ctrl
, or Meta

From MDN

Ok, so my understanding of a keypress was a bit off. It appears to be including all chars that set a value and not other keys like shift, control, alt…etc that don’t produce a character. According to MDN it appears that the keypress is deprecated so you would just need to be aware of that when using keypress.

I never in my life thought that someone could complicate a key press, but here we are 2020 virus is out. Try to stay inside guys ok.

TL DR

The onKeyDown event is triggered when the user presses a key.
The onKeyUp event is triggered when the user releases a key.
The onKeyPress event is triggered when the user presses & releases a key (onKeyDown followed by onKeyUp).

from stackoverflow

In my defence I’m not as technical as MDN, my theory was around more towards what the stackoverflow post said.

I’ll leave you with that guys I really hope that this helps you out and helps you know that there is a bit more to a keypress than meets the eye.

On a side note. I got some positive comments on my previous post. Thanks so much for the support I’ll continue posting my findings and sharing the knowledge to help myself and others. I was so chuffed in fact i made a live sample of some javaScript and keypresses right here enjoy.

[Sample] Angular hitting API with Service

If you want the sample main steps scroll to the “TO THE POINT” part of this article thanks. If you all good keep reading.

So this lock out isolation thing has been quite challenging for everyone and I feel your pain. I was working on an angular portfolio…but its been mainly css when trying to cater for mobile view and tablet view…so I want to take a break from the css and get into interacting with an API

If you don’t know what an API is…this wont cover the fundamentals sadly, it’ll be a working example of an api request. As for now we are Focusing on Angular working with APIs using services.

There are many free open API sites the one i came across apifootball.com where upon registering they’ll provide you with an API key (you’ll need to keep this safe and secure) From my experience most of the free apis require a registration.

We have an api and an api key, now you want to check and see if we can make a call of some sort and log a response. A great API tool is postman. Basically setup the API call to your liking and it allows you to see and track the response and what not, look its great.

ok so that is the long of it. Now i’m going to try to keep it as short as possible. Yes that does say “overal_league_payed” learned that the hard way.

TO THE POINT HOW TO SETUP TO HIT AN API

Using the angular cli we can just enter the following command in the terminal

// short hand
ng g s serviceName
// full on
ng generate service serviceName

The command will generate a service for you in your solution. Basic boiler plate.

Right now you know your API is working. Let’s make that service in our angular app give that API a call and see if we can get their response.

We need RXJS thats right that beast that does magic with Observables (high level comparison of observables vs promises.).

npm i rxjs

Make sure that you are using HttpClient for the http calls.
I normally use the below structure for api calls. Adding variable for base urls and other things that are constant like my apiKey this is just personal preference.

I was advised that when it comes to services, make sure they only deliver the data keep that part clean. Now moving along to the app.component we’ll need to create a function that hits that service and the getLeagueStand and subscribe to the response and then extract the data you want. Make sure you return the url.

And ALSO do not forget to import your service and the httpClient module to your app.module file like so…I can’t believe I forgot to add this guy.



As you can see in the code above we subscribing to the data and then setting out its values to variables. Here is a repo to a working sample. You’ll need to add your own apikey though.

How OAuth 2.0 and OpenID connect work

I was shared this video for a tech discussions and I have learned so much from this man. I wanted to add some personal notes below but its actually a fair amount to digest. Enjoy the video and get ready for the flow of knowledge coming your way.

Inherit a Codebase or Rewrite one?

For all you guys that just want the pros and cons, check at the bottom of the post for the main out comes of my experience and findings. Continue reading if you want to read more details on said findings.

I never thought so early in my career there would be a time that I would need to inherit a codebase.

There was a bit of talk with the team and with the client about a lift and shift an existing code base and what not. I didn’t really have a problem with it cause everything was still pretty new to me.

So new codebase, go through the norm git clone <https://github.com/tony2tones/angular/someotherbsprojectthatcouldbegreatorlame.git and you npm install and so on. I navigate around and then start looking at the code base…you got to make sure that the project works before looking right?

So i navigate around and its just things i’ve never seen before, I’m checking this shit out and there is like Models within Models Referencing other models and other things i’ve seen before.

I tried to remain calm even though knowing full well that i’d need to upkeep this possibly add features to this code base so I was nervous.

I heard from the other devs that the codebase was actually pretty good, to a high ‘clean code’ standard I believe. That was quite a big deal. So the codebase was ours to hold and to manage.

These are the first few things i realised:

  • Code was not unit tested(which basically become our duty to fix)
  • Code was to a high standard but reading the code was difficult…there was a lot going on
  • Not unit tested therefor code was not developed to be unit tested
  • Lots of refactoring breaking down code and making sure it would be unit testable
So the lift and shift was a success(in the pipeline and all) but the unit tests  were incredibly difficult...it came down to whenever i got assigned a unit test on that codebase, I needed help. Everyone struggled...I was a little annoyed thinking i'm really new at this job and they are giving me things that senior devs are struggling on....don't get me wrong they did them and they're were very complex but you know a lot of effort is all i'm saying. So reading the code and understanding it for me...took quite some time weeks infact..so ya lot of time understanding things and always struggling at unit tests..I learned a bit but ya i'm far from perfect.

Thanks for reading the above journey of my experience. So my understanding and outcomes come to these things:

TLDR

Here are my main experience and findings.

Yes, there is a typo ‘may be more ‘

The above is just my findings of inHeriting vs rewriting a codebase. Open to discussion i’ll be happy to update. This is like XP Xperience Post

Ngx-datatables conditional rendering of columns

Hi, I trust that you have enjoyed the read on how to get setup with your ngx-datatables, if not checkout my previous post right here.

You have your ngx-datatable all set and you want to show a cool icon if there is a boolean value. Luckily we have such data in one of our columns.

note that the working data is a boolean

So when looking at the current solution and the HTML (or view as the pros like to call it) you would think that to add conditional rendering logic to a single column, one would need to add the following.

Well I was wrong. The code is correct but, this will not render the entire table as you can see below.

The point that I wanted to make is that you will need to add details now for every column, so if there are a 100 columns you would need to add 100 of them. I also did some conditional rendering with text. HOWEVER, please use boolean values, just wanted to show you that it is possible, but not recommended. Any text change or updates….cases will not make the conditions work.

the final code

You will need to add column details for every column if you want to use conditional rendering. The end result should look a little something like this.

very sexy I know.

So thats how one would do conditional rendering, using *ngIf logic using the row value boolean variable to dictate what to render.

I have added this to my github account under the ngx-datatable-conditional-rendering branch.

git clone https://github.com/tony2tones/ngx-table.git

How to setup ngx-datatables

Before I start, yes the image above has a table in it. I was hoping to fit everything into one blog post, but I think it may be best to breaking down into sections, so if its your first time using ngx tables this will hopefully help me and you on how to set it up more or less.

I was trying to find some sources on ngx-datatables and i only found a video podcast about people talking about how great it is from the creator with no real implementing advice. So I want to try to share my learnings from it

This video didn’t really explain how to use ngx-datatables.

I’ve got a repo on this so you can see how it works with working code, I won’t go through the setup of data (although I have added some comments…fun).

git clone https://github.com/tony2tones/ngx-table.git

Firstly setup your project and install the ngx-datatable goodies like so.

npm i @swimlane/ngx-datatable --save

One thing I’ve learned is don’t be so afraid of official documentation their docs which can be found here are actually pretty good so don’t be shy to give it a shot and their demos are great.

Side note for the peeps that want to use bootstrap styling on their ngx-dataatable be sure to check my post on adding bootstrap to a project quick and then add this guy to your projects root styles sheet.

// styles.css
@import "../node_modules/@swimlane/ngx-datatable/release/themes/bootstrap.css";

Ok , so your table comes with its basic stuff, a mock services with a data model to utilising the power of intellisense. If you open the master you’ll see in the app.component.html the following structure for the ngx-datatable.

the square bracket stuff.

ngx-datatables are pretty fancy and quite easy to custom. from adding a total count to adjusting column length and pagination. Feel free to edit these properties and find out what they are all about. For example the [columnMode]=”‘force'” just tries to let your column stretch across the dimensions so it doesn’t look weird…cause it looks weird without it.

without…gross i know

You will also encounter a columns array with prop and column name objects.

 public columns = [
    { prop: "firstName", name: "Name" },
    { prop: "lastName", name: "Surname" },
    { prop: "gender", name: "Gender" },
    { prop: "working", name: "Employed" }
  ];

The above code basically states the column names and props. I use the props for mapping the naming convention that i receive from the api (which i have mocked in my sample repo) so when the data comes in it knows where to go and with the name it is just the naming of the columns.

I’ve added an empty array called rows and as you can see in my ngOninIt() function i’m setting the data to the said rows array. then WHAM you have yourself a table showing lovely data. Next up will be conditional rendering… very excited to share it….and you can reduce the load time delay if you like. The loader credit goes to here.

Ng Serve: solution keeps on re-compiling

Quick post here, i’ve come across this a couple of times when starting a new project normally. Where no changes have been made or saved, but the console keeps on compiling every now and again..it kinda looks something like this.

i’m sure we have all seen this before.

What worked for me was just doing the following:

ng update @angular/cli @angular/core

This has helped me out, if you don’t come alright just keep looking.