text:
# json-sql-builder2

Levelup your Queries with `json-sql-builder2`.

# Table of Content

- [Why to use json-sql-builder2](#why-to-use-json-sql-builder2)
- [Supported SQL-Dialects](#supported-sql-dialects)
- [Documentation](#documentation)
- [Getting Started](#getting-started)
  - [Install](#install)
  - [First Example](#first-example)
  - [Setup SQLBuilder](#setup-sqlbuilder)
  - [Support different Data Types](#support-different-data-types)
  - [Using Keywords](#using-keywords)
  - [More Examples](#more-examples)
  - [Working with SQL-Functions](#working-with-sql-functions)
- [Writing new Helpers and Operators](#writing-new-helpers-and-operators)
  - [What are the differences between Operators and Helpers?](#what-are-the-differences-between-operators-and-helpers)
  - [Using a Template](#using-a-template)
    - [Example writing LEFT-Function Helper](#example-writing-left-function-helper)
    - [Understanding, Writing the Syntax](#understanding-writing-the-syntax)
      - [Sub-Syntaxing](#sub-syntaxing)
    - [Native js Function support - using SQLBuiler.CALLEE](#native-js-function-support---using-sqlbuilercallee)
    - [Dialect-Specific SQL-Parts](#dialect-specific-sql-parts)
  - [Concating iterateable Informations](#concating-iterateable-informations)
  - [BuiltIn Parameters](#builtin-parameters)
  - [More Examples writing new stuff](#more-examples-writing-new-stuff)
- [Tests](#tests)
- [Generating docs](#generating-docs)
- [License](#license)

# Why to use json-sql-builder2

You are working with javascript and got the power of json, so why do you concat string by string or worry about query parameters.
When you need to write dynamic queries defined by the user it is also much easier to use JSON instead of generating a string-based query.

Another point is that in most cases the readability and structuring the query is much better than using strings.

Working with the JSON DataType is also much easier (see JSON-Example below).

# Supported SQL-Dialects

By default `json-sql-builder2` supports the follwing languages.
- [x] MySQL
- [x] MariaDB
- [x] PostgreSQL
- [x] SQLite
- [x] Oracle
- [x] Microsoft SQL Server

# Documentation
Each Operator and Helper is well documented. And you've got a lot of examples for each.

For further details on each Helper or Operators have a look at the complete
documentation at [https://github.com/planetarydev/json-sql-builder2/tree/master/sql](https://github.com/planetarydev/json-sql-builder2/tree/master/sql) and search or browse through the directories.

# Getting Started

## Install

```sh
npm install jsonaql --save
```

## First Example

```javascript
const SQLBuilder = require('json-sql-builder2');
// create a new instance of the SQLBuilder and load the language extension for mysql
var sql = new SQLBuilder('MySQL');

// lets start some query fun
var totalSalary = sql.$select({
    job_title: true,
    total_salary: { $sum: 'salary' }
    $from: 'people',
    $where: {
        job_title: { $in: ['Sales Manager', 'Account Manager'] },
        age: { $gte: 18 },
        country_code: 'US',
    },
    $groupBy: 'job_title',
});

```

**Result**
```javascript
// totalSalary.sql
SELECT
    `job_title`,
    SUM(`salary`) AS `total_salary`
FROM
    `people`
WHERE
    `job_title` IN (?, ?)
AND `age` >= ?
AND `country_code` = ?
GROUP BY
    `job_title`

// totalSalary.values
['Sales Manager', 'Account Manager', 18, 'US']

```

## Setup SQLBuilder

By default you will create a new Instance of SQLBuilder by passing the language-dialect as String you would like to work with.

```javascript
const SQLBuilder = require('json-sql-builder2');
// Syntax:
// SQLBuilder(<dialect>[, options]);
//
// dialect: String | Function
// options: Object

// Setup a new instance for MySQL
var sql = new SQLBuilder('MySQL');

// Setup a new instance for MariaDB
var sql = new SQLBuilder('MariaDB');

// Setup a new instance for PostgreSQL
var sql = new SQLBuilder('PostgreSQL');

// Setup a new instance for SQLite
var sql = new SQLBuilder('SQLite');

// Setup a new instance for Oracle
var sql = new SQLBuilder('Oracle');

// Setup a new instance for SQLServer
var sql = new SQLBuilder('SQLServer');

// Passing a function as dialect param to setup your individual needs
var sql = new SQLBuilder(function(sql) {
    // set the name to one of the supported language-dialects
    sql.setLanguage('SQLServer');

    // set the left and right handed quoting character
    sql.setQuoteChar('[', ']');
    // if there the character is the same for left and right
    sql.setQuoteChar('`');

    // setup the placholder for each value pushed to the value-stack
    sql.placeholder = function() {
        return '@param' + sql._values.length;
    }

    // if neccessary turn the array of values to a object
    sql.transformValueResult = function(valuesAsArray) {
        let resultAsObj = {}
        sql.forEach(valuesAsArray, (value, index) => {
            resultAsObj['param' + index] = value
        });
        return resultAsObj;
    }
});
```

### Options

- `quoteIdentifiers` true | false (Default=false)

If this option is `true` each identifier will be quoted. If this option is set to `false` only invalid, unsafe identifiers will be quoted.

- `attachGlobal` true | false (Default=false)

This Option will attach each Operator like `$select` in uppercase `SELECT`, each callee like `left` in lowercase `$left` and each Keyword in uppercase letters to the `globals` Object, so you could write your code like:

```javascript
var sql = new SQLBuilder('SQLServer', {
    attachGlobal: true
});

let myQuery = SELECT({
    people_name: $concat($left($i('people.first_name'), 1), '. ', $i('people.last_name')),
    $from: 'people',
    $where: {
        job_title: $in(['Sales Manager', 'Account Manager']),
        last_name: $eq('Doe')
    }
});

// Results
// myQuery.sql
SELECT
    CONCAT(LEFT([people].[first_name], @param1), @param2, [people].[last_name]) AS [people_name]
FROM
    [people]
WHERE
    [job_title] IN (@param3, @param4)
AND [last_name] = @param5

// myQuery.values
{
    param1: 1,
    param2: '. ',
    param3: 'Sales Manager',
    param4: 'Account Manager',
    param5: 'Doe'
}

```

- `useOuterKeywordOnJoin` true | false

Have a look at the source of [/sql/helpers/queries/join/.joinhelper.js](./sql/helpers/queries/join/.joinhelper.js)

## Support different Data Types

Each Operator and Helper can be used with different Data Types, so it is easy to take the Type that fits your needs.
Have a look at the README.md for the Helpers, Operator you like to use. Each of them are well documented and the file
is located directly beside the source-code.

```javascript
myQuery = sql.$insert({
    $table: 'people',
    $columns: {
        first_name: true,
        last_name: true,
        age: true
    },
    $values: ['John', 'Doe', 40]
});

// is the same as:
myQuery = sql.$insert({
    $table: 'people',
    $columns: ['first_name', 'last_name', 'age'],
    $values: ['John', 'Doe', 40]
});

// is the same as:
myQuery = sql.$insert({
    $table: 'people',
    $documents: {
        first_name: 'John',
        last_name: 'Doe',
        age: 40
    }
});

// SQL output
INSERT INTO
    people (first_name, last_name, age)
VALUES
    ($1, $2, $3)

// Values
{
    "$1": "John",
    "$2": "Doe",
    "$3": 40
}
```

### Using Keywords

A complete List of all Keywords you will find at [./sql/keywords/](./sql/keywords/).

:bulb: **Exmple using Keyword DEFAULT**
```javascript
myQuery = sql.$insert({
    $table: 'people',
    $documents: {
        first_name: 'John',
        last_name: 'Doe',
        age: sql.DEFAULT
    }
});

// SQL output
INSERT INTO
    people (first_name, last_name, age)
VALUES
    ($1, $2, DEFAULT)

// Values
{
    "$1": "John",
    "$2": "Doe"
}
```

## More Examples

## Working with SQL-Functions

```javascript
myQuery = sql.$select({
    people_name: { $concat: ['~~first_name', ' ', '~~last_name'] },
    $from: 'people'
});

// instead using $concat helper as js-function is also possible
myQuery = sql.$select({
    people_name: sql.concat('~~first_name', ' ', '~~last_name'),
    $from: 'people'
});

// SQL output
SELECT
    CONCAT(first_name, $1, last_name) AS people_name
FROM
    people

// Values
{
    "$1": " "
}
```

:bulb: **PostgreSQL update jsonb column**
```javascript
myQuery = sql.$update({
    $table: 'people',
    $set: {
        'data->profile->firstName': 'John',
        'data->profile->lastName': 'Doe'
    },
    $where: {
        people_id: 456
    }
});

// SQL output
UPDATE
    "people"
SET
    "data" = jsonb_set(jsonb_set("data", $1, $2), $3, $4)
WHERE
    "people_id" = $5

// Values
{
    "$1": "{profile,firstName}",
    "$2": "\"John\"",
    "$3": "{profile,lastName}",
    "$4": "\"Doe\"",
    "$5": 456
}
```

# Writing new Helpers and Operators

## What are the differences between Operators and Helpers?
Any Operator can build a valid SQL result by it's own without additional stuff.
So each operator will be directly attached as `$<operator-name>` to the SQLBuilder instance.
That means you can directly call each Operator like:

```javascript

// standard build-call
let myQuery = sql.build({
    // using '$select'-Operator
    $select: {
        $from: 'people'
        // ...
    }
});

// '$select' is an Operator and so you can use this directly
let myQuery = sql.$select({
    $from: 'people'
});

// instead $from is a Helper
// and this could'nt be directly called like sql.$from({...})

```
## Using a Template

**A Template for writing new Helpers and Operators:**

Each Operator should be located in `/sql/operators/<operator-name/`.

Use the following template to create a new Operator.

```javascript
class <operator-name> extends SQLBuilder.[SQLOperator | SQLHelper] {
    constructor(sql){
        super(sql);

        // definition of allowed types and it's SQL Syntax
        // more details on writing your Syntax (see 'Define a new Syntax' below)
        this.Types({
            // simple Type-based Syntax
            // where Type is String, Number, Boolean, Primitive, Object, Array, Function
            [type]: { syntax: this.Syntax(...) },

            // simple type-based Syntax as iterateable with defined sub/item-types
            // type can be Object or Array
            [type]: {
                eachItemOf: {
                    // type can be String, Number, Boolean, Primitive, Object, Array, Function
                    <type>: { syntax: this.Syntax(...) }
                }
            }

            // type-value-based definitions:
            // type can be String, Number, Boolean
            [type]: {
                syntax: {
                    // List all values that are valid to use
                    // with the current Helper or Operator
                    [<value-1>: this.Syntax(...) [,<value-n>: ...]]
                }
            }

            // type-based, iterateable and value-ased restricted Syntax
            // type can be Object or Array
            [type]: {
                eachItemOf: {
                    // type can be String, Number, Boolean, Primitive, Object, Array, Function
                    <type>: {
                        syntax: {
                            // List all values that are valid to use
                            // with the current Helper or Operator
                            [<value-1>: this.Syntax(...) [,<value-n>: ...]]
                        }
                    }
                }
            }

        });

        // optional declaration of Keywords
        this.Keyword('<keyword>');

        // optional registration of private Helpers that are used inside the
        // Syntax declared above with this.Types({...})
        this.registerPrivateHelper('<helper-name>'); // the helper must be located in "./private/<helper-name>/<helper-name>.js"
        // or register your private helper by your own
        this.$<helper-name> = new <helperClass>(sql);
    }

    // optional function callee definition if the standard
    // callee - generated by Syntax - doesn't fit
    callee(/*args*/, identifier){
        // ...
        return sqlResultString;
    }

    // optional linker-method
    link(query, identifier){
        // ...
    }

    // optional preBuild-method
    preBuild(query, identifier) {
        // ...
        return query;
    }

    // optional postBuild-method
    postBuild(result, type, itemType){
        // ...
        return result;
    }
}

module.exports = {
    definition: <class-definition>,
    description: <String: a short description of the new Helper or Operator>,
    supportedBy: {
        // list all SQL-dialects that support this new Helper or Operator
        // SQL-dialect can be: MySQL, MariaDB, PostgreSQL, SQLite, Oracle, SQLServer
        <SQL-dialect>: <'' | url to official docs>
        [, <another SQL-dialect>: <'' | url to official docs>]
    },
    examples: {
        // write at minimum one Test "Basic Usage" for each Type of Syntax defined above
        // using the same structure as used by this.Types({...}) in the class constructor.
        // Additional Tests and Examples allways wellcome!

        // Example of a Test-Case for the Type "Object":
        Object: {
            "Basic Usage": function(sql) {
                return {
                    // if the test is restricted to special SQL dialects
                    [supportedBy: {
                        // list all dialects (MySQL, MariaDB, PostgreSQL, SQLite, Oracle, SQLServer)
                        // the Test is valid for
                        <SQL-dialect>: true
                    },]
                    test: function() {
                        return sql.build({
                            $select: {
                                $from: 'people'
                            }
                        });
                    },
                    expectedResults: {
                        sql: 'SELECT * FROM people',
                        values: {}

                        // List any SQL-dialect if the Result on Test is different to the generell Result
                        [,<SQL-dialect>: {
                            sql: <Result-String if there are different using a special SQL-dialect>
                            values: {
                                $1: ...
                                $2: ...
                            }
                        }]
                    }
                }
            }
            [, "<name of another Test>": function(sql){
                // ...
            }]
        }
    }
}
```

### Example writing LEFT-Function Helper

If there is something missing you can easily extend all your required stuff.

**If you will create a new Helper or Operator I would be glad if you will
contribute and share your magic stuff.**

The only thing you have to do is browse to the right place inside the `/sql/` directory
and create a new folder and file named with the Helper or Operator.

In our Example we will create the `LEFT()` SQL-Function.

This file will be located at `/sql/helpers/functions/string/`:
- create a new Folder `left`
- create a new File `left/left.js`

Here is the code you need to write for `left.js` using the Template:

```javascript
'use strict';

// give the new Class the name of the Helper or Operator
class left extends SQLBuilder.SQLHelper {
    constructor(sql){
        // always call the construtor of SQLHelper first
        super(sql);

        // declare the possible types that can be used
        this.Types({
            Number: { syntax: this.Syntax('LEFT(<key-ident>, <value-param>)') },
            Object: { syntax: this.Syntax('LEFT(<$str>, <$len>)', SQLBuilder.CALLEE) },
        });

        // add each Helper defined in the Syntax as private, predefined Helper
        this.$str = new SQLBuilder.SQLPredefined.StringValueParam(sql);
        this.$len = new SQLBuilder.SQLPredefined.NumberValueParam(sql);
    }
}

// export the new $left Helper
module.exports = {
    // exports the class-definition (this is used by SQLBuilder to setup the new Helper)
    definition: left,

    // add some description for the auto-generation of the docs README.MD
    description: `Specifies the \`LEFT\` function.`,

    // define the SQL-dialects that support this new Helper
    // Each dialect listed by supported by can use this Helper. If you pass a string
    // that starts with 'http://' or 'https://' inside the docs it automatically creates a link
    // to the official docs
    supportedBy: {
        MySQL: 'https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_left',
        MariaDB: 'https://mariadb.com/kb/en/library/left/',
        PostgreSQL: 'https://www.postgresql.org/docs/9.1/static/functions-string.html',
        // SQLite did not support the left() function at this time
        // Oracle did not support the left() function at this time --> instead we can use SUBSTR( string, start_position [, length ] ) defined as new SQLHelper
        SQLServer: 'https://docs.microsoft.com/en-us/sql/t-sql/functions/left-transact-sql'
    },

    // Always add at least "Basic Usage" as test and example for each type you
    // have declared by the new class using this.Types()
    examples: {
        Number: {
            // Basic Usage is the Name of the Test and must always declared as function(sql)
            // Parameter sql will be passed as instance of the SQLBuilder
            "Basic Usage": function(sql) {
                // the function always returns an Object {test: function() {}, expectedResults: {} [, supportedBy: { PostgreSQL: true, MySQL: true, ... }] }
                return {
                    // write your test and return always the result
                    test: function(){
                        return sql.$select({
                            firstname: { $left: 1 }
                        });
                    },
                    // define the expected results of the test with
                    // sql as String and values as Object. If there are no values expected, so define an empty Object like values: {}
                    expectedResults: {
                        sql: 'SELECT LEFT(first_name, $1) AS first_name',
                        values: {
                            $1: 1
                        }
                    }
                }
            }
        },
        Object: {
            // Basic Usage is the Name of the Test and must always declared as function(sql)
            // where sql is the instance of the SQLBuilder
            "Basic Usage": function(sql) {
                // the function always returns an Object {test: function() {}, expectedResults: {} [, supportedBy: { PostgreSQL: true, MySQL: true, ... }] }
                return {
                    // write your test and return always the result
                    test: function(){
                        return sql.$select({
                            test: { $left: { $str: 'Hello World', $len: 5 } }
                        });
                    },
                    // define the expected results of the test with
                    // sql as String and values as Object. If there are no values generated, so define an empty Object values: {}
                    expectedResults: {
                        sql: 'SELECT LEFT($1, $2) AS test',
                        values: {
                            $1: 'Hello World',
                            $2: 5
                        }
                    }
                }
            },
            // Optionally add some more Tests and Examples with a different name:
            "Usage of LEFT as Function": function(sql) {
                return {
                    test: function(){
                        return sql.$select({
                            // The helper can directly used as native js-function because
                            // we setup the Syntax for Type "Object" with SQLBuilder.CALLEE parameter as second (see above)
                            test: sql.left('Hello World', 5)
                        });
                    },
                    expectedResults: {
                        sql: 'SELECT LEFT($1, $2) AS test',
                        values:{
                            $1: 'Hello World',
                            $2: 5
                        }
                    }
                }
            }
        }
    }
}
```

### Understanding, Writing the Syntax

Every Helper or Operator will be defined by a Type, iterateable sub-Type and optionally value restrictions.
For each of this situation you have to support a valid Syntax, that will generate the
SQL-Result-String for the Helper or Operator.

**Example of SUBSTR-Syntax for Type Object**

```javascript
class substr extends SQLBuilder.SQLHelper {
    constructor() {
        ...
        this.Types({
            Object: { syntax: this.Syntax('SUBSTR(<$str> FROM <$start>{ FOR [$len]})', SQLBuilder.CALLEE) }
        }
        ...
    }
}
```

Okay, lets explain the *magic* stuff we have declared above.

By defining only the Type `Object` you can only use the `$substr` Helper like `first_name: { $substr: {...} }`.
If you try to use it with a Number-Value like `first_name: { $substr: 5 }` the SQLBuilder will throw an Error like `Type Number is not allowed by Syntax`.

In our case we define two required Parameters (or better say Helpers). The first one is `<$str>` and the second one is `<$start>`.
The third `[$len]` Helper is optional. With this informations we could write the following examples:

```javascript
let myQuery = sql.$select({
    test: { $substr: { $str: 'Hello World', $start: 3 } }
});

// SQL-Output
SELECT
    SUBSTR($1 FROM $2) AS test
```

#### Sub-Syntaxing

In most cases of SQL there are optional parts that also include keywords. In our Example of the SUBSTR Function it's the `FOR` option
that specifies the length of the substring. So we need a *Sub-Syntax* that will only be generated when the Helper inside is supported.
The *Sub-Syntax* is defined by using curly braces like `{ FOR [$len]}`.

Sometimes it's quite usefull to use a Helper as native js-Function like `test: sql.substr('Hello World', 3)`, so
you can specifiy one Syntax per Helper or Operator as callee by adding an optional parameter to the Syntax-Function `SQLBuiler.CALLEE`.
This option will automatically turn the Syntax into a native js-function located on the current instance of the SQLBuilder.
In our case the Syntax of the Function will be: `sql.substr(<str>, <start> [, options])` where **options** is an Object that could take all
optional Helpers defined by the Syntax.

**Example**
```javascript
let myQuery = sql.$select({
    test: sql.substr('Hello World', 3, {
        $len: 5
    })
});

// SQL-Output
SELECT
    SUBSTR($1 FROM $2 FOR $3) AS test
```

### Write an individual callee**

Sometimes the auto generated callee does not fit our rules, so you can easily write your own callee by adding a method named `callee` to the new Helper class.
In this case you could define each Function-Parameter by your own and add code to build the SQL-Result.
Just a small Example how the substr-callee can look like.

**Example**
```javascript
class substr extends SQLBuilder.SQLHelper {
    constructor() {
        ...
        this.Types({
            Object: { syntax: this.Syntax('SUBSTR(<$str> FROM <$start>{ FOR [$len]})') } // remove this param: , SQLBuilder.CALLEE) }
        }
        ...
    }

    // add our own callee method
    callee(str, start, len, identifier /*identifier will always be injected by SQLBuilder as last argument*/) {
        // the callee-method will be executed
        // in the context (this) of the current SQLBuilder instance
        // !!! **this** is NOT the context of this class-Object
        // so you have access to all useful methods of the SQlBuilder like:
        // - isString(), isNumber() ...
        // - isMySQL(), isPostgreSQL(), ...
        // - quote(), addValue(), isCurrent(), isPreviousHelper(), ...
        let sqlResult = 'SUBSTR(';

        // check types
        if (!this.isString(str) || !this.isNumber(start) || (len && !this.isNumber(len))) {
            throw new Error('Using sql.substr failed because of wrong parameter type. Syntax is: sql.substr(str, start[,len])');
        }

        sqlResult += this.addValue(str) + ' FROM ' + start // we dont add start as parameter and put it directly into the SQL string //this.addValue(start);
        if (len) {
            sqlResult += ' FOR ' + len;
        }
        sqlResult += ')'

        return sqlResult;
    }
}

...

// Using our new selfmade CALLEE
let myQuery = sql.$select({
    test: sql.substr('Hello World', 3, 5)
});

// SQL-Output
SELECT
    SUBSTR($1 FROM 3 FOR 5) AS test
```

### Dialect-Specific SQL-Parts

About 70% or 80% of all SQL comply with the ANSI SQL-Standard. So you can write code for each Helper and Operator for each SQL-dialect or
you can add your specific Helper-Syntax as dialect-specific expression.

**Example**

```javascript
SELECT
    { [$top]}-->(SQLServer)
    { DISTINCT[$distinct]}
    { SQL_CALC_FOUND_ROWS[$calcFoundRows]}-->(MySQL,MariaDB)

    { <$columns>}
        { [$into]}-->(MySQL,MariaDB,SQLServer)

    { FROM [$from]}    { [$join]}
    { WHERE [$where]}
    { GROUP BY [$groupBy]}
        { WITH ROLLUP[$withRollup]}-->(MariaDB,MySQL)
    { HAVING [$having]}
    { ORDER BY [$orderBy]}
    { LIMIT [$limit]}-->(MariaDB,MySQL,PostgreSQL,SQLite)
    { OFFSET [$offset]}-->(MariaDB,MySQL,PostgreSQL,SQLite)
```

The Example shows the current Syntax of the `SELECT` Statement. Here you can see some
dialect-specific Helpers marked with `-->(<sql-dialect>[,<sql-dialect>,...])`.

So, if you are running SQLBuilder with PostgreSQL the `$info` Helper for the ` INTO ` clause
is only supported by MySQL, MariaDB and SQLServer. If you write `$select: { $from: 'people', $into: ... }`
the SQLBuilder will throw an Error that `$into Helper is not permitted by Syntax`.

### Concating iterateable Informations

Sometimes you need to define an Array of columns or an Object with column-identifiers and they all need to
concatenated by comma with the previouse one. To archive this you can specifiy a concatination-String or Joiner.

Let's build a part of the `$columns` Helper from the `$select` Operator.

```javascript
let myQuery = sql.$select({
    $columns: {
        first_name: true,
        last_name: true,
        ...
    }
})

// SQL-Output
SELECT
    first_name,
    last_name,
    ...

// This is the definition of the $columns Helper.
// Have a look at the joiner "[ , ... ]" inside the Syntax.
class columns extends SQLBuilder.SQLHelper {
    constructor(sql){
        super(sql);

        this.Types({
            Object: {
                // Here we have a iterateable...
                eachItemOf: {
                    // ...where each value should have one of the
                    // following types listed:
                    Boolean: {
                        syntax: {
                            true: this.Syntax('<key-ident>[ , ... ]'),
                            false: this.Syntax('')
                        }
                    },
                    Number: {
                        syntax: {
                            1: this.Syntax('<key-ident>[ , ... ]'),
                            0: this.Syntax('')
                        }
                    },
                    String: { syntax: this.Syntax('<key-ident> AS <value-ident>[ , ... ]') },
                    Object: { syntax: this.Syntax('<value> AS <identifier>[ , ... ]') },
                    Function: { syntax: this.Syntax('<value> AS <key-ident>[ , ... ]') }
                }
            },
            Array: {
                eachItemOf: {
                    String: { syntax: this.Syntax('<value-ident>[ , ... ]') },
                    Object: { syntax: this.Syntax('<value> AS <key-ident>[ , ... ]') }
                }
            },
            String: { syntax: this.Syntax('<value-ident>') }
        });
    }
}

// Joiner [ , ... ] explained:
// Each joiner has this style: "[ <joiner-def>... ]"
// ! note of the space chars >---^---------------^
```

Every time the Syntax includes such a declaration the SQLBuilder extracts the joiner-definition and concatenates each item with this string-definition.

Another Example of a joiner-Definition you will find at `/sql/helpers/locical/and/and.js` which is a Helper that is used by the $where Helper.
The joiner is defined as `[  AND ... ]`.

### BuiltIn Parameters

Each Syntax can take - so called BuiltIn-Params - to interact with the JSON-Data. For this
you have to following parameter definitions you could use inside each Syntax:

- `<key>`, `<key-ident>` or `<key-param>`
- `<value>`, `<value-ident>` or `<value-param>`
- `<identifier>`

`<key>`, `<value>`:

Native replacement for the Objects Key (or Index when using an Array) and replacement for the value of an Item.
```javascript
class columns extends... {
    ...
    this.Types({
        Object: {
            eachItemOf: {
                String: { syntax: this.Syntax('<key> AS <value>') }
            }
        }
    });
    ...
}

let myQuery = sql.$select({
    $columns: {
        my_key: 'my_string_value'
    }
})

//SQL-Output
SELECT
    my_key AS my_string_value
```

`<key-ident>`, `<value-ident>`:

Safely quoted replacement for the Objects Key (or Index when using an Array - does not really make sense :-) ) and replacement for the value of an Item.
```javascript
class columns extends... {
    constructor(){
        ...
        this.Types({
            Object: {
                eachItemOf: {
                    String: { syntax: this.Syntax('<key-ident> AS <value-ident>') }
                }
            }
        });
        ...
    }
}

let myQuery = sql.$select({
    $columns: {
        my_key: 'my_string_value',
        'my_schema.my_table.my_col': 'my_test_alias'
    }
})

//SQL-Output for PostgreSQL
SELECT
    "my_key" AS "my_string_value",
    "my_schema"."my_table"."my_col" AS "my_test_alias"

//SQL-Output for MySQL
SELECT
    `my_key` AS `my_string_value`,
    `my_schema`.`my_table`.`my_col` AS `my_test_alias`

//SQL-Output for SQLServer
SELECT
    [my_key] AS [my_string_value],
    [my_schema].[my_table].[my_col] AS [my_test_alias]
```

`<key-param>`, `<value-param>`

Parameterized Key and Value replacement where the value itself is pushed to the value-stack.

```javascript
class left extends... {
    constructor(){
        ...
        this.Types({
            Number: { syntax: this.Syntax('<key-ident> AS <value-param>')
        });
        ...
    }
}

let myQuery = sql.$select({
    $columns: {
        first_name: { $left: 1 }
    }
})

//SQL-Output for PostgreSQL
SELECT
    LEFT("first_name", $1) AS "first_name"

//SQL-Output for MySQL
SELECT
    LEFT(`first_name`, ?) AS `first_name`

//SQL-Output for SQLServer
SELECT
    LEFT([first_name], @param1) AS [first_name]

```

## More Examples writing new stuff

**For more informations browse through the `/sql/operator` or `/sql/helper` directories. There are a lot
of Helpers and Operators and they all give you the best examples to write your own magic stuff.**

# Tests

After changing an existing Helper, Operator or maybe creating some new stuff you should run the Test.
For this use always:

```sh
npm test
```

If you like to Test only a specific language dialect or specific helper or operator you could pass arguments for that:

```sh
npm test -- [ --language|dialect <MySQL|MariaDB|PostgreSQL|SQLite|Oracle|SQLServer> ] [ --helper|operator <path of helper located in ./sql> ]

# Test only the $left-helper for language-dialect MySQL
npm test -- --helper /helpers/functions/string/left/left.js --language MySQL
```

## Generating docs

The documentation will automatically rebuild with every successful Test run.
Please note that a successful Test will only be archived by running a complete Tests without a specific language, helper or operator.

# License

MIT License

Copyright (c) 2017-2018 planetarydev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

 IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

repository: abalbastrem/moosic

gha_language: PLpgSQL

repo_name: abalbastrem/moosic


text:
# dot-files
A bunch of dot files that work accross different platforms.

## tmux
The .tmux.conf is a configuration file for tmux. To use, make a symlink of this file under $HOME.

See [this video](https://youtu.be/JXwS7z6Dqic) for more information about tmux.

### TPM

Tmux plugin manager (TPM) is used for some plugins of Tmux. To use it, run
```
git submodule update --init .tumx/plugins/tpm
```
then within tmux, press `Prefix I` to finish setup.

## spacemacs

Install emacs on Mac, as recommended by Spacemacs developers:
```bash
$ brew tap d12frosted/emacs-plus
$ brew install emacs-plus
$ brew linkapps emacs-plus
```

In `.spacemacs` file, load `spacemacs/user-init.el` in
`dotspacemacs/user-init ()` and load `spacemacs/user-config.el`
in `dotspacemacs/user-config ()`.

## neovim
The .nvimrc is a configuration file for neovim. To use it, first install
[vim-plug](https://github.com/junegunn/vim-plug)
following the instructions therein, then make a symlink of this file under $HOME.

After that, start nvim and run
```vim
PlugUpdate | PlugUpgrade
```

A good resource for learning vim is Steve's [Learn Vimscript the Hard Way](http://learnvimscriptthehardway.stevelosh.com/).

## ctags

The .ctags is to maek ctags ignore some common directories. To use is, make a symlink as $HOME/.ctags.

## clang-format

There is a .clang-format file that is used to format C++ code. To use it, make a symlink as $HOME/.clang-format and pass -style=file to clang-format

## MacOS

The .bashrc here also works for MacOS. Just add

```bash
source $HOME/.bashrc
```
to `.bash_profile`

license: MIT

repository: xywei/dot-files

branch_name: refs/heads/master

extension: md

license_type: permissive

repo_name: xywei/dot-files


text:
# nix-kit
Portable Unix/Linux config & tools I use everywhere that I don't want to lose, copy between system
Basically, I want my same setup every time I have a login on a unix like box.

## DOES include :
* home dir config: .bashrc, .profile, .ssh/config, .vimrc, etc
* system config (if I have root)
* helper scripts
* templates

## Does NOT include*:
* keys: ssh, gpg, etc
* passwords
* account numbers

<b>*</b> Encrypted in the **secrets** repo

repository: morganism/nix-kit

repo_name: morganism/nix-kit


text:
---
type: rule
title: Strategy - Do you have a marketing plan?
uri: have-a-marketing-plan
authors:
  - title: Ulysses Maclaren
    url: https://ssw.com.au/people/ulysses-maclaren
  - title: Camilla Rosa Silva
    url: https://ssw.com.au/people/camilla-rosa-silva
  - title: Jerwin Parker Roberto
    url: https://ssw.com.au/people/jerwin-parker
    img: https://github.com/SSWConsulting/SSW.People.Profiles/raw/main/Jerwin-Parker/Images/Jerwin-Parker-Profile.jpg
related: []
redirects:
  - do-you-have-a-marketing-plan
created: 2014-10-13T16:53:07.000Z
archivedreason: null
guid: 58f98cda-4632-4785-b393-eebb32baabaa
---

If you were going to build a house, you would hope that the architect and builders were working together using architectural plans and blueprints as their guide. So why would trying to build a solid customer base or market share be any different?

You should know that a marketing plan is of monumental importance. Although we recognize that in many cases marketing plans get filed away in the closet until it's time to get a business loan, they're most effective when they act as a blueprint for all the marketing activities a company undertakes.

<!--endintro-->

Here are some of the important points to consider in a marketing plan:

* Set out your marketing goals and objectives then align them with your overall business goals and strategy
* Set out a time frame for achieving those goals
* Identify a target market and segmentation strategy
* Define how you will position and differentiate your product
* Use competitor and industry analysis
* Identify current and proposed marketing methods
* Include marketing reports (historical and forecasts)
* Set the criteria against which the plan will be assessed for success or failure

The most important thing to remember about a marketing plan is that it is a work in progress, always needing to be reassessed and changed to adapt to the dynamic business environment.

branch_name: refs/heads/main

gha_language: TSQL


text:
ScalikeJDBC 1.6.1 has been released. Several fixes for Query DSL.

![ScalikeJDBC Logo](https://raw.github.com/seratch/scalikejdbc/master/logo.png)

http://git.io/scalikejdbc

## interpolation

- Added sqls alias for SQLSyntax object

Now you can write sqls.count instead of SQLSyntax.count!

- Added insert-select

    insert.into(Product).select(_.from(LegacyProduct as lp).where.isNotNull(lp.id))

- Added dynamicAnd/OrConditions

    val (productId, accountId) = (Some(1), None)
    val ids: List[Int] = withSQL {
      select(o.result.id).from(Order as o)
        .where
        .dynamicAndConditions(
          productId.map(id => sqls.eq(o.productId, id)),
          accountId.map(id => sqls.eq(o.accountId, id))
        )
        .orderBy(o.id)
    }.map(_.int(1)).list.apply()

- Added #exists, #notExists

    select(a.result.id)
      .from(Account as a)
      .where.exists(select.from(Order as o).where.eq(o.accountId, a.id))
      .orderBy(a.id)

- Added #union, #unionAll

    val ids: List[Int] = withSQL {
      select(a.id).from(Account as a)
        .union(select(p.id).from(Product as p))
    }.map(_.int(1)).list.apply()

- Fixed the bug that adding #groupBy after where clause is not allowed
- Fixed the bug that lazy loading columns doesn't work with sub-query
- Added wildcard count for PostgreSQL users
- Renamed SQLSyntax.and(Seq), or(Seq) to joinWithAnd, joinWithOr
- Added some basic DSL on SQLSyntax class

- Added QueryDSL prefix to select/insert/update/delete

In some cases, select/insert/update/delete might be already used. QueryDSL prefix is the easiest way to avoid the name confliction.

    def select(id: Long)(implicit s: DBSession): Option[User] = {
      withSQL { QueryDSL.select.from(User as u).where.eq(u.id, id) }.map(User(u)).single.apply()
    }

## mapper-generator

- Added queryDsl template

## library

- Avoid SQL printer's IndexOutOfBoundsException just in case
- Catching Formatter's exception

Enjoy writing typesafe SQL and get things done!

repository: scalikejdbc/scalikejdbc

extension: markdown

gha_language: Scala

repo_name: scalikejdbc/scalikejdbc


text:
# Warehouse example application with Knative Eventing

This repository contains an example microservices application for orders processing in a warehouse, with the purpose of trying and showing different technologies. This is a high level diagram showcasing how the application works

![app diagram](/img/diagram.png)

## How it's implemented?

The main feature of this application is it's event driven nature, implemented in a way that makes all the microservices composing the application agnostic to the messaging layer they are working with. Technologies such as Knative Eventing, Apache Kafka, Quarkus, among others are being used.

[Knative Eventing](https://knative.dev/docs/eventing) provides the platform to build decoupled systems on top of it. All the microservices in this application only speak [CloudEvents](https://cloudevents.io/) via http, Knative Eventing handles the routing of messages sent to it's messaging layer.

[Apache Kafka](https://kafka.apache.org/), deployed in Kubernetes using [Strimzi](https://strimzi.io/), is used by Knative Eventing as the broker that backs the messaging layer.

[Quarkus](https://quarkus.io/) is used to implement all the microservices in this application, as stated all microservices only speak CloudEvents via http so development of the microservices aims to be very simple. CloudEvents SDK is being used to implement CloudEvents aware aplications that send (to Knative Eventing Broker, backed by Apache Kafka) or receive (being invoked by Knative) CloudEvents messages. CloudEvents is used because of Knative and for messaging based communication patterns, for point to point communication (orders-processor to stocks-service in the example) Microprofile Rest Client is being used.

## How to run it?

You need a Kubernetes or Openshift cluster up and running.
If you don't have one you can use Kind.
You can install Kind running the script:
```
./scripts/install_kind.sh
```
Then create a Kind cluster:
```
make kind-start
```

Then to install the required infrastructure to run the application:
```
make setup-knative
```
Then wait until the kafka cluster is deployed, you can check the status with
```
kubectl get pod -n kafka
```
Once the kafka cluster is running please execute:
```
make eventing-kafka-broker
```

Once all the requirements are satisfied you can deploy the application:
```
kubectl apply -n warehouse -f kubefiles/orders-processor
kubectl apply -n warehouse -f kubefiles/stocks-service
kubectl apply -n warehouse -f kubefiles/warehouse-service
```

Then if you are using a Kind cluster run:
```
kubectl apply -n warehouse -f kubefiles/warehouse-service/optional/kind_warehouse_ingress.yaml
```
With this you'll be able to see the warehouse web in
```
http://localhost/
```

repository: famarting/warehouse-event-driven

repo_name: famarting/warehouse-event-driven


text:
# Frontend Mentor - Tip calculator app solution

This is a solution to the Tip calculator app challenge on Frontend Mentor.

## Table of contents

- [Overview](#overview)
  - [Screenshot](#screenshots)
  - [Links](#links)
- [My process](#my-process)
  - [Built with](#built-with)
  - [What I learned](#what-i-learned)
  - [Continued development](#continued-development)
  - [Useful resources](#useful-resources)
- [Author](#author)
- [Extras](#extras)

## Overview

### Screenshots

### Links

- Solution URL: My Solution
- Live Site URL: Splitter

 **Click, tap or point the camera**

## My process

### Built with

- Semantic HTML5 markup;
- CSS custom properties;
- Flexbox;
- Mobile-first workflow;
- JavaScript (no frameworks or libraries);
- GitFlow.

### What I learned

Use this section to recap over some of your major learnings while working through this project. Writing these out and providing code samples of areas you want to highlight is a great way to reinforce your own knowledge.

To see how you can add code snippets, see below:

- **CSS**
  - Flexbox;
  - How to change placeholders;
  - How to change text insertion indicator;
  - How to change cursor appearance;
  - Multiple classes (.class.class);
  - Outline + Box-Shadow vs. Border.
- **HTML**
  - Div element.
- **JavaScript**
  - NaN and Infinity;
  - querySelectorAll();
  - How to handle DOM events;
  - Node.contains().

```css
/*To leave the container covering the useful screen in the mobile version*/
.container, html, .area {
    height: 100%;
    margin: 0;
}
```
```js
//I'm proud of my functions for inputs, in this format
input.addEventListener('keyup', event=>{});
//and I also really liked my Regular Expression (one of the only ones without "search" that worked) for hundred units
const commaRegex = /(\d)(?=(\d{3})+(?!\d))/g; //Application: 1000.00 => 1,000.00 for example
```

### Continued development

I want to learn more about **HTML DOM Events**, and improve the creation of **Regular Expressions** (mine almost never worked right).

### Useful resources

- Keycode - This helped me to get the JavaScript event keycodes. I've added it to my favorites list, to use when I need it.
- Regex101 - I use this site to test my regular expressions.
- HTML DOM Events - Here I discovered other events for inputs (besides the traditional ones: blur and focus). I want to know and use more options in the future.
- GitFlow (**pt-BR video** :brazil:) - I learned how to use GitFlow with this video.

## Author

- Frontend Mentor - @gileadeteixeira
- Twitter - @giltxra
- LinkedIn - @gileade-teixeira

## Extras

- I did it without a team;
- Estimated Time vs. Completed Time (discounting hours "living" 😂):
  - ET - 2 days ___ CT - Almost 3 days;
  - Started on 7/26/2021, Completed on 07/29/2021.

repository: gileadeteixeira/tip-calculator-app

gha_language: JavaScript

gha_license_id: MIT

repo_name: gileadeteixeira/tip-calculator-app


text:
# Changelog

## 0.2.2

- [feat] both support webpack 4 and webpack 5.

## 0.2.1

- [fix] import css of swiper not found.

## 0.2.0

- [feat] update swiper version to 8.x

## 0.1.11

- [fix] stop `change` event bubble in runtime miniapp

## 0.1.10

- [fix] calc error in css file caused by `postcss-calc`

## 0.1.9

- [fix] fix style in wechat-miniprogram

## 0.1.8

- [fix] return instance ref in web
- [fix] make slidePrev and slideNext same in web and miniapp

## 0.1.7

- [feat] support swiper in miniapp

## 0.1.6

- [fix] remove space in `swiper.css` `@font-face` url
- [fix] type of `Swiper` & `SwiperSlide`

## 0.1.5

- [chore] update swiper dependency version to 6.8.4
- [feat] keep the same with Swiper.js 6.8.4
- [fix] event handler can't update

## 0.1.4

- [chore] update swiper version to 6.7.1

## 0.1.3

- [fix] remove extra space in url source of font-face

## 0.1.2

- [chore] Sync from rax-pkg-rax-swiper
- [chore] use `build-plugin-component` instead of `build-plugin-rax-component`
- [chore] update `rax-view` version

repository: raxjs/rax-components

gha_license_id: NOASSERTION

repo_name: raxjs/rax-components


text:
---
subcategory: "Cluster"
---

# Resource: clusternodegroup_nslimitidentifier_binding

The clusternodegroup_nslimitidentifier_binding resource is used to create clusternodegroup_nslimitidentifier_binding.

## Example usage

```hcl
resource "citrixadc_clusternodegroup_nslimitidentifier_binding" "tf_clusternodegroup_nslimitidentifier_binding" {
  name           = "my_group"
  identifiername = "my_nslimitidentifier"
}

```

## Argument Reference

* `identifiername` - (Required) stream identifier  and rate limit identifier that need to be bound to this nodegroup.
* `name` - (Required) Name of the nodegroup to which you want to bind a cluster node or an entity. Minimum length =  1

## Attribute Reference

In addition to the arguments, the following attributes are available:

* `id` - The id of the clusternodegroup_nslimitidentifier_binding. It is the concatenation of `name` and `identifiername` attributes separated by a comma.

## Import

A clusternodegroup_nslimitidentifier_binding can be imported using its name, e.g.

```shell
terraform import citrixadc_clusternodegroup_nslimitidentifier_binding.tf_clusternodegroup_nslimitidentifier_binding my_group,my_nslimitidentifier
```

repository: citrix/terraform-provider-citrixadc

gha_language: Go

repo_name: citrix/terraform-provider-citrixadc


text:
# Microsoft SQL Server Data Types
Complete list of all  Microsoft SQL Server Data Types

## Source link
 - [MSDN Data Types](https://msdn.microsoft.com/en-us/library/ms187752.aspx)
 - [MSDN Data Type Precedence](https://msdn.microsoft.com/en-us/library/ms190309.aspx)
 - [MSDN Data Type Synonyms](https://msdn.microsoft.com/en-us/library/ms177566.aspx)
 - [MSDN Precision, Scale, and Length](https://msdn.microsoft.com/en-us/library/ms190476.aspx)
 - [Integration Services Data Types](https://msdn.microsoft.com/en-us/library/ms141036.aspx)
 - [DbType Enumeration](https://msdn.microsoft.com/en-us/library/System.Data.DbType.aspx)
 - [SQL Server, SSIS and Biml Data Types](http://www.cathrinewilhelmsen.net/2014/05/27/sql-server-ssis-and-biml-data-types/)
 - [SQL Server Integration Services, Data Type Mapping ](http://milambda.blogspot.ru/2014/02/sql-server-integration-services-data.html)
 - [SQL Server Data Type Conversion](https://msdn.microsoft.com/en-us/library/ms191530.aspx)

## Data Type Precedence (Transact-SQL)
When an operator combines two expressions of different data types, the rules for data type precedence specify that the data type with the lower precedence is converted to the data type with the higher precedence.
If the conversion is not a supported implicit conversion, an error is returned.
When both operand expressions have the same data type, the result of the operation has that data type.

SQL Server uses the following precedence order for data types:
 1. sql_variant
 2. xml
 3. datetimeoffset
 4. datetime2
 5. datetime
 6. smalldatetime
 7. date
 8. time
 9. float
 10. real
 11. decimal
 12. money
 13. smallmoney
 14. bigint
 15. int
 16. smallint
 17. tinyint
 18. bit
 19. ntext
 20. text
 21. image
 22. timestamp
 23. uniqueidentifier
 24. nvarchar (including nvarchar(max) )
 25. nchar
 26. varchar (including varchar(max) )
 27. char
 28. varbinary (including varbinary(max) )
 29. binary (lowest)

## Data Type Synonyms (Transact-SQL)
Data type synonyms are included in SQL Server for ISO compatibility.
The following table lists the synonyms and the SQL Server system data types that they map to.

| Synonym                       | SQL Server system data type |
|-------------------------------|-----------------------------|
| Binary varying                | varbinary                   |
| char varying                  | varchar                     |
| character                     | char                        |
| character                     | char(1)                     |
| character(n)                  | char(n)                     |
| character varying(n)          | varchar(n)                  |
| Dec                           | decimal                     |
| Double precision              | float                       |
| float[(n)] for n = 1-7        | real                        |
| float[(n)] for n = 8-15       | float                       |
| integer                       | int                         |
| national character(n)         | nchar(n)                    |
| national char(n)              | nchar(n)                    |
| national character varying(n) | nvarchar(n)                 |
| national char varying(n)      | nvarchar(n)                 |
| national text                 | ntext                       |
| timestamp                     | rowversion                  |

Data type synonyms can be used instead of the corresponding base data type name in data definition language (DDL) statements, such as CREATE TABLE, CREATE PROCEDURE, or DECLARE @variable.
However, after the object is created, the synonyms have no visibility.
When the object is created, the object is assigned the base data type that is associated with the synonym.
There is no record that the synonym was specified in the statement that created the object.

## Precision, Scale, and Length (Transact-SQL)
Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. For example, the number 123.45 has a precision of 5 and a scale of 2.

In SQL Server, the default maximum precision of numeric and decimal data types is 38. In earlier versions of SQL Server, the default maximum is 28.

Length for a numeric data type is the number of bytes that are used to store the number. Length for a character string or Unicode data type is the number of characters. The length for binary, varbinary, and image data types is the number of bytes. For example, an int data type can hold 10 digits, is stored in 4 bytes, and does not accept decimal points. The int data type has a precision of 10, a length of 4, and a scale of 0.

When two char, varchar, binary, or varbinary expressions are concatenated, the length of the resulting expression is the sum of the lengths of the two source expressions or 8,000 characters, whichever is less.

When two nchar or nvarchar expressions are concatenated, the length of the resulting expression is the sum of the lengths of the two source expressions or 4,000 characters, whichever is less.

When two expressions of the same data type but different lengths are compared by using UNION, EXCEPT, or INTERSECT, the resulting length is the maximum length of the two expressions.

The precision and scale of the numeric data types besides decimal are fixed. If an arithmetic operator has two expressions of the same type, the result has the same data type with the precision and scale defined for that type. If an operator has two expressions with different numeric data types, the rules of data type precedence define the data type of the result. The result has the precision and scale defined for its data type.

The following table defines how the precision and scale of the result are calculated when the result of an operation is of type decimal. The result is decimal when either of the following is true:
 - Both expressions are decimal.
 - One expression is decimal and the other is a data type with a lower precedence than decimal.

 The precision and scale for any expression that is not decimal is the precision and scale defined for the data type of the expression.

| Operation                              | Result precision                    | Result scale *      |
-----------------------------------------|-------------------------------------|---------------------|
| e1 + e2                                | max(s1, s2) + max(p1-s1, p2-s2) + 1 | max(s1, s2)         |
| e1 - e2                                | max(s1, s2) + max(p1-s1, p2-s2) + 1 | max(s1, s2)         |
| e1 * e2                                | p1 + p2 + 1                         | s1 + s2             |
| e1 / e2                                | p1 - s1 + s2 + max(6, s1 + p2 + 1)  | max(6, s1 + p2 + 1) |
| e1 { UNION \| EXCEPT \| INTERSECT } e2 | max(s1, s2) + max(p1-s1, p2-s2)     | max(s1, s2)         |
| e1 % e2                                | min(p1-s1, p2 -s2) + max( s1,s2 )   | max(s1, s2)         |
\* The result precision and scale have an absolute maximum of 38. When a result precision is greater than 38, the corresponding scale is reduced to prevent the integral part of a result from being truncated.

## SQL Server, SSIS and Biml Data Types
The table below shows a simplified mapping between SQL Server, SSIS and Biml data types. The table does not include all possible mappings or all data types, but is meant as a quick reference while developing and learning Biml.

| SQL Server       | SSIS                 | Biml                  |
|------------------|----------------------|-----------------------|
| bigint           | DT_I8                | Int64                 |
| binary           | DT_BYTES             | Binary                |
| bit              | DT_BOOL              | Boolean               |
| char             | DT_STR               | AnsiStringFixedLength |
| date             | DT_DBDATE            | Date                  |
| datetime         | DT_DBTIMESTAMP       | DateTime              |
| datetime2        | DT_DBTIMESTAMP2      | DateTime2             |
| datetimeoffset   | DT_DBTIMESTAMPOFFSET | DateTimeOffset        |
| decimal          | DT_NUMERIC           | Decimal               |
| float            | DT_R8                | Double                |
| geography        | DT_IMAGE             | Object                |
| geometry         | DT_IMAGE             | Object                |
| hierarchyid      | DT_BYTES             | Object                |
| image (*)        | DT_IMAGE             | Binary                |
| int              | DT_I4                | Int32                 |
| money            | DT_CY                | Currency              |
| nchar            | DT_WSTR              | StringFixedLength     |
| ntext (*)        | DT_NTEXT             | String                |
| numeric          | DT_NUMERIC           | Decimal               |
| nvarchar         | DT_WSTR              | String                |
| nvarchar(max)    | DT_NTEXT             | String                |
| real             | DT_R4                | Single                |
| rowversion       | DT_BYTES             | Binary                |
| smalldatetime    | DT_DBTIMESTAMP       | DateTime              |
| smallint         | DT_I2                | Int16                 |
| smallmoney       | DT_CY                | Currency              |
| sql_variant      | DT_WSTR              | Object                |
| text (*)         | DT_TEXT              | AnsiString            |
| time             | DT_DBTIME2           | Time                  |
| timestamp (*)    | DT_BYTES             | Binary                |
| tinyint          | DT_UI1               | Byte                  |
| uniqueidentifier | DT_GUID              | Guid                  |
| varbinary        | DT_BYTES             | Binary                |
| varbinary(max)   | DT_IMAGE             | Binary                |
| varchar          | DT_STR               | AnsiString            |
| varchar(max)     | DT_TEXT              | AnsiString            |
| xml              | DT_NTEXT             | Xml                   |

(\* *These data types will be removed in a future version of SQL Server. Avoid using these data types in new projects, and try to change them in current projects*)

repository: Evdlaar/sqlserver-kit

path: /SQL Server Data Types.md

filename: SQL Server Data Types.md

repo_name: Evdlaar/sqlserver-kit


text:
# CommonCoreOntologies
The Common Core Ontology Repository holds the current released version of the Common Core Ontology suite.

The Common Core Ontologies (CCO) comprise twelve ontologies that aim to represent and integrate taxonomies of generic classes and relations across all domains of interest.

CCO is designed as a mid-level extension of Basic Formal Ontology (BFO), an upper-level ontology framework widely used to structure and integrate ontologies in the biomedical domain (Arp, et al., 2015). BFO aims to represent the most generic categories of entity and the most generic types of relations that hold between them, by defining a small number of classes and relations. CCO then extends from BFO in the sense that every class in CCO is asserted to be a subclass of some class in BFO, and that CCO adopts the generic relations defined in BFO (e.g., has_part) (Smith and Grenon, 2004). Accordingly, CCO classes and relations are heavily constrained by the BFO framework, from which it inherits much of its basic semantic relationships.

The CCO provide semantics for concepts and relations that are used in most domains of interest. The utility of the CCO comes from preventing BFO compliant domain specific ontologies from needlessly duplicating common concepts or from forcing such ontologies to include concepts outside of their domain (e.g. organization in the Ontology of Biomedical Investigations). This utility has been realized by a number of projects in which either existing BFO compliant ontologies were aligned to the CCO or domain ontologies were created by using the CCO as a starting point and adding classes and properties as needed. Examples include:

Emotion Ontology (http://obofoundry.org/ontology/mfoem.html)

Airforce Aircraft Maintenance Ontology

Aircraft Ontology

Army Universal Task List Ontology

Hydrographic Feature Ontology

Sensor Ontology

Legal and Criminal Act Ontology

Skills Ontology

Military Operations Ontology

Space Object Ontology

Mission Planning Ontology

Transportation Infrastructure Ontology

Occupation Ontology

Undersea Warfare Ontology

Physiographic Feature Ontology

Watercraft Ontology

repository: kaleb-himes/CommonCoreOntologies

repo_name: kaleb-himes/CommonCoreOntologies


text:
# safety-worker

Service worker unregistering old service worker

```sh
$ npm i safety-worker
```

```javascript
//client script

navigator.serviceWorker.register("/safety-worker.js")
```

repository: IKatsuba/safety-worker

repo_name: IKatsuba/safety-worker


text:
# Scala.js typings for stylelint

Typings are for version 15.6.1

## Library description:
A mighty, modern CSS linter.

|                    |                 |
| ------------------ | :-------------: |
| Full name          | stylelint |
| Keywords           | css-in-js, css, less, lint, linter, markdown, sass, scss, stylelint, sugarss |
| # releases         | 38 |
| # dependents       | 0.0 |
| # downloads        | 1.5604025333333334E7 |
| # stars            | 10070.0 |

## Links
- [Homepage](https://stylelint.io)
- [Bugs](https://github.com/stylelint/stylelint/issues)
- [Repository](https://github.com/stylelint/stylelint)
- [Npm](https://www.npmjs.com/package/stylelint)

## Note
This library has been generated from typescript code from first party type definitions.

Provided with :purple_heart: from [ScalablyTyped](https://github.com/oyvindberg/ScalablyTyped)

## Usage
See [the main readme](../../readme.md) for instructions.

repository: ScalablyTyped/Distribution

repo_name: ScalablyTyped/Distribution


text:
TransportationWsBundle
======================
lol
Symfony2 bundle to handle all the webservices between Transportation website and its partners

Installation
============

To install this bundle please follow the next steps:

First add the dependency in your `composer.json` file:

```json
"require": {
        ...,
        "transportation/ws-bundle": "dev-master"
    },
```

Then install the bundle with the command:

```sh
php composer update
```

Enable the bundle in your application kernel:

```php
<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        //
        new Transportation\Bundle\WsBundle\TransportationWsBundle(),
    );
}
```

Now the Bundle is installed.


text:
# Property Based Testing with LINQ Expressions

> There are two ways of constructing a software design: One way is to make it
> so simple that there are obviously no deficiencies, and the other way is to
> make it so complicated that there are no obvious deficiencies. The first
> method is far more difficult.
>
> C.A.R. Hoare in his 1980 Turing Award Lecture

Although [Tony Hoare]'s famous quote is undoubtedly correct, it is increasingly
difficult nowadays to design software so simple that it is obviously bug-free by
design. Software gets more and more complex every day, and usually the only
practical way to assure its quality is to test it thoroughly. Design is important, as
is aspiration for simplicity, but they don't guarantee error free programs.

Another famous quote by [Edsger W. Dijkstra] says that testing shows the
presence, not the absence of bugs. However, the term testing can refer to many
types of activities. We should recognize that the number and types of bugs we
find varies greatly depending on the kind of testing we perform. The stricter
and more systematic our approach is, the more value we get out of it.

The problem is that testing can be a very tedious and time consuming task. Even
automated tests require a lot of work and discipline to be effective in
discovering bugs. So, we should continuously seek ways to improve our testing
strategies, and explore new methods with an open mind. The best we could hope
for is a technique which reduces the amount of test code we need to write while
revealing more bugs, and even new kinds of bugs. Is there an approach that
could satisfy these requirements? I think there is.

## Property Based Testing

Property based testing refers to a software verification method where the
test cases are generated by a computer. This tehcnique was first introduced in
the [QuickCheck] library, originally developed for the purely functional
programming language [Haskell]. As the name "property based testing" hints,
the idea is to specify properties that should hold for arbitrary input data,
not just for a single test case. Typically a testing library similar to
Quickcheck is used to produce random input and test the specified properties.
In a sense, the testing library is trying to prove our assumptions wrong by
searching for counter-examples.

If the library finds a case where one or more properties do not hold, it will
reduce the case to a minimal example that still fails. This is a much better
starting point for analyzing the problem than getting an exception or
assertion error in the middle of program execution. The program flow that led
to the error can be lengthy and hard to reproduce. Also, it  might be difficult
to discern which actions are relevant for reproducing the problem and which
are not.

Property based testing generally works best for testing pure functions
whose result depend only on their input. However, the co-inventor of QuickCheck
[John Hughes] has demonstrated that it is possible to test also imperative
programs with property based testing. Rather than generating input data directly,
we create sequences of function calls that modify the program's mutable state.
When a failing sequence is found, the library reduces it to a minimal example
that produces the same error.

There are a lot of resources on the Internet to learn more about property
based testing, but I would recommend reading the
[original paper] by Hughes and Koen Classen. It not only introduces the
concept but also explains how the library is implemented in an easy-to-follow
way. The paper assumes the reader to be familiar with Haskell, which might
be an obstacle. If you know the basics of Haskell, though, the paper serves
as an excellent guide on how to implement the library in some other
programming language.

## LinqCheck

As you might have guessed LinqCheck is a port of QuickCheck for C#. It
implements all of the concepts present in QuickCheck, and tries to provide
an API which feels natural, not mimicking the original design too much. It
also aims to demonstrate how you can program in C# like it was a functional
programming language. You can write really elegant and simple code by following
the principles of FP; the kind of obviously correct code that Tony Hoare was
referring to in his speech. The ideas of functional programming are applicable
in any programming language that has the few required constructs such as
closures and function types.

Another feature you might deduce from the name is that LinqCheck is built on
the language facilities provided by LINQ. It is no coincidence that LINQ
expressions resemble very much [monads](https://en.wikipedia.org/wiki/Monad_(functional_programming))
in Haskell. [Erik Meijer](https://en.wikipedia.org/wiki/Erik_Meijer_(computer_scientist)),
who is commonly credited to be the creator of LINQ, was involved in the design of
Haskell language. So, naturally he designed LINQ using the same concepts that
proved to be very powerful in Haskell. Understanding the correspondence between
monads and LINQ helps porting the features of QuickCheck from Haskell to C# as
the orginal implementation utilizes monads in many places.

## Getting Started

The easiest way to learn LinqCheck is by example. The first part of this
documentation covers several test examples and introduces the most important
features of the library. If you are only interested in how to use the library,
you can read just those chapters. But if you want to learn how the library works
under the hood, you can continue reading the following chapters which cover the
whole implementation.

This documentation is generated with the [LiterateCS] tool, which creates HTML
documentation automatically from C# projects. Literate programming is a methodology
that encourages writing documentation in tandem with code. It helps you build nice
documentation for programs whose operation you want to explain to others.

LiterateCS is actually a great accompanion to LinqCheck. By documenting your
properties and test code you will also get live documentation which specifies in
natural language how the code you are testing works.

### Obtaining and Installing the Library

You can download the library as a [Nuget package] from <https://www.nuget.org/>. The
library targets [.NET Standard 2.0].

[Tony Hoare]: https://en.wikipedia.org/wiki/Tony_Hoare
[Edsger W. Dijkstra]: https://en.wikipedia.org/wiki/Edsger_W._Dijkstra
[QuickCheck]: https://en.wikipedia.org/wiki/QuickCheck
[Haskell]: https://www.haskell.org/
[John Hughes]: https://en.wikipedia.org/wiki/John_Hughes_(computer_scientist)
[original paper]: http://www.eecs.northwestern.edu/~robby/courses/395-495-2009-fall/quick.pdf
[monads]: https://en.wikipedia.org/wiki/Monad_(functional_programming)
[LiterateCS]: https://johtela.github.io/LiterateCS/
[Nuget package]: https://www.nuget.org/packages/LinqCheck/
[.NET Standard 2.0]: https://docs.microsoft.com/en-us/dotnet/standard/net-standard

repository: johtela/LinqCheck

repo_name: johtela/LinqCheck


text:
---
title: Docker users and user namespaces
date: "2018-10-09T00:00:00.284Z"
tags: ["programming"]
cover: "./docker.png"
description: After taking a break from DevOps for a few months and switching to other fields, I would always forget the details of how users within a docker container map to users on the host machine.  Normally, you'd have a docker group on your machine
    that your user (e.g. boris) belongs to.

    Normally, uid/pids within the container are the same uids and pids as in your host system, cause containers and
    the host machine share the same kernel.

    E.g. when you run a docker container, normally processes within the container run as root user with uid 0. Files,
    owned by those processes (e.g. through a mounted volume), are seen as owned by root on the host, they have uid
    of 0 as well.

    If you run a process as a non-root user within the container (e.g. stock postgres image does
    gosu to uid 999 before running, on the host machine postgres-owned files will be owned by uid=999.

    uids for non-system users normally start with 1000,
    so if you're running some process within the docker container as uid 1001,

    In a Dockerfile you can use USER instruction to specify that some commands might need to be run under a
    different uid.

    You can pass a --user option to docker run, e.g. docker run -d --user 1001 ubuntu:latest sleep infinity,
    and in that case process within your container process will run as user 1001. This option overrides the
    USER command in your container.

    Read more examples in this excellent posts by Marc Campbell.

    Take note that examples, provided in the post, work on true Linux machines, but not on Mac OS, where ps
    doesn't show docker processes, due to implementation details of docker machine on macs.

User namespaces and remapping

    There's a mechanism in Linux kernel called user namespaces, which allows you to improve security of your
    containers.

    Basically, you can remap a range of uids, used within a docker container, to regular users uids on your host machine,
    when configuring the docker daemon. Read more in the official documentation.

Links:

Understanding how uid and gid work in docker containers

Don't run processes in containers as root

User namespaces and remapping


text:
# *vbb-anybar* ⏱

**Let the status bar show you when to catch the train.**

[![npm version](https://img.shields.io/npm/v/vbb-anybar.svg)](https://www.npmjs.com/package/vbb-anybar)
[![dependency status](https://img.shields.io/david/derhuerst/vbb-anybar.svg)](https://david-dm.org/derhuerst/vbb-anybar)
![ISC-licensed](https://img.shields.io/github/license/derhuerst/vbb-anybar.svg)
[![gitter channel](https://badges.gitter.im/derhuerst/vbb-rest.svg)](https://gitter.im/derhuerst/vbb-rest)
[![support me on Patreon](https://img.shields.io/badge/support%20me-on%20patreon-fa7664.svg)](https://patreon.com/derhuerst)

## Installing

```shell
npm install -g vbb-anybar
```

## Usage

*This guide assumes you have the [AnyBar app](https://github.com/tonsky/AnyBar#anybar-os-x-menubar-status-indicator) installed.*

`vbb-anybar` needs the station where you want to catch the train and the direction, which is just the next station your train will pass. You can find them using [`vbb-stations-cli`](https://github.com/derhuerst/vbb-stations-cli#vbb-stations-cli). To set them, run the following:

```shell
vbb-anybar init <station-id> <next-station-id> [<time-to-station>]
```

From now on, if you call `vbb-anybar` (without any arguments), it will talk to the AnyBar app and set a color that tells you when to leave. You would usually run this every few seconds.

time-to-station is an optional argument which allows you to configure a time (in minutes) for how long it takes you to get to the station. The color telling you when to leave will calculate with this time as well.

## API

```
Usage:
    vbb-anybar
    vbb-anybar init <station-id> <next-station-id> [<time-to-station>]
```

## Contributing

If you **have a question**, **found a bug** or want to **propose a feature**, have a look at [the issues page](https://github.com/derhuerst/vbb-anybar/issues).

license: ISC

repository: derhuerst/vbb-anybar

repo_name: derhuerst/vbb-anybar


text:
# Other features

## Arthas Async Jobs

If you need to investigate an issue, but you are unsure about the exact time it occurs, you can run the monitoring command in the background and save the output to a log file.

- [Arthas Async Jobs](async.md)

## Log the output

All execution records are fully saved in the log file for subsequent analysis.

- [log the output](save-log.md)

## Docker

Arthas configuration reference for using in Docker containers.

- [Docker](docker.md)

## Web Console

Arthas supports living inside a browser. The communication between arthas and browser is via websocket.

- [Web Console](web-console.md)

## Arthas Tunnel

Arthas Tunnel Server/Client enables remote management/connection to Java services across multiple servers.

- [Arthas Tunnel](tunnel.md)

## How to use ognl

- [Basic ognl example](https://github.com/alibaba/arthas/issues/11)
- [Ognl special uses](https://github.com/alibaba/arthas/issues/71)

## IDEA Plugin

Build arthas commands more efficiently in the IntelliJ IDEA compiler.

- [IDEA Plugin](idea-plugin.md)

## Arthas Properties

Arthas supports configuration options reference.

- [Arthas Properties](arthas-properties.md)

## Start as a Java Agent

- [Start as a Java Agent](agent.md)

## Arthas Spring Boot Starter

Starting with the application.

- [Arthas Spring Boot Starter](spring-boot-starter.md)

## HTTP API

The Http API provides structured data and supports more complex interactive functions, making it easier to integrate Arthas into custom interfaces.

- [HTTP API](http-api.md)

## Batch Processing

It is convenient for running multiple commands in bulk with custom scripts. It can be used in conjunction with the `--select` parameter to specify the process name.

- [Batch Processing](batch-support.md)

## as.sh and arthas-boot tips

- Select the process to be attached via the `select` option.

Normally, `as.sh`/`arthas-boot.jar` needs to a pid, bacause the pid will change.

For example, with `math-game.jar` already started, use the `jps` command to see.

```bash
$ jps
58883 math-game.jar
58884 Jps
```

The `select` option allows you to specify a process name, which is very convenient.

```bash
$ ./as.sh --select math-game
Arthas script version: 3.3.6
[INFO] JAVA_HOME: /tmp/java/8.0.222-zulu
Arthas home: /Users/admin/.arthas/lib/3.3.6/arthas
Calculating attach execution time...
Attaching to 59161 using version /Users/admin/.arthas/lib/3.3.6/arthas...

real	0m0.572s
user	0m0.281s
sys	0m0.039s
Attach success.
telnet connecting to arthas server... current timestamp is<PHONE_NUMBER>
Trying <IP_ADDRESS>...
Connected to localhost.
Escape character is '^]'.
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.
 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'

wiki      https://arthas.aliyun.com/doc
tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html
version   3.3.6
pid       58883
```

## User data report

After the `3.1.4` version, arthas support user data report.

At startup, use the `stat-url` option, such as: `./as.sh --stat-url 'http://<IP_ADDRESS>:8080/api/stat'`

There is a sample data report in the tunnel server that users can implement on their own.

[StatController.java](https://github.com/alibaba/arthas/blob/master/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/StatController.java)

repository: alibaba/arthas

gha_language: Java

repo_name: alibaba/arthas


text:
---
layout:     post
title:      "Part 4: Covariance operator for reproducing kernels"
subtitle:   "Another important operator defined on a RKHS is Covariance operator, which is essential for doing kernel PCA, kernel CCA, and independence testing etc. We will see that under certain conditions, the centered Covariance operator is Hilbert-Schmidt, moreover, sharing the same spectrum as the HS Integral operator introduced in Part 3."
date:       2020-09-30 15:40
author:     "Eden"
tags: 		  [kernel, fundamentals of RKHS]
category:   math
---

_**Disclaimer.** This post is served as a summarisation of my study notes on RKHS theory [1], and classes I took on relevant topics, containing theoratical details from [1, 3] along with my interpretations directed by my personal interests on those topics. I am by no means an expert in functional analysis and spectral theory, so please feel free to point out any mistakes in the post.

_

For the last post of the fundamentals of RKHS, we will take a look at the Covariance operator, which we will show is a HS operator on the RKHS. It serves as an important and widely-applicable tool for data analysis, e.g. for feature selections using KPCA, KCCA, or by independence testing with COCO or HSIC etc. (Interested reader may be referred to [3].) Furthermore, it also plays an important role in the analysis of spectral/regularised algorithm, in determining the optimal non-asymptotic rate of convergence [2]. We will probably see more of this in the future post.

In this article, we assume $\calX$ is a Metric spaces, and let $(\calX, \Omega\_{\calX}, \P)$ be a probability space. Then, we denote $X$ as a random variable supported on $\calX$. In addition, assume $\calL^2(\calX, \P) = \calL^2(\P)$ a separable Hilbert space. Then we denote $H\_k$ as a separable RKHS equipped with reproducing kernel $k: \calX\times\calX \to \R$, such that $k(x,\cdot) = \phi(x) \in H\_k$, and $k\_{\max} = \sup\_{x\in\calX}k(x, x)<\infty$.

We have already seen in [Part 3](2020-09-24-hilbert-basis.md) that the integral operator

$$
\begin{align}
  \calK(f)(t) = \int_{\calX} f(x)k(x,y)\;d\mu(x),\quad \calK: \calL^2(\calX) \to \calL^2(\calX)
\end{align}
$$

is a HS operator if $k\in\calL^2(\calX\times\calX, \mu)$. In fact, we may impose the following assumption to get a nice property on the spectrum of the HS operator $\calK$.

**Lemma 2.** _With the above notation, assume $\E\_{X}[\norm{\phi(X)}\_{H_k}] = \int k(x,x) \;d\P < \infty$, then $\calK$ is HS and of trace class (i.e. $\tr{\calK} = \sum\_i \lambda\_i < \infty$)._

_Proof._
The fact that $\calK$ is HS is obvious, since

$$
  \E_{X,Y}[k^2(X,Y)] =
  \int_{\calX}\int_{\calX} k(x,y)^2\; d\P(x)d\P(y)
  \leq [\E\norm{\phi(X)}^2]^2 < \infty,
$$

therefore $k\in\calL^2(\calX\times\calX, \mu)$. Now, we also have that

$$
  \int k(x,x) \;d\P
  = \int \sum_i \lambda_i \phi_i(x)\phi_i(x) \;d\P
   = \sum_i \lambda_i \int \phi_i(x)\phi_i(x) \;d\P = \sum_i \lambda_i = \tr{\calK}
$$

since the LHS is bounded, we get the result.

 $\square$

This Lemma is relevant in linking the Integral operator with the centered Covariance operator via the linear operator considered in [Part 2](2020-09-24-hilbert-basis.md). What is most interesting is that the eigenvalues of the two coincides.

Covariance operator of reproducing kernel

Just as remarked in Part 3, the definition of (centered) Covariance operator is also comparable to the Covariance/Gram matrix in the finite dimensional space. But as a start, we will need to define the mean element in the RKHS.

**Definition 6 (Mean element).** _The mean element in $H_k$ is defined as $\mu\_X = \E\_X[k(X, \cdot)]\in H\_k$ such that for any $f\in H\_k$_

$$
   \inner{f, H_k}_{H_k} = \E[f(X)].
$$

**Definition 7 (Cross-covariance operator).** _With the same setup in the beginning, assume $(\calY, \Omega\_{\calY}, \Q)$ is another probability space, such that $\calY$ is a metric space. Then let $Y$ denote a random variable supported on $\calY$. Finally, denote $G\_h$ a RKHS equipped with reproducing kernel $h$._

_Let $\mu\_X, \mu\_Y$ be the two mean elements in $H\_k$ and $G\_h$ respectively. Then the Cross-covariance operator is defined as_

$$
  C_{X,Y} = \E_{X,Y}[(k(X,\cdot) - \mu_X)\otimes (h(Y,\cdot) - \mu_Y)],
$$

_where for any $f\in H\_k, g\in G\_h$,_

$$
  \begin{align*}
    \inner{f, C_{X,Y}g}_{H_k}
    &= \E_{X,Y}[\inner{k(X,\cdot)- \mu_X, f}_{H_k}\inner{h(Y,\cdot) - \mu_Y, g}_{G_h}]\\
    &= \E_{X,Y}[(f(X)-\E_X[f])(g(Y)-\E_Y[g])].
  \end{align*}
$$

_Therefore, the (Auto-)covariance operator is as followed_

$$
\Sigma_X = C_{X,X} = \E_{X,X}[(k(X,\cdot) - \mu_X)\otimes (k(X,\cdot) - \mu_X)].
$$

Indeed, the covariance operator is HS, since

$$
\begin{align*}
  \norm{\Sigma_X}_{HS}
  &\leq \E_{X,X}[\norm{(k(X,\cdot) - \mu_X)\otimes (k(X,\cdot) - \mu_X)}_{HS}^2]\\
  &= \E_{X,X}[\norm{k(X,\cdot) - \mu_X}_{H_k}^4]\\
  &\leq \E_{X,X}[\norm{k(X,\cdot)}_{H_k} + \norm{\mu_X}_{H_k}]^4\\
  &\leq \E_{X,X}[\sqrt{k(X,X)} + \sqrt{k(X,X)}]^4\\
  &= 16k_{\max}^2 < \infty
\end{align*}
$$

where the first inequality is by Jensen's inequality, and the last inequality is due to

$$
  \norm{k(X,\cdot)}_{H_k} = \sqrt{k(X,X)} \leq \sqrt{k_{\max}}\quad \text{and for $X'$ an i.i.d copy of $X$}
$$

$$
  \norm{\mu_X}_{H_k}^2 = E_{X'}\inner{k(X',\cdot), \mu_X}_{H_k} = \E_{X'}\E_{X}[k(X',X)] < k_{\max}.
$$

**Remark.** _It is to note that, the operator $L:H\_k\to\R$, s.t. $L(f) = \E\_X[f(X)]\; \forall f\in H\_k$ is linear and continuous if $k$ is uniformly bounded, i.e. $\sup\_{x\in\calX} k(x,x)<\infty$. Then by Riesz representation theorem, the existence of $\mu\_X$ is guaranteed._

**Remark.** _Since $H\_k$ is compact, it guarantees the empirical mean element to be in $H\_k$. Similarly, as the space of HS operator is a Hilbert space, it is therefore compact, which also means the empirical estimator of the covariance function is in the same space of $\Sigma\_X$. This suggests the consistency of the estimators._

From now on, we assume the Covariance operator is centered, i.e. $\mu\_X=0$. We will show next that the spectrum of the Integral operator and the Covariance operator coincides. This important result is fundamental to the analysis of a class of spectral/regularised algorithms, e.g. ridge regression and gradient methods [2].

**Theorem 7.** _Let $(\calX, \Omega\_{\calX}, \P)$ be a probability space, $H\_k$ separable RKHS with kernel $k$ and feature map $\phi$ as assumed in the beginning. In addition, let $\E\norm{\phi(X)}\_{H_k}^2<\infty$. Then, both of the integral operator $\calK$ and the Covariance operator $\Sigma\_X$ can be characterised by a continuous linear operator. Moreover, their eigenvalues (all positive) coincides._

_Proof._

It is obvious from Lemma 2. that $\calK$ is a HS trace class integral operator. Now, let us consider a linear map $\calT:H\_k\to \calL^2(\P)$ s.t.

$$
  \calT h = \inner{h, \phi(\cdot)}_{H_k}.
$$

This is in fact the linear (evaluation) operator.
Indeed $\calT h\in\calL^2(\P)$, since by Cauchy-Schwartz (CS),

$$
  \norm{\calT h}_{\calL^2}
  = \E[\calT h(X)]^2
  = \E\inner{h,\phi(X)}_{H_k}^2
  \leq \norm{h}^2_{H_k} \E\norm{\phi(X)}^2_{H_k}
  < \infty
$$

We can similarly show that $\calT$ is indeed continuous with

$$
  \norm{\calT h_1 - \calT h_2}_{\calL^2(\P)}
  \leq \norm{h_1 - h_2}_{H_k}^2 \E\norm{\phi(X)}_{H_k}^2.
$$

Then $\calT^{\ast}$ is also continuous. We will show that the adjoint is of the form $L$ introduced in Part 2. Now, let $f\in\calL^2(\P)$ it gives

$$
  \inner{\calT^{\ast}f, h}_{H_k}
  = \inner{f, \calT h}_{\calL^2(\P)}
  = \E[f(X)\inner{h, \phi(X)}_{H_k}]
  = \inner{h, \E[f(X)\phi(X)]}_{H_k},
$$

hence $\calT^{\ast}f = \E[f(X)\phi(X)] = \inner{f, \phi(\cdot)}\_{\calL^2(\P)}$. Moreover, we can show that $\calT^{\ast}f\in H\_k$, where

$$
  \norm{\calT^{\ast}f}_{H_k}
  \leq \E\norm{f(X)\phi(X)}_{H_k}
  \leq [\E\norm{f(X)}_{H_k}^2\E\norm{\phi(X)}_{H_k}^2]^{1/2}
  <\infty,
$$

then $\calT^{\ast}: \calL^2(\P) \to H\_k$. In addition, for $h, h'\in H\_k$

$$
  \inner{h, \calT^{\ast}\calT g'}_{H_k}
  = \inner{\calT h, \calT h'}_{\calL^2(\P)}
  = \E[h(X)h'(X)],
$$

hence $\Sigma\_X = \calT^{\ast}\calT$; and for $f\in\calL^2(\P)$,

$$
  \calT\calT^{\ast}f
  = \inner{\calT^{\ast}f, \phi(\cdot)}_{H_k}
  = \E[f(X)\inner{\phi(X), \phi(\cdot)}_{H_k}]
  = \int_{\calX} f(x)k(x,\cdot) \;d\P(x)
$$

therefore $\calK = \calT\calT^{\ast}$.

Now, what is left to prove is that $\Sigma\_X$ and $\calK$ have the same spectrum. Let $\lambda(A) = \\{\lambda: Ax = \lambda x\\}$ be the spectrum for $A$, and $E\_{\lambda}(A) = \\{x: Ax = \lambda x\\}$ the eigenspace associated with the eigenvalue $\lambda$. Observe that for $f\in E\_{\lambda}(\calK)$,
<dic>
$$
  (\calT^{\ast}\calT)\calT^{\ast}f = \calT^{\ast}(\calT\calT^{\ast})f
  = \lambda\calT^{\ast} f
$$
</dic>
so $\calT^{\ast}f\in E\_{\lambda}(\Sigma\_X)$, i.e. $\calT^{\ast}E\_{\lambda}(\calK)\subset E\_{\lambda}(\Sigma\_X)$. Apply $\calT$ on both sides gives
<dic>
$$
  \calT\calT^{\ast}E_{\lambda}(\calK)
  = \calK E_{\lambda}(\calK) = E_{\lambda}(\calK)
  \subset \calT E_{\lambda}(\Sigma\_X)
$$
</dic>
Similarly $\calT E\_{\lambda}(\Sigma\_X)\subset E\_{\lambda}(\calK)$, hence $E\_{\lambda}(\calK)\subset \calT E\_{\lambda}(\Sigma\_X) \subset E\_{\lambda}(\calK)$. Therefore,
the equality holds, i.e. $E\_{\lambda}(\calK) = \calT E\_{\lambda}(\Sigma\_X)$.

The same procedure also gives $E\_{\lambda}(\Sigma\_X) = \calT^{\ast} E\_{\lambda}(\calK)$. Consequently, we have $\dim{E\_{\lambda}(\Sigma\_X)} = \dim{E\_{\lambda}(\calK)}$, i.e. $\lambda$ is the eigenvalue of both of $\calK$ and $\Sigma\_X$ and with the same multiplicity.

 $\square$

With the necessary concepts introduced in these four articles, many interesting topics emerge naturally linking to spectral properties of RKHS. Apart from the use of RKHS in learning theory as we briefly mentioned in this post, we also have the connection of (stochastic) differential equations to the reproducing kernels. An evidence would be Gaussian Process (GP). Extensions on the domain of the RKHS is also possible, to e.g. compact Riemannian manifold.

Since much theory is quite involved, it would take much more time to read through the necessary details on Harmonic analysis, SDE and probably Riemannian manifold. So the following posts may be largely consists of my intuitions and comments, and may serve as a recording of my thinkings that I would like to share.

References

1. Harchaoui, Z. STAT 538 Statistical Learning: Modeling, Prediction, And Computing, [Lecture 6](../stat538lec6.pdf). University of Washington, 2019.
2. Lin J, Rudi A, Rosasco L, Cevher V. Optimal rates for spectral algorithms with least-squares regression over Hilbert spaces. Applied and Computational Harmonic Analysis. 2020 May 1;48(3):868-90.
3. Gretton, A. [Notes on mean embeddings and covariance operators](http://www.gatsby.ucl.ac.uk/~gretton/coursefiles/lecture5_covarianceOperator.pdf). UCL, 2020 Jan.

gha_language: HTML


text:
#.NET Executor

This is an implementation of a Mesos Executor that will execute a lambda written for the .NET Core CLR.  The current implementation requires that the lambda author build and publish their dependencies into a directory and zip *both* the executable and all of it's dependencies into an artifact to be inflated and executed.

We're currently using a docker container built from the `ubuntu:trusty`, but more specifically we're using the following base : `buildpack-deps:trusty-scm`.

In order to remaing consistent, lambda authors should use the following container to build and publish their executables : `microsoft/dotnet:latest` which is also based on the above listed docker images.

Here is a brief example of how to create a .NET lambda.

#Hello World

Simplest possible .NET lambda.  Note that you must implement `Main(string[] args)` entry point in order for your lambda to be executed by the system.

### Program.cs
```c#
using System;

namespace ConsoleApplication
{
	public class Program
	{
		public static void Main(string[] args)
		{
			Console.WriteLine("Hello World!");
		}
	}
}
```

### project.json

```json
{
	"version": "1.0.0-*",
		"compilationOptions": {
			"emitEntryPoint": true
		},

		"dependencies": {
			"Microsoft.NETCore.Runtime": "1.0.1-beta-*",
			"System.IO": "4.0.11-beta-*",
			"System.Console": "4.0.0-beta-*",
			"System.Runtime": "4.0.21-beta-*"
		},

		"frameworks": {
			"dnxcore50": { }
		}
}
```

Now while you're in the directory that contains your project you can run the following command to build and publish your lambda :

`>docker run --rm -v "$PWD":/dotnet_call -w /dotnet_call microsoft/dotnet@sha256:19ab67ce4fc80a1c1c68c45961216805c2119336e51be2132d4b2487a6a7034b /bin/bash -c "dotnet restore && dotnet build && dotnet publish"`

The above command will mount your working directory as a writeable volume in the docker container, and then execute the commands necessary to pull down all the dependencies specified in your project, compild your code, and publish the executable and the dependencies in a directory for the specific runtime flavor (in this case `ubuntu:trust`)

You can then zip up the contents of your directory : `zip -r hello_world.zip *`

Then you specify your lambda payload like so :

```json
{
	"eventFilter": "com.awesome.HelloWorld",
		"artifactDescription": {
			"artifactUri": "https://s3.amazonaws.com/my.lambdas/hello_world.zip",
			"description": "super simple lambda for dotnet",
			"functionName": "doesntgetused",
			"handler": "bin/Debug/dnxcore50/ubuntu.14.04-x64/hello_world",
			"memorySize": 1024,
			"cpus": 0.2,
			"publish": false,
			"role": "doesntgetused",
			"runtime": "dotnet",
			"timeoutSecs": 180
		}
}
```

Once you have your payload, you simply `POST` to the `/lambdas` endpoint for the lambda service :

`POST <hostname>/lambdas < payload.json`

And you can invoke it like so :

`POST <hostname>/lambdas/{id}/invoke < event.payload.json`

repository: GalacticFog/gestalt-lambda

repo_name: GalacticFog/gestalt-lambda


text:
# Surface anaLysis And Modeling (Slam)

[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors-)

[![Build Status](https://travis-ci.org/gauzias/slam.svg?branch=master)](https://travis-ci.org/gauzias/slam)
[![Coverage Status](https://coveralls.io/repos/github/gauzias/slam/badge.svg?branch=master)](https://coveralls.io/github/gauzias/slam?branch=master)

Slam is an open source python package dedicated to the representation of
neuroanatomical surfaces stemming from MRI data in the form of triangular meshes and to their processing and analysis.
Slam is an extension of [Trimesh](https://github.com/mikedh/trimesh), an open source python package dedicated to triangular meshes processing.

## Main Features

   Look at the [doc](https://brain-slam.github.io/slam) for a complete overview of available features!

+ ``io``: read/write gifti (and nifti) file format

+ ``generate_parametric_surfaces``: generation of parametric surfaces with random sampling

+ ``geodesics``: geodesic distance computation using tvb-gdist and networkx

+ ``differential_geometry``: several implementations of graph Laplacian (conformal, authalic, FEM...), texture Gradient

+ ``mapping``: several types of mapping between the mesh and a sphere, a disc...

+ ``distortion``: distortion measures between two meshes, for quantitative analysis of mapping properties

+ ``remeshing``: projection of vertex-level information between two meshes based on their spherical representation

+ ``topology``: mesh surgery (boundary indentification, large hole closing)

+ ``vertex_voronoi``: compute the voronoi of each vertex of a mesh, usefull for numerous applications

+ ``texture``: a class to manage properly vertex-level information.

+ ``plot``: extension of pyglet and visbrain viewers to visualize slam objects

## For contributors

### Code of conduct
The very first thing to do before contributing is to read our
[Code of conduct](CODE_OF_CONDUCT.md).

### Have a look at the github project!
We are using a github project to organize the code development and maintenance:
https://github.com/orgs/brain-slam/projects/1

If you are interested in contributing, please first have a look at it and contact us by creating a new issue.

### Contributors Installation
#### Prerequisites
1. [Create an account](https://github.com/) on Github if you do not already have one
2. Sign in GitHub and fork  the [slam GitHub repository](https://github.com/brain-slam/slam)
3. We highly recommend to rely on a (conda) virtual environment as provided by miniconda.
 See [miniconda installation instructions](https://docs.conda.io/en/latest/miniconda.html)  if you do not already have one.
 Then create a virtual environment by typing the following lines in a terminal:
  ```
    conda create -q -n slam python=3.8
    conda activate slam
  ```
 This creates an empty conda virtual environment with Python 3.8 and basic packages
  (e.g. pip, setuptools) and make it the default python environment.
#### Installation
1. Clone your personal slam fork in your current local directory
    ```# replace <username> by your Github login
    git clone https://github.com/<username>/slam
    ```
2. Perform a full slam installation in editable mode
   ```
    pip install -e .['dev']
   ```
5. Set upstream repository to keep your clone up-to-date
   ```
    git remote add upstream https://github.com/brain-slam/slam.git
   ```
You are now ready to modify slam code and submit a pull request

## Dependencies
These dependencies, whether mandatory or optional, are managed automatically and transparently for the user during the installation phase and are listed here for the sake of completeness.

### Mandatory
In order to work fine, slam requires:

+ a Python 3.8 installation

+ setuptools

+ pip

+  numpy

+  scipy

+  cython

+  trimesh

+  nibabel

### Distance computation (Optional)

tvb-gdist is recommended for geodesic distance/shortest paths computations

## Hall of fame

All contributions are of course much welcome!
In addition to the global thank you to all contributors to this project, a special big thanks to:

. https://github.com/alexpron and https://github.com/davidmeunier79 for their precious help for setting up continuous integration tools.

. https://github.com/EtienneCmb for his help regarding visualization and Visbrain (https://github.com/EtienneCmb/visbrain).

. https://github.com/aymanesouani for his implementation of a very nice curvature estimation technique.

. https://github.com/Anthys for implementing the curvature decomposition and many unitests

.  to be continued...

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

alexpron
🚧 📆 🤔 💻

JulienLefevreMars
💻 📖 💡 🤔 ⚠

Tianqi SONG
💻 💡 🤔

Etienne Combrisson
💻 🔧

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

repository: gauzias/slam

repo_name: gauzias/slam


text:
### [CVE-2022-48178](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-48178)
![](https://img.shields.io/static/v1?label=Product&message=n%2Fa&color=blue)
![](https://img.shields.io/static/v1?label=Version&message=n%2Fa&color=blue)
![](https://img.shields.io/static/v1?label=Vulnerability&message=n%2Fa&color=brighgreen)

### Description

X2CRM Open Source Sales CRM 6.6 and 6.9 was discovered to contain a stored cross-site scripting (XSS) vulnerability via the Create Action function, aka an index.php/actions/update URI.

### POC

#### Reference
- http://packetstormsecurity.com/files/171792/X2CRM-6.6-6.9-Cross-Site-Scripting.html

#### Github
No PoCs found on GitHub currently.

repository: trickest/cve

repo_name: trickest/cve