2 minute read

Tags: , , , , , , , , , , ,

Javascript


jexcel CE

class Jexcel extends React.Component {
    constructor(props) {
        super(props);
        this.options = props.options;
    }

    componentDidMount = function() {
        this.el = jexcel(ReactDOM.findDOMNode(this).children[0], this.options);
    }

    addRow = function() {
        this.el.insertRow();
    }

    render() {
        return (
            <div>
                <div></div><br/><br/>
                <input type='button' value='Add new row' onClick={() => this.addRow()}></input>
            </div>
        );
    }
}

var options = {
    data:[[]],
    minDimensions:[10,10],
};

ReactDOM.render(<Jexcel options={options} />, document.getElementById('spreadsheet'))

ESLint Warning “Function declared in a loop contains unsafe references to variable(s)…no-loop-func”

After I did some reserch, I found in this post, JSHint error : Functions declared within loops referencing an outer scoped variable may lead to confusing semantics, mentioned that JSHint doesn’t like how the anonymous function in there is being re-created over and over.

I changed forEach arrow function to for (let index i = 0; index < someInputs.length; index++), and the warning is gone.

Perhaps in your case, change setTimeout to traditional non-arrow function can remove the warning.

moment() get timestamp

moment().toDate().getTime()
  • parse utc format

    • moment().utc().format()

regex

  • /.+/g
    • So the difference between /.+/g and /.+/ is that the g version will find every occurrence instead of just the first.




DB


Add constraint

alter table public.TABLE ADD CONSTRAINT TABLE_UN UNIQUE ("name", "id");

Find Duplicated value in one column

select p.number,
       count(p.number)
from product p
group by p.number
having count(p.number) > 1;
select p.number,
       count(p.number),
       p.id ,
       count(p.id )
from product p
group by 
    p.number,
    p.id 
having 
    count(p.number) > 1 and 
    count(p.id ) > 1;

Postgres: Find last query executed by specific session in PostgreSQL database

select pid,
       usename as username,
       datname as database_name,
       query,
       application_name,
       backend_start,
       state,
       state_change
from pg_stat_activity
where pid = 'chosen_session';
  • pg_stat_activity 在 pg_catalog schema
select  * from pg_catalog.pg_stat_activity psa where psa.pid = '168292'




CI/CD


Gitlab Auto CI/CD




K8S


kubeapps

App Deployments

主要要運行的東西在Deployments中

對外需要Ingress 與 Service

  • 傳輸流
    • Loadbalancer Ingress(with IP) -> Ingress -> Service -> Pod
  • 重點
    • kubectl create namespace xxxx
    • Ingress annotations中 必須加
      • kubernetes.io/ingress.class: "nginx"
      • kubernetes.io/tls-acme: "true"
    • Ingress要能夠有SSL的話, 必須指定secret name, Cert-bot那邊會自動產生名為 ${servicename}-${tls} 的secret
    • Ingress 的 Rule 與TLS的 host 都必須打上需要的doamin name
  • Deployments
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: hasura
    hasuraService: custom
  name: hasura
  namespace: hasura
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hasura
  template:
    metadata:
      labels:
        app: hasura
    spec:
      containers:
      - image: hasura/graphql-engine:v1.3.3
        imagePullPolicy: IfNotPresent
        name: hasura
        env:
        - name: ENV_NAME
          value: "value"
        ports:
        - containerPort: 8080 
          protocol: TCP
        resources: {}
  • Service
apiVersion: v1
kind: Service
metadata:
  labels:
    app: hasura
  name: production-auto-deploy
  namespace: hasura
spec:
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  selector:
    app: hasura
  type: ClusterIP
  • Ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  namespace: hasura
  name: production-auto-deploy
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "true"
spec:
  rules:
  - host: hasura.lol.app
    http:
      paths:
      - path: /
        backend:
          serviceName: production-auto-deploy
          servicePort: 80
  tls:
  - hosts:
    - hasura.lol.app
    secretName: production-auto-deploy-tls

Helm

Istio




其他


OPC UA & Modbus

Imgur

Imgur

DNC & LSV/2

webhooks