install-reddit

文章排名算法reddit
第一步安装

1
2
3
wget https://raw.github.com/reddit/reddit/master/install-reddit.sh
chmod +x install-reddit.sh
sudo ./install-reddit.sh

first-time-try-electron

今天突然想起来 electron,就花了点时间试了一下
第一步先安装:

1
npm install electron

安装后,创建一个文件夹 your project
然后创建3个文件
main.js、package.json、index.html
目录结构如下

1
2
3
4
your projetc
- main.js
- package.json
- index.html

配置package.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
"name": "your app",
"version": "1.0.0",
"description": "A minimal Electron application",
"main": "main.js",
"scripts": {
"start": "electron ."
}
,

"repository": {
"type": "git",
"url": "git+https://github.com/electron/electron-quick-start.git"
}
,

"keywords": [
"Electron",
"quick",
"start",
"tutorial"
],

"author": "GitHub",
"license": "CC0-1.0",
"bugs": {
"url": "https://github.com/electron/electron-quick-start/issues"
}
,

"homepage": "https://github.com/electron/electron-quick-start#readme",
"devDependencies": {
"electron-prebuilt": "^1.2.0"
}

}

配置 main.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const {app, BrowserWindow} = require('electron')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win

function createWindow () {
// Create the browser window.
win = new BrowserWindow({width: 800, height: 600})

// and load the index.html of the app.
win.loadURL(`file://${__dirname}/index.html`)

// Open the DevTools.
win.webContents.openDevTools()

// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

最后 编辑一下index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
We are using node <script>document.write(process.versions.node)</script>,
Chrome <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
</body>
</html>

最后的最后

1
npm start

就会自动弹出窗口

希望可帮到你,Best wishes

firsttime-try-vue.js

最近一直听别人在说vue.js,也简单了解了一下,单页面效果跟移动端的体验很像,所以今天尝试用一下,废话不多说
第一步安装
在用 Vue.js 构建大型应用时推荐使用 NPM 安装,NPM 能很好地和诸如 Webpack 或 Browserify 的 CommonJS 模块打包器配合使用。Vue.js 也提供配套工具来开发单文件组件。

1
2
3
4
# 最新稳定版本
$ npm install vue
# 最新稳定 CSP 兼容版本
$ npm install vue@csp

命令行工具

Vue.js 提供一个官方命令行工具,可用于快速搭建大型单页应用。该工具提供开箱即用的构建工具配置,带来现代化的前端开发流程。只需一分钟即可启动带热重载、保存时静态检查以及可用于生产环境的构建配置的项目:

1
2
3
4
5
6
7
8
# 全局安装 vue-cli
$ npm install -g vue-cli
# 创建一个基于 "webpack" 模板的新项目
$ vue init webpack my-project
# 安装依赖,走你
$ cd my-project
$ npm install
$ npm run dev

nginx-config-setting-load-balance

之前也用过nginx的负载均衡,但是一直都没时间去记录一下,今天又实际操作了一次,就抽个时间简单写一下吧
我的/ect/nginx/nginx.conf是我的配置文件

1
vim /ect/nginx/nginx.conf

配置文件都一样,我就直接说重点部分了
weight是设置权重

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

upstream todaysay{
server 127.0.0.1:11001 weight=4;
server 127.0.0.1:11002 weight=3;
server 127.0.0.1:11003 weight=2;
server 127.0.0.1:11004 weight=1;
}



server {
listen 11000;
#access_log on;

location / {
#proxy_redirect on;
proxy_pass http://todaysay;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}

}

保存退出,先检查一下文件是否正确

1
2
3
$ ginx -t -c /etc/nginx/nginx.conf
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

一般nginx是80端口,可以先杀掉nginx

1
sudo fuser -k 80/tcp

加载配置文件

1
ginx  -c /etc/nginx/nginx.conf

重启服务

1
service nginx start

检查状态

1
2
$    service nginx status
* nginx is running

到这里你就可以用11000端口nginx,nginx会自动分配到你指定的某个端口上来处理请求

希望可以帮到你,Best wishes

login-into-linux-server-without-password

ssh 无密码登录要使用公钥与私钥。linux下可以用用ssh-keygen生成公钥/私钥对,下面我以CentOS为例。

有机器A(192.168.1.155),B(192.168.1.181)。现想A通过ssh免密码登录到B。

1.在A机下生成公钥/私钥对。

1
[chenlb@A ~]$ ssh-keygen -t rsa -P ''

-P表示密码,-P ‘’ 就表示空密码,也可以不用-P参数,这样就要三车回车,用-P就一次回车。
它在/home/chenlb下生成.ssh目录,.ssh下有id_rsa和id_rsa.pub。

2.把A机下的id_rsa.pub复制到B机下,在B机的.ssh/authorized_keys文件里,我用scp复制。

1
2
3
4

[chenlb@A ~]$ scp .ssh/id_rsa.pub chenlb@192.168.1.181:/home/chenlb/id_rsa.pub
chenlb@192.168.1.181's password:
id_rsa.pub 100% 223 0.2KB/s 00:00

由于还没有免密码登录的,所以要输入密码。

3.B机把从A机复制的id_rsa.pub添加到.ssh/authorzied_keys文件里。

1
2
chenlb@B ~]$ cat id_rsa.pub >> .ssh/authorized_keys
[chenlb@B ~]$ chmod 600 .ssh/authorized_keys

authorized_keys的权限要是600。

4.A机登录B机。

1
2
3
4
5
6
7
[chenlb@A ~]$ ssh 192.168.1.181
The authenticity of host '192.168.1.181 (192.168.1.181)' can't be established.
RSA key fingerprint is 00:a6:a8:87:eb:c7:40:10:39:cc:a0:eb:50:d9:6a:5b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.181' (RSA) to the list of known hosts.
Last login: Thu Jul 3 09:53:18 2008 from chenlb
[chenlb@B ~]$

第一次登录是时要你输入yes。

现在A机可以无密码登录B机了。

小结:登录的机子可有私钥,被登录的机子要有登录机子的公钥。这个公钥/私钥对一般在私钥宿主机产生。上面是用rsa算法的公钥/私钥对,当然也可以用dsa(对应的文件是id_dsa,id_dsa.pub)

想让A,B机无密码互登录,那B机以上面同样的方式配置即可。

django deplop by virtualenv + gunicorn + nginx + supervisor

今天尝试了一下在一台机器上去安装不同版本的python、django
发现原来linux上有个类似模拟虚拟环境的东西啊virtualenv
就尝试自己在这个虚拟环境里搭建了一套自django1.9.2 python2.7 然后用gunicorn做web服务器、supervisor去管理进程、nginx去做外部转发和访问,这期间参考了国外和国内的一些大牛写的文章,在这里首先表示感谢
我也确实是按照这个步骤自己完成了一套这样的服务

第一步:安装虚拟环境的库

1
2
3
4
5
6
7
sudo pip install virtualenv

Downloading/unpacking virtualenv
Downloading virtualenv-15.0.3-py2.py3-none-any.whl (3.5MB): 3.5MB downloaded
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...

第二步:创建虚拟环境

1
2
3
virtualenv bugenv
New python executable in /Users/tataufo/todaysay_env/bin/python
Installing setuptools, pip, wheel...done.

第三步:进入虚拟环境

1
2
3
root@recall:/home/www# cd bugenv/
root@recall:/home/www/bugenv# source bin/activate
(bugenv)root@recall:/home/www/bugenv #激活环境,这个每次在重新登陆服务器的时候都需要激活

第三步:安装django和gunicorn

1
2
sudo pip install django==1.9.2
sudo pip install gunicorn

第四步:创建django项目和django app

django-admin.py startproject bugproject
python manages.py startapp bugapp

1
2
3
4
5
6
7
8
复制
(bugenv)root@recall:/home/www/bugenv# ls
bin include lib local
(bugenv)root@recall:/home/www/bugenv# mkdir djcode
(bugenv)root@recall:/home/www/bugenv# cd djcode/
(bugenv)root@recall:/home/www/bugenv/djcode# django-admin.py startproject bugproject
(bugenv)root@recall:/home/www/bugenv/djcode# cd bugproject/
(bugenv)root@recall:/home/www/bugenv/djcode/bugproject# python manage.py startapp bugapp

第五步:设置django 的settings.py文件
添加app,最后结果如下

1
2
3
4
5
6
7
8
9
10
11
12

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# add app
'bugapp',
'gunicorn',
)

