I Try Do


  • 首页

  • 归档

  • 分类

  • 标签

  • 搜索
close
I Try Do

rails ssh login

发表于 2017-07-24 | | 阅读次数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require 'net/ssh'
host = '13.19.13.24'
username = 'deploy'
port = 5331
#连接服务器,执行 tail -f 指令
server_cmd1 = %q(tail -f /mnt/www/nirvana_staging/current/log/production.log)
# 连接到远程主机
ssh = Net::SSH.start(host, username, { :port => port }) do |ssh|
result = ssh.exec!(server_cmd1) do |ssh, type , data|
if /INFO/ =~ data
puts "\e[32m#{data}\e[0m" #这里的data就是,每次写入staging.log的数据
elsif /FATAL/ =~ data
puts "\e[31m#{data}\e[0m"
elsif /WARN/ =~ data
puts "\e[33m#{data}\e[0m"
else
p data
end

end
puts result
end
I Try Do

canvas

发表于 2017-07-21 | | 阅读次数

hex to rgb

1
2
3
4
5
6
7
8
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}

rgb to hex

1
2
3
function rgbToHex(r, g, b) {
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}

像素点遍历与修改

1
2
3
4
5
6
7
8
9
10
11
12
function decryptColor(canvas, rotten) {
var ctx = canvas.getContext('2d')
var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
var data = imgData.data;

for (let i = 0; i < data.length; i+=4) {
data[i] = data[i] // r
data[i+1] = decNumber(data[i+1], i+1, rotten) // g
data[i+2] = decNumber(data[i+2], i+2, rotten) // b
}
ctx.putImageData(imgData, 0, 0)
}

I Try Do

form表单提交

发表于 2017-07-05 | | 阅读次数

js form提交文件

axis

1
2
3
4
const config = { headers: { 'Content-Type': 'multipart/form-data' } };
let fd = new FormData();
fd.append('file',files[0])
return axios.post("http://localhost:5000/upload", fd, config)

多文件提交

1
2
3
4
5
6
7
const config = { headers: { 'Content-Type': 'multipart/form-data' } };
let fd = new FormData();
// 这里必须用循环,一个个添加到表单
Array.prototype.forEach.call(evt.target.files, file => {
fd.append('files', file)
})
return axios.post("http://localhost:5000/upload", fd, config)

I Try Do

rails gems

发表于 2017-06-14 | | 阅读次数

Rails的环境变量设置

  • gem Figaro

tree型结构

  • gem ancestry
  • github
  • ruby-china wiki

搜索条件过滤

  • gem ransack
  • github
  • ruby-child post
  • ransack enum question resolve

构建积分,等级,徽章

  • gem merit
  • github
  • 用更优雅的方式构建的网站的积分,等级,徽章系统

用户活跃度

  • gem activerecord-reputation-system
  • github

状态机

  • gem aasm

用户活跃度

  • gem activerecord-reputation-system

更友好的展示错误页

  • gem better_errors

api 表单验证,数据验证

  • gem reform

    gem reform validation usage

  • gem dry-validation
  • gem rails_param

cors

  • gem rack-cors

配置application.rb

1
2
3
4
5
6
7
# Rails 5
config.middleware.insert_before 0, 'Rack::Cors', debug: false do
allow do
origins (ENV['CORS_HOSTS'] ? ENV['CORS_HOSTS'].split(',') : '*')
resource '*', headers: :any, methods: :any, credentials: false
end
end

加标签[tag]

  • gem acts-as-taggable-on

权限管理

  • gem Pundit
I Try Do

css疑难杂症

发表于 2017-06-06 | 分类于 css | | 阅读次数

垂直居中

单行文字居中

  • line-height
    1
    2
    3
    <div style="line-height: 100px">
    <span>文字垂直居中</span>
    </div>
  • table-cell, vertical-align
    1
    2
    3
    <div style="height: 300px; display: table-cell; vertical-align: middle;">
    <p>aaa</p>
    </div>

多行文字居中

  • table-cell
    1
    2
    3
    4
    <div style="height: 300px; display: table-cell; vertical-align: middle;">
    <p>aaa</p>
    <p>bbb</p>
    </div>

单行文字和图片垂直居中 (前提:内部字体相对较小)

  • line-height, vertical-align
    1
    2
    3
    4
    <div style="line-height: 500px;">
    <img src="./titles-calc.png" style="/*display: inline-block;*/vertical-align: middle;">
    <span style="vertical-align: middle">aaa</span>
    </div>
  • flex 布局
    1
    2
    3
    4
    <div style="height: 500px; display: flex; align-items: center;">
    <img src="./titles-calc.png">
    <span>aaa</span>
    </div>
I Try Do

加密算法

发表于 2017-05-31 | 分类于 加密 | | 阅读次数

javascript

AES

crypto-js

