Coder Social home page Coder Social logo

blog's People

Contributors

21paradox avatar

Watchers

 avatar  avatar  avatar

blog's Issues

好用的git看diff工具

https://www.npmjs.com/package/diff2html-cli

diff2html -s side -o preview -- -M HEAD~5
查看最近5次提交的diff

git show 4f6a7913c9b6bd2462c5b4b15053841d4e707dd6 | diff2html -s side -i stdin
查看某个 commit 的 改动

git show 4f6a7913c9b6bd2462c5b4b15053841d4e707dd6 -- src/* | diff2html -s side -i stdin
查看 src下文件夹的改动

git diff 7bd48^..1f62d -- src/* | diff2html -s side -i stdin
查看diff between commits

koa简单的proxy http请求方法

    app.get(/^\/mirrors(?:\/|$)/, function* () {

        var remote = yield urllib.request(cfg.mirrorsUrl+ this.path, {
            streaming: true,
        });

        var res = remote.res;

        if (res.headers && res.headers['content-type']) {
            this.type = res.headers['content-type'];
        }

        this.body = res;
    });

js格式化RMB

const cnNums = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
const pos4OccurMap = {
  1: '',
  2: '万',
  3: '亿',
};
const Zero = '零';

function fmtNum(numStr) {
  let StrTxt = '';
  let pos4Occur = 0;

  const prependTxt = (a) => {
    StrTxt = a + StrTxt;
  };

  for (let indexFromLast = 0; indexFromLast < numStr.length; indexFromLast++) {
    const curIndex = numStr.length - 1 - indexFromLast;
    const curItem = numStr[curIndex];
    const pos4 = indexFromLast % 4;

    if (pos4 === 0) {
      pos4Occur += 1;
    }

    const fmtNormal = (name) => {
      const nextItem = numStr[numStr.length - indexFromLast];
      if (parseInt(curItem) === 0) {
        if (parseInt(nextItem) !== 0) {
          prependTxt(Zero);
        }
      } else {
        prependTxt(cnNums[curItem] + name);
      }
    };

    switch (pos4) {
      case 0: {
        if (curItem !== '0') {
          prependTxt(cnNums[curItem] + pos4OccurMap[pos4Occur]);
        } else if (
          numStr[curIndex] === '0'
            && numStr[curIndex - 1] === '0'
            && numStr[curIndex - 2] === '0'
            && numStr[curIndex - 3] === '0'
        ) {
          if (typeof numStr[curIndex + 1] !== 'undefined' && numStr[curIndex + 1] !== '0') {
            prependTxt(Zero);
          }
        } else {
          prependTxt(pos4OccurMap[pos4Occur]);
        }
        break;
      }
      case 1: {
        fmtNormal('拾');
        break;
      }
      case 2: {
        fmtNormal('佰');
        break;
      }
      case 3: {
        fmtNormal('仟');
        break;
      }
      default:
        break;
    }
  }
  return StrTxt;
}

function fmtDecimal(numStr, showZero) {
  if (numStr.length === 0) {
    return '';
  }
  if (numStr.length === 1) {
    return `${cnNums[numStr[0]]}角`;
  }

  let desTxt = '';
  if (numStr[0] === '0') {
    if (showZero === true) {
      desTxt += Zero;
    }
  } else {
    desTxt += `${cnNums[numStr[0]]}角`;
  }
  if (numStr[1] !== '0') {
    desTxt += cnNums[numStr[1]];
    desTxt += '分';
  }
  return desTxt;
}

function toRmb(a) {
  const [partInt = '', partDes = ''] = a.split('.');
  if (parseInt(partInt, 10) === 0 && parseInt(partDes, 10) === 0) {
    return '零元整';
  }
  if (partInt === '0' && partDes) {
    return fmtDecimal(partDes, false);
  }
  if (!partDes || parseInt(partDes, 10) === 0) {
    return `${fmtNum(partInt)}元整`;
  }
  return `${fmtNum(partInt)}${fmtDecimal(partDes, true)}`;
}

module.exports = toRmb;

ntp时间同步

ntpdate -d -B -t 5 -4 "114.114.114.114" ntp1.aliyun.com

指定dns 和阿里云服务器

COUNT DISTINCT by conditions

CREATE TABLE t_table (
  P_Id int NOT NULL AUTO_INCREMENT,
  color VARCHAR(50),
  type VARCHAR(50),
  PRIMARY KEY (P_Id)
);

INSERT INTO t_table (color, type) VALUES ('YELLOW', 'q');
INSERT INTO t_table (color, type) VALUES ('YELLOW', 'w');
INSERT INTO t_table (color, type) VALUES ('BLUE', 'w');
INSERT INTO t_table (color, type) VALUES ('BLUE', 'r');
INSERT INTO t_table (color, type) VALUES ('BLUE', 'w');
INSERT INTO t_table (color, type) VALUES ('RED', 'f');
INSERT INTO t_table (color, type) VALUES ('RED', 'e');;
SELECT
  SUM(IF(color = 'YELLOW', 1, 0)) AS YELLOW,
  SUM(IF(color = 'BLUE', 1, 0)) AS BLUE,
  SUM(IF(color = 'RED', 1, 0)) AS RED,
  COUNT(DISTINCT color) AS colorc,
  COUNT(DISTINCT CASE WHEN color = 'BLUE' THEN type END) AS typec  
FROM t_table

http://sqlfiddle.com/#!9/9d305/4

supervisor 使用

指定进程数量启动不同端口的服务,这个会启动 7000,7001,7002,7003,7004 这几个端口

[program:platform1]
command=node test.js --PORT=70%(process_num)02d
numprocs=5
process_name=%(process_num)02d

Ramda处理异步

function resolver() {
  
  var cbCurry;

  var take = function(_cb1) {
    cbCurry = R.curry(2, _cb1);
  }

  return {
    resolve: function(...args) {
      cbCurry = cbCurry(...args)
    },
    take: take
  }
}


var re = resolver();


re.take(function(a, b) {


})


re.resolve('aaa');
re.resolve(__, bbb);
 

knex example

var Knex = require('knex');


function createTable() {

  var knex = Knex({
    client: 'sqlite3',
    connection: {
      filename: "./sqlite.db"
    }
  });

  knex.schema.createTable('users', function (table) {
    table.increments('id').primary();
    table.string('name', 100);
    table.timestamps();

    table.json('extra_info');
  })

    .createTable('strategy', function (table) {
      table.increments('id').primary();
      table.string('name', 100);
      table.timestamps();

      table.json('extra_info');
      table.integer('user_id').unsigned().references('users.id');
    })

    .then(function () {

      return knex.transaction(function (trx) {

        let ins1 = {
          name: 'swz',
          extra_info: JSON.stringify({
            a: 1,
            b: 2,
            c: 3
          }),
          created_at: new Date(),
          updated_at: new Date()
        }

        knex('users')
          .transacting(trx)
          // .returning([
          //   'id',
          //   'name',
          //   'extra_info'
          // ])
          .insert(ins1)

          .then(function (row) {

            return knex('strategy').insert({
              name: 'st1',
              extra_info: JSON.stringify({
                a: 1,
                b: 2,
                c: 31
              }),
              user_id: row[0],
              created_at: new Date(),
              updated_at: new Date()
            })

            .transacting(trx)
          })

          .then(function(e) {

            trx.commit(e);
            console.log('commit' , e)
          })
          .catch(function(e) {
            console.log('rollback', e);
            trx.rollback(e);
          });

      });
    })

    .then(function () {
      console.log('do select');

      return knex('users')
        .join('strategy', 'users.id', '=', 'strategy.user_id')
        .select('*')

        .then(function (rows) {

          console.log(rows);
          return rows
        })
    })

    .then(function () {
      console.log('done');
    })

    .catch(function (e) {
      console.log(e, 'ee');
    });

}




module.exports = {
  createTable
}


if (require.main === module) {
  createTable();
}

vagrant

Setup modern.ie vagrant boxes

Since modern.ie released vagrant boxes, it' no longer necessary to manually import the ova file to virtualbox, as mentioned here.

However, the guys at modern.ie didn't configured the box to work with WinRM. This how-to addresses that, presenting steps to proper repackage these boxes, adding WinRM support. Additionally configures chocolatey package manager and puppet provisioner.

Pre-requisites

The host machine must have Vagrant and VirtualBox installed.

1. Configure the Vagrantfile

The same Vagrantfile can be used with different versions of modern.ie available boxes. Read the comments in the file for details.

# -*- mode: ruby -*-
# vi: set ft=ruby :

# box name into env var, same script can be used with different boxes. Defaults to win7-ie11.
box_name = box_name = ENV['box_name'] != nil ? ENV['box_name'].strip : 'win7-ie11'
# box repo into env var, so private repos/cache can be used. Defaults to http://aka.ms
box_repo = ENV['box_repo'] != nil ? ENV['box_repo'].strip : 'http://aka.ms'

Vagrant.configure("2") do |config|
  # If the box is win7-ie11, the convention for the box name is modern.ie/win7-ie11
  config.vm.box = "modern.ie/" + box_name
  # If the box is win7-ie11, the convention for the box url is http://aka.ms/vagrant-win7-ie11
  config.vm.box_url = box_repo + "/vagrant-" + box_name
  # big timeout since windows boot is very slow
  config.vm.boot_timeout = 500

  # rdp forward
  config.vm.network "forwarded_port", guest: 3389, host: 3389, id: "rdp", auto_correct: true

  # winrm config, uses modern.ie default user/password. If other credentials are used must be changed here
  config.vm.communicator = "winrm"
  config.winrm.username = "IEUser"
  config.winrm.password = "Passw0rd!"

  config.vm.provider "virtualbox" do |vb|
    # first setup requires gui to be enabled so scripts can be executed in virtualbox guest screen
    #vb.gui = true
    vb.customize ["modifyvm", :id, "--memory", "1024"]
    vb.customize ["modifyvm", :id, "--vram", "128"]
    vb.customize ["modifyvm", :id,  "--cpus", "2"]
    vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]
  end
end

2. Setup

Create a directory and a Vagrantfile file with the contents from previous section. For the first run, uncomment the vb.gui=true line to disable VirtualBox headless mode. Start the box running the command:

# uncomment below to change the box version and repo
# export box_name=win7-ie11 && export box_repo=http://aka.ms
$ vagrant up

When the machine is booted, do the following steps on VirtualBox guest window:

@echo off
set WINRM_EXEC=call %SYSTEMROOT%\System32\winrm
%WINRM_EXEC% quickconfig -q
%WINRM_EXEC% set winrm/config/winrs @{MaxMemoryPerShellMB="300"}
%WINRM_EXEC% set winrm/config @{MaxTimeoutms="1800000"}
%WINRM_EXEC% set winrm/config/client/auth @{Basic="true"}
%WINRM_EXEC% set winrm/config/service @{AllowUnencrypted="true"}
%WINRM_EXEC% set winrm/config/service/auth @{Basic="true"}
  • At this time the up command will be probably verifying if the guest booted properly. Since you just configured WinRM, the command should terminate successfully.

3. Chocolatey and Puppet

Run the following script to configure chocolatey and puppet on the guest machine:

@echo off
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
choco install -y puppet

4. Package

Since there's a lot of Windows specific configuration, you can include the Vagrantfile in the package command so winrm and virtualbox configuration get's default values when the repackaged is used for other purposes. Remember to run the command in the same directory the Vagrantfile resides:

$ vagrant package --output "yourboxname" --Vagrantfile Vagrantfile

After that you're all set!

在aws上用k8s上搭建jenkins

本文主要介绍
1、k8s初步体验(minikube)
2、在aws上配置k8s集群
3、安装helm服务,安装可视化kubeapps管理工具
4、安装jenkins mysql, confluence 等常见服务
5、设置aws的gp2磁盘为动态可扩容
6、配置jenkins ,能够动态使用k8s创建agent,进行git构建

rsync 服务架设

新建
/etc/rsyncd.conf

use chroot = false
[release_pkg]
   path = /var/jenkins
   comment = release
   read only = yes
   list = yes
   exclude =   .npm/  .ssh/

然后

rsync --daemon --config=/var/temp/rsyncd.conf --log-file=/var/temp/out.log --port=8881

rsync -av --progress rsync://1xx.xx.xx.xx:8881/release_pkg ./down

python环境安装

mac版本的python环境安装

使用 https://github.com/yyuu/pyenv pyenv 作为安装工具

$ brew install pyenv

After installation, you'll still need to add eval "$(pyenv init -)" to your profile (as stated in the caveats). You'll only ever have to do this once.

就可以同时使用python 2.7和3.3了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.