Skip to content

Instantly share code, notes, and snippets.

View Baozi2's full-sized avatar
💭
I may be slow to respond.

zouyu1026 Baozi2

💭
I may be slow to respond.
View GitHub Profile
@Baozi2
Baozi2 / gist:0aa48da3e1f64983fa979c8601f920db
Last active March 12, 2018 09:38
one webpack plugin create json file with template / 一个用于根据json模板文件生成json文件的webpack插件
"use strict"
const fs = require('fs');
const path = require('path');
function MP(templateFile, options){
let _this = this,
mp = {};
//获取webpack root
let rootPath = path.dirname(module.parent.filename);
let tmpFilePath = path.resolve(rootPath, templateFile);
@Baozi2
Baozi2 / gist:4c7de68d038e4a7259a7f7381d35df70
Last active March 11, 2018 03:28
在Ubuntu16.04配置rails环境/ Setup rails environment in Ubuntu16.04
# install rvm /安装rvm
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm install version
# install nginx/安装nginx 要安装最新的nginx版本参照官网 http://nginx.org/en/linux_packages.html#stable
sudo apt-get update
sudo apt-get install nginx
#show nginx version/显示nginx的版本
nginx -v
@Baozi2
Baozi2 / gist:c33a4f0d8eb1edc1d360b9c005e526ee
Created March 13, 2018 05:41
给定数组 和 间距 计算 平均值得算法
function calAVG(array, interval){
if(!(Array.isArray(array))) throw '参数异常'
for(let ele of array){
if(isNaN(parseFloat(ele))){
throw '数组中有不能转换为数字的元素'
}
}
@Baozi2
Baozi2 / gist:5c47446f895dff19242004951039126e
Created April 3, 2018 07:30
java将int转换为指定长度的hex不足的用0补齐
String.format("%08x", int);
8即为指定长度
@Baozi2
Baozi2 / gist:ba0d30e1eef5242664e709fbfe85762d
Created April 19, 2018 10:05
在ubuntu16.04上安装nginx
# ubuntu16.04 nginx安装
wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
deb http://nginx.org/packages/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/ubuntu/ xenial nginx
sudo apt-get update
sudo apt-get install nginx
vhost 实现多域名映射
upstream 实现反向代理
@Baozi2
Baozi2 / gist:14f38b125fc4ee5e7ed9cd818481e61d
Created April 28, 2018 03:47
rails 5.2 add a test task for lib directory
namespace :test do
task :lib => "test:prepare" do
$: << "test"
Rails::TestUnit::Runner.rake_run(["test/lib"])
end
end
@Baozi2
Baozi2 / gist:b04f65fc3d4abfdfa402e7c86af3da08
Created April 28, 2018 05:54
ruby gem faraday when request path /
如果设置了 prefix_url为 http://test.com/api
如果此时 get '/', { name: 1} 则请求路径会变为 http://test.com?name=1
@Baozi2
Baozi2 / gist:5a855cbfa2b9f461a736f87c2436df84
Created November 16, 2018 04:19
jquery ajax data content ?? make a JSONP
jQuery的ajax数据中含有??
此问题仅在 dataType指定为JSON,并且data为string是出现。解决办法,
1. 转移data
2. 使用object的data
3. 指定contentType
4. 不指定dataType
@Baozi2
Baozi2 / gist:12db8e49419c2b336c47e7d34d65d9a4
Last active January 14, 2019 08:07
ruby rake demo 定义 依赖、参数、参数和依赖
desc 'when run `rake` a task name default is run by default '
task :default do
p 'I’m default'
end
desc 't0 task name 可以是 symbol或string'
task 't0' do
p 't0'
end
@Baozi2
Baozi2 / gist:14e13d339c6be9551c01b46e2d75d44e
Created August 10, 2021 04:13
rails set default value for jsonb
```
def change
create_table :test do |t|
t.jsonb :names, default: []
t.jsob :profil, default: {}
t.timestamps
end
```