2019年9月24日 星期二

set postgres password

charles@charles-composer:~$ su
Password:
root@charles-composer:/home/charles# su postgres
postgres@charles-composer:/home/charles$ \password postgres
No command 'password' found, did you mean:
 Command 'assword' from package 'assword' (universe)
password: command not found
postgres@charles-composer:/home/charles$ psql
psql (9.5.19)
Type "help" for help.

postgres=# \password postgres
Enter new password:
Enter it again:
postgres=# \q
postgres@charles-composer:/home/charles$

2019年9月20日 星期五

HyperV Ubunt resolution

  1. From within the Ubuntu virtual machine, open Terminal
  2. Type sudo vi /etc/default/grub
  3. Find GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
  4. Append that line with video=hyperv_fb:[specify resolution, e.g. 1024x768]
  5. Here is what it might look like: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1024x768"
  6. Save changes and exit
  7. Run the following command: sudo update-grub
  8. Restart the VM

2019年2月11日 星期一

Python getopt.getopt

1. 处理所使用的函数叫getopt() ,因为是直接使用import 导入的getopt 模块,所以要加上限定getopt 才可以。 
2. 使用sys.argv[1:] 过滤掉第一个参数(它是执行脚本的名字,不应算作参数的一部分)。 
3. 使用短格式分析串"ho:" 。当一个选项只是表示开关状态时,即后面不带附加参数时,在分析串中写入选项字符。当选项后面是带一个附加参数时,在分析串中写入选项字符同时后面加一个":" 号 。所以"ho:" 就表示"h" 是一个开关选项;"o:" 则表示后面应该带一个参数。 
4. 使用长格式分析串列表:["help", "output="] 。长格式串也可以有开关状态,即后面不跟"=" 号。如果跟一个等号则表示后面还应有一个参数 。这个长格式表示"help" 是一个开关选项;"output=" 则表示后面应该带一个参数。 
5. 调用getopt 函数。函数返回两个列表:opts 和args 。opts 为分析出的格式信息。args 为不属于格式信息的剩余的命令行参数。opts 是一个两元组的列表。每个元素为:( 选项串, 附加参数) 。如果没有附加参数则为空串'' 。 
6. 整个过程使用异常来包含,这样当分析出错时,就可以打印出使用信息来通知用户如何使用这个程序。 

如上面解释的一个命令行例子为: 
'-h -o file --help --output=out file1 file2'

在分析完成后,opts 应该是: 
[('-h', ''), ('-o', 'file'), ('--help', ''), ('--output', 'out')]