下面设置opt为了使每次加密,都会生成相同的密文

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const AESCrypt = require('crypto-js/aes')
const encUtf8 = require('crypto-js/enc-utf8')
const modeCFB = require('crypto-js/mode-cfb')
const NoPadding = require('crypto-js/pad-nopadding')
const IV = 'nirvana'

const opt = {
iv: encUtf8.parse(IV),
mode: modeCFB,
padding: NoPadding
}
let AES = {
encrypt: (text, secretkey) => {
let enText = AESCrypt.encrypt(text, encUtf8.parse(secretkey), opt).toString()
return atob(enText)
},
decrypt: (text, secretKey) => {
let deText = btoa(text)
return AESCrypt.decrypt(deText, encUtf8.parse(secretKey), opt).toString(encUtf8)
}
}

export { AES }

I Try Do

mysql客户端连接服务器

发表于 2017-05-30 | 分类于 mysql | | 阅读次数
  1. 登录服务器

  2. 进入数据库

    1
    2
    mysql -h localhost -u root -p 
    Enter password: ***
  3. 创建一个新用户mars

    1
    2
    3
    4
    mysql> use mysql;
    # 格式:grant 权限 on 数据库名.表名 用户@登录主机 identified by "用户密码";
    # 如果 grant select,update,insert,delete on 可以设置为 grant all privileges on
    mysql> grant all privileges on waimaiph_pro.* to 'mars'@'11.11.11.11' identified by "123456"

    'mars'@'11.11.11.11':mars用户连接的客户端ip必须是11.11.11.11

  4. 如果允许来自所有不同的IP访问: 'mars'@'%'

    1
    grant all privileges on waimaiph_pro.* to 'mars'@'%' identified by "123456"

    将host字段的值改为%就表示在任何客户端机器上能以mars用户登录到mysql服务器,建议在开发时设为%。

    1
    update user set host = '%' where user = 'mars';
    1
    mysql> FLUSH PRIVILEGES;

配置参数

MySql 5.7

1
/etc/mysql/mysql.conf.d/mysqld.cnf

below versions

1
/etc/mysql/my.cnf

modify to

bind-address = 0.0.0.0

I Try Do

vim常用命令

发表于 2017-05-06 | 分类于 vim | | 阅读次数

vim

I Try Do

git常用命令

发表于 2017-05-06 | 分类于 git | | 阅读次数

命令大全

png

删除git代码管理中已经提交的服务器的提交

1
2
3
#git reset --hard HEAD~1 # 取消当前版本之前的一次提交
git reset --hard HEAD~2 # 取消当前版本之前的两次提交
git push origin HEAD --force # 强制提交到远程版本库,从而删除之前的两次提交数据

在mac中自动保存git用户名与密码如此简单

在Mac OS X中这个操作竟然如此简单。只需在Terminal中输入如下的命令:

1
git config --global credential.helper osxkeychain

然后在git操作时只要输入一次用户名与密码,以后就不用输入了。

【参考资料】

Git keeps prompting me for password

I Try Do

js table拖动排序

发表于 2017-05-05 | 分类于 js | | 阅读次数
  1. table添加类.draggable-items
  2. 将可拖动的tr写到tbody中
  3. 添加下面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
    var cloneEl = null
    var currentDragEl = null
    var parentNode = document.querySelector('.draggable-items tbody')
    var trs = parentNode.querySelectorAll('tr')
    trs.forEach(function (el, index) {
    el.setAttribute('draggable', true)
    el.orSeq = index
    el.index = index

    el.onmousedown = function (event) {
    cloneEl = el.cloneNode(true)
    parentNode.insertBefore(cloneEl, el)
    cloneEl.index = el.index
    el.style.display = 'none'
    currentDragEl = el

    cloneEl.onmouseup = currentDragEl.onmouseup = function (event) {
    currentDragEl.index = cloneEl.index
    parentNode.removeChild(currentDragEl)
    parentNode.insertBefore(currentDragEl, cloneEl)
    parentNode.removeChild(cloneEl)
    currentDragEl.style.display = 'table-row'
    }
    }

    el.ondragover = function (event) {
    var nowElIndex = el.index
    if (el.index > cloneEl.index) {
    parentNode.removeChild(cloneEl)
    for (let i = cloneEl.index + 1; i <= el.index; i++) {
    el.index = el.index - 1
    }
    if (parentNode.lastChild === el) {
    parentNode.appendChild(cloneEl)
    } else {
    parentNode.insertBefore(cloneEl, el.nextSibling)
    }
    cloneEl.index = nowElIndex
    } else if (el.index < cloneEl.index) {
    for (let i = el.index; i < cloneEl.index; i++) {
    el.index = el.index + 1
    }
    parentNode.removeChild(cloneEl)
    parentNode.insertBefore(cloneEl, el)
    cloneEl.index = nowElIndex
    }
    }
    })
1234
wsen

wsen

不积跬步无以至千里

38 日志
19 分类
20 标签
© 2019 wsen
由 Hexo 强力驱动
主题 - NexT.Pisces