youtube-dl Troubleshooting: ERROR: This video is unavailable

When you want to download some video from youtube with favorite tool youtube-dl, but this error shows up. That means the youtube-dl version that you’re using needs to be updated.

This is how to install the latest version of youtube-dl :

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl 

Or if you installed with pip, you just upgrade it

sudo pip install --upgrade youtube_dl
youtube-dl --version

How to Push Docker Image to Google Cloud Repository (GCR) (Easy steps!)

 

 

 

Here’s how to push your local docker image to your GCR (Google Cloud Repository). You might want to use your own docker image later for your containerized app or kubernetes.

For this research, I use Ubuntu 18.04.03 LTS

Install gcloud, see the full instructions here : https://cloud.google.com/sdk/docs/quickstarts

Once you’ve installed the gcloud, let’s continue to the next step:

$ gcloud init
Welcome! This command will take you through the configuration of gcloud.

Your current configuration has been set to: [default]

You can skip diagnostics next time by using the following flag:
  gcloud init --skip-diagnostics

Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.                                                                                                                                                                                               
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).

You must log in to continue. Would you like to log in (Y/n)?  y

Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?code_challenge=00SNwoATS92Is6deNqmONmgLM_RPM8x7n_IT_9ZU55s&prompt=select_account&code_challenge_method=S256&access_type=offline&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=xxxxxxxxxxxxxxxxxxxxxxx


Enter verification code: 

For the first time initiation, gcloud will ask you to log in. Therefore it will provide the link that you can click on your browser. Follow the instruction from google browser, then you will get the verification code. You also will be asked to pick the cloud project that you want to use:

Enter verification code: 4/sgEzW-mHbbknYMPEIM7vPPjENJuIxRnT1ov9xxxxxxxxxx
You are logged in as: [xxxxxx@gmail.com].

Pick cloud project to use: 
 [1] my-project-id
 [2] Create a new project
Please enter numeric choice or text value (must exactly match list 
item):  1

Next, select the the region and zone:

Your current project has been set to: [my-project-id].

Do you want to configure a default Compute Region and Zone? (Y/n)?  Y

Which Google Compute Engine zone would you like to use as project 
default?
If you do not specify a zone via a command line flag while working 
with Compute Engine resources, the default is assumed.
 [1] us-east1-b
 [2] us-east1-c
 [3] us-east1-d
 [4] us-east4-c
 [5] us-east4-b
 [6] us-east4-a
 [7] us-central1-c
 [8] us-central1-a
 [9] us-central1-f
 [10] us-central1-b
 [11] us-west1-b
 [12] us-west1-c
 [13] us-west1-a
 [14] europe-west4-a
 [15] europe-west4-b
 [16] europe-west4-c
 [17] europe-west1-b
 [18] europe-west1-d
 [19] europe-west1-c
 [20] europe-west3-c
 [21] europe-west3-a
 [22] europe-west3-b
 [23] europe-west2-c
 [24] europe-west2-b
 [25] europe-west2-a
 [26] asia-east1-b
 [27] asia-east1-a
 [28] asia-east1-c
 [29] asia-southeast1-b
 [30] asia-southeast1-a
 [31] asia-southeast1-c
 [32] asia-northeast1-b
 [33] asia-northeast1-c
 [34] asia-northeast1-a
 [35] asia-south1-c
 [36] asia-south1-b
 [37] asia-south1-a
 [38] australia-southeast1-b
 [39] australia-southeast1-c
 [40] australia-southeast1-a
 [41] southamerica-east1-b
 [42] southamerica-east1-c
 [43] southamerica-east1-a
 [44] asia-east2-a
 [45] asia-east2-b
 [46] asia-east2-c
 [47] asia-northeast2-a
 [48] asia-northeast2-b
 [49] asia-northeast2-c
 [50] europe-north1-a
Did not print [12] options.
Too many options [62]. Enter "list" at prompt to print choices fully.
Please enter numeric choice or text value (must exactly match list 
item):  30

Next, we need to configure the docker config. Run the command below to add some config file. Input Y if prompted.

$ gcloud auth configure-docker
The following settings will be added to your Docker config file 
located at [/home/ubuntu/.docker/config.json]:
 {
  "credHelpers": {
    "gcr.io": "gcloud", 
    "us.gcr.io": "gcloud", 
    "eu.gcr.io": "gcloud", 
    "asia.gcr.io": "gcloud", 
    "staging-k8s.gcr.io": "gcloud", 
    "marketplace.gcr.io": "gcloud"
  }
}

Do you want to continue (Y/n)?  Y

Docker configuration file updated.

Now, let’s build your docker image, tag, and push it to your GCR registry

$ sudo docker build -t simple-image:v1 .
$ sudo docker tag simple-image:v1 asia.gcr.io/my-project-id/simple-image:v1
$ sudo docker push asia.gcr.io/my-project-id/simple-image:v1

That’s it!

Run bash terminal inside VIM with Conque-Shell

This is one of the coolest trick I’ve ever seen when working with VIM. This plugin allows you to run the bash terminal inside the VIM. And you can actually make it a spitted pane within your VIM work space.

Check out this plugin:

How to install conque-shell:

Open vim config:

vim ~/.vimrc
call plug#begin('~/.vim/plugged')
Plug 'lrvick/Conque-Shell'
call plug#end()

Close the ~/.vimrc file, and open vim again, and Install the plugin with this syntax:

:PlugInstall

Let’s understand Git Submodule

What is git submodule?

It is another git project inside your git repository. If you working on multiple git projects but need them in one repository instead. You will be happy to setup git submodule.

So here I have two git repositories for example:

https://github.com/muffat/repo-a
https://github.com/muffat/repo-b

And since I’m updating the repo-b frequently, I want my repo-b to be inside the repo-a so it helps me to work with multiple repos as possible and easy to maintain codes across the repo and be able to work more faster and efficiently.

Setup git submodule

Add git submodule in your current repo

$ git clone git@github.com:muffat/repo-a.git
$ cd repo-a/
/repo-a$
/repo-a$ git submodule add git@github.com:muffat/repo-b.git

Commit and push your submodule

/repo-a$ git add .
/repo-a$ git commit -m "Add submodule repo-b"
/repo-a$ git push origin master

Note that, git submodule doesn’t automatically get pulled after you clone your repository (repo-a). You need to do manual initialize and pull your submodule. So after you clone your repository, you will find out that your submodule directory (repo-b) is empty.

$ git clone git@github.com:muffat/repo-a.git
$ cd repo-a/
/repo-a$ cd repo-b/
/repo-a/repo-b/$ ls
/repo-a/repo-b/$

go to submodule directory, and do this:

/repo-a$ cd repo-b/
/repo-a/repo-b/$ git submodule init
/repo-a/repo-b/$ git submodule update

How to git clone including submodules

$ git clone --recursive git@github.com:muffat/repo-a.git

Some problem occurred whenever I tried to clone with recursive. It failed to fetch the submodule repository because of the permission. Although my submodule is a public repository, yet still failed.

Then I changed the url of submodule from git to be https.

$ cat .gitmodules
[submodule "repo-b"]
path = repo-b
url = https://github.com/muffat/repo-b.git
branch = master

After that, the git recursive cloning was working.

Nginx: set the server_name as wildcard without hostname

Simple trick to run the nginx with no server_name.

server {
  listen 80 default_server;
  server_name _;
  location / {
    root /path/to/app;
    index index.php;
    try_files $uri $uri/ /index.php?q=$uri&$args;
    location ~* \.php {
      try_files $uri =404;
      include fastcgi_params;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_pass 127.0.0.1:9000;
    }
  }
}