text:
---
title: Proximity
author: Jeremy
tags: [life]
imagelink: Proximity
permalink: /789
date: 2023-08-18
---

![A graph of "How easy it is to solve" versus "Proximity to the problem". It's an inverse relationship, with it being harder to solve the problem when it's closer to you.](https://res.cloudinary.com/dh3hm8pb7/image/upload/q_auto:best/v1535842782/Handwaving/Published/{{ page.imagelink }}.png){: .centre-image }

Without that emotional attachment, it sure is easy to prescribe what to do for others!


text:
---
path: "/modern-react-with-redux-section2-lecture-29-33"
date: "2018-03-25"
title: "Mordern React with Redux Section 2 Lecture 29-33"
---

In these videos, I learn to pass data around with props. But from time to time I still ask myself why React needs to have instances every time we want to pass something to its. At first I think these kind of things only occur with class base component but then function base component behaves the same way so I guess it is some sort of React mystery. (or I can go back to Lecture 10 Section 1).

With a list of item react need a key for each item.

I got a problem with the screen when they are in different sizes. Things in there are crammed when it is a big screen and become better with smaller screen. I wrote about this in here:

https://github.com/freeCodeCamp-Hanoi/learn-react-udemy/issues/8

I tends to be forgetful sometimes so I need to remind myself that the main reason I write this blog is to explain code for myself. Therefore, no question should be left unasked and I should not be hesitate to speak my mind. So these are few things that bother me:

![First bothering thing](http://res.cloudinary.com/hunghayho131/image/upload/v1530354607/bother1.jpg)

In the code above, what are **video-list media**, **media-left** and **media-heading**? And **why do we need those things?** They are not explained in the docs of Bootstrap 4 is one thing but Stephen don't tell me about is another thing. (*Well actually he has the Q&A section but I will do it later*). Then I have this one.

![Second bothering thing](http://res.cloudinary.com/hunghayho131/image/upload/v1530354607/bother2.jpg)

Despite of reading these things in the Boostrap 4 docs, I still don't get used to it (*This is just me, my stupidity and my personality. May want to work on that!*) and come to term with it.  (*Unlike you Hung! Stephen must have studied very detailed about youtube api. Number four](http://res.cloudinary.com/hunghayho131/image/upload/v1530354607/bother4.jpg)

Again! **How did he know this syntax to access Youtube api?** (*Again! Did you read the docs Hung?*)

![Last thing](http://res.cloudinary.com/hunghayho131/image/upload/v1530354607/bother5.jpg)

**How did he come up with the idea of constructing this object?**

I will have to answer these questions if I want to understand React better. That might not be an issue if I had a photographic memory and a stronger brain but I should do what I can.

license: MIT

branch_name: refs/heads/master

extension: md

license_type: permissive


text:
# Node Field Selectors

![GA](assets/ga.svg)

> v2.8 and after

## Introduction

The resume, stop and retry Argo CLI and API commands support a `--node-field-selector` parameter to allow the user to select a subset of nodes for the command to apply to.

In the case of the resume and stop commands these are the nodes that should be resumed or stopped.

In the case of the retry command it allows specifying nodes that should be restarted even if they were previously successful (and must be used in combination with `--restart-successful`)

The format of this when used with the CLI is:

```--node-field-selector=FIELD=VALUE```

## Possible options

The field can be any of:

| Field | Description|
|----------|------------|
| `displayName`| Display name of the node. This is the name of the node as it is displayed on the CLI or UI, without considering its ancestors (see example below). This is a useful shortcut if there is only one node with the same `displayName` |
| `name`| Full name of the node. This is the full name of the node, including its ancestors (see example below). Using `name` is necessary when two or more nodes share the same `displayName` and disambiguation is required. |
| `templateName`| Template name of the node |
| `phase`| Phase status of the node - eg Running |
| `templateRef.name`| The name of the WorkflowTemplate the node is referring to |
| `templateRef.template`| The template within the WorkflowTemplate the node is referring to |
| `inputs.parameters.<NAME>.value`| The value of input parameter NAME |

The operator can be '=' or '!='. Multiple selectors can be combined with a comma, in which case they are ANDed together.

## Examples

To filter for nodes where the input parameter 'foo' is equal to 'bar':

```--node-field-selector=inputs.parameters.foo.value=bar```

To filter for nodes where the input parameter 'foo' is equal to 'bar' and phase is not running:

```--node-field-selector=foo1=bar1,phase!=Running```

Consider the following workflow:

```
 ● appr-promotion-ffsv4    code-release
 ├─✔ start                 sample-template/email                 appr-promotion-ffsv4-3704914002  2s
 ├─● app1                  wftempl1/approval-and-promotion
 │ ├─✔ notification-email  sample-template/email                 appr-promotion-ffsv4-524476380   2s
 │ └─ǁ wait-approval       sample-template/waiting-for-approval
 ├─✔ app2                  wftempl2/promotion
 │ ├─✔ notification-email  sample-template/email                 appr-promotion-ffsv4-2580536603  2s
 │ ├─✔ pr-approval         sample-template/approval              appr-promotion-ffsv4-3445567645  2s
 │ └─✔ deployment          sample-template/promote               appr-promotion-ffsv4-970728982   1s
 └─● app3                  wftempl1/approval-and-promotion
   ├─✔ notification-email  sample-template/email                 appr-promotion-ffsv4-388318034   2s
   └─ǁ wait-approval       sample-template/waiting-for-approval
```

Here we have two steps with the same `displayName`: `wait-approval`. To select one to suspend, we need to use their
`name`, either `appr-promotion-ffsv4.app1.wait-approval` or `appr-promotion-ffsv4.app2.wait-approval`. If it is not clear
what the full name of a done is, it can be found using `kubectl`:

```
$ kubectl get wf appr-promotion-ffsv4 -o yaml

...
    appr-promotion-ffsv4-3235686597:
      boundaryID: appr-promotion-ffsv4-3079407832
      displayName: wait-approval                        # <- Display Name
      finishedAt: null
      id: appr-promotion-ffsv4-3235686597
      name: appr-promotion-ffsv4.app1.wait-approval     # <- Full Name
      phase: Running
      startedAt: "2021-01-20T17:00:25Z"
      templateRef:
        name: sample-template
        template: waiting-for-approval
      templateScope: namespaced/wftempl1
      type: Suspend
...
```

repository: coreweave/argo

gha_language: Go

repo_name: coreweave/argo


text:
# Datanectar is a base architecture for large-scale, production-ready, ETL and data science jobs.

## Goals
1. Dependency based task chain execution workflow (one task's completion is the requirement for the next downstream task, etc.)
2. Task idempotency
3. Task failover resolution
4. Task logging
5. Task visualization front-end
6. Dynamically built API
7. Bridging the gap between data science and software engineering (lets the data scientists worry about the data science and provides a software engineering backend for them to work with and go directly to production)

### Dependency based task chain execution workflow
Datanectar heavily leverages Spotify's [luigi](https://media.readthedocs.org/pdf/luigi/latest/luigi.pdf).  Luigi provides a very nice architecture for dependency based task chain workflows.  Since there is a plethora of documentation on the project, I'm going to defer going deeper to their docs.

### Dynamically built backend schema
Datanectar builds target locations based on project-level code locations by looking within the code directory.

### Task failover resolution
Due to the fact we have achieved idempotency in the project, if we have a 5 step task chain and step 3 fails, we can simply pick back up at step 3 after the bug is fixed.  Our step 1-3 targets (the output of our tasks) are already in S3 (or our local filesystem if we're doing local dev).

### Task logging
Datanectar creates tempfiles and pushes them to S3 out of the box for us.

### Task visualization front-end
Thanks to the authors of luigi, we get a d3 directed acyclic graph of tasks, their statuses, and stack traces for free.  Since datanectar uses luigi, this is available fo free

### Dynamically built API
Datanectar imposes certain taxonomy on the developer to make use of a dynamically available API for HTTP based task execution (if desired).
* All task chains must live under some chains/[somechaintype] dir.
* The actual chain definition in python code must be suffixed with _chain.py.  Ex. (hello_luigiworld_chain.py).
* The Task classes within the chain.py file must be suffixed with Task Ex. (TestS3Task, DownstreamTask, ETLTask).
If these schema and taxonomy are not followed, there will be no API availability at (http://localhost:5000/api/chains or your custom project URI in production).

## Local Setup
* checkout the project `git clone https://github.com/wesmadrigal/datanectar`
* `cd datanectar`
* build the virtual environment: `virtualenv venv`
* install dependencies: `venv/bin/pip install -r configuration/requirements.txt`
* startup the luigi server: `source venv/bin/activate && luigid`
* startup the app server: `cd ~/path/to/datanectar/code/ && ../venv/bin/python app.py`
* visit http://localhost:5000 (app front-end)
* visit http://localhost:8082 (luigi front-end)

## API and Hello World task (Local)
* make sure you've got the app and luigi running (final steps in local setup)
* visit http://localhost:5000/api/chains to explore the available task chains
* we'll be using the test chain at http://localhost:5000/api/chains/testchains/hello_luigiworld_chain
* fire up a python shell (you'll need the `requests` package)
* in the python shell execute the following:
* `import requests`
* `r = requests.post('http://localhost:5000/api/chains/testchains/hello_luigiworld_chain/TestS3Task')
* `print r.text`
```
{
  "data": {
    "expires_in": 600,
    "status_url": "http://localhost:5000/api/chainstatus?chain=chains/testchains/hello_luigiworld_chain/TestS3Task/b226f1826734303ca9d39d79f960b367/out.txt"
  },
  "message": "success",
  "status": 200
}
```
* `status = requests.get('http://localhost:5000/api/chainstatus?chain=chains/testchains/hello_luigiworld_chain/TestS3Task/b226f1826734303ca9d39d79f960b367/out.txt')`
* `print status.text`
```
{
data: {
expires_in: null,
job_status: "RUNNING",
resource_url: null
},
message: "success",
status: 200
}
```
* visit http://localhost:8082 and check the status on the luigi front-end (the API mirrors this status)
* when the task finally finishes (after about 2 minutes), you should see the target in ~/path/to/datanectar/local_targets
* if you don't see it there, check the luigi front-end to see if a stack trace exists

## API and Hello World (production-ready REQUIRES AWS ACCESS)
* this is where our Environment variables come in
* in your ~/.bash_profile or ~/.profile dependening on your distribution, set the following
* `AWS_ACCESS_KEY_ID=YOURKEY`
* `AWS_SECRET_ACCESS_KEY=YOURSECRET`
* `ENV=(qa, prod, or your preference for env name but needs to be something other than local)`
* `PROJECT_BUCKET=yourcustomprojectname`
* Now that we have our environment variables set, make sure you've resourced the environment in all relevant terminals before continuing `source ~/.bash_profile` or `source ~/.profile`
* fire up the app server
* `cd ~/path/to/datanectar/code && ../venv/bin/python app.py`
* fire up luigi
* `cd ~/path/to/datanectar && venv/bin/python luigid`
* ok, given that your AWS credentials are correct we will now do the same as the local hello world but our output will go to s3 instead of our local machine
* fire up a python shell and execute the following commands
* `import requests, json`
* `r = requests.post('http://localhost:5000/api/chains/testchains/TestS3Task')
* `status_url = json.loads(r.text)['data']['status_url'])`
* when the task finishes this time, our status URL will respond with the S3 resource
* `status_resource = requests.get(status_url)`
* `print status_resource.text`
```
{
  "data": {
    "expires_in": 600,
    "job_status": null,
    "resource_url": "https://qa.datanectartest.s3.amazonaws.com/chains/testchains/hello_luigiworld_chain/TestS3Task/b226f1826734303ca9d39d79f960b367/out.txt?Signature=2DVZzbEJEFjcgNBELrJPe0S2wwc%3D&Expires=1464972637&AWSAccessKeyId=obfuscated"
  },
  "message": "success",
  "status": 200
}
```
* that resource_url is the path to your luigi.Target which is defined in your task
* now, you can check the front-ends just like before, but now navigate to your [s3 console](https://console.aws.amazon.com/s3/home?region=us-west-2#)
* you should see an s3 bucket with your `ENV.PROJECT_BUCKET` environment variables
* The S3 bucket schema mirrors our project structure
* The S3 bucket path will be chains/testchains/hello_luigiworld_chain/TestS3Task
* inside `TestS3Task` key you should see an MD5 hash, which represents the task you just executed, click that
* inside that hash you should see out.txt, log, and params.txt
* out.txt is the Target output of your task
* logs contains the stdout and stderr of our task execution
* params.txt contains the parameters provided for this task

## More on architecture

Chains

   * all chains live under the code/chains/* directory
   * chain types
      * all chain types live under the code/chains/[TYPE] directory structure
      * example: code/chains/agg
         * all chains under this directory will be of type agg
   * all chains should be suffixed with _chain.py (example: hello_world_chain.py)
      * this allows our code.api.api_chains.APIChainCollector to infer which modules under relevant directories are actually chains
      * this also allows for out-of-the-box exposure and access via the data nectar api: /api/chains/*

Tasks

   * all tasks should live within a _chain.py module
   * all tasks should be suffixed with Task (example: NectarS3Task)
   * all tasks desiring to target to S3 (this should be almost all of our tasks) should inherit from the NectarS3Task (code.util.s3task.NectarS3Task)

API

   * the datanectar API is a dynamically built and maintained API based on the above mentioned naming conventions
   * anything under chains/[TYPE]/some_chain.py will be dynamically exposed and accessible via the API
   * anything WITHOUT the proper naming conventions will not be exposed or accessible via the API, and that’s totally fine if we want to isolate some things
   * execution
      * all the API does is allow HTTP access to the luigi Tasks, so where a task might be normally invoked in python like:
         * SomeLuigiTask(param1=hello, param2=world).run()
      * the api access is as follows:
         * POST /api/chains/[TYPE]/some_chain/SomeLuigiTask?param1=hello&param2=world
   * responses
      * the API will provide an HTTP response by default with an ephemeral s3 url for the target created by the task like:

```
                    {
  "data": {
    "expires_in": 60,
    "target_url": "https://qa.datanectar.s3.amazonaws.com/chains/test/hello_world_chain/TestS3Task/testdocker?Signature=3lFmgIabBQ9s51M1M2ajKiix4po%3D&Expires=1458956284&AWSAccessKeyId=obfuscated"
  },
  "message": "success",
  "status": 200
}
```

Copyright 2021 Wes Madrigal

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: wesmadrigal/datanectar

repo_name: wesmadrigal/datanectar


text:
# Development Strategy

> App Theme Website

write a short description of your project:
- Users who want to download the app or get information about it.
- To read about the features that the app contains.

## Wireframe

<!-- include a wireframe for your project in this repository, and display it here -->
<!-- wireframe.cc is a good site for getting started with wireframes -->
![Wireframe - app-design](https://user-images.githubusercontent.com/60271901/95391768-0fda7080-0911-11eb-88af-a35869dd46da.png)

## 0. Set-Up

__A User can see my initial repository and live demo__

### Repo

- Generate from Template
- Write initial, basic README
- Turn on GitHub Pages
- Clone repo to work locally

## 1. __

__full user story description__

### Repo

Worked on Index branches:
* Header
* Showcase
* Features
* Info
* Footer

Worked on About page branches:
* Header
* Main
* Footer

Worked on Services page branches:
* Header
* Main
* Footer

Worked on Contact page branches:
* Header
* Main
* Footer

Worked on images branch
* Added image files to repo

Worked on additional css branches
* Added flexboxgrid
* Added Font awesome css

### HTML

Changed the font, changed image links.

### CSS

Changed image links.

## 2. Steps to follow
* Clone the repo
* Create project board

### Steps to Repeat for each branch.
* Add a note to the project board
* Convert it to issue
* Create Branch
* Checkout to Branch
* Add Code
* Git Add
* Git Commit
* Git Push - u new branch
* Go to github, compare and pull
* Link PR to the issue
* Merge
* Move it to done on the project board
* Git Checkout master (in terminal)
* Git Pull to pull remote changes locally.

## Finishing Touches

  - [README](https://github.com/sharafcs50/app-theme/blob/master/README.md)

gha_language: HTML

gha_license_id: MIT


text:
---
layout: post
cover: 'assets/images/pexels-eric-hammett-2989658.jpg'
logo: 'assets/images/logo.jpg'
navigation: true
author: jyeary
disqus: true
date: 2021-01-15 00:00:00+00:00
title: Running Kibana on Docker
categories: jyeary
tags: web
subclass: 'post tag-web'
---

There are a number of documents on how to run Kibana on Docker using a `docker-compose` file. The instructions from Elastic have you create a link, but there is nothing as simple as the commands below.

```
docker container run -d --rm -e ELASTICSEARCH_HOSTS=https://{YOUR_SERVER_IP_HERE}:9200 -p 5601:5601 docker.elastic.co/kibana/kibana:7.10.0
```

This will create an instance of Kibana that is removed when you are done with it. You just need to replace the `{YOUR_SERVER_IP_HERE}` with the IP address or DNS name of the server, e.g. localhost.

If you need to provide a custom `kibana.yml`, you can create the files locally and bind mount them as shown below.

### Powershell Example

```
docker container run -d --rm -e ELASTICSEARCH_HOSTS=https://{YOUR_SERVER_IP_HERE}:9200 -v ${PWD}/kibana/:/usr/share/kibana/config/ -p 5601:5601 docker.elastic.co/kibana/kibana:7.10.0
```

### MacOS/Linux/UNIX Example

```
docker container run -d --rm -e ELASTICSEARCH_HOSTS=https://{YOUR_SERVER_IP_HERE}:9200 -v $(PWD)/kibana/:/usr/share/kibana/config/ -p 5601:5601 docker.elastic.co/kibana/kibana:7.10.0
```

gha_language: CSS


text:
# Chat

A fork of the [node.js chat app](https://github.com/eiriksm/chat-test-2k) by [@orkj](https://twitter.com/orkj)
using socket.io, rethinkdb, passport and bcrypt on an express app.

Note:
 This is an example application. Even though it shows an example of how to integrate Passport and bcrypt, you shouldn't assume it is free from security vulnerabilities. Have the code audited carefully by an expert before you put anything modeled on it into production.

# Complete stack #

* [node.js](http://nodejs.org)
* [socket.io](http://socket.io)
* [express](http://expressjs.com) and [jade](http://jade-lang.com)
* [Passport](http://passportjs.org) and [bcrypt](https://github.com/ncb000gt/node.bcrypt.js/)
* [debug](https://github.com/visionmedia/debug)
* [RethinkDB](http://www.rethinkdb.com/)

# Installation #

```
git clone https://github.com/Kapranov/chat-rethinkdb
cd chat-rethinkdb && npm install
```

_Note_: If you don't have RethinkDB installed, you can follow [these instructions to get it up and running](http://www.rethinkdb.com/docs/install/).

# Running the application #

Running the app is as simple as:

```
node app
```

Then open a browser: <http://localhost:8000>.

_Note_: If you want to override the default RethinkDB connection details, you can
specify them as environment variables:

* `RDB_HOST`: the RethinkDB host (default: `localhost`)
* `RDB_PORT`: the port (default `28015`)
* `RDB_DB`: the app database (default: `chat`)

If you want to enable logging for the database queries (see [debug docs](https://github.com/visionmedia/debug)
for more configuration options:

```
DEBUG=rdb:* node app
```

# Fixed fix deprecation issue Node v7.2.0

```
(DeprecationWarning: Using Buffer without `new` will soon stop working.
Use `new Buffer()`, or preferably `Buffer.from()`, `Buffer.allocUnsafe()`
or `Buffer.alloc()` instead.)
```

>  Edit file ``net.js``

```javascript
# chat-rethinkdb/node_modules/rethinkdb/net.js

node --trace-deprecation app.js

- 550: _this.rawSocket.write(Buffer.concat([version, Buffer(message.toString()), nullbyte]));
+ 550: _this.rawSocket.write(Buffer.concat([version, new Buffer(message.toString()), nullbyte]));

and

- 675 _this.rawSocket.write(Buffer.concat([Buffer(message.toString()), nullbyte]));
+ 675 _this.rawSocket.write(Buffer.concat([new Buffer(message.toString()), nullbyte]));

```

# License #

This demo application is licensed under the MIT license: <http://opensource.org/licenses/mit-license.php>

repository: Kapranov/chat-rethinkdb

repo_name: Kapranov/chat-rethinkdb


text:
+++
# Display name
name = "Lele Shu"
weight = 10
# Username (this should match the folder name)
authors = ["LeleShu"]

# Is this the primary user of the site?
superuser = true

# Role/position
role = "Ph.D, associate professor, lead of the SHUD project"

# Organizations/Affiliations
#   Separate multiple entries with a comma, using the form: `[ {name="Org1", url=""}, {name="Org2", url=""} ]`.
organizations = [ {name=" NIEER, CAS", url="https://www.nieer.ac.cn"}, {name="LPCC, CAS", url="http://lpcc.careeri.cas.cn/"}  ]
# {name="Pennsylvania State University", url="www.psu.edu"} ]

# Short bio (displayed in user profile at end of posts)
bio = "Associate professor on numeric hydrologic modeling, impact of landuse and climate change, and Coupled-Nature-Human System"

# Enter email to display Gravatar (if Gravatar enabled in Config)
# email =<EMAIL_ADDRESS>
# List (academic) interests or hobbies
interests = [
'Hydrological response under stress of climate and landuse change',
'Hydrology/remote-sensing data informatics',
'Spatial heterogeneity and homogeneity and their sensitivity to controls',
'High-performance/parallel computing in hydrologic models',
'Coupled Nature-Human watershed modeling']

# Organizational groups that you belong to (for People widget)
#   Set this to `[]` or comment out if you are not using People widget.
user_groups = ["Principal Investigators", "Researchers", "Lead", "Contributors", "Member"]

# List qualifications (such as academic degrees)
[[education.courses]]
  course = "Ph.D in Water Resources Engineering and Computational Science"
  institution = "Pennsylvania State University "
  year = 2017

[[education.courses]]
  course = "M.S. in Remote Sensing"
  institution = "University of Chinese Academy of Sciences (Lanzhou, China)"
  year = 2009

[[education.courses]]
  course = "B.S in Geography Information System"
  institution = "Lanzhou University (Lanzhou, China)"
  year = 2005

# Social/Academic Networking
# For available icons, see: https://sourcethemes.com/academic/docs/widgets/#icons
#   For an email link, use "fas" icon pack, "envelope" icon, and a link in the
#   form<EMAIL_ADDRESS>or "#contact" for contact widget.

[[social]]
  icon = "fa-external-link"
  icon_pack = "fas"
  link ="http://www.shulele.net"
[[social]]
  icon = "envelope"
  icon_pack = "fas"
  link<EMAIL_ADDRESS>#  link = "#contact"  # For a direct email link, use<EMAIL_ADDRESS>
[[social]]
  icon = "twitter"
  icon_pack = "fab"
  link = "https://twitter.com/leleshu"

[[social]]
  icon = "google-scholar"
  icon_pack = "ai"
  link = "https://scholar.google.com/citations?user=6yiZVfkAAAAJ&hl=en"

[[social]]
  icon = "github"
  icon_pack = "fab"
  link = "https://github.com/shulele"

[[social]]
  icon = "weixin"
  icon_pack = "fab"
  link = "../../img/weixin.jpg"
# Link to a PDF of your resume/CV from the About widget.
# To enable, copy your resume/CV to `static/files/cv.pdf` and uncomment the lines below.
[[social]]
   icon = "cv"
   icon_pack = "ai"
   link = "/cv/LeleShu_CV.pdf"

+++

Dr. Shu is an associate professor at Northwest Institute of Eco-Environment and Resources, Chinese Academy of Sciences (NIEER, CAS). He obtained a Ph.D. degree in Water Resource Engineering and a minor degree of Computational Science from Pennsylvania State University in 2017. He is the lead developer of the Simulator for Hydrologic Unstructured Domains(SHUD) model. His major interests are computational hydrologic model, hydrologic data mining, and integrated Coupled Nature-Human System modeling.

repository: shulele/Be-A-Hydrologist

repo_name: shulele/Be-A-Hydrologist


text:
# CreateFiles
Create Files is a simple project Node.js that create files dinamically. You can seetting quantity of files and time interval in seconds that you need.  Once you execute code, the files created before will delete because the new process will create new files.

## Installation
Clone the repository
```bash
git clone https://github.com/jmsg78/createFiles.git
```
Locate the path where you cloned the repository and you can run
```bash
node src/createFile.js
```
or If You have install nodemon, You could execute it
```bash
nodemon src/createFile.js
```
### Executing code
You can see in the following image to know how the file is executed with nodemon
![Begin](/screenshot/BeginProcess.png)
This image also shows when files have been deleted , because is a process that execute before of create the new files.
### Creating and Reading Files
![CreatingAndReadingFiles](/screenshot/MessageLanguages.png)
This image shows when files have been created, also You can see the messages in different languages, once read it.
les. In this case, the creation of 5 files was requested in an interval of 60 seconds each.
### End
![FinishedProcess](/screenshot/ProcessFinished.png)
When the code creates all the requested files in the established time interval, it sends a process finished message.

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License
[MIT](https://choosealicense.com/licenses/mit/)


text:
# Learn C++

## [C++ For C Programmers, Part A](https://www.coursera.org/learn/c-plus-plus-a/)
## [C++ For C Programmers, Part B](https://www.coursera.org/learn/c-plus-plus-b/)
## [Accelerated Computer Science Fundamentals Specialization](https://www.coursera.org/specializations/cs-fundamentals)

## Comments
Line comment
```C++
// This is a line comment
```
Block comment
```C++
/* This is
*  block comment
*/
```

## Data types and size
char: 1 byte
bool: 1 byte

## Resources
- [Sololearn.com](https://sololearn.com)
- [Learn C++ on CommonLounge](https://www.commonlounge.com/discussion/b7d5d197ea274a0f83eee5c1c9d17e8c/)

repository: tuyendq/lthwcplus

repo_name: tuyendq/lthwcplus


text:
# Azure Stream Analytics Toll App

## Introduction
A toll station is a common phenomenon. You encounter them on many expressways, bridges, and tunnels across the world. Each toll station has multiple toll booths. At manual booths, you stop to pay the toll to an attendant. At automated booths, a sensor on top of each booth scans an RFID card that's affixed to the windshield of your vehicle as you pass the toll booth. It is easy to visualize the passage of vehicles through these toll stations as an event stream over which interesting operations can be performed.

Toll App is a sample streaming application that demonstrates how to use Azure Stream Analytics to get real-time insights from your data. You can easily combine streams of data, such as click-streams, logs, and device-generated events, with historical records or reference data to derive business insights. As a fully managed, real-time stream computation service that's hosted in Microsoft Azure, Azure Stream Analytics provides built-in resiliency, low latency, and scalability to get you up and running in minutes.

For more information about TollApp sample, please see  "Build an IoT solution by using Stream Analytics."

For more information about the Stream Analytics service, see http://azure.microsoft.com/en-us/services/stream-analytics/

## Setup Toll App on Azure
### Prerequisites
* A Microsoft account. You can get a free Microsoft account from http://account.live.com.
* An Azure account. You can sign-up for a free trial Azure account from http://azure.microsoft.com/en-us/pricing/free-trial/.

### Deploy
To deploy the app to Azure, click the link below. Deploy the app in a new resource group, select an Azure location, and provide a short *user* value that will be appended to several resource names to make them globally unique. Your initials and a number is a good pattern to use.

Verify that the Azure Stream Analytics TollApp deployment was successful
1. Log into Microsoft Azure Portal
1. Go to Resource Groups
1. Select the Resource Group name used during deployment
1. Verify that the following services are listed:
    * One Cosmos DB Account
    * One Azure Stream Analytics Job
    * One Azure Storage Account
    * One Azure Event Hub
    * Two Web Apps

When the application is deployed the interval timer is set. This will specify the amount of time between vehicles entering the tollbooth in seconds.
To change this time update the TimerSetting value in the Web App application settings
* Log into Microsoft Azure Portal
* Open App Services
* Select the tollapp Web App
* Select Application settings
* Set the TimerSetting value to desired time in seconds.

The Azure Stream Analytics Job is not started upon deployment.
Steps to start the job
* Log into Microsoft Azure Portal
* Open Stream Analytics jobs
* Select the TollData job
* Click Start

## License
Microsoft Azure Stream Analytics sample application and tutorials are licensed under the MIT license. See the [LICENSE](https://github.com/Azure/azure-stream-analytics/blob/master/LICENSE.txt) file for more details.

repository: mamccrea/azure-stream-analytics

repo_name: mamccrea/azure-stream-analytics


text:
---
page_title: "spinnaker_pipeline"
---

# spinnaker_pipeline Resource

Manage spinnaker pipeline

## Example Usage

```
provider "spinnaker" {
    server = "http://spinnaker-gate.myorg.io"
}

resource "spinnaker_application" "terraform_example" {
    application = "terraformexample"
    email       =<EMAIL_ADDRESS>}

resource "spinnaker_pipeline" "terraform_example" {
    application = spinnaker_application.terraform_example.application
    name        = "Example Pipeline"
    pipeline    = file("pipelines/example.json")
}
```

## Argument Reference

- `application` - (Required) Spinnaker application name.
- `name` - (Required) Pipeline name.
- `pipeline` - (Required) Pipeline json

## Attribute Reference

In addition to the above, the following attributes are exported:

- `pipeline_id` - Pipeline ID


text:
---
layout: post
title:  "Optimizing with Karnush-Kuhn-Tucker conditions"
date:   2019-04-25 08:00:00 -0600
categories: update
---
{% include mathJax.html %}
# Spaceship to Mars
The goal is to optimize a non trivial model with multiple parameters and conditions using `pyTorch.optim` and **Karnush-Kuhn-Tucker** (KKT)

We want to send a spacecraft from Earth to Mars in a straight line at constant speed, Ignoring gravity and Orbital mechanics ([see this otherwise](https://www.jpl.nasa.gov/edu/teach/activity/lets-go-to-mars-calculating-launch-windows/))
{% include videoPlayer.html file="tomars/toMars0.mp4" %}
All the code and additional details can be found [here](https://colab.research.google.com/drive/1TkazncDHYCHdxeyKk9e4eZnBvnTBW1JW)

#### Assumptions
* Traveling on a straight line with constant speed
* The path of Mars and Earth are perfectly circular around the sun and move on the same inclination

#### Requirements
* Select the time from now to launch the spaceship
* Tell how many days it will take the spaceship to travel
* Max speed allowed is 0.5 M km/day

# Unconstrained

We will build our model with [`PyTorch.Optim`](https://pytorch.org/docs/stable/optim.html), [here](/page/optim/2019-04-25-optimizing_with_torch) is a small post about that.

Fist we need some hard date to build the model, here is some knowledge we got from Wikipedia:
{% highlight python %}
import math

# Radius
rE = 149.6
rM = 227.9

# Periods
yearE = 365.25
yearM = 687.0

# Orbital speed
radE = 2*math.pi / yearE
radM = 2*math.pi / yearM

# Given max speed
max_v = .5

# minimun fly time
time_min = (rM - rE)/max_v
{% endhighlight %}

Given this data we can now calculate where every planet is given a point in time.

$$\begin{equation}
   calcPosXY(t,rad, r)= (x,y) | x=cos(t, rad)r \land y=sin(t, rad)r \\
\end{equation}$$

{% highlight python %}
def calct_x(date,rad,r):
    return torch.cos(date*rad)*r

def calct_y(date,rad,r):
    return torch.sin(date*rad)*r

def calct_xy(date,rad,r):
    return calct_x(date,rad,r),calct_y(date,rad,r)
{% endhighlight %}

If we have the launch date and the flight time we can also calculate the distance the rocket will travel.

$$\begin{equation}
   distance(t_{launch}, t_{flight})= \sqrt{(x_{mars}-x_{earth})^2+(y_{mars}-y_{earth})^2} | \\
   (x_{mars}, y_{mars})=calcPosXY(t_{launch}+t_{flight}, rad_{mars}, r_{mars}) \land  \\
   (x_{earth}, y_{earth})=calcPosXY(t_{launch}, rad_{earth}, r_{earth})
\end{equation}$$

{% highlight python %}
def distance(launch_date,flytime):
    xE,yE = calct_xy(launch_date, radE, rE)
    xM,yM = calct_xy(launch_date+flytime, radM, rM)
    return torch.sqrt(torch.pow(xE-xM,2)+torch.pow(yE-yM,2))
{% endhighlight %}

We can use the distance as a loss function. The reasoning behind this is that if we have minimal distance to travel we can travel to mars the fastest. If the distance was large we might be even traveling near by the sun, we don't want that.

## Good Parameter initialization

To calculate the distance we need two parameters:
{% highlight python %}
# Launch date: days starting from now
Launch = nn.Parameter(ft([200]))
# time spent in flight
time = nn.Parameter(ft([time_min]))
{% endhighlight %}

now we can minimize the loss with a optimizer, similar to the situation before:
{% highlight python %}
opt = Adam([Launch,time],lr = 1e-1)

for i in range(300):
  opt.zero_grad()
  Distance = distance(Launch, time)
  Distance.backward()
  opt.step()

flyDistance = distance(Launch, time)
print('Launch date=%f \tflighttime=%f\t distance=%f \tspeed=%f'%(Launch, time, flyDistance, flyDistance/time))
{% endhighlight %}
`Launch date=189.591919 	flighttime=167.008087	 distance=78.299988 	speed=0.468839`

[LINK TO CODE](https://colab.research.google.com/drive/1TkazncDHYCHdxeyKk9e4eZnBvnTBW1JW#scrollTo=f_5YVApYYFrq)

{% include videoPlayer.html file="tomars/toMars3.mp4" %}
Nice, we got a **Launch date in 189 days!** And its also the shortest route to the target because the **distance** is actually the same as the **Closest approach**. Speed is within bounds as well!

But there is a problem: **Its a lie!** Kind of a lie. The values work and are correct, but it's a manufactured situation because of the `Launch` initial value of `200` and `time` initial value of `time_min`.
> It works but not always.

## solution with bad starting point
lets do it again. Now with my favorite value and the only number I seem to remember
{% highlight python %}
# Launch date: days starting from now
Launch = nn.Parameter(ft([0]))
# time spent in flight
time = nn.Parameter(ft([0]))
{% endhighlight %}
`Launch date=0.000000 	flighttime=0.000000	 distance=78.299988 	speed=inf`

[LINK TO CODE](https://colab.research.google.com/drive/1TkazncDHYCHdxeyKk9e4eZnBvnTBW1JW#scrollTo=je9vNb7y17x5)

{% include videoPlayer.html file="tomars/toMars4.mp4" %}

**Ouff! We should launch right now with an infinite speed!**
* But why now? Well turns out our planetary models starting position (at Launch day 0) is in position of closest approach, meaning there is no closer distance to optimize toward.
* But why infinite speed? Because we made the sin of dividing by 0 in the print function.
lets do it again. Now lets chose a not perfect Launch day, and prevent a division by 0.

{% highlight python %}
# Launch date: days starting from now
Launch = nn.Parameter(ft([10]))
# time spent in flight
time = nn.Parameter(ft([0.1]))
{% endhighlight %}
`Launch date=5.369761 	flighttime=4.730242	 distance=78.299988 	speed=16.553061`

[LINK TO CODE](https://colab.research.google.com/drive/1TkazncDHYCHdxeyKk9e4eZnBvnTBW1JW#scrollTo=Bp7sE_tNxP2V)

{% include videoPlayer.html file="tomars/toMars5.mp4" %}
Well this is better but **not within the speed limit** of *0.5 M km/day*
We now have different options:
* Go on and search for good starting parameters where everything is within bounds, like the example with good parameter initialization. This is not really reliable but maybe good enough.
* Set the speed to constant max, this might be okay or might cause us to miss a good solution.
* Change the Optimization target, not just optimize for minimal distance but also minimal speed. Since in space changing speed means spending fuel(delta v), maybe it is a good idea to minimize it too.
* We can add speed constraints to the optimization with Karnush-Kuhn-Tucker. And then try to get to mars at minimal time.

> This solution is not useful.

## Constant max speed
lets see what happens if we just use the max speed in our model.
Since we know we travel in a straight line and at a constant speed we get a distance.
This distance needs to be the same as the one we get from the space between the planets. Therefore we need to minimize the delta between the two.

{% highlight python %}
# Launch date: days starting from now
Launch = nn.Parameter(ft([0]))
# time spent in flight
time = nn.Parameter(ft([0]))
{% endhighlight %}
We will use zero initialization.

{% highlight python %}
def distanceMaxSpeed(time):
  return time*max_v

opt = Adam([Launch,time],lr = 1)

for i in range(1000):
  opt.zero_grad()
  delta = torch.abs(distance(Launch, time) - distanceMaxSpeed(time))
  delta.backward()
  opt.step()

flyDistance = distance(Launch, time)
print('Launch date=%f \tflighttime=%f\t distance=%f \tspeed=%f'%(Launch, time, flyDistance, flyDistance/time))
{% endhighlight %}
`Launch date=173.894073 	flighttime=157.322617	 distance=78.611275 	speed=0.499682`

[LINK TO CODE](https://colab.research.google.com/drive/1TkazncDHYCHdxeyKk9e4eZnBvnTBW1JW#scrollTo=lilDzuuM1YFa)

{% include videoPlayer.html file="tomars/toMars6.mp4" %}
Nice, it worked! Notice that this one is better than the original (here we  have 10 days less travel). We can also start to search future opportunities.
{% include videoPlayer.html file="tomars/toMars7.mp4" %}
Not too surprising since we use `sin`, `cos` like in the optimizer introduction. Or in other words: Planets tend to come back around.

> This solution is not guaranteed to be the best.

## Minimal Speed
What if we want to save fuel? Fuel is used to accelerate and brake the spaceship, the less fuel we use the less speed we are going to need.
We calculate the speed and add it to our loss function, so it should be minimized. Lets see what happens here.

{% highlight python %}
opt = Adam([Launch,time],lr = 1)

for i in range(20000):
  opt.zero_grad()
  Distance =distance(Launch, time)
  speed = Distance/time
  loss = Distance + speed
  loss.backward()
  opt.step()

flyDistance = distance(Launch, time)
print('Launch date=%f \tflighttime=%f\t distance=%f \tspeed=%f'%(Launch, time, flyDistance, flyDistance/time))
{% endhighlight %}
`Launch date=1018.749268 	flighttime=897.419373	 distance=78.299988 	speed=0.087250`

[LINK TO CODE](https://colab.research.google.com/drive/1TkazncDHYCHdxeyKk9e4eZnBvnTBW1JW#scrollTo=T6bGTGpp7By-)

{% include videoPlayer.html file="tomars/toMars8.mp4" %}
A ton of iterations and still not at the optimum. What happened? Since the distance can not be less than the minimal distance between the planets *(78.299 M km)* the only gradient that can be minimized is the speed. Since planets tend to come around again we would just need a light push and wait for a long long time eventually we would arrive. That's where this optimization is going.
In reality there is gravity of all the celestial bodies causing this plan to fail. **This Strategy is not useful.**

> This solution is not useful.

# Constraint with Karnush-Kuhn-Tucker (KKT)
While it's great to minimize functions with an optimizer we sometimes have constraints that need to be followed, like our speed limit of *0.5 M km/day*.

There are different ways to do this. One way is to create or change our model so it is impossible to have values outside of our conditions. This is tricky and maybe not always possible. For example we could use speed instead of fly time in our model as a parameter. We then swap the speed with a function that binds it between 0 and 0.5 for any given meta speed parameter like sigmoid.

$$ speed(metaSpeed) = \frac{maxSpeed}{1+e^{-metaSpeed}}$$

A general way to constrain an optimization is the Karnush-Kuhn-Tucker method. It's quite tricky to explain this simply so I would recommend the great chapter [4.4 Constrained Optimization](https://www.deeplearningbook.org/contents/numerical.html) of the [deeplearningbook](https://www.deeplearningbook.org/).

---

Instead of a generalized problem I want to try explain it in applied situations. So let us start with the function to optimize:

$$f(x) = x^2 -x -1 | 1\leq x\leq5$$

Without the constraints $$1\leq x\leq5$$ we would have had the following optimization:

$$ \min_{x} f(x) = \min_{x} x^2 -x -1 $$

We did this already in the introduction of optimization section. But now we have the following inequality constraints and no equality constants:

$$\begin{equation}
   h_0: 1 - x \leq 0 \\
   h_1: x - 5 \leq 0
\end{equation}$$

---

Now let us look at the generalized Lagrangian:

$$\begin{equation}
   L(x,\lambda, \alpha) = f(x)+\sum_{i} \lambda_{i} g_{i}(x) + \sum_{j} \alpha_{j} h_{j}(x) \\
   f(x) \text{ is the function to optimize} \\
   \sum_{i} \lambda_{i} g_{i}(x) \text{ are the equality constants, we don't need them} \\
   \sum_{j} \alpha_{j} h_{j}(x) \text{ are the inequality constants, we have 2}
\end{equation}$$

By throwing away the empty sum for the equality constants and filling in the inequality constants we get:

$$\begin{equation}
   L(x,\alpha) = f(x) + lh_{0}(x)+ lh_{1}(x) \\
   L(x,\alpha) = f(x) + \alpha_{0} h_{0}(x)+ \alpha_{1} h_{1}(x) \\
   L(x,\alpha) = x^2 -x -1 + \alpha_{0} (1 - x)+ \alpha_{1}(x-5) \\
\end{equation}$$

And instead of optimizing all:

$$\begin{equation}
   \min_{x} \max_{\lambda} \max_{\alpha,\alpha \geq 0} L(x,\lambda, \alpha)
\end{equation}$$

we only need to optimize:

$$\begin{equation}
   \min_{x} \max_{\alpha,\alpha \geq 0} L(x,\alpha)
\end{equation}$$

Great! I know this can be confusing at first so let us observe two situations with the equations.

---

Once for within bounds `x=1` and once outside of them `x=0.5`

$$\begin{equation}
\text{x=1}\\
   L(x,\alpha) = x^2 -x -1 + \alpha_{0} (1 - x)+ \alpha_{1}(x-5) \\
   L(1,\alpha) = 1^2 -1 -1 + \alpha_{0} (1 - 1)+ \alpha_{1}(1-5)\\
   L(1,\alpha) = -1 + \alpha_{0} (0)+ \alpha_{1}(-4)
\end{equation}$$

Now let us chose an $$a$$ that makes this equation as big as possible:

$$\begin{equation}
   \max_{\alpha,\alpha \geq 0} L(1,\alpha) = \max_{\alpha,\alpha \geq 0} (-1 + \alpha_{0} (0)+ \alpha_{1}(-4) )\\
   \max_{\alpha,\alpha \geq 0} (\alpha_{0} * 0 )\to  \alpha_{0} = \infty \\
   \max_{\alpha,\alpha \geq 0} (\alpha_{1} * -4 )\to  \alpha_{1} = 0
\end{equation}$$

Both constraints have no way to increase the value of the term. Note $$\alpha_{1} = 0$$ because all $$\alpha$$ can only be positive.

But why $$\alpha_{0} = \infty$$? We plan to use gradient descent for our solution, this will cause our x to a bit under `x=1` causing the term to be slightly positive and that is why $$\alpha_{0}$$ will grow rather large, we will see this later. Since both terms end up 0 we remove them and get:

$$\begin{equation}
   L(1,\alpha) = -1 + \infty*0+ 0*-4 \\
   L(1,\alpha) = -1 = f(1) = f(x)
\end{equation}$$

Both constraints are satisfied and cause the terms to be zero. This is called *complementary slack*. We are left with the original $$f(x)$$.

---

Now let us observe the situation when a constraint is not satisfied anymore. `x=0.5` is actually the optimal solution without constraints. But with:

$$\begin{equation}
\text{x=0.5}\\
   L(x,\alpha) = x^2 -x -1 + \alpha_{0} (1 - x)+ \alpha_{1}(x-5) \\
   L(0.5,\alpha) = 0.5^2 -0.5 -1 + \alpha_{0} (1 - 0.5)+ \alpha_{1}(0.5-5)\\
   L(0.5,\alpha) = -1.25 + \alpha_{0} (0.5)+ \alpha_{1}(-4.5)
\end{equation}$$

Now let us chose an $$a$$ that makes this equation as big as possible:

$$\begin{equation}
   \max_{\alpha,\alpha \geq 0} L(0.5,\alpha) = \max_{\alpha,\alpha \geq 0} (-1.25 + \alpha_{0} (0.5)+ \alpha_{1}(-4.5) )\\
   \max_{\alpha,\alpha \geq 0} (\alpha_{0} * 0.5 )\to  \alpha_{0} = \infty \\
   \max_{\alpha,\alpha \geq 0} (\alpha_{1} * -4.5 )\to  \alpha_{1} = 0
\end{equation}$$

Note $$\alpha_{1} = 0$$ because all $$\alpha$$ can only be positive.
Now $$\alpha_{0} = \infty$$ because this way the term can be maximized.

$$\begin{equation}
   L(0.5,\alpha) = -1.25 + \infty*0.5+ 0*-4.5 \\
   L(0.5,\alpha) = \infty
\end{equation}$$

The Lagrangian does not end up being equal to $$f(x)$$ because the first constraint is not satisfied. The gradient of the function will change to push x back within bounds.

---

When using KKT to constrain a problem it is also important to check the following properties:
* The gradient of the generalized Lagrangian is 0. $$\frac{d}{d x} L(x,\lambda, \alpha) = 0$$
* The inequality constraints have _complementary slackness_. $$\alpha * h(x) = 0$$
* $$x$$ satisfies the conditions we set.

If this conditions are not met after the optimization we need to investigate and try to solve the problem.

## KKT applied
Let's apply the process of constraint optimization to code and then visualize it to see what happens to the KKT conditions. We will still use the same $$f(x) = x^2-x-1$$ with the constrains $$ 1\leq x \leq 5$$.

$$\begin{equation}
   f(x) = x^2-x-1 \\
   lh_0(x)= \alpha_{0} (1 - x) \\
   lh_1(x)= \alpha_{1} (x - 5) \\
   \min_{x}  \max_{\alpha, \alpha \geq 0 }  x^2 -x -1 + \alpha_{0} *(1 -x) + \alpha_{1} *(x-5)

\end{equation}$$

{% highlight python %}
x = nn.Parameter(ft([3]))
a0 = nn.Parameter(ft([1]))
a1 = nn.Parameter(ft([1]))

def f(x):
  return x**2 -1*x -1

#coditions
def h0(x):
  return 1 -x

def h1(x):
  return x -5

#lagrange conditions
def lh0(x, a):
  return torch.abs(a) * h0(x)

def lh1(x, a):
  return torch.abs(a) *h1(x)

def lagrange(x, a0, a1):
  return lh0(x, a0) +lh1(x,a1)

f_opt = Adam([x], lr=5e-2)
lagrange_opt = SGD([a0, a1], lr=8e-3)

for i in range(120):
  # maxing the a
  for k in range(10):
    lagrange_opt.zero_grad()
    lagrange_loss = -lagrange(x, a0, a1)
    lagrange_loss.backward()
    lagrange_opt.step()

  # minimizing x
  for m in range(5):
    f_opt.zero_grad()
    loss = f(x) + lagrange(x, a0, a1)
    loss.backward()
    f_opt.step()
{% endhighlight%}
The following should be noted about the implementation:
* First we introduce all the parameters. In order to keep the `a`'s positive we wrap them in the torch.abs or square them.
* Since we need to do two optimizations (min, max) we need two optimizers. One for the x and one for the a.
* first we max a for a given x. *Notice the sign swap at `-lagrange()` in the `k` loop as optimizes only minimize*.
* We now minimize the whole generalized Lagrangian. *Notice the `+lagrange()` in the `m` loop, no more sign swap* needed.

---

The optimization is successful if we see the following:
* All x constraints satisfied. The first plot (*north*) will show us where x ended up and the lower limit is marked.
* The gradient of the general lagragian is 0. This is shown by the middle middle (*center*) diagram, and to it's side the active components that create it (`f(x)`(*west*) and the `lh0(x)`(*east*))
* Complementary slack = 0. We find this in the lowest part of the diagramm, here in blue. Along with all the gradients of the lagragian (*south*).

{% include videoPlayer.html file="tomars/toMars9.mp4" %}
Focus on the north diagram.  See that the optimizer fist approaches `x=0.5` but once under the `x=1.0` line it goes back and finally balances on the `x=1.0` bound. Once the optimizer is settled our `x` satisfies all our requirements.

The west diagram shows the gradient of $$f(x)$$. It shows the steepens of the function $$f()$$ we originally want to optimize. Notice that during the whole time and even at the end this gradient always points to down to the left (lower x).

The eastern diagram shows the gradient of `a0*h0`.
* At first while x stays within the `x>=1` bound the gradient is 0, this means it has no influence on the optimization during that time.
* Once x passes the bound it jumps up in an attempt to get x back within its bounds.
* The x then goes back within its bounds and the gradient decreases again (if x would stay within the bounds it would go back to 0).
*  At the end the the gradient ends up to match the opposite of $$f(x)$$

The center diagram shows the generalized Lagrangian. It is basically the west and eastern diagram added together. This shows us how `x` will optimize in the next step.
* At fist the gradient is following the gradient of the function f.
* Once over the bound it increases so much as to actually cause x to go back up.
* It then goes back and fourth around the bound.
* At the end the gradient settles at 0. This means it found a minima.

The south diagram shows all of the gradients, including $$\frac{d}{dx}lh_1(x)$$ which stays at 0 since x is always staying bellow 5.
Notice the blue line `slack0:` $$lh_0(x)$$, it is one of the KKT conditions and should be 0 at the end, once x is out of bounds this one shoots up. The slack then settles at 0 once within bounds again.

### KKT applied to a different function
Now let us look at the same diagram but now with the function $$f(x)= x^2 -2.5x +0.5$$ and the constraints $$ 1\leq x \leq 5$$.

{% include videoPlayer.html file="tomars/toMars10.mp4" %}
Here we have a situation where we can see that constraints only influence the optimization while over the boundary. Make sure you see that all conditions are satisfied!

## To Mars with speed limits
Now let it put all together and solve our initial problem but now with speed constraints.

$$0 \leq speed \leq 0.5$$

{% highlight python %}
# Launch date: days starting from now
Launch = nn.Parameter(ft([0]))
# time spent in flight
time = nn.Parameter(ft([0.1]))
# Lagrange
a = nn.Parameter(ft([0.1, 0.1]))

def lagrange(x):
  return torch.abs(a[0])*(x-0.5) + torch.abs(a[1])*(-x)

def speed(day_launched, fly_time):
  return distance(day_launched, fly_time)/ fly_time

opt = Adam([Launch,time],lr = 2e-2)
lagrange_opt = SGD([a],lr = 2e-2)

for i in range(10000):
  for k in range(5):
    lagrange_opt.zero_grad()
    lagrange_loss = -lagrange(speed(Launch, time))
    lagrange_loss.backward()
    lagrange_opt.step()

  for k in range(2):
    opt.zero_grad()
    distance_loss = distance(Launch, time) + time + lagrange(speed(Launch, time))
    distance_loss.backward()
    opt.step()

flyDistance = distance(Launch, time)
print('Launch date=%f \tflighttime=%f\t distance=%f \tspeed=%f'%(Launch, time, flyDistance, flyDistance/time))
grads = distance(Launch, time) + time + lagrange(speed(Launch, time))
grads.backward()
print('comp slack=%f \tgradient Launch=%f time=%f'%(lagrange(speed(Launch, time)),Launch.grad.item(),time.grad.item() ))
{% endhighlight %}

`Launch date=181.453705 	flighttime=159.843613	 distance=78.299995 	speed=0.489854`

`comp slack=-43.264542 	gradient Launch=-0.000694 time=-24.136995`

First this looks good. Let us check the KKT conditions:
* The gradient of the generalized Lagrangian is 0. *OK*
* The inequality constraints have _complementary slackness_. $$\alpha * h(x) = 0$$. *BAD*
* $$x$$ satisfies the conditions we set. The speed is below 0.5 *OK*

This does not look good, complementary slack should be 0. This means that we might not found the optimum yet.

> This is not a solution!

---

We have to search for the right meta parameters like learning rate and repetitions.

{% highlight python %}
# Launch date: days starting from now
Launch = nn.Parameter(ft([0]))
# time spent in flight
time = nn.Parameter(ft([100]))
# Lagrange
a0 = nn.Parameter(ft([0.1]))
a1 = nn.Parameter(ft([0.1]))

def lagrange(x):
  return torch.abs(a0)*(x-0.5)+torch.abs(a1)*(-x)

def speed(day_launched, fly_time):
  return distance(day_launched, fly_time)/ fly_time

opt = SGD([Launch,time],lr = 1e-1)
lagrange_opt = SGD([a0,a1],lr = 1e-1)

for i in range(25000):
  for k in range(3):
    lagrange_opt.zero_grad()
    lagrange_loss = -lagrange(speed(Launch, time))
    lagrange_loss.backward()
    lagrange_opt.step()
  opt.zero_grad()
  distance_loss = distance(Launch, time) + time + lagrange(speed(Launch, time))
  distance_loss.backward()
  opt.step()
{% endhighlight %}
`Launch date=177.702499 	flighttime=156.541138	 distance=78.299988 	speed=0.500188`

`comp slack=0.041567 	gradient Launch=-0.000459 time=-0.000172`

Let us check the KKT conditions again:
* The gradient of the generalized Lagrangian is 0. *OK*
* The inequality constraints have _complementary slackness_. $$\alpha * h(x) = 0$$. *OK*
* $$x$$ satisfies the conditions we set. The speed is below 0.5 *OK*

*PERFECT*

Now all of our KKT conditions are satisfied. We had to change the learning rate and all numbers of iterations. I also changed from an Adam optimizer to SGD as the momentum caused the optimizer not to settle down.

Always check if you actually satisfy these conditions, otherwise you could be tricking yourself.

> This is a solution!

[LINK TO CODE](https://colab.research.google.com/drive/1TkazncDHYCHdxeyKk9e4eZnBvnTBW1JW#scrollTo=A6IAX02MVYhq)

Let us marvel at what we achieved.
{% include videoPlayer.html file="tomars/toMars11.mp4" %}

# Conclusions
We have seen a lot now:
* How pyTorch optimizes work
* How to model our problem
* How to change and adapt our model and reason with it
* How Karnush-Kuhn-Tucker works
* How to apply it to our model
* How to fix KKT optimization problems

I recommend you to try it out yourself. [Here is my code](https://colab.research.google.com/drive/1TkazncDHYCHdxeyKk9e4eZnBvnTBW1JW) if you want to find out what else I did and how I made the animations.

If you have any input or feedback please drop me a mail<EMAIL_ADDRESS>
# Attribution
Original problem [presented here](https://colab.research.google.com/drive/15sg1s9WSkAvXaGJ5genkHi_SeXKT5xES) by<EMAIL_ADDRESS>

extension: markdown

gha_language: Ruby


text:
Docker Container (Linux)
========================

The following section assumes a thorough knowledge of Docker.

The first thing to do is to create a Dockerfile. Here is an example in which it is also shown that
the necessary libraries *GDI+* and *proj4* are installed.

```

   FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0-buster-slim

   #
   # Install GDI +
   #
   RUN apt-get update
   RUN apt-get install -y libgdiplus lsof
   RUN apt-get install -y libc6-dev
   RUN ln -s /user/lib/libgdiplus.so.0.0.0 /usr/lib/gdiplus.dll

   #
   # Install Proj4 Lib
   #
   RUN apt-get install -y proj-bin
   RUN ln -s /usr/lib/x86_64-linux-gnu/libproj.so.13 /usr/lib/proj.dll

   #
   # Copy app (optional: copy from override for example _config...)
   #
   WORKDIR /app
   EXPOSE 80
   COPY /app .
   COPY /override .

   #
   # Install Fonts Example (optional)
   #
   run mkdir ~/.fonts
   COPY /fonts /fonts
   RUN cp /fonts/* ~/.fonts
   RUN apt-get install fontconfig
   RUN fc-cache -f -v

   ENTRYPOINT ["dotnet", "gView.Server.dll"]

```

A container can be created with the following command:

```

    docker build -t gview_server:5.0.1 .
    docker tag gview_server:5.0.1 gview_server:latest

```

It can be started with the following command:

```

   docker run -d -p 8085:80 --name=gview-server gview_server:latest

```

[Next..](installation_standalone.md)

gha_language: C#


text:
# Form Engine

Used in conjunction with redux-form, to create an "engine" capable of rendering any form template in React

## Getting Started

### Prerequisites

- Will only work in a React/Redux app.
- [Redux-Form](https://github.com/erikras/redux-form/)

### Installing

```
npm i redux-form --save
```

```
npm i form-engine --save
```

## Usage

### Templates
The point of the library is so that you can have an effiecent engine that is capable of rendering any 'template'. This is beneficial for any application that is composed of many many forms. It becomes tiresome and hecktic when trying to code each individual form. What this library offers instead, is the ability to create generic temaplates (JSON) that can be converted into dynamic forms. All the user needs to do is supply the forms. A suggestion for template managment on the backend will be created later but will most likely incorporate mongodb.

[Example Template](https://github.com/datastructr/form-engine/blob/master/examples/template.js)

## Authors

* **Michael Ramos**

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

## Acknowledgments

* [erikras](https://github.com/erikras) for making [Redux-Form](https://github.com/erikras/redux-form/)

repository: datastructr/form-engine

repo_name: datastructr/form-engine


text:
---
layout: page
mathjax: true
title: Final Project
permalink: /2020/proj/p4/
---

Table of Contents:
- [Deadline](#due)
- [Introduction](#intro)
- [Part 1: Intro to GTSAM](#part1)
- [Part 2: SLAM Implementation](#part2)
- [Implementation Overview](#system_overview)
- [Submission Guidelines](#sub)
- [Collaboration Policy](#coll)

## Deadline
11:59:59PM, Tuesday, December 18, 2020
- No late days allowed in this project.
***Submissions made by 11:59PM December 10 will receive extra credit equal to 20% of their grade on
the project.***

## Introduction
Factor graphs are graphical models that are well suited to modeling complex estimation problems such as Simultaneous Localization and Mapping (SLAM) or Structure from Motion (SfM). You might be familiar with another often used graphical model, Bayesian Networks [1]. Unlike Bayesian Networks, which are directed acyclic graphs (DAG), factor graphs are bipartite graphs consisting of factors connected to variables. Variables represent the unknown random variables and factors represent probabilistic information on those variables, derived from measurement or prior knowledge.

In this project, you'll implement a Bayesian Network-based solution to SLAM, an estimation problem that's ubiquitous in robotics. You'll first familiarize yourself with the algorithm in a simplified setting, before diving into the full problem.  Both our "toy problem" and your project are based on the GTSAM[2] ("Georgia Tech Smoothing and Mapping") toolbox which can be downloaded from this link.

It’s surprising how effectively the factor graph-based frameworks can solve a problem as complex as SLAM (where they provide state-of-the-art performance). Excited already?

For more details about the homework refer to the relevant course notes.

## Part 1: Intro to GTSAM
To help you familiarize yourself with GTSAM and its application to SLAM, we've implemented a "toy example" application.  Find it here.  We highly recommend that you install and run it, and gain an understanding of how the code works, before moving on to the rest of the project.

## Part 2: SLAM Implementation
Now that you're familiar with how GTSAM can be applied to SLAM in the 2D setting, you're ready to implement it yourself-- in 3D!

We've recorded some videos from the perspective of a small drone.  Your task is to build a map based on the observation measurements the drone makes.
You'll use data from the `DataMapping.mat` file to build a map and localize your robot on the map (Simultaneous Localization and Mapping) using the GTSAM package.

### The Environment
The provided data for this phase was collected with a hand-held SLAMDunk sensor module [3] (shown in Fig. 1), manufactured by Parrot R , simulating flight patterns over a floor mat of AprilTags [4] each of which has a unique ID.

    Figure 1: Parrot SLAMDunk

The data contains the rectified left camera images, IMU data, SLAMDunk’s pose estimates, AprilTag [4] detections with tag size and camera intrinsics and extrinsics. All units are in m, rad, rads^1 and ms^2 if not specified.

Camera Intrinsics and Extrinsics are given specifically in `CalibParams.mat` and has the following parameters:

- `K` has the camera intrinsics (assume that the distortion coefficients in the radtan model
are zero).
- `TagSize` is in size of each AprilTag in meters.
- `qIMUToC` has the quaternion to transform from IMU to Camera frame (`QuaternionW`,
`QuaternionX`, `QuaternionY`, `QuaternionZ`).
- `TIMUToC` has the translation to transform from IMU to Camera frame `(TransX`, `TransY`,
`TransZ`).

The `.mat` file for any of the sequence (in the format `DataNAME OF SEQUENCE.mat` for e.g., `DataSquare.mat` where Square is the sequence name) will contain the following data:

- `DetAll` is a cell array with AprilTag detections per frame. For e.g., frame 1 detections can be extracted as `DetAll{1}`. Each cell has multiple rows of data. Each row has the following data format:
    - `[TagID, p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y]`
         - Here `p1` is the left bottom corner and points are incremented in counter-clockwise direction, i.e., the `p1x`, `p1y` are coordinates of the bottom left, `p2` is bottom right, `p3` is top right, and `p4` is top left corners (Refer to Fig. 2).
You will use the left bottom corner (p1) of Tag 10 as the world frame origin with positive X being direction pointing from p1 to p2 in Tag 10 and positive Y being pointing from p1 to p4 in Tag 10 and Z axis being pointing out of the plane (upwards) from the Tag.
    - `IMU` is a cell array where each row has the following data:
        - `[QuaternionW, QuaternionX, QuaternionY, QuaternionZ, AccelX, AccelY, AccelZ, GyroX, GyroY, GyroZ, Timestamp]`
        - You do not need the IMU readings for this project, however, if you find a creative way to use it, please feel free to use it.
    - `LeftImgs` is a cell array where each cell is a Image.
    - `TLeftImgs` is the Timestamps for `LeftImgs`. For e.g. `LeftImgs{1}` was collected
at time `TLeftImgs(1)`.
    - `Pose` is an array with each row in the form:
        - `[PosX, PosY, PosZ, QuaternionW, QuaternionX, QuaternionY, QuaternionZ, EulerX, EulerY, EulerZ, Timestamp]`
        - Here ZYX Euler angle was used which is the default for Matlab’s `quat2eul`
function.

    Figure 2: AprilTag, with corners highlighted.

## Implementation Overview

Download the starter code and data  here

### Code
The starter code can be found in the code folder. There are two .m files in the folder:
`SLAMUsingGTSAM.m` and `Wrapper.m`. Your SLAM implementation goes in `SLAMUsingGTSAM` (you may also use helper functions in additional files). The script `Wrapper.m` is given for your debugging only.
The input and output for the `SLAMUsingGTSAM` are given in the "Environment" section above. The `SLAMUsingGTSAM` function has two return
arguments, `LandMarksComputed` and `AllPosesComputed`:

 - `LandMarksComputed` is an array of landmark locations.
     - Each row is of the form `[TagID, p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y]`.
     - Note that the rows have to be sorted in ascending order by TagIDs.
 - `AllPosesComputed` is an array of 6DOF poses.
     - Each row gives the pose measurement at a single camera timestep.
     - Each row is of the form `[PosX, PosY, PosZ, Quaternion, QuaternionX, QuaternionY, QuaternionZ]`.
        - (We use quaternions because euler angles flip near singularity conditions-- similar to the ones we are operating in.)

 Please note:

 - Do NOT add any subdirectories.
 - Comment out any visualization code or debug print statements before submitting.

## Submission Guidelines
 We will deduct points if your submission does not comply with the following guidelines.

Please submit the project  once  for your group -- there's no need for each member to submit it.

### File tree and naming

Your submission on Canvas must be a zip file, following the naming convention **YourDirectoryID_proj4.zip**.  For example, xyz123_proj4.zip.  The file **must have the following directory structure**:

- `YourDirectoryID_proj4.zip/`
    - `code/`
        - `SLAMusingGTSAM.m`
        - *(any dependencies of `SLAMusingGTSAM.m`)
    - `report.pdf`

### Report
**You will be graded primarily based on your report.**

Logistics and bookkeeping you **must** include at the top of your report:

 - The name of each group member.
 - A brief (one paragraph or less) description of what each group member contributed to the project.

You must include output plots of the landmarks in 3D with the camera poses/localization, as shown in
the example below.

    Plot of landmark and camera poses, viewed from above.  Please also provide plots viewed from the side.

We want you to demonstrate an understanding of the concepts involved in the project, and to show the output produced by your code.

Assume that we're familiar with the project, so you don't need to spend time repeating what's already in the course notes.  Instead, focus on any interesting problems you encountered and/or solutions you implemented.

As usual, your report must be full English sentences, **not** commented code. There is a word limit of 1500 words and no minimum length requirement.

## Collaboration Policy
We encourage you to work closely with your groupmates, including collaborating on writing code.  With students outside your group, you may discuss methods and ideas but may not share code.

For the full collaboration policy, including guidelines on citations and limitations on using online resources, see the course website.

## References:
[1] Bernd Pfrommer, Nitin Sanket, Kostas Daniilidis, and Jonas Cleveland. Penncosyvio: A
challenging visual inertial odometry benchmark. In 2017 IEEE International Conference
on Robotics and Automation (ICRA), pages 3847–3854, May 2017.

[2] Michael Bloesch, Michael Burri, Sammy Omari, Marco Hutter, and Roland Siegwart.
Iterated extended kalman filter based visual-inertial odometry using direct photometric
feedback. The International Journal of Robotics Research, 36(10):1053–1072, 2017.

[3] Parrot. SLAMDunk. http://developer.parrot.com/docs/slamdunk/, 2016.

[4] Edwin Olson. AprilTag: A robust and flexible visual fiducial system. In Proceedings of the
IEEE International Conference on Robotics and Automation (ICRA), pages 3400–3407.
IEEE, May 2011.


text:
Presence Insights SDK for Android
========================

Presence Insights is being retired. Please visit [our docs](https://presenceinsights.ibmcloud.com/pidocs/docs/en/introduction/whatsNew/) to learn more.

This library contains classes that allows for easy integration with IBM [Presence Insights](https://console.ng.bluemix.net/catalog/presence-insights/) service available on [Bluemix](https://console.ng.bluemix.net/).

This SDK supports Android 4.3+.

Features
--------

* **BLE beacon sensor** - monitor regions, range for beacons, and send beacon notification messages to PI

* **Management Config REST** - make calls to the management config server to retrieve information about your organization

* **Device Registration** - easily registers a smartphone or tablet with your organization.

Getting Started
---------------

### Adding the library to your project

#### JCenter/MavenCentral

**This is the recommended approach for retrieving the library.**

*   [JCenter](http://jcenter.bintray.com/com/ibm/pi/pi-sdk/)
*   [MavenCentral](https://repo1.maven.org/maven2/com/ibm/pi/pi-sdk/)

In the project `build.gradle`,

    allprojects {
        repositories {
            // add for Maven Central repo
            mavenCentral()
            // add for JCenter repo
            jcenter()
        }
    }

In the module `build.gradle`,

    dependencies {
        compile 'com.ibm.pi:pi-sdk:1.3.0'
    }

#### Manually

[Download](http://presenceinsights.ibmcloud.com/pidocs/mobileapps/mobile_android/) or build the Presence Insights SDK library from GitHub. See [Building the SDK](#building-the-sdk)

1. Add library file to `/libs` directory. If the directory doesn't exist, create it.

2. Add the following dependencies to the modules `build.gradle` file:

        dependencies {
            compile 'org.altbeacon:android-beacon-library:2.7'
            compile (name:'presence-insights-1.3.0', ext:'aar')
        }

3. You will also have to add the `flatDir` attribute to the project `build.gradle` file:

        allprojects {
            repositories {
                flatDir {
                    dirs 'libs'
                }
            }
        }

4. Add the `altbeacon` library to the dependencies. This is a requirement if you are taking this manual approach. Edit the modules `build.gradle` file and add:

        compile 'org.altbeacon:android-beacon-library:2.7'

Sync your gradle project. You should now have access to all of the Presence Insights APIs!

### Building the SDK

You can build the Presence Insights SDK straight from Git. This is useful if you ever have any need to build a custom version of the SDK.

In the terminal, type:

    git clone git@github.ibm.com:PresenceInsights/pi-clientsdk-android.git
    cd pi-clientsdk-android
    chmod +x build-android.sh
    sh build-android.sh

**Tip:** At this point, you may need to configure your development environment. Just follow the error messages. Some common issues include forgetting to create an `ANDROID_HOME` environment variable, or not having the correct android SDK downloaded.

After the build finishes, you will find the library file (.aar) under `./pi-sdk/build/outputs/aar/`.

Using the SDK
-------------

There are two classes that do most of the heavy lifting: PIAPIAdapter and PIBeaconSensor.

####The PIAPIAdapter

The first thing you need to do is initialize an adapter.

```
PIAPIAdapter mAdapter = new PIAPIAdapter(context, <username>, <password>, "https://presenceinsights.ibmcloud.com", <tenant>, <org>);
```

You can obtain your tenant, org, username, and password from the Presence Insights dashboard on Bluemix. We do not store your username and password, it is up to the developer using this library to properly secure the credentials.

You are now able to query all sorts of useful information from Presence Insights!

* How about presenting a floor map to your customers?

```
mAdapter.getFloorMap(<site code>, <floor code>, new PIAPICompletionHandler() {
    @Override
    public void onComplete(PIAPIResult result) {
        if (result.getResponseCode() == HttpURLConnection.HTTP_OK) {
            mMap.setImageBitmap((Bitmap)result.getResult());
        } else {
            Log.e(TAG, result.getResponseCode() + ": " + result.getResult());
        }
    }
});
```

* You want to get a list of all the beacons on that floor and display their location on the map you just retrieved?

```
piAdapter.getBeacons(<site code>, <floor code>, new PIAPICompletionHandler() {
    @Override
    public void onComplete(PIAPIResult result) {
        if (result.getResponseCode() == HttpURLConnection.HTTP_OK) {
            ArrayList<PIBeacon> beacons = (ArrayList<PIBeacon>) result.getResult();
            // use the x and y coords from each beacon obj to place them on the map.
        } else {
            Log.e(TAG, result.getResponseCode() + ": " + result.getResult());
        }
    }
});
```

Don't forget to add the Internet permission to your manifest file!

```
<uses-permission android:name="android.permission.INTERNET" />
```

####The PIBeaconSensor

After you initialize the adapter, you can initialize a Beacon Sensor.

    PIBeaconSensor mBeaconSensor = PIBeaconSensor.getInstance(context, mAdapter);

Before starting the beacon sensor you will need to add the beacon layout to tell the sensor how to read the BLE advertisement from your beacons.

    // adding beacon layout for iBeacons
    mBeaconSensor.addBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");

*Note:* From AltBeacon's [Github](https://github.com/AltBeacon/android-beacon-library), "**IMPORTANT:** By default, this library will only detect beacons meeting the AltBeacon specification."

Now we can start the beacon sensor.

    mBeaconSensor.start()

And that's really all there is to getting the app to start sending the device location back to your Presence Insights instance.

The SDK by default sends information about the beacons around you every 5 seconds. This can be adjusted (time in ms).

    mBeaconSensor.setSendInterval(10000); // send every 10 seconds

To stop beacon sensing,

    mBeaconSensor.stop()

The PIBeaconSensor monitors and ranges for beacons in the background. By default, we set `backgroundScanPeriod` to 1.1 seconds,
and `backgroundBetweenScanPeriod` to 1 minute. These can be adjusted by calling,

    // how long to scan for each cycle
    mBeaconSensor.setBackgroundScanPeriod()
    // how long to wait in between each cycle
    mBeaconSensor.setBackgroundBetweenScanPeriod()

The beacon sensor will survive the user hitting the back button and restarting the phone, but will kill the service if
the user swipes away the app from the task switcher, or the user force stops the app from settings.

## Listening for monitoring and ranging callbacks

We have three callbacks that you can tie into when using the `PIBeaconSensor`.

    beaconsInRange(ArrayList<Beacon> beacons)
    didEnterRegion(Region region)
    didExitRegion(Region region)

Set up a listener, and you are good to go.

    mBeaconSensor.setDidEnterRegionListener(this);

## Device Registration

When registering a device, you have the option to use our default device descriptor, or your own.

    // will create a registered device using the default descriptor
    PIDeviceInfo mDeviceInfo = new PIDeviceInfo(context, "My Nexus 5", "External");

    // will create a registered device using the custom descriptor
    PIDeviceInfo mDeviceInfo = new PIDeviceInfo(context, "My Nexus 5", "External", "my_custom_unique_id");

If the user chooses not to register their device, we offer a way to register the device anonymously.

    // will create an anonymous device using the default descriptor
    PIDeviceInfo mDeviceInfo = new PIDeviceInfo(context);

    // will create an anonymous device using the custom descriptor
    PIDeviceInfo mDeviceInfo = new PIDeviceInfo(context, "my_custom_unique_id");

Adding personal data to PIDeviceInfo object (optional).

    JSONObject data = new JSONObject();
    data.put("cellphone", "919-555-5555");
    data.put("email", "android@us.ibm.com");
    mDeviceInfo.setData(data);

Adding non personal data to PIDeviceInfo object (optional). For example, linking push notification ID from another service to a device.

    JSONObject data = new JSONObject();
    data.put("pushID", "PIisAwesome");
    mDeviceInfo.setUnencryptedData(data);

Blacklisting a device. For example, to ignore an employees device.

    mDeviceInfo.setBlacklisted(true);

Finally, once the PIDeviceInfo object is ready to register, make the call to registerDevice from the PIAPIAdapter. Instantiate mAdapter as seen in section above, ['Setting up PIAPIAdapter'](#pi_adapter)

    mAdapter.registerDevice(mDeviceInfo, new PIAPICompletionHandler() {
        @Override
        public void onComplete(PIAPIResult result) {
            // if result.getResponseCode() is OK or CREATED
            PIDevice device = (PIDevice) result.getResult();
        }
    });

## Troubleshooting

*   First things first, if things are not working, enable debugging to see all the inner workings in LogCat.

        PILogger.enableDebugMode(true);

*   I started the beacon sensor, but it is not picking up any beacons. There are several reasons why this may be happening.

    1.  The beacons are not configured correctly in the PI UI. Ensure that the Proximity UUID is set correctly. We retrieve that to create a region to range for beacons.
    2.  The beacon layout has not been set on the PIBeaconSensor. Please see the section on [beacon advertisement layout](#beacon_layout).
    3.  The codes (username, password, tenant, org) used in creating the PIAPIAdapter may have been entered incorrectly.

*   I set up the callback for `beaconsInRange(ArrayList<Beacon>)`, but it is not being called. Make sure you set the listener for the callback you want.

        mBeaconSensor.setBeaconsInRangeListener(this);

*    How can I send location events when the application is in the background or not open?

    1. There is a background process we create that uses backgroundScanPeriod (how long you scan) and backgroundBetweenScanPeriod (how long to wait before waking up and scanning BLE). You should set these to values that make sense for your application. Consider the fact that scanning for BLE devices drains the battery and reduces a users privacy.
    2. If a user force closes the app, Android will stop these background services. Consider solutions such as signage around your venue to encourage users to open the application. However, if a user restarts their phone, and your app was scanning for beacons, we will start back up and continue scanning.

repository: presence-insights/pi-clientsdk-android

gha_language: Java

repo_name: presence-insights/pi-clientsdk-android


text:
# Real-name authentication failures and solutions {#concept_x3m_zwv_12b .concept}

After you submit all required information for real-name authentication, Alibaba Cloud immediately submits the information to the China Internet Network Information Center \(CNNIC\) for verification. CNNIC will verify the submitted verification information and the domain name registration information for authenticity, consistency, and completeness. If the verification fails, you can troubleshoot any issues according to the solutions described in this topic.

## Invalid certificates or identity documents {#section_spz_gqk_5gb .section}

If the system displays the message **Verification failed due to invalid certificate**, you can troubleshoot the fault as follows

1.  Check whether the domain name holder has a special occupation.

    Individuals with special occupations, for example, military personnel and monks, cannot use the 18-digit resident identity card number for verification. We recommend that you use other identification documentation for the verification.

2.  Check whether the submitted verification information is consistent with the domain registration information.

    For example, if you select Organization Holder and Unified Social Credit Code Certificate, but upload a scanned copy of a business license, the submitted verification information and the domain registration information are inconsistent.

3.  Check whether you have submitted a correct and valid identity document or certificate.

    Individual domain holders must submit a scanned copy of their resident identity card or passport. Photo examples:

    -   [Resident identity card](intl.en-US/Real-name authentication for domains /Real-name authentication examples/Real-name authentication examples for individual domain holders.md#section_bjz_lh3_wgb)
    -   [Passport](intl.en-US/Real-name authentication for domains /Real-name authentication examples/Real-name authentication examples for individual domain holders.md#section_fln_sy3_wgb)
    Organization domain holders must submit a copy of the business license, unified social credit code certificate, organization code certificate, or other valid certificates. Photo examples:

    -   [Business license](intl.en-US/Real-name authentication for domains /Real-name authentication examples/Real-name authentication examples for organization domain holders.md#section_wsm_jf3_wgb)
    -   [Unified social credit code certificate](intl.en-US/Real-name authentication for domains /Real-name authentication examples/Real-name authentication examples for organization domain holders.md#section_bjh_pck_wgb)
    -   [Organization code certificate](intl.en-US/Real-name authentication for domains /Real-name authentication examples/Real-name authentication examples for organization domain holders.md#section_f4l_xrd_xgb)
    -   [Other certificates](intl.en-US/Real-name authentication for domains /Real-name authentication examples/Real-name authentication examples for organization domain holders.md#section_jlt_gqz_zgb)

## Inconsistent domain holder names {#section_dgw_jqk_5gb .section}

If the system displays the message **Verification failed due to inconsistent names in the verification and registration information**, you can troubleshoot the fault as follows

-   Check whether the name of the domain holder specified in the submitted verification information is consistent with that in the domain registration information. Pay close attention to Chinese characters with similar forms or pronunciations. Do not use abbreviated or shortened names.
-   The certificate type that you select must be consistent with the one that you upload. If you select the business license, you must submit a scanned copy of your business license.
-   The certificate number that is specified in the verification information must be consistent with that of the actual certificate. If you select the resident identity card, business license, or unified social credit code certificate, make sure that the certificate number you specify in the verification information is consistent with that of the actual certificate.

    **Note:**

    -   Use half-width characters when you enter the certificate number.
    -   If the business license contains a duplicate number, for example, \(1-1\), do not enter the duplicate number.
    -   Pay close attention to numbers and words with similar forms, such as the number 0 and the letter O, the number 1 and the letter I.
    -   Pay close attention to the number of digits of the certificate code. Enter the complete certificate number.

## Lack of identity documents of the domain holder {#section_itj_3rk_5gb .section}

If the system displays the message **Verification failed due to the lack of identity documents of the domain holder**, you can troubleshoot the fault as follows

-   If the domain name holder is a natural person, submit a scanned copy of the resident identity card or passport of the holder. For more information, see[Real-name authentication examples for individual domain holders](intl.en-US/Real-name authentication for domains /Real-name authentication examples/Real-name authentication examples for individual domain holders.md#).
-   If the domain name holder is an organization, submit a scanned copy of the business license, unified social credit code certificate, organization code certificate, or other valid certificates. For more information, see [Real-name authentication examples for organization domain holders](intl.en-US/Real-name authentication for domains /Real-name authentication examples/Real-name authentication examples for organization domain holders.md#).

## Incomplete information about the domain holder {#section_i5p_vrk_5gb .section}

If the system displays the message **Verification failed due to incomplete information about the domain holder**, you can troubleshoot the fault as follows

Submit a copy of the identity document or certificate. Include the borders of the document or certificate. If you use the business license, scan all information contained in the license, including any national emblem or seal affixed by the authority that manages the business license.

## Invalid holder information {#section_lxv_wrk_5gb .section}

If the system displays the message **Verification failed due to invalid holder information**, you can troubleshoot the fault as follows

Submit a copy of a valid identity document or certificate.

-   Mainland China holders
    -   We recommend that organization domain holders submit a scanned copy of a certificate that contains a valid **18-digit** unified social credit code, such as the business license, unified social credit code certificate, and organization code certificate.

    -   Natural persons can submit a copy of their resident identity card or residency certificate.

-   Non-mainland China holders
    -   Organization domain holders can submit a copy of other valid certificates.
    -   Natural persons can submit a copy of their passport or other valid identity documents.

## Failed attempts to upload the verification information to CNNIC {#section_mst_1sk_5gb .section}

If the system displays the message **Failed attempts to upload the verification information to CNNIC**, you can troubleshoot the fault as follows:

Check whether the format and size of the photo and the number of the certificate are correct.

-   Submit a scanned copy or photo of the certificate. The size of a scanned copy or photo must be from 55 KB to 1 MB. Supported photo formats include **JPG and BMP**.

    For other formats, use a graphics editor such as Microsoft Paint or Adobe Photoshop to convert them to the JPG or BMP format. **Do not change the file extension directly**.

-   You must submit a complete and clear scanned copy of the identity document with no cover or smudges. Include the borders of the identity document.
-   Use half-width characters when you enter the certificate number.

## Inconsistency between the submitted resident identity card and the one provided by the Ministry of Public Security {#section_aws_2sk_5gb .section}

If the system displays the message **Verification failed due to inconsistency between the submitted resident identity card and the one provided by the Ministry of Public Security**, you can troubleshoot the fault as follows

Check whether you have entered the correct holder name and the 18-digit resident identity card number.

**Note:** Individuals with special occupations, for example, military personnel and monks, cannot use the 18-digit resident identity card number for verification. We recommend that you use another identity document for the verification.

## International users {#section_swz_3sk_5gb .section}

If the system displays the message **Verification failed because the submitted information identifies the domain holder as an international user**, you can troubleshoot the fault as follows

International domain holders must keep the name of the domain holder consistent with that in the submitted verification information. If the verification information is written in English, enter the English name in the **Holder Name \(Chinese\)** field.

**Note:** CNNIC has not authorized the Alibaba Cloud China site to provide .cn, .中国, and .公司 domain name registration services to users other than mainland China, Hong Kong, and Macao organizations and individual users, and Taiwan individual users. Only mainland China, Hong Kong, and Macao organizations and individual users, and Taiwan individual users can complete the real-name authentication process for .cn, .中国, and .公司 domain names on the Alibaba Cloud China site. If you need to use a .cn domain name, register a .cn domain name and complete the real-name authentication process on the Alibaba Cloud International site. The process will be verified and regulated by CNNIC.

## Newly issued certificates or identity documents {#section_yyj_ksk_5gb .section}

If the system displays the message **Verification failed due to newly issued certificates or identity documents**, you can troubleshoot the fault as follows

The newly issued certificate or identity document has not been entered in the system of the verification authority. It takes at least 10 natural days to synchronize data. Submit the verification information 10 natural days after the certificate is issued.

## Incorrect contact information {#section_q1s_rgm_zgb .section}

If the system displays the message **Verification failed due to incorrect contact information. Command syntax errors occurred**, or **Verification failed due to incorrect contact information. XML schema validation failed**, you can troubleshoot the fault as follows

Check whether you have entered the correct country code in the domain registration information. For example, the country code for the People's Republic of China is 86. Do not enter the area code in the country code field. We recommend that you use the default code selected by the system.

## Sensitive words in domain names {#section_fh4_qdg_chb .section}

If the system displays the message **Verification failed due to content that may damage the honor and interests of the state**, or **Verification failed due to violation of China Internet Domain Name Regulations article 27: Those that insult or libel others and infringe other people's legal rights and interests** or **Other content prohibited by laws, rules and administrative regulations**, you can troubleshoot the fault as follows

We recommend that you use another domain name, or transfer your domain name to the Alibaba Cloud International site or other domain name service providers.

**Note:** Currently, the Alibaba Cloud International site only requires real-name authentication for .cn domain names.

## International individual or organization holders {#section_iqy_j5g_chb .section}

If the system displays the message **Verification failed due to international individual or organization holders**, you can troubleshoot the fault as follows

Check whether the region of the domain name holder is correct. Select the region specified in the submitted certificate or identity document. For example, if you are an individual domain holder and have submitted a scanned copy of a Mainland Travel Permit for Hong Kong and Macao Residents, select Hong Kong or Macao as specified by the permit.

url: https://raw.githubusercontent.com/Wyte3z/domain/9194c3cafa4da80412691ac016f86e5d5a6b5765/intl.en-US/Real-name authentication for domains /Real-name authentication failures and solutions.md


text:
# wales-matches-cli-app
This programs gives you information about upcoming Welsh Rugby matches

I used the below repo as a general guideline for formatting and structuring this repo.
 https://github.com/dannyd4315/worlds-best-restaurants-cli-gem/blob/master/lib/worlds_best_restaurants/version.rb

repository: byojelly/wales-matches-cli-app

repo_name: byojelly/wales-matches-cli-app


text:
**From email address:**

If you want to change the from email address, where the application send emails from, than you are able to change the configuration in /phpci/PHPCI/config.yml like this:

    b8:
        database: { servers: { read: localhost, write: localhost }, name: example, username: example, password: example }
    phpci:
        url: 'http://phpci.example.com'
        email_settings:
            from_address: 'phpci@example.com'

repository: carlosreig/PHPCI

repo_name: carlosreig/PHPCI


text:
## Berkeley Autolab Perception Module

This package provides a wide variety of useful tools for perception tasks.
It directly depends on the [Berkeley Autolab Core
module](https://www.github.com/BerkeleyAutomation/autolab_core), so be sure to install
that first.
View the install guide and API documentation for the perception module
[here](https://BerkeleyAutomation.github.io/perception).

repository: StanfordVL/perception

repo_name: StanfordVL/perception


text:
# `elm-toml`
> Parsing TOML in Elm

[![Build Status](https://travis-ci.org/zwilias/elm-toml.svg?branch=master)](https://travis-ci.org/zwilias/elm-toml)

This library attempts to model [TOML](https://github.com/toml-lang/toml) in Elm,
providing a means to parse a TOML document into an Elm datastructure.

## Usage

Let's say we have a TOML document like so:

```toml
################################################################################
## This is my very important settings document                                ##
################################################################################

org.name = "Test org"
org.created = 2017-08-11

z-index = 12321

[[user]]
name = "Ilias"

[[user]]
name = "Alice"

[[user]]
name = "Fido"
```

We could model an equivalent Elm datastructure like so:

```elm
import Toml.Calendar as Calendar

type alias User =
    { name : String }

type alias Organisation =
    { name : String
    , created : Calendar.Date
    }

type Settings =
    { zIndex : Int
    , org : Organisation
    , users : List User
    }
```

Now, writing some decoder for this should be pretty straightforward, too:

```elm
import Toml.Decode as Decode exposing (Decoder)

user : Decoder e User
user =
    Decode.map User (Decode.field "name" Decode.string)

organisation : Decoder e Organisation
organisation =
    Decode.map2 Organisation
        (Decode.field "name" Decode.string)
        (Decode.field "created" Decode.localDate)

settings : Decoder e Settings
settings =
    Decode.map3 Settings
        (Decode.field "z-index" Decode.int)
        (Decode.field "org" organisation)
        (Decode.field "users" (Decode.list user))
```

And finally, we could run the `settings` decoder against our `document` using
`Toml.Decode.decodeString settings document`.

## Contributing

Code in this project is formatted with `elm-format`. The currently used version
is specified in the `package.json` file. Verifying formatting is part of CI.

Examples in the documentation are verified using `elm-verify-examples`.

Unit tests are available in the `tests` directory and can be executed using
`elm-test`.

To run all tests locally:

```bash
$ npm i # Install all dependencies
$ npm test # Run tests
```

All contributions are welcome. Opening an issue and starting a conversation
before delving into the code is very much appreciated! Collaboration requires
communication.

## License

Licensed with love under BSD-3. Refer to the `LICENSE` file for more info.

repository: reiner-dolp/elm-package-index

repo_name: reiner-dolp/elm-package-index


text:
# D-lay
A VST that models the mellow, distorted tones of traditional analog Bucket-Brigade Device ('BBD') delay effects. Written in the latest C++20 draft using the [JUCE framework](https://juce.com/).

**This is repo contains *depercated* code. Please refer to [my VA library](https://github.com/thezhe/SOUL-VA) for new effects and an updated BBD delay model in the future.**

repository: DaveChambers/D-lay

repo_name: DaveChambers/D-lay


text:
**Contributors:** {% for member in site.github.contributors %}{% endfor %}

## Introduction
The Wave Analysis Network (WAnet) is a neural network for producing wave-structure interaction forces for ocean applciations. This repository contains all software required to recreate the networks.

## Table of Contents
* [The Basics]()
  * [NEMOH]()
  * [Neural Networks]()
* [Data]()
* [Training]()
  * [Training the Autoencoders]()
  * [Training the Analytical/Synthetic Networks]()
* [Application]()

## Acknowledgements
This work has been submitted to the [Design Computing and Cognition Conference](http://dccconferences.org/dcc18/).
*Portions of this repository (specifically, those in [openwec.py](https://github.com/THREDgroup/WAnet/tree/master/WAnet/openwec.py)) are based on [openWEC](https://github.com/tverbrug/openWEC)*

repository: THREDgroup/WAnet

repo_name: THREDgroup/WAnet