text:
# wasm2evm
A WebAssembly to EVM compiler

Right now we aim to compile the hello world program below from WASM to
EVM.

```
(module
  (memory 1
   (segment 8 "hello world!\n")
  )
  (import $__fwrite "env" "_fwrite" (param i32 i32 i32 i32) (result i32))
  (import $_get__stdout "env" "get__stdout" (param) (result i32))
  (export "main" $main)

  (func $main (result i32)
    (local $stdout i32)
    (set_local $stdout (call_import $_get__stdout))

    (return (call_import $__fwrite
       (i32.const 8)         ;; void *ptr    => Address of our string
       (i32.const 1)         ;; size_t size  => Data size
       (i32.const 13)        ;; size_t nmemb => Length of our string
       (get_local $stdout))  ;; stream
    )
  )
)
```

## Integer Size

The compiled version will only utilize at most 64 bit of integers
except for hash values and addresses. This is under the assumption
that most integers never exceed `u64::max_value()`.

This could lead to a small increase in gas cost. But under the above
assumption, using a well-optimized EVM interpreter, it does not
necessily lead to slower code.

## Initialization

First, we use the `PUSHX` opcodes and `MSTORE` opcode to initialize
the memory as specified by WASM. This writes `"hello world!\n"` from
memory location 8.

## Table

WebAssembly's table is probamatic. Currently, it is only used to
implement indirect function calls in C/C++ using an integer index as
the pointer-to-function and the table to hold the array of
indirectly-callable functions. As a result, it can be ignored as of
now.

In the future, table is mostly dealt with GC. This is not existant in
the Ethereum world. So it can also be ignored.

## Imports and Exports

Exports are ignored (or they can be used in ABI in the
future). Imports other than `"env"` is not allowed right now.

In the future, imports from other modules will be compacted to one
single module.

## Unwrap `$main`

Code in main is unwrapped directly below initialization. Other
functions are added below, with a `JUMPDEST` opcode. Those functions
will need to manage their own call stack and return values. Local
variables are set to the memory, with the exception of external
objects like this returned by `$_get__stdout`. This is analyzed away.

When dealing with nested function calls. The return values are dealt
by stack. `__fwrite` call serves two functions -- when working with
stdout, it uses `LOG` opcode; when working with other things, it uses
a filesystem library built on top of the contract storage.

The hello world example will be directly compiled to a `LOG` opcode
and a `RETURN` opcode (with several `PUSH` opcodes to write the
parameters, probably).


text:
# WalletConnect Wizard