第六步:运行gunicorn

mysql-django-support-emoji(utf8mb4)

今天在做mysql数据存储的时候就遇见了大家可能都会遇见的问题(emoji存储)
这里主要是涉及到utf8mb4的设置

mysql 5.5以上才支持字符集
第一步:数据库版本检查:

1
select version() #查看mysql版本

第二步:修改mysql配置文件 my.conf(windows上my.ini), 修改/添加如下配置为:

1
2
3
4
5
6
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8mb4

第三步:重启mysql

1
$service mysql restart

第四步:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
+--------------------------+--------------------+
| Variable_name | Value |
+--------------------------+--------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| collation_connection | utf8mb4_unicode_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+--------------------------+--------------------+
rows in set (0.00 sec)

最后,因为我是跟django一起配合用的,所以 django的settings.py文件里也要做相应的配置

1
2
3
4
5
6
7
 DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
...
'OPTIONS': {'charset': 'utf8mb4'},
}
}

希望可帮到你,Best wishes

first-product

来谈一谈近期从iOS转做PM的感受吧,
之前觉得PM的工作其实是很简单,整天就会随便想一想,就要来让我们来做这做那的,而且感觉他们整天很清闲,
真正当我去做这项工作的时候,才发现其实不是这样的,他们每天除了要解决各个部门的需求之外,每天脑子里还要想各种天花乱坠的需求和玩法,
而且最大的感受其实是,一天到晚都在开会,去解决各个部门的问题。
即使我以后不做PM了,我也会对PM好的,因为他们真的不容易,最后一句请善待你们公司的PM,啊哈哈哈!

ReactiveCocoa-UI-UITextField

今天遇见了UITextField的使用
1.监听输入的状态
[[self.textField rac_signalForControlEvents:UIControlEventEditingDidBegin] subscribeNext:^(UITextField *sender) {
@strongify(self);
NSLog(@”tag is %@”,@(sender.tag));
}];

  1. 监控输入的内容
    [self.textField.rac_textSignal subscribeNext:^(id x) {
    NSLog(@"content is %@",x);
    
    }];