text:
# Accelerex Eat-In

[![N|Solid](https://github.com/cedest/Accelerex-Eat-In/blob/main/Accelerex.Web/wwwroot/images/NET_Core_Logo.svg.thumb70.png)](https://dotnet.microsoft.com/download/dotnet/5.0)

[![Build Status](https://travis-ci.com/cedest/Accelerex-Eat-In.svg?branch=main)](https://travis-ci.com/cedest/Accelerex-Eat-In)

Accelerex Eat-In (Web & API) is a micro self hosted, mobile-ready C# .Net Core solution. This solution helps Accelerex restaurant manage open hours on a daily basis.

## Table of Content
- Features
- How to Install
- How to Use
- Tech Stack
- Plugins
- Credits
- License
- Answer to Question 2

## Features
- The solution features two projects
-- The Web project and the API project
- The Web project serves has the client side, from where the data will be provided
- Data can be either be uploaded or pasted as string on the page
- If data would be uploaded, the upload components accepts either a text file (.txt) or a json file (.json). The uploaded file must contain a valid json string
- Once a valid json is submitted, the processed response will be displayed on the page

- The API project receives the submitted json string
- It then processes the string to an easily readable format
- Sends readable formatted string back to the caller

## How to Install
- [Download](https://git-scm.com/downloads) and Install Git for your OS version
- [Download](https://dotnet.microsoft.com/download/dotnet/5.0) and Install .NET 5
- [Download](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=16) and Install Visual Studio Community Edition
- Clone the project from github

```sh
Navigate to the directory where you want to download the solution, run the following line of code to download the solution from git
git clone https://github.com/cedest/Accelerex-Eat-In.git
```
- Once the pull is complete:
> Navigate to the downloaded application folder and double click on the solution (Accelerex.Test.sln) file to lauch the application using visual studio.
> You then need to ensure that both Web & API projects are set to start. Then click Start

[![N|Solid](https://github.com/cedest/Accelerex-Eat-In/blob/main/Accelerex.Web/wwwroot/images/MulipleProj.PNG)](#)

> Alternatively, you can publish the projects to a self hosted IIS environment

## How to Use

When you launch the application, you should see a page as shown below:

- ### API Endpoint
- [HttpPost] http://domain.com:port/api/OpenHour (e.g. http://localhost:8983/api/OpenHour)

- ### Web Interface
[![N|Solid](https://github.com/cedest/Accelerex-Eat-In/blob/main/Accelerex.Web/Screenshots/Landing.PNG)](#)
- Select the Json submission type

If File upload submission type is selected;
[![N|Solid](https://github.com/cedest/Accelerex-Eat-In/blob/main/Accelerex.Web/Screenshots/Landing-File.PNG)](#)
- Upload a text or json file containing a valid json string, click the button "Process OH"

If text pasting submissin type is selected
[![N|Solid](https://github.com/cedest/Accelerex-Eat-In/blob/main/Accelerex.Web/Screenshots/Landing-Text.PNG)](#)
- Paste only a valid json string in the section provided, click the button "Process OH"

If the json string provided was well formatted, a valid, east to read open hour data is displayed
[![N|Solid](https://github.com/cedest/Accelerex-Eat-In/blob/main/Accelerex.Web/Screenshots/WithoutError.PNG)](#)

If error encountered is not syntatic, the API tries to provide a proper error notification at that exact location
[![N|Solid](https://github.com/cedest/Accelerex-Eat-In/blob/main/Accelerex.Web/Screenshots/WithError.PNG)](#)

## Tech Stack

The solutions use a number of open source projects to work properly:

- [C#] - the best mordern day programming language - no shades to JAVA!
- [HTML5] - HTML enhanced for web apps!
- [Twitter Bootstrap] - great UI boilerplate for modern web apps
- [jQuery] - duh
- [Github] - made reading this possible, isn't this awesome
- [Font Awesome] - great responsibe and flexible fonts

## Plugins

The solutions are currently extended with the following plugins.
Instructions on how to use them in your own application are linked below.

| Plugin | README |
| ------ | ------ |
| Newtonsoft.Json | [plugins/Newtonsoft.Json/README.md](https://github.com/JamesNK/Newtonsoft.Json/blob/master/README.md) |
| Polly | [plugins/Polly/README.md](https://github.com/App-vNext/Polly/blob/master/README.md) |

## Credits
The credit is mine.

## Answer to Question 2
Besides the fact that Json is the de-factor standard for modern client-to-API data communication, it is also lightweight, easily readable and is usually structured to match a data object. It is text-based open standard designed for human-readable data interchange. It is the best way to store this kind of data; especially when compared with XML that requires node parsing; which can be very expensive

repository: cedest/Accelerex-Eat-In

repo_name: cedest/Accelerex-Eat-In


text:
[![Build Status](https://travis-ci.com/dotslash/recent2.svg?branch=master)](https://travis-ci.com/dotslash/recent2)
[![codecov](https://codecov.io/gh/dotslash/recent2/branch/master/graph/badge.svg)](https://codecov.io/gh/dotslash/recent2)
[![PyPI version](https://badge.fury.io/py/recent2.svg)](https://badge.fury.io/py/recent2)
# Recent

Recent is a more structured way to log your bash history.

The standard `~/.bash_history` file is inadequate in many ways, its
worst fault is to by default log only 500 history entries, with no timestamp.
You can alter your bash `HISTFILESIZE` and `HISTTIMEFORMAT` variables but it
is still a unstructured format with limited querying ability.

Recent does the following.

1. Logs current localtime, command text, current pid, command return value,
   working directory to an sqlite database in `~/.recent.db`.
2. Logs history immediately, rather than at the close of the session.
3. Provides a command called `recent` for searching bash history.

## NOTE about [trengrj/recent](https://github.com/trengrj/recent)

`recent2` started off as a clone of [trengrj/recent](https://github.com/trengrj/recent).
I used [trengrj](https://github.com/trengrj)'s util for about a month and I really
liked it. However I saw some short comings in the tool. I made a clone because trengrj
has not been very responsive.

Most of the core logic is written by [trengrj](https://github.com/trengrj). I added
a lot of incremental patches for the things that interested me. I intend to actively
maintain this as I see more interesting use cases.

## Installation instructions

Install the recent2 pip package via pip (python 3)

`pip3 install recent2`

Add the following to your `.bashrc` or `.bash_profile`.

`export PROMPT_COMMAND='log-recent -r $? -c "$(HISTTIMEFORMAT= history 1)" -p $$'`

And start a new shell.

## Usage

See example usage at https://asciinema.org/a/271533

### Help Text

```sh
> recent -h
usage: recent [-h] [-n 20] [--status_num 0] [--successes_only]
              [--failures_only] [-w /folder] [--cur_session_only]
              [-d 2016-10-01] [--return_self] [--char_limit 200]
              [--env key[:val]] [--hide_time] [--debug] [--detail]
              [--columns COLUMNS] [-re] [-sql] [--nocase]
              [pattern]

recent is a convenient way to query bash history. Visit
https://github.com/dotslash/recent2 for more examples or to ask
questions or to report issues

positional arguments:
  pattern               optional pattern to search

optional arguments:
  -h, --help            show this help message and exit
  -n 20                 max results to return
  --status_num 0, -stn 0
                        int exit status of the commands to return. -1 =>
                        return all.
  --successes_only, -so
                        only return commands that exited with success
  --failures_only, -fo  only return commands that exited with failure
  -w /folder            working directory
  --cur_session_only, -cs
                        Returns commands only from current session
  -d 2016-10-01         date in YYYY-MM-DD, YYYY-MM, or YYYY format
  --return_self         Return `recent` commands also in the output
  --char_limit 200, -cl 200
                        Ignore commands longer than this.
  --env key[:val], -e key[:val]
                        Filter by shell env vars. Env vars set in
                        RECENT_ENV_VARS as comma separated list will be
                        captured.
  --hide_time, -ht      dont display time in command output
  --debug               Debug mode
  --detail              Return detailed output
  --columns COLUMNS     Comma separated columns to print if --detail is
                        passed. Valid columns are command_dt,command,pid,retur
                        n_val,pwd,session,json_data
  -re                   enable regex search pattern
  -sql                  enable sqlite search pattern
  --nocase, -nc         Ignore case when searching for patterns

To import bash history into recent db run recent-import-bash-history
```

Look at your current history using recent. Here are some examples on how to use recent.

 Query via regexp mode.
recent -re git.*commit
```

### Less basic usage

- Filter commands by exit status
  1. `recent git --successes_only` or `recent git -so`
  2. `recent git --failures_only` or `recent git -fo`
  3. `recent git --status_num 1` or `recent git -stn 1` returns only the git commands that have exit status 1.
- `recent git --return_self`. By default `recent` commands are not displayed in the output. Pass the `return_self` to change that.
- `recent git -w ~/code`. This returns only the commands that were executed with `~/code` as current working directory.
- Filter the commands by execution date by doing `recent git -d 2019` or `recent git -d 2019-10` or `recent git -d 2019-10-04`
- By default recent prints command timestamp and the command in the output. Use `recent git --hide_time` or `recent git -ht` to hide the command timestamp. This is useful when copy-pasting commands from output.
- Copy paste errors into the shell can result in random junk coming up
  in the bash history. While `-so` option mostly takes care of this,
  another way to tackle this is to not show commands that are longer
  than a given limit. The default is 200. If you want longer commands,
  then do `recent git --char_limit 10000` or `recent git -cl 10000`
### Usage via sqlite

It is possible directly interact with sqlite if all the above options have failed you. See the table schema below.

```sql
CREATE TABLE commands(
  command_dt timestamp,
  command text,
  pid int,
  return_val int,
  pwd text,
  session text);
CREATE INDEX command_dt_ind on commands (command_dt);
```

- option1: `recent -sql 'command like "%git%" and command not like "%commit%"'`
- option2: You can directly play around with sqlite `sqlite3 ~/.recent.db "select * from commands limit 10"`

### FAQs

**Q**: Can I have a custom location to store my history sqlite file?
**A**: Yes. Point RECENT_DB environment variable to your sqlite file.

**Q**: I want to have a custom PROMPT_COMMAND that calls log-recent using my own logic. How do I do that?
**A**: This is basically https://github.com/dotslash/recent2/issues/32. Set RECENT_CUSTOM_PROMPT environment variable
       to a non empty value.

## Dev installation instructions

```sh
git clone https://github.com/dotslash/recent2 && cd recent2
pip install -e .
```

license: MIT

branch_name: refs/heads/master

extension: md

gha_license_id: MIT

license_type: permissive


text:
# ![nf-core/ampliseq](docs/images/nfcore-ampliseq_logo.png)

[![Nextflow](https://img.shields.io/badge/nextflow-%E2%89%A519.10.0-brightgreen.svg)](https://www.nextflow.io/)
[![nf-core](https://img.shields.io/badge/nf--core-pipeline-brightgreen.svg)](https://nf-co.re/)
[![DOI](https://zenodo.org/badge/150448201.svg)](https://zenodo.org/badge/latestdoi/150448201)
[![Cite Preprint](https://img.shields.io/badge/Cite%20Us!-Cite%20Preprint-orange)](https://biorxiv.org/cgi/content/short/2<IP_ADDRESS>0468v1)

[![GitHub Actions CI Status](https://github.com/nf-core/ampliseq/workflows/nf-core%20CI/badge.svg)](https://github.com/nf-core/ampliseq/actions)
[![GitHub Actions Linting Status](https://github.com/nf-core/ampliseq/workflows/nf-core%20linting/badge.svg)](https://github.com/nf-core/ampliseq/actions)

[![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg)](http://bioconda.github.io/)
[![Docker](https://img.shields.io/docker/automated/nfcore/ampliseq.svg)](https://hub.docker.com/r/nfcore/ampliseq)
![Singularity Container available](https://img.shields.io/badge/singularity-available-7E4C74.svg)

[![Joins us on Slack](https://img.shields.io/badge/slack-nfcore/ampliseq-blue.svg)](https://nfcore.slack.com/channels/ampliseq)

## Introduction

**nfcore/ampliseq** is a bioinformatics analysis pipeline used for 16S rRNA amplicon sequencing data.

The workflow processes raw data from FastQ inputs ([FastQC](https://www.bioinformatics.babraham.ac.uk/projects/fastqc/)), trims primer sequences from the reads ([Cutadapt](https://journal.embnet.org/index.php/embnetjournal/article/view/200)), imports data into [QIIME2](https://www.nature.com/articles/s41587-019-0209-9), generates amplicon sequencing variants (ASV, [DADA2](https://www.nature.com/articles/nmeth.3869)), classifies features against the [SILVA](https://www.arb-silva.de/) [v132](https://www.arb-silva.de/documentation/release-132/) database, excludes unwanted taxa, produces absolute and relative feature/taxa count tables and plots, plots alpha rarefaction curves, computes alpha and beta diversity indices and plots thereof, and finally calls differentially abundant taxa ([ANCOM](https://www.ncbi.nlm.nih.gov/pubmed/26028277)). See the [output documentation](docs/output.md) for more details of the results.

The pipeline is built using [Nextflow](https://www.nextflow.io), a workflow tool to run tasks across multiple compute infrastructures in a very portable manner. It comes with docker / singularity containers making installation trivial and results highly reproducible.

### Documentation

The nf-core/ampliseq pipeline comes with documentation about the pipeline, found in the `docs/` directory:

1. [Installation](https://nf-co.re/usage/installation)
2. Pipeline configuration
    * [Local installation](https://nf-co.re/usage/installation)
    * [Adding your own system config](https://nf-co.re/usage/adding_own_config)
3. [Running the pipeline](docs/usage.md)
4. [Output and how to interpret the results](docs/output.md)
5. [Troubleshooting](https://nf-co.re/usage/troubleshooting)

### Credits

These scripts were originally written for use at the [Quantitative Biology Center (QBiC)](http://www.qbic.life) and [Microbial Ecology, Center for Applied Geosciences](http://www.uni-tuebingen.de/de/104325), part of Eberhard Karls Universität Tübingen (Germany) by Daniel Straub ([@d4straub](https://github.com/d4straub)) and Alexander Peltzer ([@apeltzer](https://github.com/apeltzer)).

## Citation

If you use nf-core/ampliseq for your analysis, please cite it using the following DOI:

[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3568091.svg)](https://doi.org/10.5281/zenodo.3568091)

The pre-print can be cited as follows:

[![DOI](https://img.shields.io/badge/-Cite%20Preprint-orange)](https://www.biorxiv.org/content/10.1101/2<IP_ADDRESS>0468v1)

You can cite the `nf-core` pre-print as follows:

> Ewels PA, Peltzer A, Fillinger S, Alneberg JA, Patel H, Wilm A, Garcia MU, Di Tommaso P, Nahnsen S. **nf-core: Community curated bioinformatics pipelines**. *bioRxiv*. 2019. p. 610741. [doi: 10.1101/610741](https://www.biorxiv.org/content/10.1101/610741v2).

repository: DiegoBrambilla/ampliseq

gha_language: Nextflow

repo_name: DiegoBrambilla/ampliseq


text:
---
layout: post
title:      "Flow of fetch in Rails&JS Project to view Index content"
date:       2019-10-11 10:28:36 -0400
permalink:  flow_of_fetch_in_rails_and_js_project_to_view_index_content
---

First thing we need to make sure that our backend is set up and our routes and associations connected.

In this walkthrough we create Lesson resource using:

```
rails g resource Lesson title:string content:string comment_id:integer
```

Comment:

```
rails g resource Comment text:string
```

Rating:

```
rails g resource Rating integer:stars lesson_id:integer
```

After that we run:

```
rake db:migrate
```

to create shema that would look like this:

```
ActiveRecord::Schema.define(version: 2019_10_08_091954) do

  create_table "comments", force: :cascade do |t|
    t.string "text"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  create_table "lessons", force: :cascade do |t|
    t.string "title"
    t.string "content"
    t.integer "comment_id"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  create_table "ratings", force: :cascade do |t|
    t.integer "stars"
    t.integer "lesson_id"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end
end

```

Associations in models look like this:

```
class Comment < ApplicationRecord
    has_many :lessons
end

class Lesson < ApplicationRecord
    belongs_to :comment
    has_many :ratings
end

class Rating < ApplicationRecord
    belongs_to :lesson
end

```

Then we go to our Lesson controller and add:

```
    def index
        @lessons = Lesson.all
        respond_to do |f|
          f.html
          f.json {render json: @lessons}
        end
    end

```

With this we get a json representation of all Lessons (render) and allow access to html and json data. The way we check the return value would be by running:

```
http://localhost:3000/lessons.json
```

That would return an ARRAY of OBJECTS (lessons we created before). Every object we get back will be an instance of a Lesson with each having its own attributes like title, content, comment and ratings (plural- has_many).

One thing to be aware is that other actions like New, Create, private lesson_params are added correctly in the same controller.

To finish up the backend part we need to add

```
gem 'active_model_serializers'
```

to our gemfile and bundle install.

To create serializer folder to work with run:

```
rails g serializer Lesson
```

After that is done we add attributes we want to work with and see in json plus we add associations to the Lesson serializer:

```
class LessonSerializer < ActiveModel::Serializer
  attributes :id, :title, :content,:comment_id

  belongs_to :comment
  has_many :ratings
end

```

The reason why we are adding associations here are the same as why we are adding same ones in Rails model, to be able to use build-in methods and get access to associated data.

**Now for the frontend part.
**

The behaviour we want is that whenever we click on our Index link on the homepage we don't open a new page with all lessons but we want to repaint the DOM using Ajax fetch.

We do this by "hijacking" CLICK on a link that we added to our homepage. To do that we add a html link that displays all lessons(index link), that is essentially same as we have for Rails index:

```
        <%= link_to 'All Lessons', lessons_path, class: "all_lessons" %>
```

- VERY IMPORTANT : add a class to the link and remember the name of the class. We will use that class in JS section.

Now we create our JS file where we do all of the magic:

```
assets/javascripts/lessons.js
```

In our .js file first we make a document ready function:

```
$(() => {
    clickHandlers();
})

```

The ready() method is used to make a function available after the document is loaded. Whatever code you write inside the $(document ).ready() method will run once the page DOM is ready to execute JavaScript code.

Then we define our clickHandlers function:

```
const clickHandlers = () => {
    $('.all_lessons').on('click', e => {
        e.preventDefault()
        getLessons()
    })

```

Now comes the important part. Using jQuery we are selecting that particular element with a class "all_lessons" that we created before.

.on method in jQuery takes two arguments, event we want to listen for and callback function we want to run  when that event happens (takes in event object „e“).

Using

```
e.preventDefault()
```

we prevent default when that link is clicked (meaning default will render via rails html markup).
On the last line we simply call getLessons() when our link is clicked.

For us to call that function we need to declare it:

```
  const getLessons = () => {
    fetch(`/lessons.json`)
      .then(res => res.json())
      .then(lessons => {
         lessons.forEach(lesson => {
           let newLesson = new Lesson(lesson)

           let lessonHtml = newLesson.formatIndex()

           $('#app-container').append(lessonHtml)
         })
      })
  }

```

Here we use

```
fetch(`/lessons.json`)
```

to get lessons (backend API endpoint) as a response object(res).

Using

```
.then(res => res.json
```

we convert that data to ARRAY of OBJECTS and with the line

```
.then(lessons..
```

we have lessons as a manipulatable  Array we can work with.

Since lessons are now an array we can iterate and get individual object in array:

```
         lessons.forEach(lesson => {
```

Here on every iteration we create a new instance depending on how many lesson objects we have in our lessons array.

BUT!

We can't create a new instance without a constructor that will allow us to use line like this:

```
           let newLesson = new Lesson(lesson)
```

So!

Let's create our Lesson constructor:

```
  function Lesson(lesson) {
    this.id = lesson.id
    this.title = lesson.title
    this.content = lesson.content
    this.user = lesson.user
    this.comment = lesson.comment
    this.ratings = lesson.ratings
  };

```

This works in the same way as Class in Ruby meaning it takes an argument and assigns attributes from the argument to the instance being created.

So now every instance of a lesson we created from our json array has its own id,title etc..

Now this works:

```
           let newLesson = new Lesson(lesson)
```

Next line

```
           let lessonHtml = newLesson.formatIndex()
```

tells us that we are calling a

```
.formatIndex()
```

function on our instance we created (newLesson).

Meaning we have to create Lesson „class“ method, in JS it is a prototype function:

```
  Lesson.prototype.formatIndex = function(){
    let postRatings = this.ratings.map(rating => {
      return (`
      *${rating.stars}
      `)
    })

    let lessonHtml = `
    <p>Lesson title:</p>
    <p>${this.title}</p>
    <p>Lesson content: </p>
    <p>${this.content}</p>
    <p>Lesson comment: </p>
    <p>${this.comment.text}</p>
    <p>Lesson Ratings: </p>
    <p>${postRatings}</p>
    `
    return lessonHtml
  };

```

Function is called formatIndex. As the name implies it formats the Index page. Simply it just creates new html elements that we will use to put on our lesson data on the page.

Now we go back to this line

```
           let lessonHtml = newLesson.formatIndex()
```

that adds all this html and connects it to the newLesson object so now we can use „this“ and give that html data like id, content, comment etc..

Last part is

```
           $('#app-container').append(lessonHtml)
```

Here we add all that html with object data to a specific part on the dom. I use id #app-container.

To summarise what happens overall:

User clicks the index link on homepage:

```
        <%= link_to 'All Lessons', lessons_path, class: "all_lessons" %>
```

After clicking function getLessons() runs and it repaints the dom with our new html on a location we choose.

```
        <p id="app-container"></p>
```

The End

:)

extension: markdown


text:
# Project: Finding lane lines on the road

## Table of contents
1. [Overview](#Overview)
2. [Pipeline of the lane detection](#Pipeline-of-the-lane-detection)
3. [Detailed description of the pipeline](#Detailed-description-of-the-pipeline)
4. [Shortcomings of the approach](#Shortcomings-of-the-approach)
5. [Improvements for this pipeline](#Improvements-for-this-pipeline)

Overview
---
The aim of this project is to find the lane lines on the road for a self driving car.

Pipeline of the lane detection
---
The image processing pipeline to find the lines involves following steps
* Input is an 3-channel color image (an image or a frame of the video). This is our `original image`
* Conversion from `original image` to `grayscale image`
* Blurring the `grayscale image` using _Gaussian Filter_ to obtain `blurred image`
* Applying _Canny edge detection_ for the `blurred image` to obtain the `edge image`
* Selecting suitable region of interest in this `edge image`. Output of this stage is `roi image`
* Use of _hough lines_ algorithm to find lines. Input is `roi image` and output is `line image` and the `line segments`
* With the `line segments` left and right lines are identified and extrapolated them to fill the entire line
* Finally this `extrapolated lines` are superimposed on the `original image` to obtain `final output image`

Detailed description of the pipeline
---

#### Step1: Original Image

#### Step2: Grayscale Image

In this step original image is converted to grayscale image using the helper function.

#### Step3: Blurring

In this step, grayscale image is blurred using gaussian blur helper function. `Kernel size` value is chosen as `7`. In order to obtain the output for challenge.mp4 video, if in the previous frame if the lane is not identified then in the current frame gaussian blur step is skipped.

#### Step4: Edge Detection

In this step, blurred image is passed on to canny edge detector. `Lower threshold` and `Upper threshold` is chosen to be `80` and `240` respectively. In order to obtain the output for challenge.mp4 video, if in the previous frame if the lane is not identified then in the current frame the threshold values are chosen to be `40` and `160`.

#### Step5: ROI Selection

In this step Region of Interest is selected in a trapezoidal form with `vertices`: `(0.4*width, 0.56*height)`, `[0.15*width, height]`, `[0.95*width, height]` and `[0.6*width, 0.56*height]`.

#### Step6: Line Detection

In this step, lines are detected using hough line detection alogorithm. The helper function is modified to return both line segments and the line image. Parameters used for the detection are: `rho = 1`, `theta = pi /180`, `threshold = 10`, `min_line_len = 15` and `max_line_gap = 5`.

#### Step7: Identify left and right lines

In this step left and right lines are identified separately. Lines are identified based on the slope values. Line is identified as right line if the value of the slope lies between `sin(30)` and `sin(60)` and as left line if the value of the slope lies between `cos(120)` and `cos(150)`. The angle values 30, 60, 120 and 150 are selected because the line orientation from the camera view angle will be in this range. This assumes there will not be any horizontal and vertical line markings.

After identifying the left and right line, a new pair of x and y coordinate is found for each line to draw a line segment. To do this `2-point form` of the straight line is used.
From the hough lines there will be more than one line segment for each left and right lane. So y coordinate value is fixed and x coordinate value is found out for all the lines and the x coordinate value is averaged to get the new x coordinate. This procedure is repeated for other end point and other lane. This will result in 2 points for each line.

#### Step 8: Superimpose the lines on to the original image

From the points obtained in the previous step, 2 lines are drawn using `draw_lines` function. The resulting line image and the original image is fed into `weighted_img` function to obtain the final output image

Shortcomings of the approach
---
* Illumination changes - The parameter values are fine tuned for the images and videos that provided in the test set. It will not work in most cases such as a bright sunny day and the sunlight is directly coming onto the camera, night time where there are street lights and no street lights.
* Different weather conditions such as rainy and snow. In this situation camera cannot see the lane markings, so this pipeline may not work.
* If there is discontinuation in the lane painted on the road, that part of the frames cannot identify the lane markings.
* Horizontal lanes such as STOP line cannot be detected because of the filtering of the lines with the slope values. Currently I have used +- 30 to +- 60 degrees to the horizontal in my code.

Improvements for this pipeline
---
* Adaptive parameter tuning for the Gaussian filter, Canny edge detection and Hough lines based on the illumination changes.
* Prediction of the line segments using the history information when camera cannot find line segments in certain number of frames.


text:
---
templateKey: event
eventKey: Lost Shepherd Fell Race
venueForeignKey: Shoulder of Mutton Inn
championshipForeignKey: 2023 Summer Championship
eventType: Race
terrain: Fell
startsAt: '2023-09-10 10:30'
---
This is the eighth race in our [2023 Summer Championship](/championships/2023-summer-championship/).

The longest race on our Summer Championship this year is this challenging 24km fell race over open moor and footpaths.
It includes 820m of ascent and although the route is partially flagged, some navigational skills will be helpful.

**PLEASE SEE THE RACE WEBSITE FOR DETAILS ON REQUIRED KIT.**

If you are new to Fell Running here is a link which explains some of the basics: [https://www.fellrunner.org.uk/faq/frequently-asked-questions](https://www.fellrunner.org.uk/faq/frequently-asked-questions)

£10 pre-entry or £10 on the day. Enter at: [https://craggrunner.com/lost-shepherd-fell-race/](https://craggrunner.com/lost-shepherd-fell-race/)

gha_language: JavaScript


text:
# InstaLV ❤

A PHP script + webapp that allows you to go live on Instagram with any streaming program that supports RTMP!

Built with [mgp25's amazing Instagram Private API Wrapper for PHP](https://github.com/mgp25/Instagram-API/).

**InstaLV** is a fork of [JRoy/InstagramLive-PHP](https://github.com/JRoy/InstagramLive-PHP).

## Features

* A webapp to easily control livestream
* See livestream viewers
* See likes & comments during livestream
* Call custom callbacks when a user like or comment

## Setup

* Install PHP
* [Install Composer](https://getcomposer.org/download/)
* Download the [latest release](https://github.com/subins2000/InstaLV/releases) or clone this repo
* Run ```composer install``` in the cloned folder
* Edit the username and password inside `config.php` with your Instagram username and password
* Run the `live.php` script :
    ```bash
    php live.php
    ```
* On another terminal, run the server :
    ```bash
    php -S localhost:8000 server.php
    ```
  You can also simply execute the `run_server.sh` or `run_server.bat` (Windows) which will run the above command.
* Open the URL [`http://localhost:8000`](http://localhost:8000) in a browser.
* In the InstaLV webpage, click on the button `Stream Key/URL`. Copy the Stream-URL and Stream-Key and paste them into your streaming software. [See OBS-Setup](#obs-setup)

## OBS-Setup

* Go to the "Stream" section of your OBS Settings
* Set "Stream Type" to "Custom Streaming Server"
* Set the "URL" field to the stream url you got from the script
* Set the "Stream key" field to the stream key you got from the script
* Make Sure "Use Authentication" is **unchecked** and press "OK"
* Start Streaming in OBS
* To stop streaming, run the "stop" command in your terminal and then press "Stop Streaming" in OBS
* Note: To emulate the exact content being sent to Instagram, set your OBS canvas size to 720x1280. This can be done by going to Settings->Video and editing Base Canvas Resolution to "720x1280".

## FAQ

#### OBS gives a "Failed to connect" error

This is mostly due to an invalid stream key: The stream key changes **every** time you start a new stream so it must be replaced in OBS every time.

#### I've stopped streaming but Instagram still shows me as live

This is due to you not running the "stop" command inside the script. You cannot just close the command window to make Instagram stop streaming, you must run the stop command in the script. If you *do* close the command window however, start it again and just run the stop command, this should stop Instagram from listing to live content.

#### I get an error inside of Instagram when archiving my story

This is usually due to archiving a stream that had no content (video). Just delete the archive and be go on with your day.

# Donate

If you have found this software useful, [Please Donate](https://subinsb.com/donate)

repository: Lesliesibbs/LiveInstagramLocalhosts

repo_name: Lesliesibbs/LiveInstagramLocalhosts


text:
# micro_orchestra
## Test for 3 microservices communicating

3 docker microservices communication throught a redis docker instance.

Using my own library redis_connector

Each of the microservices will be able to process its own messages, and will be connecting to the list of channels.
Each message will be processed only once using the redis lock feature.
So you can scalate up any of the microservices without worring about the concurrence.

eg:
docker-compose up --scale final_box=3 processor_box=2


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

### Description

Google Monorail before 2018-06-07 has a Cross-Site Search (XS-Search) vulnerability because CSV downloads are affected by CSRF, and calculations of download times (for requests with a crafted groupby value) can be used to obtain sensitive information about the content of bug reports.

### POC

#### Reference
- https://medium.com/@luanherrera/xs-searching-googles-bug-tracker-to-find-out-vulnerable-source-code-50d8135b7549
- https://www.reddit.com/r/netsec/comments/9yiidf/xssearching_googles_bug_tracker_to_find_out/ea2i7wz/

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

repository: trickest/cve

branch_name: refs/heads/main

gha_language: HTML

repo_name: trickest/cve


text:
# monkey-cli

Ethereum utility to generate random transactions that aids in testing.

## Usage

### Step 1

Deploy ERC20 sample token contract

```sh
$ yarn monkey deploy
```

### Step 2

Check if contract is deployed and get contract address:

```sh
# yarn monkey txdetail <txhash>
$ yarn monkey txdetail 0xe17c0b51510dac4aa8f06f51db040d5e9f0c5af4371b875cdd8d964ee34fc554
```

### step 3

Start generating random txs:

```sh
# yarn monkey start <contractaddress>
$ yarn monkey start 0xee24211fe08d46419e3bdf2d910e0b23fe5302f2
```

repository: alant/ethvm

repo_name: alant/ethvm


text:
# VSTesting

##### Unit tests to for rocket related calculations built with Visual Studio MVC, C#, and .NET.  04/20/18

## By Sara Hamilton, Joel Adams, Nico Daunt, and Kayla Ondracek

# Description
This is an Epicodus practice project for week 2 of the .NET course.  Its purpose is to display understanding of Testing in Visual Studio.

## Technologies Used
* Visual Studio
* C#
* .NET

## Run the Application

  * _Clone the github respository_
  ```
  $ git clone https://github.com/Sara-Hamilton/VSTesting
  ```
* _Open project solution in Visual Studio_

*  _Restore the program_

 ```
 $ dotnet restore
 ```
 * _Open project solution in Visual Studio_
*  _Run the tests_

### License

*MIT License*

Copyright (c) 2018 **_Sara Hamilton, Joel Adams, Nico Daunt, and Kayla Ondracek_**

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

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

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

repository: Sara-Hamilton/VSTesting

repo_name: Sara-Hamilton/VSTesting


text:
# ursa_key_utils

Standalone Key Generator for `Iroha` [Accounts](https://iroha.readthedocs.io/en/latest/concepts_architecture/glossary.html#account)
and [Peers](https://iroha.readthedocs.io/en/latest/concepts_architecture/glossary.html#peer).

## Usage

### Standalone

Download binary or build with `cargo build --release`.

```bash
ursa_key_utils 0.1
Soramitsu
ursa_key_utils is a command line arguments wrapper around `Ursa`.

USAGE:
    ursa_key_utils [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
        --secret <secret_key>    Sets a secret key. Should be used separately from `seed`.
        --seed <seed>            Sets a seed for random number generator. Should be used separately from `secret`.
```

## Functionality

- [ ] Generate keys for `Ed25519` using [Hyperledger Ursa](https://github.com/hyperledger/ursa).

## Use cases

- Standalone key generator for nodes and peers.
- As a library inside `Iroha 2`:
  - generate `peers` IDs when default hasn't been provided.

## Concerns

### Strong Random Number Generator

>> One thing to keep in mind is that when generating keys, they need to be done using a cryptographically secure random number generator.

`Ursa` provides an ability to generate pseudo random numbers via [BigNumber::rand](https://docs.rs/ursa/0.3.2/ursa/bn/struct.BigNumber.html#method.rand) which internally is [OpenSSL BigNumRef::rand](https://docs.rs/openssl/0.10.28/openssl/bn/struct.BigNumRef.html#method.rand).


text:
---
layout: post
title: "OsNADH-GOGAT2"
description: ""
category: genes
tags: [spikelet number, yield, spikelet, panicle, sheath, biomass, leaf]
---

* **Information**
    + Symbol: OsNADH-GOGAT2
    + MSU: [LOC_Os05g48200](http://rice.uga.edu/cgi-bin/ORF_infopage.cgi?orf=LOC_Os05g48200)
    + RAPdb: [Os05g0555600](https://rapdb.dna.affrc.go.jp/locus/?name=Os05g0555600)

* **Publication**
    + [Disruption of a Novel NADH-Glutamate Synthase2 Gene Caused Marked Reduction in Spikelet Number of Rice](http://www.ncbi.nlm.nih.gov/pubmed?term=Disruption of a Novel NADH-Glutamate Synthase2 Gene Caused Marked Reduction in Spikelet Number of Rice%5BTitle%5D), 2011, Front Plant Sci.

* **Genbank accession number**
    + [AB274818](http://www.ncbi.nlm.nih.gov/nuccore/AB274818)

* **Key message**
    + In rice grown under paddy field conditions, disruption of the OsNADH-GOGAT2 gene caused a remarkable decrease in spikelet number per panicle associated with a reductions in yield and whole plant biomass, when compared with wild-type (WT) plants
    + OsNADH-GOGAT2, a newly identified gene, was expressed mainly in fully expanded leaf blades and leaf sheaths

* **Connection**

[//]: # * **Key figures**


text:
---
title: Deployment with Wercker
linktitle: Deployment with Wercker
description: You can use a free tool called Wercker to automate deployments between your GitHub-hosted source and final website on GitHub pages.
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
categories: [hosting and deployment]
keywords: [wercker,deployment,github,git]
authors: [Arjen Schwarz, Samuel Debruyn]
menu:
  docs:
    parent: "hosting-and-deployment"
    weight: 60
weight: 60
sections_weight: 60
draft: false
aliases: [/tutorials/automated-deployments/]
toc: true
wip: false
notesforauthors:
---

## Goals

By the end of this guide, you will have completed the following:

* Creating a basic Hugo project and website
* Version controlling your project with Git
* Adding your project to GitHub
* Automating site deployments with a free tool called Wercker
* Deploying your website to GitHub Pages for free hosting

## Assumptions

1. You have a working familiarity with using Git for version control
2. You have a GitHub account
3. You have already created a basic Hugo project

If you do not meet these assumptions, the [GitHub help section][githubhelp] has an explanation of how to install and use git. [Signing up for a GitHub][ghsignup] account is free as well. If you are completely unfamiliar with creating a new Hugo website, visit the [Hugo Quick Start][quickstart].

## Create a Basic Hugo Site

{{% note "This Guide Uses the Hugo CLI" %}}
All the work for setting up a Hugo project and using this guide is done via the Hugo CLI's most basic commands. See the [command line reference page](/commands/) for a more exhaustive account of the CLI's features.
{{% /note %}}

First, create your new Hugo website using the [`hugo new site` command][basicusage] and change into the newly created directory for the project. In this guide, we are calling our new project `hugo-wercker-example`:

{{< code file="hugo-new-site.sh" >}}
hugo new site hugo-wercker-example
cd hugo-wercker-example
{{< /code >}}

We will use the [Herring Cove theme][] by first cloning the theme into the `themes` directory.

{{< code file="clone-herring-cove-theme.sh" >}}
cd themes
git clone https://github.com/spf13/herring-cove.git
{{< /code >}}

Cloning the project from the command line will conflict with our own version control. So, we need to remove the external git configuration that came with the clone of Herring Cove:

{{< code file="remove-herring-cove-git.sh" >}}
rm -rf herring-cove/.git
{{< /code >}}

We need content for Hugo to build. Let's add a quick `/about` page:

```
hugo new about.md
```

{{% note %}}
The preceding example for the about page leverages archetypes to scaffold a new content file with preconfigured front matter. [Find out more about Hugo's archetypes](/content-management/archetypes/).
{{% /note %}}

Now you can edit `contents/about.md` in your text editor of choice, but this is not necessary for the purposes of this guide. Running the following command will build your Hugo site into the `public` directory.

Once the website is build, it's a good idea to run the following command to start a local server and ensure you're changes have been implemented:

```
hugo server --theme=herring-cove
```

If everything is fine, you should see something similar to the image below when you go to <http://localhost:1313> in your browser.

![][1]

## Set up Version Control in Git

Adding Git to your project is done by running the `git init` command from the root directory of your project.

```
git init
```

Running `git status` at this point will show you the following entries: the `config.toml` file, the `themes` directory, the `contents` directory, and the `public` directory. However, we don't want the `public` directory version controlled because Wercker is responsible for generating the finished website later on. Therefore, we'll add a `.gitignore` file to our project that will exclude the `/public` directory from being tracked by Git:

{{< code file="gitignore.sh" >}}
echo "/public" >> .gitignore
{{< /code >}}

Wercker might complain when we try to build the site later on because we currently do not have any static files outside of the `themes` directory. We simply have to add *any* file to the static folder to prevent Wercker from complaining. To keep this guide simple, let's add a `robots.txt`. The following command creates the file in `/static`. The contents of the `robots.txt` lets search engines know they have full access to crawl the published website:

{{< code file="addrobotstxt.sh" >}}
echo "User-agent: *\nDisallow:" > static/robots.txt
{{< /code >}}

Now we need to add (i.e., [stage [see Git documentation]][gitbasics]) and commit all of our changes in the repository into Git:

```
git commit -a -m "Initial commit"
```

## Add the Project to GitHub

Now we need to create a new repository on GitHub. Once you are signed in to GitHub, you can add a new repository by clicking on the **+▼** dropdown at the top right or by going to [https://github.com/new](https://github.com)..

We then choose a name for the project (`hugo-wercker-example`). When clicking on create repository GitHub displays the commands for adding an existing project to the site. The commands shown below are the ones used for this site, if you're following along you will need to use the ones shown by GitHub. Once we've run those commands the project is in GitHub and we can move on to setting up the Wercker configuration. Be sure to replace `YourUserName` with your GitHub account/username:

{{< code file="setup-gh-repo.sh" >}}
git remote add origin git@github.com:YourUsername/hugo-wercker-example.git
git push -u origin master
{{< /code >}}

![][2]

## Set Up Wercker

To sign up for a free Wercker account, go to <https://www.wercker.com> and click the **Sign Up** button on the top right of the home screen.

![][3]

### Register for Wercker with Your GitHub Account

Sign up for Wercker using your GitHub credentials. If you don't have a GitHub account, or don't want to use it for your account, you have the option to register with a username and password as well. However, the second half of this guide---devoted to hosting your website on GitHub pages---will no longer be of interest to you.

![][4]

### Connect GitHub or Bitbucket

After you are registered, you will need to link your GitHub or Bitbucket account to Wercker. You can link your account by navigating to your profile settings and then selecting "Git connections."

![][17]

If you registered for Wercker using GitHub, it will most likely look like the following image. To connect a missing service, click the **Connect** button, which may send you to either GitHub or Bitbucket to sign into your respective account.

![][5]

### Add Your Project

Now that we've got all the preliminaries out of the way, it's time to set up our application. For this we click on the **+ Create** button next to Applications and choose GitHub as our provider.

![][6]

### Select a Repository

When selecting GitHub, Wercker will show all your GitHub repositories. You have the option to filter repositories using the search input at the top of the repositories list. Once you have your repository selected, click the **Use selected repo** button.

![][7]

### Select the Repository Owner

In the next step, Wercker asks you to select the repository owner. Select your GitHub account and continue.

![][8]

### Configure Access

{{% note %}}
This guide assumes you are using a public GitHub repository and understand that the [published GitHub Pages website will be available to everyone](https://help.github.com/articles/what-is-github-pages/#usage-limits).
{{%/note %}}

This step can be slightly tricky. Wercker does not have privileges to check out your private projects by default and therefore needs your permission to add a deploy key to your repository. By selecting the first option, you're simply allowing Wercker to check out the code via the same methods available to anyone visiting the project on GitHub.

![][9]

### Wercker.yml

Wercker will now attempt to create an initial `wercker.yml` file for you. More specifically, it will create a code block within the Wercker interface that you can copy to your finished file. Wercker gives us a `debian` box because our project does not have any special requirements.

Now we need to create a *wercker.yml* file in the root of our project. This file will contain our Wercker app's configuration. After we finish setting up our app, we will expand the contents of this file to build and deploy our website.

![][10]

### Public or Private

This is a personal choice. You can make an app public so that everyone can see more details about it. Keeping it private or public does not provide any overt benefits for you as the creator of the app. That said, [the app we are currently creating has been made public][publicappurl] to facilitate easier usage of this hosting and deployment guide.

![][11]

#### App Successfully Created

The application is now added and Wercker will offer you the chance to trigger a build. However, we will decline the offer because we haven't yet pushed our `wercker.yml` file to our GitHub repository.

![][12]

### Add the Hugo-build Step

Now we need to add the Wercker steps to our build process. First, we go to the "Registry" action in the top menu. When in the registry, we can search for "hugo build". Select the "Hugo-Build by **arjen**" step.

![][13]

### Use the Hugo-build Step

A summary of very basic usage is available at the top of the details for the Hugo-Build step. Below the basic usage is the contents of the `README.md` file associated with the step's repository. `README.md`'s on Wercker usually contain more details about the advanced options and examples of usage.

We're not going to use any of the advanced features of Hugo-Build in this guide. Let's return to our project and add the first section of details we need to our `wercker.yml`.

{{% warning "Hugo Version in `wercker.yml`" %}}
The docs are a work in progress. As such, the `version` represented in this guide may not represent the version you've been using for local development. Be sure to use the appropriate Hugo version for your build step.
{{% /warning %}}

{{< code file="wercker-build-step.yml" >}}
box: debian
build:
  steps:
    - arjen/hugo-build:
        version: "0.17"
        theme: herring-cove
        flags: --buildDrafts=true
{{< /code >}}

We can conclude this first step by pushing our `wercker.yml` to our GitHub repository and then seeing the magic at work within Wercker's interface.

{{< code file="push-wecker-to-gh.sh" >}}
git commit -a -m "Add wercker.yml"
git push origin master
{{< /code >}}

If completed and successful, a green check mark should appear in the commit column of your first build. However, this is only the build step. We still need to deploy the website to our free hosting on GitHub Pages. If you would like more details about the build, you can click the commit hash.

![][14]

### Add a GitHub Pages Deploy Step to `wercker.yml`

In order to deploy to GitHub Pages, we need to add a deploy step to our `wercker.yml`. We are going to add `lukevevier/gh-pages`, the most popular GitHub Pages step in the Wercker Steps repository. Additionally, we need to ensure the box Wercker uses for our deployments has git and ssh installed. We can do this using the `install-packages` command. Here is our *final* `wercker.yml` file:

{{< code file="wercker.yml" >}}
box: debian
build:
  steps:
    - arjen/hugo-build:
        version: "0.17"
        theme: herring-cove
        flags: --buildDrafts=true
deploy:
  steps:
    - install-packages:
        packages: git ssh-client
    -<EMAIL_ADDRESS>        token: $GIT_TOKEN
        domain: hugo-wercker.ig.nore.me
        basedir: public
{{< /code >}}

### How does the GitHub Pages Configuration Work?

We've provided a some important information in our `wercker.yml`. First, we've added the domain we want to use for our published website. Configuring the domain here will ensure that GitHub Pages is aware of the domain we want to use.

Secondly, we've configured the `basedir` to `public`. This is the directory that will be used as the website on GitHub Pages. `public` is also the default publishing directory in Hugo. (For more information, see [hugo's configuration docs][hugoconfig]).

Lastly, you'll notice a `$GIT_TOKEN` variable. This is used for pushing our changes to GitHub. We will need to configure this token before Wercker can build our website.

### Set the App's Deploy Target

We can set our deploy target by going to our app's settings and clicking on **Deploy targets**. Now select **Add deploy target** and then **Custom deploy**.

![][15]

### Configure the Deploy Step in Wercker

The next screen requires you fill in the deploy target name.

1. Make sure you enable **auto deploy** from the **master** branch.
2. Add a variable for the **GIT_TOKEN**. You'll need to create an access token in GitHub. Follow the directions in [GitHub help][accesstokenghhelp].
3. With the deploy step configured in Wercker, we can push the updated wercker.yml file to GitHub and it will create the GitHub pages site for us.

The website described in this guide is available at <http://hugo-wercker.ig.nore.me>.

![][16]

## Conclusion

Once this workflow is established, you can update your website automatically by pushing any content changes to your GitHub repository.

### Code for the Wercker Deployment Guide

[The source code for the site used in this guide is available on GitHub][guidesource], as is the [Wercker Hugo Build step][guidestep].

[1]: /images/hosting-and-deployment/deployment-with-wercker/creating-a-basic-hugo-site.png
[2]: /images/hosting-and-deployment/deployment-with-wercker/adding-the-project-to-github.png
[3]: /images/hosting-and-deployment/deployment-with-wercker/wercker-sign-up.png
[4]: /images/hosting-and-deployment/deployment-with-wercker/wercker-sign-up-page.png
[5]: /images/hosting-and-deployment/deployment-with-wercker/wercker-git-connections.png
[6]: /images/hosting-and-deployment/deployment-with-wercker/wercker-add-app.png
[7]: /images/hosting-and-deployment/deployment-with-wercker/wercker-select-repository.png
[8]: /images/hosting-and-deployment/deployment-with-wercker/wercker-select-owner.png
[9]: /images/hosting-and-deployment/deployment-with-wercker/wercker-access.png
[10]: /images/hosting-and-deployment/deployment-with-wercker/werckeryml.png
[11]: /images/hosting-and-deployment/deployment-with-wercker/public-or-not.png
[12]: /images/hosting-and-deployment/deployment-with-wercker/and-we-ve-got-an-app.png
[13]: /images/hosting-and-deployment/deployment-with-wercker/wercker-search.png
[14]: /images/hosting-and-deployment/deployment-with-wercker/using-hugo-build.png
[15]: /images/hosting-and-deployment/deployment-with-wercker/adding-a-github-pages-step.png
[16]: /images/hosting-and-deployment/deployment-with-wercker/configure-the-deploy-step.png
[17]: /images/hosting-and-deployment/deployment-with-wercker/wercker-account-settings.png

[accesstokenghhelp]: https://help.github.com/articles/creating-an-access-token-for-command-line-use/
[basicusage]: /getting-started/usage/
[ghsignup]: https://github.com/join
[gitbasics]: https://git-scm.com/book/en/v2/Getting-Started-Git-Basics
[githubhelp]: https://help.github.com/articles/set-up-git/
[guidesource]: https://github.com/ArjenSchwarz/hugo-wercker-example
[guidestep]: https://github.com/ArjenSchwarz/wercker-step-hugo-build
[Herring Cove theme]: https://github.com/spf13/herring-cove
[hugoconfig]: /getting-started/configuration/
[publicappurl]: https://app.wercker.com/#applications/5586dcbdaf7de9c51b02b0d5
[quickstart]: /getting-started/quick-start/

repository: SchumacherFM/hugo

gha_language: Go

repo_name: SchumacherFM/hugo


text:
---
title: Apache Karaf Tutorial Part 9 - Annotation based blueprint and JPA
---

Shows how to create a small application with a model, persistence layer and UI just with CDI annotations running as blueprint.

## blueprint-maven-plugin

Writing blueprint xml is quite verbose and large blueprint xmls are difficult to keep in sync with code changes and especially refactorings. So many people prefer to do most declarations using annoations. Ideally these annotations should be standardized so it is clearly defined what they do. The aries maven-blueprint-plugin allows to configure blueprint using annotations. It scans one or more paths for annotated classes and creates a blueprint.xml in target/generated-resources. See aries documentation of the maven-blueprint-plugin.

Example tasklist-blueprint-cdi
This example shows how to create a small application with a model, persistence layer and UI completely without handwritten blueprint xml.

You can find the full source code on github Karaf-Tutorial/tasklist-cdi-blueprint

## Structure

* features
* model
* persistence
* ui

## Creating the bundles

The bundles are created using the maven bundle plugin. The plugin is only used in the parent project and uses `<_include>osgi.bnd</_include>` to extract the OSGi configs into a separate file. So each bundle project just needs a osgi.bnd file which is empty by default and can contain additional configs.

As bnd figures out most settings automatically the osgi.bnd file are typically very small.

## Features

Defines the karaf features to install the example as well as all necessary dependencies.

## Model

The model project defines Task as a jpa entity and the Service TaskService as an interface. As model does not do any dependency injection the blueprint-maven-plugin is not involved here.

```
@Entity
public class Task {
    @Id
    Integer id;
    String title;
    String description;
    Date dueDate;
    boolean finished;
    // Getters and setters omitted
}

public interface TaskService {
    Task getTask(Integer id);
    void addTask(Task task);
    void updateTask(Task task);
    void deleteTask(Integer id);
    Collection<Task> getTasks();
}
```

```
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

    <persistence-unit name="tasklist" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>osgi:service/tasklist</jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        </properties>
    </persistence-unit>

</persistence>
```

Persistence.xml defines the persistence unit name as "tasklist" and to use JTA transactions. The jta-data-source points to the jndi name of the DataSource service named "tasklist". So apart from the JTA DataSource name it is a normal hibernate 4.3 style persistence definition with automatic schema creation.

One other important thing is the configuration for the maven-bundle-plugin.

```
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
<Import-Package>*, org.hibernate.proxy, javassist.util.proxy</Import-Package>
The Meta-Persistence points to the persistence.xml and is the trigger for aries jpa to create an EntityManagerFactory for this bundle.
The Import-Package configurations import two packages that are needed by the runtime enhancement done by hibernate. As this enhancement is not known at compile time we need to give the maven bundle plugin these hints.
```

## Persistence

The tasklist-cdi-persistence bundle is the first module in the example to use the blueprint-maven-plugin. In the pom we set the scanpath to "net.lr.tasklist.persistence.impl". So all classes in this package and sub packages are scanned.

In the pom we need a special configuration for the maven bundle plugin:
```
<Import-Package>!javax.transaction, *, javax.transaction;version="[1.1,2)"</Import-Package>
```

In the dependencies we use the transaction API 1.2 as it is the first spec version to include the @Transactional annotation. At runtime though we do not need this annotation and karaf only provides the transaction API version 1.1. So we tweak the import to be ok with the version karaf offers. As soon as the transaction API 1.2 is available for karaf this line will not be necessary anymore.

```
@OsgiServiceProvider(classes = {TaskService.class})
@Singleton
@Transactional
public class TaskServiceImpl implements TaskService {
    @PersistenceContext(unitName="tasklist")
    EntityManager em;
    @Override
    public Task getTask(Integer id) {
        return em.find(Task.class, id);
    }
    @Override
    public void addTask(Task task) {
        em.persist(task);
        em.flush();
    }
    // Other methods omitted
}
```

TaskServiceImpl uses quite a lot of the annotations. The class is marked as a blueprint bean using @Singleton. It is also marked to be exported as an OSGi Service with the interface TaskService.

The class is marked as @Transactional. So all methods are executed in a jta transaction of type Required. This means that if there is no transaction it will be created. If there is a transaction the method will take part in it. At the end of the transaction boundary the transaction is either committed or in case of an exception it is rolled back.

A managed EntityManager for the persistence unit "tasklist" is injected into the field em. It transparently provides one EntityManager per thread which is created on demand and closed at the end of the transaction boundary.

```
@Singleton
public class InitHelper {
    Logger LOG = LoggerFactory.getLogger(InitHelper.class);
    @Inject TaskService taskService;
    @PostConstruct
    public void addDemoTasks() {
        try {
            Task task = new Task(1, "Just a sample task", "Some more info");
            taskService.addTask(task);
        } catch (Exception e) {
            LOG.warn(e.getMessage(), e);
        }
    }
}
```

The class InitHelper is not strictly necessary. It simply creates and persists a first task so the UI has something to show. Again the @Singleton is necessary to mark the class for creation as a blueprint bean.
@Inject TaskService taskService injects the first bean of type TaskService it finds in the blueprint context into the field taskService. In our case this is the implementation above.
@PostConstruct makes sure that addDemoTasks() is called after injection of all fields of this bean.

Another interesting thing in the module is the test TaskServiceImplTest. It runs outside OSGi and uses a special persistence.xml for testing to create the EntityManagerFactory without a jndi DataSource which would be difficult to supply. It also uses RESOURCE_LOCAL transactions so we do not need to set up a transaction manager. The test injects the plain EntityManger into the TaskServiceImpl class. So we have to manually begin and commit the transaction. So this shows that you can test the JPA code with plain java which results in very simple and fast tests.

## Servlet UI
The tasklist-ui module uses the TaskService as an OSGi service and publishes a Servlet as an OSGi service. The Pax-web whiteboard bundle will then pick up the exported servlet and publish it using the HttpService so it is available on http.
In the pom this module needs the blueprint-maven-plugin with a suitable scanPath.

```
@OsgiServiceProvider(classes={Servlet.class})
@Properties({@Property(name="alias", value="/tasklist")})
@Singleton
public class TaskListServlet extends HttpServlet {
    @Inject @OsgiService
    TaskService taskService;
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
        IOException {
        // Actual code omitted
    }
}
```

The TaskListServlet is exported with the interface javax.servlet.Servlet with the service property alias="/tasklist". So it is available on the url http://localhost:8181/tasklist.

@Inject @OsgiService TaskService taskService creates a blueprint reference element to import an OSGi service with the interface TaskService. It then injects this service into the taskService field of the above class.
If there are several services of this interface the filter property can be used to select one of them.

## Abgular JS / Bootstrap UI

![Image](tasks.png)

The Angular UI is just a bundle that statically exposes a html and js resource. It uses Angular and Bootstrap to create a nice looking and functional interface. The Tasks are read and manipulated using the Tasklist REST service.As the code completely runs on the client there is not much to talk about it from the blueprint point of view.

The example uses $http to do the rest requests. This is because I am not yet familiar enough with the $resource variant which would better suit the rest concepts.

From the OSGi point of view the Angular UI bundle simply sets the Header Web-ContextPath: /tasklist and provides the html and js in the src/main/resources folder.

## Build

```
mvn clean install
```

Installation and test
See [Readme.txt on github](../../tasklist-blueprint-cdi/README.md).

repository: alcorrius/Karaf-Tutorial

repo_name: alcorrius/Karaf-Tutorial


text:
## Glue Job Sync Utility

This utility helps you to synchronize Glue Visual jobs from one environment to another without losing visual representation.

## How to use it

You can run this utility in any location where you have Python and the following environment.

### Pre-requisite
* Python 3.6 or later
* Latest version of boto3

### Command line Syntax
```
$ sync.py [-h] [--src-job-names SRC_JOB_NAMES] [--src-profile SRC_PROFILE] [--src-region SRC_REGION] [--dst-profile DST_PROFILE] [--dst-region DST_REGION] [--sts-role-arn STS_ROLE_ARN] [--skip-no-dag-jobs SKIP_NO_DAG_JOBS]
                  [--overwrite-jobs OVERWRITE_JOBS] [--copy-job-script COPY_JOB_SCRIPT] [--config-path CONFIG_PATH] [-v]

optional arguments:
  -h, --help            show this help message and exit
  --src-job-names SRC_JOB_NAMES
                        The comma separated list of the names of AWS Glue jobs which are going to be copied from source AWS account. If it is not set, all the Glue jobs in the source account will be copied to the destination account.
  --src-profile SRC_PROFILE
                        AWS named profile name for source AWS account.
  --src-region SRC_REGION
                        Source region name.
  --dst-profile DST_PROFILE
                        AWS named profile name for destination AWS account.
  --dst-region DST_REGION
                        Destination region name.
  --sts-role-arn STS_ROLE_ARN
                        IAM role arn to be assumed to access destination account resources.
  --skip-no-dag-jobs true/false
                        Skip Glue jobs which do not have DAG. (possible values: [true, false]. default: true)
  --overwrite-jobs true/false
                        Overwrite Glue jobs when the jobs already exist. (possible values: [true, false]. default: true)
  --copy-job-script true/false
                        Copy Glue job script from the source account to the destination account. (possible values: [true, false]. default: true)
  --config-path CONFIG_PATH
                        The config file path to provide parameter mapping. You can set S3 path or local file path.
  -v, --verbose         (Optional) Display verbose logging (default: false)
```

### Config file
When you synchronize your Glue Visual jobs into another account, all the account specific parameters need to be replaced.
This utility allows you to provide simple config file to determine the mapping rules to replace values.

The config file needs to be written in flat JSON. You can place this config file in local or S3.

Example:
```
{
    "123456789012": "234567890123",
    "aws-glue-assets-123456789012-eu-west-3": "aws-glue-assets-234567890123-eu-west-3",
    "GlueServiceRoleSourceAccount": "GlueServiceRoleDestinationAccount"
}
```

### Credentials
There are two options to configure credentials for accessing resources in target accounts.

#### Profile

When you provide `--dst-profile`, this utility uses AWS Named profile set in the option to access resources in the destination account.

#### STS AssumeRole

When you provide `--sts-role-arn`, this utility assumes the role and use the role to access resources in the destination account.
You need to create IAM role in the destination account, and configure the trust relationship for the role to allow `AssumeRole` calls from the source account.

## Examples

### Example 1. Synchronize single Glue Visual job to another account using AWS named profile
```
$ python3 sync.py --src-profile test1 --src-region eu-west-3 --dst-profile test2 --dst-region eu-west-3 --src-job-names dag-test --config-path mapping.json
```
* This command synchronizes only one job named `dag-test`.

### Example 2. Synchronize all Glue Visual jobs to another account using AWS named profile
```
$ python3 sync.py --src-profile test1 --src-region eu-west-3 --dst-profile test2 --dst-region eu-west-3 --config-path mapping.json
```
* This command synchronizes all the Glue Visual jobs because `--src-job-names` is not provided.

### Example 3. Synchronize all Glue Studio jobs to another account using STS temporary credential
```
$ python3 sync.py --sts-role-arn arn:aws:iam::234567890123:role/admin --src-region eu-west-3 --dst-region eu-west-3 --config-path s3://path_to_config/mapping.json
```
* This example expects that you have default credential for the source account (e.g. IAM role, etc.).
* As you can see in this example, the mapping config file can be placed in S3.

repository: JoshCrosby/aws-glue-samples

gha_license_id: NOASSERTION

repo_name: JoshCrosby/aws-glue-samples


text:
`CPU` is a sample plugin demonstrating the [Stream Deck SDK](https://developer.elgato.com/documentation/stream-deck/).

# Description

`CPU` is a plugin that displays the CPU usage on a key.

# Features

- code written in C++
- cross-platform (macOS, Windows)
- localized

![](screenshot.png)

# Installation

In the Release folder, you can find the file `com.elgato.cpu.streamDeckPlugin`. If you double-click this file on your machine, Stream Deck will install the plugin.

# Source code

The Sources folder contains the source code of the plugin.

repository: elgatosf/streamdeck-cpu

repo_name: elgatosf/streamdeck-cpu


text:
# Morchella patula var. gigas (Pers.) S. Imai, 1954 VARIETY

#### Status
SYNONYM

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
Science Rep. Yokohama Nat. Univ. , Section 2 3: 15 (1954)

#### Original name
Morchella gigas Pers., 1801

### Remarks
null

repository: mdoering/backbone

path: /life/Fungi/Ascomycota/Pezizomycetes/Pezizales/Morchellaceae/Mitrophora/Mitrophora gigas/ Syn. Morchella patula gigas/README.md

repo_name: mdoering/backbone


text:
---
layout: post
title: "Coherent tunneling in an AlGaN/AlN/GaN heterojunction captured through an analogy with a MOS contact"
date: 2017-05-09 14:09:43
categories: arXiv_CV
tags: arXiv_CV GAN
author: Yannick Baines, Julien Buckley, Jérôme Biscarrat, Gennie Garnier, Matthew Charles, William Vandendaele, Charlotte Gillot, Marc Plissonnier
mathjax: true
---

* content
{:toc}

##### Abstract
Due to their wide band gaps, III-N materials can exhibit behaviors ranging from the semiconductor class to the dielectric class. Through an analogy between a Metal/AlGaN/AlN/GaN diode and a MOS contact, we make use of this dual nature and show a direct path to capture the energy band diagram of the nitride system. We then apply transparency calculations to describe the forward conduction regime of a III-N heterojunction diode and demonstrate it realizes a tunnel diode, in contrast to its regular Schottky Barrier Diode designation. Thermionic emission is ruled out and instead, a coherent electron tunneling scenario allows to account for transport at room temperature and higher.

##### Abstract (translated by Google)

##### URL
[https://arxiv.org/abs/1704.08505](https://arxiv.org/abs/1704.08505)

##### PDF
[https://arxiv.org/pdf/1704.08505](https://arxiv.org/pdf/1704.08505)


text:
# Lowercase Evernote Tags
This is an AppleScript that will lowercase all of your tags in Evernote

## Instructions

1. Backup Your Evernote Notes.
  * Open Evernote
  * Click on 'Notebooks' to select it
  * Go to the File menu
  * Export All Notes
    * Be sure the Format is 'Evernote XML Format (.enex)
2. Open Script Editor
3. Copy and paste this script into the window or just open the file if its saved on your hard drive
4. Go to the View menu and ensure that the Log window is shown
5. Switch tabs in the Log window to 'Events'
6. Press the Play button to execute the script

The script will output the results to the Events window showing you a before and after.

repository: objectmethod/lowercase-evernote-tags

repo_name: objectmethod/lowercase-evernote-tags


text:
# Web3.py

[![Join the chat at https://gitter.im/pipermerriam/web3.py](https://badges.gitter.im/pipermerriam/web3.py.svg)](https://gitter.im/pipermerriam/web3.py?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![Build Status](https://travis-ci.org/pipermerriam/web3.py.png)](https://travis-ci.org/pipermerriam/web3.py)

A Python implementation of [web3.js](https://github.com/ethereum/web3.js)

* Python 2.7, 3.4, 3.5 support

Read more in the [documentation on ReadTheDocs](http://web3py.readthedocs.io/). [View the change log on Github](docs/releases.rst).

## Developer setup

If you would like to hack on web3.py, set up your dev environment with:

```sh
sudo apt-get install libssl-dev
# ^ This is for Debian-like systems. TODO: Add more platforms

git clone git@github.com:pipermerriam/web3.py.git
cd web3.py
virtualenv venv
. venv/bin/activate
pip install -r requirements-dev.txt
pip install -e .
```

For different environments, you can set up multiple virtualenvs, like:

**Python 2**

```sh
virtualenv -p python2 venvpy2
. venvpy2/bin/activate
pip install -r requirements-dev.txt
pip install -e .
```

**Docs**

```sh
virtualenv venvdocs
. venvdocs/bin/activate
pip install -r requirements-dev.txt
pip install -e .
```

### Testing Setup

During development, you might like to have tests run on every file save.

Show flake8 errors on file change:

```sh
# Test flake8
when-changed -r web3/ tests/ -c "clear; git diff HEAD^ | flake8 --diff"
```

You can use pytest-watch, running one for every python environment:

```sh
pip install pytest-watch

cd venv
ptw --onfail "notify-send -t 5000 'Test failure ⚠⚠⚠⚠⚠' 'python 3 test on web3.py failed'" ../tests ../web3

#in a new console
cd venvpy2
ptw --onfail "notify-send -t 5000 'Test failure ⚠⚠⚠⚠⚠' 'python 2 test on web3.py failed'" ../tests ../web3
```

Or, you can run multi-process tests in one command, but without color:

```sh
# in the project root:
py.test --numprocesses=4 --looponfail --maxfail=1
# the same thing, succinctly:
pytest -n 4 -f --maxfail=1
```

### Release setup

For Debian-like systems:
```
apt install pandoc
```

*TODO* other release instructions


text:
# Close Tab by Double Right Click
Extension **Close Tab by Double Right Click** for Google Chrome and Mozilla Firefox.
| Close active tab by                                                 | Chrome             | Firefox            |
| :---                                                                |        :----:      |               ---: |
| Double right click anywhere on the page                             | :heavy_check_mark: | Upto Firefox 101   |
| Left click immediately followed by right click anywhere on the page | :heavy_check_mark: | :heavy_check_mark: |

   https://chrome.google.com/webstore/detail/klngijkfgagcnegkffeckmkdpnpmbdpm

   https://addons.mozilla.org/firefox/addon/close-tab-double-right-click/

**This extension is inspired by "Rights To Close" legacy extension for Mozilla Firefox.**

**Open source:**
* https://github.com/webextensions/close-tab-by-double-right-click

**This extension is available for:**
* Google Chrome
* Mozilla Firefox

**Created by:**
* Priyank Parashar

**Notes:**

* To enable this extension in "incognito" window mode or for "file:///" URLs, you will need to provide permissions for this by going to "chrome://extensions".

* Close Tab by Double Right Click implements an alternative approach for closing "chrome:///", "about:blank" and other special tabs. This is due to technical limitations of Chrome API. In these tabs, you would find a "Close Tab" context-menu entry which is shown when you right click anywhere on the page.

**Inspirations:**
* The idea of this extension is inspired by "Rights To Close" legacy extension for Mozilla Firefox.

**Connect with us:**
* https://www.webextensions.org/
* [GitHub](https://github.com/webextensions/close-tab-by-double-right-click)
* [Twitter](https://twitter.com/webextensions)
* [LinkedIn - Priyank Parashar](https://linkedin.com/in/ParasharPriyank/)


text:
# component-driven-workshop/slides

> Create, test, deploy and maintain frontend code

> (without losing your mind)

This repository contains all slides used for the workshop "Component driven design". Each session has its own slide deck:

*  [Session 1](./session-1) - 2016-11-29
*  [Session 2](./session-2) - 2016-11-30
*  Session 3 - 2016-12-14

## Installation

```
git clone https://github.com/component-driven-workshop-slides.git
cd slides
npm install
npm start
```

## License

(c) Adam Christian, Mario Nebl, MIT License

repository: simonwalter/slides

repo_name: simonwalter/slides


text:
---
title: Generating Images with Desired Features
tags: GAN CVAE SeFa disentanglement conditioned_generation
---

Generative Adversarial Networks (GANs) are the best choices of modern image
synthesis, aren't they? We already have hardly distinguishable face generator
of StyleGAN2[^1] (you can see [an online demo](https://thispersondoesnotexist.com/))
and this seems only a step away from the perfect image generation. However, even
that SOTA model has limitations: how to generate an image with **certain traits**
of interest? In other words, StyleGANs do not take any conditioning attributes
on the resulting image but one long lengthy noise vector to generate an image.
In this post, let's take a look why this problem is hard and what are the efforts
to solve (or at least, mitigate) it.

## Why is generating a specific image by a GAN model hard?

In fact, if you want to generate an image of *any cat* with *any species* in *any
posture*, then there's no problem.  That's not our interest at the moment. The thing is, how can we
tell the model the length of the hair, or the orientation of the head and so on
and on?

![StyleGANs' architectures](https://neurohive.io/wp-content/uploads/2019/12/Screenshot_2-scaled.png)
> StyleGAN's architectures. From the original paper[^1].

As you can see on the above architecture, the StyleGAN family all get the input of
`A` and `B`: `A` denotes the learned style vector and `B` stands for the broadcasted
true noise. The difference between the architectures is out of the scope of this
post, so let's focus on what those input vectors mean.

### No explicit mention of the feature

As you realised, there is no explicit part indicating which dimension means what
feature of the resulting images. All the images are generated from the noise vectors
and, in fact, it is nearly impossible to configure the image in advance to synthesis.

### Entangled vector space

And yes, since the input vectors are noise, the model would not likely to learn
the features correpond to a single dimension of the input. In other words, if we
want to change the speices of cat, then we probably need to change several values
on the input vector. Also the adjustment will be definitely non-linear, so there's
no chance to get Siamese by putting 1 to the 42nd value and Russian blue by 2.
This chaotic situation is denoted as **entanglement** of the latent space.

In StyleGAN family, `A` is the *mapped style vector* from noise so it is in some
way more *disentangled*, than the input noise space. It learns the 'style' from
the noise and can be appliable to transfer the style to another generated image.
Still, nonetheless, we don't know which dimension stands for what.

## Proposed methods

Facing those challenges, researchers are working on the interpretability of exiting
models and novel architectures. Here I list up some of those works.

### Feed the exact image to the model

![Image2StyleGAN]({{ site.url }}/assets/images/2021-02-10-image2stylegan.png)
> Core algorithm of Image2StyleGAN. From the original paper[^2].

Somehow unrealistic setting, isn't it:) but if we can obtain the nice latent style vector
producing the image we have, then we can play with the model much easier. Abdal et al.[^2]
proposed the simple gradient descent based algorithm for it.

This algorithm starts from a random vector and gradually optimise the style vector
to produce as similar image as possible to the given image. Here, $L_{perceptual}$
is the *perceptual loss* (or perceptual distance) between two images. I mentioned
briefly about this at my [previous post]({{ site.url }}/2021/01/16/Evaluating-GANs.html#bonus-perceptual-path-length-ppl).
This perceptual loss is to minimise the stylistic difference between images
by using pre-trained VGG-16 network's interim results. Hence, the optimised
latent style vector will produce the most similar image in terms of the pixels and
the (machine) perception.

The authors already extended this to Image2StyleGAN++, but I would insist
the powerful use case of this method regarding this post's theme is that we can
collect the style vectors from the set of images with our desired features.
We could hopefully find some common directions from the vectors!

### Provide details to the model

<img src="{{site.url}}/assets/images/2021-02-10-simplegans.jpg" width="600">
> Some primitive GANs. Source unknown.

This is what ConditionalGAN[^3] tried at first - providing the additional input
to the generator model. Early stage of works on GAN (image above) including CGAN,
ACGAN and infoGAN shows how they tried to put the additional information to the
entire architecture. This approach is intuitive as well as simple to implement.
However, in many cases, those works are tested with categorical values at most
10 (and one or two continuous hidden features in infoGAN cases), so have limit
on scalability.

![cvae-gan]({{ site.url }}/assets/images/2021-02-10-cvae-gan.png)
> CVAE-GAN architecture and the loss propagation diagram. From the original paper[^4].

CVAE-GAN[^4] is an alternative to vanilla GAN approaches. You might heard about
Variational Auto-Encoder, or VAE, to generate images just like GANs do but in
deterministic way. The idea of VAEs is to encode the latent vectors from the real
images and later decode them. In mathematical terms, the objective of VAEs is:

$$ \log P(X) - D_{KL} [Q(z|X) \| P(z|X)] = \mathbb{E} [\log P(X|z)] - D_{KL} [Q(z|X) \| P(z)]$$

where $Q(z|x)$ is the encoder distribution. Simplifying the calculation, we usually
model the true distribution $P$ with a Gaussian. Anyway, CVAE is just conditioning
every term on the condition of interest, $c$.

VAE family usually performs 'okay' with blurry results, but at least in determinstic sense.
CVAE-GAN merges two named architectures - treating the generator of GAN
as the decoder of CVAE, and update them with the losses calculated from the
auxiliary classifier and discriminator. To overcome the vanishing gradient during the
GAN training, the authors proposed *mean feature matching* loss term as well, which
is quite similar to the perceptual loss but within the model itself. Interested
readers can read the original paper listed below.

### Finding semantic transformations of the model

This is the post-processing approach of controlling GAN. In case of StyleGAN,
after the image is generated, we can play with the style vectors to see which
value corresponds to what visual feature. However, the style vector has 512
dimension by default setting and we may don't have much time to play with each
of the value. Plus, the style vector can still be entangled, so we might not find
the exact feature we want by brute-force.

Yujun et al.[^5] proposed an elegant approach named SeFa (Semantic Factorization)
to find *significant transformations* on several generative models, including
StyleGAN v1 and v2, PGGAN, and BigGAN. Their idea is simple: take the first affine
transformation of the generator and find the direction on the input vector which
results in the most change in the objective space. Let's formulate this by following
authors' logic.

Consider a generator $G$ taking an input $\mathbf{z} \in \mathbb{R}^d$. Denote $G_1$ be the first affine
transformation of $G$. We can formulate this:

$$ G_1(\mathbf{z}) = \mathbf{A} \mathbf{z} + \mathbf{b} $$

Let's say the resulting dimension is $m$, so $\mathbf{A} \in \mathbb{R}^{m \times d}$ and $\mathbf{b} \in \mathbb{R}^m$.
Editing the image can be denoted as:

$$ G(\mathbf{z}') = G(\mathbf{z} + \alpha \mathbf{n}) $$

where $\mathbf{n} \in \mathbb{R}^d$ is an unit vector and $\alpha$ is an manipulation intensity.
From this preliminaries, let's expand the first transformation with $\mathbf{z}'$.

$$
\begin{align*}
    G_1(\mathbf{z}') &= G_1(\mathbf{z} + \alpha \mathbf{n}) \\
    &= \mathbf{A} \mathbf{z} + \mathbf{b} + \alpha \mathbf{A} \mathbf{n} \\
    &= G_1(\mathbf{z}) + \alpha \mathbf{A} \mathbf{n}
\end{align*}
$$

This states that the transformation is invariant to the bias trained.
The authors propose to solve the following optimisation problem:

$$ \mathbf{N}^* = \arg\max_{\mathbf{N} \in \mathbb{R}^{d \times k},\ \mathbf{n}_i^\intercal \mathbf{n}_i = 1,\ \forall i \in [k]} \Sigma_{i=1}^{k} \| \mathbf{A} \mathbf{n}_i \|_2^2 $$

where $\mathbf{N} = [\mathbf{n}_1, \cdots, \mathbf{n}_k]$ and is the $k$-*most-significant
transformations*. Introducing the Lagrange multipliers $\lambda_1, \cdots \lambda_k$ to solve:

$$
\begin{align*}
    \mathbf{N}^* &= \arg\max \Sigma_{i=1}^{k} \| \mathbf{A} \mathbf{n}_i \|_2^2 - \Sigma_{i=1}^{k} \lambda_i (\mathbf{n}_i^\intercal \mathbf{n}_i - 1) \\
    &= \arg\max \Sigma_{i=1}^{k} \left( \mathbf{n}_i^\intercal \mathbf{A}^\intercal \mathbf{A} \mathbf{n}_i - \lambda_i \mathbf{n}_i^\intercal \mathbf{n}_i - \lambda_i \right) \\
    \frac{\partial}{\partial \mathbf{n}_i} \mathbf{N}^* &= 2 \mathbf{A}^\intercal \mathbf{A} \mathbf{n}_i - 2\lambda_i \mathbf{n}_i = 0
\end{align*}
$$

so it searching $\mathbf{n}_i$ goes equivalent to finding $k$ eigenvectors with
the largest eigenvalues of $\mathbf{A}^\intercal \mathbf{A}$. Simple, isn't it?
we can just add $\mathbf{n}_i$ with the scalar parameter $\alpha$ to adjust our
image. Oh, this can make positive synergy with the first approach I introduced:)

Yes, I should admit that this approach may not lead to the features what we exactly
want to find, but would insist this has much higher chance to find some meaningful
transformations.

## Wrap up

We went through the ways how to generate the image with our desired features.
Nothing is so perfect - I'm still seeking and making experiments to control the
image generation with as many attributes as possible. Until the mysteries of GANs
be unveiled:)

## Read more

1. [Conditional Variational Autoencoder: Intuition and Implementation](https://wiseodd.github.io/techblog/2016/12/17/conditional-vae/), A. Kristiadi, 2016
2. [CVAE-GAN original paper](https://openaccess.thecvf.com/content_ICCV_2017/papers/Bao_CVAE-GAN_Fine-Grained_Image_ICCV_2017_paper.pdf), J. Bao et al., 2017
3. [SeFa demo page](https://genforce.github.io/sefa/)

[^1]: Karras, Tero, et al. "Analyzing and improving the image quality of stylegan." Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. 2020.
[^2]: Abdal, Rameen, Yipeng Qin, and Peter Wonka. "Image2stylegan: How to embed images into the stylegan latent space?." Proceedings of the IEEE/CVF International Conference on Computer Vision. 2019.
[^3]: Mirza, Mehdi, and Simon Osindero. "Conditional generative adversarial nets." arXiv preprint arXiv:1411.1784 (2014).
[^4]: Bao, Jianmin, et al. "CVAE-GAN: fine-grained image generation through asymmetric training." Proceedings of the IEEE international conference on computer vision. 2017.
[^5]: Shen, Yujun, and Bolei Zhou. "Closed-form factorization of latent semantics in gans." arXiv preprint arXiv:2007.06600 (2020).


text:
---
products:
  - name: rhoam
    environments:
      - osd-fresh-install
      - osd-post-upgrade
    targets:
      - 1.6.0
      - 1.10.0
estimate: 15m
tags:
  - automated
---

# A34 - Verify Quota values

Note: There is also an automated version of this test, so the steps below are just initial checks to validate the quota
parameter is as expected and to validate an upgrade scenario. Please also check that the A34 automated test is passing.

## Prerequisites

- Logged in to a testing cluster as a kubeadmin
- access to OCM UI org where the testing cluster is created (usually CSQE OCM org)

## Steps

1. Get `toQuota` field's value from RHMI CR

```bash
oc get rhmi rhoam -n redhat-rhoam-operator -o json | jq -r '.status.toQuota'
```

> The output should be `null`, unless the quota configuration is still in progress. Try again in a couple of minutes.

2. Get the Quota value from RHMI CR

```bash
oc get rhmi rhoam -n redhat-rhoam-operator -o json | jq -r '.status.quota'
```

3. Get the param value from the Secret

```bash
oc get secret addon-managed-api-service-parameters -n redhat-rhoam-operator -o json | jq -r '.data.addon-managed-api-service' | base64 --decode
```

> Verify that the quota value matches the mapped parameter from the secret.
>
> if param is == 0 then Quota should be 100K - Evaluation -> (Evaluation option)
> if param is == 10 then Quota should be 1 Million
> if param is == 50 then Quota should be 5 Million
> if param is == 100 then Quota should be 10 Million
> if param is == 200 then Quota should be 20 Million
> if param is == 500 then Quota should be 50 Million
> if param is == 1 then Quota should be 100k

> If there is no value in the secret, the cluster has been upgraded from a version of rhoam which did not have
> the quota paramater. aka pre 1.6.0. If this is the case go to step 4. Otherwise skip to step 5.

4. Get the param value from the container Environment Variable.

```bash
oc get $(oc get pods -n redhat-rhoam-operator -o name | grep rhmi-operator) -n redhat-rhoam-operator -o json | jq -r '.spec.containers[0].env[] | select(.name=="QUOTA")'
```

> Validate that the value of the status.quota matches the parameter from the secret using the mapping above.

5. Go to OpenShift console search for config map `quota-config-managed-api-service` in redhat-rhoam-operator namespace.
6. Depending on what the current quota value is on the testing cluster, navigate to the section of a quota config where that value is defined (e.g. for 5 million: `"param": "50"`)

7. Compare the values of resources with what you get by running this command from the terminal

```bash
backend_listener_replicas=$(oc get dc backend-listener -n redhat-rhoam-3scale --no-headers=true | awk '{print $4}')
backend_listener_resources=$(oc get dc backend-listener -n redhat-rhoam-3scale -o json | jq -r .spec.template.spec.containers[0].resources)

backend_worker_replicas=$(oc get dc backend-worker -n redhat-rhoam-3scale --no-headers=true | awk '{print $4}')
backend_worker_resources=$(oc get dc backend-worker -n redhat-rhoam-3scale -o json | jq -r .spec.template.spec.containers[0].resources)

apicast_production_replicas=$(oc get dc apicast-production -n redhat-rhoam-3scale --no-headers=true | awk '{print $4}')
apicast_production_resources=$(oc get dc apicast-production -n redhat-rhoam-3scale -o json | jq -r .spec.template.spec.containers[0].resources)

usersso_replicas=$(oc get statefulset keycloak -n redhat-rhoam-user-sso --no-headers=true | awk '{print $2}')
usersso_resources=$(oc get statefulset keycloak -n redhat-rhoam-user-sso -o json | jq -r .spec.template.spec.containers[0].resources)

ratelimit_replicas=$(oc get deployment ratelimit -n redhat-rhoam-marin3r --no-headers=true | awk '{print $2}')
ratelimit_resources=$(oc get deployment ratelimit -n redhat-rhoam-marin3r -o json | jq -r .spec.template.spec.containers[0].resources)

ratelimit_value=$(oc get configmap ratelimit-config -n redhat-rhoam-marin3r -o json | jq -r '.data["apicast-ratelimiting.yaml"]' | yq e '.[0].max_value' - )

echo requests per limit value: $ratelimit_value

echo backend-listener replicas: $backend_listener_replicas
echo backend-listener resources: $backend_listener_resources

echo backend-worker replicas: $backend_worker_replicas
echo backend-worker resources: $backend_worker_resources

echo apicast-production replicas: $apicast_production_replicas
echo apicast-production resources: $apicast_production_resources

echo user-sso replicas: $usersso_replicas
echo user-sso resources: $usersso_resources

echo rate limit replicas: $ratelimit_replicas
echo rate limit resources: $ratelimit_resources
```

8. Login to OCM with provided token

```bash
ocm login --url=https://api.stage.openshift.com/ --token=<YOUR_TOKEN>
```

9. Set cluster name variable

```bash
CLUSTER_NAME="<CLUSTER_NAME>"
```

10. Get cluster id and assign it to a variable

```bash
CLUSTER_ID=$(ocm get clusters --parameter search="name like '%$CLUSTER_NAME%'" | jq -r '.items[].id')
```

11. Set quota value

```bash
QUOTA_VALUE=<QUOTA_VALUE>
```

12. Update quota

```bash
ocm patch /api/clusters_mgmt/v1/clusters/$CLUSTER_ID/addons/managed-api-service --body=<<EOF
{
   "parameters":{
      "items":[
         {
            "id":"addon-managed-api-service",
            "value":"$QUOTA_VALUE"
         }
      ]
   }
}
EOF
```

13. Check addon parameters updated successfully

```bash
ocm get /api/clusters_mgmt/v1/clusters/$CLUSTER_ID/addons/managed-api-service
```

14. Repeat this for all available quota values.