This is a web component to integrate [WalletConnect](https://www.myetherwallet.com/) token and cryptocurrency wallets to your service easily.

We believe that separating the concerns of service providers and value storages increases security and privacy of Internet. However this so called Web3 principle is also a novel concept for a lot of users and education in this area is needed. WalletConnect Wizard is a component designed to provide a smooth user experience for helping users to install, start using, confirm transactions and see their tokens in their third party wallets.

We support different kind of wallet mechanisms (see below), though the emphasis is on WalletConnect wallets as they are more secure due to running on a separate hardened mobile device.

# Goals

* A component for web and mobile service developers
* Easy to integrate to your site - providing a bundled JS and CSS option
* Explain new users what is a wallet and why it is needed
* Support both WalletConnect (mobile) and web3.js/MetaMask (desktop) style wallets
* Support multiple blockchains: Ethereum, Binance, otehrs
* Maintain list of logos, names and install locations of supported wallets
* Multimodal - automatically adapt styles and installation links depending on the platform: desktop, iOS, Android

# Demo

* [See live demo](https://tokenmarketnet.github.io/walletconnect-wizard/demo/index.html)

# Usage

We currently provide an UMD build, which should be usable directly from the browser, and a CommonJS build.

```html
<div id="root"></div>
<script src="./dist/umd/walletconnect-wizard.js"></script>
```

```javascript
walletConnectWizard.init('root', {
    onConnect: function(response) {
        alert("You are connected with: " + response.type);
        response.provider.sendAsync({
            method: 'eth_accounts',
            params: [],
        }, function(error, params)  {
            var account = params.result[0];
            alert("Your ethereum account is:" + account);
        });
    }
});
```

Usage with ES6/Typescript and React:

```javascript
import { Wizard } from 'walletconnect-wizard';

<Wizard
    onConnect={(response) => {
        // do stuff
    }}
/>
```

The response object API is to be fully designed, but it looks something like this:

```typescript
export interface ConnectionResponse {
    type: ConnectionType;                   // 'walletconnect' or 'browser'
    provider: any;                          // asyncSendable provider that can be passed to new Web3(...)
                                            // for MetaMask, this will be window.ethereum
                                            // for WalletConnect, we use @walletconnect/web-provider
    web3: any;                              // currently always null, maybe Web3 object in the future
    walletConnector: WalletConnect | null;  // WalletConnect object, or null if connected using MetaMask
}
```

# Development

We use StoryBook for easy local development:

```
$ yarn
$ yarn start
```

Building:

```
$ yarn build
```

Updating github pages (live demo):

```
$ git checkout gh-pages
$ git merge master
$ rm -rf dist
$ yarn build
$ git add --force dist
$ git commit -m "Update gh-pages"
$ git push origin gh-pages
```

Analyzing built bundle size:

```
$ yarn analyze-bundle
```

This opens a server in http://localhost:8888/, where you can see a visual representation of the bundle contents.

# UI mockups

* [See LucidChart mock ups](https://www.lucidchart.com/documents/view/741793a6-be73-4ee4-8709-46e811ffe4c1)

# Eligible wallets

We are currently focusing on wallets that can directly interact with smart contracts and blockchain. Wallets that do only transfer-of-value only are out of the scope

For Ethereum the wallet must pass all tests on [example.walletconnect.org](https://example.walletconnect.org)

## Different wallet categories

We can roughly classify how wallets and web services interact

* Mobile wallets that connect to your service by reading a [WalletConnect](https://walletconnect.org) QR code on a desktop page
* Desktop web browser extensions (MetaMask)
* Wallet integrated in a desktop web browser (Opera, Brave)
* Wallet integrated in a mobile browser (Opera for Android)
* Mobile app that integrates a WebView web browser (Status.im)
* Desktop wallet apps that connect via localhost socket (Scatter for EOS)

Limitations between if your wallet integrates a browser or a browser integrates a wallet comes obvious when you try to interact with third party sign in services like Facebook and Google.

# Wallet database entries

* *id*: internal id
* *name*: Human readable brand name
* *homepage*: Link to the homepage
* *support*: Link to the support - displayed on connection page if the user is having issues
* *blockchains*: ids of supported blockchains - currently `ethereum` and `binance`
* *install*: direct installation links to different platform
* *operations*: what kind of operations this support: transactions, message signing, etc.

# TODO

* Generate wallet list from database json
* Detect mobile browsers and don't show QR-code
* Provide multiple build targets: [x] UMD (named walletconnect-wizard.js), [x] CommonJS, [ ] esmodule
* Strip down the build size
* Finalize response (maybe return Web3 object there)
* Better documentation (document finalized response object and props to pass to `init` and `Wizard`)
* Configure TSLint

# License

MIT

license: MIT

branch_name: refs/heads/master

extension: md

license_type: permissive


text:
## Grant Timmerman

<img src="https://user-images.githubusercontent.com/744973/143484396-8f5e689b-4427-4e22-b5cc-0369b4a1550e.png" width="400" />

Grant is a software engineer at Observable. Previously he worked at Google for over 5 years on serverless runtimes for Google Cloud and open source for G Suite APIs. He loves Node, GitHub, and plays the alto saxophone in his spare time.

Grant earned a bachelor's degree in computer science from the University of Washington, Seattle.

## Common Questions

- **Name:** Grant Timmerman
- **Profession:** Software Engineer, Google
- **Short Bio:** Software Engineer at Google focusing on serverless technologies on Google Cloud.
- **Export Keywords:** Cloud, Serverless, G Suite, Open Source
- **Facebook:** facebook.com/grant.timmerman
- **Twitter:** twitter.com/granttimmerman
- **GitHub:** github.com/grant
- **LinkedIn:** linkedin.com/in/granttimmerman
- **Website:** grant.cm
- **YouTube:** youtube.com/granttimmerman

### Session

- Session Title
- Session Description (100 words max)
- Categories (General, Cloud, Mobile, Web, ML, IoT, Android, Firebase, VR/AR, Polymer)
- Beginner/Intermediate/Advanced

### Other photos

![https://twitter.com/granttimmerman/status/1103069984576569345](https://pbs.twimg.com/media/D07kM0SU8AAMQBe.jpg)
https://twitter.com/granttimmerman/status/1103069984576569345

![Screen Shot 2019-08-09 at 10 52 16](https://user-images.githubusercontent.com/744973/62798717-d3ed1680-ba93-11e9-9338-e65b6c3a22ae.png)

![Grant Timmerman](https://user-images.githubusercontent.com/744973/93780614-fe455900-fbed-11ea-8208-3d4081ad421e.jpg)

![](https://user-images.githubusercontent.com/744973/38894674-c762c6dc-4242-11e8-82a4-c3369c2adf94.jpg)

![gmoji](https://user-images.githubusercontent.com/744973/62798784-f97a2000-ba93-11e9-8e28-c35348588620.png)

repository: grant/talks

gha_license_id: MIT

repo_name: grant/talks


text:
# Frontend Todo list

[![Contributors][contributors-shield]]()

<!--General tasks to accomplish-->

- Carousels for individual topics -

Project Link: [https://github.com/your_username/repo_name](https://github.com/your_username/repo_name)

<!-- MARKDOWN LINKS & IMAGES -->

[build-shield]: https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square
[contributors-shield]: https://img.shields.io/badge/contributors-4-orange.svg?style=flat-square
[license-shield]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
[license-url]: https://choosealicense.com/licenses/mit
[product-screenshot]: https://imgur.com/a/r0aXgWx

repository: wikipockets/Game-On

repo_name: wikipockets/Game-On


text:
[![TravisCI](https://img.shields.io/travis/qbx2/pscp/master.svg?style=flat)](https://travis-ci.org/qbx2/pscp/)
[![PyPI](https://img.shields.io/pypi/v/pscp.svg?style=flat)](https://pypi.org/project/pscp)
![PyPI-License](https://img.shields.io/pypi/l/pscp.svg?style=flat)
[![codecov](https://codecov.io/gh/qbx2/pscp/branch/master/graph/badge.svg)](https://codecov.io/gh/qbx2/pscp)

# PSCP: Per-session checkpoint

PSCP is a brand-new way to make checkpoint in git repository efficiently.
By logging the hash output by `pscp.create()`, you can `git diff`, `git stash branch` and `git checkout` using them whenever you want.
PSCP is framework-agnostic, so can be used in any git repository.

PSCP inherits all strengths from git, which are very useful for study.

* Recycle unchanged objects
* Compression (zlib)
* Show differences using `git diff a..b`
* Checkout to, using `git checkout`
* Create branch from, using `git stash branch`. This restores staged files staged and unstaged files unstaged.

Besides, PSCP does make neither `git log` nor `git stash list` messy.

## Requirements

* python 3.5+
* git

## Installation

`pip install pscp`

## Getting Started

[Getting Started](Getting_Started.md)

## Frequently Asked Questions

### How does it work?

[How PSCP Works](How_PSCP_Works.md)

### Does PSCP just save 'all' files?

No, PSCP saves git-tracked files only.
For details, please refer to [2.2 Git Basics - Recording Changes to the Repository](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository).

### Tracking New Files

Use `git add` to stage, to track new files. Untracked files will not be added to the checkpoint.

### Saving environment variables or argparse results?

You're supposed to write to any file and track them (using `git add`).
Using json built-in library, it can be done easily.

```python
import json
```

To save environment variables,

```python
import os
json.dump(fp, dict(os.environ), indent=4)
```

To save argparse namespace,

```python
json.dump(fp, vars(args), indent=4)
```

Any other data can be saved in same way.

## Command Line Tool (TODO)

`python -m pscp`

## pscp.create(return\_head\_on\_nothing=True, return\_format='abbrev', link=True)

Create per-session checkpoint.

* `return_head_on_nothing`: If True, return hash of `HEAD` when there are nothing changed compared to `HEAD`, otherwise, return `None`.
* `return_format`
	* `abbrev`, `short`: Return abbreviated hash.
	* `long`: Return just unabbreviated hash.
	* `ref`: Return refspec. Raises exception when link == False.
* `link`: See `pscp.link()` below.

## pscp.link(hash, refspec=None)

Create reference. `pscp.link()` could be used to avoid pruning on garbage collection.

* `hash`: The hash to be referenced.
* `refspec`: If `None`, `refs/pscp/{timestamp_ms}` is used.

## pscp.delete(refspec)

Delete pscp reference. Call `pscp.gc()` if you want.

* `refspec`: Target refspec to be deleted. `timestamp_ms` is also allowed.

## pscp.gc(prune='now')

Run `git gc --prune=<prune>`.

## pscp.push(refspec=None, repository='origin')

Push checkpoint to the remote repository.

* `refspec`: If `None`, all checkpoints are pushed.

## pscp.fetch(refspec=None, refmap=None, repository='origin')

* `refspec`: If `None`, all checkpoints are fetched.
* `refmap`: If `None`, `refs/pscp/*:refs/pscp/*` is used.


text:
Tofu Notes
==========

The most elegant and user friendly note editor for Android, now Open Source!

Overview
----------------
Tofu Notes is a note editor for the Android platform, created by [Hampus Olsson](http://dribbble.com/hampus) and [Jonathan Pettersson](http://jpettersson.com) and is released as a [Spacetofu](http://spacetofu.com) product. The application can be downloaded free of charge from [Google Play](https://play.google.com/store/apps/details?id=com.spacetofu.umlaut&hl=en).

Roadmap
-------

**Version 2.4.4**
Released: Feb 04 2014
Updates:

* Increase maximum note limit from 150 to 500.
* Announce the Tofu Notes Open Source project!
* Optimization and bugfixes for Android 4.x (Ice Cream Sandwich & Jelly Bean)

**Version 2.4.5**
Release date: TBD
Updates include:

* Export/Import notes! (To SD card)

Bugs & Feature Requests
-----------

Use the issues page to report any bugs you are experiencing while using Tofu Notes. Also feel free to request features and suggest improvements, we would love to hear your feedback!

Contributions
-------------
This is an Open Source effort and we would love some help making this app even better!

Eventually this README will include instructions and guidelines for how to contribute, but until then please contact me at [jonathan<EMAIL_ADDRESS>if you'd like to help us.

License & Copyright
-------
The Tofu Notes application source code is licensed under the [MIT License](http://opensource.org/licenses/MIT).

Brand names: "Tofu Notes" and "Spacetofu" and all logos and artworks are © 2010-2014 Hampus Olsson & Jonathan Pettersson.

repository: jpettersson/Tofu-Notes

repo_name: jpettersson/Tofu-Notes


text:
# Group BancorX

[**Modules**](modules.md)
 **>** [**BancorX**](group___bancor_x.md)

_The BancorX contract allows cross chain token transfers._ [More...](#detailed-description)

## Modules

| Type | Name |
| ---: | :--- |
| module | [**Amounts Table**](group___amounts___table.md)
_This table quantities for cross-transfers._  |
| module | [**Reporters Table**](group___reporters___table.md)
_This table stores the account names of BancorX reporters_  _!_  |
| module | [**Transfers Table**](group___tranfsers___table.md)
_This table stores transfer stats._  |
| module | [**Settings Table**](group___x_settings___table.md)
_This table stores settings for cross-transfers._  |

## Public Functions

| Type | Name |
| ---: | :--- |
|  ACTION | [**addreporter**](group___bancor_x.md#function-addreporter) (name reporter)
_adds a new reporter, can only be called by the contract account_  |
|  ACTION | [**clearamount**](group___bancor_x.md#function-clearamount) (uint64\_t x\_transfer\_id)
_closes row in amounts table, can only be called by bnt token contract or self_  |
|  ACTION | [**enablerpt**](group___bancor_x.md#function-enablerpt) (bool enable)
_can only be called by the contract account_  |
|  ACTION | [**enablext**](group___bancor_x.md#function-enablext) (bool enable)
_can only be called by the contract account_  |
|  ACTION | [**init**](group___bancor_x.md#function-init) (name x\_token\_name, uint64\_t min\_reporters, uint64\_t min\_limit, uint64\_t limit\_inc, uint64\_t max\_issue\_limit, uint64\_t max\_destroy\_limit)
_initializes the contract settings_  |
|  void | [**on\_transfer**](group___bancor_x.md#function-on-transfer) (name from, name to, asset quantity, string memo)
_transfer intercepts with standard transfer args_  |
|  ACTION | [**reporttx**](group___bancor_x.md#function-reporttx) (name reporter, string blockchain, uint64\_t tx\_id, uint64\_t x\_transfer\_id, name target, asset quantity, string memo, string data)
_reports an incoming transaction from a different blockchain_  |
|  ACTION | [**rmreporter**](group___bancor_x.md#function-rmreporter) (name reporter)
_removes an existing reporter, can only be called by the contract account_  |
|  ACTION | [**update**](group___bancor_x.md#function-update) (uint64\_t min\_reporters, uint64\_t min\_limit, uint64\_t limit\_inc, uint64\_t max\_issue\_limit, uint64\_t max\_destroy\_limit)
_updates the contract settings_  |

## Macros

| Type | Name |
| ---: | :--- |
| define  | [**EMIT\_DESTROY\_EVENT**](group___bancor_x.md#define-emit-destroy-event) (from, quantity)
_triggered when account tokens are destroyed after cross chain transfer initiation_  |
| define  | [**EMIT\_ISSUE\_EVENT**](group___bancor_x.md#define-emit-issue-event) (target, quantity)
_triggered when enough reports arrived and tokens are issued to an account and the cross chain transfer is fulfilled_  |
| define  | [**EMIT\_TX\_REPORT\_EVENT**](group___bancor_x.md#define-emit-tx-report-event) (reporter, blockchain, transaction, target, quantity, x\_transfer\_id, memo)
_triggered when a reporter reports a cross chain transfer from another blockchain_  |
| define  | [**EMIT\_X\_TRANSFER\_COMPLETE\_EVENT**](group___bancor_x.md#define-emit-x-transfer-complete-event) (target, id)
_triggered when final report is succesfully submitted_  |
| define  | [**EMIT\_X\_TRANSFER\_EVENT**](group___bancor_x.md#define-emit-x-transfer-event) (blockchain, target, quantity, id)
_triggered when an account initiates a cross chain transafer_  |

# Detailed Description

There are two processes that take place in the contract:
* Initiate a cross chain transfer to a target blockchain (destroys tokens from the caller account on EOS)
* Report a cross chain transfer initiated on a source blockchain (issues tokens to an account on EOS) Reporting cross chain transfers works similar to standard multisig contracts, meaning that multiple callers are required to report a transfer before tokens are issued to the target account.

## Public Functions Documentation

### function addreporter

```cpp
ACTION addreporter (
    name reporter
)
```

**Parameters:**

* `reporter` - name of the reporter

### function clearamount

```cpp
ACTION clearamount (
    uint64_t x_transfer_id
)
```

**Parameters:**

* `x_transfer_id` - the transfer id

### function enablerpt

```cpp
ACTION enablerpt (
    bool enable
)
```

**Parameters:**

* `enable` - true to enable reporting (and thus issuance), false to disable it

### function enablext

```cpp
ACTION enablext (
    bool enable
)
```

**Parameters:**

* `enable` - true to enable cross chain transfers, false to disable them

### function init

```cpp
ACTION init (
    name x_token_name,
    uint64_t min_reporters,
    uint64_t min_limit,
    uint64_t limit_inc,
    uint64_t max_issue_limit,
    uint64_t max_destroy_limit
)
```

can only be called once, by the contract account

**Parameters:**

* `x_token_name` - cross chain token account
* `min_reporters` - minimum required number of reporters to fulfill a cross chain transfer
* `min_limit` - minimum amount that can be transferred out (destroyed)
* `max_issue_limit` - maximum amount that can be issued on EOS in a given timespan
* `max_destroy_limit` - maximum amount that can be transferred out (destroyed) in a given timespan

### function on\_transfer

```cpp
void on_transfer (
    name from,
    name to,
    asset quantity,
    string memo
)
```

if the token received is the cross transfers token, initiates a cross transfer

**Parameters:**

* `from` - the sender of the transfer
* `to` - the receiver of the transfer
* `quantity` - the quantity for the transfer
* `memo` - the memo for the transfer

### function reporttx

```cpp
ACTION reporttx (
    name reporter,
    string blockchain,
    uint64_t tx_id,
    uint64_t x_transfer_id,
    name target,
    asset quantity,
    string memo,
    string data
)
```

can only be called by an existing reporter

**Parameters:**

* `reporter` - reporter account
* `blockchain` - name of the source blockchain
* `tx_id` - unique transaction id on the source blockchain
* `x_transfer_id` - unique (if non zero) pre-determined id (unlike \_txId which is determined after the transactions been mined)
* `target` - target account on EOS
* `quantity` - amount to issue to the target account if the minimum required number of reports is met
* `memo` - memo to pass in in the transfer action
* `data` - custom source blockchain value, usually a string representing the tx hash on the source blockchain

### function rmreporter

```cpp
ACTION rmreporter (
    name reporter
)
```

**Parameters:**

* `reporter` - name of the reporter

### function update

```cpp
ACTION update (
    uint64_t min_reporters,
    uint64_t min_limit,
    uint64_t limit_inc,
    uint64_t max_issue_limit,
    uint64_t max_destroy_limit
)
```

can only be called by the contract account

**Parameters:**

* `min_reporters` - new minimum required number of reporters
* `min_limit` - new minimum limit
* `limit_inc` - new limit increment
* `max_issue_limit` - new maximum incoming amount
* `max_destroy_limit` - new maximum outgoing amount

## Macro Definition Documentation

### define EMIT\_DESTROY\_EVENT

```cpp
#define EMIT_DESTROY_EVENT (
    from,
    quantity
) START_EVENT("destroy", "1.1") \
    EVENTKV("from",from) \
    EVENTKVL("quantity",quantity) \
    END_EVENT()
```

### define EMIT\_ISSUE\_EVENT

```cpp
#define EMIT_ISSUE_EVENT (
    target,
    quantity
) START_EVENT("issue", "1.1") \
    EVENTKV("target",target) \
    EVENTKVL("quantity",quantity) \
    END_EVENT()
```

### define EMIT\_TX\_REPORT\_EVENT

```cpp
#define EMIT_TX_REPORT_EVENT (
    reporter,
    blockchain,
    transaction,
    target,
    quantity,
    x_transfer_id,
    memo
) START_EVENT("txreport", "1.2") \
    EVENTKV("reporter",reporter) \
    EVENTKV("from_blockchain",blockchain) \
    EVENTKV("transaction",transaction) \
    EVENTKV("target",target) \
    EVENTKV("quantity",quantity) \
    EVENTKV("x_transfer_id",x_transfer_id) \
    EVENTKVL("memo",memo) \
    END_EVENT()
```

### define EMIT\_X\_TRANSFER\_COMPLETE\_EVENT

```cpp
#define EMIT_X_TRANSFER_COMPLETE_EVENT (
    target,
    id
) START_EVENT("xtransfercomplete", "1.2") \
    EVENTKV("target", target) \
    EVENTKVL("id", id) \
    END_EVENT()
```

### define EMIT\_X\_TRANSFER\_EVENT

```cpp
#define EMIT_X_TRANSFER_EVENT (
    blockchain,
    target,
    quantity,
    id
) START_EVENT("xtransfer", "1.2") \
    EVENTKV("blockchain",blockchain) \
    EVENTKV("target",target) \
    EVENTKV("quantity",quantity) \
    EVENTKVL("id",id) \
    END_EVENT()
```

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

repository: bancorprotocol/docs

gha_language: JavaScript

repo_name: bancorprotocol/docs


text:
# joda-time-fake [![Build Status](https://travis-ci.org/shibayu36/joda-time-fake-scala.svg?branch=master)](https://travis-ci.org/shibayu36/joda-time-fake-scala)

Provides utilities to fake current time gotten by [joda-time](http://www.joda.org/joda-time/).  This is useful for test.

## Getting started

Add dependency in your `build.sbt` as the following.

```scala
libraryDependencies ++= Seq(
  "com.github.shibayu36" %% "joda-time-fake" % "0.0.2"
)
```

The library is available on [Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.shibayu36/joda-time-fake_2.12).  Currently,
supported Scala versions are 2.11 and 2.12.

## Basic usage

```scala
import com.github.shibayu36.jodatimefake.FakeTimer
import org.joda.time.DateTime

// fake by millis
val result = FakeTimer.fake(1515974400000L) {
    println(DateTime.now.toString) // 2018-01-15T00:00:00.000Z
    "hoge"
}

// current time is restored after block
println(DateTime.now.toString) // current time is printed

// You can get the value returned from block
println(result) // hoge

// You can also pass DateTime instance
FakeTimer.fake(new DateTime(2018, 2, 13, 14, 59)) {

}

// You can also pass ISODateTimeFormat
FakeTimer.fake("2018-03-02T12:34:56+09:00") {

}

// If you use fakeWithTimer, a timer instance is passed to block.
// You can advance time using tick() method.
FakeTimer.fakeWithTimer(1515974400000L) { t =>
    println(DateTime.now.toString) // 2018-01-15T00:00:00.000Z
    t.tick(3000) // Advance time by 3000ms
    println(DateTime.now.toString) // 2018-01-15T00:00:03.000Z
}
```

## Caution

This library doesn't support a parallel test by thread, because org.joda.time.DateTimeUtils uses shared static variables.  Use fork if you want to test in parallel.


text:
<!-- README.md is generated from README.Rmd. Please edit that file -->
emyweather
==========

[![Travis-CI Build Status](https://travis-ci.org/kvantas/emyweather.svg?branch=master)](https://travis-ci.org/kvantas/emyweather) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/kvantas/emyweather?branch=master&svg=true)](https://ci.appveyor.com/project/kvantas/emyweather) [![minimal R version](https://img.shields.io/badge/R%3E%3D-3.4.0-6666ff.svg)](https://cran.r-project.org/) [![packageversion](https://img.shields.io/badge/Package%20version-0.2.0-orange.svg?style=flat-square)](https://github.com/kvantas/emyweather) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1159500.svg)](https://doi.org/10.5281/zenodo.1159500)

`emyweather` is an R package that contains climatic data from the [Greek National Meteorological Service](http://emy.gr), as well as a number of useful other related data sets. The climatic data come from 21 weather stations, with a time step of 3 hours and the time period is from 1975 to 2004. For more details checkout the package's [website](https://kvantas.github.io/emyweather/).

<img src="https://github.com/kvantas/emyweather/raw/master/man/figures/stations_map.png" align = "center"/>

Installation
------------

You can install emyweather from github with:

``` r
# install.packages("devtools")
devtools::install_github("kvantas/emyweather")
```

Using emyweather
----------------

This package is comprised of three data sets:

-   `emy_data`: climatic measurements
-   `emy_stations`: weather stations' coordinates and elevation
-   `borders`: borders of Greece

### `emy_data`

The variables in this data set are:

| Variable             | Description                                      |
|----------------------|--------------------------------------------------|
| date                 | The observation's date                           |
| station\_id          | Greek National Meteorological Service station ID |
| pressure             | Pressure, in hPa                                 |
| dry\_temp            | Dry temperature, in degree Celsius               |
| wet\_temp            | Wet temperature, in degree Celsius               |
| max\_temp            | Maximum temperature, in degree Celsius           |
| min\_temp            | Minimum temperature, in degree Celsius           |
| rel\_humidity        | Relative humidity, in percent                    |
| wind\_direction      | Wind direction, in degrees                       |
| wind\_force\_knot    | Wind force, in knots                             |
| visibility           | Visibility, in km                                |
| total\_cloud\_amount | Total cloud amount, in values 0 to 9             |
| precipitation        | Precipitation height, in mm                      |

Please note that these time series are not checked for consistency or errors.

### `emy_stations`

The stations' data are taken from the Greek National Data Bank for Hydrological and Meteorological Information, [Hydroscope](http://www.hydroscope.gr/) using the package [`hydroscoper`](https://github.com/ropensci/hydroscoper/blob/master/vignettes/intro_hydroscoper.Rmd). The variables are:

| Variable        | Description                                        |
|-----------------|----------------------------------------------------|
| name            | The station's name                                 |
| station\_id     | Greek National Meteorological Service station ID   |
| hydroscope\_id  | The station's ID from kyy.hydroscope.gr database   |
| water\_division | The station's Water Division                       |
| longitude       | The station's longitude in decimal degrees, ETRS89 |
| latitude        | The station's latitude in decimal degrees, ETRS89  |
| altitude        | The station's altitude, meters above sea level     |

### `borders`

The borders of Greece are taken from Geoadata.gov.gr. The variables are created using the function `tidy` from the [`broom`](https://cran.r-project.org/web/packages/broom/index.html) package for use with `geom_polygon` from [`ggplot2`](https://cran.r-project.org/web/packages/ggplot2/).

Meta
----

-   Please [report any issues or bugs](https://github.com/kvantas/emyweather/issues).
-   Licence:
    -   All code is licensed MIT.
    -   All data are from the open data sources in <http://www.emy.gr/>.
-   To cite `emyweather` in publications, please use:

          Vantas, (2018). emyweather: R package with open climatic data from the Greek National
          Meteorological Service, URL: https://github.com/kvantas/emyweather,
          DOI:http://doi.org/10.5281/zenodo.1159500

    A BibTeX entry for LaTeX users is

        @Manual{ vantas2018emy,
        author = {Konstantinos Vantas},
        title = {{emyweather}: R package with open climatic data from the Greek National Meteorological Service},
        doi = {10.5281/zenodo.1159500},
        year = {2018},
        note = {R package version 0.2.0},
        url = {https://github.com/kvantas/emyweather},
          }

-   Please note that this project is released with a [Contributor Code of Conduct](/CONDUCT.md). By participating in this project you agree to abide by its terms.

References
----------

-   [GEODATA.gov.gr](http://geodata.gov.gr/)
-   [Hydroscope](http://www.hydroscope.gr/)
-   [National Meteorological Service](http://www.emy.gr/)

repository: kvantas/emyweather

repo_name: kvantas/emyweather


text:
# Singleton Design Pattern

## Implementation

### 1. Eager initialization

* If the program will always need an instance, or if the cost of creating the instance is not too large in terms of time/resources, the programmer can switch to eager initialization, which **always creates an instance when the class is loaded into the JVM.**

```java
public class Singleton {

    // Static member holds only one instance of the Singleton class
    private static Singleton sInstance = new Singleton();

    // Singleton prevents any other class from instantiating
    private Singleton() {
    }

    // static getter
    public static Singleton getInstance() {
        return sInstance;
    }
}
```

* **Static block initialization**

The main advantage of using the static block here is that it supports the options for exception handling for the instantiation of the singleton class.

```java
public class Singleton {

    // Static member holds only one instance of the Singleton class
    private static Singleton sInstance;
    static {
        try {
            sInstance = new Singleton();
        } catch (IOException e) {
            throw new RuntimeException("An error occurred!", e);
        }
    }
    // Singleton prevents any other class from instantiating
    private Singleton() {
    }

    // static getter
    public static Singleton getInstance() {
        return sInstance;
    }
}
```
### 2. Lazy initialization

```java
public class Singleton {

    // private static instance
    private static Singleton sInstance;

    // private constructor for prevent outside initialization
    private Singleton() {
    }

    // static getter
    public static Singleton getInstance() {
        if (null == sInstance) {
            sInstance = new Singleton();
        }
        return sInstance;
    }
}
```

_When your application runs multithread, your code can be paused at any line within any time. So maybe two threads can run into two initialization blocks_

In the multithreading environment to prevent each thread to create another instance of singleton object and thus creating concurrency issue we will need to use locking mechanism. This can be achieved by synchronized keyword.

```java
public static synchronized Singleton getInstance() {
    if (null == sInstance) {
        sInstance = new Singleton();
    }
    return sInstance;
}
```

Every time the getInstance() is called it gives us an additional overhead.

**HOW TO AVOID THIS**

* **Double Check Locking Design Pattern**

```java
public static Singleton getInstance() {
    if (null == sInstance) {
        // block so other threads cannot come into while initialize
        synchronized (Singleton.class) {
            // recheck again. maybe another thread has initialized before
            if (null == sInstance) {
                sInstance = new Singleton();
            }
        }
    }
    return sInstance;
}
```

You know what **above code won’t work for Java**. I'm not jokking, many of you (including me) have implemented like that over, and over, and over again.

Here is why, please read those link below carefully:
- [The "Double-Checked Locking is Broken" Declaration](http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html)
- [Double-checked locking](https://en.wikipedia.org/wiki/Double-checked_locking)

**How to fix:** simply use **volatile** keyword. And here is a true version of Double Check Locking pattern:

```java
public class Singleton {

    // adding volatile keyword here
    private static volatile Singleton sInstance;

    private Singleton() {
    }

    public static Singleton getInstance() {
        // using local variable for storing volatile object
        // for increasing performance
        Singleton result = sInstance;
        if (result == null) {
            synchronized (Singleton.class) {
                result = sInstance;
                if (result == null) {
                    sInstance = result =  new Singleton();
                }
            }
        }
        return result;
    }
}
```

Note the local variable "`result`", which seems unnecessary. The effect of this is that in cases where `sInstance` is already initialized (i.e., most of the time), the volatile field is only accessed once (due to "`return result;`" instead of "`return sInstance;`"), which can improve the method's overall performance by as much as 25 percent.

* **Initialization-on-demand holder idiom**

```java
public class Singleton {

    private Singleton() {
    }

    // create a static nested class
    public static class Helper {
        public static Singleton searchBox = new Singleton();
    }

    public static Singleton getsInstance() {
        return Helper.searchBox;
    }

}
```

Java ensures thread-safe property for static class loader. So when one thread is initialized object using class Helper, no other threads can come and create another object.

Above method also ensures lazy initialization property. Static instance field is initialized no earlier than SingletonHolder class is loaded and initialized. SingletonHolder class in its turn is loaded and initialized no earlier than it is first referenced. Finally SingletonHolder class is first referenced no earlier than getSingletonInstance() method is called. And this is exactly what we need.

* **Enum**

```java
public enum Singleton {

    // and just call Singleton.INSTANCE
    // no private constructor. no getInstance
    INSTANCE;
```

> This approach is functionally equivalent to the public field approach, except that it is more concise, provides the serialization machinery for free, and provides an ironclad guarantee against multiple instantiation, even in the face of sophisticated serialization or reflection attacks. While this approach has yet to be widely adopted, **a single-element enum type is the best way to implement a singleton.**

## Serialization problem:

Serialization allows storing the object in some data store and re-create it later on. However when we serialize a singleton class and invoke deserialization multiple times, we can end up with multiple objects of the singleton class.

In order to make serialization and singleton work properly, we have to introduce readResolve() method in the singleton class. readResolve() method lets developer control what object should be returned  on deserialization.

```java
// This method is called immediately after an object of this class is deserialized.
protected Object readResolve() {
    // Instead of the object we’re on, return the class variable singleton
    return sInstance;
}
```

## Cloning Problem

Although we have taken enough precaution to make the Singleton object work as singleton, Cloning the object can still copy it and result into duplicate object. The clone of the singleton object can be constructed using clone() method of the object. Hence it is advisable to overload clone() method of Object class and throw CloneNotSupportedException exception.

```java
public Object clone() throws CloneNotSupportedException {
   throw new CloneNotSupportedException();
}
```

---
## Inspiration

* Inspired by [Huỳnh Quang Thảo](https://blog.androidcafe.in/@huynhquangthao) and his article about Singleton Design Pattern on Medium. You can check it [here](https://blog.androidcafe.in/singleton-design-pattern-2c63dfcfccf2).

* Also reference [Singleton Design Pattern](https://javarevealed.wordpress.com/tag/singleton-and-serialization/).

repository: phamducminh/Today-I-Learned

repo_name: phamducminh/Today-I-Learned


text:
# cidr-house-rules
[![Build Status](https://travis-ci.org/trulia/cidr-house-rules.svg)](https://travis-ci.org/trulia/cidr-house-rules)

A lightweight API and collection system to centralize important AWS resource information across multiple accounts in near-realtime

![cidr-house-rules](https://user-images.githubusercontent.com/538171/37231223-3ee8eda2-239f-11e8-8ca6-6cb58da11d48.png)

#### Collection subsystem

Centralized AWS Lambda functions assume role on monitored AWS accounts to collect the following:

* [NAT Gateway IPs](https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-nat-gateway.html) with associated VPCs and environment tags
* [EIPs](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html)
* [VPC CIDR blocks](https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/working-with-vpcs.html) (including associated CIDR blocks)
* [Classic ELBs](http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/introduction.html)
* [ALBs, NLBs (elbv2)](https://aws.amazon.com/documentation/elastic-load-balancing/)
* Available IPv4 Addresses per subnet (Note that the IPv4 addresses for any stopped instances are considered unavailable)

Items collected into Dynamodb will expire if no longer found (default is 48 hours). TTLs are controlled via environment variables passed to each import function. TTL time is expressed in seconds. It is a calculation of current time + TTL. Each import related DynamoDB table leverages [TTL](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html) for object expiration

##### Collection subsystem runner process

The above noted cidr-house-rules collection functions are triggered by a [runner function](https://github.com/trulia/cidr-house-rules/blob/master/runner.py) which invokes the necessary number of
import functions based upon the number of AWS accounts managed and number of regions provided by AWS. The runner process allows for cidr-house-rules to scale given any number of AWS accounts to collect information from.

###### Import functions invokation visual

![import-function-invoke](https://user-images.githubusercontent.com/538171/37374885-71c37074-26da-11e8-9531-182c228088a9.png)

#### API interface

An API interface is provided to expose collected data for consumption. Example usage is through Terraform's [http data source](https://www.terraform.io/docs/providers/http/data_source.html)

* retrieve all NAT Gateways for a given AWS account (team)
* retrieve all EIPs for a given AWS account (team)
* lookup a given CIDR block, i.e. <IP_ADDRESS>/16 for potential VPC peering conflicts

#### Terraform modules that use cidr-house-rules for dynamic data

* [Dynamic NAT Gateway Security Group Terraform Module](https://github.com/trulia/cidr-house-rules-terraform-nat-gateway-sg)

#### Deployment

1. Requires [serverless-aws-documentation plugin](https://www.npmjs.com/package/serverless-aws-documentation)
2. Pick an AWS account to deploy cidr-house-rules to.
3. On remote accounts applying the supporting terraform see link below to generate role access
4. With roles generated on remote accounts you can now move serverless.yml.example to serverless.yml and add your target account roles
5. Run ```serverless deploy --stage prod```

#### Onboarding new AWS accounts

1. Apply the following Terraform and obtain outputs

```hcl
provider "aws" {
  region = "us-west-2"
}

module "cidr-house-rules-role" {
  cidr_house_rules_account_number = "123456770"
  serverless_stage                = "prod"
  serverless_region               = "us-west-2"
  source                          = "git::ssh://git@github.com/trulia/cidr-house-rules-role.git?ref=v0.0.1"
}

output "account_alias" {
  value = "${module.cidr-house-rules-role.account_alias}"
}

output "account_id" {
  value = "${module.cidr-house-rules-role.account_id}"
}

output "cidr-house-rules-role" {
  value = "${module.cidr-house-rules-role.cidr-house-rules-role}"
}
```

2. With the account_alias, account_id to app

```bash
curl \
  --header "X-Api-Key: <GET_KEY_FROM_AWS_API_GATEWAY>" \
  https://yourapigateway-endpoint-generated-by-serverless.com/prod/add_account?team=trucomms?account=35682931234
```

3. Add the role for Lambda functions to use in serverless.yml

```
Under this section add the new role, there should be a list of them already
iamRoleStatements:
  - Effect: Allow
    Action: sts:AssumeRole
    Resource:
      arn:aws:iam::<remote_aws_account_number_here>:role/role_cidr_house
```

4. Run deployment job in Jenkins noted in the "Deployment" section

#### Example API calls

##### Obtain NAT gateways for platform, webteam and dataeng teams

```bash
curl \
  --header "X-Api-Key: <GET_KEY_FROM_AWS_API_GATEWAY>" \
   https://yourapigateway-endpoint-generated-by-serverless.com/prod/get_nat_gateways_for_team?platform&webteam&dataeng

# Or just one team
curl \
  --header "X-Api-Key: <GET_KEY_FROM_AWS_API_GATEWAY>" \
  https://yourapigateway-endpoint-generated-by-serverless.com/prod/get_nat_gateways_for_team?team=platform
```

##### Obtain NAT gateways for all monitored accounts

```bash
curl \
  --header "X-Api-Key: <GET_KEY_FROM_AWS_API_GATEWAY>" \
   https://yourapigateway-endpoint-generated-by-serverless.com/prod/get_nat_gateways_for_all
```

##### Obtain number of result pages for NAT gatways, useful for Terraform to count out resources on

```bash
# Default is 50 results per page
curl --header "X-Api-Key: <GET_KEY_FROM_AWS_API_GATEWAY>" 'https://yourapigateway-endpoint-generated-by-serverless.com/prod/get_number_of_nat_gateway_pages'
```

```bash
# Request number of results per page to be 10, and return total number of pages
curl --header "X-Api-Key: <GET_KEY_FROM_AWS_API_GATEWAY>" 'https://yourapigateway-endpoint-generated-by-serverless.com/prod/get_number_of_nat_gateway_pages?results_per_page=10'
```

##### Obtain paged results of Nat gateways results

```bash
curl --header "X-Api-Key: <GET_KEY_FROM_AWS_API_GATEWAY>" 'https://yourapigateway-endpoint-generated-by-serverless.com/prod/get_nat_gateways_for_all?results_per_page=10&page=4'
```

##### Check for a VPC CIDR conflict

```bash
curl \
  --header "X-Api-Key: <GET_KEY_FROM_AWS_API_GATEWAY>" \
  https://yourapigateway-endpoint-generated-by-serverless.com/dev/check_conflict?cidr=<IP_ADDRESS>/16
```

##### Obtain all ELBs, ALBs, NLBs across all accounts

```bash
curl \
--header "X-Api-Key: <GET_KEY_FROM_AWS_API_GATEWAY>" \
https://yourapigateway-endpoint-generated-by-serverless.com/dev/get_elbs_for_all
```

##### Obtain all PrivateLink endpoint services across all accounts

```bash
curl \
--header "X-Api-Key: <GET_KEY_FROM_AWS_API_GATEWAY>" \
https://yourapigateway-endpoint-generated-by-serverless.com/dev/get_service_endpoints_for_all
```

##### Obtain a specific PrivateLink endpoint service based upon the "Name" tag of an NLB associated with it. (AWS presently doesn't allow tagging of PrivateLink endpoint services, so next best option is to use tags of NLB associated with PrivateLink)

```bash
curl \
--header "X-Api-Key: <GET_KEY_FROM_AWS_API_GATEWAY>" \
https://yourapigateway-endpoint-generated-by-serverless.com/dev/get_service_endpoints_for_nlb?nlb=my-nlb
```

##### Add a new account

```bash
curl \
  --header "X-Api-Key: <GET_KEY_FROM_AWS_API_GATEWAY>" \
  https://yourapigateway-endpoint-generated-by-serverless.com/dev/add_account?team=my_aws_account_alias_here&account=35682931234
```

#####  Supporting Terraform

[cird-house-rules-role](https://github.com/trulia/cidr-house-rules-role) - use this Terraform on your accounts you would like your cidr-house-rules deployment to have access to. The outputs on this Terraform can then be used in your serverless.yml. The account number of the remote account can then be added using the `add_account` API endpoint.

repository: trulia/cidr-house-rules

gha_language: Python

repo_name: trulia/cidr-house-rules


text:
# Ophiostoma arborea (Olchow. & J. Reid) Yamaoka & M.J. Wingf., 1997 SPECIES

#### Status
SYNONYM

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

#### Published in
in Yamaoka, Wingfield, Takahashi & Solheim, Mycol. Res. 101(10): 1223 (1997)

#### Original name
Ceratocystis arborea Olchow. & J. Reid, 1974

### Remarks
null

repository: mdoering/backbone

path: /life/Fungi/Ascomycota/Sordariomycetes/Microascales/Ceratocystidaceae/Ceratocystis/Ceratocystis arborea/ Syn. Ophiostoma arborea/README.md

repo_name: mdoering/backbone


text:
# Astra Server
Input example: `http://<IP_ADDRESS>:8080/?x=5&y=-8&z=-3`

Response example: `{
    "Name": "GOES",
    "Velocity": "4430 m/s",
    "Image": "https://img.favpng.com/25/16/15/geostationary-operational-environmental-satellite-weather-satellite-goes-16-png-favpng-04VEAEATWNL6fFi5YAQRsy9jZ.jp",
    "ResourceID": "spase://SMWG/Observatory/GOES",
    "ResourceName": "Geostationary Operational Environmental Satellites",
    "Description": "GOES is a series of NASA-developed, NOAA-operated, geosynchronous, and operational spacecraft."
}`

repository: AstraApp/AstraBackend

repo_name: AstraApp/AstraBackend


text:
# Installing Harbor Scanner Adapter for Sysdig Secure

This guide explains how to install Harbor Scanner Adapter for Sysdig Secure.

## Prerequisites

* Kubernetes >= 1.14
* Harbor >= 1.10
* Helm >= 3
* A Sysdig Secure API Token

### Obtaining the Sysdig Secure API Token

Once you have your Sysdig Secure account, you need to login and go to your
settings. Is just below the Get Started sidebar item.

![Getting Secure API Token](images/getting_secure_api_token.png)

## Deploying on Kubernetes using the Helm Chart

The fastest way to deploy the scanner adapter is using the Helm Chart we
provide. Be aware that you need to provide the Sysdig Secure API token when
you type the `helm install` command.

```
$ helm repo add sysdiglabs https://sysdiglabs.github.io/charts
"sysdiglabs" has been added to your repositories

$ kubectl create namespace harbor-scanner-sysdig-secure
namespace/harbor-scanner-sysdig-secure created

$ helm -n harbor-scanner-sysdig-secure install harbor-scanner-sysdig-secure --set sysdig.secure.apiToken=XXX sysdiglabs/harbor-scanner-sysdig-secure
NAME: harbor-scanner-sysdig-secure
LAST DEPLOYED: Tue Jun  9 13:38:12 2020
NAMESPACE: harbor-scanner-sysdig-secure
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:

export POD_NAME=$(kubectl get pods --namespace harbor-scanner-sysdig-secure -l "app.kubernetes.io/name=harbor-scanner-sysdig-secure,app.kubernetes.io/instance=harbor-scanner-sysdig-secure" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://<IP_ADDRESS>:8080 to use your application"
kubectl --namespace harbor-scanner-sysdig-secure port-forward $POD_NAME 8080:80
```

And that's it. The new scanner adapter is deployed. Now is time to tell Harbor
to use it, and you can find [how to configure Harbor to use Sysdig Secure Scanner Adapter](#configuring-harbor-to-use-sysdig-secure-scanner-adapter) a few lines below.

### Using Backend Scanning instead of Inline Scanning

This mode is not recommended and it is supported only for legacy purposes.

You will need to disable inline scan by setting `inlineScanning.enabled: false` in the values.yaml:

```yaml
sysdig:
  secure:
    apiToken: XXX

inlineScanning:
  enabled: false
```

You already know [how to get the Sysdig Secure API Token](#obtaining-the-sysdig-secure-api-token).

## Configuring Harbor to use Sysdig Secure Scanner Adapter

Once the Helm Chart is deployed, is time to configure Harbor to use the scanner
adapter. You need to add it under Interrogation Services. Click on New Scanner
button and fill the details:

Use the service that Helm Chart creates as endpoint, and to make sure it can be
reached click on Test Connection button.

![Adding Sysdig Secure to Harbor Interrogation Services](images/add_secure_to_harbor.png)

Final step is to select Sysdig Secure scanner and set it as default. You can
check the **Default** label appears next to the scanner's name.

![Set Secure as default scanner](images/secure_as_default_harbor_ui.png)

repository: JianfuYang/harbor-scanner-sysdig-secure

repo_name: JianfuYang/harbor-scanner-sysdig-secure


text:
---
title: MetaICVI.jl
subtitle: A Julia package for the MetaICVI method.
layout: single
date: 2023-07-10

categories: ["projects"]
tags: [
    "Julia",
    "ICVI",
    "MetaICVI"
]
summary: The MetaICVI method is implemented as a Julia package.

header:
    teaser: "/assets/posts/clustering.png"
    caption: "Clustering"

---

![Clustering icon from https://www.flaticon.com/free-icon/clustering_8847040](/assets/posts/clustering.png)

[`MetaICVI.jl`](https://github.com/AP6YC/MetaICVI.jl) is a Julia implementation of the [MetaICVI method](https://doi.org/10.36227/techrxiv.21685214) ([documentation here](https://ap6yc.github.io/MetaICVI.jl/dev/)).
The package a registered [JuliaHub](https://juliahub.com/ui/Packages/MetaICVI/N0cWm) package.

The `MetaICVI.jl` package is represented in the following locations:

- [GitHub](https://github.com/AP6YC/MetaICVI.jl)
- [Documentation](https://ap6yc.github.io/MetaICVI.jl/dev/)
- [JuliaHub](https://juliahub.com/ui/Packages/MetaICVI/N0cWm)

The project can be cited with the following BibTex entry:

```bibtex
@article{Melton2022,
  author = "Niklas Melton and Sasha Petrenko and Donald Wunsch",
  title = "{Meta-iCVIs: Ensemble Validity Metrics for Concise Labeling of Correct, Under- or Over-Partitioning in Streaming Clustering}",
  year = "2022",
  month = "12",
  url = "https://doi.org/10.36227/techrxiv.21685214",
  doi = "10.36227/techrxiv.21685214"
}
```

## Attribution

The image for this post is taken from the following:

- [Clustering icons created by Paul J. - Flaticon](https://www.flaticon.com/free-icons/clustering)([clustering_8847040](https://www.flaticon.com/free-icon/clustering_8847040))

branch_name: refs/heads/main


text:
# FlowUploadFilter
.Net MVC 5 Flow JS Filter

This is a MVC 5 pre-action filter that will handle uploads from the [Flow.js](https://github.com/flowjs) library.

## Install
` PM> Install-Package FlowUploadFilter `

## Usage
```csharp
using System.Net;
using System.Web.Mvc;
using FlowUploadFilter;
using WebGrease.Css.Extensions;

namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        [HttpPost]
        [FlowUpload("pdf","txt")]
        [ActionName("Upload")]
        public ActionResult Upload(FlowFile file)
        {
            return Json(new {derp=file.flowFilename});
        }
    }
}
```

The filter works by recognizing that `FlowFile` type is a paramater of the Action. When a 'chunk' from flow.js
come in it will check to see if that chunk completes the file, if it does not it will accept the chunk, save it then respond
with an accepted http status and skip execution of the actual Action. When the final chunk is recieved it will hydrate the FlowFile parameter
of the Action and let excution of the Action proceed. Paramater name is not important, only the Parameter type. The filter uses Temp storage.

The chunk handling is based off of [Dimitry Efimenko's](https://github.com/DmitryEfimenko) [FlowJs-MVC](https://github.com/DmitryEfimenko/FlowJs-MVC)

repository: Grummle/FlowUploadFilter

gha_language: C#

repo_name: Grummle/FlowUploadFilter


text:
[Unchase Swashbuckle Asp.Net Core Extensions](https://www.nuget.org/packages/Unchase.Swashbuckle.AspNetCore.Extensions/) is a library contains a bunch of extensions (filters) for [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore).

> The project is developed and maintained by [Nikolay Chebotov (**Unchase**)](https://github.com/unchase).

## Breaking Changes

* Since [v2.0.0](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/releases/tag/v2.0.0) supports [Swashbuckle.AspNetCore 5.0.0](https://www.nuget.org/packages/Swashbuckle.AspNetCore/) with **breaking changes**.

For old versions see [README_OLD.md](README_OLD.md).

* Since [v2.3.0](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/releases/tag/v2.3.0) there are [**breaking changes**](#breaking-changes-2.3.0) in `Startup.cs`

### Compatibility

|Swashbuckle Version|ASP.NET Core|Swagger / OpenAPI Spec.|This extension Version|
|:------------------|:-----------|:----------------------|:---------------------|
|[master](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/tree/master/README.md)|>= 2.0.0|2.0, 3.0|[master](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/tree/master/README.md)|
|[6.1.5](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/tree/v6.1.5)|>= 2.0.0|2.0, 3.0|[v2.6.1](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/tree/v2.6.1/README.md)|
|[6.1.0](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/tree/v6.1.0)|>= 2.0.0|2.0, 3.0|[v2.6.0](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/tree/v2.6.0/README.md)|
|[6.0.0](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/tree/v6.0.0)|>= 2.0.0|2.0, 3.0|[v2.5.1](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/tree/v2.5.1/README.md)|
|[5.0.0](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/tree/v5.0.0)|>= 2.0.0|2.0, 3.0|[v2.0.0](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/tree/v2.0.0/README.md)|
|[4.0.0](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/tree/v4.0.0)|>= 2.0.0, < 3.0.0|2.0|[v1.1.4](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/tree/v1.1.4/README.md)|

## Getting Started

To use the extensions, install [*NuGet* package](https://www.nuget.org/packages/Unchase.Swashbuckle.AspNetCore.Extensions/) into your project:

#### Manually with the *NuGet* Package Manager:

```powershell
Install-Package Unchase.Swashbuckle.AspNetCore.Extensions
```

#### Using the .NET CLI:

```powershell
dotnet add package Unchase.Swashbuckle.AspNetCore.Extensions --version {version}
```

> Where {version} is the version of the package you want to install.
> For example, `dotnet add package Unchase.Swashbuckle.AspNetCore.Extensions --version 2.4.0`

Then use whichever extensions (filters) you need.

## Extensions (Filters) use

Ensure your API actions and parameters are decorated with explicit **"Http"** and **"From"** (optional) bindings.

```csharp
[HttpPost]
public void CreateProduct([FromBody]Product product)
...
```

```csharp
[HttpGet]
public IEnumerable<Product> SearchProducts([FromQuery]string keywords)
...
```

In the `Configure` method, insert middleware to expose the generated Swagger as JSON endpoint(s):

```csharp
app.UseSwagger();
```

Optionally, insert the swagger-ui middleware if you want to expose interactive documentation, specifying the Swagger JSON endpoint(s) to power it from:

```csharp
app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
```

1. **Fix enums in OpenApi document**:
- In the _ConfigureServices_ method of _Startup.cs_, inside your `AddSwaggerGen` call, enable whichever extensions (filters) you need:

```csharp
using Unchase.Swashbuckle.AspNetCore.Extensions.Extensions;
using Unchase.Swashbuckle.AspNetCore.Extensions.Filters;
```

*  Since [v2.3.0](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/releases/tag/v2.3.0):

```csharp
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddControllers();

    // Register the Swagger generator
    services.AddSwaggerGen(options =>
    {
        options.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });

        // use it if you want to hide Paths and Definitions from OpenApi documentation correctly
        options.UseAllOfToExtendReferenceSchemas();

        // if you want to add xml comments from summary and remarks into the swagger documentation, first of all add:
        // you can exclude remarks for concrete types
        var xmlFilePath = Path.Combine(AppContext.BaseDirectory, "WebApi3.1-Swashbuckle.xml");
        options.IncludeXmlCommentsWithRemarks(xmlFilePath, false,
            typeof(ComplicatedClass),
            typeof(InnerEnum));

        // or add without remarks
        //options.IncludeXmlComments(xmlFilePath);

        // if you want to add xml comments from inheritdocs (from summary and remarks) into the swagger documentation, add:
        // you can exclude remarks for concrete types
        options.IncludeXmlCommentsFromInheritDocs(includeRemarks: true, excludedTypes: typeof(string));

        // Add filters to fix enums
        // use by default:
        //options.AddEnumsWithValuesFixFilters();

        // or configured:
        options.AddEnumsWithValuesFixFilters(services, o =>
        {
            // add schema filter to fix enums (add 'x-enumNames' for NSwag or its alias from XEnumNamesAlias) in schema
            o.ApplySchemaFilter = true;

            // alias for replacing 'x-enumNames' in swagger document
            o.XEnumNamesAlias = "x-enum-varnames";

            // alias for replacing 'x-enumDescriptions' in swagger document
            o.XEnumDescriptionsAlias = "x-enum-descriptions";

            // add parameter filter to fix enums (add 'x-enumNames' for NSwag or its alias from XEnumNamesAlias) in schema parameters
            o.ApplyParameterFilter = true;

            // add document filter to fix enums displaying in swagger document
            o.ApplyDocumentFilter = true;

            // add descriptions from DescriptionAttribute or xml-comments to fix enums (add 'x-enumDescriptions' or its alias from XEnumDescriptionsAlias for schema extensions) for applied filters
            o.IncludeDescriptions = true;

            // add remarks for descriptions from xml-comments
            o.IncludeXEnumRemarks = true;

            // get descriptions from DescriptionAttribute then from xml-comments
            o.DescriptionSource = DescriptionSources.DescriptionAttributesThenXmlComments;

            // new line for enum values descriptions
            // o.NewLine = Environment.NewLine;
            o.NewLine = "\n";

            // get descriptions from xml-file comments on the specified path
            // should use "options.IncludeXmlComments(xmlFilePath);" before
            o.IncludeXmlCommentsFrom(xmlFilePath);
            // the same for another xml-files...
        });
    });
}
```

* For older versions:

```csharp
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddMvc();

    services.AddSwaggerGen(options =>
    {
        options.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });

        // if you want to add xml comments into the swagger documentation, first of all add:
        var filePath = Path.Combine(AppContext.BaseDirectory, "WebApi3.1-Swashbuckle.xml");
        options.IncludeXmlComments(filePath);

        // Add filters to fix enums
        options.AddEnumsWithValuesFixFilters(true);

        // or custom use:
        //options.SchemaFilter<XEnumNamesSchemaFilter>(true); // add schema filter to fix enums (add 'x-enumNames' for NSwag) in schema
        //options.ParameterFilter<XEnumNamesParameterFilter>(true); // add parameter filter to fix enums (add 'x-enumNames' for NSwag) in schema parameters
        //options.DocumentFilter<DisplayEnumsWithValuesDocumentFilter>(true); // add document filter to fix enums displaying in swagger document
    });
}
```

2. **Hide Paths and Definitions from OpenApi documentation** without accepted roles:
- In the _ConfigureServices_ method of _Startup.cs_, inside your `AddSwaggerGen` call, enable `HidePathsAndDefinitionsByRolesDocumentFilter` document filter:

```csharp
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddSwaggerGen(options =>
    {
        ...

        // remove Paths and Defenitions from OpenApi documentation without accepted roles
        options.DocumentFilter<HidePathsAndDefinitionsByRolesDocumentFilter>(new List<string> { "AcceptedRole" });
    });
}
```

- Since [v2.2.1](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/releases/tag/v2.2.1) you can hide Paths and Definitions from OpenApi documentation for specific controller action (or all actions) without accepted roles like this:

```csharp
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    //...

    // enable middleware to serve generated Swagger as a JSON endpoint.
    app.UseSwagger(c =>
    {
        c.PreSerializeFilters.Add((openApiDoc, httpRequest) =>
        {
            // remove Paths and Components from OpenApi documentation for specific controller action without accepted roles
            openApiDoc.RemovePathsAndComponentsWithoutAcceptedRolesFor<SomeController>(controller => nameof(controller.SomeAction), new List<string> {"AcceptedRole"});

            // or
            //openApiDoc.RemovePathsAndComponentsWithoutAcceptedRolesFor<SomeController>(nameof(SomeController.SomeAction), new List<string> { "AcceptedRole" });

            // remove Paths and Components from OpenApi documentation for all controller actions without accepted roles
            openApiDoc.RemovePathsAndComponentsWithoutAcceptedRolesForController<AnotherController>(new List<string> {"AcceptedRole"});

            // or you can get accepted roles by httpRequest like this:
            //openApiDoc.RemovePathsAndComponentsWithoutAcceptedRolesForController<AnotherController>(GetAcceptedRolesByRemoteIp(httpRequest.HttpContext.Connection.RemoteIpAddress));
        });
    });

    //...
}
```

Validated actions must be annotated with the one of `HttpMethodAttribute` (`HttpGetAttribute`, `HttpPostAttribute`, `HttpDeleteAttribute`, `HttpPutAttribute`, `HttpPatchAttribute`) attributes.

3. **Append action count into the SwaggetTag's descriptions in OpenApi document**:
- In the _ConfigureServices_ method of _Startup.cs_, inside your `AddSwaggerGen` call, enable `AppendActionCountToTagSummaryDocumentFilter` document filter:

```csharp
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddSwaggerGen(options =>
    {
        ...

        // enable openApi Annotations
        options.EnableAnnotations();

        // add action count (with message template) into the SwaggerTag's descriptions
        // you can use it after "HidePathsAndDefinitionsByRolesDocumentFilter"
        options.DocumentFilter<AppendActionCountToTagSummaryDocumentFilter>("(count: {0})");

        ...
    });
}
```

In the controller need to use `SwaggerTag` attribute:

```csharp
using Swashbuckle.AspNetCore.Annotations;
```

```csharp
[SwaggerTag("Controller for todo")]
public class TodoController : ControllerBase
...
```

4. **Change all responses for specific HTTP status codes in OpenApi document**:
- In the _ConfigureServices_ method of _Startup.cs_, inside your `AddSwaggerGen` call, enable `ChangeAllResponsesByHttpStatusCode<T>` extension (filter) with whichever HTTP status codes you need:

```csharp
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddSwaggerGen(options =>
    {
        ...

        // change responses for specific HTTP status code ("200")
        options.ChangeAllResponsesByHttpStatusCode(
            httpStatusCode: 200,
            responseDescription: "200 status code description",
            responseExampleOption : ResponseExampleOptions.AddNew, // add new response examples
            responseExample: new TodoItem { Tag = Tag.Workout, Id = 111, IsComplete = false, Name = "test" }); // some class for response examples

        // change responses for specific HTTP status code ("400" (HttpStatusCode.BadRequest))
        options.ChangeAllResponsesByHttpStatusCode(
            httpStatusCode: HttpStatusCode.BadRequest,
            responseDescription: "400 status code description",
            responseExampleOption: ResponseExampleOptions.Clear, // claer response examples
            responseExample: new ComplicatedClass()); // some class for response examples

        // change responses for specific HTTP status code ("201" (StatusCodes.Status201Created))
        options.ChangeAllResponsesByHttpStatusCode(
            httpStatusCode: StatusCodes.Status201Created,
            responseDescription: "201 status code description",
            responseExampleOption: ResponseExampleOptions.None, // do nothing with response examples
            responseExample: new ComplicatedClass()); // some class for response examples

        ...
    });
}
```

5. **Order tags by name in OpenApi document**:
- In the _ConfigureServices_ method of _Startup.cs_, inside your `AddSwaggerGen` call, enable `TagOrderByNameDocumentFilter` document filter:

```csharp
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddSwaggerGen(options =>
    {
        ...

        // order tags by name
        options.DocumentFilter<TagOrderByNameDocumentFilter>();

        ...
    });
}
```

6. **Add xml comments from summary and remarks into the swagger documentation**:

- Since [v2.4.0](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/releases/tag/v2.4.0) in the _ConfigureServices_ method of _Startup.cs_, inside your `AddSwaggerGen` call, add `IncludeXmlCommentsWithRemarks` option instead of `IncludeXmlComments` option:

```csharp
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddSwaggerGen(options =>
    {
        ...

        // add xml comments from summary and remarks into the swagger documentation
        options.IncludeXmlCommentsWithRemarks("<xml_File_Full_Path>");

        // add xml comments from summary and remarks into the swagger documentation
        // with excluding remarks for concrete types (since v2.4.1)
        var xmlFilePath = Path.Combine(AppContext.BaseDirectory, "WebApi3.1-Swashbuckle.xml");
        options.IncludeXmlCommentsWithRemarks(xmlFilePath, false,
            typeof(ComplicatedClass),
            typeof(InnerEnum));

        ...
    });
}
```

7. **Add xml comments from <inheritdoc/> (from summary and remarks) into the swagger documentation**:

- Since [v2.5.0](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/releases/tag/v2.5.0) in the _ConfigureServices_ method of _Startup.cs_, inside your `AddSwaggerGen` call, add `IncludeXmlCommentsFromInheritDocs` option:

```csharp
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddSwaggerGen(options =>
    {
        ...

        // add xml comments from inheritdocs (from summary and remarks) into the swagger documentation, add:
        // with excluding concrete types
        options.IncludeXmlCommentsFromInheritDocs(includeRemarks: true, excludedTypes: typeof(string));

        ...
    });
}
```

## Builds status

|Status|Value|
|:-----|:---:|
|Build|[![Build status](https://ci.appveyor.com/api/projects/status/els72xabgex9lntc)](https://ci.appveyor.com/project/unchase/unchase-swashbuckle-aspnetcore-extensions)
|Tests|[![Build Tests](https://img.shields.io/appveyor/tests/unchase/unchase-swashbuckle-aspnetcore-extensions.svg)](https://ci.appveyor.com/project/unchase/unchase-swashbuckle-aspnetcore-extensions/build/tests)
|Buid History|![Build history](https://buildstats.info/appveyor/chart/unchase/unchase-swashbuckle-aspnetcore-extensions)
|GitHub Release|[![GitHub release](https://img.shields.io/github/release/unchase/unchase.swashbuckle.aspnetcore.extensions.svg)](https://github.com/unchase/unchase.swashbuckle.aspnetcore.extensions/releases/latest)
|GitHub Release Date|[![GitHub Release Date](https://img.shields.io/github/release-date/unchase/unchase.swashbuckle.aspnetcore.extensions.svg)](https://github.com/unchase/unchase.swashbuckle.aspnetcore.extensions/releases/latest)
|GitHub Release Downloads|[![Github Releases](https://img.shields.io/github/downloads/unchase/unchase.swashbuckle.aspnetcore.extensions/total.svg)](https://github.com/unchase/unchase.swashbuckle.aspnetcore.extensions/releases/latest)
|Nuget Version|[![NuGet Version](http://img.shields.io/nuget/v/Unchase.Swashbuckle.AspNetCore.Extensions.svg?style=flat)](https://www.nuget.org/packages/Unchase.Swashbuckle.AspNetCore.Extensions/)
|Nuget Downloads|[![Nuget Downloads](https://img.shields.io/nuget/dt/Unchase.Swashbuckle.AspNetCore.Extensions.svg)](https://www.nuget.org/packages/Unchase.Swashbuckle.AspNetCore.Extensions/)

## Features

### Fix enums

- Add an output enums integer values with there strings like `0 = FirstEnumValue` without a `StringEnumConverter` in swaggerUI and schema (by default enums will output only their integer values)
- Add description to each enum value that has an `[Description]` attribute in `swaggerUI` and schema - should use *options.DocumentFilter\<DisplayEnumsWithValuesDocumentFilter\>(**true**);* or *options.AddEnumsWithValuesFixFilters(**true**);*

    In [`Swashbuckle SwaggerUI`](https://github.com/domaindrivendev/Swashbuckle):

    ![Enum Description in SwaggerUI](assets/enumDescriptionInSwaggerUI.png)

    In schema `parameters`:

    ![Enum Description in Schema Parameters](assets/enumDescriptionInSchemaParameters.png)

    In schema `definitions`:

    ![Enum Description in Schema Definitions](assets/enumDescriptionInSchemaDefinitions.png)

    To show enum values descriptions you should use `[Description]` attribute in your code:

    ```csharp
    /// <summary>
    /// Title enum.
    /// </summary>
    [DataContract]
    public enum Title
    {
        /// <summary>
        /// None.
        /// </summary>
        [Description("None enum description")]
        [EnumMember]
        None = 0,

        /// <summary>
        /// Miss.
        /// </summary>
        [Description("Miss enum description")]
        [EnumMember]
        Miss,

        /// <summary>
        /// Mr.
        /// </summary>
        [Description("Mr enum description")]
        [EnumMember]
        Mr
    }

    ...

    /// <summary>
    /// Sample Person request and response.
    /// </summary>
    public class SamplePersonRequestResponse
    {
        /// <summary>
        /// Sample Person title.
        /// </summary>
        public Title Title { get; set; }

        /// <summary>
        /// Sample Person age.
        /// </summary>
        public int Age { get; set; }

        /// <summary>
        /// Sample Person firstname.
        /// </summary>
        [Description("The first name of the person")]
        public string FirstName { get; set; }

        /// <summary>
        /// Sample Person income.
        /// </summary>
        public decimal? Income { get; set; }
    }
    ```
 - Fix enum values in generated by [`NSwagStudio`](https://github.com/RicoSuter/NSwag/wiki/NSwagStudio) or [Unchase OpenAPI Connected Service](https://marketplace.visualstudio.com/items?itemName=Unchase.unchaseopenapiconnectedservice) client classes:

    ```csharp
    /// <summary>Sample Person title.
    ///
    /// 0 = None (None enum description)
    ///
    /// 1 = Miss (Miss enum description)
    ///
    /// 2 = Mr (Mr enum description)</summary>
    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "<IP_ADDRESS> (Newtonsoft.Json v<IP_ADDRESS>)")]
    public enum Title
    {
        None = 0,

        Miss = 1,

        Mr = 2,

    }
    ```

### Hide Paths and Defenitions from OpenApi documentation

- Hide all OpenAPIDocument **Paths** and **Defenitions** without accepted roles:

    ![Hide SwaggerDocument PathItems](assets/hideSwaggerDocumentPathItems.png)

    You should use `AuthorizeAttribute` for methods or controllers:

    ```csharp
    ...
    public class SamplePersonController : ControllerBase
    {
        // this method will not be hidden with using 'swaggerDoc.HidePathItemsWithoutAcceptedRoles(new List<string> {"AcceptedRole"});'
        [Authorize(Roles = "AcceptedRole")]
        [HttpGet]
        public ActionResult<SamplePersonRequestResponse> Get(Title title)
        {
            ...
        }

        // this method will be hidden with using 'swaggerDoc.HidePathItemsWithoutAcceptedRoles(new List<string> {"AcceptedRole"});'
        [Authorize(Roles = "NotAcceptedRole")]
        [HttpPost]
        public ActionResult<SamplePersonRequestResponse> Post([FromBody] SamplePersonRequestResponse request)
        {
            ...
        }
    }
    ```

### Append action count into the SwaggetTag's descriptions

![Append action count](assets/appendActionCountIntoSwaggerTag.png)

You should use `SwaggerTagAttribute` for controllers:

```csharp
[SwaggerTag("SamplePerson description")]
public class SamplePersonController : ControllerBase
{
    ...
}
```

### Change responses for specific HTTP status codes

For example:

![Change responses](assets/changeResponsesByHttpStatusCode.png)

### Add xml comments from summary and remarks into the swagger documentation

![Add xml comments from summary and remarks](assets/addXmlCommentsFromSummaryAndRemarks.png)

For code:

```csharp
/// <summary>
/// Inner class
/// </summary>
/// <remarks>
/// Inner class remarks - class
/// </remarks>
public class InnerClass
{
    /// <summary>
    /// List of inner enums
    /// </summary>
    /// <remarks>
    /// List of inner enums remarks - property
    /// </remarks>
    public List<InnerEnum> InnerEnum { get; set; }

    /// <summary>
    /// Second inner class
    /// </summary>
    /// <remarks>
    /// Second inner class remarks - property
    /// </remarks>
    public SecondInnerClass<SecondInnerEnum> SecondInnerClass { get; set; }
}

/// <summary>
/// Inner enum
/// </summary>
/// <remarks>
/// Inner enum remarks - enum
/// </remarks>
public enum InnerEnum
{
    /// <summary>
    /// Inner enum value
    /// </summary>
    /// <remarks>
    /// Inner enum value remarks
    /// </remarks>
    Value = 1
}

/// <summary>
/// Second inner class
/// </summary>
/// <remarks>
/// Second inner class remarks - class
/// </remarks>
public class SecondInnerClass<T> where T : Enum
{
    /// <summary>
    /// Second inner enum
    /// </summary>
    /// <remarks>
    /// Second inner enum remarks - property
    /// </remarks>
    public T InnerEnum { get; set; }
}

/// <summary>
/// Second inner enum
/// </summary>
/// <remarks>
/// Second inner enum remarks - enum
/// </remarks>
public enum SecondInnerEnum
{
    /// <summary>
    /// Second inner enum value
    /// </summary>
    /// <remarks>
    /// Second inner enum value remarks
    /// </remarks>
    Value = 0
}
```

### Add xml comments from <inheritdoc/> (from summary and remarks) into the swagger documentation

![Add xml comments from ingeritdoc](assets/addXmlCommentsFromInheritdoc.png)

For code:

```csharp
/// <inheritdoc cref="IInheritDocClass"/>
public class InheritDocClass : IInheritDocClass
{
    /// <inheritdoc/>
    public string Name { get; set; }

    /// <inheritdoc/>
    public string Common { get; set; }

    /// <inheritdoc/>
    public InheritEnum InheritEnum { get; set; }
}

/// <summary>
/// InheritDocClass - inheritdoc
/// </summary>
/// <remarks>
/// InheritDocClass remarks - inheritdoc
/// </remarks>
public interface IInheritDocClass : IInheritDocCommon
{
    /// <summary>
    /// Name - inheritdoc
    /// </summary>
    /// <remarks>
    /// Name remarks - inheritdoc
    /// </remarks>
    public string Name { get; set; }
}

/// <summary>
/// IInheritDocCommon interface
/// </summary>
/// <remarks>
/// IInheritDocCommon interface remarks
/// </remarks>
public interface IInheritDocCommon
{
    /// <summary>
    /// Common - inheritdoc (inner)
    /// </summary>
    /// <remarks>
    /// Common remarks - inheritdoc (inner)
    /// </remarks>
    public string Common { get; set; }

    /// <summary>
    /// InheritEnum - inheritdoc (inner)
    /// </summary>
    public InheritEnum InheritEnum { get; set; }
}

/// <summary>
/// Inherit enum - enum
/// </summary>
/// <remarks>
/// Inherit enum remarks - enum
/// </remarks>
public enum InheritEnum
{
    /// <summary>
    /// Inherit enum Value
    /// </summary>
    /// <remarks>
    /// Inherit enum Value remarks
    /// </remarks>
    Value = 0
}
```

## HowTos

- [ ] Add HowTos in a future
- [ ] ... [request for HowTo you need](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/issues/new?title=DOC)

## Roadmap

See the [changelog](CHANGELOG.md) for the further development plans and version history.

## Feedback

Please feel free to add your [request a feature](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/issues/new?title=FEATURE) or [report a bug](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/issues/new?title=BUG). Thank you in advance!

## Thank me!

If you like what I am doing and you would like to thank me, please consider:

[![Buy me a coffe!](assets/buymeacoffe.png)](https://www.buymeacoffee.com/nikolaychebotov)

Thank you for your support!

----------

Copyright © 2019 [Nikolay Chebotov (**Unchase**)](https://github.com/unchase) - Provided under the [Apache License 2.0](LICENSE).


text:
# Inceptor.js

[![Build Status](https://travis-ci.org/Nercury/inceptor-js.svg?branch=master)](https://travis-ci.org/Nercury/inceptor-js)
[![Coverage Status](https://coveralls.io/repos/Nercury/inceptor-js/badge.svg?branch=master&service=github)](https://coveralls.io/github/Nercury/inceptor-js?branch=master)
[![npm version](https://badge.fury.io/js/inceptor.svg)](https://badge.fury.io/js/inceptor)

[![Sauce Test Status](https://saucelabs.com/browser-matrix/nercury.svg)](https://saucelabs.com/u/nercury)

## Ownership-driven dependency injection for JavaScript

Usually, dependency injection frameworks rely on central container
to retrieve dependencies.

In contrast, this ownership-driven approach spawn __scopes__ when
these dependencies are created.

## Features:

- Very small (5kb minified).
- Does not depend on any other library.
- Works everywhere! Both node.js and browser are supported.
- Re-uses familiar loading mechanisms such as `requirejs` or node's `require`.
- Does not need string names to map objects.
- Code is well-tested.
- Scopes can be tested in isolation without dependency map.
- Once dependency map is used, it becomes immutable.
- No global variables or containers!

## How does it work?

This container turns the problem on its head: instead of creating a dependency when your code requests it, __Inceptor.js__ does the reverse.

It runs your code when all dependencies are created.

Let's look at simple example.

Suppose we have a simple __logger__ that logs our messages to multiple __backends__.

In traditional DI, we would inject the __backends__ into the __logger__ constructor.

Here, we do the reverse: we tell the __backend__ to require the __logger__.

Let's see the code for __logger__:

```js
var Logger = inceptor.scope({
    initialize: function() {
        this.backends = [];
    },

    log: function(message) {
        for (var i = 0; i < this.backends.length; i++) {
            this.backends[i].log(message);
        }
    }
});
```

Here, we achieved the abstraction: the __logger__ knows nothing about the __backends__, the only thing it requires is that they implement the `log()` method.

Let's see the code for __backend__:

```js
var Backend = inceptor.scope([Logger], {
    initialize: function(logger) {
        logger.backends.push(this);
    },

    log: function(message) {
        console.log(message);
    }
});
```

Here, the __backend__ receives the __logger__ over the first argument, and adds itself to the list.

Somewhere at the root of the project, we add both the `Logger` and the `Backend` to dependency map:

```js
var deps = inceptor.load(
    Logger,
    Backend,
);
```

And later create the logger using this map:

```js
var logger = deps.create(Logger);
logger.log('Hello!');
```

Receive the `Hello!` in console!

If we later need a different `Backend` implementation, or want to silence the logs, we don't need to touch the __logger__, just modify the backend.

So, we have achieved what is required from the dependency injection.

The big difference here is that lifetime of all objects spawned by logger depend directly on the lifetime of logger. If a new logger is created, the whole tree of dependent objects is created too.

## Usage in frameworks

Intrigued? See how it can be used in your environment:

- [Use Inceptor.js with RequireJs](/) [TODO]
- [Use Inceptor.js in Node.js](/) [TODO]
- [Browse the annotated source.](docs/inceptor.html)

## License

MIT

repository: Nercury/inceptor-js

repo_name: Nercury/inceptor-js


text:
# just-this-once
A dependency-free HOTP and TOTP implementation that can be used for Two-Factor Auth.

Uses/requires Node v8+.

## HOTP/TOTP 101

HOTP and TOTP are protocols used for generating and verifying one-time passwords. They are often used for 2FA (e.g. Google Authenticator). In both cases, a secret is shared between the server and the client. This secret is then used to generate a passcode client-side which can be independently verified by the server.

HOTP makes use of the secret together with a counter in order to generate the passcode. The counter should be incremented every time that a passcode is generated/verified, and thus prevents replay attacks. However, this leads to issues around keeping the server's counter synced with the client's counter.

TOTP improves on HOTP by replacing the counter with the current time - or, more precisely, the number of time-steps that have passed since some start time - in order to avoid having to keep the counter synced between client and server.

HOTP Spec: https://tools.ietf.org/html/rfc4226

TOTP Spec: https://tools.ietf.org/html/rfc6238

## Example

Let's consider using just-this-once on the server to allow two-factor auth via a TOTP. The flow is:

- A user/client enables 2FA, so the server generates a secret and sends it to the client.
- The client puts the secret into a client-side TOTP generator such as Google Authenticator.
- Later on, when the client tries to log in or access some protected resource, the server requests a passcode.
- The client gets a passcode from their TOTP generator and sends it to the server.
- The server can then verify the passcode and allow/disallow access to the resource.

Ok, to enable 2FA for the client, let's generate a client-specific secret server-side:

```javascript
const secret = generateSecret(16);  // 16 bytes for the secret; returns base32-encoded string

sendSecretToClient(secret);
saveSecretToDB(secret);
```

The client puts this secret into their TOTP passcode generator. Then, at some later point when the client requests access to some protected resource, we need to verify the passcode they send:
```javascript
const secret = getFromDB();
const candidatePasscode = getFromClientRequest();

const isPasscodeValid = verifyTOTP(candidatePasscode, secret, Date.now());
```

If `isPasscodeValid` is `false` then the login/request should be rejected. And that's it!

## Usage

Just-this-once exposes 5 functions: `generateHOTP`, `verifyHOTP`, `generateTOTP`, `verifyTOTP`, and `generateSecret`.

### Secrets

`generateHOTP`, `verifyHOTP`, `generateTOTP`, and `verifyTOTP` all require a secret in order to generate/verify passcodes. The secret can be passed in as either a Buffer or an encoded string. The accepted encodings are 'base32', 'urlsafe-base64', 'base64', or 'hex'. The specific encoding used can be specified in the optional options object (see below), and the default is 'base32'.

### Options

`generateHOTP`, `verifyHOTP`, `generateTOTP`, and `verifyTOTP` all accept an optional `options` object. All fields in the options object are optional; and the defaults match those used by most popular implementations including Google Authenticator.

NB: All times passed into the TOTP functions should be numbers expressed in milliseconds.

```
{
    encoding: <string - one of 'base32', 'urlsafe-base64', 'base64', 'hex'; default: 'base32'>,
    codeLength: <positive integer; default: 6>,
    // these are only used for TOTP:
    hashFunction: <string - one of 'sha1', 'sha256', 'sha512'; default: 'sha1'>,
    startTime: <positive integer; default: 0>,
    timeStep: <positive integer; default: 30000>,
    verifyWithOneTimeStep: <boolean; default: false>
}
```

`encoding` - this is the encoding used to decode the secret (if passing the secret as a Buffer, this will be ignored)

`codeLength` - this is the length of the passcode

`hashFunction` - this is the hash function used in the process of generating the passcodes

`startTime` - this is the start time in milliseconds used in TOTP in order to calculate the time-based counter

`timeStep` - this is the time-step in milliseconds used in TOTP in order to calculate the time-based counter

`verifyWithOneTimeStep` - due to the possibility that the clocks between the client and the server are slightly out of sync (and also due to the non-zero amount of time required to transmit the candidate passcode from the client to the server), it's common for implementations to give a leeway of +1/-1 time-step when verifying the TOTP code. This implementation also defaults to verifying using +1/-1 time-step, but that behaviour can be used off by setting `verifyWithOneTimeStep` to `true`

### generateHOTP(secret, counter, options)
### verifyHOTP(candidate, secret, counter, options)

Used to generate/verify a HOTP passcode.

`secret`, `options` - See above

`counter` - A non-negative integer used to generate the passcode. It should be incremented on each request.

`candidate` - A string containing the candidate passcode to be verified.

### generateTOTP(secret, time, options)
### verifyTOTP(candidate, secret, time, options)

Used to generate/verify a TOTP passcode.

`secret`, `options` - See above

`time` - The current time, expressed in milliseconds. (i.e. Unix time, except milliseconds are used rather than seconds)

`candidate` - A string containing the candidate passcode to be verified.

### generateSecret(numBytes, encoding)

Used to generate a cryptographically strong pseudo-random secret. Returns an encoded string.

`numBytes` - the number of bytes used to generate the secret

`encoding` - this is the encoding used to encode the secret. Can be one of 'base32', 'urlsafe-base64', 'base64', or 'hex'.

## TODO

- Use ArrayBuffer in place of Buffer so that this can be used outside of Node. For crypto functions:
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
- Use TypeScript to do input validation

repository: BYossarian/just-this-once

repo_name: BYossarian/just-this-once


text:
# m3cpy
A dead simple .m3u file extractor

## Usage
```
λ m3cpy.exe

Usage: m3cpy --m3u=<path-to-m3u> --out=<path-to-output-folder>
Options:
         -f, --m3u: Path to m3u file.
         -o, --out: Path to output folder.
               -rm: Attempt to remove the original once it has been copied.
         --replace: Replace the file if it already exists.
    -h, -?, --help: Display help.
      -v,--verbose: Toggle verbose mode.
```

## Notes
 * Does not support http:// URIs, nor any URI but file:// in fact.
 * Should handle and warn you about filesystem rights issues
 * Not tested on GNU/Linux. The biggest issue might be that the required .Net assembly is 4.5, but Mono should handle it.

## License
m3cpy is licensed under the MIT License.


text:
---
layout: post
title: Attention with Transformer
output: pdf_document
usemathjax: true
---

The aim of this post is to describe the original Transformer architecture in details, and then provide a flavour of the subsequent transformations (:P) of the model. This post could be math heavy, so a friendlier version of this post will be attempted in an upcoming post.

# Motivation

The Transformer architecture aims to address the problem of [Sequence Transduction](https://arxiv.org/abs/1211.3711), which involves transformation of input sequences to output sequences e.g. machine translation, speech recognition, text-to-speech. Transformers map sequences of input vectors $(x_1, ..., x_n)$ to sequences of output vectors $(y_1, ... , y_n)$ of the same length.

Transformers can be any sequence based model that primarily uses *self-attention* to propagate information along the time dimension.

# Self-attention

Self-attention allows a network to directly extract and use information from arbitrarily large contexts (unlike RNNs which would need to pass it through intermediate recurrent connections).

Self-attention can manifest in multiple forms, namely *Encoder-Decoder attention*, *Causal self-attention* and *Bi-directional self-attention*.

## Encoder-Decoder attention

One sentence (decoder) looks at another sentence (encoder) e.g. in a Machine Translation model where a French sentence looks at an English sentence.

## Causal (or masked) self-attention

In a given sentence, words only look at previous words e.g. in autoregressive text generation (summarization). In this case,
- the model has access to information about inputs upto and including the current input, but no information regarding the inputs beyond.
- the computation performed for each item is independent of other computations. This means we can parallelize the forward inference and training of these models.

## Bi-directional self-attention

In one sentence, words look at both previous and upcoming words. This mechanism is used in models like BERT and T5 (these will be discussed later).

# Causal self-attention in detail

Attention, at its core,

Simple attention calculation

$$
similarity\_score (x_i, x_j) = x_i \cdot x_j
$$

This dot product results in a scalar value, $ -\infty < similarity\_score (x_i, x_j) < \infty$, so a softmax normalization can be applied to map the values to $[0,1]$ and to ensure that it sums to $1$ over the entire sequence.

$$ w_{i, j} = softmax(similarity\_score(x_i, x_j)) \quad \forall j \leq i\\
 = \frac{exp(similarity\_score(x_i, x_j))}{\sum_{k=1}^i exp(similarity\_score(x_i, x_j))} \quad \forall j \leq i
$$

$$
y_i = \sum_{j \leq i} w_{i,j} x_j
$$

## Query, Key and Value parameters

$$ q_i = W^Q x_i; \quad k_i = W^K x_i; \quad v_i = W^V x_i $$

$$ score(x_i, x_j) = q_i \cdot k_j $$

$$ y_i = \sum_{j \leq i} \alpha_{i, j} v_j $$

$$ score(x_i, x_j) = \frac{q_i \cdot k_j}{\sqrt{d_k}} $$

## Final formulation

$$ Q = W^Q X; \quad K = W^K X; \quad V = W^D X $$

$$ SelfAttention(Q, K, V) = \text{softmax} (\frac{Q K^T}{\sqrt{d_k}}) V $$

# Model Architecture

## Masking

In case of autoregressive models, masking makes the Transformer models causal. This is so that it does not know the upcoming value from the training data, but instead only care about the earlier positions in the output sequence. Masking should be done in the decoder.

## Positional Embedding

To ensure that Transformer cares about the order of words.

## Positional Encoding

Encodings created through some funcitons that map the positions to some real valued vectors. A well chosen function could mean that the transformer is able to deal with sequence lengths longer that the ones it has seen during training.

# Knowledge Check

1. What is an autoregressive model?
2. Why do we need to normalize the comparison score between two word embeddings?
3. What is the difference between an encoding and an embedding?
4. Is multi-head attention > simple attention? Why?

# References

[1] Peter Bloem, Transformers From Scratch
[2] Daniel Jurafsky & James Martin, Deep Learning Architectures for Sequence Processing


text:
# magicDateExtension

### Introduction

Make your life easier than before with magicDateExtension just type Date().
and control+spacebar will bring everything you need.

Useful date and time format

    README DATE FORMAT

    y = 2014            E,EE,EEE = Wed
    yy = 14             EEEE     = Wednesday
    yyy = 2014          EEEEE    = W
    yyyy = 2014         EEEEEE   = We

    M = 7
    MM = 07
    MMM = Jul
    MMMM = July

    d = 4
    dd = 04

    README TIME FORMAT

    h = 1-12 based hour
    H = 0-23 based hour

    m = minute at least 1 digit
    mm = minute at least 2 digit

    s = second at least 1 digit
    ss = second at least 2 digit

    S, SS = fractional second (Tenths place)
    SSS = fractional second (Tenths, hundredths and thousanths place)

### Installation

Create new file name dateExtension.swift then copy all the code into that
file and build project then you good to go.

### How To use

**1)  GET CURRENT DATE AND/OR TIME WITH CUSTOM FORMAT**

  * currentDateTime(with stringFormat: String) -> String

        Example: Date().currentDateTime(with "dd/MM/yyyy")

**2)  REFORMAT DATE OR DATE STRING TO ANOTHER DATE STRING FORMAT**

  * reFormat(with dateString: String, toFormat: String) -> String

        Example: Date().reFormat(with "23-10-2018", toFormat: "dd/MM/yyyy")

  * reFormat(with date: Date, toFormat: String) -> String

        Example: Date().reFormat(with Date, toFormat: "dd/MM/yyyy")

  * dateFrom(string: String) -> Date

        Example: Date().dateFrom(string: "23/10/2018")

**3)  CALCULATE ESTIMATE TIME WITH INPUT MINUTE**

  * estimateTime(min: Int, withFormat: String) -> String

        Example: Date().estimateTime(min: 20, withFormat: "dd/MM/yyyy HH:mm:ss")
        This will return current time + 20 minute as input format

## License ##

MIT License

Copyright (c) 2018 Chantanat Sensupa

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: magicspring/magicDateExtension

repo_name: magicspring/magicDateExtension