text:
## Testing openmonero

[Googletest](https://github.com/google/googletest) and
[googlemock](https://github.com/google/googletest/tree/master/googlemock)
frameworks are used for unit testing of openmonero. There is no need
to install them, as they are provided with openmonero.

### MySQL setup

Testing openmonero's operations on MySQL database are performed using
actuall mysql database. For this purpose a testing database with
some pre-populated data is used: `openmonero_test`. Thus before
tests are run, make sure that `openmonero_test` database is initilized
using `openmonero/sql/openmonero_test.sql` file, and `database_test` contains
information on conneting to the test database in
`openmonero/config/config.json`.

### Compile and run openmonero  tests

```bash
# go into build folder of openmonero
cd openmonero/build

# indicate that test should be build
cmake -DBUILD_TESTS=ON ..

# compile openmonero with tests
make

# run all tests
make test

# the above command will produce summary of test results (shown below).
# for verbose output, the following command can use used
# make test ARGS=-V

# individual tests executables can also be run. they are located in
# openmonero/build/tests

```

Example test output is:

```bash
mwo@arch:build$ make test
Running tests...
Test project /home/mwo/openmonero/build
    Start 1: mysql_tests
1/4 Test #1: mysql_tests ......................   Passed   60.64 sec
    Start 2: microcore_tests
2/4 Test #2: microcore_tests ..................   Passed    1.67 sec
    Start 3: bcstatus_tests
3/4 Test #3: bcstatus_tests ...................   Passed   25.39 sec
    Start 4: txsearch_tests
4/4 Test #4: txsearch_tests ...................   Passed    1.04 sec

100% tests passed, 0 tests failed out of 4

Total Test time (real) =  88.79 sec
```

repository: moneroexamples/generic-xmr-scanner

repo_name: moneroexamples/generic-xmr-scanner


text:
# midway-schedule

[![Package Quality](http://npm.packagequality.com/shield/midway-schedule.svg)](http://packagequality.com/#?package=midway-schedule)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)

this is a sub package for midway.

Document: [https://midwayjs.org/midway](https://midwayjs.org/midway)

## Config

Midway has enabled this plugin by default.

```js
// plugin.ts(js)
exports.schedulePlus = {
  enable: true,
  package: 'midway-schedule'
}
```

## Detail

The schedule of midway is based on [egg schedule](https://eggjs.org/en/basics/schedule.html), and provide more typescript and decorator support. The task can store in any file like `src/schedule`, it can be configured the properties and specify jobs. For example:

```typescript
// src/schedule/hello.ts
import { provide, schedule, CommonSchedule } from 'midway';

@provide()
@schedule({
  interval: 2333, // 2.333s interval
  type: 'worker', // only run in certain worker
})
export class HelloCron implements CommonSchedule {
  // The detail job while times up
  async exec(ctx) {
    ctx.logger.info(process.pid, 'hello');
  }
}
```

It is recommended to use `CommonSchedule` interface to standardize your schedule class.

## About run schedule

Egg provides the app.runSchedule method to test the scheduled task. The parameters of the midway are different. The format of the midway parameter is `ioc id#className`.

Take the example of the `HelloCron` class above.

```js
app.runSchedule('helloCron#HelloCron');
```

Please see our test case for more detail.

## License

[MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))

license: MIT

repository: AsJoy/midway

branch_name: refs/heads/master

extension: md

gha_language: TypeScript

gha_license_id: MIT

license_type: permissive

repo_name: AsJoy/midway


text:
### Swag
#### Stickers
* Rush order from Alaska Serigraphics $.60/each for 50 2x2 die cut

### Sending out a monthly newsletter
	Purpose: Show developers that there is an active programming community with events happening. Spread awareness about events for developers to participate in. Get attendance for events. Promote other groups working in tech that would like to build a following. Even if there are no events, send a newsletter letting people know that there are no events and we will be taking a break until the next event.

#### When: At the beginning of the month.
    1. Gather events, date, time, description, location from:
    	1. #allianceorganizers (slack)
    	2. Code for Anchorage - Brendan Babb<EMAIL_ADDRESS>		3. VMUG - Jeremy Mayfield (slack)
		4. UAA CS club - Link Larson (slack)
		5. UAF CS Club - Matt Perry (slack)
		6. Log into mailchimp
		7. Duplicate a previous month’s newsletter
		8. Update the Title
		9. Update the subject
		10. UPDATE THE URL (this is very easy to miss)
		11. Update the twitter / Facebook / Social posts
		12. Update the description with important events to emphasize
		13. Upload a photo from the last event
		14. Update the list of events
		15. Schedule to send Tuesday-Thursday afternoon from 1-3pm.

repository: akdevalliance/about

repo_name: akdevalliance/about


text:
## Generate services in the 'srv' folder
add_service_files(
   FILES
   GetADevice.srv
   GetAllDevices.srv
   GetCanMSG.srv
)

#add_message_files(
 # FILES
#)

## Generate added messages and services with any dependencies listed here
generate_messages(
   DEPENDENCIES
   std_msgs
   can_msgs
)

when making a message containing custom types such as std_msgs and can_msgs, you need to specify types in the generate_messages(DEPENDENCIES ...) object.


text:
# trollclassmates
Want to troll your classmates? If all the computers have the same login creds and SSH listening, now you can.

## What does it do?
This tool allows you to:
* Set a network (IP/Range)
* Specify login credentials
* Specify a command to execute
* Try to log into every host of that network range with the login credentials and execute the specified command

## Usage
`bash trollclassmates.sh`

## Options
* `1-Install dependencies`
* `2-Start trolling`
* `99-Exit`

repository: javiervidrua/trollclassmates

branch_name: refs/heads/main

repo_name: javiervidrua/trollclassmates


text:
# BMI Calculator GUI

## Aim:
Calculate BMI ratio

## Purpose:
It's main purpose is to calculate the Body Mass Index Ratio of a person and tell whether the person is healthy, underweight, overweight or obesity.

## Description:
Here with the help of tkinter module I had designed a helpful system for calculating the Body Mass Index Ratio. The user will enter his/her age, gender, height(in cm) and weight(in kg). The system will calculate and show the BMI of the person and will also tell that the person is underweight, healthy, overweight or obesity.

## Workflow:
As soon as, we run the program a splash screen appears which will last for 4 sec. only and then automatically the main screen will launch(the input screen). At the input screen the user will enter his/her details like age, select his gender, then the user will enter his/her height(in cm) and weight(in kg).
When the person click on Calculate a window will appear which will show the BMI ratio of the person by calculating it as per the formula given below:
w=weight(in kg)
m=height(in m)
bmi=w/(m*m)

The user can even reset the entries by using the reset button.
Then, finally by using the exit button the person can close the application.

## Input:
![InputScreen](https://user-images.githubusercontent.com/77405013/122948904-e1b29900-d398-11eb-81a3-d31bec26cadf.png)

## Output:
![CalculatedValue](https://user-images.githubusercontent.com/77405013/122948832-d65f6d80-d398-11eb-8aea-c59abd8db6e3.png)

## FirstScreen and ExitScreen
![FirstScreen](https://user-images.githubusercontent.com/77405013/122949198-16beeb80-d399-11eb-97d0-77a03f881592.png)
![ExitScreen](https://user-images.githubusercontent.com/77405013/122949259-22121700-d399-11eb-9d67-6da3fc26ea84.png)

## Functioning of the program
https://user-images.githubusercontent.com/77405013/122972482-d453d980-d3ad-11eb-92d6-2087021d0467.mp4

## Author:
Prathima Kadari


text:
# List of things to learn

[![Join the chat at https://gitter.im/drvinceknight/list-of-dev-things](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/drvinceknight/list-of-dev-things?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

A repository containing lists of concepts, tutorials etc to be able to do development.

I often take on students at the beginning of their coding 'careers' and this
repository is meant to be a list of things that they should learn/take a look at
before getting started. **Pull
requests welcome**.

In general the development I do is either for [sagemath](http://sagemath.org/)
or to build [python](https://www.python.org/) libraries.

## General concepts

Here are some basic language agnostic things:

### Text editor

Get a good text editor.

- I like to use [vim](http://www.vim.org/) but this has been historically referred to as having a steep
  learning curve. The plugins and ability to work right in the terminal are a
  huge strengths.
- Here are three other options if you prefer to make use of your mouse:
    - [atom](https://atom.io/) - has a bunch of plugins and can be hacked easily
      using css etc...
    - [sublime](http://www.sublimetext.com/) - a favorite of many. I can't say
      I've used it myself.
    - [geany](http://www.geany.org/) - friendly though mighty and cross-platform.

There are various other options (please do add them via pull request).

**Choose a good editor and most importanly realise that it is a very powerful
tool that (if you have chosen a good one) will do far more than just edit
text.**

### Terminal

The terminal is an interface to your computer that allows you to do a variety of
things through text based commands. This might seem archaic but once you are
used to it you will not want to use anything else. Developing a graphical user
interface is a step that a lot of great software has not taken so you would be
surprised by the amount of great tools available to you on the _command line_
(another word for terminal).

If you are using a linux machine you are probably familiar with a good terminal
tool. If you are using Mac OS then take a look at
[iterm2](https://www.iterm2.com/).
If you are using Windows take a look at the section at the end of this file that
is about [using Windows](#windows).

[Here](http://cli.learncodethehardway.org/book/) is a good tutorial.

### Git and github

When doing software development you need to use a 'version control' system.
This allows you to keep track of what you're doing and also to 'merge' your
changes in to the changes of others.

The most popular version control system at the moment is one called
[git](https://git-scm.com/). It comes with a bit of a learning curve but here
are some videos/tutorial to get you started.

This is probably worth reading first (it gives an overall description of what
version control is):

- [The git parable](http://tom.preston-werner.com/2009/05/19/the-git-parable.html)

Here are some tutorials:

- [Pro Git](https://progit.org/)
- [What's so good about git](https://www.youtube.com/watch?v=OiiZIVb-rZ4)
- [Advanced git](https://www.youtube.com/watch?v=4EOZvow1mk4)

Although you'll want to become proficient at driving Git via the command line,
it can often be useful to have a graphical tool for those occasions when you are
uncertain of the correct command.
[SourceTree](https://www.atlassian.com/software/sourcetree/overview) is a free,
cross platform desktop Git client which you may find useful.

When using git it is helpful to have 'remote repositories' a good place for this
is a website called [github](https://github.com/). This is used by coders all
over the world to share code (and easily contribute to other's code).

It is worth setting up an account on github. Here are a few things that might be
helpful:

- [Don't be afraid to
  commit](https://dont-be-afraid-to-commit.readthedocs.org/en/latest/)
- [Contributing to the Axelrod
  library](https://www.youtube.com/watch?v=5kOUVdktxAo)

If you are a student then sign up for github's [Student Pack](https://education.github.com/pack)
### Testing

When writing code it is very important to write automated tests. This is a good
book that takes you through the concepts for Django and Python:
[http://chimera.labs.oreilly.com/books/1234000000754](http://chimera.labs.oreilly.com/books/1234000000754)
but I need to find some better (smaller tutorials).

When using tests and github it's great to also use
[travis](https://travis-ci.org/).

### Markup languages

Markdown is a language worth learning to be able to neatly write on github
issues etc...

- [This video](https://www.youtube.com/watch?v=6A5EpqqDOdk) is probably the
  easiest way to do this (note that you will just write markdown in your
  preferred editor).
- You can also read the [github flavoured markdown
  documentation](https://help.github.com/articles/github-flavored-markdown/).

There are various other markup languages (html, LaTeX, rest etc...) but I do not
consider them to be fundamental (they will be listed where relevant in this
repository).

### Windows

If you are using Windows, you have several choices for your terminal program:

- The original Command Prompt runs commands and scripts in the MS-DOS scripting
  language. It's old, but there's lots of material online to help you
- When you install the [windows git client](https://git-scm.com/download/win)
  you will also get a git-bash client which gives a good command line
  environment.
- Windows Powershell is built into all modern versions of Windows and gives you
  a far superior, modern, object-oriented scripting language and a far better
  terminal.
- [ConEmu](https://conemu.github.io/) is a very powerful, free and open source
  terminal program.
- If you want to use a Linux based interface to your Windows machine, you can
  install [Cygwin](https://www.cygwin.com/) which will give you most of the
  common Linux tools and commands.

[This blog post by John
Cook](http://www.johndcook.com/blog/2015/06/01/unix-like-shells-on-windows/)
gives a good overview of some of the above.

If you are using Windows, you should definitely use the [Anaconda distribution
of Python](https://www.continuum.io/downloads#_windows). You almost certainly
want to use Python 3 (check with whoever you are working with).

You could also use [cloud.sagemath](https://cloud.sagemath.com/) which gives you
a linux environment in the cloud with a terminal, text editor and various other
things, it is discussed in the section on [using the cloud](#using-the-cloud).

For your text editor, both [atom](https://atom.io/),
[sublime](http://www.sublimetext.com/) and [geany](http://www.geany.org/) will
all work perfectly. If you are using Cygwin, you can also use Vim.

### Using the cloud

If you are using Windows and/or have other reasons you can do a lot of
development right in your web browser.

There are a variety of options but I am a big fan of
[cloud.sagemath](https://cloud.sagemath.com/). In particular if you want to
develop for [sagemath](http://sagemath.org/) this is an excellent option.

### Communication

There are various tools I like to use for communicating during a project.

- Quick text based messages:
    - I particularly like [google hangouts](https://plus.google.com/hangouts):
    light weight and has a mobile app (which is very useful when I can only
    respond whilst running between meetings).
    - Another great option is [gitter](https://gitter.im). Again, has a mobile
      app and also interfaces very nicely with github repositories. You can find
      the gitter room for this repository
      [here](https://gitter.im/drvinceknight/list-of-dev-things).
    - Slack is slowly becoming an industry standard:
      [slack.com/](https://slack.com/).
    - [irc](http://en.wikipedia.org/wiki/Internet_Relay_Chat) is very popular
      in the open source world. I can't say I'm the
      biggest fan but it's a great place to drop in and speak to people.

- github issues. When using github for a project it comes with a nice interface
  to raise a so called 'issue' which allows for a public record of a
  conversation. This is very helpful and worthwhile in a development process as
  at some point down the line it might be helpful to remember why something was
  decided. It's always good to open an issue for a feature before starting to
  work on it.

- Emails (they do a job).

- Virtual meetings: Very rarely are face to face meetings a regular requirement.
  I like to use hangouts for these but again there are a variety of options.

- urls: when working remotely it's very helpful to be able to just paste link to
  something that brings it up in the receivers browser. There are various tools
  for this:
    - Github (just grab the link from the particular file)
    - [Gists](https://gist.github.com/) (for throw away pieces of code)
    - Dropbox (if you have something in a dropbox folder you can use the 'share
      a link feature' - this is partcilarly helpful and quick for screenshots)

## Contributing to this repository

I would be delighted for contributions to this repository:

- If you are a student who has worked with me and feel that I am leaving
  something out or indeed that there are useful tutorials/videos etc then please
  do add them via pull request.
- All other contributions are of course welcome, please keep in mind that I am
  attempting to build a fairly generic list for students assuming only a very
  basic knowledge of writing code.

Please do raise an issue if you're not sure if something is worth having.


text:
# social_feed_share

Share Instagram and Facebook feed posts by [Lightsnap](https://lightsnap.app)

## Features
- Share to Instagram Feed
- Share to Facebook Feed

## About the package

This package is made for the Lightsnap app, but feel free to use it if you need
social sharing capabilities in your app. This package is only for sharing media
to Instagram and Facebook.

If you would like to add more platforms to share to feel free to fork
the app. Lightsnap is currently not planning on adding more than
Instagram or Facebook.

## TODOS
- Add better readme for setting up the Facebook SDK on Android & iOS
- Add code examples to the Readme.md


text:
---
layout: project
type: project
image: images/gecko.jpg
title: SHA1
permalink:
date: 2017-18-04
labels:
  - C
  - Crytography
  - Algorithms
summary: This is the final project for my ICS 212 class during the spring of 2017 at Kapiolani Community College. The algoritm used is an obsolete one, SHA-1.  The program inputs a file, processes it, and spits out out an alphanumeric string. I implemented SHA-1 using C.
---

This project first introduced me to the complex subjects and algorithms and cryptography and sparked my interest into computer security.  In the future, I hope to develop better algorithms and produce extremely effecient and secure hashes for passwords.

This program uses multiple functions.   My first function reads the entire file character by character and stores the contents in an array of unsigned integers. Second, I divide the bits of the file by 512 to determine the block count.  Once I have the block count, I covert the array of unsigned characters to an array of unsigned integers.  Finally, I compute message digest, which initializes the blocks according to the hashes standard, and loop through each of the blocks.


text:
# Developer guides

The purpose of the Developer guides documentation is to get you acquainted with Dokka's internals so that you can
start developing your own plugins or contributing features and fixes to Dokka itself.

If you want to start hacking on Dokka right away, the only thing you need to be aware of is the
[general workflow](workflow.md): it will teach you how to build, debug and test Dokka locally.

[CONTRIBUTING.md](https://github.com/Kotlin/dokka/blob/master/CONTRIBUTING.md) contains information that can be useful
if you want to contribute to Dokka.

If you want to get into plugin development quick, see
[Introduction to plugin development](plugin-development/introduction.md).

If you have time to spare and want to know more about Dokka's internals, its architecture and capabilities, follow
[Architecture overview](architecture/architecture_overview.md) and subsequent sections inside `Internals`.

Having read through all the developer guides, you'll have a pretty good understanding of Dokka and how to develop
for it.

If you have any questions, feel free to get in touch with maintainers via [Slack](community/slack.md) or
[GitHub](https://github.com/kotlin/dokka).

repository: Kotlin/dokka

gha_language: Kotlin

repo_name: Kotlin/dokka


text:
# EHR-based Stratification of Hypertensive Patients Powered by Integration of Genetic Variants
This project proposes a multi-modal deep representation learning model, which extracts latent feature vectors from high-dimensional EHR and genetic data. On top of it, we perform the K-means clustering to derive hypertension subtypes.

The pipeline is adapted from [Landi, I., Glicksberg, B. S., Lee, H. C., Cherng, S., Landi, G., Danieletto, M., Dudley, J. T., Furlanello, C., & Miotto, R. Deep representation learning of electronic health records to unlock patient stratification at scale. npj Digit. Med. 3, 96 (2020)]. The original repository is found in this [link](https://github.com/landiisotta/convae_architecture)

The project is structured as follows:

## EHR-based model
Here, only the EHR data is used.

Following hyperparameters are changed to the original pipeline:

batch-size = 32, epoch = 30, learning rate = 0.00001, weight-decay = 0.0001, kernel = 3.

## Multimodal model
In this part, we combine both EHR data and genetic data to create a fused representation.

## Clustering
The K-means clustering algorithm is applied to derive patient clusters.

_**Please refer to README file in each subdirectory for detailed description.**_


text:
# Background

The liquidity baking (LB) system is a Uniswap-style constant product market maker (CPMM) for two assets: Tez and wrapped Bitcoin (tzBTC) where arbitary users can decide to become a liquidity provider (LP) and obtain liquidity share tokens by providing reserves of each asset to the CPMM.
The system actually consists of three separate smart contracts which work together in concert:

```
      [Dexter]
         |
[LQT]---------[tzBTC]
```

-   the main contract *Dexter* is responsible for:
    -    all system entrypoints (i.e. users interacting with the system should *only* need to interact with this contract)
    -    the CPMM logic
    -    managing the Tez asset reserves
-   the *LQT* contract is a _FA1.2_ contract (with an additional `%mintOrBurn` entrypoint) responsible for managing the liquidity share tokens (as far as we can tell, *LQT* stands for liquidity token)
-   the *tzBTC* contract is a _FA1.2_ contract responsible for managing the tzBTC asset reserves

In this report, we use the K Framework and K Michelson semantics to verify two important safety properties of LB which we first state informally below:

1.  *Liquidity share value security* - LP shares never decrease in *redemption value* (note this is *different* from *monetary value*, see below)
2.  *Operation safety* - all trades and liquidity redemptions/deposits have a bounded exchange rate and time in which they are applicable.

Before we formally define these properties, we describe how CPMMs work using a simple state machine model.
This simple state machine model is _not_ equivalent to any smart contract.
Instead, it provides an intuition which ideally helps lay people and experts understand why the safety properties above are sufficient.
We conclude this section by discussing where to go from here.

## Constant Product Market Makers in Theory

**Introduction:**
A constant product market maker (CPMM) is an exchange for two assets *A* and *B* that holds a varying amount of both assets, as long as both amounts have a constant product.
Let the ordered 2-tuple *(X,Y)* denote a CPMM where naturals *X* and *Y* represent the exchange-held reserves of assets *A* and *B* respectively.
We also have the exchange function *E* which is defined as follows:

```
            V * w
E(w,U,V) =  -----
            U + w
```

where *U* and *V* are the amounts of assets *A* or *B*.

Network participants interact with the CPMM in a two-step, asynchronous, and unordered manner.
For example, suppose both Alice and Bob wish to perform trades on the exchange.
They will both need to *submit* their trade operations to the exchange operation pool.
Some time later, the exchange will *apply* their operations.
In this example, suppose Alice submits operation *o_1* first and then Bob submits operation *o_2*.
The exchange may apply *o_1* first; on the other hand, it is just as likely that it will apply *o_2* first.
It all depends on network conditions.
For this reason, we use the notation *{o_1, o_2 ... o_k}* to represent the pending set of *submitted* operations.
We let *...* represent a (possibly empty) subset of a set.
Thus, the notation *{o ...}* represents a set with an element *o* and does *not* mean that the first element in set is *o* (in any case, sets are unordered).
Let *valid(o_k)* be a predicate that defines the set of valid operations.

Finally, to properly model asynchronous operations, our exchange is equipped with a clock *[T]* where *T* is a natural number which represents the current exchange time.

**Model:**
Now we can describe CPMMs as a state machine starting from state `init` with the following rules:

```
rule init => (X, Y)[0]{ } requires X > 0 /\ Y > 0
rule (X, Y)[T]{ ... } => (X, Y)[T + 1]{ ... }
rule (X, Y)[T]{ ... } => (X, Y)[T]{ ... o } requires valid(o)
rule (X, Y)[T]{ sell-A(x) ... } => (X + x, Y - E(x,X,Y))[T]{ ... } requires x <= X
rule (X, Y)[T]{ sell-B(y) ... } => (X - E(y,Y,X), Y + y)[T]{ ... } requires y <= Y
rule (X, Y)[T]{ redeem    ... } => (0, 0)               [T]{ ... }
```

We give a brief description of each rule in order:

1.  A liquidity provider (LP) may use their assets to create a CPMM with an initially empty operation set.
2.  The system clock may tick forward.
3.  A network participant may *submit* a valid operation to the CPMM.
4.  The exchange may apply a trade operation selling asset *A* to obtain *B*.
5.  Symmetrically, the exchange may apply a trade operation selling asset *B* to obtain *A*.
6.  The exchange may apply an LP redemption operation, i.e., the LP redeems their stored assets and shuts down the CPMM exchange.
    At this point, all applicable trades are zero-valued and effectively no-ops.

**Exchange-rate Analysis:**
Any good exchange-rate function should be monotonic, i.e., we should get more units of money out if we put more units of moeny in.
Formally, we want to check that:

`w <= w' => E(w,U,V) <= E(w',U,V)`

The result follows by a chain of inequalities:

```
E(w,U,V) <= E(w',U,V) => (V * w) / (U + w) <= (V * w') / (U + w')
                      => w / (U + w)       <= w' / (U + w')
                      => w * (U + w')      <= w' * (U + w)
                      => w * U + w * w'    <= w' * U + w * w'
                      => w * U             <= w' * U
                      => w                 <= w'
```

assuming that _U > 0_ and _V > 0_ since otherwise the two division steps (i.e. dividing by _V_ and dividing _U_) become impossible.

**Invariant Analysis:**
Note that the exchange function is designed so that trades preserve the constant product, i.e., for the `sell-A(x)` operation we have:

```
X * Y = [X + x] * [Y - E(x,X,Y)]
      = [X + x] * [ Y - {Y * x / (X + x)}]
      = {[X + x] * Y} - Y * x
      = X * Y + (Y * x) - (Y * x)
      = X * Y
```

The case for the `sell-B(y)` follows by a symmetric calculation.

**Remarks:**
While our theoretical model is convenient and illustrates the sense in which CPMMs have a *constant* product, it has a few serious drawbacks:

1.  (incentive) there is no immediate incentive to provide assets (i.e. liquidity) to the exchange, limiting CPMM creation and operation
2.  (scalability) the entire amount of liquidity must be provided by one party, limiting the growth of the exchange reserves

## Constant Product Market Makers in Practice

**Introduction:**
To counteract the incentive and scalability issues, pratical CPMMs make two slight adjustments to the theoretical model:

1.  fees are assessed on every transaction (i.e. a percentage of the amount sold in terms of either asset *A* or *B*) and added to the exchange reserves
2.  a system of shares is created that allows multiple parties to:
    -   provide both assets to the exchange reserves in proportion and obtain a corresponding amount of shares
    -   destory shares and redeem a corresponding amount of exchange-held reserves

Let us reformulate our CPMM model in light of the above considerations.
A CPMM is now an ordered 4-tuple *(L,P,X,Y)* where:

-   natural *L* is total number of _liquidity_ shares
-   *P* is in the range *[0,1]* is the trade scaling factor and represents the percentage of trades paid into the exchange reserves as a _fee_, e.g., if there is a 25% fee on trades, then *P=.75*, and if there are no fees, then *P=1*
-   naturals *X* and *Y* represent the exchange-held _reserves_ of assets *A* and *B* respectively.

To account for fees, we develop a new exchange function:

`E(w,P,U,V) = E(w * P,U,V)`

**Model:**
Now we refine our previous CPMM state machine model:

```
rule init => (l, p, x, y)[0]{ } requires l > 0 /\ p \in [0,1] /\ x > 0 /\ y > 0
rule (X, Y)[T]{ ... } => (X, Y)[T + 1]{ ... }
rule (L, P, X, Y)[T]{ ... } => (L, P, X, Y)[T]{ ... o } requires valid(o)
rule (L, P, X, Y)[T]{ sell-A(x) ... } => (L, P, X + x, Y - E(x,P,X,Y)) [T]{ ... } requires x <= X
rule (L, P, X, Y)[T]{ sell-B(y) ... } => (L, P, X - E(y,P,Y,X), Y + y) [T]{ ... } requires y <= Y
rule (L, P, X, Y)[T]{ redeem(n) ... } => (L - L*n, P, X - X*n, Y - Y*n)[T]{ ... } requires 0 <= n <= 1
rule (L, P, X, Y)[T]{ add(n)    ... } => (L + L*n, P, X + X*n, Y + Y*n)[T]{ ... } requires 0 <= n
```

These rules are very similar to our original rules, with a few distinctions:

-   The `init` rule now creates a 4-tuple CPMM.
-   The `sell-A(x)` and `sell-B(y)` operations now compute exchange rates using a fee.
-   The `redeem(n)` operation is parametric on the amount `n` of liquidity shares redeemed.
    When `n = 1`, this is equivalent to shutting down the exchange, i.e., the last LP removed their remaining liquidity; afterwards, all applicable trades and liquidity redemptions/additions are no-ops.
-   The new `add(n)` rule describes how an LP can mint new liquidity shares by storing assets in the reserves in exchange for new shares.

The above model is equivalent to our original model under the following conditions:

1.  When initializing a new exchange, the only allowed trade scaling factor is *P = 1*;
2.  The `redeem(n)` operation is only applied when *n = 1*;
3.  The `add(n)` operation is *never* applied.

**Exchange-rate with Fees Analysis**:
We want to understand how the exchange rate function _E()_ varies as the trade scaling factor _P_ grows or shrinks.
Using the equality _E(w,P,U,V) = E(w * P,U,V)_ and monotonicity, observe that _E(w,P,U,V)_ shrinks as _P_ shrinks.
Again, this result only holds when _U_ and _V_ are both greater than _0_.
Finally, note that _E(w,1,U,V) = E(w * 1,U,V) = E(w,U,V)_.

**Invariant Analysis:**
Recall that our theoretical CPMM model without fees satisfied the _constant product_ invariant after trades.
In case of CPMMs with fees, is the the product of the pre-trade assets always equal to the product of the post-trade assets?
Suppose we started off in a state `(L, P, X, Y)` with product _k = X * Y_.
Then suppose the `sell-B(b)` operation was applied to obtain the resulting state:

`(L, P, X - E(y,P,Y,X), Y + y)`

Thus, we have:

```
X * Y =  [ X - E(y,Y,X)     ] * [ Y + y ]
      <= [ X - E(y * P,Y,X) ] * [ Y + y ]
      =  [ X - E(y,P,Y,X)   ] * [ Y + y ]
```

Thus, we see that the answer to our question is:

-   if *P = 1*, then the product is constant in both states.
-   if *P < 1*, then the product _increases_ by monotonicity of the exchange-rate function.

A symmetric calculations shows that the same rule applies in the case of the `sell-A(a)` operation.
In either case, this derivation shows us by applying trades, the redemeption value of liquidity shares _never decreases_.

**Liquidity Shares vs. Exchange Reserves Analysis:**
If our CPMM state is `(L, P, X, Y)`, during `redeem` or `add` operations, how do liquidity shares *L* scale with respect to the product of our exchange reserves `X*Y`?
Let us consider the `redeem` and `add` operations in turn.

First suppose we apply a `redeem(n)` operation.
Then our updated state tuple is:

`(L - L*n, P, X - X*n, Y - Y*n) = (L * (1 - n), P, X * (1 - n), Y * (1 - n))`.

In other words, we update *L*, *X*, and *Y* by the constant factor *q = 1 - n* such that *0 <= n <= 1* which gives *0 <= q <= 1*.
Now suppose we apply an `add(n)` operation.
Then our updated state tuple is:

`(L + L*n, P, X + X*n, Y + Y*n) = (L * (1 + n), P, X * (1 + n), Y * (1 + n))`.

Symmetrically, this means we update *L*, *X*, and *Y* by the constant factor *q = 1 + n* such that *0 <= n* which gives *1 <= q*.
By this reasoning, we see that the disjunction of these two rules is equivalent to the rule below:

_(*)_ `rule (L, P, X, Y) => (L * q, P, X * q, Y * q) requires 0 <= q`.

Thus, as `L` scales to `L*q`, we see that the product of our exchange reserves `X*Y` scales to `(X*q)*(Y*q)` or `(X*Y)*q^2`.
Thus, `L` scales proportionally with `sqrt(X*Y)`, i.e., the *geoemtric mean of X and Y*.

If the reader is unconvinced, we can carry our a simple calculation to verify our intuition.
Let us assume `L * m = sqrt(X*Y)`.
Now, scale both sides as indicated by rule `(*)` above.
We want to show that `L*q * m = sqrt((X*q)*(Y*q))`.
By arithmetic, we have `L*q * m = sqrt((X*q)*(Y*q)) = sqrt(X*Y*q^2) = q*sqrt(X*Y)`.
Finally, we divide both sides by `q` to obtain the equality we already assumed: `L* m = sqrt(X*Y)`.

In words, our answer is *liquidity scales proportionally with the geometric mean of X and Y*.

**Remarks:**
The new model is clearly an improvement over the previous model because it addressed the incentive and scalability issues.
However, it still has non-trivial and non-obvious issues which relate to the asynchronous nature of operations:

1.  (slippage) in the time between trade/redeem/add operation submission and application, exchange rates may vary, making such operations incredibly risky
2.  (time-unboundedness) after an operation is submitted, it may be applied at *any* time in the future, even when that makes no sense for the submitter

To counteract this risk of price variance, practical implementations allow operations to inlcude both: exchange rates and time bounds.

**Revised Rules:**
We can formalize this notion by revising our trade and liquidity redemption/addition operations to include explicit bounds.
These four rules will then replace the last four rules of the former model.

```
rule (L, P, X, Y)[T]{ sell-A(d,e,x)   ... } => (L, P, X + x, Y - E(x,P,X,Y)) [T]{ ... }
  requires x <= X /\ T <= d /\ E(x,P,X,Y) >= x*e
rule (L, P, X, Y)[T]{ sell-B(d,e,y)   ... } => (L, P, X - E(y,P,Y,X), Y + y) [T]{ ... }
  requires y <= Y /\ T <= d /\ E(y,P,Y,X) >= y*e
rule (L, P, X, Y)[T]{ redeem(d,a,b,n) ... } => (L - L*n, P, X - X*n, Y - Y*n)[T]{ ... }
  requires 0 <= n <= 1 /\ T <= d /\ X*n >= a /\ Y*n >= b
rule (L, P, X, Y)[T]{ add(d,a,b,n)    ... } => (L + L*n, P, X + X*n, Y + Y*n)[T]{ ... }
  requires 0 <= n /\ T <= d /\ X*n <= a /\ Y*n <= b
```

These revised operations are identical to their former counterparts except:

-   all operations now include an explicit deadline, denoted by variable `d`
-   the `sell-A(d,e,x)` and `sell-B(d,e,y)` operations now include a minimum exchange rate parameter `e`
-   the `redeem(d,a,b,n)` operation now includes parameters `a` and `b`, the *minimum* redeemed units of asset *A* and *B* respectively
-   the `add(d,a,b,n)` operation now includes parameters `a` and `b`, the *maximum* stored units of asset *A* and *B* respectively

## Safety Property Formalization

We now come back to our two safety properties that we state informally in the beginning of our document:

1.  *Liquidity share value security* - LP shares never decrease in *redemption value*
2.  *Operation safety* - all trades and liquidity redemptions/deposits have a bounded exchange rate and time in which they are applicable.

We can now formalize these properties using our model.
Consider an arbitrary CPMM in the form `(L, P, X, Y)`.

1.  *Liquidity share value security*

    If `(L, P, X, Y)[T]{ ... } =>* (L', P, X', Y')[T']{ ... }` then:

    `X' * Y' / X * Y >= L'^2 / L^2`

2.  *Operation safety*

    All operations have bounded exchange rates and application deadlines.
    In other words:

    If `(L, P, X, Y)[T]{ o ... } => (L', P, X', Y')[T]{ ... }` then:

    ```
    t <= deadline(o) /\ bounded-exchange(P,X,Y,o)
    ```

    where `deadline(o)` projects the deadline from an operation and `bounded-exchange(P,X,Y,o)` is defined as:

    ```
    bounded-exchange(P,X,Y,sell-A(d,e,x))   = E(x,P,X,Y) >= x*e
    bounded-exchange(P,X,Y,sell-B(d,e,y))   = E(y,P,Y,X) >= y*e
    bounded-exchange(P,X,Y,redeem(d,a,b,n)) = X*n >= a /\ Y*n >= b
    bounded-exchange(P,X,Y,add(d,a,b,n))    = X*n <= a /\ Y*n <= b
    ```

Both properties are satisfied by our simplified model.
Property (1) follows by an induction argument while property (2) follows by definition.

## Integer Arithmetic Considerations

In computer programs, we do not have access to infinite precision numbers (i.e. real numbers).
We typically either use fixed-width or arbitrary width integers (with rounding or truncation) or floating point numbers.
In this section, we discuss which of the properties that we proved above hold when we restrict ourselves to arbitrary width integer arithmetic with truncation.
Note that some of the expressions we used above do not work well (or at all) in the realm of integer arithmetic because they contain fractional values.
In such cases, we can use algebra to re-formulate such expressions to minimize division operations (and thus, minimize rounding error).
By doing so, we may also gain performance, since division is a fairly expensive operation.
For the purposes of this section, let

```
 a
---
 b
```

and:

`a / b`

denote fractions using _real_ division and let:

```
 a
---I
 b
```

and:

`a // b`

denote fractions using _integer_ division with truncation.

**Invariant Analysis without Fees:**:
Recall that our original exchange rate function `E(w,U,V)` was chosen so that:

`[ X - E(y,Y,X) ] * [ Y + y ] == X * Y`

However, in the world of integer arithmetic, the above equality no longer holds, becase integer division is not exact.
As a counter example, suppose our exchange has two assets with reserves of asset A and B set to _10_ and _10_ respectively.
Now suppose we wish to by as many units of asset A as possible for _5_ units of asset B.
When we plug these values into our formula, we obtain:

```
[ 10 - E(5,10,10) ] * [ 10 + 5 ] = [ 10 - ( 10 * 5 / 10 + 15 ) ] * 15
                                 = [ 10 - ( 50 / 15 ) ] * 15
                                 = [ 10 - ( 10 / 3 ) ] * 15
                                 = [ 10 - 3.333... ] * 15
                                 = [ 10 - 3 ] * 15
                                 = 7 * 15
                                 = 105
                                 > 100
                                 = 10 * 10
```

The crucial problem arises because we must truncate the division _10 / 3_, which gives us _3_ instead of the infinite decimal expansion _3.333..._
In fact, because we are truncating a number that is subtracted, the end result is that, in case of arbitrary-width integer arithmetic with truncation, even *without a fee*, the product of our asset reserves *never decreases, but may increase*.

**Exchange-rate with Fees Analysis:**:
Recall that our exchange rate function with fees was:

```
              V * w * P
E(w,P,U,V) =  ---------
              U + w * P
```

where *P* is a scaling factor in the range *[0,1]*.
To make this operation usable under integer arithmetic, we can rewrite the exchange function as follows:

```
                        V * w * Q
Ei(w,P = Q/R,U,V) =  ---------------I
                     (U * R) + w * Q
```

where the division operator `---I`, as mentioned above, is integer division with truncation.
By a straightforward calculation, we can show that the above is provably equal to our original function when using real division, i.e.,

```
   V * w * Q       (1 / R)    V * w * Q/R   V * w * P
--------------- * --------- = ----------- = --------- = E(w,P = Q/R,U,V)
(U * R) + w * Q    (1 / R)    U + w * Q/R   U + w * P
```

We also note that:

```
                       V * w * Q           V * w * Q
Ei(w,P = Q/R,U,V) = ---------------I <= --------------- = E(w,P = Q/R,U,V)
                    (U * R) + w * Q     (U * R) + w * Q
```

since integer division will truncate the fractional part, giving a smaller value.

**Exchange-rate with Compounded Fees Analysis:**
Suppose that, instead of our exchange function applying a fee which is a single scaling factor, it applies the same scaling factor twice in succession?
That is, suppose we have this exchange function with a compound fee:

```
                                           V * w * P^2
EC(w,P = Q/R,U,V) = E(w,P = Q^2/R^2,U,V) = ----------- = E((w * Q) / R,P = Q/R,U,V)
                                           U + w * P^2
```

Now suppose that we reformulate it in the world of integer arithmetic using the following formulation:

```
                        V * ((w * Q) // R) * Q
ECi(w,P = Q/R,U,V) = -----------------------------I = Ei((w * Q) // R,P = Q/R,U,V)
                     (U * R) + ((w * Q) // R)  * Q
```

Note that this formulation _does not_ minimize rounding error, but, as shown above, _does_ allow us to re-use our exchange function we defined earlier.
With our above knowledge, we can _almost_ prove the following:

```
ECi(w,P = Q/R,U,V) =  Ei((w * Q) // R,P = Q/R,U,V)
                   <= E ((w * Q) // R,P = Q/R,U,V)
                   <= E ((w * Q) /  R,P = Q/R,U,V)
                   =  EC(w,P = Q/R,U,V)
```

The first, second, and fourth steps follow all by either definition or by our analysis in the subsection above.
The second step follows because `(w * Q) // R <= (w * Q) / R` by integer division truncation and monotonicity.

**Invariant Analysis with Fees or Compounded Fees:**
Given our exchange-rate analysis in the preceeding subsections, we have:

```
X * Y =  [ X - E(y,Y,X)                     ] * [ Y + y ]
      <= [ X - E((y * Q) / R,Y,X)           ] * [ Y + y ]
      =  [ X - E(y,P = Q/R,Y,X)             ] * [ Y + y ]
      <= [ X - Ei(y,P = Q/R,Y,X)            ] * [ Y + y ]
      <= [ X - Ei((y * Q) // R,P = Q/R,Y,X) ] * [ Y + y ]
      =  [ X - ECi(y,P = Q/R,Y,X)           ] * [ Y + y ]
```

where:

1.  the equality steps follow by definition;
2.  the second and third inequality steps follow by monotonicity;
3.  the first inequality follows by our exchange rate with fees analysis.

**Exchange Reserves Non-negativity Analysis:**
After trades, are the exhange reserves always non-negative?
The answer to this is: yes.
It can be shown by examining the exchange function directly, but there is an easier proof.
We have already shown that product of our exchange reserves can _never decrease_.
That is, if our exchange currently has asset reserves _X_ and _Y_ and a series of trades is performed producing reserves _X'_ and _Y'_, we know that _X * Y <= X' * Y'_.
Since our exchange reserves are assumed to be non-negative integers, this means that we know:

`0 <= X * Y <= [ X - Ei(y,P,Y,X) ] * [ Y + y ]`.

By _Y_ and _y_ being non-negative, we also know:

`Y + y > 0`.

If `X - Ei(y,P,Y,X)` could be negative, then we would have the contradiction:

`0 <= X * Y <= [ X - Ei(y,P,Y,X) ] * [ Y + y ] < 0`.

Thus, our exchange function to convert asset _B_ into asset _A_ can never exceed the total units of asset _A_.

## Next Steps

The simplified models in this section ignore critical features needed in real implementations such as:

-   authorization logic for performing various actions
-   logic for maintaining an account's balance in assets *A* and *B*
-   means of integrating the CPMM with the underlying assets (which are either blockchain primitives or smart contracts)
-   logic to programmatically issue transactions to interact with other smart contracts (if necessary)
-   etc...

Our functional specification proofs in K and hand-proofs cover these additional details (and more) needed to provide a complete proof of our two safety properties list above.

license: NCSA

repository: runtimeverification/michelson-semantics

gha_language: Makefile

gha_license_id: NOASSERTION

repo_name: runtimeverification/michelson-semantics


text:
# create-commerce-app

**This repo has been archived and is no longer in development. Please see https://github.com/SalesforceCommerceCloud/pwa-kit for using Salesforce Commerce APIs to build a headless shopping experience.**

A Salesforce Commerce application generator that allows you to generate a sample commerce storefront application.

## Prerequisites
Download and install Node.js and npm [here](https://nodejs.org/en/download/).

> **Note:** Only Node.js 12 LTS is supported. Any other version can cause unexpected results. To use a different version of Node.js for other projects, you can manage multiple versions of Node.js with [nvm](https://github.com/nvm-sh/nvm).

## Quick Start

To get up and running execute the following command in a shell/terminal:

```
npx create-commerce-app your-app-name
```

This will run a npx installation of create-commerce-app and create a sample Salesforce Commerce Storefront app for you. It creates the app as a sub-directory of the current working directory with the name of the directory being the app name provided while running the above command. In order to run your new application, please follow the instructions for the [sample Salesforce Commerce Storefront app](https://github.com/SalesforceCommerceCloud/sfcc-sample-apps). You don't need to clone the sample apps repo, but you do need to run the yarn commands shown in the root directory of your new commerce app.

## Issues

First, check the [open issues](https://github.com/SalesforceCommerceCloud/create-commerce-app/issues) and [Commerce Cloud Developer Center](https://developer.commercecloud.com/) for any open issues related to the issue that you are experiencing. If not already raised please file a new issue [here](https://github.com/SalesforceCommerceCloud/create-commerce-app/issues/new) with all the necessary details. If you require an urgent resolution to your issue please ask your AM/CSM to file a support ticket with Salesforce Commerce.

## Contributing

If you would like to contribute please take a look at our [contributors' guide](./Contributing.md).

## License Information
This package is licensed under BSD-3-Clause license. See the [license](./LICENSE.txt) for details.

repository: olegforce/create-commerce-app

repo_name: olegforce/create-commerce-app


text:
# Tutuorial on Spike Internal

Documentation editor: Po-wei Huang

Acknowledgement
==================
I would like to thank the following peoples for their time, feedback, and contribution:

Wei Song

Tutorial on Spike Internal
==================
*   [Goal of this document](#goal-of-this-document)
*   [Which branch is being tageted?](#which-branch-is-being-tageted)
*   [Overview of Spike](#overview-of-spike)
*   [Top Level Structure](#top-level-structure)
    *   [What is modelled by Spike?](#what-is-modelled-by-spike)
    *   [Spike's source code](#spikes-source-code)
*   [Memory System Overview](#Memory)
    *   [What does Spike try to model?](#model_memory)
*   [TLB & MMU](#MMU_TLB)
    *   [Spike's source code?](#source_MMU_TLB)
*   [Cache simulation](#Cache_sim)
    *   [Spike's source code?](#source_cache)
    *   [Result of cache simulation](#Result_of_cache)
*   [Processor Overview](#Processor)
    *   [What does Spike try to model?](#model_processor)
*   [Hart modeling](#hart)
    *   [What does Spike try to model?](#model_hart)
    *   [Spike's implementation](#source_hart)
*   [Trap modeling](#trap)
    *   [What does Spike try to model?](#model_trap)
    *   [Spike's implementation](#source_trap)
*   [Interrupt modeling](#interrupt)
*   [Exception modeling](#interrupt)
*   [Bus and Miscellaneous devices](#bus)
    *   [Device Simulation](#device_sim)
*   [Appendix](#appendix)
    *   [Dealing with Instructions](#Instruction)

Goal of this document
-----------------
* Let people understand the implementation of Spike.
* Work with Spike to help people understand RISC-V more as Spike is a golden reference
* Provide information about how to use the spike, especially those features that are in the code but not well known to people. Ex. cache simulation, multi-core simulation.

As Spike is a functional simulator, the simulator structure would not necessarily match the hardware structure. In order to make simulation faster, sometimes simulator optimization will be used, and these optimization will make the structure completely different. We will try to point out these difference when we meet them.

Which branch is being tageted?
-----------------

This tutorial is for branch master from the RISC-V ISA SIM repo and the commit is [daaf28f](https://github.com/riscv/riscv-isa-sim/tree/daaf28f7296c0a5f5c90fe6646a4f8a73a720af5).

Overview of Spike
-----------------
1. Spike is an ISS (instruction set simulator), which is not cycle accurate.
2. Spike is a function simulator which omits all internal delays such as cache misses, memory transactions, IO accesses.
3. Spike does not have a full cache model, instead, the cache is a tracer or monitor (It doesn't allocate a space to cache any data).

Top Level Structure
-----------------

### What is modelled by Spike?

For spike, they use a multi-core framework. Each core includes a MMU for virtual memory, and all of the core have a common I$ and D$. Then, both I$ and D$ connect to a single L2$. The main memory follows.

The cores and the memory hierarchy are inside a class sim, and the class could interact with outside by interactive command. Moreover, the sim includes  bus, debug module, boot rom, and real time clock (RTC) . The processors, boot ROM, debug module and RTC are hooked on the bus, but the memory is not. These components together enable spike to run a simple proxy kernel pk.

![Top level overview](./pictures/Sim.png)

### Spike's source code

The code below comes from `riscv-isa-sim/spike_main/spike.cc`. You could see that I$ and D$ connect to L2$ by miss handler. Moreover, for each core, it has a mmu and the mmu connect to a single ic and dc.
After all the components are connected, the method run is called to start the simulation.

~~~cpp
  if (ic && l2) ic->set_miss_handler(&*l2);
  if (dc && l2) dc->set_miss_handler(&*l2);
  for (size_t i = 0; i < nprocs; i++)
  {
    if (ic) s.get_core(i)->get_mmu()->register_memtracer(&*ic);
    if (dc) s.get_core(i)->get_mmu()->register_memtracer(&*dc);
    if (extension) s.get_core(i)->register_extension(extension());
  }

  s.set_debug(debug);
  s.set_log(log);
  s.set_histogram(histogram);
  return s.run();
~~~

On the other hand, inside riscv-isa-sim/riscv/sim.cc, you could see many bus.add_device(), just like the following figure shows. Spike use this function to attach device on bus. After these attachments are done, spike could start to run.

![Source of Bus add](./pictures/Bus_Add_device.png)

Memory system overview

What does Spike try to model?

![Memory system overview](./pictures/Memory_system.png)

The picture above is an overview of the memory system. The MMU contains a TLB, which could send back the data without invocation of cache. If the TLB fail, they will go through the table and access the cache. For cache, they model a write-back cache, and use sets/ways/line size to set the configuration. This scheme actually will make cache simulation inaccurate, but they do this in order to speed up performance of simulator.

TLB & MMU

Spike's source code

When an instruction execute a load, it will call load function of MMU and use WRITE_RD to write the data back t register. Then, how to implement the MMU load?

![Instruction load](./pictures/Instruction_MMU.png)

Below is an excerpt of riscv-isa-sim/riscv/mmu.h. The functions are defined in macro. The load will go through TLB first and then go to the slow path if TLB miss happens.

![MMU trace](./pictures/mmu_trace.png)

Then, when TLB fail, MMU will call the slow path, and it will ask tracer to call trace. The trace will start to access the cache. Finally, when we jump to riscv-isa-sim/riscv/cachesim.h, we could see that the tracer will call access function of cache.

![cache trace](./pictures/cache_trace.png)

Cache_simulation

Spike's source code

To understand how the cache is accessed, we could see riscv-isa-sim/riscv/cachesim.cc shown below. There are two functions, access and victimize. When tracer calls trace, the cache will call access.The access will check tag and then do the write or read. Moreover, it use lfsr to find the victim when a replacement happens.

![cache access](./pictures/Cache_code.png)

Result of Cache simulation

The picture below is a result of cache simulation. It could show read/write miss for I$, D$ and
L2. Though it’s not accurate, it could provide a basic analysis.

![result_cache](./pictures/Cache_miss.png)

Processor_Overview

What does Spike try to model?

Basically, to model a processor, we need the following:

* Model a RISC-V hart

* Processor stepping, including fetch and execution.

* Trap Handling including exception and interrupt handling.

* Optional: MMU for VA->PA

Hart modeling

What does Spike try to model?

* Architecture state of a hart, including CSR, pc, registers and floating point registers.

Spike’s implementation

Below is an excerpt from spike/riscv/processor.c. The state_t contains pc, register_file, and CSR. Notice that Spike only implement some of the CSR inside the hart. It implements other CSR in the processor.

![Hart](./pictures/hart_spike.png)

Trap modeling

What does Spike try to model?

To model a trap, the followings are needed:

* Cause of the trap. The information is in mcause ( machine cause register)

* For memory related trap, the faulting address needs to be saved in mbadaddr (machine bad address register).

* For trap caused by exception, virtual address of the instruction that encountered the exception. It’s in mepc(machine exception pc register).

* For trap caused by interrupt?

Spike's source code

Inside encoding.h, the causes are defined.

![trap_code](./pictures/trap.png)

![trap_spec](./pictures/trap_spec.png)

Inside trap.h , two base classes are defined. The which and badaddr are for the cause and faulting address respectively. Then, macros are used to construct classes for each kind of trap and the cause are saved into the class at the same time.

![trap_class](./pictures/trap_class.png)

![trap_define](./pictures/trap_define_class.png)

Then, how about epc? (Todo)

Interrupt Modeling

Todo

Exception Modeling

Todo

Bus and Miscellaneous devices

Device simulation

Related file:

* riscv/device.h

* riscv/device.cc

In this section, we want to describe how to simulate or add a device. The devices inherit from a base class abstract_device_t, which has virtual functions load and store. Then, each device implements the load/store, and provides their special functions.

![device](./pictures/abstract_device_t.png)

In spike, five devices are simulated, including bus, rom, real time clock (rtc), processor and debug module.

Appendix

Dealing with Instructions

Related file:

* riscv/decode.h

The spike use a class instruction_t to represent instructions. To extract each field, it defines functions like rs1() or rm(), as the following code shows.

![instruction](./pictures/instruction.png)

The number of x comes from the following encoding table from the spec.
![instruction_spec](./pictures/instruction_spec.png)


text:
---
hrs_structure:
  division: '1'
  volume: '5'
  title: '17'
  chapter: '286'
  section: 286-109.7
type: hrs_section
tags:
  - Government
menu:
  hrs:
    identifier: HRS_0286-0109_0007
    parent: HRS0286
    name: 286-109.7 Organ and tissue education fee
weight: 38470
title: Organ and tissue education fee
full_title: 286-109.7 Organ and tissue education fee
---
**§286-109.7 Organ and tissue education fee.** Notwithstanding any other law to the contrary, beginning July 1, 2000, a donation of $1, in addition to any other fees under this chapter, may be collected upon designation by an individual or entity from each certificate of registration by the director of finance of each county to be deposited on a quarterly basis into the organ and tissue education special fund pursuant to section 327-24\. The counties may retain a portion of the $1 donation as an administrative fee to cover the cost of collecting, accounting for, and depositing the balance into the organ and tissue education special fund. The retention shall not exceed $0.20 for each $1 collected. [L 1999, c 88, pt of §2; am L 2003, c 88, §2; am L 2008, c 122, §3]

repository: SamMade/BlueAndKrabby

repo_name: SamMade/BlueAndKrabby


text:
ng-detector
===========

Chrome extension that detects [AngularJS](https://angularjs.org) apps as you browse.

Adds a small AngularJS icon into the address bar when you come across a page that is built using AngularJS.

![ng-detector screenshot](/images/ng-detector-screenshot.png?raw=true)

repository: madewithangular/ng-detector

repo_name: madewithangular/ng-detector


text:
# Install BigDL-Nano on Windows

## Step 1: Install WSL2

Follow [BigDL Windows User guide](../../../UserGuide/win.md) to install WSL2.

## Step 2: Install conda in WSL2

It is highly recommended to use conda to manage the python environment for BigDL-Nano. Follow [BigDL Windows User Guide/Conda Install](../../../UserGuide/win.md#install-conda) to install conda.

## Step 3: Create a BigDL-Nano env

Use conda to create a new environment. For example, use `bigdl-nano` as the new environment name:

```bash
conda create -n bigdl-nano
conda activate bigdl-nano
```

## Step 4: Install BigDL-Nano from Pypi

You can install BigDL-Nano from Pypi with `pip`. Specifically, for PyTorch extensions, please run:

```
pip install bigdl-nano[pytorch]
source bigdl-nano-init
```

For Tensorflow:

```
pip install bigdl-nano[tensorflow]
source bigdl-nano-init
```

repository: intel-analytics/BigDL

gha_language: Jupyter Notebook

repo_name: intel-analytics/BigDL


text:
# Cluster-Funk
## Apache Spark Jobs Running on Amazon EMR

The organization of jobs is pretty simple and aims to be self contained. Each job reside in it's own
subdirectory.  Within each sub-directory are files that are used to configure the cluster the job runs
on as well as define the dependencies and code required to run the job.

Directories are as follows:
1. jobs (top level directory for EMR jobs)
2. environments (collection of cloudformation templates used to build VPC, IAM, and Security Groups)

After installing the cluster_funk tool you can create a new job by typing
```
cluster_funk jobs create --name my_new_job_name
```

gha_language: Python


text:
# MyVerses

Welcome to MyVerses! This is a Rails app that I built as my third Flatiron School project. It allows you to write your favorite Bible verses, and check out other people's favorites as well. My hope is that whoever uses this app will gain a better understanding and appreciation of God's Word.

![MyVerses Home Page](app/assets/images/MyVerses_home_page.png)

## Features

This app allows you to:

* Create an account, either manually or through Facebook.

* Log in and log out.

* Create, read, update and delete your favorite Bible verses (or MyVerses).

* View a list of everyone's MyVerses.

* Search for MyVerses by book.

* View other people's profiles and individual MyVerses.

* Find out who has the most MyVerses.

* View a list of Verse References (book, chapter, and verse) that have (or have had) at least one MyVerse created with them.
  * Note: Every time you create a new MyVerse, a new Verse Reference is added to this list, unless it is already there. It is not possible at this time to delete a Verse Reference.

* View a list of MyVerses with a specific Verse Reference.

* Create a new MyVerse with one of the listed Verse References.

## Installation

Since this app is not yet publicly available, you will need to fork and clone it onto your own computer. After that, you can install it with the following steps:

1. Run ```bundle install``` to install the gems.
2. Run ```rails db:migrate``` to set up the database.
3. Optionally, seed the database with ```rails db:seed```.

## Usage

To start the MyVerses app, run ```rails s``` in your terminal, and then navigate to http://localhost:3000. To exit the app, hit Ctrl-C or Cmd-C.

If you wish to play around with the (SQLite) database, run ```rails c``` in your terminal (or ```rails c -s``` if you don't want to save any changes to it). To exit, type in ```exit``` or hit Ctrl-D or Cmd-D.
  * Note: Be careful with ```rails c -s```.  This appears to be a bug.

You can also run the Rspec test suite. First, migrate the test database with ```rails db:migrate RAILS_ENV=test```. Then, run the tests with ```rspec```.

You can watch a demo of the MyVerses app here:

https://www.loom.com/share/1a1cfaaba80e4f86af2298bc4170c8db

There is also a walk-through of this app at https://www.youtube.com/watch?v=nFCklCUEjuE&feature=youtu.be

Finally, I wrote a blog post about the MyVerses app here: https://stevendcrouse.com/myverses_a_rails_project_of_biblical_proportions

## Development notes

* Ruby version: 2.6.1

* Rails version: <IP_ADDRESS>

* In addition to Ruby and Rails, MyVerses makes use of the following gems:
  * Omniauth
  * Omniauth-facebook
  * Dotenv-rails
  * SQLite
  * Bcrypt
  * Rspec-rails
  * Pry

* I used Figma to help design my web pages. You can view those designs here: https://www.figma.com/file/ZVn3NeqHjnaxdM7MqjAjz1/Web-Pages?node-id=0%3A1

## Contributing

Please feel free to raise a new Issue on my repository if you have any problems with my app (installation, usage, bugs, etc), or you have suggestions for a new feature. Pull requests are also welcome.

Contributors are expected to follow the project's code of conduct. This can be viewed in the CODE_OF_CONDUCT.md file.

## License

The MyVerses app is available as open source under the terms of the MIT License, which can be viewed in the LICENSE file.

repository: Sdcrouse/my-verses

gha_language: Ruby

repo_name: Sdcrouse/my-verses


text:
# libsasl2

**Deprecation Notice**: This plan has been deprecated in favor of `core/cyrus-sasl` which provides the same functionality. If you want libsasl2, you probably want cyrus-sasl.

Simple Authentication and Security Layer library.

## Maintainers

* The Habitat Maintainers<EMAIL_ADDRESS>
## Type of Package

Binary package

## Usage

Include this package as a build or runtime dependency as required:

```
pkg_deps=(
  core/libsasl2
)
```

repository: scottford-io/core-plans

repo_name: scottford-io/core-plans


text:
# doc-search
A doc searcher of the documents on the local host that is based on: Tika, ElasticSearch and Kibana

# ElasticSearch
- [Install Elasticsearch with Dockeredit](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html)
Testing: `curl -X GET "localhost:9200/_cat/nodes?v&pretty"`
[Java REST Client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.10/index.html)
- [Installing Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html)
See the gradle task `install` under [elasticsearch-server](./elasticsearch-server)

# Kibana
UI dashboard for Elastic Search
- [Install Kibana with Dockeredit](https://www.elastic.co/guide/en/kibana/current/docker.html)
- [Insalling Kibana](https://www.elastic.co/guide/en/kibana/current/install.html)
See the gradle task `install` under [kibana-server](./kibana-server)

# Tika+OCR Server
See [TikaOCR](https://cwiki.apache.org/confluence/display/TIKA/TikaOCR)
See [Recursive Metadata and Conten](https://cwiki.apache.org/confluence/display/TIKA/TikaServer#TikaServer-RecursiveMetadataandContent)

# Scan Server
This is a Spring Boot application the main tasks of that are:
 - scanning every 1 minute the files in the special folder
 - extracting a content of the files via Tika+OCR server API
 - storing the metadata and the content of the files in the Elasticsearch

# Build
 - `./gradlew clean build`
 - `./gradlew clean build; docker-compose up --force-recreate --build`

# Docker
 - [Prune unused Docker objects](https://docs.docker.com/config/pruning/): `docker system prune -f`
 - To clear containers: `docker rm -f $(docker ps -a -q)`
 - To clear images: `docker rmi -f $(docker images -a -q)`
 - To clear volumes: `docker volume rm $(docker volume ls -q)`
 - To clear networks: `docker network rm $(docker network ls | tail -n+2 | awk '{if($2 !~ /bridge|none|host/){ print $1 }}')`

repository: zhurlik/doc-search

repo_name: zhurlik/doc-search


text:
FDA
===

Listas de exercícios e exercícios feitos em sala de aula de FDA. Recomendável resolvê-las por conta própria e usar as soluções daqui apenas para conferir/comparar respostas.
Utils.c é um arquivo com métodos recorrentes em exercícios, por exemplo, printArray e fatorial.

===

Como usar:
  * Você pode visualizar os arquivos pelo próprio GitHub.
  * Baixar e editar no Code::Blocks ou qualquer outra IDE.
  * Se for fazer alguma edição ou novo arquivo que nao seja pelo próprio site, `git pull` antes de começar para não ter problemas com conflitos e merges.

===

Links:
  * [Code::Blocks](http://www.codeblocks.org/downloads)
  * [DevC++](http://www.bloodshed.net/download.html)
  * [CodeLite](http://downloads.codelite.org/)
  * [Eclipse com Extensão para C/C++](http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/lunar)
  * [NetBeans (pacotes com apenas C/C++ ou completo)](https://netbeans.org/downloads/)
  * Visual Studio: [Aqui](http://www.visualstudio.com/downloads/download-visual-studio-vs) ou [aqui](http://thepiratebay.se/)
  * [CLion by JetBrains](http://www.jetbrains.com/clion/)

===

Sites com desafios para praticar:
  * [/r/dailyprogrammer](http://www.reddit.com/r/dailyprogrammer) - a subreddit with daily programming challenges
  * [UVa Online Judge](http://uva.onlinejudge.org/) - collection hundreds of programming contests problems with online  solution checking system
  * [Timus](http://acm.timus.ru) - similar to UVA, includes problems from many past competitions (world and regional scale)
  * [SPOJ](http://spoj.pl) - similar to UVA, with largest choice of programming languages allowed for solutions
  * [/r/tinycode](http://www.reddit.com/r/tinycode) - a subreddit dedicated to doing big things with little code
  * [CodingBat](http://codingbat.com/) - coding exercises for Java and Python
  * [Python Challenge](http://www.pythonchallenge.com/) - combines riddles and programming puzzles to move through different levels
  * [Project Euler](http://projecteuler.net/) - math-heavy challenges meant to be solved through code
  * [CodeAbbey](http://codeabbey.com) - set of beginner level problems with solutions being checked by answers (like ProjectEuler) and features of reviewing and commenting other's codes
  * [codegolf.stackexchange.com](http://codegolf.stackexchange.com/) - site for posting and discussing programming puzzles
  * [/r/programmingchallenges](http://www.reddit.com/r/programmingchallenges) - a subreddit dedicated to programming challenges, could use reviving
  * [TopCoder](http://www.topcoder.com/) - online programming competitions, several times each month; solving problems from past contests is allowed for training
  * [CodeForces](http://codeforces.com) - similar to TopCoder, but more tasks at competitions, and few special features including "virtual contests"


text:
# Configuration and Structure

## Default project structure

See the [build documentation](./build.md) for details on how to customise the project structure.

### Source locations

-   config (optional. TypeScript has to be transpiled to JavaScript before building!)
    -   webpack.[target].[environment].js: Override/replaces configuration
    -   webpack-hooks.js: Add webpack options
    -   config.js: Override default configuration
    -   setup-tests.ts/js: Jest test setup
-   common: Application code
-   client
    -   index.tsx: Client entry file
    -   polyfills.ts: Polyfills (optional)
-   public: Public directory for assets that aren't bundled with the application
    -   index.html: HTML template for client-only mode
-   server
    -   start.ts: Server entry file
-   .env: Environment variables
-   .env.default: Definition of environment variables

#### Webpack hooks

To add additional config (in addition to the default webpack config, you can specify a hooks file)

The interface looks like this:

```ts
export interface WebpackHooks {
    base?: webpack.Configuration | CreateWebpackConfig
    server?: webpack.Configuration | CreateWebpackConfig
    client?: webpack.Configuration | CreateWebpackConfig
    dev?: webpack.Configuration | CreateWebpackConfig
    prod?: webpack.Configuration | CreateWebpackConfig
    serverDev?: webpack.Configuration | CreateWebpackConfig
    serverProd?: webpack.Configuration | CreateWebpackConfig
    serverDebug?: webpack.Configuration | CreateWebpackConfig
    clientDev?: webpack.Configuration | CreateWebpackConfig
    clientProd?: webpack.Configuration | CreateWebpackConfig
    clientDebug?: webpack.Configuration | CreateWebpackConfig
}
```

### Output locations

-   build/client: Client build output directory
    -   static
        -   js
            -   main.js (hashed in production build)
        -   css
            -   main.css (hashed in production build)
        -   media
        -   fonts
-   build/server: Server build output directory
    -   _server.js_: Main file generated for server
    -   ...
    -   index.html
-   assets.json: Mapping to the location of the generated assets
-   build-stats.csv: Generated build metrics

## Override default configuration

Options for the file `/config/config.js` (usage explained in the [build documentation](./build.md))

```ts
export interface BuildConfig {
    /** Prefix for all assets (JS, CSS, media, fonts) with trailing slash */
    ASSETS_PATH_PREFIX: string

    /** root path of your application */
    BASE: string

    /** entry file for the client */
    CLIENT_ENTRY: string

    /** file for client polyfills if needed */
    CLIENT_POLYFILLS: string | false

    /** output directory for the client build */
    CLIENT_OUTPUT: string

    /** set to false if the application is serverless */
    HAS_SERVER: boolean

    /** Default port for the server (when process.env.PORT is not set) */
    PORT: number

    /** URL prefix for all resources */
    PUBLIC_PATH: string

    /** entry file for the server if applicable */
    SERVER_ENTRY: string

    /** if true, all externals will be bundled */
    SERVER_BUNDLE_ALL: boolean

    /** Include all modules, except those specified */
    SERVER_BUNDLE_ALL_EXCEPT?: string[]

    /** modules which the server build includes in the bundle */
    SERVER_INCLUDE_IN_BUNDLE: string[]

    /** output directory of the server */
    SERVER_OUTPUT: string

    /** directory that is served as static resources */
    SERVER_PUBLIC_DIR: string | false

    /** if true, no hash is added to the generated assets */
    STATIC_RESOURCE_NAMES: boolean

    /** Additional environment variables for build stats */
    STATS_ENV: { [key: string]: string }

    /** Pages to run build stats on, format { name: URL } */
    STATS_PAGES: { [name: string]: string }

    /** Regular expression of paths to be ignored in watch mode */
    WATCH_IGNORE: RegExp
}
```

Default configuration:

```ts
{
    ASSETS_PATH_PREFIX: 'static/',
    ASSETS_ROOT: path.resolve(root),
    BASE: root,
    CLIENT_ENTRY: path.resolve(root, 'client', 'index.tsx'),
    CLIENT_OUTPUT: path.resolve(root, 'dist'),
    CLIENT_POLYFILLS: path.resolve(root, 'client', 'polyfills.ts'),
    HAS_SERVER: true,
    PUBLIC_PATH: '/',
    DEV_SERVER_PORT: 3000,
    /** if true, all externals will be bundled */
    SERVER_BUNDLE_ALL: false,
    SERVER_INCLUDE_IN_BUNDLE: [
        'project-watchtower',
    ],
    SERVER_ENTRY: path.resolve(root, 'server', 'start.ts'),
    SERVER_OUTPUT: path.resolve(root, 'dist'),
    SERVER_PUBLIC_DIR: path.resolve(root, 'public'),
    STATIC_RESOURCE_NAMES: false,
    STATS_ENV: {},
    STATS_PAGES: { home: '/' },
}
```

repository: sevenwestmedia/project-watchtower

repo_name: sevenwestmedia/project-watchtower


text:
### CATEGORY: Deceptive Interactions (156)
- 154 - Resource Location Spoofing
  - 161 - Route Manipulation
    - XXX - [BGP Tampering](https://github.com/elationfoundation/CAPEC_censorship/blob/master/deceptive_interaction.md#bgp-tampering)
    - XXX - [BGP Route Leaks](https://github.com/elationfoundation/CAPEC_censorship/blob/master/deceptive_interaction.md#bgp-route-leaks)
- 148 - Content Spoofing
  - 141 - Cache Poisoning
    - 142 - [DNS Cache Poisoning](https://github.com/elationfoundation/CAPEC_censorship/blob/master/deceptive_interaction.md#dns-cache-poisoning-142)

### BGP Tampering

Detailed Attack Pattern

"BGP lacks mechanisms to authenticate the allocation of IP prefixes to autonomous systems; a prefix hijacker exploits this by originating a prefix that was not allocated to its AS." [1]

An adversary originates a BGP prefix that was not allocated to its ISP's AS (autonomous system). The goal of this attack is to have the traffic destined for a legitimate service be forwarded to the adversaries AS instead of to the legitimate AS. For example, Pakistan Telecom's AS 17557 originated the subprefix <IP_ADDRESS>/24 of YouTube's prefix <IP_ADDRESS>/22 to its customer ASes in Pakistan in response to Authoritiees demanding that YouTube be censored within Pakistan. The techniques require the adversary to have control of an ISP's AS with neighbors that it can make malicious BGP announcements to.

* References
  * [1] [Why Is It Taking So Long to Secure Internet Routing?](https://queue.acm.org/detail.cfm?id=2668966)
  * [Interconnection and Traffic Exchange on the Internet](http://www.bitag.org/documents/Interconnection-and-Traffic-Exchange-on-the-Internet.pdf)
  * [2] [Practical Defenses Against BGP Prefix Hijacking](http://docs.lib.purdue.edu/cgi/viewcontent.cgi?article=1365&context=ecetr)

* Resources Required
  * AS (autonomous system)

* Method of Attack
  * BGP Prefix Hijacking

"In a prefix hijack, the hijacking AS originates the exact same prefix as the AS(es) that is legitimately allocated the victim IP prefix. The bogus BGP announcement originated by the hijacking AS will be disseminated throughout the routing system, and the other ASes will use their local policies to choose between routes to the legitimate origin AS(es) and bogus routes originated by the hijacking AS." [1]

  * BGP Subprefix Hijacking

"In a subprefix hijack, the hijacking AS originates a subprefix of the victim’s IP prefix—that is, a prefix that is covered by the victim IP prefix."

### BGP Route Leaks

Detailed Attack Pattern

"... the perpetrator announces a legitimate route that it is actually using, but announces it to too many of its neighbors. The perpetrator is then overwhelmed by a flood of traffic from neighbors that select the leaked route." [1]

An adversary announces a legitimate route, but announces it to too many neighboring ASes. The adversary is then overwhelmed by a traffic from neighbors that select the leaked route. The goal of this attack is to capture legitimate traffic that would otherwise be routed through other ASes routed through the "leaking AS". This attack can be used to intentionally censor through targeted dropping/rejection of traffic or unintentionally blackholeing all traffic by overwhelming the network. The techniques require the adversary to have control of an ISP's AS with neighbors that it can make BGP announcements to.

* Attack Motivation

" Understanding why this had an impact requires knowledge of [an AS' neighbors] local routing policies. Many routers likely including those in a neighboring [AS], are configured to prefer a route through a neighboring customer over one through a neighboring settlement-free peer. By forwarding traffic through its customers, an AS can generate more revenue. As such, [an AS' neighbors] routers [may prefer] the customer route through [the leaked route] over the usual settlement-free peering route directly to [the destination]." [1]

* References
  * [1] [Why Is It Taking So Long to Secure Internet Routing?](https://queue.acm.org/detail.cfm?id=2668966)

* Resources Required
  * ISP's AS

### [DNS Cache Poisoning](http://capec.mitre.org/data/definitions/142.html) (142)

* Mitigations

  * Hard Coded Alternate DNS server in applications
  * don't depend on DNS
  * include "hosts file"/IP address in your app
  * Use a .onion domain with Tor support

* Methods of Attack

  * Below-Recursive DNS Poisoning

An adversary provides malicious ("NXDOMAIN" ("No such domain") code, or DNS A record) DNS responses to requests made of it. This technique requires the adversary to be an otherwise legitimate recursive DNS server.

  * Above-Recursive DNS Poisoning

An adversary provides malicious ("NXDOMAIN" ("No such domain") code, or DNS A record) DNS responses to requests made of it. This technique requires the adversary to be an otherwise legitimate authority DNS server.


text:
# TL;DR

This repo has all the ingredients to make a Caddy s2i builder image.
Once built, the image can be used to simplify the build process of content that needs to be served up via Caddy such as projects based on React, Angular, or Gatsby.

# Usage

The easiest way to consume this image is to find it in Artifactory and reference it in the `sourceStrategy` section of your build config.

```yaml
  strategy:
        sourceStrategy:
          env:
          - name: BUILD_LOGLEVEL
            value: "5"
          from:
            kind: ImageStreamTag
            name: caddy-s2i-builder:latest
            namespace: bla
          incremental: false
        type: Source
```

If you can't find it, or don't have access to it, you can build your own copy in your `tools` namespace with the steps below:

First, create your own build config using the template in this repo:

```console
oc process -f https://raw.githubusercontent.com/bcgov/s2i-caddy-nodejs/master/openshift/templates/build.yaml | \
oc apply -f -
```

The OCP `builder` will need to pull a base image from the RedHat Container Registry; you'll see it as the first line in the [Dockerfile](./Dockerfile):

```console
FROM registry.redhat.io/rhel8/nodejs-14:1-72
```

To let your `builder` do this, sign-up for a *free* RedHat Developer to [this site](https://catalog.redhat.com/software/containers/search). Once you have credentials, [create a secret](https://docs.openshift.com/container-platform/3.11/dev_guide/managing_images.html#allowing-pods-to-reference-images-from-other-secured-registries) the builder can use to pull image from the catalog:

```console
oc create secret docker-registry rh-registry \
--docker-server=registry.redhat.io \
--docker-username=<USERNAME> \
--docker-password=<PASSWORD> \
--docker-email=unused
```

[Link the secret](https://docs.openshift.com/container-platform/3.11/dev_guide/managing_images.html#allowing-pods-to-reference-images-from-other-secured-registries) so the `builder` can use it; this command assumes your went with the default config name `caddy-s2i-builder` and the default secret name `rh-registry`. If you changed these, adjust the command below.

```console
oc set build-secret --pull bc/caddy-s2i-builder rh-registry
```

The final step is to trigger the build which will make the s2i caddy image and store a copy in your namespace:

```console
oc start-build bc/caddy-s2i-builder --follow
```

Reference this newly minted image in your `sourceStrategy` of your project yaml as you would any other source image.

# Creating a basic S2I builder image

This section is usefully if you want to customize this image.

## Getting started

### Files and Directories
| File                   | Required? | Description                                                  |
|------------------------|-----------|--------------------------------------------------------------|
| Dockerfile             | Yes       | Defines the base builder image                               |
| s2i/bin/assemble       | Yes       | Script that builds the application                           |
| s2i/bin/usage          | No        | Script that prints the usage of the builder                  |
| s2i/bin/run            | Yes       | Script that runs the application                             |
| s2i/bin/save-artifacts | No        | Script for incremental builds that saves the built artifacts |
| test/run               | No        | Test script for the builder image                            |
| test/test-app          | Yes       | Test application source code                                 |

#### Dockerfile
Create a *Dockerfile* that installs all of the necessary tools and libraries that are needed to build and run our application.  This file will also handle copying the s2i scripts into the created image.

#### S2I scripts

##### assemble
Create an *assemble* script that will build our application, e.g.:
- build python modules
- bundle install ruby gems
- setup application specific configuration

The script can also specify a way to restore any saved artifacts from the previous image.

##### run
Create a *run* script that will start the application.

##### save-artifacts (optional)
Create a *save-artifacts* script which allows a new build to reuse content from a previous version of the application image.

##### usage (optional)
Create a *usage* script that will print out instructions on how to use the image.

##### Make the scripts executable
Make sure that all of the scripts are executable by running *chmod +x s2i/bin/**

#### Create the builder image
The following command will create a builder image named blarb based on the Dockerfile that was created previously.
```
docker build -t blarb .
```
The builder image can also be created by using the *make* command since a *Makefile* is included.

Once the image has finished building, the command *s2i usage blarb* will print out the help info that was defined in the *usage* script.

#### Testing the builder image
The builder image can be tested using the following commands:
```
docker build -t blarb-candidate .
IMAGE_NAME=blarb-candidate test/run
```
The builder image can also be tested by using the *make test* command since a *Makefile* is included.

#### Creating the application image
The application image combines the builder image with your applications source code, which is served using whatever application is installed via the *Dockerfile*, compiled using the *assemble* script, and run using the *run* script.
The following command will create the application image:
```
s2i build test/test-app blarb blarb-app
---> Building and installing application from source...
```
Using the logic defined in the *assemble* script, s2i will now create an application image using the builder image as a base and including the source code from the test/test-app directory.

#### Running the application image
Running the application image is as simple as invoking the docker run command:
```
docker run -d -p 8080:8080 blarb-app
```
The application, which consists of a simple static web page, should now be accessible at  [http://localhost:8080](http://localhost:8080).

#### Using the saved artifacts script
Rebuilding the application using the saved artifacts can be accomplished using the following command:
```
s2i build --incremental=true test/test-app nginx-centos7 nginx-app
---> Restoring build artifacts...
---> Building and installing application from source...
```
This will run the *save-artifacts* script which includes the custom code to backup the currently running application source, rebuild the application image, and then re-deploy the previously saved source using the *assemble* script.

branch_name: refs/heads/develop

gha_language: JavaScript


text:
# Library-Py

### Requirements
To install and run this project you need:
* `Python 3.6+`
* `npm`

### How to install

1. Clone this repo `git clone https://github.com/Fredy/Library-Py.git` and `cd` to the repo directory.
2. If you have pipenv:
   ```
   pipenv install
   ```
   Otherwise: create a *virtualenv* and install the requierements in `requirements.txt`:
   ```
   pip install -r requierements.txt
   ```
3. Install the `npm` requierements: `npm install`
4. Activate the project virtualenv.
5. Create an temporal enviroment variable:
   ```
   export DJANGO_KEY='%@r_g2yvvbdemk&%&6f-k=w^e7f5-)tryvrraj6)5s8%4sc*#v' // A random string of size 50
   ```
6. Run:
   ```
   python manage.py makemigrations books
   python manage.py migrate
   python datagen.py
   python manage.py loaddata books
   ```
7. Run the servers:
   In one terminal: `python manage.py runserver`
   In another terminal: `npm run dev`

### How to use

* `http://<IP_ADDRESS>:8000/` is the *user view*, there you can search books by title, author and date.
* If you want to use the *admin* view, first you must create an account running:
  ```
  python manage.py createsuperuser --email<EMAIL_ADDRESS>--username admin
  ```
  * Then go to `http://<IP_ADDRESS>:8000/admin` to log into the admin account.
  * To create, edit and remove books, go to `http://<IP_ADDRESS>:8000/admin_page`
  * **Note:** you can only modify the database if you are loged as the admin.
  * In the current version you cannot log out, please delete the site cookies to logout.

repository: Fredy/Library-Py

repo_name: Fredy/Library-Py


text:
---
layout: page
title: CoEx
description: "Correlate-and-Excite: Real-Time Stereo Matching via Guided Cost Volume Excitation"
img: /assets/img/publications/2021_iros_lignet.gif
importance: 1
category: Research
---

D1-all% error on KITTI stereo 2015 leaderboard vs. frame rate. Our proposed method CoEx, shown in the red star, achieve competitive performance compared to other state-of-the-art models while also being real-time.

## Abstract

Volumetric deep learning approach towards stereo
matching aggregates a cost volume computed from input left
and right images using 3D convolutions. Recent works showed
that utilization of extracted image features and a spatially
varying cost volume aggregation complements 3D convolutions.
However, existing methods with spatially varying operations
are complex, cost considerable computation time, and cause
memory consumption to increase. In this work, we construct
[Guided Cost volume Excitation (GCE)](#gce) and show that simple channel excitation of cost volume guided by image can
improve performance considerably. Moreover, we propose a
novel method of using [top-k](#top-k-soft-argmin-disparity-regression) selection prior to soft-argmin
disparity regression for computing the final disparity estimate.
Combining our novel contributions, we present an end-to-end
network that we call [Correlate-and-Excite (CoEx)](#coex-overall-architecture). Extensive
experiments of our model on the SceneFlow, KITTI 2012,
and KITTI 2015 datasets demonstrate the effectiveness and
efficiency of our model and show that our model outperforms
other speed-based algorithms while also being competitive to
other state-of-the-art algorithms

\[[Paper]()\]   \[[Code](https://github.com/antabangun/coex)\]

## Contributions

- We present Guided Cost volume Excitation (GCE) to utilize extracted feature map from image as guidance for cost aggregation to improve performance.
- We propose a new method of disparity regression in place of soft-argmax(argmin) to compute disparity from the top-k matching cost values and show that it reliably improves performance.
- Through these methods, we build a real-time stereo matching network CoEx, that outperforms other speedoriented methods and shows its competitiveness when compared to state-of-the-art models.

## CoEx overall architecture

### GCE

 GCE excites stereo cost volume using weights extracted from image features.

Computed excitation weights in one of the GCE layers.

### Top-k soft-argmin disparity regression

 Instead of computing disparity by soft-argmin using the whole cost volume, only the top-k relevant values are used.

Ground truth disparity is represented by vertical solid green line. Predicted disparity is vertical dashed red line. *k=2* makes the closest regression estimates to the ground truth.

        Top-48

        Top-2

    Activation strengths at fronto-parallel slices of the cost volume for top-48 and top-2 soft-argmax regression. Red represents stronger activation and blue is weak. Notice how the activations with top-2 regression is stronger and sharper.

## Demo

### Real-time stereo matching

CoEx (Ours)

            PSMNet

        [1]

            GANet

        [2]

    Speed comparison with previous works. *The images shown are compressed, so image quality may not reflect the real output of the models.

### Stereo 3D reconstruction

Reconstructed 3d point cloud computed from the predicted stereo disparity map.

### Application - visual odometry and point cloud mapping

Application test using the computed stereo depth to perform visual odometry and point cloud mapping.

### Related works
[\[1\] J.-R. Chang and Y.-S. Chen, “Pyramid stereo matching network,” in
CVPR, 2018](https://openaccess.thecvf.com/content_cvpr_2018/papers/Chang_Pyramid_Stereo_Matching_CVPR_2018_paper.pdf)
[\[2\] F. Zhang, V. Prisacariu, R. Yang, and P. H. Torr, “Ga-net: Guided
aggregation net for end-to-end stereo matching,” in CVPR, 2019.](https://openaccess.thecvf.com/content_CVPR_2019/papers/Zhang_GA-Net_Guided_Aggregation_Net_for_End-To-End_Stereo_Matching_CVPR_2019_paper.pdf)

extension: markdown


text:
# Starcounter.Linq

Starcounter.Linq is a LINQ to SQL Provider for Starcounter. It uses standard LINQ syntax for queries.

It is available for downloading as [Starcounter.Linq](https://www.nuget.org/packages/Starcounter.Linq/) NuGet package.

## Versioning

| Starcounter.Linq versions | Supported Starcounter version |
|---------------------------|-------------------------------|
| [1.*](https://github.com/Starcounter/Starcounter.Linq/tree/master)  | 2.3.1, 2.3.2 |
| [2.*](https://github.com/Starcounter/Starcounter.Linq/tree/develop) | 2.4          |
| [3.*](https://github.com/Starcounter/Starcounter.Linq/tree/nova)    | Nova         |

## How to use

First, in your Starcounter app, add a reference to `Starcounter.Linq.dll` through NuGet: `Install-Package Starcounter.Linq`.

`DbLinq` static class defined in `Starcounter.Linq` namespace should be used as starting point when you want to build LINQ queries. It contains two important methods: `Objects<T>` and `CompileQuery<T>` (many overloaded ones) which are used for two different approaches. For example:

```csharp
// ad-hoc request
var johns = DbLinq.Objects<Person>().Where(p => p.Name == "John");

// request using compiled query
var peopleByNameQuery = DbLinq.CompileQuery((string name) =>
                        DbLinq.Objects<Person>().Where(p => p.Name == name));
var jennifers = peopleByNameQuery("Jennifer");
```

## Ad-hoc requests

With this approach, you build a LINQ expression and obtain data as usual when an application needs it.

`DbLinq.Objects<T>()` returns a data context `Queryable<T>` which can be used for obtaining data.

The LINQ expression is translated to SQL every time it's called if `DbLinq.Objects<T>()` is called. This is an expensive operation. Thus, don't use `DbLinq.Objects<T>()` in places where it's executed many times.

Example:

```csharp
// this method is rarely used, so we can use ad-hoc requests here
void Handle(Input.DeleteGroupTrigger action)
{
    Db.Transact(() =>
    {
        var surfaces = DbLinq.Objects<WebTemplate>().Where(x => x.WebTemplateGroup == this.Data);

        foreach (WebTemplate surface in surfaces)
        {
            surface.WebTemplateGroup = null;
        }
        this.Data.Delete();
    });
}
```

## Compiled query

Compiled query lets you build a LINQ expression with translated SQL once and use it many times.

`DbLinq.CompileQuery<T>` returns a delegate `Func<IEnumerable<T>>` which can be invoked to execute the compiled query. It has many overloads and it supports passing parameters.

Use `DbLinq.CompileQuery<T>()` in places where the query will be executed many times since it only translates the LINQ statement to SQL one time which makes subsequent calls fast.

Example:

```csharp
partial class SurfacePage : Json
{
    private static readonly Func<IEnumerable<WebTemplate>> SurfaceGroupsQuery = DbLinq.CompileQuery(() =>
            DbLinq.Objects<WebTemplateGroup>().Where(x => !x.Deleted));

    private static readonly Func<WebTemplate, IEnumerable<WebUrl>> RoutesQuery =
        DbLinq.CompileQuery((WebTemplate surface) =>
            DbLinq.Objects<WebUrl>()
                .Where(x => !x.Deleted && !x.Hidden)
                .Where(x => x.Template == surface)
                .OrderBy(x => x.SortNumber));
    /*
    ...
    */

    // this method is often called, so we should use compiled queries
    public void RefreshData()
    {
        this.SurfaceGroups.Data = SurfaceGroupsQuery();
        this.Routes.Data = RoutesQuery(this.Data);
    }
}
```

Compiled queries are more restricted than ad-hoc requests since it represents a pre-translated SQL and should support passing parameters. Read more about the restrictions below.

## Restrictions

### Database fields

Starcounter.Linq **only supports database properties**. It is not possible to get access to fields.

Example:

```csharp
// throws System.MissingFieldException since Name is a field
DbLinq.Objects<WebTemplateGroup>().OrderBy(x => x.Name);

// works well since SortNumber is defined as property
DbLinq.Objects<WebTemplateGroup>().OrderBy(x => x.SortNumber);
```

The exception will be thrown when calling the method which contains the query definition, which means that the exception will not be thrown from Starcounter.Linq code.

### `Take` and `Skip` methods

Starcounter.Linq uses literal values for `FETCH` and `OFFSET` clauses for performance reason, it means that you cannot pass the value when executing a compiled query.

Example:

```csharp
// works well
var people = DbLinq.Objects<Person>().Take(10).Skip(20).ToList();

// does not work
var query = DbLinq.CompileQuery((int take, int skip) => DbLinq.Objects<Person>().Take(take).Skip(skip));
people = query(10, 20);

// works well
var query = DbLinq.CompileQuery(() => DbLinq.Objects<Person>().Take(10).Skip(20));
people = query();
```

### NULL values

Since comparisons with `null` values are translated to `IS NULL` form in SQL, there is no possibility to pass such values with parameters into compiled queries. Starcounter.Linq throws an exception in such cases.

Example:

```csharp
Office office = GetOffice();    // can be null
Office noOffice = null;

// ad-hoc requests works well without restrictions
var employee1 = DbLinq.Objects<Employee>().FirstOrDefault(p => p.Office != null);
var employee2 = DbLinq.Objects<Employee>().FirstOrDefault(p => p.Office == office);

// works well
var withoutOfficeQuery = DbLinq.CompileQuery(() =>
                         DbLinq.Objects<Employee>().FirstOrDefault(p => p.Office != null));
var withoutOfficeQuery2 = DbLinq.CompileQuery(() =>
                          DbLinq.Objects<Employee>().FirstOrDefault(p => p.Office == noOffice));

var withOfficeQuery = DbLinq.CompileQuery((notNullOffice) =>
                      DbLinq.Objects<Employee>().FirstOrDefault(p => p.Office == notNullOffice));

// it does not work because the SQL query has been translated and IS NULL cannot be inserted
employee1 = withOfficeQuery(null);  // ArgumentNullException will be thrown

// that should be written in the following way
employee1 = office == null ? withoutOfficeQuery() : withOfficeQuery(office);
```

### `Contains` method

The `Contains` method is supported by ad-hoc requests but not by compiled queries.

Example:

```csharp
var ages = new[] { 41, 42, 43 };
var person = Objects<Person>().FirstOrDefault(p => ages.Contains(p.Age));
```

### Deleting data

Deleting data is supported by ad-hoc requests but not by compiled queries.

Example:

```csharp
Objects<Person>().Delete(x => x.Age > 40);
Objects<Person>().DeleteAll();
```

## Supported features

- `SELECT` clause, also by using `IQueryable.Select` method
- `WHERE` clause by using methods:
  - `IQueryable.Where`
  - `IQueryable.First`
  - `IQueryable.FirstOrDefault`
  - `IQueryable.Single`
  - `IQueryable.SingleOrDefault`
  - `IQueryable.Count`
  - `IQueryable.Any`
- `ORDER BY` clause by using methods:
  - `IQueryable.OrderBy`
  - `IQueryable.OrderByDescending`
  - `IQueryable.ThenBy`
  - `IQueryable.ThenByDescending`
- `GROUP BY` clause by using `IQueryable.GroupBy` method. Aggregation is required by using one of the following methods inside of `IQueryable.Select` one:
  - `IEnumerable.Count`
  - `IEnumerable.LongCount`
  - `IEnumerable.Average`
  - `IEnumerable.Min`
  - `IEnumerable.Max`
  - `IEnumerable.Sum`
- Logical operators `AND`, `OR`, `NOT` by using `&&`, `||`, `!` operators in LINQ queries
- Comparison by using:
  - operators `=`, `>`, `>=`, `<`, `<=`, `<>`
  - method `Object.Equals`
- `LIKE` operator by using methods:
  - `String.Contains`
  - `String.EndsWith`
- `STARTS WITH` operator by using `String.StartsWith` method
- `IEnumerable.Contains` method in LINQ queries
- `DbHelper.GetObjectNo` method in LINQ queries
- `IS` operator by using `is` operator in LINQ queries
- `OFFSET` clause by using `IQueryable.Skip` method
- `FETCH` clause by using methods:
  - `IQueryable.Take`
  - `IQueryable.FirstOrDefault`
  - `IQueryable.First`
  - `IQueryable.Single`
  - `IQueryable.SingleOrDefault`
- `COUNT` function by using methods `IQueryable.Count` and `IQueryable.LongCount`
- `AVG` function by using method `IQueryable.Average`
- `MIN` function by using method `IQueryable.Min`
- `MAX` function by using method `IQueryable.Max`
- `SUM` function by using method `IQueryable.Sum`
- Calculating expression values in LINQ queries
- `DELETE FROM` statement by using methods:
  - `Starcounter.Linq.Queriable.Delete`
  - `Starcounter.Linq.Queriable.DeleteAll`
- Using of generic types for a query context
- Overridden `IQueryable.ToString` for providing of generated SQL queries

## Unsupported features

- `IQueryable.All` method - [#31](https://github.com/Starcounter/Starcounter.Linq/issues/31)
- Querying a specific set of data properties (currently supports only single property querying) - [#60](https://github.com/Starcounter/Starcounter.Linq/issues/60)

-----

**For the latest news, look at the [Starcounter Blog](https://starcounter.io/blog/).**

gha_language: C#