Node.js中,导出一个对象可以用exports,也可以用module.exports,但是这两者是有些区别的。
先看一个例子:

1
2
3
4
5
6
7
8
9
10
11
//snippet-1:

// foo1.js
exports.foo = "foo1";

// foo2.js
module.exports.foo = "foo2";

// bar.js
console.log(require('./foo1').foo); // Output: foo1
console.log(require('./foo2').foo); // Output: foo2
阅读全文 »

豆瓣: 《你就是孩子最好的玩具》

这是上上周读完的一本书,讲的的怎样教育孩子,通过“情感引导”什么的。。。读完很有收获,建议有孩子的可以读一下。
可是,我家跳跳并不在我身边。
我现在不敢确定跳跳长大后会以什么样的情感面对我这个和他呆的时间少的可怜的爸爸。我说这些话是有些伤心的,有孩子的大概会懂我是有多想和儿子在一起,和他玩游戏,给他讲故事。好吧,这对我来说很奢侈。

阅读全文 »

SSHSecure Shell的简称,是一种加密的网络传输协议。

免密登录

将生成好的本机的公钥填写到服务器的/home/{username}/.ssh/authorized_keys文件中,如果没有该文件,创建一个,然后重启sshd服务。
这时就可以在本机通过ssh登录服务器了:

1
ssh username@hostname

多个秘钥

默认情况下,ssh会使用~/.ssh/id_rsa文件进行连接,但是很多情况下可能会在本机生成多个秘钥key pair。这个时候可以使用~/.ssh/config配置文件来指定各个主机的私钥文件:

1
2
3
4
5
6
7
8
9
Host {name}
HostName {hostname}
User {user name}
IdentityFile ~/.ssh/id_rsa1

Host {name}
HostName {hostname}
User {user name}
IdentityFile ~/.ssh/id_rsa2

对于非登录的情况,比如克隆git仓库,HostHostName 不能随意指定,具体得看git托管平台的情况。比如github的设置:

1
2
3
4
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/xxx

更多

  1. man ssh_config 5
  2. Secure Shell (简体中文)

GitLab CI 能做什么

比如,

  • 项目的单元测试覆盖率检查
  • 项目中每次合并到 master 分支时都生成一个 tag

使用

必备条件: 有一个8.0+版本的 Gitlab, 或者使用 gitlab.com, gitlab.com 有免费的共享 Runner

  1. 在项目中的根目录添加.gitlab-ci.yml文件
  2. 配置GitLab Runner
阅读全文 »

一些常用或有用的代码段,积少成多。

http

  • server
    1
    2
    3
    4
    5
    6
    7
    const http = require('http');

    http.createServer((request, response) => {
    response.writeHead(200, { 'Content-Type': 'text/plain;charset=utf-8'});

    response.end('你好,跳跳');
    }).listen(8080);
阅读全文 »

概念

Linux 手册页惯用的节名

描述
Name 显示命令名和一段简短的描述
Synopsis 语法
Configuration 配置信息
Description 一般性描述
Options 选项描述
Exit Status 退出状态指示
Return Value 返回值
Errors 错误消息
Environment 使用的环境变量
Files 用到的文件
Version 版本信息
Conforming To 遵从的标准
Notes 其它有帮助的资料
Bugs 提交Bug的途径
Example 例子
Authors
CopyRight
SeeAlso
阅读全文 »

移动

  • 导航到鼠标上次的位置:
    • Windows
      Alt+Left: Back
      Alt+Right: Forward
    • Mac
      Control+-: Back
    • Linux
      Ctrl+Alt+-: Back
      Ctrl+Shift+-: Forward
阅读全文 »

Tools

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import threading
from functools import wraps

def delay(delay=0.):
"""
Decorator delaying the execution of a function for a while.
"""
def wrap(f):
@wraps(f)
def delayed(*args, **kwargs):
timer = threading.Timer(delay, f, args=args, kwargs=kwargs)
timer.start()
return delayed
return wrap

@delay(3.0)
def my_func(arg1, arg2):
print arg1, arg2


if __name__ == '__main__':
my_func('Hello', 'world')

数字转换

  • 十进制和16进制相互转换

    1
    2
    let hexNumber = (n).toString(16); // to hex
    let decimal = parseInt(hexNumber, 16); // to decimal
  • 16进制字符串转换为ACSII

From: Stack Overflow

1
2
3
4
5
6
7
8
9
function hex2a(data) {
let hex = data.toString();
let str = '';
for(let i = 0; i < hex.length; i += 2) {
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
}

return str;
}

加密

  • sha1 加密
    1
    2
    3
    var crypto = require('crypto');
    var sha1 = crypto.createHash('sha1');
    sha1.update('str').digest('hex');

其它

  • padLeft

    1
    2
    3
    4
    5
    6
    7
    // ES6

    function padLeft(str, len) {
    let val = '0'.repeat(len - str.length) + str;

    return val;
    }
  • reverse

    1
    2
    3
    function reverse(str) {
    return str.split('').reverse().join('');
    }

tar

bz2

  • tar cjf X.bz2 files 压缩
  • tar xjf X.bz2 解压

dd

dd if=./{filename} of=/dev/{设备} bs={bytes a time} status=progress

lsof

# lsof -i :[port] 查看端口占用信息

Ubuntu升级单个的软件

apt-get install --only-upgrade <packagename>

合并多个文件

cat f1 f2 > f

需要读的书:

  • 《你不知道的JavaScript(上卷)》 八号读完
  • 《你不知道的JavaScript(中卷)》 月底读完
  • 读三章NodeJS文档

代码

  • 这个月底上线新版的网站,不再使用Hexo
  • 完成 LeetCode 10道题
阅读全文 »

毕业四年了,工作也整整四年了,总感觉自己学过的技术掌握的泛泛;当然这和我学习的态度以及工作的经历有很大的关系。虽然也在不停的学习,但苦于没有质的提升。

阅读全文 »

Ubuntu版本: 16.04

每次使用一个新的Ubuntu系统时,总需要将之前的配置一个一个的移动过来,但是时间久了,有些配置都忘了怎么配了,所以我将我个人习惯的配置记录在这里。

阅读全文 »

前一段时间在Linode上买了一台最低配的服务器,大概每个月5刀,想在上面玩儿一些有意思的东西。随后我把博客放在了上面。博客是用hexo建的,最开始托管在Github Pages,用Travis自动发布。迁移到新的服务器上后,使用的还是Travis自动生成的静态页面,只是需要手动下载Travis生成的静态页面。

阅读全文 »

添加一个了二级域名,使用Nginx作为代理,配置如下:

1
2
3
4
5
6
7
8
9
server {
listen 80;

server_name 域名;

location / {
proxy_pass 域名映射的url地址;
}
}

Bash 移动快捷键备忘

昨天(2017年4月4日)发现bash默认的快捷键是emacs的,可以设置成vi: set -o vi, zsh设置成vi是: bindkey -v

下面是emacs的模式:

总是在Windows上用git bash操作git的时候嫌用方向键移动麻烦,所以在这里简单的总结一下bash的移动命令

阅读全文 »
0%