ruan4261

Public Snippets 19

About CCP

## Summary

If you go as extreme and as fanatic as CCP, then you are CCP.
Communism is never a group of people limit to certain region, sharing specific outlook or calling every strange "brother and sister", it was an idea to unify the goal and maybe even dream of every living being, exhausting all available resources to achieve the so called utopia.
Once the ideas of "something must be eliminated", "some people must be educated", "everyone need to fight towards the same goal" start growing with

weaver-micro-devkit2.0开发计划

- [ ] ArrayUtils 支持多数组合并
- [ ] ActionHandler 中的 log 改为非 final
- [ ] 自增量控制器
- [ ] ActionHandler 中新增复选框转换字符串函数 1,2,3 => A, B, C (可自定义分隔符)
- [ ] StringUtils 中的 toString 函数中的分隔符逻辑存在缺陷
- [ ] LogEventProcessor 打印模式优化
- [ ] 前缀后缀补充字符串函数(PadLeft / PadRight)

Oracle数据库操作

-- Replace ${} with your text

-- Compare the structure of two tables
-- Pay attention to the case of the table name
select v1.table_name,v2.table_name, v1.column_name,v2.column_name,
v1.data_type,v2.data_type,v1.data_length,v2.data_length ,v1.data_precision,v2.data_precision,v1.data_scale,v2.data_scale
from
(select * from user_tab_columns where table_name='${table_A}') v1 left join
(select * from user_tab_columns where table_name='${table_B}') v2 on v1.column_name=v2.column_name

-- Query from 

简化idea实现方式

# The easy implementation for your ideas.

## Drawing

