ptnega's technical blog

I’ve moved. Mình chuyển nhà rồi :>

I have moved to my new blog here: https://protegototalum.faith

This blog will just be kept for historical reasons.

Thanks for tuning in! :>

 

Mình đã chuyển sang nhà mới tại https://protegototalum.faith

Blog này sẽ chỉ dùng cho mục đích lưu trữ.

Cảm ơn đã ghé thăm :>

Leave a comment »

Giới thiệu về Kivy

1. Kivy là gì?

Kivy là một thư viện mã nguồn mở viết bằng Python để phát triển ứng dụng, đặc biệt là giao diện người dùng.

2. Kivy có thể chạy trên hệ điều hành nào?

Kivy có thể chạy trên hầu hết các hệ điều hành hiện nay, từ Windows cho tới Linux mà Mac OS. Kivy còn có thể chạy trên Raspberry Pi. Tất nhiên là trên Raspberry Pi thì sẽ cài Windows hay Linux.

3. Ứng dụng viết bằng Kivy có thể chạy trên nền tảng nào?

Kivy có tính đa nền tảng. Những ứng dụng viết bằng Kivy có thể chạy trên cả Windows, Linux, OS X tới Android hay iOS.

4. Kivy giúp chúng ta làm những gì?

Với Kivy, chúng ta có thể làm game và rất nhiều ứng dụng tương tác khác. Đặc biệt là trong bối cảnh mà cảm ứng đa điểm ngày càng đóng vai trò quan trọng thì Kivy cũng hướng tới điều này.

Mọi người có thể tìm thấy các project tạo bằng Kivy tại đây:

Kivy Gallery

5. Nói tóm lại thì Kivy có gì khác so với những thư viện/công cụ tương tự?

– Kivy được xây dựng 1 cách thuần túy. Có rất nhiều điều mới để khám phá ở Kivy…

– Kivy được viết bằng Python. Do đó nó rất nhanh và có độ chính xác cao. Ngoài Python thì Kivy cũng tự xây dựng ngôn ngữ riêng của mình là ngôn ngữ Kivy. Với ngôn ngữ Kivy thì chúng ta có thể tạo giao diện người dùng chỉ trong một số ít dòng code. Những luồng code rất rõ ràng và do đó cũng dễ để debug.

– Ngoài ra có những phần của Kivy được viết bằng C và Cython.

– Kivy có tính đa nền tảng, một điều rất cần thiết khi mà các thiết bị ngày nay ngày càng đa dạng trên nhiều nền tảng khác nhau.

– Hơn cả, Kivy là miễn phí. Tuy vậy, đối với một số nhà phát triển Kivy thì nó là cuộc sống của họ. Vì thế nên Kivy chắc chắn sẽ đi theo thời gian rất lâu nữa.

6. Một số liên kết hữu ích:

Cài đặt Kivy

Kivy API

Lập trình cơ bản với Kivy

Một số project với Kivy:


Chúc mọi người có những giây phút vui vẻ khi tìm hiểu Kivy 🙂

Leave a comment »

Loklak for the first time

I’ve just set up loklak server locally on my Ubuntu 15.10 and harvested more than 1M tweets. That’s interesting.

12

3

Query myself 😀

45

Here is the link to the data file of my collected tweet (just in case):

https://goo.gl/droNwk

Leave a comment »

How to install Hugo on Linux and Windows

In this tutorial, I will show you how to properly install Hugo on your machine.

1. Installation on a Linux machine

  • Debian: In this section, I use my Ubuntu 15.10 64-bit as an example:

First, I need to download the appropirate package file from here:

https://github.com/spf13/hugo/releases

The file I need is hugo_0.15_amd64.deb since my system is 64-bit. If you use a 32-bit system, you will need hugo_0.15_i386.deb

Now I’ve got the package file in ~/Download/ on my machine. Navigate to this directory and use dpkg to simply install Hugo

cd ~/Downloads/

sudo dpkg -i hugo_0.15_amd64.deb

Screenshot from 2015-12-28 12-53-58

You might encounter problems about dependencies. The following command might help you:

sudo apt-get -f install

It will fix the issues of your installation and then install the package for you.

  • Arch Linux:

