A lecture of Go

概述

串讲,是以会议形式,串讲人给同事讲一个topic。会上的其他同事,对串讲人进行相关知识的提问,以考查其对此topic的掌握程度。便于尽快上手,投入工作。

Install Snap on Centos7

问题

在Centos7系统上安装snap,遇到的问题记录

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[centos@ip-172-26-6-67 ~]$ sudo snap install core
error: system does not fully support snapd: cannot mount squashfs image using "squashfs": -----
       mount: wrong fs type, bad option, bad superblock on /dev/loop0,

       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

       -----

Google一圈之后,解决方案如下:

Deploy Hugo on Github Page

Hugo is a framework written with Golang for building website.

I told my wife I wrote something on my blog. After heard that, she said she wants to build a blog and start writing. So I spent a few hours on setting up a local hugo site and deployed it on Github pages.

Here are all the thing you need to do:

  • A github account, if you didn’t have one, you need to sign up
  • Git installed on your local machine
  • Install hugo
  • Head over to GitHub and create a new public repository named username.github.io, where username is your username (or organization name) on GitHub
  • Generate a website on local machine
  • Push your local reposity to github
  • Add a github workflow
  • Config reposity’s page setting

If everything goes well, you will see your blog online https://YourGithubUsername.github.io/

Build your own tools

背景

从拥有自己的第一台电脑至今,由于工作或其他原因,我已经换过好几台电脑。每一次拿到新电脑的第一件事,就是安装各种软件以及配置开发环境。手动下载,安装,这些工作其实完全可以自动化。 本篇文章持续记录自己工作和生活中用到的软件,最终目标,可以在新电脑上(Mac OS)能够一键安装所需的软件。

A tool for testing server

让我们来对服务器做一下压力测试吧!
本篇文章讲一下压力测试应该怎么做,压力测试过程中需要注意哪些指标,以及需要注意的事项。
首先,我们要清楚我们进行压测的目的是什么。是为了找出服务的性能瓶颈,还是为了检验当前服务能否扛住xxx量的并发? 俗话说,“不打无准备之仗”,首先要根据压测目的出一个可行的书面方案。
下面是一个方案模板

Gdb

This article keep tracks of the most used commands of GDB

Write a classic C program with your favoriate editor and save it as main.c.

1
2
3
4
5
#include <stdio.h>

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

Compile it with gcc, which is a popular c/c++ compiler on linux.

1
gcc -o main -g main.c 

Debug with gdb

1
gdb main      // gdb programname -p [pid]
1
2
3
4
(gdb) b main  // set breakpoint
(gdb) layout src // gui
(gdb) p  // print p/x hex
(gdb) i b // list all breakpoints, you can list other info
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
┌─test.c───────────────────────────────────────────────────┐
│   3           int main(int argc, char *argv[]) {         │
│B+>4               printf("Hello world\n");               │
│   5           }                                          │
└──────────────────────────────────────────────────────────┘
process 31551 In: main             L4    PC: 0x555555555144
(gdb) r
Starting program: /home/junxxx/Workspace/the_c_language/test


Breakpoint 1, main (argc=1, argv=0x7fffffffe338)
    at test.c:4
(gdb)
AbbreviationCommandExplanation
bbreakbreak [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]
ccontinueconntinue [N]
sstepstep [N]
nnextnext [N]
pprintprint [[OPTION]… –] [/FMT] [EXP]
iinfo, infuse help i to check out info

Reference

  1. Debugging with GDB

Vim

前言

本文记录“玩”Vim的经验,学习Vim是一件起步很困难的事,但是当你稍微熟悉它的操作模式之后, 会对它爱不释手。

学习,或者换句话说,玩Vim,最重要的是实际上手去用,去玩,去实操。心态放平衡,不要想着一口气学完所有的技巧并掌握它,事实上,作为一款编辑器,只要它能满足你的实际需求就行,你平常用不到的那些高级特性,可以在你日后慢慢使用的过程中逐渐去尝试。

Shell

Learn a shell a day, master Unix one day!

Pipe

Process read previous process’s output as its input and generate output to next process’s input. Use symbol | to create a pipeline, which a powerful skill in Unix.

1
2
// count the numbers of text file in current directory.
ls -la | grep *.txt | wc -l

Xargs

Many programs, takes its arguments from the command line (char *argv[]) but ignores standard input fd 0. If you want to pipe the output of a program to input of another program that ignores standard input, like rm, you need to use xargs.

C Programming Language

The C Programming Language is the best textbook for a beginner who wants to learn C. This article mostly talks about pointers and memory in C.

C’s syntax is simple but handling pointers in C is too easy to get stuck.

Primitive data types and sizes

char, int, float, double

signed, unsigned, short, long

constant

1
2
3
printf("%u\n", sizeof(int));
printf("%u\n", sizeof(char));
printf("%u\n", sizeof(float));

Array

Array is a continuous fixed-length address. Different data types have different sizes. sizeof returns the size(how many bytes it holds to represent a data) of a data.