1. ### [Nvidia Canvas](https://www.nvidia.com/en-gb/studio/canvas/)

   #### Desc
   ![](https://cdn.cacher.io/attachments/u/3dtcd0cdx53p2/wXjOI-PN6G0cCs2vkPldAH6U_bHvAdRH/qvzc7j5jt.png)  
   Nvidia 公司推出的一个人工智能照片编辑软件,可以免费下载。用户只要选择要添加的对象(比如云彩),在对应的位置上涂抹几笔,就能够自动生成照片。

   #### Ref
   - https://www.ruanyifeng.com/blog/2021/07/weekly-issue-165.html

2. ### [calligrapher.ai](https://www.calligrapher.ai/)
  
   #### Desc
   自动生成英文字符串的手写动画,可以定制各种参数。

isStringEmpty.js

/**
 * Only for String and ArrayLike.
 * Return false if parameter is an object.
 *
 * @return {boolean}
 */
function isEmpty(obj) {
  return (
    obj === undefined ||
    obj === null ||
    Number(obj.length) === 0 ||
    (typeof obj === "string" && obj.trim().length === 0)
  );
}

Ecology前端代码集合

/**
 * 获取表单页面中指定明细表所有行数据的索引
 *
 * @param detailIndex 明细表索引是对于当前流程而言的, 与模板无关(同一个明细表在不同节点模板内拥有相同的索引)
 */
function getCheckNodeIndexSeq(detailIndex) {
  var key = "check_node_" + detailIndex;
  var jqSeq = jQuery('[name="' + key + '"]');
  var idxSeq = [];
  for (var i = 0; i < jqSeq.length; i++) {
    idxSeq[i] = jqSeq[i].value;
  }
  return idxSeq;
}

getUrlParams.js

function getUrlParams() {
  var query = location.search// from ? to #
  var params = {}
  if (query.length > 1) {
    var queryStr = query.substr(1)
    var entry = queryStr.split('&')
    for (var i = 0; i < entry.length; i++) {
      var kv = entry[i].split('=')
      var key = kv[0]
      var value = kv[1]// maybe undefined
      params[kv] = value
    }
  }
  return params
}

english note

# Words
**Reference**
> 欧路词典, 沪江小D辞典, 谷歌翻译, 剑桥辞典, 百度翻译等

**Template**
> | 英文(缩写) | 中文 | 词性 | 美音 | 英音 |
> | -- | -- | -- | -- | -- |

## 2021
### May
#### Day12
| 英文(缩写) | 中文 | 词性 | 美音 | 英音 |
| -- | -- | -- | -- | -- |
| evaluation | 评估; | n. | /ɪˌvæljuˈeɪʃn/ | /ɪˌvæljuˈeɪʃn/ |

#### Day13
| 英文(缩写) | 中文 | 词性 | 美音 | 英音 |
| -- | -- | -- | -- | -- |
| literal | 字面意义的; 字面量; | adj. | /ˈlɪtərəl/ | /ˈlɪtərəl/ |
| scene | 场景; 事件; (尤指不愉快事件发生的)地点; | n. | /siːn/ | /siːn/ |
| sense | 感觉; 感官; 意识; | n. | /sens

Dynamic Hierarchical Classloader

# Dynamic Hierarchical Classloader(动态分级加载器)
## 技术攻坚点
1. 加载器动态委派, 分级
2. 命名空间适配(目前想法是重写ProxyGenerator生成继承同命名空间类, 问题在于final类无法通过加载器校验)

## Features
- 上传class文件, 存放文件夹并加载
- 上传java文件编译, 自动存放文件夹(最后再考虑)

排列组合公式

// Arrangement or Permutation
int P(int n, int m) {
  int res = 1;
  int limit = n - m;
  while (n > limit) {
    res *= n--;
  }
  return res;
}

// Combination
int C(int n, int m) {
  m = Math.min(m, n - m);
  int res = P(n, m);
  while (m > 0) {
    res /= m--;
  }
  return res;
}

模板_反转整数

public int rev(int x) {
  int res = 0;
  while (x > 0) {
    int mod = x % 10;
    x /= 10;
    res = res * 10 + mod;
  }
  return res;
}

dynamic import javascript

window.dynamic_import_javascript = function(url, text, type, frameWindow){
  frameWindow = frameWindow || window
  var doc = frameWindow.document
  var container = frameWindow.document.head || frameWindow.document.body
  var newEle = doc.createElement('script')
  if (url)
    newEle.src = url
  if (text)
    newEle.appendChild(document.createTextNode(text))
  newEle.type = type || 'text/javascript'
  container.append(newEle)
}

linux mean

## 常用
- ls: list
- cd: change directory
- su: switch user
- pwd: print work directory
- ps: process status
- lsof: list open file
- df: disk free
- du: disk usage
- rm: remove
- cat: concatenate
- ln: link
- man: manual
- touch: touch (用于修改文件时间属性)
- uname: unix name
- mv: move
- cp: copy
- nohup: no hang up
- fg: foreground (将后台命令放到前台执行)
- bg: background (将前台命令放到后台执行)
- chown: change owner
- chgrp: change group
- chmod: change mode

## 非常用
- mkfs: make file system
- fsck: file system check
- ins

ProxyGenerator重点方法

一个`ProxyGenerator`实例代表一个代理类  

`ProxyGenerator`实例中重要的属性
```java
  /** 保存所有接口的方法, key为方法签名, value中位不同返回值的同签名方法 */
  Map<String, List<ProxyMethod>> proxyMethods;
  
  /** 保存最终的字段信息, 每一个元素会生成一个实例字段 */
  List<FieldInfo> fields;
  /** 保存最终的方法信息, 每一个元素会生成一个实例方法 */
  List<MethodInfo> methods;
```

0. `#generateClassFile()`
   > 生成入口, 返回代理类字节码  
   > **步骤**
   > 1. 通过`#addProxyMethod(Method, Class)`注册`hashCode`, `equals`, `toString`方法
   > 2. 通过`#addProxyMethod(Method, Class)`循环注册每个接口的每个方法
   > 3. 对所有注册

The fastest way to exchange binary values.

/**
 * better
 */
function(a, b) {
  a = a ^ b
  b = a ^ b
  a = a ^ b
}

/**
 * standard
 */
function(a, b) {
  var temp = a
  a = b
  b = temp
}

模板_快速幂

// 不能输入负数参数
long binaryPow(long base, long exponent) {
  long res = 1;
  while (exponent > 0) {
    if ((exponent & 1) == 1) res *= base;
    base *= base;
    exponent >>= 1;
  }
  return res;
}