text:
# HolisticWare.Xamarin.Tools.Bindings.XamarinAndroid.Decompilers

One of the key factors whether technology will be successful and accepted by users/consumers
is certainly - ecosystem - 3rd part libraries, SDKs and tools.

Xamarin's ecosystem and ability to enhance, extend that ecosystem is one of the biggest advantages
when compared to other cross platform development technologies. Enhancing ecosystem id mostly
done through bindings. Though Xamarin tooling for binding have huge advantage compared to other
techmologies, tools itself are not always ideal and perfect.

This set of nuget packages is an attempt to improve developers experience and productivity through
improving the build system, IDE experience for Xamarin.Android bindings like:

*   code intellisene (autocompletion) for Managed Callable Wrappers MCW

*   Decompiler dumps (java code dumps) for the cases when Xamarin tools cannot surface
    some classes

This repository is personal side project to add code completion (intellisense) to MCWs and it
consists of custom MSBuild task that hooks in the Xamarin.Android bindings build task (process),
intercepts it and adds generated code tot the IDE enabling code completion and navigation through
the code.

NOTE: this is personal attempt to learn MSBuild via solving some problems and code is not ideal,
so any kind of suggestions, ideas, constructive criticism is accepted.

## Decompilers support

## Usage

1.  install nuget package

    `HolisticWare.Xamarin.Tools.Bindings.XamarinAndroid.Decompilers`

    via:

    `Install-Package HolisticWare.Xamarin.Tools.Bindings.XamarinAndroid.Decompilers`

    `dotnet add package HolisticWare.Xamarin.Tools.Bindings.XamarinAndroid.Decompilers`

    `paket add HolisticWare.Xamarin.Tools.Bindings.XamarinAndroid.Decompilers`

    https://www.nuget.org/packages?q=HolisticWare.Xamarin.Tools.Bindings.XamarinAndroid.Decompilers

2.  configure decompilers used in project file `*.csproj`

    ```xml
    <PropertyGroup>
        <!--
            Customizations default values:

            *   CLI - commandline CLI calls from EXEC

                due to stdout and stderr redirection and piping some calls implemented only with API (javap)

            *   API - custom tasks in C# code
        -->
        <RunCLIJavaDecompilerProcyon>true</RunCLIJavaDecompilerProcyon>
        <RunCLIJavaDecompilerCFR>true</RunCLIJavaDecompilerCFR>
        <RunCLIJavaDecompilerBytecodeViewerProcyon>true</RunCLIJavaDecompilerBytecodeViewerProcyon>
        <RunCLIJavaDecompilerBytecodeViewerCFR>true</RunCLIJavaDecompilerBytecodeViewerCFR>
        <!--
            Bytecode Viewer support for Krakatau - needs Python/PyPy support
        -->
        <RunCLIJavaDecompilerBytecodeViewerKrakatau>false</RunCLIJavaDecompilerBytecodeViewerKrakatau>
        <RunCLIJavaDecompilerBytecodeViewerKrakatauBytecode>false</RunCLIJavaDecompilerBytecodeViewerKrakatauBytecode>
        <!--
            Bytecode Viewer support for JD GUI - comming soon
        -->
        <RunCLIJavaDecompilerBytecodeViewerJDGUI>true</RunCLIJavaDecompilerBytecodeViewerJDGUI>
        <!--
            Bytecode Viewer support for Smali - comming soon
        -->
        <RunCLIJavaDecompilerBytecodeViewerSmali>true</RunCLIJavaDecompilerBytecodeViewerSmali>
    </PropertyGroup>
    ```

2.  do the bindings and decompiled code will be in `./holisticware-generated/decompilers`

3.  uninstall nuget package after bindings are done

NOTE: support for SDK style project is ongoing work due to lack of knowledge about file inclusion
mechanisms (Default).

## Motivation

This repository consists of the source for the build task in the `./source` folder and 2 bindings
projects in `./samples` folder. Though folder is named `./samples` those are not true Android
apps, but bindings projects for testing MSBuild tasks that are supposed to fix this issue.

There are 2 bindings projects in `./samples` folder - one classic Xamarin.Android bindings
project and other with new "SDK style project" flavour.

In some cases Xamarin.Android bindings tools (`jar2xml` and `class-parse`) cannot "surface"
certain java API for various reasons (generics, obuscation, even bugs...).

In this case it is possible to inspect `*.jar` files (and `*.aar` of course) with various
decompilers for java binaries and to analyse the reasons why classes were not "surfaced" to
C# API (MCWs).

There are several decompilers with UI options:

1.	Luyten

2.	JD-GUI

3.	...

and of course several commandline options:

1.	`javap`

2.	procyon decompiler used by Luyten

3.	CFR decompiler

4. `smali` and `baksmali`

5.  ...

This nuget package adds automatic decompiler dumps to Build target of the Xamarin.Android bindings
projects.

Dumps can be found in `./holisticware-generated/decompilers/*.class`

## TODOs

1.	MSBuild SDK style project support

2. windows platform support

3.	more parameters for customization (output folders, ...)

4. 	other Android artifacts support (`*.aar`, ...)


text:
---
layout: blogpost.njk
tags: post
title: So I've decided to make a blog
image: /img/post/test.png
date: Created
permalink: "/blog/posts/{{ title | slug }}/index.html"
---

## Why?

... Why not?

Seems like everyone has a blog these days, and it would be a nice place to put down my thoughts.
This week is the week of the 2020 US Presidential Election; it's definitely a turbulent time and there's tension in the air. This seems like a pretty good way to relax.

This blog itself is made with a static site generator (11ty), and hopefully loaded pretty quickly for you.
The nice thing is that I can theoretically write my blog anywhere and immediately update it just by pushing a markdown file to GitHub. Neato.

## How?

