ruby-csv-helper-method

background

  • 一般情况下, 对程序来说处理文本是最友好的
  • 对程序来说, csv的数据比excel更友好

read

1
2
3
4
5
6
7
8
9
10
require 'csv'

def get_array_of_hashes(input_csv_file_path)
result = []
CSV.foreach(input_csv_file_path, headers: true, converters: :all) do |row|
result << row.to_h.transform_keys(&:to_sym)
end

result
end

write

1
2
3
4
5
6
7
8
9
10
11
12
13
require 'csv'

def write_output_as_csv(output, output_csv_file_path)
headers = output.first.keys

CSV.open(output_csv_file_path, "w") do |csv|
csv << headers

output.each do |hash|
csv << hash.values
end
end
end

example workflow

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def get_output(datasource)
# xxx
end

def run
input_file_path = "xxx.csv"
datasource = get_array_of_hashes(input_file_path)

output_csv_file_path = "yyy.csv"
output = get_output(datasource)

write_output_as_csv(output, output_csv_file_path)
end

run

local-directory-as-git-remote-repo

为什么不用github

  1. fetch/push速度慢
  2. 练习git操作, 没必要专门建一个github仓库
  3. 练习git操作, 本地的repo操作起来速度飞快

local repo on my mac

1
alias local_repo='cd $HOME/local.repo/api-provider.git'

将本地目录当做git仓库…步骤

  1. 本机, 在某个目录里
1
2
# 会在当前目录下, 新建一个 test.git 的bare仓库
$ git init --bare test.git
  1. 客户端: 初始化仓库或者使用已有的git仓库
1
2
# 如果 origin已存在, 可以换个别的名字(例如 demo_origin), 只是推送代码的时候要注意 向demo_origin推
$ git remote add origin file://$HOME/local.repo/api-provider.git # local directory

如果就想用origin, 那么可以先删掉原先的, 再添加origin

1
$ git remote remove origin
  1. 客户端可以推送代码了… git push

  2. 克隆

1
$ git clone file:///home/webuser/my_git_repo/notebook.git

扩展: 可以把ECS作为自己的git仓库

原理和上面类似

efficiency-sharing

本篇记录了我如何使用命令行+编辑器提高工作效率

关键点

  • 编辑器(我主用sublime)

    • 多光标
    • markdown
    • 快捷键
  • 思维方式

    • 文本
    • 信息冗余
    • 清晰
  • worklog

    • 工作流(TODO OK)
    • 文件目录
  • 命令行(软件)

    • git
    • template/套路
    • 能否自动化
    • mkdir cp mv open alias
  • 一维表

    • 数据组织方式
    • 字段
    • 脚本+csv
  • “命令行+编辑器 天下无敌”

  • 当一件事有用/有益的时候, 做他的成本越低, 一个人就越愿意/乐意去做某件事

    • 就是这种工具
    • 文本
    • git分支
  • “一致性 大于 正确性”

  • 命令行+编辑器(文本型 二进制型)

    • 转变思维方式: 尽量使用文本型文件
    • markdown
    • IDE / EDITOR
    • 使用文本的优点

notebook目录结构

当前做笔记用的是一个目录(名为notebook)+markdown, 用git管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
lijunwei@bxzy:notebook(master)$ tree . -L 1
.
├── README.md
├── TODO.md
├── efficiency
├── fun
├── goal
├── learn
├── log
├── notes
├── questions.note
├── read
├── share
├── tmp
└── work

11 directories, 2 files

first-hexo-blog-post

今天开始使用hexo公开自己的文章

还有很多问题没解决掉, 慢慢来

部署步骤

  • 本地启动安装hexo
1
sudo npm install hexo-cli -g
  • 本地用hexo新建一个项目
1
2
3
4
hexo init blog
cd blog
npm install
hexo server
  • 安装部署工具
1
npm install hexo-deployer-git
  • 修改配置

主要是 _config.yml 里的deploy部分

1
2
3
4
deploy:
type: git
repo: webuser@xiaoli:/home/webuser/my_git_repo/blog-gallary.git
branch: master
  • 在VPS上新建一个 bare git仓库(下面称为 bare-git-repo)(使用github也可以, 一样的)
1
2
3
ssh webuser@xiaoli
cd /home/webuser/my_git_repo
git init --bare blog-gallary.git
  • 本地提交代码(不一定提交到到github, 本地存着也可以)

  • 使用 hexo deploy, 把代码部署到VPS的 bare-git-repo

1
hexo clean && hexo deploy
  • 在VPS上的 /srv/www 目录下clone bare-git-repo
1
2
3
ssh webuser@xiaoli
cd /srv/www
git clone file:///home/webuser/my_git_repo/notebook.git
  • 配置dns解析

  • 配置nginx

基本配置

1
2
3
4
5
6
7
8
cat /etc/nginx/sites-enabled/production.blog.conf

server {
listen 80;
server_name blog.bxzy.top;
root /srv/www/blog-gallary;
index index.html;
}
  • 访问 blog.bxzy.top

Basic Workflow

1
2
3
4
5
6
7
8
# local
cd ~/OuterGitRepo/blog-gallary
hexo new title_xxx
git add .; git commit -am 'Added blog post title_xxx.'
hexo clean && hexo deploy && ssh webuser@xiaoli "cd /srv/www/blog-gallary && git pull"

# visit
http://blog.bxzy.top