Showing posts with label Github. Show all posts
Showing posts with label Github. Show all posts

What is GitHub Copilot and how it works?

What is GitHub Copilot?

GitHub Copilot might be one of the most intersting AI use case from Microsoft GitHub in 2021. In this post, we look into an overview of what is GitHub Copilot and how it works with some examples.


GitHub Copilot is an artificial intelligence tool developed by GitHub and OpenAI to assist users of Visual Studio Code, Neovim, and JetBrains by autocompleting code. It was first announced by GitHub on 29 June 2021.


If you visit the GitHub Copilot official website, you will see the brief summary of Copilot as "Your AI pair programmer", and with GitHub Copilot, get suggestions for whole lines or entire functions right inside your editor.



How it works?

So based on the above description, we get an idea about what is Copilot - your pair programmer which can provide quick suggestions for completing your code (e.g., entire functions) in your editor so that you can complete your code without actually typing the content of a function for example.


To test with some examples, I applied GitHub Copilot Technical Preview and got approved, and used the following environments for the testing:


First example: Binary Search

The following video shows how we can complete binary_search function with the help of Copilot where its suggested code will be shown in gray color, and if you like the suggestion, you can use [Tab] key to accept the suggested code for your usage instead of coding from scratch - which is super awesome!


First, when I try def binary_search(, the Copilot will suggest two input parameters (i.e., arr and target) for my function based on the function name that I typed.

Secondly, when I move to the body of the function to write, as we can see from the video, Copilot will automatically suggest the entire binary search example code for us to use if we satisfied with the suggested code - which is working without any problem like a charm!








Second example: Bubble, Selection and Insertion Sort

Next, we try three basic sorting algorithm implementations with the help of Copilot in the following video. Based on the function name itself, the Copilot can automatically suggest relevant code snippet for the function when I change the function name from "bubble_sort" to "selection_sort" or "insertion_sort" - which again runs smoothly without any problem.



The first impression of the Copilot is absolutely will be very helpful for speeding up a lot of well-established functions, and the impact of it will be more clear in the next few years. It is also worth noting that the suggested code with AI technique is not perfect, and it is the programmer's responsibility to check, use, or refine it for their needs.

How does GitHub Copilot work? 


OpenAI Codex was trained on publicly available source code and natural language, so it understands both programming and human languages. The GitHub Copilot editor extension sends your comments and code to the GitHub Copilot service, which then uses OpenAI Codex to synthesize and suggest individual lines and whole functions.


Does GitHub Copilot write perfect code? 


No. GitHub Copilot tries to understand your intent and to generate the best code it can, but the code it suggests may not always work, or even make sense. While we are working hard to make GitHub Copilot better, code suggested by GitHub Copilot should be carefully tested, reviewed, and vetted, like any other code. As the developer, you are always in charge.


remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.



From August 13, 2021, GitHub is no longer accepting account passwords when authenticating Git operations, and will show the message below when you are trying to use methods before.

-----------------------------------------------------------------

Git Message 

remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.

-----------------------------------------------------------------

Instead, you need to add PAT (Personal Access Token). 


First, you need to generate a PAT on GitHub following the steps below:

  • Settings => Developer Settings => Personal access tokens => Generate a personal access token => Fill the form => click Generate token => copy the generated token, which is something like "ghp_***"
Second, clone or set remote url with PAT
  • git clone https://<username>:<githubtoken>@github.com/<username>/<repositoryname>.git
  • git remote set-url origin https://<username>:<githubtoken>@github.com/<username>/<repositoryname>.git

자주 쓰는 git command 모음



// 현재 git 상황
git status

// 새로운 repo시작
git init [repository name]

// (github) 등에 있는 repo 복사
git clone [url]

// branch바꾸기
git checkout [branch name]
git checkout -b [branch name] // 새 branch생성후 사용

// branch통합
git merge [branch name]

// 파일(들)을 staging 영역에 추가
git add [file]
git add *

// 파일 삭제 및 삭제를 stage영역에 추가
git rm [file]

// stage안된 파일 다른점 비교
git diff
git diff –staged // stage영역 파일과 최신 버전 비교

// 파일을 stage영역에서 제거
git reset [file]

// 파일을 repo로 commit
git commit -m “[ Type in the commit message]”

// 로컬 파일변경된 myfile.ext를 무시하고 hard reset, @ 는 HEAD 대표함
git checkout @ -- myfile.ext
git pull

// 전체 repo를 hard reset할 경우 (모든 파일의 로컬 변경을 무시)
git checkout HEAD
git pull

// remote repo에 변경사항을 보냄
git push [variable name] master

A sample mobile application built with AngularJS and linked to SAP HANA Trial backend


For HCP trial, every developer will have two schemas (DEV_XXX and NEO_XXX) by default. So, NEO_XXX should be your development schema, meanwhile DEV_XXX is the private schema of your developer user. And usually we need to create objects in NEO_XXX schema instead of DEV_XXX [1].


Figure 1


Make sure you've done some basic steps before it. 

I created in the "hanatrial" package for the example and with the same folder structure of the example on Github.
Figure 2

.xsaccess file contains some access control information and .xsapp indicates the application we are building is a xs application of HANA. (File details can be found on Github)


1. Create Models:


  •  Create two tables (people.hdbtable and taxes.hdbtable) and one sequence (peopleseq.hdbsequence). 
    • Use your NEO_*** SCHEMA for table.schemaName. In my case, it will be "NEO_91NN2NENJITDMWTLGL5DD5INO" as displayed in Fig. 3.

1:  table.schemaName = "YOUR SCHEMA STARTS WITH NEO_*** HERE";  
2:  table.tableType = COLUMNSTORE;  
3:  table.columns = [  
4:       {name = "PPSno"; sqlType = VARCHAR; nullable = false; length = 200;},  
5:       {name = "firstName"; sqlType = NVARCHAR; nullable = false;length = 200;},  
6:       {name = "lastName"; sqlType = NVARCHAR; nullable = false; length = 200;},  
7:       {name = "title"; sqlType = NVARCHAR;length = 200;},  
8:       {name = "cellPhone"; sqlType = NVARCHAR;length = 200;},  
9:       {name = "officePhone"; sqlType = NVARCHAR;length = 200;},  
10:       {name = "email"; sqlType = NVARCHAR;length = 200;},  
11:       {name = "city"; sqlType = NVARCHAR;length = 200;},  
12:       {name = "pic"; sqlType = NVARCHAR;length = 200;}];  
13:  table.primaryKey.pkcolumns = ["PPSno"];  

Figure 3
Figure 4


  • Create "init_data" folder and copy files from Gitbub to your folder.
  • Call the procedure to insert data into people and taxes tablestablespoon.
  • Copy all files to the rest folder (Fig. 6), [Run on Server] to check if the data can be accessed (Fig. 7) by your account.


Figure 7
Figure 6
  • Finally, copy all files to your client folder (and change the relative path in these files).

  • Run index.html or iphone.html. You could see the app is running as displayed in Fig 9, 10.

Figure 9

Figure 10

If the page shows insufficient privilege, give the privilege to p**** user account of yours and then try again.

1:  GRANT EXECUTE,select ON schema "NEO_***" TO p***