text:
# CEF Python, PyGTK, Flask
This variation uses the following:
PyGTK -- Windowing
CEF Python -- Portable browser
Flask -- Local webserver
Tornado -- Launches Flask - Threading issues with Flask caused the need for Tornado
Tkinter -- Folder selection
Bootstrap - Web UI
xmlhttprequest - Communication with Flask to update UI

# How to Use

## Get Started

### Download
Create a directory for new your project
Download the contents of this folder into your directory

### Setup Environment

[Python 2.7](https://www.python.org/downloads/)
[PyGTK All In One for Python 2.7](http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.24/)
`pip install flask`
`pip install tornado`
`pip install cefpython3`
`pip install pyinstaller`

### Test Application
Start the application to make sure everything is working `python neuron.py`
The application comes with a sample GUI with some interactions with the backend.
The data you see is loaded dynamically from the backend then javascript loads them into the form.
You can modify the data in the form and click `Save`. Then an AJAX call will be made to send it to the backend and
printed in the terminal.
The included HTML and Javascript functions are a sample of how actions can be performed.

## Understanding Structure

### neuron.py
Starts the application.  It is a `cefpython` (portable chrome browser) application, and the windowing system.
It calls a function called `find_port()` which finds an open port on the local machine.
It then calls the function `start_cyclone()` which imports from `cyclone.py`

### cyclone.py
This file is used to run `Tornado` which handles running Flask and the incoming connections from your web gui.
There were threading issues with Flask and this was an easy solution to that problem.
Cyclone is importing the Flask application from `app.py`

### app.py
This is the Flask application.  This is were routing for http calls will be, creating the HTML, and the backend of
the application.
This is where main part of the application is handled.

### Templates directory
Contains the HTML files for the application

### Static directory
Contains the resources for the HTML files. Fonts, images, javascript libraries etc.

### Locales directory
Language for `cefpython`

### Everything else
The other files in the directory are for executing cefpython/neuron.py

## Rebrand Project

### Windowing and Icons
Open `neuron.py` and go to the `PyGTKExample` class and in the `__init__` function you can modify
`self.mainWindow.set_title('Neuron')` to rename your application.
Then edit `icon.ico` and `icon_big.ico` to your application's icon.

## Modifying the Application
After rebranding the project, development on the new application can begin.

### Main Program Logic
`app.py` is the Flask application that controls the main logic of the application.
Sample AJAX functions are included in the HTML to communicate with the backend Flask application.

### GUI
`Bootstrap` is used for the HTML.  This is not required, any HTML can be used.
Modifying the files in the `templates` and `static` directories will allow you change the GUI.
You call run `python app.py` and go to `localhost:5000` in your browser to work on your application without having
to execute `neuron.py`

## Create Windows Executable with PyInstaller
The following must be executed on a 32bit Windows machine with 32bit Python
Execute `pyinstaller neuron_installer.spec`
Two directories will be created, `dist` and `build`
`build` contains the temporary files used to create the executable
`dist` contains the files that need to be distributed
Manually copy the folders `static` and `templates` into `dist/Neuron`
You can modify `neuron_installer.spec` to match the name of the new application

# References
[CEFPython](https://github.com/cztomczak/cefpython) - Python bindings for the Chromium Embedded Framework
[Flask](http://flask.pocoo.org/) - Python microframework
[Bootstrap](http://getbootstrap.com/) - Web Front-End Framework
[PyInstaller](http://www.pyinstaller.org/) - Turn Python projects into executables

# Screenshot
![Neuron Screenshot](screen_shot.png)

repository: peacerior/Neuron

repo_name: peacerior/Neuron


text:
``` r
if (!require("edgarWebR")) install.packages("edgarWebR")
if (!require("RSelenium")) install.packages("RSelenium")
if (!require("rvest")) install.packages("rvest")
if (!require("tidyverse")) install.packages("tidyverse")
if (!require("WDI")) install.packages("WDI")

library(rvest)
library(tidyverse)
```

Introduction
============

**Definition**
*In a nutshell, web scraping is the process of extracting data from
websites. All the job is carried out by a piece of code which is called
a “scraper”.*
[upwork.com](https://www.upwork.com/hiring/for-clients/web-scraping-tutorial/).

![](webscrap1.jpg)

Fundamental considerations
==========================

-   Where do I get data
    -   [Do I need web scraping?](#do-i-need-web-scraping)
    -   [Is there a package / library?](#is-there-a-package--library)
-   What data do I want?
    -   [Is data stored in files?](#is-data-stored-in-files)
    -   [How is data structured? (e.g. text, tables, attributes)](#how-is-data-structured)
    -   [Is interaction needed? (e.g. event-based code, forms)](#is-interaction-needed)
-   How do I get data?
    -   [How do I access data? (i.e. access website A to get to
        website B)](#how-do-i-access-data)
    -   [How do I identify data? (e.g. xpath, css-selector)](#how-do-i-identify-data)
    -   [Is my identifier unique?](#is-my-identifier-unqiue)
    -   [Is my identifier stable?](#is-my-identifier-stable)
 -  [Legal aspects](#legal-aspects)
 -  [Additional resources](#additional-resources)

Where do I get data?
====================

Do I need web scraping?
-----------------------

[Get to top](#fundamental-considerations)

This comes down to the question “Is it worth the effort?”. Web scraping
is most efficient when…

-   …the website provides no interface to access data (e.g. [World
    Bank](https://databank.worldbank.org/source/world-development-indicators))
-   …you would have to repeat the same web-based task several times.
-   …the website structure is known and consistent. –\> Is my identifier
    unique? / Is my identifier consistent?
-   …the website allows you to webscrap. –\> Legal aspects

Is there a package / library?
-----------------------------

[Get to top](#fundamental-considerations)

In some cases there are packages / libraries available that make web
scaping unnecessary:

------------------------------------------------------------------------

**World Bank**

``` r
WDI::WDI(country = c("US","BR"), indicator = "NY.GNS.ICTR.GN.ZS", start = 1999, end = 2000, extra = TRUE, cache = NULL)
```

------------------------------------------------------------------------

**Securities and Exchange Commission**

``` r
edgarWebR::company_filings("AAPL", before = "20170810", count = 10)
```

What data do I want?
====================

Is data stored in files?
------------------------

[Get to top](#fundamental-considerations)

------------------------------------------------------------------------

**saving stored files**
Downloading and saving a file from a
[website](https://www.wu.ac.at/iib/team).

``` r
url <- "https://www.wu.ac.at/fileadmin/wu/_processed_/3/e/csm_WU_IIB_GroupPicture-1_ca2bfa13bc.jpg"

download.file(url, "out.jpg", mode = "wb")
```

------------------------------------------------------------------------

**reading stored files**
Downloading a file from a
[website](https://www.stats.govt.nz/information-releases/annual-enterprise-survey-2018-financial-year-provisional)
and importing it directly into R. The website prevents web scraping in
its *robots.txt* file - see below.

``` r
url <- "https://www.stats.govt.nz/assets/Uploads/Annual-enterprise-survey/Annual-enterprise-survey-2018-financial-year-provisional/Download-data/annual-enterprise-survey-2018-financial-year-provisional-csv.csv"

read_csv(url)
```

------------------------------------------------------------------------

**reading data**
Accessing [website](https://de.wikipedia.org/wiki/Marcus_Tullius_Cicero)
content and saving this content as an object in R. – Focus of this
document!

``` r
url <- "https://de.wikipedia.org/wiki/Marcus_Tullius_Cicero"

url %>%
  read_html() %>%
  html_nodes("#firstHeading") %>%
  html_text()
```

How is data structured?
-----------------------

[Get to top](#fundamental-considerations)

Data on a [website](https://www.geschichtewiki.wien.gv.at/Gasometer) can
be categorized into three broard groups: text, tables, and attributes.
Regardless of these types, web scraping always consists three steps:

1.  access html site
2.  access html nodes
3.  extract information

However, *extracting* information differs depending on these groups.

------------------------------------------------------------------------

**accessing html site**
![](webscrap2.jpg)

``` r
url <- "https://www.geschichtewiki.wien.gv.at/Gasometer"

data_site <- read_html(url)
print(data_site)
```

*Python example*

``` python
# import packages
from lxml import html
import requests

# connect to webpage
url = "https://www.geschichtewiki.wien.gv.at/Gasometer"
resp = requests.get(url, headers={'User-Agent': 'Custom'})

# download webpage
page = html.fromstring(resp.content)
```

------------------------------------------------------------------------

**accessing html nodes**
![](webscrap3.jpg)

``` r
url <- "https://www.geschichtewiki.wien.gv.at/Gasometer"

data_nodes <- url %>%
  read_html() %>%
  html_nodes(".text")
print(data_nodes)

# subsetting html nodes like list
print(data_nodes[[2]])
```

*Python example*

``` python
# import packages
from lxml import html
import requests

# connect and download webpage
url = "https://www.geschichtewiki.wien.gv.at/Gasometer"
resp = requests.get(url, headers={'User-Agent': 'Custom'})
page = html.fromstring(resp.content)

# download elements
page = html.fromstring(resp.content)
web_data = page.cssselect(".text")
```

------------------------------------------------------------------------

**text data**
*html\_text()* extracts the *text* content of html nodes. The output is
a character vector.
![](webscrap4.jpg)

``` r
url <- "https://www.geschichtewiki.wien.gv.at/Gasometer"

url %>%
  read_html %>%
  html_nodes(".text") %>%
  html_text()
```

*Python example*

``` python
# import packages
from lxml import html
import requests

# connect and download webpage
url = "https://www.geschichtewiki.wien.gv.at/Gasometer"
resp = requests.get(url, headers={'User-Agent': 'Custom'})
page = html.fromstring(resp.content)

# download elements
page = html.fromstring(resp.content)
web_data = page.cssselect(".text")

# print element text
web_test = []
for i in web_data:
  web_test.append(i.text)
```

------------------------------------------------------------------------

**tables**
*html\_table()* extracts tables that are defined by a *\<table\>* tag
from html nodes. The output ist a list of data frames.
![](webscrap6.jpg)

``` r
url <- "https://www.geschichtewiki.wien.gv.at/Gasometer"

url %>%
  read_html %>%
  html_nodes("table") %>%
  html_table()
```

------------------------------------------------------------------------

**attributes**
*html\_attr()* extracts attributes that are defined by the respective
*\<tag\>* indicated in the *html\_attr()* function from html nodes. The
output is a character vector.
![](webscrap5.jpg)

``` r
url <- "https://www.geschichtewiki.wien.gv.at/Gasometer"

url %>%
  read_html %>%
  html_nodes(".text") %>%
  html_attr("href")
```

*Python example*

``` python
# import packages
from lxml import html
import requests

# connect and download webpage
url = "https://www.geschichtewiki.wien.gv.at/Gasometer"
resp = requests.get(url, headers={'User-Agent': 'Custom'})
page = html.fromstring(resp.content)

# download elements
page = html.fromstring(resp.content)
web_data = page.cssselect(".text")

# print element href attribute
web_test = []
for i in web_data:
  web_test.append(i.attrib.get('href'))
```

Is interaction needed?
----------------------

[Get to top](#fundamental-considerations)

------------------------------------------------------------------------

**loading data**
Some websites are built in a way that data is only loaded after when the
website is opened - the data is part of the “as-loaded” website but not
part of the “as-is”
[website](https://www.liveticker.com/turnierbaum/zLZKqTTF/ATnr2OzD/#draw).
Since *rvest* loads “as-is” websites, data that is part of the
“as-loaded” webite cannot be accessed.

``` r
url <- "https://www.liveticker.com/turnierbaum/zLZKqTTF/ATnr2OzD/#draw"

url %>%
  read_html() %>%
    html_nodes(xpath = "//*[@id='match-0-0']") %>%
    html_text()
```

The package *RSelenium* uses the testing mode of the browser to open a
[website](https://www.liveticker.com/turnierbaum/zLZKqTTF/ATnr2OzD/#draw)
before the actual scraping starts. This provides access to the
“as-loaded” website.

``` r
# open server session and open browser client
rD <- rsDriver(browser = c("chrome"), chromever = "latest", verbose = FALSE)
# binman::list_versions("chromedriver")
# rD <- rsDriver(browser = c("chrome"), chromever = "79.0.3945.36", verbose = FALSE)
remDr <- rD$client

# navitage to url in browser client
url <- "https://www.liveticker.com/turnierbaum/zLZKqTTF/ATnr2OzD/#draw"
remDr$navigate(url)

# access single webnelement using xpath
webElem <- remDr$findElement(using = "xpath", "//*[@id='match-0-0']")
webElem$getElementText()

# close browser client and close server session
remDr$close()
rD$server$stop()
```

------------------------------------------------------------------------

**entering data**
Through the browser testing mode *RSelenium* can also be used provide
browser inputs. The example below is from the RSelenium
[documentation](https://ropensci.github.io/RSelenium/articles/basics.html#sending-events-to-elements).

``` r
# open server session and open browser client
rD <- rsDriver(browser = c("chrome"), chromever = "79.0.3945.36", verbose = FALSE)
remDr <- rD$client

# open website, enter data, and press button
remDr$navigate("http://www.google.com/ncr")
webElem <- remDr$findElement(using = "css", "[name = 'q']")
webElem$sendKeysToElement(list("R Cran", key = "enter"))

# get elements from new website
webElems <- remDr$findElements(using = "css selector", "h3.r")
resHeaders <- unlist(lapply(webElems, function(x) {x$getElementText()}))
webElem <- webElems[[which(resHeaders == "R for Windows")]]

# click element on new website
webElem$clickElement()

# get results
remDr$getCurrentUrl()
remDr$getTitle()

# close browser client and close server session
remDr$close()
rD$server$stop()
```

How do I get data?
==================

How do I access data?
---------------------

[Get to top](#fundamental-considerations)

If data is saved on sub-pages it might be necessary to scrap data
(e.g. URLs) from [website
A](https://de.wikipedia.org/wiki/Kategorie:Kaiser_(Rom)) and use these
URLs to access [website
B](https://de.wikipedia.org/wiki/Aemilianus_(Kaiser)) where the actual
data is scraped.

------------------------------------------------------------------------

``` r
url <- "https://de.wikipedia.org/wiki/Kategorie:Kaiser_(Rom)"

# scrap urls for page B from page A
url_b <- url %>%
  read_html() %>%
  html_nodes("#mw-pages a") %>%
  html_attr("href")

# scrap data from page B
str_c("https://de.wikipedia.org", url_b) %>%
  map_chr(~{
    read_html(.x) %>%
    html_nodes("#firstHeading") %>%
    html_text()
  })
```

How do I identify data?
-----------------------

[Get to top](#fundamental-considerations)

For web scraping, a clear identification of the data is necessary. Data
on a website can by identfied using its URL (e.g. for files linked to
the website), the data’s xpath, or its css style.

------------------------------------------------------------------------

**xpath**
The xpath is the address of an object within the
[website](https://www.marketwatch.com/investing/stock/IRS/profile)’s
code. The xpath can be copied from the browser’s developer view (Ctrl +
I).

``` r
url <- "https://www.marketwatch.com/investing/stock/IRS/profile"

url %>%
  read_html() %>%
  html_nodes(xpath = '//*[@id="maincontent"]/div[2]/div/div/p') %>%
  html_text()
```

Using different xpaths might lead to the same / similar results for
[website](https://www.marketwatch.com/investing/stock/IRS/profile)
elements - but could also result in differing / unstable results.

``` r
url <- "https://www.marketwatch.com/investing/stock/IRS/profile"

url %>%
  read_html() %>%
  html_nodes(xpath = '//*[@class="section"]') %>%
  html_text() %>%
  str_squish()
```

The xpath for
[website](http://www.taipeitimes.com/News/front/archives/2020/01/12/2003729107)
elements can also use wildcards in the form *contains()*.

``` r
url <- "http://www.taipeitimes.com/News/front/archives/2020/01/12/2003729107"

len_a <- url %>%
  read_html() %>%
  html_nodes(xpath = '//*[@id="front_boxd"]/h1') %>%
  length()

len_b <- url %>%
  read_html() %>%
  html_nodes(xpath = '//*[contains(@id, "_boxd")]') %>%
  length()

print(len_a)
print(len_b)
print(len_a == len_b)
```

------------------------------------------------------------------------

**css styles**
The easiest way to identify
[website](https://www.marketwatch.com/investing/stock/IRS/profile) data
is using
[selectorgadet](https://cran.r-project.org/web/packages/rvest/vignettes/selectorgadget.html)
to identify its css style.

``` r
url <- "https://www.marketwatch.com/investing/stock/IRS/profile"

url %>%
  read_html() %>%
  html_nodes("#maincontent .section p") %>%
  html_text()
```

Is my identifier unqiue?
------------------------

[Get to top](#fundamental-considerations)

Defining a selector that is not sufficiently unambiguous might lead to
undesirable result -\> too many / unwanted results.

------------------------------------------------------------------------

**xpath**
Depending on the
[website](https://www.transfermarkt.de/adi-hutter/profil/trainer/5018)
structure, an ambiguous xpath might result in too many results /
unwanted results.

``` r
url <- "https://www.transfermarkt.de/adi-hutter/profil/trainer/5018"
xpath_selector <- '//*[@id="main"]/div[8]/div/div[1]/div[2]/div/div[1]/p[1]/span[2]'

len_a <- url %>%
  read_html() %>%
  html_nodes(xpath = xpath_selector) %>%
  length()

xpath_selector <- '//*[@id="main"]/div[8]/div/div[1]/div[2]/div/div/p/span'

len_b <- url %>%
  read_html() %>%
  html_nodes(xpath = xpath_selector) %>%
  length()

print(len_a)
print(len_b)
print(len_a == len_b)
```

------------------------------------------------------------------------

**css styles**
Depending on the
[website](https://followinghadrian.com/2019/10/15/the-forest-inscriptions-of-hadrian-in-mount-lebanon/)
structure, an ambiguous css style selector might result in too many
results / unwanted results.

``` r
url <- "https://followinghadrian.com/2019/10/15/the-forest-inscriptions-of-hadrian-in-mount-lebanon/"
css_selector <- ".wp-caption-text"

len_a <- url %>%
  read_html() %>%
  html_nodes(css_selector) %>%
  length()

css_selector <- "#caption-attachment-13802"

len_b <- url %>%
  read_html() %>%
  html_nodes(css_selector) %>%
  length()

print(len_a)
print(len_b)
print(len_a == len_b)
```

Is my identifier stable?
------------------------

[Get to top](#fundamental-considerations)

When looping across a list of websites it might happen that an
identifier that worked on *page A* does not work anymore on *page B*.

------------------------------------------------------------------------

**xpath**
xpath, that does not account for changes in the website design between
[page A](https://de.wikipedia.org/wiki/Augustus) and [page
B](https://de.wikipedia.org/wiki/Trajan):

``` r
url_a <- "https://de.wikipedia.org/wiki/Augustus"
url_b <- "https://de.wikipedia.org/wiki/Trajan"
xpath_selector <- '//*[@id="mw-content-text"]/div/p[1]/b'

len_a <- url_a %>%
  read_html() %>%
  html_nodes(xpath = xpath_selector) %>%
  length()

len_b <- url_b %>%
  read_html() %>%
  html_nodes(xpath = xpath_selector) %>%
  length()

print(len_a)
print(len_b)
print(len_a == len_b)
```

xpath, that does account for changes in the website design between [page
A](https://de.wikipedia.org/wiki/Augustus) and [page
B](https://de.wikipedia.org/wiki/Trajan):

``` r
url_a <- "https://de.wikipedia.org/wiki/Augustus"
url_b <- "https://de.wikipedia.org/wiki/Trajan"
xpath_selector <- '//*[@id="mw-content-text"]/div/p[1]/b[1]' # changing 'b' to 'b[1]' for less ambiguity

len_a <- url_a %>%
  read_html() %>%
  html_nodes(xpath = xpath_selector) %>%
  length()

len_b <- url_b %>%
  read_html() %>%
  html_nodes(xpath = xpath_selector) %>%
  length()

print(len_a)
print(len_b)
print(len_a == len_b)
```

------------------------------------------------------------------------

**css styles**
css style, that does not account for changes in the website design
between [page
A](https://www.metacritic.com/browse/games/score/metascore/all/ps4?sort=desc&page=6)
and [page
B](https://www.metacritic.com/browse/games/score/metascore/all/ps4?sort=desc&page=7):

``` r
url_a <- "https://www.metacritic.com/browse/games/score/metascore/all/ps4?sort=desc&page=6"
url_b <- "https://www.metacritic.com/browse/games/score/metascore/all/ps4?sort=desc&page=7"
css_selector <- "#main .positive"

len_a <- url_a %>%
  read_html() %>%
  html_nodes(css_selector) %>%
  length()

len_b <- url_b %>%
  read_html() %>%
  html_nodes(css_selector) %>%
  length()

print(len_a)
print(len_b)
print(len_a == len_b)
```

css style, that does account for changes in the website designbetween
[page
A](https://www.metacritic.com/browse/games/score/metascore/all/ps4?sort=desc&page=6)
and [page
B](https://www.metacritic.com/browse/games/score/metascore/all/ps4?sort=desc&page=7):

``` r
url_a <- "https://www.metacritic.com/browse/games/score/metascore/all/ps4?sort=desc&page=6"
url_b <- "https://www.metacritic.com/browse/games/score/metascore/all/ps4?sort=desc&page=7"
css_selector <- "#main .game"

len_a <- url_a %>%
  read_html() %>%
  html_nodes(css_selector) %>%
  length()

len_b <- url_b %>%
  read_html() %>%
  html_nodes(css_selector) %>%
  length()

print(len_a)
print(len_b)
print(len_a == len_b)
```

Legal aspects
=============

[Get to top](#fundamental-considerations)

Not all website allow web scraping, either in their usage terms or through their *robots.txt* file. See [this blog entry](https://ryo-n7.github.io/2020-05-14-webscrape-soccer-data-with-R/) for further considerations.

<https://www.marketwatch.com/support/disclaimer.asp>
3.4 No Modification of Content. You agree not to rearrange or modify the
Content. You agree not to create abstracts from, scrape or display
headlines from the Content for use on another web site or service or use
the Content for commercial purposes, including without limitation
algorithmic trading programs. You agree not to upload, post or submit
any Content from the Services to weblogs, newsgroups, mail lists or
electronic bulletin boards, except through services we specifically
provide for that purpose (e.g., an RSS Feed) or after we give our
written consent in advance.

------------------------------------------------------------------------

<https://moz.com/learn/seo/robotstxt>
User-agent: \*
Disallow: /
Using this syntax in a robots.txt file would tell all web crawlers not
to crawl any pages on www.example.com, including the homepage.

Additional resources
====================

[Get to top](#fundamental-considerations)

[Beckman, M., Guerrier, S., Lee, J., Molinari, R., Orso, S., &
Rudnytskyi, I. (2019). Web scraping in R. In An Introduction to
Statistical Programming Methods with
R.](https://smac-group.github.io/ds/web-scraping-in-r.html)
[Udemy - Automate the Boring Stuff with Python
Programming](https://www.udemy.com/course/automate/)
[w3schools.com - XPath
Tutorial](https://www.w3schools.com/xml/xpath_intro.asp)

license: MIT

branch_name: refs/heads/master

extension: md

gha_license_id: MIT

license_type: permissive


text:
---
lesson_id: 787cfcc66d1c
title: Waiting for external dependencies
permalink: "/adopting/dealing-with-dependencies/waiting-for-external-dependencies/"
course: adopting
vimeo: '259618225'
type: video
discussion_id: 787cfcc66d1c
---

## Preparation for the video
* [Prepare the Docker related files for the pg_isready example](https://github.com/learndocker/docker_examples/commit/8f87726)

## Changes to the examples
* [Wait for postgres to be up and running via an entrypoint](https://github.com/learndocker/docker_examples/commit/2400560)

## Links
* [Control startup order in Compose](https://docs.docker.com/compose/startup-order/)
* [pg_isready](https://www.postgresql.org/docs/9.6/static/app-pg-isready.html)

## Commands
```sh
docker-compose run app echo 1
```

repository: jlarrayoz/site

repo_name: jlarrayoz/site


text:
# Gauges

A gauge is a value that is sampled at some point in time. Typical examples
for gauges would be the size of a queue or number of threads in the running
state. Since gauges are not updated inline when a state change occurs, there is
no information about what might have occurred between samples.

Consider monitoring the behavior of a queue of tasks. If the data is being
collected once a minute, then a gauge for the size will show the size when
it was sampled. The size may have been much higher or lower at some point
during interval, but that is not known.

## Polled Gauges

The most common use of gauges is by registering a hook with Spectator so that
it will poll the values in the background. This is done by using the [PolledMeter]
helper class.

[PolledMeter]: http://netflix.github.io/spectator/en/latest/javadoc/spectator-api/com/netflix/spectator/api/patterns/PolledMeter.html

A polled gauge is registered by passing in an id, a reference to the object, and
a function to get or compute a numeric value based on the object. Note that
a gauge should only be registered once, not on each update. Consider this
example of a web server tracking the number of connections:

```java
class HttpServer {
  // Tracks the number of current connections to the server
  private AtomicInteger numConnections;

  public HttpServer(Registry registry) {
    numConnections = PolledMeter.using(registry)
      .withName("server.numConnections")
      .monitorValue(new AtomicInteger(0));
  }

  public void onConnectionCreated() {
    numConnections.incrementAndGet();
    ...
  }

  public void onConnectionClosed() {
    numConnections.decrementAndGet();
    ...
  }

  ...
}
```

The spectator registry will keep a weak reference to the object. If the object is
garbage collected, then it will automatically drop the registration. In the example
above, the registry will have a weak reference to `numConnections` and the server
instance will have a strong reference to `numConnections`. If the server instance
goes away, then the gauge will as well.

When multiple gauges are registered with the same id the reported value will
be the sum of the matches. For example, if multiple instances of the `HttpServer`
class were created on different ports, then the value `server.numConnections`
would be the total number of connections across all server instances. If a different
behavior is desired, then ensure your usage does not perform multiple registrations.

There are several different ways to register a gauge:

### Using Number

A gauge can also be created based on an implementation of Number. Note the number
implementation should be thread safe. For example:

```java
AtomicInteger size = new AtomicInteger();
PolledMeter.using(registry)
  .withName("queue.size")
  .monitorValue(size);
```

The call will return the Number so the registration can be inline on the
assignment:

```java
AtomicInteger size = PolledMeter.using(registry)
  .withName("queue.size")
  .monitorValue(new AtomicInteger());
```

Updates to the value are preformed by updating the number instance directly.

### Using Lambda

Specify a lambda that takes the object as parameter.

```java
public class Queue {

  @Inject
  public Queue(Registry registry) {
    PolledMeter.using(registry)
      .withName("queue.size")
      .monitorValue(this, Queue::size);
  }

  ...
}
```

!!! warning
    Be careful to avoid creating a reference to the object in the
    lambda. It will prevent garbage collection and can lead to a memory leak
    in the application. For example, by calling size without using the passed
    in object there will be a reference to `this`:

    ```
    PolledMeter.using(registry).withName("queue.size").monitorValue(this, obj -> size());
    ```

### Collection Sizes

For classes that implement `Collection` or `Map` there are helpers:

```java
Queue queue = new LinkedBlockingQueue();
PolledMeter.using(registry)
  .withName("queue.size")
  .monitorSize(queue);

Map<String, String> cache = new ConcurrentMap<>();
PolledMeter.using(registry)
  .withName("cache.size")
  .monitorSize(cache);
```

### Monotonic Counters

A common technique used by some libraries is to expose a monotonically increasing
counter that represents the number of events since the system was initialized. An
example of that in the JDK is [ThreadPoolExecutor.getCompletedTaskCount()] which
returns the number of completed tasks on the thread pool.

For sources like this the `monitorMonotonicCounter` method can be used:

```java
// For an implementation of Number
LongAdder tasks = new LongAdder();
PolledMeter.using(registry)
  .withName("pool.completedTasks")
  .monitorMonotonicCounter(tasks);

// Or using a lambda
ThreadPoolExecutor executor = ...
PolledMeter.using(registry)
  .withName("pool.completedTasks")
  .monitorMonotonicCounter(executor, ThreadPoolExecutor::getCompletedTaskCount);
```

For thread pools specifically, there are better options for getting standard metrics.
See the docs for the [Thread Pools extension](../ext/thread-pools.md) for more
information.

[ThreadPoolExecutor.getCompletedTaskCount()]: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ThreadPoolExecutor.html#getCompletedTaskCount--

## Active Gauges

Gauges can also be set directly by the user. In this mode the user is responsible for
regularly updating the value of the gauge by calling set. Looking at the HttpServer
example, with an active gauge it would look like:

```java
class HttpServer {
  // Tracks the number of current connections to the server
  private AtomicInteger numConnections;
  private Gauge gauge;

  public HttpServer(Registry registry) {
    numConnections = new AtomicInteger();
    gauge = registry.gauge("server.numConnections");
    gauge.set(numConnections.get());
  }

  public void onConnectionCreated() {
    numConnections.incrementAndGet();
    gauge.set(numConnections.get());
    ...
  }

  public void onConnectionClosed() {
    numConnections.decrementAndGet();
    gauge.set(numConnections.get());
    ...
  }

  ...
}
```

repository: guru-raj/spectator

repo_name: guru-raj/spectator


text:
---
layout: post
title: 697. Degree of an Array
category: [Leetcode]
description:
keywords: ['Array', 'Leetcode', 'Easy']
---
### [697. Degree of an Array](https://leetcode.com/problems/degree-of-an-array)

#### Tags: 'Array'

Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.

Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.

Example 1:

Input: [1, 2, 2, 3, 1]
Output: 2
Explanation:
The input array has a degree of 2 because both elements 1 and 2 appear twice.
Of the subarrays that have the same degree:
[1, 2, 2, 3, 1], [1, 2, 2, 3], [2, 2, 3, 1], [1, 2, 2], [2, 2, 3], [2, 2]
The shortest length is 2. So return 2.

Example 2:

Input: [1,2,2,3,1,4,2]
Output: 6

Note:

nums.length will be between 1 and 50,000.

nums[i] will be an integer between 0 and 49,999.

### Solution

path: /_drafts/0697-Degree of an Array.md

filename: 0697-Degree of an Array.md


text:
# UI Testing in iOS

## Basics

UI testing with XCUITest allows you to cover your app with UI tests that mimic user behavior on Simulator or a real device.

You write UI tests using XCTest library. Main classes that you will be using are the following.

### XCUIApplication
proxy for your app under test

    launch() - launches the app

    let app = XCUIApplication()
    app.launch()

### XCUIElement
proxy for a visible element on the screen.

    // exists - whether it exists
    // isHittable - whether it can be tapped
    // tap() - taps the element

    let button = app.buttons["myButton"]
    if button.exists && button.isHittable {
        button.tap()
    }

    // swipeUp|Down|Left|Right() - swipes on the element
    // label - accessibility label
    // identifier - accessibility identifier
    // value - accessibility value

    app.swipeUp()
    let colorLabel = app.staticTexts["color"]
    XCTAssertEqual(colorLabel.value as? String, "red")

    let buyButton = app.buttons["buyButton"]
    XCTAssertEqual(buyButton.label "Buy")

### XCUIElementQuery
encapsulates a query to find elements on the screen

    // element - returns the element

    let navBar = app.navigationBars.element

    // element(boundBy: <index>) - element at index

    let firstCell = app.tableViews.element.cells.element(boundBy: 0)

    // [<identifier|label>] - returns element by identifier or label,
    //    like buttons["close"] returns button with "close" label or identifier.
    //    Raises exception if multiple elements found with the same value.

    let button = app.buttons["myButton"]
    let label = app.staticTexts["Help"]

### Common UI elements

    .buttons
    .staticTexts
    .images
    .tableViews
    .collectionViews
    .cells

### Making your app UI-testable
* Adding identifier to buttons, images, and other elements
* Localization - use identifiers

* accessibilityIdentifier
* accessibilityLabel
* accessibilityElements

## Writing your test
* Using XCTAssert* assertions
* Arrange, Act, Assert
* One test does one (logical) thing
* Handy assertion to wait until exists instead of sleep
* Using screen objects
* Organizing your test code and reusing some pieces.
* Utility methods for tests.

## App launch arguments
* You can pass arguments to your app on XCUIApplication.launch() and parse them from ProcessArguments object accessible in your app.
* This is a way to turn on / turn off some functionality for UI testing, like mock servers or A/B testing.

## Table views and Collection views
* Cells are opaque to UI test system by default, you have to implement accessiblity container protocol for cells.
* Only cells that are visible on screen exist. If you have 100 items in a table, 4 items fitting on the screen, when you scroll and query tableView for cells it will always return 4 visible cells.
* Add index/indexPath to accessibility identifier of cell.
* You have to scroll until some element is visible or hittable.
* When working with XCUIElement cells, convert them to Cell objects for better code.
* allElementsBoundByIndex

## Screen sizes
* Different screen size may have different behavior, hence your UI test for one screen size may fail for another.
* Screen objects are useful to encapsulate the difference on the screen. If your objects for the same screen will have same interface, you can use the same test for different screen sizes.

## Localizations
* Using buttons' or static text's labels might be a bad idea if you are testing for multiple localizations. Either you need to include localized strings bundle in your tests and use localization keys or use accessiblity identifiers to locate screen elements in any locale.

## Working with network
* If your app works with network, mocking the network communication might be beneficial for tests stability - same input will have same output. One might create a mock server (Sinatra app) and use it during UI testing in the app instead of real servers.
* Another approach - override URLSessionProtocol to return mock responses.

## Cloud testing
In case you want to test your app on different devices, you can use TestDroid, Xamarin Test Cloud or Amazon Device Cloud

* [http://testcloud.xamarin.com](http://testcloud.xamarin.com)
* [https://bitbar.com](https://bitbar.com)

## Online resources
[https://github.com/joemasilotti/UI-Testing-Cheat-Sheet](https://github.com/joemasilotti/UI-Testing-Cheat-Sheet)

repository: Rifinio/UIAutomationClassroom

path: /UI Testing in iOS.md

filename: UI Testing in iOS.md

repo_name: Rifinio/UIAutomationClassroom


text:
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.

The distance between two adjacent cells is 1.

**Example 1:**

Input:

```
0 0 0
0 1 0
0 0 0
```

Output:

```
0 0 0
0 1 0
0 0 0
```

**Example 2:**

Input:

```
0 0 0
0 1 0
1 1 1
```

Output:

```
0 0 0
0 1 0
1 2 1
```

**Note:**

 1. The number of elements of the given matrix will not exceed 10,000.
 2. There are at least one 0 in the given matrix.
 3. The cells are adjacent in only four directions: up, down, left and right.

### [Editorial](https://leetcode.com/articles/01-matrix/)

repository: liupangzi/codekata

repo_name: liupangzi/codekata


text:
# neurotransmitter

## Synopsis

Link synapses together. Call a synapse from another one depending on the captured speech from the user.

## Options

| parameter | required | default | choices | comment                                                                                |
|-----------|----------|---------|---------|------------------------------------------------------------------------------------------------|
| links     | yes      |         |         | List of tuple synapse/answer object                                                            |
| synapse   | yes      |         |         | Name of the synapse to launch if the captured audio from the STT is present in the answer list |
| answers   | yes      |         |         | List of sentences that are valid for running the attached synapse                              |
| default   | yes      |         |         | Name of the synapse to launch if the captured audio doesn't match any answers                  |

## Return Values

None

## Synapses example

Here the synapse will ask the user if he likes french fries. If the user answer "yes" or "maybe", he will be redirected to the synapse2 that say something.
If the user answer no, he will be redirected to another synapse that say something else.
If the user say something that is not present in `answers`, he will be redirected to the synapse4.

```
 - name: "synapse1"
    signals:
      - order: "ask me a question"
    neurons:
      - say:
          message: "do you like french fries?"
      - neurotransmitter:
          links:
            - synapse: "synapse2"
              answers:
                - "absolutely"
                - "maybe"
            - synapse: "synapse3"
              answers:
                - "no at all"
          default: "synapse4"

  - name: "synapse2"
    signals:
      - order: "synapse2"
    neurons:
      - say:
          message: "You like french fries!! Me too! I suppose..."

  - name: "synapse3"
    signals:
      - order: "synapse3"
    neurons:
      - say:
          message: "You don't like french fries. It's ok."

  - name: "synapse4"
    signals:
      - order: "synapse4"
    neurons:
      - say:
          message: "I havn't understood your answer"
```

repository: pierre-alain-b/kalliope

repo_name: pierre-alain-b/kalliope


text:
# exporteer\_imdb

This is a very simple tool for exporting your data from IMDB.

Currently, it only retrieves your watchlist and ratings. It uses [puppeteer](https://github.com/puppeteer/puppeteer) to download the CSV exports of them from IMDB.

## Setup

1. Install node.js and npm
2. `npm install -g exporteer_imdb`

## Usage

```bash
export IMDB_EMAIL=your_account_email_address
export IMDB_PASSWORD=your_account_password
exporteer_imdb outputdir
```

This will create the folder `outputdir` (if it doesn't already exist), and write the files `watchlist.csv` and `ratings.csv` to it.

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/brokensandals/exporteer_imdb.

## License

This is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

gha_language: JavaScript


text:
## Technology

I've been interested in tech since I was 9 years old and my parents gave me a hand-me-down laptop loaded with Windows 98.

I learned how to type on it using Mavis Beacon - then crashed it a couple of months later by trying to install a racing game on it written for Windows XP.

In 8th grade I was introduced to programming with [Turbo Pascal][pascal] and crashed my new XP machine several times.

During high school I took several Java courses, and also did all of the classic things computer kids do - proxied around the school filter to get on Facebook and Youtube, sniffed school wifi passwords with `aircrack-ng`, figured out how to access password-protected XP machines using rainbow tables, etc., etc.  At this point I had figured out how to dual boot Linux and was pretty sure that I wanted to study computer science in college.

Now, after some years in college, I've got a decent amount of experience in a number of languages and quite a lot of algorithm theory under my belt.  I've gotten _a lot of practice_ reading documentation.  And with all that, I still crash my computer a couple times a year by messing around with the internals - and have fun doing it.

[pascal]: https://en.wikipedia.org/wiki/Turbo_Pascal "Wikipedia: Turbo Pascal"

repository: mosbasik/portfolio

extension: markdown

repo_name: mosbasik/portfolio


text:
---
title: Photoplacer
summary: A light weight Lumen application for embedding temporary images in a web template. Host your own stock images for use in your design & development workflow.
collection: portfolio
tags:
    - PHP
    - Lumen
accent: "#009058"
---

Photoplacer is a simple PHP application for providing placeholder images for your projects. It allows you to define your own categories for organising your image bank, and also to apply various filters to your images on the fly.

![Home page](/images/portfolio/photoplacer/homepage.png)

Aiming for simplicity and speed, the Lumen PHP micro-framework was chosen as a suitable base due to its basis on the reliable and well-documented Laravel framework. The result is a lean application with a great deal of flexibility allowing for its primary users, front-end developers to quickly populate the image store and organise their images by category.

Complete with a full suite of [tests](https://github.com/Jamesyps/Photoplacer/blob/master/tests/ImageControllerRoutesTest.php), the code is robust, maintainable and 100% open source.

![UI](/images/portfolio/photoplacer/ui.png)

The UI reflects the simple URL structure for accessing images. I wished to avoid the unclear structure of /width/height/category, instead implementing the well known width x height notation. Filters continue this clear labeling of URL segments, having a prefix of filter: so at no point can users be uncertain between width, height, categories or filter types.

![Landing Page](/images/portfolio/photoplacer/project-page.png)

Accompanying this project, a [re-usable Jekyll template](https://github.com/Jamesyps/Jekyll-Project-Page) was created to serve as the products landing page, containing installation instructions, configuration help and other important documentation.

### Further Reading

You can see more by visiting the project page and source code.

* [Project Page](http://photoplacer.jameswigger.co.uk)
* [Repository](https://github.com/Jamesyps/Photoplacer)


text:
# HTML Components

Combining comments, semantic HTML, and CSS to build HTML components.

## The Document Object Model (DOM)

The Document Object Model is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The document can be further processed and the results of that processing can be incorporated back into the presented page. This is an overview of DOM-related materials here at W3C and around the web.

<img src="http://www.w3.org/TR/DOM-Level-2-Core/images/table.gif">

The HTML you write is parsed by the browser and turned into the DOM. But your HTML is not the DOM.

## Semantic Review

HTML semantic tags can be considered components

```html
<article>
    <header>
        <h1>First Week at NSS</h1>
    </header>

    <section>
        Saw some amazing projects from the previous
        cohort. I'm nervous that I won't be able to do
        that in 3 months, but the instructors keep telling
        me that I will.
    </section>

    <footer>
    By Johhny Q. Student © 2018
    </footer>
</article>

<aside>
    <header>
        <h2>Promoted Articles</h2>
    </header>

    <ul>
        <li>First Week at NSS</li>
        <li>Starting NSS Soon</li>
        <li>I Got Accepted!</li>
        <li>Thinking of Attending a Bootcamp</li>
    </ul>
</aside>
```

Here is a visualization for how semantic tags are intended to be in HTML for structuring a typical web page.

![semantic tags](./images/html-semantic-tags.png)

## The Importance of Comments

One of the most important things you can do for yourself, and your teammates, is comment your code. Let's start with adding comments for your components in this HTML snippet.

```html
<!-- Blog Post Component -->
<article>

    <!-- Header Element of Blog Post Component -->
    <header>
        <h1>First Week at NSS</h1>
    </header>

    <!-- Content Element of Blog Post Component -->
    <section>
        Saw some amazing projects from the previous
        cohort. I'm nervous that I won't be able to do
        that in 3 months, but the instructors keep telling
        me that I will.
    </section>

    <!-- Footer Element of Blog Post Component -->
    <footer>
    By Johhny Q. Student © 2018
    </footer>
</article>

<!-- Sidebar Component -->
<aside class="sidebar">
    <!-- Header Element of Blog Post Component -->
    <header>
        <h2>Promoted Articles</h2>
    </header>

    <!-- List Element of Blog Post Component -->
    <ul>
        <li>First Week at NSS</li>
        <li>Starting NSS Soon</li>
        <li>I Got Accepted!</li>
        <li>Thinking of Attending a Bootcamp</li>
    </ul>
</aside>
```

## Intelligent CSS Class Naming Conventions

Styling components intelligently can be handled through naming your classes according to the component name. One popular convention is the [BEM method](http://getbem.com/introduction/).

```html
<!-- Blog Post Component -->
<article class="blogpost">

    <!-- Header Element of Blog Post Component -->
    <header class="header header--xxlarge blogpost__header">
        <h1>First Week at NSS</h1>
    </header>

    <!-- Content Element of Blog Post Component -->
    <section class="blogpost__content">
        Saw some amazing projects from the previous
        cohort. I'm nervous that I won't be able to do
        that in 3 months, but the instructors keep telling
        me that I will.
    </section>

    <!-- Footer Element of Blog Post Component -->
    <footer class="blogpost__footer">
    By Johhny Q. Student © 2018
    </footer>
</article>

<!-- Sidebar Component -->
<aside class="sidebar">
    <!-- Header Element of Blog Post Component -->
    <header class="header header--medium sidebar__header">
        <h2>Promoted Articles</h2>
    </header>

    <!-- List Element of Blog Post Component -->
    <ul  class="sidebar__items">
        <li>First Week at NSS</li>
        <li>Starting NSS Soon</li>
        <li>I Got Accepted!</li>
        <li>Thinking of Attending a Bootcamp</li>
    </ul>
</aside>
```

```css
.blogpost {
    padding: 10px;
    color: goldenrod;
    background-color: fuscia;
    margin: 0;
}

.sidebar {
    border: 1px solid black;
    float: right;
}
```

## Additional Reading

1. [CSS Tricks - BEM](https://css-tricks.com/bem-101/)

## Videos to Watch

1. [Introduction to BEM - A front-end methodology](https://www.youtube.com/watch?v=IO-4Z32O--c)
1. [020 CSS Architecture Components and BEM](https://www.youtube.com/watch?v=8wX78mtlNyU)

## Practice

You're going to create an HTML component to represent a political candidate. Specifically, the representative of your Congressional district. Visit the GovTrack site link below, enter in your home address, and you'll find basic information about your representative.

[GovTrack - Congressional District Map](https://www.govtrack.us/congress/members/map)

1. In your HTML, create an `article` tag that will serve as your main representative component. Give the element a unique identifier.
1. In this component, create a sub-component for basic information using the `section` tag. In this section create elements for the representative's image, name, district info, and political affiliation.
1. Beneath the basic information, you will create a sub-component, using a `section` tag, to list any committees the candidate is serving on.
1. The last component will hold links to any legislation that your representative has enacted.

Make sure you use good BEM-style class names for each element in your components. Put a comment above each component explaining what it is.

repository: kgalleg/client-side-mastery

repo_name: kgalleg/client-side-mastery


text:
# flutter_material_showcase

Material Design components showcase for Flutter apps.

This project is based on Ataul's [Material Design Components Showcase](https://github.com/ataulm/material-design-components-showcase) Android project, but for Flutter!

You can use this Flutter package to preview your `ThemeData` and see how it looks like with different Material Widgets.

![image](https://raw.githubusercontent.com/miquelbeltran/flutter_material_showcase/master/screenshot.png)

## Usage

Add the `MaterialShowcase` Widget somewhere in your app:

```dart
MaterialApp(
  title: 'Flutter Demo',
  theme: ThemeData(
    primarySwatch: Colors.blue,
  ),
  home: Scaffold(
    body: ListView(
      children: <Widget>[
        MaterialShowcase(),
      ],
    ),
  ),
);
```

Then play with the different parameters in `ThemeData` and see how it looks like.

## Contributing

- Additions to the `MaterialShowcase` Widget are welcome.
- Documentation improvements are welcome.

## License

```
MIT License

Copyright (c) 2019 Miguel Beltran
```

Miguel Beltran - [beltran.work](https://beltran.work)

gha_language: Dart


text:
# properties-maven-extension

[![Build Status](https://img.shields.io/travis/pascalgn/properties-maven-extension.svg?style=flat-square)](https://travis-ci.org/pascalgn/properties-maven-extension) [![License](https://img.shields.io/github/license/pascalgn/properties-maven-extension.svg?style=flat-square)](LICENSE)

A Maven extension to introduce properties *before* the build is started.
This allows the usage of dynamic project versions like `1.2.3.${sha1}`.

## Example

For a simple example, consider the following POM file:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>example-artifact</artifactId>
    <version>1.2.3.${sha1}</version>

    <properties>
        <sha1>${git.commit.id.abbrev}</sha1>
    </properties>
</project>
```

For a useful project version, the build would have to be invoked like `mvn clean install -Dsha1=abcd123`.

Using the Properties Maven Extension, this configuration can be set in the project directory itself,
by adding the following `.mvn/extensions.xml` file to the project:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
    <extension>
        <groupId>com.github.pascalgn</groupId>
        <artifactId>properties-maven-extension</artifactId>
        <version>0.4.0</version>
    </extension>
</extensions>
```

A build is now as easy as `mvn clean install` and the commit hash will be available as a property,
so that the final project version will be `1.2.3.abcd123` (depending on the current commit hash).

## Requirements

You will need at least Maven 3.5.0 for this to work. See
[the release notes](https://maven.apache.org/docs/3.5.0/release-notes.html) for more information.
You also need to run your Maven build with at least Java 8 (due to the [JGit](https://eclipse.org/jgit) dependency).

## Properties

The following properties are currently provided by the extension:

* `git.branch`, the current branch name (*master*, *feature/some-feature*, etc.)
* `git.build.datetime.simple`, build time in simple datetime format (yyyyMMdd_HHmmss)
* `git.commit.id`, the full SHA of the HEAD commit (*cbf1b9a1be984a9f61b79a05f23b19f66d533537*)
* `git.commit.id.abbrev`, the abbreviated SHA of the HEAD commit (*cbf1b9a*)
* `git.count`, the current number of commits reachable from HEAD
* `git.commit.color.value`, always the first six characters of the commit SHA (*cbf1b9*)
* `git.commit.color.name`, the name of the closest matching color (*Gossip*)
* `git.commit.color.lightness`, the lightness of the color, in the range 0 - 100 (inclusive)
* `git.commit.color.foreground`, a recommended foreground color, based on the lightness (*000000* or *ffffff*)
* `git.dir.git`, the absolute path of the repository (*/home/user/workspace/myproject/.git*)
* `git.dir.worktree`, the absolute path of the working tree (*/home/user/workspace/myproject*)
* `git.tag.last`, last tag from sorted tag list (*v1.2.3*)

If you need more properties, feel free to create an [issue](https://github.com/pascalgn/properties-maven-extension/issues)
or a [pull request](https://github.com/pascalgn/properties-maven-extension/pulls).

## Notes

* When you use placeholders in your version, be sure to also read the [Maven CI Friendly Versions](https://maven.apache.org/maven-ci-friendly.html) guide, especially the section about the [flatten-maven-plugin](http://www.mojohaus.org/flatten-maven-plugin)
* When building in Jenkins, you might run into the issue that the
  [branch name is not set due to detached HEAD](https://stackoverflow.com/questions/39297783/detached-head-w-jenkins-git-plugin-and-branch-specifier)
* The versioning scheme of this project follows [semantic versioning](http://semver.org/)

## Related projects

* There are already plugins providing properties, like [maven-git-commit-id-plugin](https://github.com/ktoso/maven-git-commit-id-plugin).
  However, the POM structure, including versions, is built by Maven before any plugins are executed, hence this extension.
* The [maven-git-versioning-extension](https://github.com/qoomon/maven-git-versioning-extension) is very similar,
  but it directly sets the project version, based on existing branches and tags, which makes it less flexible.

## License

The Properties Maven Extension is licensed under the Apache License, Version 2.0.

This software uses the Resene RGB values list, see [the license](src/main/resources/resene.md) for more details.

repository: pascalgn/properties-maven-extension

gha_language: Java

repo_name: pascalgn/properties-maven-extension


text:
🚨 No longer maintained. Moved to [@reallyland/node_mod](https://github.com/reallyland/node_mod). 🚨

@reallyland/polling-observer

A new way of running polling function with observer pattern

[![tippin.me][tippin-me-badge]][tippin-me-url]
[![Follow me][follow-me-badge]][follow-me-url]

[![Version][version-badge]][version-url]
[![Node version][node-version-badge]][node-version-url]
[![MIT License][mit-license-badge]][mit-license-url]

[![Downloads][downloads-badge]][downloads-url]
[![Total downloads][total-downloads-badge]][downloads-url]
[![Packagephobia][packagephobia-badge]][packagephobia-url]
[![Bundlephobia][bundlephobia-badge]][bundlephobia-url]

[![CircleCI][circleci-badge]][circleci-url]
[![Dependency Status][daviddm-badge]][daviddm-url]
[![codecov][codecov-badge]][codecov-url]
[![Coverage Status][coveralls-badge]][coveralls-url]

[![codebeat badge][codebeat-badge]][codebeat-url]
[![Codacy Badge][codacy-badge]][codacy-url]
[![Code of Conduct][coc-badge]][coc-url]

> Like PerformanceObserver or any other observer APIs you could find in a browser, but this is for polling. Not only does it run polling with defined parameters but also collect polling metrics for each run until timeout or a defined condition fulfills.

## Table of contents

- [Pre-requisites](#pre-requisites)
  - [Node.js](#nodejs)
  - [Browser](#browser)
- [Setup](#setup)
  - [Install](#install)
  - [Usage](#usage)
    - [TypeScript or native ES Modules](#typescript-or-native-es-modules)
    - [Node.js](#nodejs-1)
  - [Browser](#browser-1)
    - [ES Modules](#es-modules)
    - [UMD](#umd)
- [Demo](#demo)
- [API Reference](#api-reference)
  - [OnfinishFulfilled<T>](#onfinishfulfilledlttgt)
  - [OnfinishRejected](#onfinishrejected)
  - [PollingMeasure](#pollingmeasure)
    - [Methods](#methods)
      - [PollingMeasure.toJSON()](#pollingmeasuretojson)
  - [PollingObserver<T>](#pollingobserverlttgt)
    - [Methods](#methods-1)
      - [PollingObserver.observe(callback[, options])](#pollingobserverobservecallback-options)
      - [PollingObserver.disconnect()](#pollingobserverdisconnect)
      - [PollingObserver.takeRecords()](#pollingobservertakerecords)
    - [Event handler](#event-handler)
      - [PollingObserver.onfinish](#pollingobserveronfinish)
- [deno](#deno)
- [License](#license)

## Pre-requisites

### Node.js

- [Node.js][nodejs-url] >= 8.16.0
- [NPM][npm-url] >= 6.4.1 ([NPM][npm-url] comes with [Node.js][nodejs-url] so there is no need to install separately.)
- [perf_hooks] (Added in<EMAIL_ADDRESS>behind experimental flag)

### Browser

- [window.Performance]

## Setup

### Install

```sh
# Install via NPM
$ npm install --save @reallyland/polling-observer
```

### Usage

[Performance] API is strictly required before running any polling. To ensure `performance.now` is available globally on Node.js, you can do:

```js
/** Node.js */
import { performance } from 'perf_hooks';

global.performance = performance; // or globalThis.performance = performance;
```

#### TypeScript or native ES Modules

```ts
interface DataType {
  status: 'complete' | 'in-progress';
  items: Record<string, any>[];
}

import { PollingObserver } from '@reallyland/polling-observer';

const obs = new PollingObserver((data/** list, observer */) => {
  const { status, items } = data || {};
  const itemsLen = (items && items.length) || 0;

  /** Stop polling when any of the conditions fulfills */
  return 'complete' === status || itemsLen > 99;
});

obs.observe(
  async () => {
    /** Polling callback - fetch resources */
    const r = await fetch('https://example.com/api?key=123');
    const d = await r.json();

    return d;
  },
  /** Run polling (at least) every 2 seconds and timeout if it exceeds 30 seconds */
  {
    interval: 2e3,
    timeout: 30e3,
  }
);

/**
 * When polling finishes, it will either fulfill or reject depending on the status:
 *
 * | Status  | Returns   |
 * | ------- | --------- |
 * | finish  | <value>   |
 * | timeout | <value>   |
 * | error   | <reason>  |
 *
 */
obs.onfinish = (data, records/**, observer */) => {
  const { status, value, reason } = data || {};

  switch (status) {
    case 'error': {
      console.error(`Polling fails due to: `, reason);
      break;
    }
    case 'timeout': {
      console.log(`Polling timeouts after 30 seconds: `, value);
      break;
    }
    case 'finish':
    default: {
      console.log(`Polling finishes: `, value);
    }
  }

  console.log(`Formatted polling records: `, records.map(n => n.toJSON()));
  /**
   * [
   *   {
   *     duration: 100,
   *     entryType: 'polling-measure',
   *     name: 'polling:0',
   *     startTime: 100,
   *   },
   *   ...
   * ]
   */

  obs.disconnect(); /** Disconnect to clean up */
};
```

#### Node.js

```js
const { PollingObserver } = require('@reallyland/polling-observer');

const obs = new PollingObserver((data/** entries, observer */) => {
  const { status, items } = data || {};
  const itemsLen = (items && items.length) || 0;

  /** Stop polling when any of the conditions fulfills */
  return 'complete' === status || itemsLen > 99;
});

obs.observe(
  async () => {
    /** Polling callback - fetch resources */
    const r = await fetch('https://example.com/api?key=123');
    const d = await r.json();

    return d;
  },
  /** Run polling (at least) every 2 seconds and timeout if it exceeds 30 seconds */
  {
    interval: 2e3,
    timeout: 30e3,
  }
);

/**
 * When polling finishes, it will either fulfill or reject depending on the status:
 *
 * | Status  | Returns   |
 * | ------- | --------- |
 * | finish  | <value>   |
 * | timeout | <value>   |
 * | error   | <reason>  |
 *
 */
obs.onfinish = (data, entries/**, observer */) => {
  const { status, value, reason } = data || {};

  switch (status) {
    case 'error': {
      console.error(`Polling fails due to: `, reason);
      break;
    }
    case 'timeout': {
      console.log(`Polling timeouts after 30 seconds: `, value);
      break;
    }
    case 'finish':
    default: {
      console.log(`Polling finishes: `, value);
    }
  }

  console.log(`Formatted polling entries: `, entries.map(n => n.toJSON()));
  /**
   * [
   *   {
   *     duration: 100,
   *     entryType: 'polling-measure',
   *     name: 'polling:0',
   *     startTime: 100,
   *   },
   *   ...
   * ]
   */

  obs.disconnect(); /** Disconnect to clean up */
};
```

### Browser

#### ES Modules

```html
<!doctype html>
<html>
  <head>
    <script type="module">
      import { PollingObserver } from 'https://unpkg.com/<EMAIL_ADDRESS>
      // --snip
    </script>
  </head>
</html>
```

#### UMD

```html
<!doctype html>
<html>
  <head>
    <script src="https://unpkg.com/<EMAIL_ADDRESS>    <script>
      var { PollingObserver } = window.PollingObserver;

      // --snip
    </script>
  </head>
</html>
```

## Demo

[![Edit PollingObserver](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/pollingobserver-b269s?fontsize=14)

## API Reference

### OnfinishFulfilled<T>

```ts
interface OnfinishFulfilled<T> {
  status: 'finish' | 'timeout';
  value: T;
}
```

### OnfinishRejected

```ts
interface OnfinishRejected {
  status: 'error';
  reason: Error;
}
```

### PollingMeasure

```ts
interface PollingMeasure {
  duration: number;
  entryType: 'polling-measure';
  name: string;
  startTime: number;
}
```

- `duration` <[number][number-mdn-url]> Duration of the polling takes in milliseconds.
- `entryType` <[string][string-mdn-url]> Entry type, defaults to `polling-measure`.
- `name` <[string][string-mdn-url]> Polling name in the format of `polling:<index>` where `<index>` starts from `0` and increments on each polling.
- `startTime` <[string][string-mdn-url]> Relative timestamp (in milliseconds ) indicates when the polling starts at.

#### Methods

##### PollingMeasure.toJSON()

- <[Function][function-mdn-url]> Returns a JSON representation of the polling object's properties.

---

### PollingObserver<T>

- `conditionCallback` <[Function][function-mdn-url]> Condition callback to be executed in each polling and return the condition result in the type of boolean, e.g. return `true` to stop next poll.
  - `data` <`T`> Polling data returned by `callback` in the type of `T` which defined in the [PollingObserver.observe()] method.
  - `entries` <[Array][array-mdn-url]<[PollingMeasure]>> A list of [PollingMeasure] objects.
  - `observer` <[PollingObserver]<`T`>> Created [PollingObserver] object.
  - returns: <[boolean][boolean-mdn-url]> If `true`, the polling stops. Returning `false` will result in an infinite polling as the condition will never meet.
- returns: <[PollingObserver]<`T`>> [PollingObserver] object.

#### Methods

##### PollingObserver.observe(callback[, options])

The method is used to initiate polling with a polling callback and optional configuration.

- `callback` <[Function][function-mdn-url]> Callback to be executed in each polling and return the result so that it will be passed as the first argument in `conditionCallback`.
  - returns: <`T` | [Promise][promise-mdn-url]<`T`>> Return polling result in the type of `T` or `Promise<T>` in each polling.
- `options` <[Object][object-mdn-url]> Optional configuration to run the polling.
  - `interval` <[number][number-mdn-url]> Optional interval in milliseconds. This is the minimum delay before starting the next polling.
  - `timeout` <[number][number-mdn-url]> Optional timeout in milliseconds. Polling ends when it reaches the defined timeout even though the condition has not been met yet. _As long as `timeout` is not a number or it has a value that is less than 1, it indicates an infinite polling. The polling needs to be stopped manually by calling [PollingObserver.disconnect()] method._

##### PollingObserver.disconnect()

Once a `PollingObserver` disconnects, the polling stops and all polling metrics will be cleared. Calling [PollingObserver.takeRecords()] after the disconnection will always return an empty record.

A `onfinish` event handler can be used to retrieve polling records after a disconnection but it has to be attached before disconnecting the observer.

##### PollingObserver.takeRecords()

The method returns a list of [PollingMeasure] object containing the metrics of each polling.

- returns: <[Array][array-mdn-url]<[PollingMeasure]>> A list of [PollingMeasure] objects.

#### Event handler

##### PollingObserver.onfinish

_Note that no `finish` event fires when the polling finishes. So `observer.addEventListener('finish', ...)` will not work._

Event handler for when a polling finishes. When a polling finishes, it can either be fulfilled with a `value` or rejected with a `reason`. Any one of which contains a `status` field to tell the state of the finished polling.

When a polling fulfills, it returns an [OnfinishFulfilled<T>] object with `status` set to `finish` or `timeout` and a `value` in the type of `T`.

When a polling rejects, it returns an [OnfinishRejected] object with `status` set to `error` and a `reason` in the type of [Error][error-mdn-url].

| Status    | Returns        |
| --------- | -------------- |
| `finish`  | <value>  |
| `timeout` | <value>  |
| `error`   | <reason> |

## deno

_Coming soon._

## License

[MIT License](https://motss.mit-license.org/) © Rong Sen Ng (motss)

[typescript-url]: https://github.com/Microsoft/TypeScript
[nodejs-url]: https://nodejs.org
[npm-url]: https://www.npmjs.com
[node-releases-url]: https://nodejs.org/en/download/releases
[perf_hooks]: https://nodejs.org/api/perf_hooks.html
[Performance]: https://developer.mozilla.org/en-US/docs/Web/API/Performance
[window.performance]: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now

[PollingObserver]: #pollingobservert
[PollingObserver.observe()]: #pollingobserverobservecallback-options
[PollingObserver.disconnect()]: #pollingobserverdisconnect
[PollingObserver.takeRecords()]: #pollingobservertakerecords
[PollingMeasure]: #pollingmeasure
[PollingMeasure.toJSON()]: #pollingmeasuretojson
[OnfinishFulfilled<T>]: #onfinishfulfilledt
[OnfinishRejected]: #onfinishrejected

[array-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
[boolean-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[function-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
[map-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
[number-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number
[object-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
[promise-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
[regexp-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
[set-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
[string-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
[void-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void
[error-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error

[tippin-me-badge]: https://badgen.net/badge/%E2%9A%A1%EF%B8%8Ftippin.me/@igarshmyb/F0918E
[follow-me-badge]: https://flat.badgen.net/twitter/follow/igarshmyb?icon=twitter

[version-badge]: https://flat.badgen.net/npm/v/@reallyland/polling-observer?icon=npm
[node-version-badge]: https://flat.badgen.net/npm/node/@reallyland/polling-observer
[mit-license-badge]: https://flat.badgen.net/npm/license/@reallyland/polling-observer

[downloads-badge]: https://flat.badgen.net/npm/dm/@reallyland/polling-observer
[total-downloads-badge]: https://flat.badgen.net/npm/dt/@reallyland/polling-observer?label=total%20downloads
[packagephobia-badge]: https://flat.badgen.net/packagephobia/install/@reallyland/polling-observer
[bundlephobia-badge]: https://flat.badgen.net/bundlephobia/minzip/@reallyland/polling-observer

[circleci-badge]: https://flat.badgen.net/circleci/github/reallyland/polling-observer?icon=circleci
[daviddm-badge]: https://flat.badgen.net/david/dep/reallyland/polling-observer
[codecov-badge]: https://flat.badgen.net/codecov/c/github/reallyland/polling-observer?label=codecov&icon=codecov
[coveralls-badge]: https://flat.badgen.net/coveralls/c/github/reallyland/polling-observer?label=coveralls

[codebeat-badge]: https://codebeat.co/badges/8400d381-c10e-4d5a-a00b-9478b50eb129
[codacy-badge]: https://api.codacy.com/project/badge/Grade/e9ea6e2433c5449b8151a4606fd60148
[coc-badge]: https://flat.badgen.net/badge/code%20of/conduct/pink

[tippin-me-url]: https://tippin.me/@igarshmyb
[follow-me-url]: https://twitter.com/igarshmyb?utm_source=github.com&utm_medium=referral&utm_content=reallyland/polling-observer

[version-url]: https://www.npmjs.com/package/@reallyland/polling-observer
[node-version-url]: https://nodejs.org/en/download
[mit-license-url]: https://github.com/reallyland/polling-observer/blob/master/LICENSE

[downloads-url]: https://www.npmtrends.com/@reallyland/polling-observer
[packagephobia-url]: https://packagephobia.now.sh/result?p=%40reallyland%2Fpolling-observer
[bundlephobia-url]: https://bundlephobia.com/result?p=@reallyland/polling-observer

[circleci-url]: https://circleci.com/gh/reallyland/polling-observer/tree/master
[daviddm-url]: https://david-dm.org/reallyland/polling-observer
[codecov-url]: https://codecov.io/gh/reallyland/polling-observer
[coveralls-url]: https://coveralls.io/github/reallyland/polling-observer?branch=master

[codebeat-url]: https://codebeat.co/projects/github-com-reallyland-polling-observer-master
[codacy-url]: https://www.codacy.com/app/motss/polling-observer?utm_source=github.com&utm_medium=referral&utm_content=reallyland/polling-observer&utm_campaign=Badge_Grade
[coc-url]: https://github.com/reallyland/polling-observer/blob/master/CODE-OF-CONDUCT.md

repository: reallyland/polling-observer

repo_name: reallyland/polling-observer


text:
# dev-npm-package-react-typescript-boilerplate

It is a boilerplate for starting developing react library to be published to npm.

It setups
- minimum building environment (including React and TypeScript)
- a GitHub Action to publish your library to npm
- a GitHub Action to publish the demo page as a GitHub Pages
- several scripts to help developing

# How to use

## prepare local repository

1. clone this repository
1. `git remote set-url origin [your-repository]`

## setup npm package information

1. edit package.json
	- "name" of the npm package you are going to publish
	- "author"
	- "repository"
1. you can do `git add` and `git commit` as usual

## setup dependencies

1. run `yarn setup:all`

## develop your library

1. rename or replace `src/ModuleFile.ts` with your library file(s)
1. edit `index.js` and `index.d.ts` as if your library files are all in `dist` folder.
1. you can do `git add` and `git commit` as usual

__NOTE: you must start a commit message like "perf:", "feat:" or "fix:" in at least one of the commits so that the auto-publishing action can decide next version number.__
more detail; see a documentation of [semantic-release](https://github.com/semantic-release/semantic-release)
It's recommended to use [git-todos](https://github.com/z0al/git-todos) together.

related scripts

```
# install dependencies
yarn run build
# build sources in `src` into `dist` folder
yarn run build
```

## create demo page

1. start creating your demo page from `demo/src/components/App.tsx`
1. you can `git add` and `git commit` as usual

related scripts

```
# install dependencies
yarn run build:demo
# build demo page into `demo/dist` folder
# it also copies `demo/dist` into `docs` for GitHub Pages
yarn run build:demo

# build library and start running local server to host demo page
yarn run dev
```

## setup remote repository

### get npm access token

1. if not yet, create npm user account on [npm](https://www.npmjs.com/)
1. create new token via `Settings -> Auth Tokens`
1. copy the token to clipboard

### prepare for publishing to npm

1. if not yet, create a git repository on [GitHub](https://github.com/)
1. go to `Settings -> Secrets`
1. create a Secret with
	- name: NPM_TOKEN
	- value: [copied npm token]

### publishing GitHub Pages
1. go to `Settings => Options -> GitHub Pages`
1. Select gh-pages branch
__note: you cannot set this before `git push` first time__
1. Select Folder `/(root)`

## Release!

1. commit your updates
__Again confirm at least one of your commit messages starts with like "perf:", "feat:" or "fix:" otherwise no new version will be released__
1. just `git push` and the new version of npm package and latest demo page will be published automatically by GitHub Actions


text:
# Azure Pass

Use your Azure Pass Code to create a Subscription [here](https://www.microsoftazurepass.com/)

> Note: Azure Passes can only be used once per e-mail account. Please do not use Azure AD Accounts with existing Azure Subscriptions - if you do so you will not get the credits and the code entered will be invalidated.

![azure-pass](_images/azure-pass.jpg)

Click Start & Log In:

![azure-pass](_images/log-in.jpg)

Confirm Account:

![azure-pass](_images/account-confirm.jpg)

Enter Code:

![azure-pass](_images/promo-code.jpg)

Complete Profile:

![azure-pass](_images/complete-profile.jpg)

Agree to Agreement:

![azure-pass](_images/agreement.jpg)

Wait for Setup to complete:

![azure-pass](_images/acct-setup.jpg)

Congratulations! You have claimed an Azure Pass for this training and activated your account on an Azure Subscription with 50$ spending limit.

![azure-pass](_images/azure-welcome.jpg)

license: Unlicense

branch_name: refs/heads/main

gha_license_id: Unlicense


text:
# jsonDoc
## History
_jsonDoc_ started out as _bsonDoc.pas_ and `IBSONDocument` in the [TMongoWire](https://github.com/stijnsanders/TMongoWire) project. Since it was a solid [JSON](http://json.org/) parser, based on IUnknowns (for the reference counting) and Variants (I really, really hate long lists of overloads for allkinds of types). The need arose to manipulate JSON in several projects unrelated to [MongoDB](https://mongod.org/), so the idea surfaced to have a dedicated project around `IJSONDocument`.

(To complete the move, [TMongoWire](https://github.com/stijnsanders/TMongoWire) has since then replaced `bsonDoc.pas` with `jsonDoc.pas` and separate conversion functions to convert from and to [BSON](http://bsonspec.org/).)

## API

### JSON

To create a new `IJSONDocument` instance:

    function JSON: IJSONDocument; overload;

To create and populate a new `IJSONDocument` instance:

    function JSON(const x: array of Variant): IJSONDocument; overload;

Pass a list of alternately keys and values, suffix the key with `{` to start an embedded document, and use key `}` to close it. E.g.: with

    d:=JSON(['a',1,'b{','x','foo','}','c{','x','bar','}','d',VarArrayOf([JSON(['x','hello']),JSON(['y','world'])]),'e',true]);

`d.ToString` will return `{"a":1,"b":{"x":"foo"},"c":{"x":"bar"},"d":[{"x":"hello"},{"x":"world"}],"e":true}`.

Convert a variant into an IJSONDocument reference.

    function JSON(x: Variant): IJSONDocument; overload;

Depending on the value of the argument:

* string types are parsed into a new `IJSONDocument` instance,
* Null (or empty or unassigned) returns `nil`,
* in all other cases the variant is probed for a reference to an `IJSONDocument` instace.

### IJSONDocument

Merge a string with JSON data into the `IJSONDocument` instance, existing keys will get their values overwritten (see `Clear` below).

    function Parse(const JSONData: WideString): IJSONDocument;

Convert the data in the `IJSONDocument` instance into a JSON string.

    function ToString: WideString;

Convert the data in the `IJSONDocument` instance into a Variant array of dimensions [0.._n_,0..1], where [_i_,0] holds keys and [_i_,1] holds values.

    function ToVarArray: Variant;

Clear the values of the `IJSONDocument`, but keep the list of keys.

    procedure Clear;

When processing a sequence of JSON documents with a similar set of keys (and keys of embedded documents), performance can be gained by avoiding the de- and re-allocation of memory to store the keys (and the Variant record for their values). (See also `IJSONDocArrayBuilder` below).

Retrieve a value by key. This is the default property, so you can access the keys of a `IJSONDocument` by index notation (e.g.: `d['id']`).

    property Item[const Key: WideString]: Variant; default;

## Remarks

**Attention:** by default the `IJSONDocument` implementation: `TJSONDocument` is **not** thread-safe. Please use proper locking and synchronisation methods to ensure only one thread accesses an instance at one time, or declare conditional define `JSONDOC_THREADSAFE`.

### JSONEnum

Create an `IJSONEnumerator` instance for a `IJSONDocument` reference.

    function JSONEnum(x: IJSONDocument): IJSONEnumerator; overload;
    function JSONEnum(const x: Variant): IJSONEnumerator; overload;

### IJSONEnumerator

Check wether the enumerator is past the end of the set of keys of the document.

    function EOF: boolean;

Move the iterator to the next item in the set. Moves the iterator to the first item on the first call. Returns false when moved past the end of the set.

    function Next: boolean;

Returns the key or value of the current item in the set.

    function Key: WideString;
    function Value: Variant;

Returns the key or value of the current item in the set.

### JSONDocArray

Use an `IJSONDocArrayBuilder` instance to store a set of similar JSON documents. JSON is converted to and from strings internally to save on memory usage. Use `LoadItem` with a single `IJSONDocument` instance to re-use keys and save on memory allocation. Pre-load a parent `IJSONDocument` with an `IJSONDocArrayBuilder` instance to postpone some of the parsing of the children documents.

    function JSONDocArray: IJSONDocArrayBuilder; overload;
    function JSONDocArray(const Items:array of IJSONDocument): IJSONDocArrayBuilder; overload;

### IJSONDocArrayBuilder

Append a document to the array.

    function Add(Doc: IJSONDocument): integer;
    function AddJSON(const Data: WideString): integer;

Retrieve a document using an existing `IJSONDocument` instance, possibly re-using allocated keys.

    procedure LoadItem(Index: integer; Doc: IJSONDocument);

Retrieve the number of documents in the array.

    function Count: integer; stdcall;

Convert the data in the `IJSONDocArrayBuilder` instance into a JSON string.

    function ToString: WideString; stdcall;

Retrieve a document by index, in a new `IJSONDocument` instance. This is the default property, so you can use index notation (e.g.: `a[3]`).

    property Item[Idx: integer]: IJSONDocument; default;

### IJSONArray

If you need to process documents that contain many and/or large arrays, some performance may get lost because manipulating Variant arrays performs a deep copy on assignment by default.

To prevent this, set the `JSON_UseIJSONArray` value to true to have `IJSONDocument` use `IJSONArray` instances to hold arrays, which use reference counting instead of deep copy on assignment.

A downside to this is that plain array-indexing (`a[i]`) no longer works. (The `VariantManager` which could provide support for this, is deprecated in Delphi since version 7.) Use the `ja` function to conveniently extract a `IJSONArray` reference from a variable of type Variant (`ja(a)[i]`).

repository: stijnsanders/jsonDoc

repo_name: stijnsanders/jsonDoc


text:
# Pastel Fullnode Wallet

[![CircleCI](https://circleci.com/gh/pastelnetwork/pastel-electron-wallet/tree/master.svg?style=svg)](https://circleci.com/gh/pastelnetwork/pastel-electron-wallet/tree/master)

## Description

Pastel Fullnode Wallet is a z-Addr first, Sapling compatible wallet and full node for pasteld that runs on Linux, Windows and MacOS.
This wallet runs `pasteld`, pastel gonode(`walletnode`), `rqservice` managed by [pastel-utility](https://pastel.wiki/en/Architecture/pastel-utility).

## Installation

Download the release binary for your OS from the releases page, unzip it and double click on the exectable to start.

## Build from source

PastelWallet is written in Electron/React/Typescript and you can use below steps to build it from source.

```
git clone https://github.com/pastelnetwork/pastel-electron-wallet.git
cd pastel-electron-wallet

yarn install
yarn make
```

The resulting binaries would be located at `out` folder. Please note that `yarn make` will create installers only for the OS where it's executed.

## Development

You need to have the following software installed before you can build Pastelwallet Fullnode

- Nodejs v12.16.x or higher - https://nodejs.org
- Yarn - https://yarnpkg.com

To start in the development mode, run:

```
yarn start
```

To contribute, please read [contribution guidelines for this project](docs/CONTRIBUTING.md).

## Database

App includes sqlite database, to make a change to database structure run:

```
yarn db:generate createTableName
```

This will create empty sql file prefixed with timestamp in src/features/pastelDB/migrations

Migration files are applied automatically during the app start up process

When you need to insert multiple records at once use transaction as [explained here](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#transactionfunction---function) because it's performed many times faster when using transaction


text:
---
layout: project
type: project
published: true
#image: images/htc-ccis1301.jpg
title: Jekyll Quiz Include
permalink: courses/htc-ccis1301
date: 2017
summary: A simple quiz include for a jekyll website.
labels:
  - HTML
  - CSS
  - Jekyll
---

An include to use on a jekyll based web site for a simple, embedded, self-assessment quiz question.

GitHub: [jekyll-quiz-include](https://github.com/mbMosman/jekyll-quiz-include)

repository: mbMosman/old-mbmosman-profile

repo_name: mbMosman/old-mbmosman-profile


text:
### [CVE-2020-24445](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-24445)
![](https://img.shields.io/static/v1?label=Product&message=Experience%20Manager&color=blue)
![](https://img.shields.io/static/v1?label=Version&message=n%2Fa&color=blue)
![](https://img.shields.io/static/v1?label=Vulnerability&message=Cross-site%20Scripting%20(Stored%20XSS)%20(CWE-79)&color=brighgreen)

### Description

AEM's Cloud Service offering, as well as version <IP_ADDRESS> (and below), are affected by a stored Cross-Site Scripting (XSS) vulnerability that could be abused by an attacker to inject malicious scripts into vulnerable form fields. Malicious JavaScript may be executed in a victim’s browser when they browse to the page containing the vulnerable field.

### POC

#### Reference
No PoCs from references.

#### Github
- https://github.com/ARPSyndicate/cvemon
- https://github.com/Live-Hack-CVE/CVE-2020-24445

repository: trickest/cve

gha_language: HTML

repo_name: trickest/cve


text:
# Sidecar  pattern

> How to enhance your service with 3rd party apps/services

![sidecar pattern](sidecar.png)

## Example

We have the following applications:

- One app exposing a REST endpoint to fetch `cats`:
  - It is exposed at port 3001
  - It contains 1 endpoint: http://localhost:3000/cats
- A frontal service:
  - It is exposed at port 80
  - It contains an index.html at: http://localhost/index.html
  - This service serves static file content that calls the cat app
- A Zookeeper
- A tiny process:
  - It register the cat app to the zookeeper

## Running the example

```bash
docker-compose up
# Calling this url will call the cat service
curl -L http://localhost:3000/cats

# Go to the index.html served by the Nginx with your favorite web browser
google-chrome http://localhost
firefox http://localhost
# The cat service can continue to live without the Nginx
# The Nginx is only used to facilitate the call to the cat service

# Connect to the zookeeper service
docker exec -it sidecar_zk_1 /zookeeper-3.4.11/bin/zkCli.sh -server localhost:2181
# This will display the content of the path /
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper, cat]
# This will display the info of the node /cat
[zk: localhost:2181(CONNECTED) 1] get /cat
{"zookeeperHosts":"zk","name":"cat","description":"Cat service"}
cZxid = 0x2
ctime = Fri Mar 30 07:50:59 GMT 2018
mZxid = 0x2
mtime = Fri Mar 30 07:50:59 GMT 2018
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 64
numChildren = 0
# This tiny process is used as an external process as the cat service
# in order to register the service to zookeeper for app/services that do
# not support zookeeper natively
```

In this example, we have 2 sidecars for our cat service:

- a Nginx that serves static file content to facilitate calls to our cat service
- a process that register our service to zookeeper

We can also add other types of sidecars:

- a logstash to parse the cat service logs and do things with them (like emailing when there are erros)
- a watchdog service that monitor the cat service and do things accordingly (ie, restart the service if crashed)
- ...

## Sources

- [Microsoft Azure](https://docs.microsoft.com/en-us/azure/architecture/patterns/sidecar)
- [IBM](https://developer.ibm.com/code/2017/05/22/polyglot-microservices-and-the-sidecar-pattern/)
- [Kubernetes](http://blog.kubernetes.io/2015/06/the-distributed-system-toolkit-patterns.html)

repository: RazaGR/architecture-cheat-sheet

repo_name: RazaGR/architecture-cheat-sheet


text:
# httpd-proxy
Modified httpd docker image allowing easy vhost configuration with proxypass.

## Modifications
* Loaded certain modules for proxying functionalities.
* Now listening on both port 80 and 443
* All files matching `*conf` in the directory `/var/vhosts` are loaded

## Usage
Docker image is build in the docker cloud, just use the `djesionek/httpd-proxy` image.

repository: djesionek/httpd-proxy

repo_name: djesionek/httpd-proxy


text:
---
layout: sw-tool
title: Select standard reference geometry (e.g. Front plane or origin) by type using SOLIDWORKS API
caption: Select Standard Plane Or Origin By Type
description: Example demonstrates how to select standard plane (Top, Front or Right) and origin by specifying its type
image: plane.svg
labels: [selection, plane, origin]
group: Model
redirect-from:
  - /solidworks-api/document/selection/select-standard-plane/
---
![Right plane selected in the graphics view](selected-right-plane.png){ width=400 }

This example demonstrates how to select standard plane (Top, Front or Right) or origin using SOLIDWORKS API by specifying its type so the selection will be consistent regardless of the plane name as it is not recommended to select the standard planes by their names as names are not consistent and may be changed in the template (e.g. different localization or standard).

This macro selects the primary planes or origin of root document. To select primary planes or origin of the specific component in the assembly, hover the mouse over any component's entity (you do not need to select it) and run the macro.

This macro works based on the fact that the default SOLIDWORKS planes are always ordered the same way, i.e. Front, Top and Right planes are the first planes in the model, positioned before the origin feature and cannot be reordered or removed.

{% youtube id: zUqHCUNxJoA %}

## Configuration

### Target plane or origin

To configure the macro set the type of the plane to select in the **REF_GEOM** variable. Supported values: **Right**, **Top**, **Front**, **Origin**

~~~ vb
Dim REF_GEOM As swRefGeom_e
~~~

~~~ vb jagged
#Else
    REF_GEOM = swRefGeom_e.Right
#End If
~~~

### Scrolling to selection

This macro allows to specify if the plane should be scrolled into view by setting **SCROLL** constant

~~~ vb
Const SCROLL As Boolean = False' scroll plane into view
~~~

> Note, this macro will ignore the **Feature Manager -> Scroll selected item into view** option and scroll based on the option above preserving the setting in SOLIDWORKS.

### Appending selection

Macro will append the selection if **ctrl** button is pressed unless the **APPEND_SEL** constant is set to true. In this case selection will alway be appended. This is useful when shortcut are used for the macro buttons as **ctrl** will conflict with shortcut.

~~~ vb
Const APPEND_SEL As Boolean = True
~~~

## CAD+

This macro is compatible with [Toolbar+](https://cadplus.xarial.com/toolbar/) and [Batch+](https://cadplus.xarial.com/batch/) tools so the buttons can be added to toolbar and assigned with shortcut for easier access or run in the batch mode.

![Buttons in toolbar](toolbar.png)

In order to enable [macro arguments](https://cadplus.xarial.com/toolbar/configuration/arguments/) set the **ARGS** constant to true

~~~ vb
#Const ARGS = True
~~~

In this case it is not required to make copies of the macro to set individual [target plane or origin](#target-plane-or-origin). Instead use the **FRONT**, **TOP**, **RIGHT**, **ORIGIN** arguments for the corresponding target entity.

You can download the icons for each button: [front plane](front.svg), [top plane](top.svg), [right plane](right.svg), [origin](origin.svg) or use your own icons.

{% code-snippet { file-name: Macro.vba } %}

repository: tpharber/codestack

repo_name: tpharber/codestack


text:
# Object: ARRAY
**NOTE:** This documentation was auto-generated from the FabricationDefinition.ts file and any errors within this text needs to be resolved within that source file
## Constructor
Constructs an Array Object.
Constructs an Array object with the number of inital elements as specified. Each element's
value will be NULL/False.
If optional NumberOfItems is not specifcied, a default value of 0 (zero) is used.
#### Signature
New ARRAY([NumberOfItems: NUMBER])
#### Arguments
- **NumberOfItems** as Optional: NUMBER
  - Remarks: Optional Number of items to initialize the Array Object to hold.
## Properties
The following items are accessed from the base object by a dot notation
### Property: Count
Get/Set the Number of elements in the array of the ARRAY Object.

If changed, new elements are set to NULL/False.
##### Returns
NUMBER
## Methods
The following items are invoked from the base object by a dot notation
### Function: Add
Adds/appends the specified data items to an array.

No additional remarks available
##### Signature
Add(ArrayData: ANY[])
##### Arguments
- **ArrayData** as: ANY[]
##### Returns
NUMBER
### Function: Delete
Removes the specified item from an array.

Index is a '1-based' meaning the first item in the Array is index # 1.
Default when ArrayIndex is missing is the last item in the Array.
Array is dynamically resized, removing an item from the beginning or middle of the array
results in the array being smaller and the other elements moving up in position.
##### Signature
Delete([ArrayIndex: NUMBER])
##### Arguments
- **ArrayIndex** as Optional: NUMBER
  - Remarks: Optional Number specifying the index number of the element to remove from the array.
##### Returns
BOOLEAN
### Function: Insert
Inserts a piece of data into an Array at the specified index.

When inserting data into an Array at a sepecific index, the previous data and all other
downstream data are shifed down in the index chain.
Default when ArrayIndex is missing is to insert at the end of the array.
##### Signature
Insert(ArrayData: ANY, [ArrayIndex: NUMBER])
##### Arguments
- **ArrayData** as: ANY
  - Remarks: Any type of data to insert into an array.
- **ArrayIndex** as Optional: NUMBER
  - Remarks: Optional Index position to insert data into.
##### Returns
BOOLEAN

repository: DyoungMCWI/FabCOD

repo_name: DyoungMCWI/FabCOD


text:
#Petulant Bear

This project a try out at building a scalable web application:

* updates all AssemblyInfo files
* compiles the application and runs all test projects
* generates [SourceLinks](https://github.com/ctaggart/SourceLink)
* generates API docs based on XML document tags
* generates [documentation based on Markdown files](http://fsprojects.github.io/ProjectScaffold/writing-docs.html)
* generates [NuGet](http://www.nuget.org) packages
* and allows a simple [one step release process](http://fsprojects.github.io/ProjectScaffold/release-process.html).

## Fresh Install
In order to do a fresh install of the petulant , you need to have fsharp installed with the latest .net framework installed

### fetching files

#### source code
open github shell and move to petulant bear folder

    git pull
    git branch v<IP_ADDRESS>

#### packages and external files
open windows explorer and under petulant bear root folder execute

    executeinstallPakage.cmd

### Building the soft

    $ build.cmd // on windows
    $ build.sh  // on mono

### running

#### development
once built, everything will be located under the bin folder, ready to be deployed for prod.

#### batch

There are 3 cmd that allows ou to start the bundle according to what you need to do (no need to configure anything):

    $ startPetulant.bat // start the full bin version of petulant (used from bin folder : web server, wwwroot, db)
    $ startPetulantFordevRoot.bat // start the bin version of petulant for accessing devroot folder of github repo (used from bin folder : web server,  db)
    $ startPetulantForWwRoot.bat // start the bin version of petulant for accessing wwwroot folder of github repo (used from bin folder : web server,  db)

when closing the petulant, beware of closing also the getEventStore...

#### app.config

You have to adjust a few things in the PetulantBear.exe.config to make it work for your environment.

    <add name="bear2bearDB" connectionString="Data Source={YOUR_LOCAL_PATH}\db\Bear2Bear.db;Version=3"/>
    <add key="rootPath" value="{YOUR_LOCAL_PATH}\wwwroot\"/>
    <add key="IPAddress" value="{YOUR_LOCAL_IP}"/>
    <add key="Port" value="{YOUR_LOCAL_PORT}"/>
    <add key="urlSite" value="{YOUR_LOCAL_URL}"/>
    <add key="eventStoreConnectionString" value="tcp://{EVENTSTORE_IP}:{EVENTSTORE_PORT}" />
    <add key="eventStoreClientIp" value="{EVENTSTORE_IP}" />
    <add key="eventStoreClientPort" value="{EVENTSTORE_PORT}" />

usually in dev these stand for :

    {YOUR_LOCAL_PATH} -> bin url of the github repo on your pc
    {YOUR_LOCAL_IP} -> <IP_ADDRESS>
    {YOUR_LOCAL_PORT} -> 8084
    {YOUR_LOCAL_URL} -> http://localhost:8084
    {EVENTSTORE_IP} -> <IP_ADDRESS>
    {EVENTSTORE_PORT} -> 1113

#### command line argument
you can also start the petulant and add command line arguments, these will be overload any definition made in the app.config

    --dbConnection (string)-> to fill out the connection string to the bear2bear sqlite db
    --rootPath (string)-> to fill out the root path to the bear2bear static files of the wwwroot
    --ipAddress (string)-> the ip address used internally to start the web server
    --port (int)-> the port used internally to start the web server
    --urlSite (string)-> the url used by facebook to enable callback from author
    --eventStoreConnectionString (string)-> the connection string of the eventstore
    --eventStoreClientIp (string)-> the ip the eventstore client should connect to
    --eventStoreClientPort (int)-> the port the eventstore client should connect to
    --elmah (string)-> the key to configure elmah logging

### database

Building the soft will build the database according to the existing one under \src\db\db. It will apply every script in order to try to ugrade it to the latest dev.

#### Building the db from production

download database prod from petulant ftp, copy it to %YourPath%\petulant-bear\src\db\db
rename the prod bear2bear.db in Bear2BearProd.db, it will be used later to apply latest script to prod database

    bear2bear.db -> Bear2BearProd.db

execute at the root of your github repo the following command :

      buildDB.bat

it will copy the previous prod version of the database and try to  apply latest sql scripts. If you want to use it with the batches previously detailled, you will have to run build.cmd once again, so that your changes are deployed to the bin folder.

#### databases

in order to reset all data, you 'll need to:

    $ delete data folder under the root folder of your github repo
    $ delete src/db/db folder
    $ execute anew build.cmd to recreate a fresh db

## Maintainer(s)

- [@arthis](https://github.com/arthis)
- [@Julienfouquet](https://github.com/Julienfouquet)

special thx for the work of the fsharp community that helped so much...

license: MIT,Unlicense

repository: cannelle-plus/petulant-bear

detected_licenses: MIT Unlicense

gha_language: F#

repo_name: cannelle-plus/petulant-bear