If you use Arch Linux, it’s quite easy to install Hugo since Hugo is available in yaourt

If you haven’t installed yaourt, add the following lines to /etc/pacman.conf:

[archlinuxfr]

SigLevel = Never

Server = http://repo.archlinux.fr/$arch

and run this command to install yaourt:

pacman -Sy yaourt

To install Hugo using yaourt, simply use this command:

yaourt hugo

You will be prompted to provide your password and everything will go in the right way.

In the end, you should be able to use hugo in your command line shell using the command hugo

 2. Installation on Windows

Depending on your system architecture – 32 bit or 64 bit – you need the correct setup file. I use my Windows 10 32-bit system as an example, so I’ll need hugo_0.15_windows_386_32-bit-only.zip

Those who use 64-bit Windows system should get hugo_0.15_windows_amd64.zip for installation.

When you’ve done downloading the setup file, extract it. Now you’re gonna add the directory of Hugo to PATH Environment variable so you can use Hugo everywhere on your system using CMD

Open Advanced system settings (This window usually appear when you right-click on My Computer and click on Properties):

2015-12-28 (1)

Click on Environment Variables:

2015-12-28 (2)

Now you should add a new variable for your user or modify the system variable. The variable to be created is PATH and the value of it is the path to the directory which contains the extracted files from the previous step. Note that values are separated by the semicolon (;) :

2015-12-28 (3)

2015-12-28 (4)

I’ve renamed the executeable file in the archive to hugo.exe for simple usage. Now I can use Hugo by typing hugo.exe <option> <params> wherever I want:

2015-12-28 (5)

If you have any problems during the installation, feel free to leave a comment in this post and I will answer as soon as possible.

1 Comment »

How to deploy a Hugo blog using Github Pages

In this post, I’m gonna show you how to use Github Pages to run your Hugo blog.

Assume that you have successfully built your blog locally and push the source to a repository on Github.

Check out the link to my post on How to install Hugo (Linux && Windows) if you haven’t installed Hugo on your machine:

https://ptnega.wordpress.com/2015/12/28/how-to-install-hugo-on-linux-and-windows/

If you haven’t got it on your machine, clone the repo to start working:

git clone https://github.com/ducphanduyagentp/ptnega-site.git

Now I will guide you step by step to build your site on Github Pages.

1. Build your blog in the working directory

In the config.toml file, there is an option called “baseurl”. In this post, we need to use it to run our site properly.

By default, your Github Pages are run at:

http://your-user-name.github.io/your-repo-name

This will absolutely your base URL for your Hugo blog. Add this line to the top of config.toml

baseurl = “http://your-user-name.github.io/your-repo-name&#8221;

For example:

baseurl = “http://ducphanduyagentp.github.io/ptnega-site&#8221;

Now, it’s easy to build your site to a specific directory. This directory contains all the file you need to push to your repository to run your blog.

At the top level of your working directory, use this command:

hugo

By default, your site will be built in the public/ directory. If you want to build it in a directory of your choice, use this command instead:

hugo -d your-build-directory

2. Create gh-pages branch in the repository

gh-pages is the branch of your repository which contains source codes from public/ in the previous step. Using git to create this branch. Note that this branch need to be orphaned

git checkout –orphan gh-pages

Now you’re switched to gh-pages branch. Simply copy all the file from public/ folder in the previous step to your working directory (which is now in gh-pages branch).

For your convenience, you can clean up the branch before copying neccessary files.

3. Push source codes to gh-pages branch

Now, everything is ready to be push to your repository.

# Add all the changes to commit

git add -A

# Commit the changes

git commit -m “Build gh-pages”

# Push everything to your repository

git push origin gh-pages

Now, your blog is online at, for example:

http://ducphanduyagentp.github.io/ptnega-site/

If you encounter any problem during the deploying process, feel free to leave a comment here and I will answer your question.

Leave a comment »

How to setup a blog using Hugo

Today I’m gonna show you how to create a simple blog using Hugo. Let’s go right into the tutorial!

1. Install Hugo

Go to Hugo Releases and download the appropriate version for your OS and architecture.