The blog uses a few things:
+ [11ty static site generator](11ty.dev)
+ [TailwindCSS for minimal styling](tailwindcss.com)
+ [Alpine.js for lightweight responsive UI](https://github.com/alpinejs/alpine)

Setting it up is pretty simple. I plan to make a full tutorial series for setting up the blog alongside a personal portfolio of sorts.
Hopefully it will be easy to follow without glaring flaws. I mostly found what I was looking for online, but I will admit that the documentation and terminology surrounding 11ty was slightly confusing, so maybe I'll be able to clear a few things up.

license: MIT

branch_name: refs/heads/master

extension: md

license_type: permissive


text:
# SonicAsteroids sound engine

A sound engine for macOS, written in Swift 4.2, for the [Elixoids v3 game engine](https://github.com/devstopfix/elixoids). Listen to the [cacophony with headphones](https://vimeo.com/332919838).

## Getting started
To install dependencies you will need XCode and [Carthage](https://github.com/Carthage/Carthage) (this can be installed using homebrew.)

SonicAsteroids has been tested on:
* Xcode 11.5 on 10.15.5 (Catalina)
* Xcode 10.1 on 10.13.6 (High Sierra)
* Xcode 7.3.1 on OS X 10.11 (El Capitan)

## Build

    brew install carthage

    carthage update

### Scripting

When starting the application from the command line, the first argument can be used to pass the URL of the game:

    ~/Applications/SonicAsteroids.app/Contents/MacOS/SonicAsteroids ws://game.example.com/0/sound

## Sound Client Protocol

Sound events can be received at `ws://example.com/0/sound` as described in the [sound protocol document](https://github.com/devstopfix/elixoids/blob/master/docs/sound_protocol.md). For maximum network efficiency we recommend sending an `Accept: application/octet-stream` header and consuming [protobufs](https://github.com/devstopfix/elixoids/blob/master/priv/proto/sound.proto).

The pan is a float from -1 to +1 where -1 is hard left and zero is center. See the [pan property](https://developer.apple.com/documentation/avfoundation/avaudioplayer/1390884-pan).  We apply a function `y=x³` to the linear pan sent by the game to keep most sounds centered but push out sounds at the very edge of the screen.

repository: jrothwell/sonic-asteroids

gha_language: Swift

gha_license_id: MIT

repo_name: jrothwell/sonic-asteroids


text:
# Purioxylon B.D. Sharma, 1972 GENUS

#### Status
ACCEPTED

#### According to
Interim Register of Marine and Nonmarine Genera

#### Published in
Advances in Plant Morphology 1972: -. [233-242]

#### Original name
null

### Remarks
null

repository: mdoering/backbone

repo_name: mdoering/backbone


text:
# modify-element

![prettier](https://img.shields.io/badge/format-prettier-blueviolet.svg)
![version](https://img.shields.io/github/package-json/v/martindzejky/modify-element.svg)

Allows you to easily modify HTML elements on websites.
A small utility library to simplify working with the `MutationObserver` browser API.

## Usage

You register a CSS selector and a callback function. When started, the callback function
will be called when any element matching the selector appears in the DOM. Suitable for
static websites as well as dynamic web apps.

1. Import or copy-paste the script to your code
1. Register your selector and callback using `ModifyElement.registerSelector`
1. Start the observer using `ModifyElement.start`

## API

The library exports a single global variable called `ModifyElement` which provides the public API.

### `ModifyElement.registerSelector`

Register a new selector and a callback function. The callback will
be called whenever a new element matching the selector appears in the DOM.

- `selector` Selector matching the target element
- `callback` Callback function to call with the element

### `ModifyElement.unregisterSelector`

Remove the registered callback.

- `selector` Selector assigned with the callback
- `callback` Callback function to remove

### `ModifyElement.start`

Start observing the root element. This applies all registered
selectors and starts the MutationObserver.

- `rootElement` Root element to observe, usually this can be `document.documentElement`

### `ModifyElement.stop`

Stop observing the root element.

## Development

Clone the repository locally first. This project uses `npm` so call `npm install` to install
the dependencies. Then there are these important scripts:

- `npm build` - Build a development version
- `npm build:min` - Build a production version (minified)
- `npm build:watch` - Watch source files and rebuild

## Tests

See [#1](https://github.com/martindzejky/modify-element/issues/1).

repository: martindzejky/modify-element

gha_language: TypeScript

gha_license_id: NOASSERTION

repo_name: martindzejky/modify-element


text:
# Relax
RESTful API endpoint manager

## Needs

> This library will need a lot of management to keep APIs updated. My plan is to start laying them out and try to find others who use specific APIs and have them keep those up to date.

## Roadmap

#### APIs

- [x] ~~Done~~ : [Docs]() *documentation link* : [File]() *source file*
- [ ] ***Started*** : [Docs]() *documentation link* : [File]() *source file*
- [ ] Future : [Docs]() *documentation link*

**Please submit an issue if you would like a lead position for any (listed/unlisted) API**

--

- [x] ~~Foursquare~~ : [Docs](https://developer.foursquare.com) : [File](APIs/FoursquareAPI.swift)
- [x] ~~Instagram~~ : [Docs](https://www.instagram.com/developer/) : [File](APIs/InstagramAPI.swift)
- [x] ~~iTunes~~ : [Docs](https://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html) : [File](APIs/ItunesAPI.swift)
- [x] ~~Marvel~~ : [Docs](http://developer.marvel.com) : [File](APIs/MarvelAPI.swift)
- [x] ~~Uber~~ : [Docs](https://developer.uber.com) : [File](APIs/UberAPI.swift)
- [ ] ***Github*** : [Docs](https://developer.github.com/v3/) : [File](APIs/GitHubAPI.swift)
- [ ] ***Marta*** : [Docs](http://www.itsmarta.com/app-developer-resources.aspx) : [File](APIs/MartaAPI.swift)

--

- [ ] Flickr : [Docs](https://www.flickr.com/services/api/)
- [ ] LinkedIn : [Docs](https://developer.linkedin.com/docs)
- [ ] Meetup : [Docs](http://www.meetup.com/meetup_api/)
- [ ] Pinterest : [Docs](https://developers.pinterest.com)
- [ ] Slack : [Docs](https://api.slack.com)
- [ ] Twitter : [Docs](https://dev.twitter.com/overview/documentation)
- [ ] Youtube : [Docs](https://developers.google.com/youtube/)
- [ ] Netflix : [Docs](http://developer.netflix.com)
- [ ] GuideBox : [Docs](https://api.guidebox.com/docs)
	- [ ] Hulu
	- [ ] Amazon

--

**API Groups**

- [Google Products](https://developers.google.com/products/)
	- [ ] Analytics : [Docs](https://developers.google.com/analytics/)
	- [ ] Maps : [Docs](https://developers.google.com/maps/)
- [Facebook Products](https://developers.facebook.com/docs/)
	- [ ] Graph API : [Docs](https://developers.facebook.com/docs/graph-api)

**Please submit an issue for any APIs you would like to see added.**

---

#### Features

- [x] ~~Response Object Structure~~ *docs coming soon*
- [x] ~~Authentication Structure~~ *docs coming soon*

## Usage

To run the example project, clone the repo, and run `pod install` from the Example directory first.

Example project screens.

![APIs](./Images/APIs.png)
![Marvel](./Images/Marvel.png)
![Foursquare](./Images/Foursquare.png)
![iTunes](./Images/iTunes.png)

### Choose or Create API

Go [here](APIs) to choose a prebuilt API or create your own. The example below uses the prebuilt [GitHubAPI](APIs/GitHubAPI.swift).

### Use API

> You will need to [register an application](https://github.com/settings/applications/new). Then create a Keys.swift file (make sure to ignore the file if your repo is public).

**run a request**

```swift
let githubAPI = GithubAPI.session

// setup endpoint

var profile = GithubAPI.Endpoints.UsersNamed.endpoint

profile.pathpieces = ["username" : "joalbright"]

// run request

githubAPI.request(profile) {

   // object returned = $0.info
   // error returned = $0.error

}

```

## Requirements

This uses [Parsable](https://github.com/joalbright/Parsable).

## Author

[Jo Albright](https://github.com/joalbright)

## License

Relax is available under the MIT license. See the LICENSE file for more info.

repository: joalbright/Relax

repo_name: joalbright/Relax


text:
---
description: Depending on which version of Umbraco CMS you are using, we distinguish between two package types, NuGet packages, and Package ZIP files.
---

# Package Types

There are two main ways to install packages in Umbraco CMS: Package zip files and NuGet packages.

{% hint style="warning" %}
The zip file package type is only available for Umbraco version 8 and earlier versions. Learn more about it in the [Package zip Files](#package-zip-files) section of this article.
{% endhint %}

When developing a package you need to consider the Umbraco CMS version you're using before determining the package type.

* Modern Umbraco (Umbraco 10+): Providing a NuGet package is the only option.
* Legacy Umbraco (Umbraco 8 and earlier versions): It is recommended to provide both a zip file and a NuGet package.

## NuGet Packages

A NuGet package is a standard way of delivering compiled code and configuration to a .NET project. NuGet packages contain dll-files and other files required for the solution. For more information on NuGet packages see Microsoft's [An introduction to NuGet](https://docs.microsoft.com/en-us/nuget/what-is-nuget) documentation.

NuGet packages can be installed using via the command line or through Visual Studio using either the [Package Manager Console](https://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-powershell) or the [NuGet Package Manager](https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio).

See below, for an example of installing a package using the Package Manager Console in Visual Studio:

```powershell
PM> Install-Package MyPackage -version 1.2
```

NuGet packages can include any solution files and can be configured to run PowerShell scripts after installation.

As NuGet packages are installed outside of the Umbraco website they cannot directly manipulate any of the Umbraco settings or content during their installation.

When adding or changing configuration of Umbraco as part of a NuGet package you need to develop code to run as part of a [Migration](../database.md). The Migration will run the first time the Umbraco site starts after the package is installed, applying the correct configuration.

## Package zip files

{% hint style="warning" %}
Zip file packages are only available for Umbraco CMS 8 and earlier versions.

Refer to the [NuGet Packages](#nuget-packages) section above, if your website is using Umbraco 10 or a later version.
{% endhint %}

A package zip file can be installed directly through the Umbraco backoffice.

![Zip packages can be installed via the Umbraco backoffice package section](images/backoffice-package-section.png)

Packages zip files can contain:

* Content
* Solutions files (`dll`s, `App_Plugins` files, etc)
* Document Types
* Templates
* Stylesheets
* Macros
* Languages
* Dictionary Items
* Data Types
* Media

{% hint style="info" %}
If you want to include media in your package, you must select it in both the "Media" section and the "Package Files" section under "Path to file"
{% endhint %}

repository: umbraco/UmbracoDocs

branch_name: refs/heads/main

repo_name: umbraco/UmbracoDocs


text:
## Connect to the HPE Cray EX Environment

The HPE Cray EX Management Network \(SMNet\) has multiple separate physical and logical links that are used to segregate traffic.

The diagram below shows the available connections from within the SMNet, as well as the connections to the customer network:

![Management NCN Interfaces and VLANs](../../img/operations/Management_NCN_Interfaces_and_VLANs.PNG "Management NCN Interfaces and VLANs")

There are multiple ways to connect to the HPE Cray EX environment. The various methods are described in the following table:

|Role|Description|
|----|-----------|
|Administrative|External customer network connection to the worker node's hardware management and administrative port|
|Application node access|External customer network connection to an Application Node|
|Customer Access Network \(CAN\)|Customer connection to the CAN gateway to access the HPE Cray EX CAN|

There are also several ways to physically connect to the nodes on the system. The following table describes the physical connections to the administrative and application nodes:

|Role|Description|
|----|-----------|
|Administrative node|1GB copper connection made from the customer network that provides administrative access and hardware management|
|Application node|Different interconnect types are available from the customer network based on customer requirements|

For more information on connecting to the CAN, see [Connect to the CAN](customer_access_network/Connect_to_the_CAN.md).


text:
---
name: "⛔ Question"
about: Please go to https://gitter.im/eslint/eslint
title: ''
labels: ''
assignees: ''

---

<!--
    ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).

    Please do not use GitHub for asking questions. Instead,
    please visit our chatroom:

        https://gitter.im/eslint/eslint

    Or our mailing list:

        https://groups.google.com/group/eslint

    Thanks in advance for helping us keep the issue tracker
    clean!
-->


text:
---
layout: work
type: work
published: true
image: images/work/uhcc.jpg
title: University of Hawaii Cancer Center
permalink: work/uhcc
date: 2019
labels:
  - Software Engineering
  - Data Science
  - PhD
  - Machine Learning
  - Cancer Research
  - Breast Cancer
  - Deep Learning
  - Neural Networks

summary: From Nov 2018 to present, I worked at the University of Hawaii Cancer Center in the Shepherd Research Lab (SRL) as a PhD graduate research assistant.
---

__Responsibilities__

As a PhD Graduate Research Assistant under [John
Shepherd](https://shepherdresearchlab.org/about/our-team/) PhD, I
conduct imaging research which is primarily focused on breast cancer. Our
research group seeks to discover novel imaging bio-markers to detect cancer and
asses risk.  Machine and deep learning are big components of my research as it
is a powerful tool for analyzing high dimensionality data that is images.  My
background in high performance computing and software engineering allows me to
fully leverage our GPU clusters to rapidly build and train machine learning
models.

**Projects**

{{ include.page.summary }}

- [Breast Thickness Tomosynthesis](../work_extra/uhcc-ge_tomo) - Breast density
  is a biomarker that is associated with cancer risk.  Accurate point thickness
measurements of the breast are necessary for calculating density.  We use nine
views from a sinogram to solve and inverse problem and derive point thickness
measurements.

    - I developed an unsupervised machine learning model using PCA to
      characterize sinograms resulting from breast of different thickness, widths, and densities.
	- [Work was presented in an abstract detailed
	  __HERE__](../essays/rsna_2019)
- _[3CB](https://shepherdresearchlab.org/research/3cb/)_ - 3 Compartment Breast
  of 3CB is a project that can render breast lesions specific to the three major
components that make  up breast tissue.  These components include water, lipid,
and protein and quantifying the amount of each component helps to assess cancer
risk and need for biopsies.
    - For this project I refactored the existing 3D rendering code and plan to
      incorporate the breast thickness tomosynthesis algorithm to get accurate
thicknesses and make up of breast lesions.
- _Interval vs Screening Cancer Detection_ - Screening cancers are cancers
  detected from a screening mammogram.  Interval cancers are a case of breast
cancers that found after a previous screening mammogram reported a negative
finding.  We use deep learning and neural networks to search for signals in
interval cancer cases to try and catch the cancers early and at the time of
screening.
    - Our group is fortunate enough to work with the largest data set of it's
      kind for this project.  I helped with high throughput preprocessing and
cleaning of our large image dataset .  I also research and explore of different
deep learning techniques and models to achieve high sensitivity and specificity
for interval cancer cases.


text:
---
layout: default
---

# 1998-12-16 - Re: CRYPTO-GRAM, December 15, 1998

## Header Data

From: Anonymous<EMAIL_ADDRESS>To<EMAIL_ADDRESS>Message Hash: eebff56166319b91485b3417e5999c0928283a661c9f73c428bcfcdde0caf029

Message ID<EMAIL_ADDRESS>Reply To: _N/A_

UTC Datetime: 1998-12-16 18:16:42 UTC

Raw Date: Thu, 17 Dec 1998 02:16:42 +0800

## Raw message

```
{% raw  %}From: Anonymous<EMAIL_ADDRESS>Date: Thu, 17 Dec 1998 02:16:42 +0800
To<EMAIL_ADDRESS>Subject: Re: CRYPTO-GRAM, December 15, 1998
Message-ID<EMAIL_ADDRESS>MIME-Version: 1.0
Content-Type: text/plain

> Okay, I finally got the story right about Network Associates Inc. and the
> Key Recovery Alliance.  (Last month I pointed to a Wired News story that
> they quietly rejoined.)  The story is wrong.  They never left the KRA.
> Since its inception, Trusted Information Systems was a big mover and shaker
> in the KRA.  When NAI bought TIS in May 1998, TIS's membership transferred
> to NAI.  NAI resigned the leadership posts that TIS had held in the
> Alliance and stopped attending its meetings, but never left the KRA.  So,
> NAI is a member of the KRA, and has been since it bought TIS.
> http://www.wired.com/news/print_version/technology/story/16219.html

As a further clarification, it is incorrect to say that NAI "never left
the KRA."

Network Associates Inc. (NAI) was formed out of McAfee and Network
General.  McAfee was a member of the KRA, so at the time NAI was formed,
it was a member of the KRA.

When NAI bought PGP, in late 1997, Phil Zimmermann found out about NAI's
membership, and he was able to persuade management to withdraw from
the KRA.  This is why it is wrong to say that NAI never left the KRA.
See http://www.news.com/News/Item/0,4,17112,00.html.

NAI bought TIS a few months later.  TIS was a member and in fact a leading
member of the KRA.  By purchasing TIS, NAI inherited its membership in
the KRA, and so NAI was once again a member.

It's not clear whether Phil Zimmermann or anyone else tried to get NAI to
again withdraw from the KRA, but if they did, they were not successful.
NAI renewed its membership later in 1998 and is still a member of the KRA,
although it has reduced its level of participation.

{% endraw %}
```

## Thread

+ Return to [December 1998](/archive/1998/12)

+ Return to "[Anonymous <nobody@replay.com>](/authors/anonymous_nobody_at_replay_com_)"

+ 1998-12-16 (Thu, 17 Dec 1998 02:16:42 +0800) - Re: CRYPTO-GRAM, December 15, 1998 - _Anonymous<EMAIL_ADDRESS>


text:
# Dymo USB Scale

This is a webapp for interfacing with the
Dymo USB scale using a Raspberry Pi.

You can run this module from anywhere,
all you need is to install Flask.
Then you can drop the following into
a script:

```
from dymousbscale import *

# run debug
app.run(debug=True)

# run on port XYZ
app.run(port="8000")

# run visible to outside world
app.run(host="<IP_ADDRESS>")
```

Now you can visit the app at (if you run
with no arguments):

```
localhost:5000/scale
```

## api scale

Defines a REST API for the scale, by defining Flask routes.

## pages scale

Defines Flask routes leading to pages.

## blueprint scale

Defines a Flask blueprint for creating a URL prefix for
the REST API.


text:
## hello next.js

Collection of getting started with next.js apps<br>
Each branch points to a different app

### branches:

- sharedComponents - using shared components in the app
- dynamicRouting - handling dynamic routes for dynamic pages
- fetchingData - fetching data from remote server and displaying them in the app

### Running the app

- git clone the repository
- run `yarn` command in root folder to install dependencies
- run `yarn dev` to start the dev server
- browse the app on `localhost:3000`

repository: himankpathak/hello-next

repo_name: himankpathak/hello-next


text:
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

---
title: Customizing Serving Component (Recommendation)
---

Serving component is where post-processing occurs. For example, if you are
recommending items to users, you may want to remove items that are not
currently in stock from the list of recommendation.

This section is based on the [Recommendation Engine Template](/templates/recommendation/quickstart/).

A full end-to-end example can be found on
[GitHub](https://github.com/apache/incubator-predictionio/tree/develop/examples/scala-parallel-recommendation/custom-serving).

<!--
This section demonstrates how to add a custom filtering logic to exclude a list
of blacklisted movies from the [Movie Recommendation Engine](/quickstart.html)
based on the Recommendation Engine Template. It is highly recommended to go
through the Quckstart guide first.

Complete code example can be found in
`examples/scala-parallel-recommendation-howto`.

If you simply want to use this customized code, you can skip to the last section.
-->

## The Serving Component

Recall [the DASE Architecture](/start/engines/), a PredictionIO engine has
4 main components: Data Source, Data Preparator, Algorithm, and Serving
components. When a Query comes in, it is passed to the Algorithm component for
making Predictions.

The Engine's serving component can be found in `src/main/scala/Serving.scala` in
the *MyRecommendation* directory. By default, it looks like the following:

```scala
class Serving extends LServing[Query, PredictedResult] {

  override
  def serve(query: Query,
    predictedResults: Seq[PredictedResult]): PredictedResult = {
    predictedResults.head
  }
}
```

We will customize the Serving component to remove temporarily disabled items
from the Prediction made by Algorithms.

## Modify the Serving Interface

We will use a file to specify a list of disabled items. When the `serve` method
is called, it loads the file and removes items in the disabled list from
`PredictedResult`. The following code snippet illustrates the logic:

```scala
import scala.io.Source  // ADDED

class Serving extends LServing[Query, PredictedResult] {

  override def serve(query: Query, predictedResults: Seq[PredictedResult])
  : PredictedResult = {
    // Read the disabled item from file.
    val disabledProducts: Set[String] = Source
      .fromFile("./data/sample_disabled_items.txt")
      .getLines
      .toSet

    val itemScores = predictedResults.head.itemScores
    // Remove items from the original predictedResult
    PredictedResult(itemScores.filter(ps => !disabledProducts(ps.item)))
  }
}
```
INFO:We will show you how not to hardcode the path
`./data/sample_disabled_items.txt` soon.

WARNING: This example code uses a local relative path. For remote deployment, it is
recommended to use a globally accessible absolute path.

DANGER: This example is only for demonstration purpose. Reading from disk for every
query leads to terrible system performance. Use a more efficient
implementation for production deployment.

## Deploy the Modified Engine

Now you can deploy the modified engine as described in the [Quick
Start](/templates/recommendation/quickstart/) guide.

Make sure the `appId` defined in the file `engine.json` match your *App ID*:

```
...
"datasource": {
  "params": {
    "appId": 1
  }
},
...
```

To build *MyRecommendation* and deploy it as a service:

```
$ pio build
$ pio train
$ pio deploy
```

This will deploy an engine that binds to http://localhost:8000. You can visit
that page in your web browser to check its status.

Now, you can try to retrieve predicted results. To recommend 4 movies to user
whose ID is 1, send this JSON `{ "user": "1", "num": 4 }` to the deployed
engine

```
$ curl -H "Content-Type: application/json" -d '{ "user": "1", "num": 4 }' \
  http://localhost:8000/queries.json
```

and it will return a JSON of recommended movies.

```json
{
  "itemScores": [
    {"item": "65", "score": 6.537168137254073},
    {"item": "69", "score": 6.391430405762495},
    {"item": "38", "score": 5.829957095096519},
    {"item": "11", "score": 5.5991291456974}
  ]
}
```

Now, to verify the blacklisting logic, we add the item 69 (the second item)
to the blacklisting file `data/sample_disabled_items.txt`. Rerun the `curl`
query, and the change should take effect immediately as the disabled item
list is reloaded every time the `serve` method is called.

```
$ echo "69" >> ./data/sample_disabled_items.txt
$ curl -H "Content-Type: application/json" -d '{ "user": "1", "num": 4 }' \
  http://localhost:8000/queries.json
```

```json
{
  "itemScores": [
    {"item": "65", "score": 6.537168137254073},
    {"item": "38", "score": 5.829957095096519},
    {"item": "11", "score": 5.5991291456974}
  ]
}
```

Congratulations! You have learned how to add customized realtime blacklisting
logic to your Serving component!

## Adding Serving Parameters

Optionally, you may want to take the hardcoded path
(`./data/sample_disabled_items.txt`) away from the source code.

PredictionIO offers `ServingParams` so you can read variable values from
`engine.json` instead. PredictionIO transforms the JSON object specified in
`engine.json`'s `serving` field into the `ServingParams` class.

Modify `src/main/scala/Serving.scala` again in the *MyRecommendation*
directory to:

```scala
import scala.io.Source

import org.apache.predictionio.controller.Params  // ADDED

// ADDED ServingParams to specify the blacklisting file location.
case class ServingParams(filepath: String) extends Params

class Serving(val params: ServingParams)
  extends LServing[Query, PredictedResult] {

  override
  def serve(query: Query, predictedResults: Seq[PredictedResult])
  : PredictedResult = {
    val disabledProducts: Set[String] = Source
      .fromFile(params.filepath)
      .getLines
      .toSet

    val itemScores = predictedResults.head.itemScores
    PredictedResult(itemScores.filter(ps => !disabledProducts(ps.item)))
  }
}
```

In `engine.json`, you specify the parameter `serving` for the Serving component
(the JSON4S library automatically extract the JSON object into a Scala class
under the hood):

```json
{
  ...
  "serving": {
    "params": {
      "filepath": "./data/sample_disabled_items.txt"
    }
  },
  ...
}
```

Again, to build *MyRecommendation* and deploy it as a service:

```
$ pio build
$ pio train
$ pio deploy
```

You can change the `filepath` value without re-building the code next time.

#### [Next: Filter Recommended Items by Blacklist in Query](blacklist-items.html)

branch_name: refs/heads/develop-elasticsearch


text:
# Litex Documentation: Document your LiteX SoC Automatically

Litex lets you take a synthesized SoC and generate full
register-level documentation.  Additionally, it will generate `.svd` files,
suitable for use with various header generation programs.

## Required Software

You must have `sphinx` and `sphinx.wavedrom` installed in order to build
the documentation.  These can be installed with pip:

```
$ pip3 install sphinxcontrib-wavedrom sphinx
```

## Usage

To document your modules, import the `doc` module and call `doc.generate_docs(soc, path)`.
You can also generate an SVD file.  For example:

```python
from litex.soc.doc import generate_docs, generate_svd

...
    soc = BaseSoC(platform)
    builder = Builder(soc)
    vns = builder.build()
    soc.do_exit(vns)
    generate_docs(soc, "build/documentation",
                        project_name="My SoC",
                        author="LiteX User")
    generate_svd(soc, "build/software")
```

After you build your design, you will have a Sphinx documentation source available
in the above directory.  To build this into a target document, use `sphinx-build`.

For example, if `sphinx-build` is in your path, you can run:

`sphinx-build -M html build/documentation/ build/documentation/_build`

`sphinx-build` may be located in `~/.local/bin/` depending on your installation environment.

You can then verify the contents by opening the file `build/documentation/_build/html/index.html`

## Documenting your Registers

You can add documentation to your registers by defining your `CSRStorage` and `CSRStatus` registers with an additional `field` list.  For example:

```python
self.bitbang = CSRStorage(4, fields=[
    CSRField("mosi", description="Output value for MOSI..."
    CSRField("clk", description="Output value for SPI CLK..."
    CSRField("cs_n", description="Output value for SPI C..."
    CSRField("dir", description="Sets the dir...", values=[
        ("0", "OUT", "SPI pins are all output"),
        ("1", "IN", "SPI pins are all input"),
    ])
], description="""Bitbang controls for SPI output.  Only
    standard 1x SPI is supported, and as a result all
    four wires are ganged together.  This means that it
    is only possible to perform half-duplex operations,
    using this SPI core.""")
```

There are several interesting properties here:

* The first argument to a `CSRStorage` or `CSRStatus` is the bit width.
* You can pass a list of `CSRField` objects, which will get turned into bit fields
* Both `CSRStorage` and `CSRStatus` support a freeform `description` property that will be used to describe the overall register.

A `CSRField` object has the following properties:

* `name`: The short name of the register.  This should be just a few characters long, as it will be used in the register diagram as well as accessor objects.  **Required**
* `size`: The size of this field.  This is optional, and defaults to `1`
* `offset`: The offset of this particular field.  If unspecified, defaults to following the previous field.  Use this to add gaps to your register definitions, for example to have reserved fields.
* `reset`: If specified, the value of this field at reset.  Defaults to `0`.
* `description`: A textual description of this register.  This is optional, but should be specified because it provides critical information to the user about what this field does.
* `pulse`: If `True`, then this value is `1` only for one clock cycle after the user writes a `1` to this field.  This is especially useful for `START` bits used to initiate operations, or `RESET` bits used to clear an operation.
* `access`: The accessibility of this field.  One of `CSRAccess.ReadWrite`, `CSRAccess.WriteOnly`, or `CSRAccess.ReadOnly`
* `values`: If present, a list of tuples of values.  The first field is the numeric value, with `x` for `don't care`.  The second field, if present, is the short name of the value.  The final field is a textual description of the value.  For example:

```python
    [
        ("0b0000", "disable the timer"),
        ("0b0001", "slow", "slow timer"),
        ("0b1xxx", "fast timer"),
    ]
```

## Further Module Documentation

You can add additional documentation to your module with the `ModuleDoc` class.  Add it to your base object.

**To use further Module Documentation, your Module must inherit from `AutoDoc`**.  For example:

```python
from litex.soc.integration.doc import AutoDoc, ModuleDoc
class DocExample(Module, AutoCSR, AutoDoc):
    def __init__(self):
        self.mydoc = ModuleDoc("Some documentation")
```

You may pass a single string to the constructor, in which case the first line becomes the title, or you may pass a separate `title` and `body` parameters to the constructor.  For example:

```python
    self.intro = ModuleDoc("""Introduce ModuleDoc

    This is an example of how to document using ModuleDoc.  An additional
    section will get added to the output documentation for this module,
    with the title ``Introduce ModuleDoc`` and with this paragraph
    as a body""")
```

Note that the default documentation format is `rst`. You can switch to markdown by passing `format="markdown"` to the constructor, however support is not very good.

### Additional Sphinx Extensions

The `generate_docs()` call produces Sphinx output. By default it only includes
additional extensions for `sphinxcontrib.wavedrom`, which is required to display
register listings. You can add additional modules by passing an array to
`generate_docs()`. For example, to add `mathjax` support:

```python
    generate_docs("build/documentation", sphinx_extensions=['sphinx.ext.mathjax'])
```

You may need to pass additional configuration to `conf.py`. In this case, pass it
as `sphinx_extra_config`. For example:

```python
    generate_docs("build/documentation",
            sphinx_extensions=['sphinx_math_dollar', 'sphinx.ext.mathjax'],
            sphinx_extra_config=r"""
   mathjax_config = {
       'tex2jax': {
           'inlineMath': [ ["\\(","\\)"] ],
           'displayMath': [["\\[","\\]"] ],
       },
   }""")
```

By default, `socdoc` unconditionally overwrites all files in the output
directory, including the sphinx `conf.py` file. To disable this feature
so you can customize your own `conf.py` file, pass `from_scratch=False`:

```python
    generate_docs("build/documentation", from_scratch=False)
```

In this case, `conf.py` will only be created if it does not already exist.

### External Documentation

You can have external documentation by passing `file` to the constructor.
For example:

```python
    self.extra_doc = ModuleDoc(file="extra_doc.rst")
```

This will be included at build-time.

### Using Python Docstrings

You can also simply have your module inherit from `ModuleDoc`, in which case
the documentation will be taken from the docstring.  For example:

```python
from litex.soc.integration.doc import AutoDoc, ModuleDoc
class DocExample(Module, AutoCSR, AutoDoc, ModuleDoc):
    """
    Automatically Documented Module

    This module will be automatically documented, and included in the
    generated module documentation output.  You can add additional
    ModuleDoc objects to this module, in order to add further subsections
    to the output docs.
    """
    def __init__(self):
        pass
```

repository: enjoy-digital/litex

gha_language: C

repo_name: enjoy-digital/litex


text:
SublimeLinter-contrib-glslc
================================

This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter) provides an interface to [glslc](https://vulkan.lunarg.com/) from the Vulkan SDK. It will be used with files that have the “GLSL” syntax.

## Installation
SublimeLinter must be installed in order to use this plugin.

Please use [Package Control](https://packagecontrol.io) to install the linter plugin.

Before installing this plugin, you must ensure that `glslc` is installed on your system. This GLSL compiler frontend is usually supplied by the Vulkan SDK alongside `glslangValidator`.

In order for `glslc` to be executed by SublimeLinter, you must ensure that its path is available to SublimeLinter. The docs cover [troubleshooting PATH configuration](http://sublimelinter.readthedocs.io/en/latest/troubleshooting.html#finding-a-linter-executable).

## Settings
- SublimeLinter settings: http://sublimelinter.readthedocs.org/en/latest/settings.html
- Linter settings: http://sublimelinter.readthedocs.org/en/latest/linter_settings.html

repository: MarioHenze/SublimeLinter-contrib-glslc

repo_name: MarioHenze/SublimeLinter-contrib-glslc


text:
# Jalopy

A source code formatter/beautifier/pretty printer for the Java programming language.

[License](http://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)

## Source Code

This is a fork of the late/great jalopy source formatter at http://sourceforge.net/projects/jalopy/, later forked by @lukespragg, and later forked again by me. The swing application and log4j appenders were removed. What remains is just the library part.

Or download the [latest zip archive](https://github.com/rotty3000/jalopy/archive/master.zip).

## Contributing

Send me pull requests OR create issues!

## Usage

### Maven

    <dependency>
        <groupId>com.github.rotty3000</groupId>
        <artifactId>jalopy</artifactId>
        <version>3000.0.0</version>
    </dependency>

### Gradle

    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        compile 'com.github.rotty3000:jalopy:3000.0.0'
    }

## Documentation

To generate the the Javadocs with Maven, use the `mvn javadoc:javadoc` command. To view the javadocs simply go to `target/site/apidocs/` and open `index.html` in a web browser.

## Legal Stuff

Jalopy is licensed under the [BSD 3-Clause License](https://tldrlegal.com/l/bsd3). Basically, you can do whatever you want as long as you include the original copyright. Please see the `LICENSE.txt` file for details.

## Credits

* The original developers of the Jalopy project and jalopy-maven-plugin.
* All the people behind [Java](http://www.oracle.com/technetwork/java/index.html), [Maven](http://maven.apache.org/), and [Gradle](http://www.gradle.org/).
* Luke Spragg for trying to get this going again.


text:
---
id: 188
title: 'Connect to HP Quality Center using Java and com4j – Tutorial (part 1)'
date: 2012-10-16T15:00:46+00:00
author: Marco Molteni
layout: post
guid: http://molteni.wordpress.com/?p=188
permalink: /2012/10/16/connect-hp-quality-center-with-java-using-com4j-tutorial/
jabber_published:
  - "1350396046"
publicize_twitter_user:
  - moltenma
dsq_thread_id:
  - "5565861297"
categories:
  - HP Quality Center
  - java
---
I try to add some new information about how to connect to Quality Center using Java.

I will complete a step by step tutorial from the creation of the basic classes to the querying of the bugs.

In this first tutorial I show how to create the classes needed to connect your program to QC using the OtaClient.dll. OtaClient is not a java library and cannot used directly by our program, we need to create a wrapper that translate our request to a native language. To do this the fastest method is to use Com4j

**1. Find the OtaClient.dll**

You should find the OtaClient.dll in the following folder:

c:Program Files (x86)Common FilesMercuryInteractiveQuality Center

[](http://molteni.files.wordpress.com/2012/10/qc_ota_dll1.png?resize=577%2C111)

If you cannot find the library try to use the search features of Windows. This library is required to communicate to the server.

**2. Download com4j**

<http://java.net/projects/com4j/downloads>

When you downloaded the library you have to unzip it. As example I unzipped it in the dev folder.

**3. Use com4j to generate a library with the wrapped classes**

Because com4j is not compatible with 64 bit systems, use a 32 bit JRE or you will get:

[](http://molteni.files.wordpress.com/2012/10/qc_error.png?resize=595%2C257)

Execute the tblimp.jar with a 32-bit JRE, you can use the following parameters:

-o is for the destination directory

-p is for the java package of destination

[](http://molteni.files.wordpress.com/2012/10/exe.png?resize=595%2C45)

You could have few warning:

[](http://molteni.files.wordpress.com/2012/10/qc_result.png?resize=343%2C357)

but at the end you should have your the sources ready under hpqc/com/qc:

[](http://molteni.files.wordpress.com/2012/10/qc_java.png?resize=324%2C638)

You can import these sources to connect and use QC from your application.

More details in the next tutorial …

gha_language: HTML


text:
---
name: Feature and Event Objects in SunPy
desc: Implements a feature/event object in SunPy.
requirements:
 - Familiar with methods for creating classes, objects and subclasses.
difficulty: medium
issues:
 - https://github.com/sunpy/sunpy/pull/2759
 - https://github.com/sunpy/sunpy/issues/1792
 - https://github.com/sunpy/sunpy/issues/1398
 - https://github.com/sunpy/sunpy/issues/164
mentors:
 - wafels
 - Cadair
 - dpshelio
initiatives:
 - GSOC
tags:
 - Python
collaborating_projects:
 - SunPy
---

#### Description

The Sun displays many different features and events (FEs).  These are
detected and described either automatically by algorithm, or by visual
inspection by human, or by a combination of both.  There are many
different repositories of these FEs online.  SunPy provides access to
two large FE repositories, the Heliophysics Event Knowledgebase (HEK) and
the Helio Event Catalogue (HEC).

The aim of this project is to create a SunPy object that normalizes
input from both the HEK and HEC and creates a SunPy FE object.  The
SunPy FE object should take advantage of existing SunPy capabilities
such as SunPy spatial co-ordinates and SunPy time.  This will make FE
data much more useful to SunPy users.

The SunPy FE object should interact intuitively with existing SunPy
objects such as the SunPy maps and timeseries.  For example, it should
be simple for a FE with a spatial extent property to be overplotted
on SunPy map; similarly, it should be simple for a FE with a temporal
duration to be overplotted on a SunPy timeseries.

#### Milestones

##### Coding Starts

* Engaged with the community and understand the motivation and
  challenges of the project.

##### Evaluation 1

* Have understood what a FE is in the context of solar physics
  research and why their interaction with existing SunPy objects is
  important.
* Have evaluated and chosen an approach to the design of a SunPy FE
  object.
* Have implemented a basic SunPy FE object.

##### Evaluation 2

* Have worked with your mentors and the community to design a simple
  and functional API.
* Have a working prototype of the SunPy FE object that normalizes
input from both the HEK and HEC.
* Have tests for the working prototype.

##### Final

* Have finished implementation, testing and documentation.
* Have written examples for the gallery of how to use the functionality.
* Have written developer documentation.
* Have the Pull Request merged after review and feedback.

gha_language: SCSS


text:
# multi_scale_detector

1. the basical detector model was public and the usage of target label generate can see rpn_target_label_generate.ipynb, the usage of inference code please see rpn_inference.ipynb (I reorgnize the Faster RCNN code, and this is different tensorflow version with other github tf version), for FDDB dataset please see another two ipynb file.

2. multi_scale detector will support soon

3. This version now support FDDB, VOC dataset, I will add KITTI support soon

4. The key point regression part will add in next version(Because of the few dataset, the model works not good, add later).

4. The face recognition model will use Hinge Loss, Softmax loss and Center Loss to train.

5. for small obj, the multi feature based region proposal model can easily detector, but because of the receptive field, it become low resolution, so for small object classification, we need add a network can have low resolution input to high resolution output. This network will also add soon (using perceptual loss or GAN based network structure).

6. Add mAP evalution code

7. add fast part(proposal nms & target proposaled label) #TODO

The results of using RPN based network as face detector please see in ./example/

Author:Walter

<EMAIL_ADDRESS>


text:
---
title: ":house: Home"
---

[![build](https://github.com/tamada/fritter/workflows/build/badge.svg)](https://github.com/tamada/fritter/actions?query=workflow%3Abuild)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/2efb1d837efe40019652723687ac9173)](https://www.codacy.com/gh/tamada/fritter/dashboard?utm_source=github.com&utm_medium=referral&utm_content=tamada/fritter&utm_campaign=Badge_Grade)
[![codecov](https://codecov.io/gh/tamada/fritter/branch/main/graph/badge.svg?token=P1BFSTXHH5)](https://codecov.io/gh/tamada/fritter)
[![Coverage Status](https://coveralls.io/repos/github/tamada/fritter/badge.svg?branch=main)](https://coveralls.io/github/tamada/fritter?branch=main)

[![License](https://img.shields.io/badge/License-Apache%202.0-blue)](https://raw.githubusercontent.com/tamada/fritter/main/LICENSE)
[![Version](https://img.shields.io/badge/Version-1.0.0-blue)](https://github.com/tamada/fritter/releases/tag/v1.0.0)

[![Docker](https://img.shields.io/badge/Docker-ghcr.io%2Ftamada%2Ffritter%3A1.0.0-green?logo=docker)](https://github.com/users/tamada/packages/container/package/fritter)
[![Homebrew](https://img.shields.io/badage/Homebrew-tamada/brew/fritter?logo=homebrew)](https://github.com/tamada/homebrew-brew)

[![Discussion](https://img.shields.io/badge/GitHub-Discussion-orange?logo=github)](https://github.com/tamada/fritter/discussions)

## Overview

Small object programming/Object oriented exercise checker.

This product extends [tamada/9rules](https://github.com/tamada/9rules).
The superior points of `fritter` than 9rules are as follows.

*  Simplify the class relationships from 9rules.
    *  In the case of `9rules`, it becomes to complicated relationships among classes to satisfy the 9rules itself.
    *  Then, `fritter` prioritizes the understandability of the source codes even if to not satisfy the rules of itself.
*  Introduce more rules, and ease to add more rules.
    *  This is the side effect of the above point.
    *  To introduce the new rule, we provide only two classes which are subclasses of `Validator` and `ValidatorService`.
*  Ease to customize the parameters for validators.
    *  All parameters are read from configuration files.
    *  The configuration files are given by `--level` option or `--config` option.  `fritter` defines the parameters by json formatted config file also `level`.
*  Enable to select the output formats.
    *  `fritter` provides `json`, `xml`, and `markdown` format as result.
* Thread supports.
    *  `fritter` uses the threads by user requests for each analyzing target.

repository: tamada/fritter

gha_language: Java

repo_name: tamada/fritter


text:
You need to construct a binary tree from a string consisting of parenthesis and integers.

The whole input represents a binary tree. It contains an integer followed by zero, one or two pairs of parenthesis. The integer represents the root's value and a pair of parenthesis contains a child binary tree with the same structure.

You always start to construct the left child node of the parent first if it exists.

**Example:**
```
Input: "4(2(3)(1))(6(5))"
Output: return the tree root node representing the following tree:

       4
     /   \
    2     6
   / \   /
  3   1 5
```
**Note:**

- There will only be '(', ')', '-' and '0' ~ '9' in the input string.
- An empty tree is represented by "" instead of "()".

**Solution:**

```golang
/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */

import "strconv"

func str2tree(s string) *TreeNode {
  var stack []*TreeNode
  for i, n := 0, len(s); i < n; i++ {
    ch := s[i]
    if ch == ')' {
      stack = stack[:len(stack)-1]
    } else if ch >= '0' && ch <= '9' || ch == '-' {
      si := i
      for i < n - 1 && s[i+1] >= '0' && s[i+1] <= '9' {
        i++
      }

      num, _ := strconv.Atoi(s[si:i+1])
      root := &TreeNode{Val: num}

      if len(stack) != 0 {
        parent := stack[len(stack)-1]
        if parent.Left == nil {
          parent.Left = root
        } else {
          parent.Right = root
        }
      }

      stack = append(stack, root)
    }
  }

  if len(stack) == 0 {
    return nil
  }
  return stack[0]
}
```

url: https://raw.githubusercontent.com/geemo/leetcode/1cc42b1b29e4164deffb679e1bdd60dcb662ca70/536.Construct Binary Tree from String/README.md

repository: geemo/leetcode

repo_name: geemo/leetcode


text:
Bootstrap Loading Screen
========================

The elegant loading screen employing Bootstrap's standard components is here:

http://shb.github.io/bootstrap-loading-screen
---------------------------------------------

license: Unlicense

repository: erdapa/bootstrap-loading-screen

repo_name: erdapa/bootstrap-loading-screen


text:
# JsonSerializer

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

    gem 'json_serializer'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install json_serializer

## Usage

The gem offers two primary features, serialize ActiveRecord models and collections into JSON and providing JSON Output helpers for an API.

### ActiveRecord Patch and Custom API Attributes

We patch ActiveRecord::Base and Array with a serializer method. You can simple call `.serialize` to see this in action. If you want to customize the attributes that are serialized, simple add an `api_attributes` method to your model:

    class Post < ActiveRecord::Base
      ...
      def api_attributes
        {
          id: self.id.to_s,
          title: self.title.to_s,
          body: self.body.to_s,
          created_at: self.created_at.to_s,
          author: self.user.api_attributes,
        }
      end
      ...
    end

Adding the `api_attributes` method will allow you to control and customize the out attributes. Also note that you can have associated models, in this case Author attribute is an associated model User. We'll need to add the `api_attributes` to that model also.

### JSON Output Helper

After you have setup your custom API attributes, you can easily output JSON with a few helper methods:

#### JSON Model
Output a model in JSON:

    post = Post.find(params[:id])
    json_model :accepted, post

It's that simple. This will automatically serialize and output your model as JSON. Notice the `:accepted` attribute, this will set the Header Status Code to 202. You can always modify this, take a look at (this nice list of Rails HTTP Status Codes)[http://www.codyfauser.com/2008/7/4/rails-http-status-code-to-symbol-mapping] for more details.

You can optionally pass parameters by simple adding them to your `json_model` method:

    post = Post.find(params[:id])
    json_model :accepted, post, param: "Some extra parameters", more: "And some more..."

You can also append full serialized objects:

  post = Post.find(params[:id])
  json_model :accepted, post, comments: post.comments.serialize

In this case we called `post.comments.serialize`, which will actually collect all the objects in the array or ActiveRecord collection and serialize each one based on the API Attributes (if available) or just to_json.

#### JSON Models

Similar to the json_model method, there is a json_models method. This is simple:

    posts = Posts.all
    json_models :accepted, posts

Similarly, you can append additional parameters:

    posts = Posts.all
    json_models :accepted, posts, categories: Category.all.serialize, tags: Tag.all.serialize

#### Success and Error

You can create simple success and errors with a few helps. To create a successful JSON response, simple call:

    # json_success message, hash={}
    json_success "Great success!", extra_params: hash
    # => { success: "true", message: "message...", ... additional params ... }

This will automatically send a 200 Ok response in the Header Status Code.

Error codes are similar:

    # json_error code, message, metadata={}
    json_error 404, "Post not found.", errors: "Whatever extra metadata and params"
    # => { error: { message: "Message goes here", code: 404, meta_data: "goes here..." } }

And this will automatically add your status code to the HTTP response

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

repository: johnkoht/json-serializer

repo_name: johnkoht/json-serializer


text:
## Fill my timesheet!

Simple Chrome extension allowing to automate monthly timesheet report.

Read more in the dedicated article:

https://marc-ed-raffalli.github.io/en/projects/time-sheet-automation-chrome-extension

Special thanks to the contributors:

- [lapy](https://github.com/lapy)

repository: marc-ed-raffalli/fill-my-timesheet

gha_language: JavaScript

repo_name: marc-ed-raffalli/fill-my-timesheet


text:
# channels

[![Docker pulls](https://img.shields.io/docker/pulls/everpcpc/channels.svg)](https://hub.docker.com/r/everpcpc/channels)
[![Go Report Card](https://goreportcard.com/badge/github.com/everpcpc/channels)](https://goreportcard.com/report/github.com/everpcpc/channels)

channels is a message hub/gateway by channel.

With a stateless irc protocol subset server and streaming web api endpoints.

And backend message queue based on redis pubsub.

### RUN

```shell
docker run --rm --net=host \
    -v /path/to/config.json:/app/config.json:ro \
    -it everpcpc/channels --help
```

### DONE

- [x] irc auth with ldap
- [x] api auth with tokens
- [x] sentry webhook support
- [x] github webhook support
- [x] alertmanager webhook support

### TODO

- [ ] api auth with openid
- [ ] role based channel permission
- [ ] forwarder component for working as a message relay
- [ ] sse/websocket api endpoint
- [ ] web ui
- [ ] mysql backend for persistent store
- [ ] kafka backend for group consuming

repository: LeoQuote/channels

repo_name: LeoQuote/channels


text:
---
layout: multipage
multipage: true
date: 2018-10-04
collection: news
stories:
  - title: "RISC-V 3D GPU"
    link: 'http://libre-riscv.org/3d_gpu/'
    notes: |
      > most of the energy of a GPU is spent getting data each way past the L2/L1 cache barrier

      > the idea is to make it entirely libre-licensed and royalty-free

      This is coming out of the [FOSSDEM 2018](https://archive.fosdem.org/2018/) conference.
  - title: "Raptor Announces 'Blackbird' Micro-ATX, Low-Cost POWER9 Motherboard"
    link: 'https://www.phoronix.com/scan.php?page=news_item&px=Raptor-Blackbird-Announced'
    image: 'https://i.redd.it/8yviz4z556q11.jpg'
    notes: |

      ## What is POWER9

      POWER9 is an alternative to x86 processor architecture. Tom's Hardware has a nice [overview](https://www.tomshardware.com/news/ibm-power9-servers-supercomputers-nvidia,31567.html). It has support in the Linux kernel, and the support of [several distributions](https://www.ibm.com/support/knowledgecenter/linuxonibm/liaam/liaamdistros.htm#liaamdistros__table_i11_l3f_1cc).

      > Blackbird is a micro-ATX motherboard intended for OpenPOWER desktops/appliances and other low-power computing needs.

      Raptor has several other POWER9 systems, and teased this release [earlier to Phoronix](https://www.phoronix.com/scan.php?page=news_item&px=Raptor-Prepping-New-POWER).
  - title: "Open Source Alternatives are Starting to Scare ARM"
    link: 'https://www.theregister.co.uk/2018/10/01/arm_cortex_m_xilinx/'
    image: 'https://regmedia.co.uk/2018/10/01/handout_xilinx_arm_designstart.jpg'
    notes: |
      > DesignStart is geared toward rapidly thrusting Arm's lower-end CPU blueprints into the hands of system-on-chip designers who are on a budget or are particularly enamored with FPGAs.
      >
      > there are no royalty nor license fees involved – the designs are available to download and use completely **gratis** for Xilinx components.

      > Previous DesignStart FPGA files were aimed at helping engineers prototype on gate arrays before they design and fabricate custom system-on-chips – whereas these latest blueprints streamline the development of FPGA-powered hardware, all the way from research stages to volume production and deployment.

      > The latest hotness (for ARM) right now is hardware accelerators, which are typically repurposed graphics cards, or customized chips, that applications on a host device can offload specialist work onto. These accelerators require controller CPU cores to glue their subsystems together, and thus a drop-in Cortex-M core could be just the ticket.
  - title: "The Big Hack: How China Used a Tiny Chip to Infiltrate U.S. Companies"
    link: 'https://www.bloomberg.com/news/features/2018-10-04/the-big-hack-how-china-used-a-tiny-chip-to-infiltrate-america-s-top-companies'
    image: 'https://assets.bwbx.io/images/users/iqjWHBFdfxIU/iuMb2IgDb_zs/v0/-999x-999.gif'
    notes: |
      > Nested on the servers’ motherboards, the testers found a tiny microchip, not much bigger than a grain of rice, that wasn’t part of the boards’ original design.

      And it was just as bad as you might expect.

      > they incorporated memory, networking capability, and sufficient processing power for an attack.

      How could FOSS hardware help?

      > Mindful of the Elemental findings, Amazon’s security team conducted its own investigation into AWS’s Beijing facilities and found altered motherboards there as well, including more sophisticated designs than they’d previously encountered.
  - title: "Ohio Linuxfest 2018"
    link: 'https://ohiolinux.org/registration/'
    image: 'https://ohiolinux.org/wp-content/uploads/2016/04/ohio-linuxfest-logo-1.png'
    notes: |
      Now = Free
      Day of = Like, $10 or something
---

repository: dominikWin/website

repo_name: dominikWin/website


text:
# `oref0-fix-git-corruption`

## Help
Sometimes openaps instances get corrupted and only produce error
messages.

Looking at recent usage in git's ref-log allows us to guess at the last known
commit.  This script attempts to remove all the broken objects after the last
known commit.

This should allow recovering a corrupted openaps instance.

repository: eliotsdad/docs

repo_name: eliotsdad/docs


text:
# [5.0.1](https://github.com/smart-care/eslint-config-smartcare/compare/v5.0.0...v5.1.0) (2019-04-04)

### Features

- Replaced our custom global restriction list with `confusing-browser-globals`.

### Fixes

- Added back Flow support.
- Make TypeScript linting only apply to TypeScript files.

# [5.0.0](https://github.com/smart-care/eslint-config-smartcare/compare/v4.0.0...v5.0.0) (2019-04-03)

### BREAKING CHANGES

Version 5 represents our move over to TypeScript for all future projects at Smartcare. So this versions `peerDependencies` have changed. Please refer to the readme to check which packages are needed.

repository: smart-care/eslint-config-smartcare

repo_name: smart-care/eslint-config-smartcare


text:
[![Build Status](https://travis-ci.org/Johannes-Sahlmann/pystrometry.svg?branch=master)](https://travis-ci.org/Johannes-Sahlmann/pystrometry)
[![Documentation Status](https://readthedocs.org/projects/pystrometry/badge/?version=latest)](https://pystrometry.readthedocs.io/en/latest/?badge=latest)
[![PyPI version](https://badge.fury.io/py/pystrometry.svg)](https://badge.fury.io/py/pystrometry)
[![PyPI - License](https://img.shields.io/pypi/l/Django.svg)](https://github.com/Johannes-Sahlmann/pystrometry/blob/master/LICENSE.md)
[![DOI](https://zenodo.org/badge/172252669.svg)](https://zenodo.org/badge/latestdoi/172252669)

# pystrometry  -  Support for high-precision astrometry timeseries analysis

### Example usage

### Documentation

### Contributing
Please open a new issue or new pull request for bugs, feedback, or new features you would like to see. If there is an issue you would like to work on, please leave a comment and we will be happy to assist. New contributions and contributors are very welcome!

### References

repository: NBauchet/pystrometry

repo_name: NBauchet/pystrometry


text:
# GoPlayAds
A simple Android library to cross promote your apps.

Currently includes a Dialog & Interstitial Ad fetched from a json stored on a site/server.

Primary Goal:

To keep it Simple & including Ads support like AdMob's Ad (Native, Interstitial)

## Gradle
[![Download](https://api.bintray.com/packages/goplay/maven/goplayAds/images/download.svg) ](https://bintray.com/goplay/maven/goplayAds/_latestVersion)

Adding GoPlayAds in your App -
```gradle
dependencies {
    implementation 'com.goplay:goplayAds:1.0.01'
}
```

## Json Array Schema
Json Array Schema that you'll have to put on a server:
```json
   {
    "apps":

     [{
       "app_title": "App Name (Dialog)",
       "app_desc": "Your App's description",
       "app_icon": "https:// URL to Icon",
       "app_header_image": "https:// URL to Header Image",
       "app_uri": "http:// URL or Package Name - com.package.name",
       "app_rating": "4.5",
       "app_cta_text": "Install",
       "app_price": "Free",
       "app_adType": "dialog"
     },

     {
       "app_interstitial_url": "IMAGE URL",
       "app_uri": "http:// URL or Package Name - com.package.name",
       "app_adType": "interstitial"
     },

     {
     "app_title": "App Name 2 (Native Ad)",
     "app_desc": "Your App's Description",
     "app_icon": "https:// URL to Icon",
     "app_header_image": "https:// URL to Header Image",
     "app_uri": "http:// URL or Package Name - com.package.name",
     "app_rating": "4.5",
     "app_cta_text": "Install",
     "app_price": "Free",
     "app_adType": "native"
     }]
    }
```

Some of the Assets like App Title, App Description, Icons & call to Action Text & Package Name are necessary!

## GoPlayAdsDialog

GoPlayAdsDialog is a Beautifully Styled Dialog which shows your Ad Assets like Header Image, App Icon, App Title & Description, Call to Action Button, Star Ratings & Price of the App.

The library internally uses `Palette API` to color the CTA Button by fetching the `Dominant Color` from Icon or Header Bitmap, whichever available.

Following is an example of GoPlayAdsDialog -
```java
GoPlayAdsDialog goplayAds = new GoPlayAdsDialog(MainActivity.this);
goplayAds.setUrl(adURL); //URL to Json File
goplayAds.hideIfAppInstalled(true); //An App's Ad won't be shown if it is Installed on the Device.
goplayAds.setCardCorners(100); // Set CardView's corner radius.
goplayAds.setCtaCorner(100); //Set CTA Button's background radius.
goplayAds.setForceLoadFresh(false); //Fetch Json everytime loadAds() is called, true by default, if set to false, Json File's Response is kept untill App is closed!
goplayAds.showHeaderIfAvailable(false); //Show Header Image if available, true by default
goplayAds.loadAds();
```

You can check if the Ad is loaded via -
```java
goplayAds.isAdLoaded();
//returns true if loaded, false otherwise!
```

You can also add a Listener to GoPlayAdsDialog,
```java
goplayAds.setAdListener(new AdListener() {
    @Override
    public void onAdLoadFailed() {}

    @Override
    public void onAdLoaded() {
        //Show AdDialog as soon as it is loaded.
        goplayAds.showAd();
    }

    @Override
    public void onAdClosed() {}

    @Override
    public void onAdShown() {}

    @Override
    public void onApplicationLeft() {}
});
```

**
NOTE: You cannot Customize the Dialog except for the CardView's Corner Radius & CTA Button's Background Radius!**

Use `GoPlayAdsNative` instead :)

## GoPlayAdsNative

GoPlayAdsNative is the type of Ad where you can pass your own views which includes Ad Assets just like AdMob's `NativeAdvancedUnified`.

The `setNativeAdView()` method in `GoPlayAdsNative` accepts two types of object to specify your View containing Ad Assets.
* GoPlayAdsNativeAdView Object,
* View Object containing Ad Assets.

#### GoPlayAdsNativeView
If you use a `GoPlayAdsNativeView`, you'll need to pass the ids of the Assets (Icon, Call to Action View, Header Image etc) in a `GoPlayAdsNativeView` in their respective setter methods
and then set that object to the GoPlayAdsNative's `setNativeView()` .

Following is an example of `GoPlayAdsNativeView` -
```java
final Relativelayout adLayout = findViewById(R.id.adLayout); //Ad Assets inside a ViewGroup
adlayout.setVisibility(View.GONE):
```
```java
GoPlayAdsNativeView nativeView = new GoPlayAdsNativeView();
nativeView.setTitleView((TextView) findViewById(R.id.appinstall_headline));
nativeView.setDescriptionView((TextView) findViewById(R.id.appinstall_body));
nativeView.setIconView((ImageView) findViewById(R.id.appinstall_app_icon));
nativeView.setHeaderImageView((ImageView) findViewById(R.id.large));
nativeView.setCallToActionView(findViewById(R.id.appinstall_call_to_action));
nativeView.setPriceView((TextView) findViewById(R.id.price));
nativeView.setRatingsView((RatingBar) findViewById(R.id.rating));
```

### Passing a View object in GoPlayAdsNative
You can also pass a View in the `setNativeAdView()`, however there are some rules you'll need to follow!

You'll need to use the same `IDs` for your Ad Assets mentioned below -

    Ad Assets
    IDs

    Header Image
    goplayAds_header_image

    App Icon
    goplayAds_app_icon

    Title
    goplayAds_title

    Description
    goplayAds_description

    Price
    goplayAds_price

    RatingBar
    goplayAds_rating

#### Loading GoPlayAdsNative
```java
GoPlayAdsNative goplayAdsNative = new GoPlayAdsNative(NativeAdActivity.this);
goplayAdsNative.setNativeAdView(nativeView); //GoPlayAdsNativeView Object
goplayAdsNative.setNativeNativeView(adLayout); //View Object
goplayAdsNative.setUrl(adUrl);
goplayAdsNative.setNativeAdListener(new NativeAdListener() {
    @Override
    public void onAdLoaded() {
        adLayout.setVisibility(View.VISIBLE);
    }

    @Override
    public void onAdLoadFailed() {
        Toast.makeText(NativeAdActivity.this, "Failed", Toast.LENGTH_SHORT).show();
    }
});
goplayAdsNative.loadAds();
```

Check if NativeAd is loaded - `goplayAdsNative.isAdLoaded();`

Additionally, you can define your own 'Call to Action' Button's action by using a `CallToActionListener`, for e.g.
```java
goplayAdsNative.setCallToActionListener(new NativeAdListener.CallToActionListener() {
            @Override
            public void onCallToActionClicked(View view) {
                //Do your Stuff!
            }
        });
```

**Note: If you don't implement the CTAListener, default implementation is used which navigates the user to PlayStore or Website depending on the passed argument to the "app_uri" object in json, when clicked.**

## GoPlayAdsInterstitial

GoPlayAds also supports Interstitial Ad support just like AdMob has one!

GoPlayAdsInterstitial shows an Image fetched from your Json & navigates the User to Google Play if you specified a Package Name or the Website otherwise.

Following is an example of GoPlayAdsInterstitial -
```java
final GoPlayAdsInterstitial interstitial = new GoPlayAdsInterstitial(MainActivity.this);
interstitial.setUrl(adURL);
interstitial.setAdListener(new AdListener() {
    @Override
    public void onAdLoadFailed() {}

    @Override
    public void onAdLoaded() {}

    @Override
    public void onAdClosed() {}

    @Override
    public void onAdShown() {}

    @Override
    public void onApplicationLeft() {}
});
interstitial.loadAd();
```

Just like the GoPlayAdsDialog, you can check if the Interstitial is Loaded in the same way - `interstitial.isAdLoaded();`

And show Interstitial like - `interstitial.show();`

## Clearing the Cache.
GoPlayAds uses Glide for Image Loading and Caching, therefore you should clear its cache periodically by calling the following method -
```java
GoPlayAdsHelper.clearGlideCache(MainActivity.this);
```

## ProGuard
```
-keep class org.jsoup.**
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}
```

repository: gpgames/GoPlayAds

repo_name: gpgames/GoPlayAds


text:
# RandomValue Provider

Sometimes, you might need to generate random values as part of your application's configuration values.

The Steeltoe `RandomValue` generator is a configuration provider that you can use to do just that. It can produce integers, longs, uuids, or strings, as the following examples show:

```csharp
var my_secret = config["random:value"];
var my_number = config["random:int"];
var my_big_number = config["random:long"];
var my_uuid = config["random:uuid"];
var my_number_less_than_ten = config["random:int(10)"];
var my_number_in_range = config["random:int[1024,65536]"];

```

You can also use the generator together with property placeholders. For example, consider the following `appsettings.json`:

```json
{
    "my": {
        "secret": "${random:value}",
        "number": "${random:int}",
        "big_number": "${random:long}",
        "uuid": "${random:uuid}",
        "number_less_than_ten": "${random:int(10)}",
        "number_in_range": "${random:int[1024,65536]}"
    }
}
```

## Usage

You should have a good understanding of how the .NET [Configuration services](https://docs.microsoft.com/aspnet/core/fundamentals/configuration) work before starting to use this provider.

In order to use the Steeltoe RandomValue provider, you need to:

1. Add a NuGet package reference to your project.
1. Add the provider to the Configuration Builder.
1. Access random values from the `IConfiguration`.

### Add NuGet Reference

To use the provider, you need to add a reference to the appropriate Steeltoe NuGet.

To do so, add a `PackageReference` resembling the following:

```xml
<ItemGroup>
...
    <PackageReference Include="Steeltoe.Extensions.Configuration.RandomValueBase" Version="3.2.0"/>
...
</ItemGroup>
```

### Add Configuration Provider

To have the ability to generate random values from the configuration, you need to add the `RandomValue` generator provider to the `ConfigurationBuilder`.

The following example shows how to do so:

```csharp
using Steeltoe.Extensions.Configuration.RandomValue;
...

var builder = new ConfigurationBuilder()
    .SetBasePath(env.ContentRootPath)
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
    .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)

    // Add RandomValue generator
    .AddRandomValueSource();
Configuration = builder.Build();
...

```

>If you wish to generate random values as part of using placeholders, you need to add the `RandomValue` provider to the builder before you add the placeholder resolver.

### Access Random Value Data

Once the configuration has been built, the `RandomValue` generator can be used to generate values. You can access the configuration data by using the appropriate `random` keys.

Consider the following `HomeController` example:

```csharp
public class HomeController : Controller
{
    private IConfiguration _config;
    public HomeController(IConfiguration config)
    {
        _config = config;
    }
    public IActionResult Index()
    {
        ViewData["random:int"] = _config["random:int"];
        ViewData["random:long"] = _config["random:long"];
        ViewData["random:int(10)"] = _config["random:int(10)"];
        ViewData["random:long(100)"] = _config["random:long(100)"];
        ViewData["random:int(10,20)"] = _config["random:int(10,20)"];
        ViewData["random:long(100,200)"] = _config["random:long(100,200)"];
        ViewData["random:uuid"] = _config["random:uuid"];
        ViewData["random:string"] = _config["random:string"];
        return View();
    }
    ...
}
```

repository: SteeltoeOSS/Documentation

gha_language: CSS

repo_name: SteeltoeOSS/Documentation


text:
# App Service authentication and service-to-service integration

Scenario:
- You have backend API in app service and you want to secure it using Azure AD authentication
- You have one or more daemon services using that backend API
- Developers creating the actual backend code can run their implementation
  locally without authentication setup
- You want to separate the responsibilities between
  developers and admins who grant access between
  these two different services
- You want to introduce authentication when deploying
  the application to Azure (not before)

We can implement above scenario using following steps:

1. Register backend application: `CloudBackend`
    - Application ID URI: `api://cloudbackend`
2. Add application role to `CloudBackend` (which we can later assign to our client application)
    - Display name: `Writers`
    - Allower member types: either `Applications` or `Both (Users/Groups + Applications)`
    - Value: `Task.Write`
    - Description: `Task.Write description text`
3. Require user assignment to this application
    - Under *"Enterprise Application"* blade find `CloudBackend`
    - Under properties set `User assignment required?` to `Yes`
4. Register client application: `CloudBackend Client`
5. Configure API permissions for `CloudBackend Client`
    - Add `CloudBackend` -> `Task.Write`
6. API permission is `Type: Application` and therefore admin consent is required
    - You can delegate the consent management to users
      in Azure AD built-in role [Cloud Application Administrator](https://docs.microsoft.com/en-us/azure/active-directory/roles/permissions-reference#cloud-application-administrator) (or role with similar permissions)
7. Use `CloudBackend` in app service authentication settings
    - Client ID = `CloudBackend` application (client) ID
    - Issuer Url = `https://sts.windows.net/{{tenant}}/`
    - Allowed Token Audiences = `CloudBackend` application ID URI (`api://cloudbackend`)

![App Service authentication and service-to-service integration](https://user-images.githubusercontent.com/2357647/112526297-74e42e80-8daa-11eb-8fef-479f08177e60.png)

Steps in above diagram:

(1). `Daemon app #1` tries to acquire token from Azure AD to the target resource

(2). Azure AD validates request and app assignment and returns valid token

(3). App connects to the backend successfully using the `access_token`

(A). `Daemon app #2` cannot acquire token since application does not have assignment to target application

Lets see how this works in action. Here are the variables:

- `clientID` = `CloudBackend Client` application (client) ID
- `clientSecret` = `CloudBackend Client`  client secret
- `resourceAppIdURI` = `CloudBackend` application ID URI (`api://cloudbackend`)
- `tenant` = Azure AD tenant identifier

`CloudBackend Client` requests access token from Azure AD:

```HTTP
POST https://login.microsoftonline.com/{{tenant}}/oauth2/v2.0/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded

client_id={{clientID}}
&client_secret={{clientSecret}}
&scope={{resourceAppIdURI}}/.default
&grant_type=client_credentials
```

You might get following error message:

```json
{
 "error": "invalid_grant",
  "error_description": "AADSTS501051: Application '{{clientID}}'
  (CloudBackend Client) is not assigned to a role for the application 'api://cloudbackend'(CloudBackend).\r\n
  Trace ID: f255b072-3a51-4deb-a6b6-996fcebb8101\r\n
  Correlation ID: f319b6c3-16a4-46dd-bf90-ac85c936cb72\r\n
  Timestamp: 2021-03-24 08:06:01Z",
   "error_codes": [
     501051
   ],
   "timestamp": "2021-03-24 08:06:01Z",
   "trace_id": "f255b072-3a51-4deb-a6b6-996fcebb8101",
   "correlation_id": "f319b6c3-16a4-46dd-bf90-ac85c936cb72",
   "error_uri": "https://login.microsoftonline.com/error?code=501051"
 }
```

Above means that you might not have assigned role correctly or then consent is missing.

This should be the correct response:

```json
{
 "token_type": "Bearer",
 "expires_in": 3599,
 "ext_expires_in": 3599,
 "access_token": "eyJ0eXAi...sZgqIbn7g"
}
```

If you grab `access_token` from above and put it to [jwt.ms](https://jwt.ms/)
to analyze the content of the token:

```json
{
  "aud": "api://cloudbackend",
  "iss": "https://sts.windows.net/{{tenant}}/",
  "iat":<PHONE_NUMBER>,
  "nbf":<PHONE_NUMBER>,
  "exp":<PHONE_NUMBER>,
  "aio": "E2ZgYJhTGP4iKuZ/BOPUo4943+zKBwA=",
  "appid": "{{clientID}}",
  "appidacr": "1",
  "idp": "https://sts.windows.net/{{tenant}}/",
  "oid": "c18eb113-8ede-4317-b986-93c54ce20991",
  "rh": "0.AQwAFaLG6jeSrUCB7sptVBQGkZZ_xDYzLIlDhK7DWMj_xvMMAAA.",
  "roles": [
    "Task.Write"
  ],
  "sub": "c18eb113-8ede-4317-b986-93c54ce20991",
  "tid": "{{tenant}}",
  "uti": "YEDcVJttIUKUL7GfmGK5AA",
  "ver": "1.0"
}
```

Important part is this:

```json
{
...
  "roles": [
    "Task.Write"
  ],
...
}
```

`CloudBackend Client` can now use above token for accessing `CloudBackend`:

```HTTP
GET https://<yourbackendapi>.azurewebsites.net/api/tasks
Authorization: Bearer eyJ0eXAi...sZgqIbn7g
```

It's important to understand how [authentication and authorization in Azure App Service and Azure Functions](https://docs.microsoft.com/en-us/azure/app-service/overview-authentication-authorization) works.

If you expose multiple APIs from the same backend application, and your want to
limit API usage per API specific role(s), then you need validate the claims
inside the APIs:

![validate tokens inside your backend application](https://user-images.githubusercontent.com/2357647/112527449-baedc200-8dab-11eb-801b-64a31d0cd343.png)

[Access user claims](https://docs.microsoft.com/en-us/azure/app-service/app-service-authentication-how-to#access-user-claims)

[User/Application claims](https://docs.microsoft.com/en-us/azure/app-service/overview-authentication-authorization#userapplication-claims)

Here is example Azure Functions code snippet for illustration purposes:

```csharp
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

public static IActionResult Run(HttpRequest req, ClaimsPrincipal principal)
{
  if (principal.HasClaim("roles", "Task.Write"))
  {
    return new OkResult();
  }
  return new UnauthorizedResult();
}
```

This enables you to do following mapping for APIs and roles:

`/api/sales` => `Sales.Read`

`/api/products` => `Products.Read`

This lets you do very fine-grained authorization.

### Links

[Daemon client application (service-to-service calls)](https://docs.microsoft.com/en-us/azure/app-service/configure-authentication-provider-aad#daemon-client-application-service-to-service-calls)

[Admin-restricted permissions](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent?WT.mc_id=Portal-Microsoft_AAD_RegisteredApps#admin-restricted-permissions)

[Validating tokens](https://docs.microsoft.com/en-us/azure/active-directory/develop/access-tokens#validating-tokens)


text:
# kube-service-exporter

A Kubernetes controller for enabling load balancing *across multiple clusters*, written in Go.

By exporting Kubernetes Service and Node metadata to Consul, `kube-service-exporter` facilitates bringing an external load balancer to Kubernetes installations for highly available cluster designs.

## Overview

Traffic ingress into a Kubernetes cluster from on-prem or custom load balancers is complex. Commonly, Ingress controllers are used to support this use case, but  this creates an often unnecessary intermediate proxy and TCP/L4 ingress is still poorly supported. `kube-service-exporter` runs inside the cluster and exports metadata about Kubernetes Services and Nodes to Consul which can be used to configure a custom load balancer according to individual needs.  Services exported by `kube-service-exporter` can be configured to load balance parallel deployments of the same service across multiple Kubernetes clusters, allowing Kubernetes clusters to be highly available. Metadata about the configuration is stored in Annotations on the Service resource which mirror the Service Annotations used when configuring cloud load balancers for providers such as AWS and GCE.

`kube-service-exporter` does not actively configure load balancers. It enables dynamic edge load balancing and highly available cluster designs by exporting information about a Kubernetes Service to Consul for consumption by tools like `consul-template`.

## Metadata

`kube-service-exporter` creates the following metadata in Consul:

* In [Consul KV](https://www.consul.io/api/kv.html): A JSON document for each exported Kubernetes Service, grouped by a cluster identifier (from the `KSE_CLUSTER_ID` environment variable)
* In Consul KV: A JSON array of healthy Nodes with their hostname and IP address
* (Optionally) A [Consul Service](https://www.consul.io/docs/agent/services.html) for each Kubernetes Service

### Services (Consul KV)

Metadata is exported to Consul for Kubernetes Services of `type: LoadBalancer` or `type: NodePort` with the `kube-service-exporter.github.com/exported` annotation set to `"true"`.  The exported metadata for each Kubernetes Service is available at `$KSE_KV_PREFIX/services/$SERVICE_NAME/clusters/$CLUSTER_ID`.  This path warrants some explanation:

* `KSE_KV_PREFIX` is the value of the `KSE_KV_PREFIX` environment variable passed in and defaults to `kube-service-exporter`.
* `SERVICE_NAME` is a generated string that uniquely identifies an exported service as `(${CLUSTER_ID}-)${NAMESPACE}-${SERVICE_NAME}-${SERVICE_PORT}`
  * cluster ID (`KSE_CLUSTER_ID` from the environment) **only if `kube-service-exporter.github.com/load-balancer-service-per-cluster` is set to `"true"`**
  * The Kubernetes Namespace (`metadata.namespace`) that the Service is deployed to
  * The Name of the Kubernetes Service (`metadata.name`)
  * The Kubernetes Service port name (`spec.ports[].name`) or port number (`spec.ports[].port`) *if no name is given*. Kubernetes Services with multiple ports exposed will be split into multiple exported services in Consul.
* `CLUSTER_ID` is the value of the `KSE_CLUSTER_ID` environment variable.

Consider a Kubernetes Service as follows:

```yaml
apiVersion: v1
kind: Service
metadata:
  annotations:
   kube-service-exporter.github.com/custom-attrs: |
      {
        "allowed_ips": [
          "<IP_ADDRESS>/8",
          "<IP_ADDRESS>/12",
          "<IP_ADDRESS>/16"
        ]
      }
    kube-service-exporter.github.com/exported: "true"
    kube-service-exporter.github.com/load-balancer-backend-protocol: http
    kube-service-exporter.github.com/load-balancer-class: internal
    kube-service-exporter.github.com/load-balancer-dns-name: robots.example.net
    kube-service-exporter.github.com/load-balancer-service-per-cluster: "false"
  labels:
    service: megatron
  name: megatron
  namespace: decepticons
spec:
  ports:
  - name: http
    nodePort: 32046
    port: 8080
    protocol: TCP
    targetPort: http
  selector:
    app: megatron
  type: LoadBalancer
```

With `KSE_CLUSTER_ID=transformers`, the Kubernetes Service :point_up: would appear in Consul KV at `kube-service-exporter/services/decepticons-megatron-http/clusters/transformers` with the value:

```json
{
  "hash": "80ce408f9e6c914",             // Internal use
  "ClusterName": "transformers",         // The cluster ID for this service
  "port": 32046,                         // The NodePort the Service is available at on each Node on this cluster
  "dns_name": "robots.example.net",      // set by `kube-service-exporter.github.com/load-balancer-dns-name`
  "health_check_path": "/healthz",       // set by `kube-service-exporter.github.com/load-balancer-health-check-path`
  "health_check_port": 32046,            // set by `kube-service-exporter.github.com/load-balancer-health-check-port`
  "backend_protocol": "http",            // set by `kube-service-exporter.github.com/load-balancer-backend-protocol`
  "proxy_protocol": false,               // set by 'kube-service-exporter.github.com/load-balancer-proxy-protocol`
  "load_balancer_class": "internal",     // set by `kube-service-exporter.github.com/load-balancer-class`
  "load_balancer_listen_port": 0,        // set by `kube-service-exporter.github.com/load-balancer-listen-port`
  "custom_attrs": {                      // set by `kube-service-exporter.github.com/custom-attrs`
    "allowed_ips": [
      "<IP_ADDRESS>/8",
      "<IP_ADDRESS>/12",
      "<IP_ADDRESS>/16"
    ]
  }
}

```

See the Annotations section :point_down: for details on how to configure these metadata with annotations on the Kubernetes Service.

### Services (Consul Service)

`kube-service-exporter` can optionally export Consul Services in addition to the Consul KV output :point_up:.  Since the `meta` property of [Consul Services](https://www.consul.io/docs/agent/services.html) is relatively new and has some limitations, it is not used to track Consul Service metadata and the companion KV data should be used instead.

To export Consul Services:

* `kube-service-exporter` must be running as a DaemonSet on every Node in the Kubernetes cluster that will serve requests
* There must be a Consul Agent running on each Kubernetes Node that serves request.
* The environment variable `KSE_SERVICES_ENABLED` must be set to a truthy [value](https://golang.org/pkg/strconv/#ParseBool) (e.g. true, t, 1).

When configured to export Consul Services, the Kubernetes Service above would have an entry in the [Consul Catalog](https://www.consul.io/api/catalog.html) for each cluster Node similar to this:

```json

[
  {
    "Node": "kube-node-1.mydomain.net",
    "Address": "<IP_ADDRESS>",
    "TaggedAddresses": {
      "lan": "<IP_ADDRESS>",
      "wan": "<IP_ADDRESS>"
    },
    "ServiceID": "decepticons-megatron-http",   // The Service Name, which follows the
    "ServiceName": "decepticons-megatron-http", // rules outlined for service names above
    "ServiceTags": [
      "transformers",                           // The Cluster ID
      "kube-service-exporter"                   // All generated Services receive this tag
    ],
    "ServiceAddress": "<IP_ADDRESS>",
    "ServicePort": 32046,                       // The Service NodePort
    "ServiceEnableTagOverride": false,
    "CreateIndex":<PHONE_NUMBER>,
    "ModifyIndex":<PHONE_NUMBER>
  },
  ...
]
```

### Nodes (Consul KV)

Metadata about Kubernetes Nodes in the Kubernetes cluster is stored as a JSON array in Consul KV under `$KSE_KV_PREFIX/nodes/$KSE_CLUSTER_ID`.

```json
$ consul kv get kube-service-exporter/nodes/mycluster
[
  {
    "Name": "kube-node-1.mydomain.net",
    "Address": "<IP_ADDRESS>"
  },
  {
    "Name": "kube-node-2.mydomain.net",
    "Address": "<IP_ADDRESS>"
  },
  {
    "Name": "kube-node-3.mydomain.net",
    "Address": "<IP_ADDRESS>"
  }
]
```

In order for a Node to appear in this list, the following criteria must be met:

* The NodeReady NodeCondition must be true
* The Node matches the label selector specified by the `KSE_NODE_SELECTOR` environment variable

This means when Nodes are drained or unhealthy, they will automatically be removed from Consul, reducing the possibility that a request will be routed to an out-of-service Node.

### "Ingress" Services

In some cases, there could be a different `Service` in-between the load balancer and the target `Service`.  A common example would be an ingress gateway, where the load balancer should be sending traffic to the NodePort for the ingress gateway, not directly to the `Service`. For these cases, there are 3 annotations which all need to be set to identify that Service:

* `kube-service-exporter.github.com/ingress-service-namespace`
* `kube-service-exporter.github.com/ingress-service-name`
* `kube-service-exporter.github.com/ingress-service-port-name`

If the ingress namespace/name/port are all set and the ingress `Service` and port exists, `kube-service-exporter` will replace the `port` and `health_check_port` fields stored in consul with the value from the ingress `Service`.
`kube-service-exporter` will also add an `ingress_sni` field to a `Service`'s metadata in consul.
This field uniquely identifies an exported service (a K8s Service port) and is useful in cases where an ingress gateway
accepts traffic for multiple TCP services on the same port.
A load-balancer can then set `ingress_sni` as an SNI so that ingress gateways can determine to which `Service` a TCP connection should be routed.

### Per-Cluster Load Balancing vs Multi-Cluster Load Balancing

## Annotations

The following Annotations are supported on the Kubernetes Service resource. Note that these Annotations only describe *intent* and their usage is specific to the *consumer* of this metadata (e.g. `haproxy` configured via `consul-template`). As with all Kubernetes Annotations, the values must be strings.

* `kube-service-exporter.github.com/exported` - When set to the string `"true"`, this Kubernetes Service will be exported.  Defaults to `"false"`, which means do not export.
* `kube-service-exporter.github.com/load-balancer-proxy-protocol` - Set to `"*"` to signal that all backends support PROXY Protocol.
* `kube-service-exporter.github.com/load-balancer-class` - The load balancer class is an identifier to associate this Service with a load balancer.  Examples might include "internal", "public", "corp", etc. It is up to the consumer to decide how this field is used.
* `kube-service-exporter.github.com/load-balancer-backend-protocol` - This is used to specify the protocol spoken by the backend Pods behind a load balancer listener. Valid options are `http` or `tcp` for HTTP or TCP backends.
* `kube-service-exporter.github.com/load-balancer-health-check-path` - A path or URI for an HTTP health check
* `kube-service-exporter.github.com/load-balancer-health-check-port` - The port for the Health check. If unset, defaults to the Service NodePort.
* `kube-service-exporter.github.com/load-balancer-service-per-cluster` - If unset (or set to `"false"`), this will create a separately named service *per cluster id*.  This is useful for applications that should *not* be load balanced across multiple clusters.  The default is `"true"`, which will aggregate the same service across different clusters into the same name.  Service uniqueness is defined by a tuple of namespace, name, & port name with an optional cluster id.
* `kube-service-exporter.github.com/load-balancer-dns-name` - The DNS name that should be routed to this Service.
* `kube-service-exporter.github.com/ingress-service-namespace` - The Namespace where the ingress Service exists
* `kube-service-exporter.github.com/ingress-service-name` - The Name of the ingress Service
* `kube-service-exporter.github.com/ingress-service-port-name` - The PortName of the ingress Service
* `kube-service-exporter.github.com/custom-attrs` - An arbitrary JSON object that will be parsed and added to the exported to Consul under `.custom_attrs`

## Configuration

Exported services are configured with Annotations on the Service, but `kube-service-exporter` itself is configured with environment variables.  The following configuration options are available:

* `KSE_NODE_SELECTOR` (default: all Nodes) - A [label selector](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors) that will be used to determine which nodes are exported to Consul.  Multiple node selectors can be specified by passing in a JSON array of label selectors.  If multiple label selectors are provided, then the first one that has `KSE_MIN_SELECTOR_NODES` available will be used.
* `KSE_MIN_SELECTOR_NODES` (default: 1) - The minimum number of nodes that must match the `KSE_NODE_SELECTOR` in order for the node selector to be used.  If no selector has this many nodes, then the last selector given that has any nodes will be used.
* `KSE_CONSUL_KV_PREFIX` (default: kube-service-exporter) - The prefix to use when setting Consul KV keys.
* `KSE_CONSUL_DATACENTER` (default: Consul Agent Default) - The name of the Consul Datacenter to use
* `KSE_CONSUL_HOST` (default: <IP_ADDRESS>) - The IP or hostname for the Consul Agent.
* `KSE_CONSUL_PORT` (default: 8500) - The HTTP port for the Consul Agent.
* `KSE_DOGSTATSD_ENABLED` (default: true) - Set to "false" to disable sending of dogstatsd metrics
* `KSE_DOGSTATSD_HOST` (default: <IP_ADDRESS>) - The IP or hostname for the Datadog dogstatsd agent
* `KSE_DOGSTATSD_PORT` (default: 8125) - The port for the Datadog dogstatsd agent
* `KSE_DOGSTATSD_TAGS` (default: none) - A comma-separated list of tags to add to all metrics sent to dogstatsd
* `KSE_HTTP_IP` (default: all IPs) - The IP for `kube-service-exporter` to listen on for the `/healthz` endpoint and [go expvar stats](https://golang.org/pkg/expvar/)
* `KSE_HTTP_PORT` (default: 8080) - The port for the health/stats listener
* `KSE_SERVICES_ENABLED` (default: false) - Set to "true" to export Consul Services in addition to Consul KV metadata.  Requires additional configuration described :point_up:
* `KSE_SERVICE_RESYNC_PERIOD` (default: 15) - The service watcher's resync period in minutes. This is the period at which the service watcher will re-queue all Services in the cluster to ensure they are up-to-date.

## Metrics

## Consul Target

Please see an [example deploy here](/examples/deploy-example.md).

### Operation

## How To Use

The current public docker image of kube-service-exporter is available on DockerHub:
`github/kube-service-exporter:latest`

For an example deploy, please see the [Examples folder](/examples/deploy-example.md).

## Contributing

Please see our [contributing document](/CONTRIBUTING.md) if you would like to participate!

## Getting help

If you have a problem or suggestion, please [open an issue](https://github.com/github/kube-service-exporter/issues/new) in this repository, and we will do our best to help. Please note that this project adheres to the [Contributor Covenant Code of Conduct](/CODE_OF_CONDUCT.md).

## License

kube-service-exporter is licensed under the [Apache 2.0 license](LICENSE).

## Maintainers

`kube-service-exporter` was originally designed and authored by [Aaron Brown](https://github.com/aaronbbrown).
It is maintained, reviewed, and tested by the Production Engineering team at GitHub.
Contact the maintainers<EMAIL_ADDRESS>

repository: github/kube-service-exporter

gha_language: Go

repo_name: github/kube-service-exporter