Saturday, October 15, 2016

Hosting a Static Website on Google Cloud Storage

I have already hosted a static website by Google Cloud Storage which is provided by Google Cloud Platform. We can manage the Google Cloud Storage using gsutil command which is related in Google Cloud SDK.



If you haven't logged-in to auth, type the following lines;
$ gcloud init
$ gcloud auth login
Set a project by project id if you have already authenticated to Google Cloud Platform.
# Confirm your configuration of gcloud.
$ gcloud config list
Your active configuration is: [default]

account = [your-account]
disable_usage_reporting = True
project = [your-project-id]

$ gcloud config set project [another-project-id]

gsutil command


See Google Cloud SDK Documentation

Transfer files using gsutil rsync

Synchronous remote directory with local one with using gsutil rsync. See the following command;
$ gsutil -m rsync -d -r [local-dir] gs://[bucket-name]/[dir-if-needed]
The option of -m will execute multi process. The options of -d and -r are the same of the original rsync command. Please see gsutil help rsync if you wanna to know the details.

Publish files by gsutil acl

We need to operate ACL for transferred files because files are private mode generally. To be accessible them from external tools like browser so add public-read attribute by gsutil acl.
$ gsutil -m acl -ar set public-read gs://[bucket-name]/[dir-if-exists]

Access to bucket

It's accessible to uploaded bucket from[your-bucket-name]. You can change the url to your definition domain. Please see this page.

Set metadata

The Uploaded files' content-type is automatically defined by its extension. If a file doesn't have an extension, to detect file as "text/html".
$ gsutil setmeta -h "Content-Type:text/html" \
  -h "Cache-Control:public, max-age=3600" \
  -h "Content-Disposition" "gs://bucket/*"
Please see the details; setmeta - Set metadata on already uploaded objects.

Tuesday, October 11, 2016

Getting HTTP status code by cURL

I often use cURL command at the command line on Linux and OS X to fetch information by HTTP requests. Sometimes I just want to know only the HTTP status code. The option -v, which means verbose printing, prints too much information though I don't need.

-w "%{http_code}"

A more specific way to print out just the HTTP status code is something along the lines of:
$ curl -sI -o /dev/null -w "%{http_code}"
The option -w means to print assigned format below:
-w, --write-out 
        Make curl display information on stdout after a completed transfer. The format is a string that may
        contain plain text mixed with any number of variables. The format can be  specified  as  a  literal
        "string",  or  you  can  have curl read the format from a file with "@filename" and to tell curl to
        read the format from stdin you write "@-".

        The variables present in the output format will be substituted by  the  value  or  text  that  curl
        thinks  fit,  as  described  below. All variables are specified as %{variable_name} and to output a
        normal % you just write them as %%. You can output a newline by using \n, a carriage return with \r
        and a tab space with \t.

        NOTE: The %-symbol is a special symbol in the win32-environment, where all occurrences of % must be
        doubled when using this option.
Too simple and many format types are available. show man page to just type man curl. The option -I might be added to improve response load performance. This parameter just request for status headers of response, without download response body.

Thursday, August 11, 2016

Can't access MySQL 5.7 as root - Error 1698 (28000)

MySQL 5.7+ isn't allowed to login as root user without sudo because that secure model has been changed. The results of login appears ERROR 1698 (28000) as following output;

$ mysql -uroot -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Skip grant tables to login

Stop the MySQL service for starting mysqld_safe.

$ sudo service mysql stop

Start the MySQL as safe mode with --skip-grant-tables to login without verification.

$ sudo mysqld_safe --skip-grant-tables

Connect to the MySQL as root.

$ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 94
Server version: 5.7.14 MySQL Community Server (GPL)

Update mysql.user

It should be that the Plugin of root user sets auth_socket. The Plugin value will be modified to mysql_native_password for compatible former MySQL.

mysql> SELECT User, Host, Plugin FROM mysql.user;
| User      | Host      | Plugin                |
| root      | localhost | auth_socket           |
| mysql.sys | localhost | mysql_native_password |
2 rows in set (0.00 sec)
mysql> UPDATE mysql.user SET authentication_string = PASSWORD ('[root-password]'), Plugin = 'mysql_native_password' WHERE User = 'root';
Query OK, 1 row affected, 1 warning (0.01 sec)

Query OK, 0 rows affected (0.01 sec)

Restart the MySQL

Restart the MySQL service and then enter via mysql-client after typed FLUSH PRIVILEGES. It should be solved.

$ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 94
Server version: 5.7.14 MySQL Community Server (GPL)

That's it!

Tuesday, July 19, 2016

SSH: Remove identified keys by hostname

Failed to connect to the host via ssh.

Have you ever seen such a error which is "Failed to connect to the host via ssh." on your terminal when connecting a host via ssh. It should be happened if known_hosts file is taken a wrong identified keys belonging to the host.

$ ssh
Failed to connect to the host via ssh.

-R hostname

To clear the problem you may take away the identified keys with ssh-keygen command.

$ man ssh-keygen

-R hostname
        Removes all keys belonging to hostname from a known_hosts file.  This option is useful to
        delete hashed hosts (see the -H option above).

Use f option to specify a known_hosts files.

$ ssh-keygen -f ~/.ssh/known_hosts -R
# No more
# rm -f ~/.ssh/known_hosts

That's it! :)

Sunday, July 17, 2016

GopherCon 2016 - A recap

I had the opportunity to attend GopherCon 2016 in Denver. It's been an amazing week at the Colorado Convention Center.


I attended to very interesting talks during the two days of the actual GopherCon. Here is a recap of several impressed talks:


Understanding nil - Francesc Campoy

The opening keynote was by Francesc Campoy who doesn't need any introduction because he is the one of the Google Cloud Platform Podcast Hosts. He started his talks about understanding nil in Golang. Please check it out to understand what nil is.

Go for Data Science - Daniel Whitenack

Data Scientist codes Python to analyze some data and modeling. Go for Data Science tells that it's possible to code Golang for analyzing.

Don't Just Check Errors, Handle Them Gracefully - Dave Cheney

See this article

The Go Gopher: A Character Study - Renée French

Renée French is creator and designer of the Gopher. She talked with the Gopher character. Especially how does he hold that champagne glass (that image is familiar by the GopherGala.

Gopher model

Practical Advice for Go Library Authors - Jack Lindamood

Practical Advice for Go Library Authors

Panel Discussion - Dave Cheney (Moderator)

IMG 2965

Hack a Day!

On the last day of the GopherCon, there was an optional hack day with hackathons and workshops carried out.

We absolutely can't wait for GopherCon 2017 in Denver!!

Saturday, July 16, 2016

Debian 8 - Install latest version of MySQL server

Debian distribution provides MySQL 5.5, not 5.6 or later.

Here’s how to install latest MySQL server:

Install the MySQL APT repository config tool

MySQL :: Download MySQL APT Repository
# Download the MySQL APT repository config tool

# Apply config tool to APT repository (as root)
dpkg -i mysql-apt-config_0.7.3-1_all.deb

# Update APT repository (as root)
apt-get clean && apt-get update

Configure the MySQL APT if you change default configurations.

Apt mysql

Install the MySQL server/client

apt-get install mysql-server
apt-get install mysql-client

That's it!

Tuesday, July 12, 2016

Hello world

Hi there. I'm in Denver, Colorado.


main(int argc, char* argv[])
    printf("Hello world\n");
    return 0;