In this tutorial, I’m using Ubuntu 15.10. To install Hugo, I download hugo_0.15_amd64.deb and using the following command:

sudo dpkg -i path/to/deb-file

Note that, if you’re using Windows, you (may) need to add Hugo’s directory to PATH Environment Variable, so that you are able to use hugo in cmd just by typing hugo.exe [-options] [-parameters]

2. Create a new site

Now, you’ve got everything setup. Let’s create a new Hugo site using this command:

hugo new site path/to/site

For example:

hugo new site ~/ptnega-site

Now, your site is created in the ptnega-site directory. Navigate to that dir to continue working

cd ptnega-site/

3. Create some content

In the working directory, you will see the following file structure:

 

  • archetypes/
  • content/
  • data/
  • layouts/
  • static/
  • config.toml

There is something you need to know about these folders and file:

  • config.toml: The title of the blog, themes you use and other configuration is in this file
  • static/: The data in this folder will not be processed when you run the blog
  • content/: This is where your posts are, typically Markdown files

To create your very first post, just type the following command:

hugo new post/nameofyourpost.md

For example:

hugo new post/intro.md

Your new post is now in ptnega-site/content/post/intro.md

Open intro.md:

+++
Categories = [“Development”, “GoLang”]
Description = “”
Tags = [“Development”, “golang”]
date = “2015-12-26T22:50:04+07:00”
menu = “main”
title = “intro”

+++

  • Categories: You can put this post to any categories you like by adding the name of the categories to this array.
  • Description: You can briefly describe your post here.
  • Tags: Somehow similar to Categories
  • date: this is the time when your post was created
  • menu: This post will appear in the menu you set it to. “main” is the top most menu
  • title: The title of your blog. Change it to what you like.

Now, add your “actual content” to the bottom of this file. This is what you want to display in the post. For example:

+++
Categories = [“GCI”, “Google”, “GCI15”]
Description = “”
Tags = [“Self”, “GCI15”]
date = “2015-12-26T22:50:04+07:00”
menu = “main”
title = “Introduce myself”

+++

Hi! I’m ptnega from Vietnam. I’m 17 and this is my last GCI.

4. Install a theme

You’ve got your content. Now you need to display it on the site. Let’s install a theme for your site:

git clone –depth 1 –recursive https://github.com/SenjinDarashiva/hugo-uno.git themes/hugo-uno themes/hugo-uno

I’m installing hugo-uno theme. You can find many interesting ones here:

Hugo Themes

Now you have another folder named themes/hugo-uno. This is where your themes stored.

5. Config.toml

We’re almost done. Now let’s config this file to make sure everything will be in the right way.

A simple config.toml could look like this:

languageCode = “en-us”
title = “Ducphanduy’s Hugo Blog”
theme = “hugo-uno”

In this tutorial, I’m gonna run my site locally on my machine. There are other options when you install different themes or run the site on github-pages. A more complex configuration, for example:

baseurl = “http://ducphanduyagentp.github.io&#8221;
languageCode = “en-us”
title = “Ducphanduy’s Hugo Blog”
theme = “hugo-uno”

[Params]

AuthorName = “Duc Phan Duy”
github = “ducphanduyagentp”
twitter = “I_am_agentp_14”

baseurl is the URL to your site when you run it online. Providing a baseurl give you chances to use some features like Menu feature, …

[Params] is the parameters of the theme you installed. You will find the patterns for the params and other configuration of the theme is its folder above, in the README.MD file or the example site provided along with the theme.

6. Run the blog locally

To run the blog locally, simply use this command:

hugo server -w

By default, you site will be running on localhost:1313

Here is my result:

Screenshot from 2015-12-26 23-28-07

Hugo is extremely fast to run static blog and it provides users with many other convenient features. In my future posts, I will introduce some other features of Hugo that may be helpful to users.

You can have a look at my github repo of the example site in this post:

ptnega-site repo

Leave a comment »

My first task in GCI 2015

Hello everyone!

It’s been a long time since I last posted on my blog. I’m so excited because I’ve just completed my very first task in GCI 2015 and appeared on FOSSASIA GCI15 site.

Here is my pull request:

Github pull request

I’ll do my best in GCI15. Thank you so much.

Leave a comment »