Tuesday, 25 January 2022

GitHub

Error:Key already in use

When I try to add a ssh public key to my GitHub account, I got that error. To figure out which account has that key

ssh -T -ai ~/.ssh/id_rsa git@github.com

Output: Hi liysysy! You've successfully authenticated, but GitHub does not provide shell access.

to solve it, remove from other account and add to this account

Ask user name when push codes

If you have upload a ssh public key and it still asks for user name when push codes, it is mostly that you are using https://.. as origin. You need to use ssh origin such as git@github.com:rllslslls

To change origin

git remote set-url origin git@github.com:rdgdfghh.git

Create a PR

git push -u origin feature/KLMP-4071

Wednesday, 19 January 2022

Use Google API

To use Google API, need several steps

  1. Create a developer token
  2. Create a project
  3. Get client id and client secret for the project
  4. Get a refresh token from user by asking them to grant permission to the project (see the below)

Ask user to grant permission to get refresh token

  1. Create a return url which will process code after user grant the permission
  2. Add the above url to authorized redirect URIs field of the project
  3. Use client library to generate an onboard url and redirect user to this url
  4. After user redirect to that url, user will be asked to grant permission

With developer token, project's client id and secret, and user's refresh token, we can implement the project using Google's client library to implement the project.

Use ngrok as tunnels to localhost

set up

  1. register an account at ngrok
  2. download ngrok and unzip
  3. find authtoken
  4. ./ngrok authtoken 23siywfFYojsSVe8ojvO0yTEgf4_7dsx9NCr9cZHoc7gb3abc

./ngrok authoken .. only needs to run once. It will create a ~/.ngrok2/ngrok.yml

usage

If have used /etc/host define different domains, use -host-header flag

./ngrok http  --host-header local.mowedhdhmedia.com 80

If only have to point to localhost

./ngrok http 80

copy the url generated by ngrok. This url can be accessed from anywhere to connect to your local host.

Friday, 7 January 2022

Blockchain

Satoshi Nakamoto's Paper

How to Store Bitcoin

Good Tutorials

Good tutoria about smart contract

Block

Every block has the previous block's hash. It has it's own hash which is generated by hashing previous hash and own data.


{data: "some data", previous_block_hash: "hash value", own_hash: "own hash value"}

hashfunction( data, previous_block_hash) => this block's hash

Chain Blocks

For the first block, we give it some randon string as the previous block hash because it does not have previous block. For every other block, it has the previous block's hash. Use hash to link blocks and these blocks become a blockchain.

Verify Block Chain

traverse through the chain, for every block, verify it's hash by using the hash function. Also, except the first block, check the previous hash property does match the hash of the previous block.

keccak256 value

use ruby. Need to install a gem first

gem install keccak256
require "keccak256"
code = Digest::Keccak256.new.hexdigest 'hello1'
puts code

Private and public key

require 'openssl'

key = OpenSSL::PKey::RSA.generate(2000)
key.public_key

puts key.public_key
puts key

Smart contract hello world

Hello World Totorial

//I made an adjustment in order to compile the contract successfully
//change to this solidity version in HelloWorld.sol
pragma solidity ^0.8.0;
//because in hardhat.config.js
solidity: "0.8.4",

Voila! successfully deploy the smart contract to a test net!

npx hardhat run scripts/deploy.js --network ropsten
//voila
Contract deployed to address: 0x4827E8a9858f73d061262fB3BAaa4FA8461F7904

See Contract Details

Screenshot of the transaction

Labs

Lab One

AWS CloudWatch Logs Insights etc

AWS CloudWatch Logs Insights

Logs Insights Syntax

Sample

#need to select a log group first. Like is case sensitive. Two filter is and logic
fields @timestamp, @message
|filter @message like "pay"
|filter @message like "POST"
|sort @timestamp desc
|limit 20

To add time range, use UT and pick absolute and then write down range. Need to pick UTC

AWS S3

Can store some public files in S3 and copy back to a Docker image
  1. Upload the file into AWS S3
  2. Edit permission to make it public
  3. Copy the url for this object
  4. Use curl to copy file in Dockerfile
    RUN curl "https://my-assets.s3.us-west-2.amazonaws.com/good-assets/grpc.so" --output /usr/lib/php8/modules/grpc.so

Amazon Elastic Container Service (ECS)

ECS runs and manages docker-enabled applications in amazon EC2 instances.

Amazon EC2 container registry stores docker images.

To use ECS

  1. Create EC2 Cluster. These instances are linked in a virtual private cloud(VPC)
  2. Create task defintion to define a container. It is a configuration for running a docker image
  3. Deploy containers using task definition to run on the cluster
  4. Use Serive to manage tasks. Serice includes task defintion, desired count and task placement strategy
  5. Update Service with new task defintions to replace old tasks

Some my aws blog links

Dynamodb

Intrinsic functions

Amazon EC2

Thursday, 6 January 2022

Make Google API Call

To make a Google API call, need to set up the below

  1. need a developer token
  2. client need to create app. For example, if use Google ads api, Google ads account customer needs to create app
  3. get client id and client secret of that app
  4. that app needs to grant permission to use Google specific api. After grant, should get a refresh access token
  5. with developer token, client id, client secret and refresh access code, we can make a Google API call (see the below)

How app to grant permission to use Google api. Use Google ads api as example

Option 1: Use Google oauth play ground

  1. add https://developers.google.com/oauthplayground under Authorized redirect URIs of that App
  2. go to https://developers.google.com/oauthplayground/
  3. click setting and click use your own OAuth credentials. Provide app client id and client secret
  4. select a Google api and click grant permission
  5. Then can convert verification code to access code and refresh access code

Option 2: build a webpag (for web app) to ask user to grant permission