text:
Fields imported by Azure Importer Plugin
====================================================================

This is a short breakdown of information returned by the various importer
object types. Obviously, each object type has to return its individual set
of fields to match the resources given by Azure.

Any query returns at least these fields by the time of writing:

* name
* subscriptionId
* id
* location
* provider
* type

The 'name' is the name chosen in Microsoft Azure for the returned object. The
'subscriptionId' is just for convenience to group inventories if you have
multiple subscriptions you are importing of. An 'id' is simply the returned
id from Azure which is the path of the URI of the object in the API for most of
times, which includes the subscription id itself. The 'id' field may not be
unique. The 'location' field is the location returned from Azure and contains
the Azure region the object is located in.

The 'type' field is just a static string derived from the API query
to give a reference to the main API call that was used and to provide the
IcingaWeb2 Director user with something to group results.

The 'metricDefinitions' field is a comma separated list with metric names
available for this object type, if available. (cf.
https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-supported-metrics?toc=/azure/azure-monitor/toc.json )

Virtual Machines
----------------

The **Virtual machines** object type does return these fields:

* name
* subscriptionId
* id
* location
* type
* osType
* osDiskName
* dataDisks
* network_interfaces_count
* publicIP
* privateIP
* cores
* resourceDiskSizeInMB
* memoryInMB
* maxDataDiscCount
* prosioningState
* metricDefinitions
* tags
* state

Please note that this reports the private and/or public IP of the first
interface found.

Virtual Machines (Disks)
------------------------

The **Virtual machines (disks)** object type does return these fields:

* name
* subscriptionId
* id
* location
* type
* managedBy
* diskState
* provisioningState
* timeCreated
* diskSizeGB
* osType
* createOption
* imageReferenceId
* imageReferenceLun
* sourceUri
* sourceResourceId
* encryptionEnabled
* vmName
* vmUsageType
* vmCaching
* vmLocation
* vmProvisioningState

Virtual Machines (Interfaces)
-----------------------------

Please note, the interfaces will show only one ip configuration on the VM
query class VirtualMachines. In opposition, this class
"VirtualMachinesInterfaces" will create an interface object for each
ip configuration found on the network interface. Therefore the object id
man not be unique and I introduced a second field uniqueId, which is
assembled from the interface id as well as the ip configuration id.

The **Virtual machines (interfaces)** object type does return these fields:

* name
* subscriptionId
* id
* type
* uniqueId
* location
* etag
* provisioningState
* macAddress
* enableAcceleratedNetworking
* enableIPForwarding
* networkSecurityGroupId
* dnsServers
* appliedDnsServers
* internalDnsNameLabel
* internalFqdn
* internalDomainNameSuffix
* virtualMachineId
* vmName
* vmLocation
* vmProvisioningState
* ipConfName
* ipConfId
* ipConfEtag
* ipConfProvisioningState
* ipConfPrivateIPAddress
* ipConfPrivateIPAllocationMethod
* ipConfSubnetId
* ipConfPrimary
* ipConfPrivateIPAddressVersion
* ipConfInUseWithService
* ipConfPublicIPAddressId
* ipConfPublicIPAddressName
* ipConfPublicIPAddress
* ipConfPublicIPAddressProvState
* ipConfPublicIPAddressVersion
* ipConfPublicIPAllocationMethod
* ipConfPublicIPAddressLocation
* ipConfPublicIPAddressIdleTimeoutInMinutes
* metricDefinitions

Load Balancers
--------------

https://docs.microsoft.com/en-us/rest/api/load-balancer/loadbalancers/list

* name
* subscriptionId
* id
* type
* location
* provisioningState
* frontEndPublicIP
* metricDefinitions

Application Gateways
--------------------

https://docs.microsoft.com/en-us/rest/api/application-gateway/applicationgateways/list

* name
* subscriptionId
* id
* type
* location
* provisioningState
* frontEndPublicIP
* frontEndPrivateIP
* operationalState
* frontEndPort
* enabledHTTP2
* enabledWAF
* metricDefinitions

Express Route Circuits
----------------------

https://docs.microsoft.com/en-us/rest/api/expressroute/expressroutecircuits/list

* name
* subscriptionId
* id
* location
* type
* provisioningState
* bandwithInGbps
* circuitProvisioningState
* allowClassicOperations
* serviceProviderName
* serviceproviderProvisioningState
* serviceProviderBandwitdthInMbps  1)
* peeringlocation
* metricDefinitions
* etag
* expressRoutePort
* gatewayManagerEtag
* serviceKey
* serviceProviderNotes
* stag
* skuName
* skuTier
* skuFamily
* tags
* authorizations
* peerings

1) was renamed from bandwithInMbps

Express Route Circuits (Authorizations)
---------------------------------------

https://docs.microsoft.com/en-us/rest/api/expressroute/expressroutecircuitauthorizations/list

* name
* id
* etags
* metricDefinitions
* type
* subscriptionId
* provisioningState
* expressRouteCircuitName
* authorizationKey
* authorizationUseStatus

Express Route Circuits (Peerings)
---------------------------------

https://docs.microsoft.com/en-us/rest/api/expressroute/expressroutecircuitpeerings/list

* name
* id
* etag
* metricDefinitions
* type
* subscriptionId
* expressRouteCircuitName
* provisioningState
* peeringType
* azureASN
* peerASN
* primaryPeerAddressPrefix
* primaryAzurePort
* secondaryPeerAddressPrefix
* secondaryAzurePort
* state
* statsPrimaryBytesIn
* statsPrimaryBytesOut
* statsSecondaryBytesIn
* statsSecondaryBytesOut
* vlanId
* lastModifiedBy
* gatewayManagerEtag
* sharedKey

Microsoft DB for PostgreSQL (server)
------------------------------------

https://docs.microsoft.com/en-us/rest/api/postgresql/servers/list

* name
* subscriptionId
* id
* location
* type
* version
* tier
* capacity
* sslEnforcement
* userVisibleState
* fqdn
* earliestRestoreDate
* storageMB
* backupRetentionDays
* geoRedundantBackup
* metricDefinitions

Microsoft DB for PostgreSQL (databases)
---------------------------------------

https://docs.microsoft.com/en-us/rest/api/postgresql/databases/listbyserver

* name
* subscriptionId
* id
* location          - the location of the server
* type
* metricDefinitions - currently empty
* charset
* collation

Microsoft DB for PostgreSQL (configurations)
--------------------------------------------

https://docs.microsoft.com/en-us/rest/api/postgresql/configurations/listbyserver

* name
* subscriptionId
* id
* location
* type
* metricDefinitions
* allowedValues
* dataType
* defaultValue
* description
* source
* value

Microsoft DB for PostgreSQL (firewall rules)
--------------------------------------------

https://docs.microsoft.com/en-us/rest/api/postgresql/firewallrules/listbyserver

* name
* subscriptionId
* id
* type
* metricDefinitions
* endIpAddress
* startIpAddress

Microsoft DB for PostgreSQL (virtual network rules)
------------------------------------------------

https://docs.microsoft.com/en-us/rest/api/postgresql/virtualnetworkrules/listbyserver

* name
* subscriptionId
* id
* type
* metricDefinitions
* ignoreMissingVnetServiceEndpoint
* state
* virtualNetworkSubnetId

Microsoft DB for PostgreSQL (security alert policies)
------------------------------------------------------

https://docs.microsoft.com/en-us/rest/api/postgresql/serversecurityalertpolicies/get

* name
* subscriptionId
* id
* type
* metricDefinitions
* disabledAlerts
* emailAccountAdmins
* emailAddresses
* retentionDays
* state
* storageAccountAccessKey
* storageEndpoint

Microsoft DB for PostgreSQL (location based performance tiers)
----------------------------------------------------------------------

https://docs.microsoft.com/en-us/rest/api/postgresql/locationbasedperformancetier/list

This importer gets all locations from any MS PostgreSQL server (SAAS) available
in the current subscription. On these locations, the location based performance
tier API is queried and the result is presented here. "slo" stands for "service
level objective".

* name
* subscriptionId
* id
* type
* metricDefinitions
* sloHardwareGeneration
* sloId
* sloMaxBackupRetentionDays
* sloMaxStorageMB
* sloMinBackupRetentionDays
* sloMinStorageMB
* sloVCore

Resource Groups
---------------

The simple query for resource groups available in the given subscription
might not be too usefull in Azure but on the one hand you could monitor
the provisioning state. The primary reason for this to exist is as a helper
for the dynamically generated configuration menu for all importers based
on this Azure API director plugin.

* name
* subscriptionId
* id
* location
* type
* provisioningState

Subscriptions
-------------

The simple query for subscriptions available with the given credentials.
This might not be too usefull in Azure but on the one hand you could monitor
the subscription state. The primary reason for this to exist is as a helper
for the dynamically generated configuration menu for all importers based
on this Azure API director plugin.

* name
* subscriptionId
* id
* type
* state
* locationPlacementId
* quotaId
* spendingLimit

Container Registries
--------------------

https://docs.microsoft.com/en-us/rest/api/containerregistry/registries/list

* name
* id
* subscriptionId
* location
* type
* metricDefinitions
* tags
* skuName
* skuTier
* loginServer
* creationDate
* provisioningState
* statusDisplayStatus
* statusMessage
* statusTimestamp
* adminUserEnabled
* storageAccountId
* policiesQuarantinePolicyStatus
* policiesTrustPolicyStatus
* policiesTrustPolicyType

gha_language: PHP


text:
---
layout: article
title:  SOHCAHTOA
author: Willy McAllister
comments: true
---

SOH CAH TOA helps you remember the definitions of sine, cosine, and tangent based on the sides of a right triangle,

![SOHCAHTOA triangle]({{ site.baseurl }}{% link i/sohcahtoa.svg%}){: .centered :}

$\sin \theta = \dfrac{\text{opposite}}{\text{hypotenuse}}\qquad$ **S**ine is **O**pposite over **H**ypotenuse (SOH)

$\cos \theta = \dfrac{\text{adjacent}}{\text{hypotenuse}}\qquad$ **C**osine is **A**djacent over **H**ypotenuse (CAH)

$\tan \theta = \dfrac{\text{opposite}}{\text{adjacent}}\quad\qquad$ **T**angent is **O**pposite over **A**djacent (TOA)

license: MIT

branch_name: refs/heads/master

extension: md

gha_language: JavaScript

gha_license_id: MIT

license_type: permissive


text:
# apkinfo
A command what to look up a apk info, that include meta-data applicationid versioncode versionname etc.

![image](docs/images/apkinfo.gif)

# How to

> How to install

* HomeBrew

    ```
     brew tap davidzou/apkinfo
     brew install apkinfo
    ```

* BashShell

    ```
     bash deploy.sh ${dest}

     ~/.bash_profile or ~/.bashrc or /etc/profile

     export PATH=${dest}:$PATH
    ```
> How to use

```
  apkinfo xxx.apk
```

# License

```
Copyright 2017 DavidZou

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

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

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

repository: davidzou/homebrew-apkinfo

repo_name: davidzou/homebrew-apkinfo


text:
# Gateway

## Overview

This is the repository for the Kyma Gateway.

## Prerequisites

The Gateway requires Go 1.8 or higher.

## Installation

To install the Gateway, follow these steps:

1. `git clone git@github.com:kyma-project/kyma.git`
1. `cd kyma/components/gateway`
1. `CGO_ENABLED=0 go build ./cmd/gateway`

## Usage

This section explains how to use the Gateway.

### Start the Gateway
To start the Gateway, run this command:

```
./gateway
```

The Gateway has the following parameters:
- **proxyPort** - This port acts as a proxy for the calls from services and lambdas to an external solution. The default port is `8080`.
- **externalAPIPort** - This port exposes the Gateway API to an external solution. The default port is `8081`.
- **eventsTargetURL** - A URL to which you proxy the incoming events. The default URL is http://localhost:9000.
- **remoteEnvironment** - Remote Environment name used to write and read information about services. The default remote environment is `default-ec`.
- **appName** - The name of the gateway instance. The default appName is `gateway`.
- **namespace** - Namespace where Gateway is deployed. The default namespace is `kyma-system`.
- **requestTimeout** - A time-out for requests sent through the Gateway. It is provided in seconds. The default time-out is `1`.
- **skipVerify** - A flag for skipping the verification of certificates for the proxy targets. The default value is `false`.
- **requestLogging** - A flag for logging incoming requests. The default value is `false`.
- **proxyTimeout** - A time-out for request send through Gateway proxy in seconds. The default is `10`.
- **proxyCacheTTL** - Time to live of Remote API information stored in proxy cache. The value is provided in seconds and the default is `120`.

The parameters for the Event API correspond to the fields in the [Remote Environment](https://github.com/kyma-project/kyma/tree/master/docs/remote-environment.md):

- **sourceEnvironment** - The name of the Event source environment.
- **sourceType** - The type of the Event source.
- **sourceNamespace** - The organization that publishes the Event.

## Development

This section explains the development process.

### Rapid development with Telepresence

Gateway stores its state in the Kubernetes Custom Resource, therefore Gateway is dependent on Kubernetes. You cannot mock the dependency. You cannot develop locally. Manual deployment on every change is a mundane task.

You can, however, leverage [Telepresence](https://www.telepresence.io/). This works by replacing a container in a specified pod, opening up a new local shell or a pre-configured bash, and proxying the network traffic from the local shell through the pod.

Although you are on your local machine, you can make calls such as `curl http://....svc.cluster.local:8081/v1/health`. When you run a server in this shell, other Kubernetes services can access it.

1. [Install telepresence](https://www.telepresence.io/reference/install).
2. Run Kyma or use the cluster. In the case of Kyma, point your local kubectl to Kyma in Docker.
3. Check the deployment name to swap and run: `telepresence --namespace <NAMESPACE> --swap-deployment <DEPLOYMENT_NAME>:<CONTAINER_NAME> --run-shell`
```bash
telepresence --namespace kyma-system --swap-deployment kyma-core-gateway:gateway --run-shell
```
4. Every Kubernetes pod has `/var/run/secrets` mounted. The Kubernetes client uses it in the Gateway. It is hardcoded. By default, telepresence copies this directory. It stores the directory path in `$TELEPRESENCE_ROOT`, under telepresence shell. It unwinds to `/tmp/tmp...`. You need to move it to `/var/run/secrets`, where the Gateway expects it. Create a symlink:
 ```bash
sudo ln -s $TELEPRESENCE_ROOT/var/run/secrets /var/run/secrets
```
5. Use the `make build` and then the `./gateway` commands, and now all the Kubernetes services that call gateway access this process. The process runs locally on your machine.

You can also run another shell to make calls to this gateway. To run this shell, swap the Remote Environment Broker deployment, because istio sidecar is already injected into this deployment:
```bash
telepresence --namespace kyma-system --swap-deployment kyma-core-remote-environment-broker:reb --run-shell
```

### Generate mocks

To generate a mock, follow these steps:

1. Go to the directory where the interface is located.
2. Run this command:
```sh
mockery -name=Sender
```

### Tests

This section outlines the testing details.

#### Unit tests

To run the unit tests, use the following command:

```
go test `go list ./internal/... ./cmd/...`
```
### Generate Kubernetes clients for custom resources

1. Create a directory structure for each client, similar to the one in `pkg/apis`. For example, when generating a client for EgressRule in Istio, the directory structure looks like this: `pkg/apis/istio/v1alpha2`.
2. After creating the directories, define the following files:
    - `doc.go`
    - `register.go`
    - `types.go` - define the custom structs that reflect the fields of the custom resource.

See an example in `pkg/apis/istio/v1alpha2`.

3. Go to the project root directory and run `./hack/update-codegen.sh`. The script generates a new client in `pkg/apis/client/clientset`.

### Contract between the Gateway and the UI API Facade

The UI API Facade must check the status of the Gateway instance that represents the Remote Environment.
In the current solution, the UI API Facade iterates through services to find those which match the criteria, and then uses the health endpoint to determine the status.
The UI API Facade has the following obligatory requirements:
- The Kubernetes Gateway service uses the `remoteEnvironment` key, with the value as the name of the remote environment.
- The Kubernetes Gateway service contains one port with the `ext-api-port` name. The system uses this port for the status check.
- Find the Kubernetes Gateway service in the `kyma-integration` Namespace. You can change its location in the `ui-api-layer` chart configuration.
- The `/v1/health` endpoint returns a status of `HTTP 200`. Any other status code indicates the service is not healthy.

### Access the Gateway on Minikube

To access the Gateway locally, provide the NodePort of the `core-nginx-ingress-controller` when you send the request.

To get the NodePort, run this command:

```
kubectl -n kyma-system get svc core-nginx-ingress-controller -o 'jsonpath={.spec.ports[?(@.port==443)].nodePort}'
```

To send the request, run:

```
curl https://gateway.kyma.local:{NODE_PORT}/ec-default/v1/metadata/services --cert ec-default.crt --key ec-default.key -k
```

### Contract between the Application Connector and the UI API Facade

The UI API Facade must check the status of the Application Connector service instances that represent the Remote Environment.
In the current solution, the UI API Facade iterates through services to find those which match the criteria, and then uses the health endpoint to determine the status.
The UI API Facade has the following obligatory requirements:
- The Kubernetes service for each Application Connector service that uses the **remoteEnvironment** key with the name of the Remote Environment as a value.
- The Kubernetes service for each Application Connector service which contains one port with the `ext-api-port` name. The system uses this port for the status check.
- Find the Kubernetes Application Connector service in the `kyma-integration` Namespace. You can change its location in the `ui-api-layer` chart configuration.
- The `/v1/health` endpoint which returns an `HTTP 200` status. Any other status code indicates that the service is not healthy.

### Contribution

To learn how you can contribute to this project, see the [Contributing](/CONTRIBUTING.md) document.

repository: Disper/kyma

repo_name: Disper/kyma


text:
## command line tools for web developers

Life as a web developer can be hard when things start going wrong. The problem could be in any number of places. Is there a problem with the request your sending, is the problem with the response, is there a problem with a request in a third party library you're using, is an external API failing? There are lots of different tools that can make our life a little bit easier. Here are some command line tools that I've found to be invaluable.

**Curl** Curl is a network transfer tool that's very similar to wget, the main difference being that by default wget saves to file, and curl outputs to the command line. This makes is really simple to see the contents of a website. Here, for example, we can get our current IP from the ifconfig.me website:

    $ curl ifconfig.me
    <IP_ADDRESS>
Curl's -i (show headers) and -I (show only headers) option make it a great tool for debugging HTTP responses and finding out exactly what a server is sending to you:

    $ curl -I news.ycombinator.com
    HTTP/1.1 200 OK
    Content-Type: text/html; charset=utf-8
    Cache-Control: private
    Connection: close
The -L option is handy, and makes Curl automatically follow redirects. Curl has support for HTTP Basic Auth, cookies, manually settings headers, and much much more.

**Siege** Siege is a HTTP benchmarking tool. In addition to the load testing features it has a handy -g option that is very similar to curl -iL except it also shows you the request headers. Here's an example with www.google.com (I've removed some headers for brevity):

    $ siege -g www.google.com
    GET / HTTP/1.1
    Host: www.google.com
    User-Agent: JoeDog/1.00 [en] (X11; I; Siege 2.70)
    Connection: close

    HTTP/1.1 302 Found
    Location: http://www.google.co.uk/
    Content-Type: text/html; charset=UTF-8
    Server: gws
    Content-Length: 221
    Connection: close

    GET / HTTP/1.1
    Host: www.google.co.uk
    User-Agent: JoeDog/1.00 [en] (X11; I; Siege 2.70)
    Connection: close

    HTTP/1.1 200 OK
    Content-Type: text/html; charset=ISO-8859-1
    X-XSS-Protection: 1; mode=block
    Connection: close

What siege is really great at is server load testing. Just like ab (apache benchmark tool) you can send a number of concurrent requests to a site, and see how it handles the traffic. With the following command we test google with 20 concurrent connections for 30 seconds, and then get a nice report at the end:

    $ siege -c20 www.google.co.uk -b -t30s
    ...
    Lifting the server siege...      done.
    Transactions:                    1400 hits
    Availability:                 100.00 %
    Elapsed time:                  29.22 secs
    Data transferred:              13.32 MB
    Response time:                  0.41 secs
    Transaction rate:              47.91 trans/sec
    Throughput:                     0.46 MB/sec
    Concurrency:                   19.53
    Successful transactions:        1400
    Failed transactions:               0
    Longest transaction:            4.08
    Shortest transaction:           0.08

One of the most useful features of siege is that it can take a url file as input, and hit those urls rather than just a single page. This is great for load testing, because you can replay real traffic against your site and see how it performs, rather than just hitting the same URL again and again. Here's how you would use siege to replay your apache logs against another server to load test it with:

    $ cut -d ' ' -f7 /var/log/apache2/access.log > urls.txt
    $ siege -c<concurreny rate> -b -f urls.txt

**Ngrep** For serious network packet analysis there's [Wireshark](http://www.wireshark.org/), with it's thousands of settings, filters and different configuration options. There's also a command line version, tshark. For simple tasks I find wireshark can be overkill, so unless I need something more powerful, ngrep is my tool of choice. It allows you to do with network packets what grep does with files.

For web traffic you almost always want the `-W` byline option which preserves linebreaks, and `-q` is a useful argument which supresses some additional output about non-matching packets. Here's an example that captures all packets that contain GET or POST:

    ngrep -q -W byline "^(GET|POST) .*"

You can also pass in additional packet filter options, such as limiting the matched packets to a certain host, IP or port. Here we filter all traffic going to or coming from google.com, port 80, and that contains the term "search".

    ngrep -q -W byline "search" host www.google.com and port 80

Posted on 13 Aug 2011

repository: koctya/dotfiles

path: /notes/unix/command line tools.md

filename: command line tools.md

repo_name: koctya/dotfiles


text:
Grails JavaScript Controller Plugin
=====================

[![Build Status](https://travis-ci.org/danveloper/grails-js-controllers.png?branch=master)](https://travis-ci.org/danveloper/grails-js-controllers)

This plugin offers developers the ability to write classes in JavaScript, and have Grails respect them as controllers. The default path from which the plugin resolves controllers is the `web-app/WEB-INF/js.controllers` directory. This directory is automatically created at plugin installation time.

Controllers
---
In the same way that Grails controllers are little more than (albeit enhanced) Groovy classes, JavaScript controllers can be any class that has a corresponding method to handle the incoming action.

```javascript

function PaymentController() {

	this.index = function(params) {
	    return {foo: 'bar', c: "payment"};
	}

}

ApplicationContainer.register("payment.controller", PaymentController, { scope: "prototype" });

```

The above example defines a controller and registers it for use within the Grails context. The key to the mapping is the first parameter to the `register` method, which declared the path that is to be handled by this controller. JavaScript controllers are resolved by convention given a **.controller** suffix. In this example, requests to **/payment/index** will delegate to the `index` function of the `PaymentController` class. All JavaScript controllers must register themselves as `path`.`controller` within the `ApplicationContainer`.

Actions should return a JavaScript object representing the model. This return object will be coerced to a Map before being delegated to the view.

Controllers can be optionally initialized by provising an `init` method to the options parameter during registration.

```javascript

function PaymentController {

	this.initialized = false;

	this.init = function() {
		this.initialized = true;
	};

	this.index = function(params) {
		return {foo: 'bar', c: "payment"};
	};
}

ApplicationContainer.register("payment.controller", PaymentController, { scope: "prototype", init: "init" });

```

Initialization methods can be used to setup per-instance variables or properties.

But, before your controller is to be reigstered within the `ApplicationContainer`, the script must first be loaded into the JavaScript execution environment. When being loaded, scripts are resolved relative to the `web-app/WEB-INF/js.controllers` directory. Scripts are loaded with the `load(String)` method off of the `JsControllersApplicationContainer` class. Accessing this class must be performed through dependency injection or application context lookup.

For example, you may load a JavaScript controller at application initialization from your `BootStrap.groovy` class:

```groovy
class BootStrap {

    def grailsApplication

    def init = { servletContext ->
        def container = grailsApplication.mainContext.getBean(JsControllersApplicationContainer)
        container.load("payment.controller.js")
    }
    def destroy = {
    }
}
```

You can think about registering your controller as a two-step process: the first step is to load your script within the JavaScript execution context; the second step is to have your script register itself with the `ApplicationContainer`.

This registration process can also be performed dynamically and at runtime. As long as each JavaScript controller registers itself within the `ApplicationContainer`, and follows the conventions outlined above, the controllers will be resolved for otherwise unmapped urls.

Scripts can also be registered from the classpath. Using the **classpath:** prefix to the script name when calling the `load(String)` method will instruct the plugin to resolve the script from the classpath instead of from a path relative to the `web-app/WEB-INF/js.controllers` directory.

```groovy
class BootStrap {

    def grailsApplication

    def init = { servletContext ->
        def container = grailsApplication.mainContext.getBean(JsControllersApplicationContainer)
        container.load("classpath:controllers/payment.controller.js")
    }
    def destroy = {
    }
}
```

Parameters
---
Each controller action should take a single argument. This argument is a Map of the parameters from the request. Parameters need to be explicitly retrieved and set, as the following example demonstrates.

```javascript
function PaymentController() {

    this.index = function(params) {
        return {foo: 'bar', c: "payment", name: params.get("name")};
    }

}
```

While the params object allows for explicit `get` and `put` operations, it also allows you direct access to the `request` object from within your JavaScript controller action. The request object is an instance of an HttpServletRequest and can be treated as such.

Services
---
The plugin exposes the beans from the Grails application to the JavaScript controllers. This means that the JavaScript controller has access to the extent of the Grails application context. Accessing services or other controllers is as simple as directly accessing the "wired" bean. Beans are wired into the JavaScript execution context by name, so referencing them from the controller should be handled as regular in the same manner as accessing a property.

Given a Grails Service, `MyGrailsService`:

```groovy
class MyGrailsService {

	def serviceMethod(String arg) {
		// ... do some stuff ...
	}

}
```

Call the `serviceMethod`:

```javascript
function PaymentController() {

	this.index = function(params) {
		var result = myGrailsService.serviceMethod("my optional parameters")

		return {result: result};
	}

}
```

Views
---
Views for JavaScript controllers are resolved in the same manner as views from regular Grails controllers. By convention, a controller action for **/payment/index** will resolve the `views/payment/index.gsp` view.

Nothing special needs to be done to make GSPs work with JavaScript controllers. The JavaScript object that is returned from the controller action is coerced to a Java Map and delegated to the controller in the same way that a regular Groovy controller would handle an action.

Given the `PaymentController`:

```javascript
function PaymentController() {

    this.index = function(params) {
        return {name: "Payment Controller"};
    }

}
```

And the GSP `views/payment/index.gsp`:

```jsp
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
  <title>Payment Controller Index</title>
</head>
<body>
<h1>${name}</h1>
</body>
</html>
```

We see a H1 rendered with "Payment Controller", just as you would expect. Sitemeshing, TagLibs, and Resources also work as expected.

Using Libraries
---
The plugin allows you to leverage additional libraries within your JavaScript controllers.

Loading a library script is the same process as loading a controller. Scripts can be loaded from either the classpath or from a physical path relative to the `web-app/WEB-INF/js.controllers` path. A good practice may be to store libraries in their own sub-directory.

```groovy
class BootStrap {

    def grailsApplication

    def init = { servletContext ->
        def container = grailsApplication.mainContext.getBean(JsControllersApplicationContainer)
        container.load("libs/payment.library.js")
        container.load("payment.controller.js")
    }
    def destroy = {
    }
}
```

Like controllers, libraries must also be registered with the `ApplicationContainer` after they are loaded.

```javascript
function PaymentLibrary() {
    this.makePayment = function(cardnum, expiraion) {
        // ... do some awesome javascript stuff ...
        return obj;
    };
}

ApplicationContainer.register("payment.library", PaymentLibrary, { scope: 'singleton' });
```

Classes can be registered with the `ApplicationContainer` in either a **Prototype** or a **Singleton** scope. While controllers should be scoped prototype, it may (probably will) make sense for you to register instances of your libraries as singletons. The above example demonsrates that process.

Once your library is registered with the `ApplicationContainer`, you can retrieve it for use in your controller through the `getBean(String)` method.

```javascript
function PaymentController() {

    this.paymentLibrary = ApplicationContainer.getBean('payment.library');

    this.index = function(params) {
        return {name: "Payment Controller", payment: this.paymentLibrary.makePayment(123, 1234)};
    };

}
```

Caveats
---
Some caveats to using JavaScript controllers is that the Groovy-enriched objects from the Grails context don't translate so well. That means that trying to leverage things like Domain class dynamic finders or other MOP methods/properties will not work.

The best workaround (and probably the best way of handling this in general) is to call a service class method that calls into MOP methods, or retrieves data with GORM.

License
---
Apache, or whatever. I mean... feel free to hack it up and change it all you want.

Author
---
Dan Woods, the man. t{ [@danveloper](http://twitter.com/danveloper) } g{ [danielpwoods<EMAIL_ADDRESS>}

repository: danveloper/grails-js-controllers

gha_language: Java

repo_name: danveloper/grails-js-controllers


text:
# Attributes

As pointed out in
[Attributes as Patterns](<../design-decisions/2018-07-25 Attributes as patterns.md>),
attributes are encoded as Kore patterns that only use application and string
literals.

## Axiom Pattern Attributes

Kore.Attribute.Axiom

Attributes specific to interpreting axiom patterns.

### Assoc

Associativity axiom

```
assoc{}()
```

Example, List concatenation

```
axiom{R} \equals{SortList{}, R} (
  Lbl'Unds'List'Unds'{}(
    Lbl'Unds'List'Unds'{}(K1:SortList{},K2:SortList{}),
    K3:SortList{}),
  Lbl'Unds'List'Unds'{}(
    K1:SortList{},
    Lbl'Unds'List'Unds'{}(K2:SortList{},K3:SortList{}))) [assoc{}()]
```

### Comm

Commutativity axiom

```
comm{}()
```

Example: Map concatenation

```
axiom{R} \equals{SortMap{}, R} (
  Lbl'Unds'Map'Unds'{}(K1:SortMap{},K2:SortMap{}),
  Lbl'Unds'Map'Unds'{}(K2:SortMap{},K1:SortMap{})) [comm{}()]
```

### Concrete

```
concrete{}()
```

Concrete axioms are not applied to symbolic patterns (patterns containing
variables).

### HeatCool

Heating and cooling axiom

```
heat{}()
cool{}()
```

In each execution step, the execution strategy first heats the configuration,
applies the normal rules (without `heat{}()` and `cool{}()`), and cools the
result.

### Idem

Idempotency axiom

```
idem{}()
```

Example: concatenation of identical Sets

```
axiom{R} \equals{SortSet{}, R} (
  Lbl'Unds'Set'Unds'{}(K:SortSet{},K:SortSet{}),K:SortSet{}) [idem{}()]
```

### Owise

```
owise{}()
```

This rule will apply only if the term does not unify with any other rules.
Has default priority 200.

### ProductionID

```
productionID{}("id")
```

### Priority

```
priority{}("123")
```

The priority attribute specifies a number which determines the order of rule
application. The attribute's argument is a string literal representing a decimal
integer.

### Simplification

```
simplification{}()
```

There are 2 types of evaluation: definition evaluations that implement the
actual semantics and simplification evaluations which are not the part of the
semantics, but can be used for simplifying the configuration before applying
definitions. For example, `(x + y) + z = (x + z) + y` where `x` and `z` are
concrete and `y` is not concrete.

### Trusted

```
trusted{}()
```

Spec axioms with this attribute are excluded from verification.

### Unit

Unit element axiom

```
unit{}()
```

### Unique ID

Unique identifier for axioms, usually assigned by the frontend at compile time.

```
UNIQUE'Unds'ID{}("07a34b11585162c291311c03441e08beb2532e48d")
```

## Symbol Attributes

Kore.Attribute.Symbol.Symbol

Attributes assigned to symbols.

### Anywhere

```
anywhere{}()
```

A symbol is given the `anywhere` attribute when it has `anywhere` rules
associated with it.

### Constructor

```
constructor{}()
```

A symbol is injective if it is given the `injective` attribute, the
`constructor` attribute, or the `sortInjection` attribute.

### Function

```
function{}()
```

A symbol is a function if it is given the `function` attribute or if it is
functional.

### Functional

```
functional{}()
```

A symbol is functional if it is given the `functional` attribute or the
`sortInjection` attribute.

### Hook

```
hook{}("BUILTIN.name")
```

The string `"BUILTIN.name"` is used to lookup for [known builtins](./hooks.md).

### Injective

```
injective{}()
```

A symbol is injective if it is given the `injective` attribute, the
`constructor` attribute, or the `sortInjection` attribute.

### Memo

```
memo{}()
```

The `memo` attribute signals that the backend may cache, or memoize, the result
of a symbol application (usually a `function`).

### Smtlib

The `smtlib` attribute specifies how a Kore application pattern built with the
symbol can be translated to SMT-LIB 2 list expression for an external SMT
solver.

```
smtlib{}("⟨S-expression⟩")
```

#### ⟨S-expression⟩ is an atom

```
smtlib{}("max")
```

The atom is used as the head of the list and the arguments of the application
are passed as arguments for the list.

#### ⟨S-expression⟩ is a list

```
smtlib{}("(mod (^ #1 #2) #3)")
```

The list may contain special meta-varialbes `#1`, `#2`, ... (not a valid
SMT-LIB syntax) which indicate the position of the arguments of the application
pattern.

### Smthook

The `smt-hook` is similar to [`smtlib`](#Smtlib), except that it's meant to
specify that the symbol will be translated to a predefined SMT operator, so
the SMT operator needs not be declared.

### SortInjection

```
sortInjection{}()
```

A symbol is injective if it is given the `injective` attribute, the
`constructor` attribute, or the `sortInjection` attribute.

A symbol is functional if it is given the `functional` attribute or the
`sortInjection` attribute.

## misc.

### Location

```
org'Stop'kframework'Stop'attributes'Stop'Location{}("Location(sl,sc,el,ec)")
```

Used for defining the location of the current declaration in the original file.
The numbers represent start line (sl), start column (sc), end line (el), and end
column (ec).

### Source

```
org'Stop'kframework'Stop'attributes'Stop'Source{}("Source(FilePath)")

```

Used for defining the source (K) file of the current declaration. 'FilePath' is
the full path to the original file.

### Subsort

```
subsort{Sub,Super}()
```

Used to define subsorting relations, attached to subsort axiom. For example,

```
axiom{R} \exists{R} (Val:SortKResult{},
  \equals{SortKResult{}, R}
    (Val:SortKResult{},
     inj{SortBool{}, SortKResult{}} (From:SortBool{})))
  [subsort{SortBool{}, SortKResult{}}()]
```

repository: traiansf/kore

gha_language: Haskell

repo_name: traiansf/kore


text:
---
title: "Helm"
chapter: true
weight: 60
tags:
  - beginner
  - CON203
---

# Kubernetes Helm

[Helm](https://helm.sh/) is a package manager for Kubernetes that packages multiple Kubernetes resources into a single logical deployment unit called **Chart**.

In this chapter, we'll cover [installing Helm](helm_intro).  Once installed, we'll demonstrate how Helm can be used to [deploy a simple NGINX webserver](helm_nginx), and a more [sophisticated microservice](helm_micro).

![Helm Logo](/images/helm-logo.svg)

repository: zengelan/eks-workshop

gha_language: CSS

gha_license_id: NOASSERTION

repo_name: zengelan/eks-workshop


text:
---
layout: feature
title: 'Clitic'
shortdef: 'clitic'
udver: '2'
---

(Please note: this part of the documentation is not yet completed.)

Language-specific feature identifying clitics attached to the word.

Skolt Sami has several enclitics used to express additive focus.

### `AddI`: Additive clitic -i

Expresses additive adverbal _too_.

#### Examples

* [sms] _tok-i_ "there too."

### `Han`: Additive clitic -han

Expresses _as we all know_.

#### Examples

* [sms] _aalmi-han kâʹl jåått da teâtt._ "the people, as we know, will do just as you suspect"

### `Os`: clitic -õs

Expresses discourse nuance, perhaps topicalizer.

#### Examples

* [sms] _Näʹde ton-õs mõõnsââʹst_ "So you take a walk..."

### `QstA`: question particle -a

Is added to the core of the question.

#### Examples

* [sms] _Haaʹlääk-a mõõnnâd?_ "Do you want to go?"

repository: UniversalDependencies/docs

branch_name: refs/heads/pages-source

gha_language: HTML

repo_name: UniversalDependencies/docs


text:
# TechDegree-Project-6

Static Node.js and Express Site(Portfolio)

With the JavaScript Express web framework and Pug templates, this static portfolio website demonstrates my skillset to potential employers.

dependencies:

- npm install

run project on localhost:

- npm start

### Technologies used:

- HTML
- CSS
- JavaScript
- Express
- Pug templates
- Node js

branch_name: refs/heads/main


text:
# Distributed Systems

A simple distribute system and multiplatform application for matches between devs and recruiters.

* For communication between client and servers, GRPC is been used, even in internal requests
* For scale and share data between servers, I implemented a chord ring with servers
* For efficient saving data, Log Structured Merge Tree is been used in each server

## Installation

1. Install Docker
2. Install Docker-Compose

## Usage

In this application you can register as 2 users:
* A Recruiter:
   * Can send message to the global chat
   * Match any employee which is talking in the chat
   * Contact the employee if match is acceptedd
* An Employee
   * Can send message to the global chat
   * Accept/Refuse a match

### Start
To start the application you need to pass 4 flags:
* Build
  * hard: Delete images and network from Docker, rebuild again and start the containers
  * soft: Just start the containers
* Mode
  * dae: Run the containers in mode daemon
  * it: Run the containers in mode interactive
* Servers: Number of servers to build
* Volumes
  * keep: Keep the volumes of old running containers
  * purge: Purge the volumes and create new ones

```bash
./build.sh --build build_opt --mode mode_opt --servers nr_servers --volumes volume_opt
```

### Stop
```bash
./stop.sh
```
## Used Technologies
* Python / Flask
* HTML, CSS, JS
* Chord (https://en.wikipedia.org/wiki/Chord_(peer-to-peer))
* Log Structured Merge Tree (LSMT) (https://en.wikipedia.org/wiki/Log-structured_merge-tree)
* GRPC (https://grpc.io/)

## Authors

* **Matheus Cunha Reis** - *creator* - [GitHub](https://github.com/matheuscr30) ✌

## License
[MIT](https://choosealicense.com/licenses/mit/)

gha_language: Python


text:
# Visit-counter for a Director

## Scenario: Show patient visits during working days and holidays

Given - Sensor as Entry-card issuer is working efficiently

When - A new patient enters in the hospital

Then - Issue a patient entry-card to the patient and
increment patient-count for that day

## Scenario: Compute parking slots to reserve for visiting specialists

Given - A schedule of specialists visiting

When - we know a specialist is visiting on
that day and a parking slot is free

Then - Reserve the parking slot for the specialist


text:
# Salesfarce

... is a fictitious, rudimentary and simplistic sales prospecting system. We are building it during a series of Domain Driven Design, CQRS and Eventsourcing exploration sessions at Vancouver's "DDD/CQRS/ES Practitioners' Meetup".

https://www.meetup.com/DDD-CQRS-ES/events/233590206/

https://www.meetup.com/DDD-CQRS-ES/events/233590334/

https://www.meetup.com/DDD-CQRS-ES/events/233590625/

## Getting Started

### Requirements

* [NodeJS](https://nodejs.org) v4.5+
* [GoES](http://github.com/nicdex/goes) to store events
  * install using `npm install goes-install` (Only supported for Windows and Linux for now)

### Requirements to compile native NodeJS modules (i.e. zmq).

#### Windows

* windows-build-tools npm package installed
  * `npm install --global windows-build-tools` (**IMPORTANT**: must be run as Administrator)

*This step can be skipped if you can already compile native nodejs modules on your computer.*

#### Linux

* build-essential distribution package installed
  * `sudo apt-get install build-essential`

#### Mac OSX

*TODO*

### Install modules

`npm install`

### Start app

#### 1) Start GoES

Windows

`start .deps\goes\bin\goes.exe --db=c:\temp\salesfarce-events`

Linux

`.deps/goes/bin/goes --db=/tmp/salesfarce-events &`

#### 2) Start the API

`npm start`

HTTP API is running at `http://localhost:8080/`

*Note: Linux user must adjust the goesStoragePath in config/local.json to /tmp/salesfarce-events before starting the app*

### Run tests

`npm test`

## Events (as of 9/22/2016):

### Bounded Context: Sales prospecting

```
SalesLeadReceived:
    receivedAtDate: 09/22/2016
    salesLeadID: 1234
    email<EMAIL_ADDRESS>    firstname: Joe
    lastname: Miller
    company: Invalid Yaml, Inc.
    phone:<PHONE_NUMBER>
    salesrep<EMAIL_ADDRESS>
SalesLeadContacted:
    salesLeadID: 1234
    contactDate: 10/21/2016
    salesrep<EMAIL_ADDRESS>    notes:

SalesLeadResponded:
    salesLeadID: 1234
    respondedAtDate: 10/26/2016
    interested: yes
    notes:
```

### Bounded Context: Order fulfillment

```
ProductSold:
    customerId: 1234
    soldAtDate: 11/23/2016
    salesrep<EMAIL_ADDRESS>    productId: 899
    quantity: 120
```

repository: adymitruk/salesfarce

repo_name: adymitruk/salesfarce


text:
---
layout: post
title: Custom activity indicator with swift
---

Custom Activity Indicator View an element that provides user feedback on the progress of a task or process with an unknown duration. As long as the task or process continues, the activity indicator spins. A user does not interact with an activity indicator. It is very similar with UIActivityIndicatorView but uses custom image. Custom Activity Indicator View is subclass of UIView.

You can download [test project] (https://github.com/snyuryev/Custom-Activity-Indicator-View) with implemented custom activity indicator from my [Github repository] (https://github.com/snyuryev/Custom-Activity-Indicator-View) or go forward and implement it by yourself. Also in test project you may find template icons for custom activity indicator.

Open XCode and create new project. Choose swift for your project language. Then create new file and call it - CustomActivityIndicatorView.swift. Here is full listing for custom activity indicator:

```
import UIKit
import QuartzCore

class CustomActivityIndicatorView: UIView {

    // MARK - Variables

    lazy private var animationLayer : CALayer = {
        return CALayer()
    }()

    var isAnimating : Bool = false
    var hidesWhenStopped : Bool = true

    // MARK - Init

    init(image : UIImage) {
        let frame : CGRect = CGRectMake(0.0, 0.0, image.size.width, image.size.height)

        super.init(frame: frame)

        animationLayer.frame = frame
        animationLayer.contents = image.CGImage
        animationLayer.masksToBounds = true

        self.layer.addSublayer(animationLayer)

        addRotation(forLayer: animationLayer)
        pause(layer: animationLayer)
        self.hidden = true
    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK - Func

    func addRotation(forLayer layer : CALayer) {
        let rotation : CABasicAnimation = CABasicAnimation(keyPath:"transform.rotation.z")

        rotation.duration = 1.0
        rotation.removedOnCompletion = false
        rotation.repeatCount = HUGE
        rotation.fillMode = kCAFillModeForwards
        rotation.fromValue = NSNumber(float: 0.0)
        rotation.toValue = NSNumber(float: 3.14 * 2.0)

        layer.addAnimation(rotation, forKey: "rotate")
    }

    func pause(#layer : CALayer) {
        let pausedTime = layer.convertTime(CACurrentMediaTime(), fromLayer: nil)

        layer.speed = 0.0
        layer.timeOffset = pausedTime

        isAnimating = false
    }

    func resume(#layer : CALayer) {
        let pausedTime : CFTimeInterval = layer.timeOffset

        layer.speed = 1.0
        layer.timeOffset = 0.0
        layer.beginTime = 0.0

        let timeSincePause = layer.convertTime(CACurrentMediaTime(), fromLayer: nil) - pausedTime
        layer.beginTime = timeSincePause

        isAnimating = true
    }

    func startAnimating () {

        if isAnimating {
            return
        }

        if hidesWhenStopped {
            self.hidden = false
        }
        resume(layer: animationLayer)
    }

    func stopAnimating () {
        if hidesWhenStopped {
            self.hidden = true
        }
        pause(layer: animationLayer)
    }
}
```

Do not forget to add some image which should be animated in custom activity indicator view. Next, go to your view controller. Custom activity indicator could be simple declared this way in your class:

```
lazy private var activityIndicator : CustomActivityIndicatorView = {
  let image : UIImage = UIImage(named: "loading")!
  return CustomActivityIndicatorView(image: image)
}()
```
where "loading" is your image in png format.

 And it could be used in the same way like original UIActivityIndicatorView.


text:
#### [PATCH 1/1] s390/dma: provide proper ARCH_ZONE_DMA_BITS value
##### From: Halil Pasic<EMAIL_ADDRESS>
```c
On s390 ZONE_DMA is up to 2G, i.e. ARCH_ZONE_DMA_BITS should be 31 bits.
The current value is 24 and makes __dma_direct_alloc_pages() take a
wrong turn first (but __dma_direct_alloc_pages() recovers then).

Let's correct ARCH_ZONE_DMA_BITS value and avoid wrong turns.

Signed-off-by: Halil Pasic<EMAIL_ADDRESS>Reported-by: Petr Tesarik<EMAIL_ADDRESS>Fixes: c61e9637340e ("dma-direct: add support for allocation from
ZONE_DMA and ZONE_DMA32")
---
 arch/s390/include/asm/dma.h | 1 +
 1 file changed, 1 insertion(+)

```
#### [PATCH 1/2] KVM: Boost vCPUs that are delivering interrupts
##### From: Paolo Bonzini<EMAIL_ADDRESS>
```c
From: Wanpeng Li<EMAIL_ADDRESS>
Inspired by commit 9cac38dd5d (KVM/s390: Set preempted flag during
vcpu wakeup and interrupt delivery), we want to also boost not just
lock holders but also vCPUs that are delivering interrupts. Most
smp_call_function_many calls are synchronous, so the IPI target vCPUs
are also good yield candidates.  This patch introduces vcpu->ready to
boost vCPUs during wakeup and interrupt delivery time; unlike s390 we do
not reuse vcpu->preempted so that voluntarily preempted vCPUs are taken
into account by kvm_vcpu_on_spin, but vmx_vcpu_pi_put is not affected
(VT-d PI handles voluntary preemption separately, in pi_pre_block).

Testing on 80 HT 2 socket Xeon Skylake server, with 80 vCPUs VM 80GB RAM:
ebizzy -M

            vanilla     boosting    improved
1VM          21443       23520         9%
2VM           2800        8000       180%
3VM           1800        3100        72%

Testing on my Haswell desktop 8 HT, with 8 vCPUs VM 8GB RAM, two VMs,
one running ebizzy -M, the other running 'stress --cpu 2':

w/ boosting + w/o pv sched yield(vanilla)

            vanilla     boosting   improved
              1570         4000      155%

w/ boosting + w/ pv sched yield(vanilla)

            vanilla     boosting   improved
              1844         5157      179%

w/o boosting, perf top in VM:

 72.33%  [kernel]       [k] smp_call_function_many
  4.22%  [kernel]       [k] call_function_i
  3.71%  [kernel]       [k] async_page_fault

w/ boosting, perf top in VM:

 38.43%  [kernel]       [k] smp_call_function_many
  6.31%  [kernel]       [k] async_page_fault
  6.13%  libc-2.23.so   [.] __memcpy_avx_unaligned
  4.88%  [kernel]       [k] call_function_interrupt

Cc: Paolo Bonzini<EMAIL_ADDRESS>Cc: Radim Krčmář<EMAIL_ADDRESS>Cc: Christian Borntraeger<EMAIL_ADDRESS>Cc: Paul Mackerras<EMAIL_ADDRESS>Cc: Marc Zyngier<EMAIL_ADDRESS>Signed-off-by: Wanpeng Li<EMAIL_ADDRESS>Signed-off-by: Paolo Bonzini<EMAIL_ADDRESS>---
	v2->v3: put it in kvm_vcpu_wake_up, use WRITE_ONCE

 arch/s390/kvm/interrupt.c | 2 +-
 include/linux/kvm_host.h  | 1 +
 virt/kvm/kvm_main.c       | 9 +++++++--
 3 files changed, 9 insertions(+), 3 deletions(-)

```
#### [RFC PATCH v4 1/6] vfio: Define device specific irq type capability
##### From: Kechen Lu<EMAIL_ADDRESS>
```c
From: Tina Zhang<EMAIL_ADDRESS>
Cap the number of irqs with fixed indexes and use capability chains
to chain device specific irqs.

Signed-off-by: Tina Zhang<EMAIL_ADDRESS>Signed-off-by: Eric Auger<EMAIL_ADDRESS>---
 include/uapi/linux/vfio.h | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

```
#### [PATCH] KVM: selftests: Remove superfluous define from vmx.c
##### From: Thomas Huth<EMAIL_ADDRESS>
```c
The code in vmx.c does not use "program_invocation_name", so there
is no need to "#define _GNU_SOURCE" here.

Signed-off-by: Thomas Huth<EMAIL_ADDRESS>---
 tools/testing/selftests/kvm/lib/x86_64/vmx.c | 2 --
 1 file changed, 2 deletions(-)

```
#### [PATCH] KVM: x86: Add fixed counters to PMU filterFrom: Eric Hankland<EMAIL_ADDRESS>##### From: Eric Hankland<EMAIL_ADDRESS>
```c
From: ehankland<EMAIL_ADDRESS>
Updates KVM_CAP_PMU_EVENT_FILTER so it can also whitelist or blacklist
fixed counters.

Signed-off-by: ehankland<EMAIL_ADDRESS>---
 Documentation/virtual/kvm/api.txt | 13 ++++++++-----
 arch/x86/include/uapi/asm/kvm.h   |  9 ++++++---
 arch/x86/kvm/pmu.c                | 30 +++++++++++++++++++++++++-----
 3 files changed, 39 insertions(+), 13 deletions(-)

```
#### [PATCH] KVM: x86/vPMU: refine kvm_pmu err msg when event creation failed
##### From: Like Xu<EMAIL_ADDRESS>
```c
If a perf_event creation fails due to any reason of the host perf
subsystem, it has no chance to log the corresponding event for guest
which may cause abnormal sampling data in guest result. In debug mode,
this message helps to understand the state of vPMC and we should not
limit the number of occurrences.

Signed-off-by: Like Xu<EMAIL_ADDRESS>---
 arch/x86/kvm/pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

```
#### [RFC PATCH] KVM: PPC: Enable the kvm_create_max_vcpus selftest on ppc64
##### From: Thomas Huth<EMAIL_ADDRESS>
```c
The kvm_create_max_vcpus is generic enough so that it works out of the
box on POWER, too. We just have to provide some stubs for linking the
code from kvm_util.c.
Note that you also might have to do "ulimit -n 2500" before running the
test, to avoid that it runs out of file handles for the vCPUs.

Signed-off-by: Thomas Huth<EMAIL_ADDRESS>---
 RFC since the stubs are a little bit ugly (does someone here like
 to implement them?), and since it's a little bit annoying that
 you have to raise the ulimit for this test in case the kernel provides
 more vCPUs than the default ulimit...

 tools/testing/selftests/kvm/Makefile          |  6 +++
 .../selftests/kvm/lib/powerpc/processor.c     | 37 +++++++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/lib/powerpc/processor.c

```
#### [PATCH v1] mm/balloon_compaction: avoid duplicate page removal
##### From: Wei Wang<EMAIL_ADDRESS>
```c
Fixes: 418a3ab1e778 (mm/balloon_compaction: List interfaces)

A #GP is reported in the guest when requesting balloon inflation via
virtio-balloon. The reason is that the virtio-balloon driver has
removed the page from its internal page list (via balloon_page_pop),
but balloon_page_enqueue_one also calls "list_del"  to do the removal.
So remove the list_del in balloon_page_enqueue_one, and have the callers
do the page removal from their own page lists.

Signed-off-by: Wei Wang<EMAIL_ADDRESS>---
 mm/balloon_compaction.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

```
#### [PATCH v2 1/2] KVM: Boosting vCPUs that are delivering interrupts
##### From: Wanpeng Li<EMAIL_ADDRESS>
```c
From: Wanpeng Li<EMAIL_ADDRESS>
Inspired by commit 9cac38dd5d (KVM/s390: Set preempted flag during vcpu wakeup
and interrupt delivery), except the lock holder, we want to also boost vCPUs
that are delivering interrupts. Actually most smp_call_function_many calls are
synchronous ipi calls, the ipi target vCPUs are also good yield candidates.
This patch introduces vcpu->ready to boost vCPUs during wakeup and interrupt
delivery time.

Testing on 80 HT 2 socket Xeon Skylake server, with 80 vCPUs VM 80GB RAM:
ebizzy -M

            vanilla     boosting    improved
1VM          21443       23520         9%
2VM           2800        8000       180%
3VM           1800        3100        72%

Testing on my Haswell desktop 8 HT, with 8 vCPUs VM 8GB RAM, two VMs,
one running ebizzy -M, the other running 'stress --cpu 2':

w/ boosting + w/o pv sched yield(vanilla)

            vanilla     boosting   improved
              1570         4000      155%

w/ boosting + w/ pv sched yield(vanilla)

            vanilla     boosting   improved
              1844         5157      179%

w/o boosting, perf top in VM:

 72.33%  [kernel]       [k] smp_call_function_many
  4.22%  [kernel]       [k] call_function_i
  3.71%  [kernel]       [k] async_page_fault

w/ boosting, perf top in VM:

 38.43%  [kernel]       [k] smp_call_function_many
  6.31%  [kernel]       [k] async_page_fault
  6.13%  libc-2.23.so   [.] __memcpy_avx_unaligned
  4.88%  [kernel]       [k] call_function_interrupt

Cc: Paolo Bonzini<EMAIL_ADDRESS>Cc: Radim Krčmář<EMAIL_ADDRESS>Cc: Christian Borntraeger<EMAIL_ADDRESS>Cc: Paul Mackerras<EMAIL_ADDRESS>Cc: Marc Zyngier<EMAIL_ADDRESS>Signed-off-by: Wanpeng Li<EMAIL_ADDRESS>---
 arch/s390/kvm/interrupt.c |  2 +-
 include/linux/kvm_host.h  |  1 +
 virt/kvm/kvm_main.c       | 12 +++++++++---
 3 files changed, 11 insertions(+), 4 deletions(-)

```
#### [PATCH v2] KVM: x86/vPMU: refine kvm_pmu err msg when event creation failed
##### From: Like Xu<EMAIL_ADDRESS>
```c
If a perf_event creation fails due to any reason of the host perf
subsystem, it has no chance to log the corresponding event for guest
which may cause abnormal sampling data in guest result. In debug mode,
this message helps to understand the state of vPMC and we may not
limit the number of occurrences but not in a spamming style.

Suggested-by: Joe Perches<EMAIL_ADDRESS>Signed-off-by: Like Xu<EMAIL_ADDRESS>---
 arch/x86/kvm/pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

```
#### [PATCH v2] mm/balloon_compaction: avoid duplicate page removal
##### From: Wei Wang<EMAIL_ADDRESS>
```c
Fixes: 418a3ab1e778 (mm/balloon_compaction: List interfaces)

A #GP is reported in the guest when requesting balloon inflation via
virtio-balloon. The reason is that the virtio-balloon driver has
removed the page from its internal page list (via balloon_page_pop),
but balloon_page_enqueue_one also calls "list_del"  to do the removal.
This is necessary when it's used from balloon_page_enqueue_list, but
not from balloon_page_enqueue_one.

So remove the list_del balloon_page_enqueue_one, and update some
comments as a reminder.

Signed-off-by: Wei Wang<EMAIL_ADDRESS>Acked-by: Nadav Amit<EMAIL_ADDRESS>---
ChangeLong:
v1->v2: updated some comments

 mm/balloon_compaction.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

```


text:
# UnexpectedFactorial
Inspired by the community of [r/unexpectedfactorial](https://www.reddit.com/r/unexpectedfactorial/hot/), this program takes in text, and evaluates any and all factorials (unexpected or not) and gives you the result.
From [r/unexpectedfactorial](https://www.reddit.com/r/unexpectedfactorial/hot/):
> What is the Sub?
> It's a math joke.
>
> If you don't like math you can leave now.
>
> If you do, and want to learn about it, here you go.
> When you put an '!' next to a number, it makes it look like a factorial. Sometimes people do this on accident, as you can see in all the posts in the sub."

For example, if you said: "Lets meet at 6!", that would evaluate to "Lets meet at 720."
This program simplifies your life by evaluating all the factorials so you don't have to.

## Running the program
If you don't have NetBeans and or don't know what NetBeans is, download this repository, and unzip `RunnerProgram.zip`.
Once you have done this, find `Text.txt`. If there isn't one, run `UnexpectedFactorial.jar`, and it will create one for you. Inside `Text.txt`, put in your text (wow, no duh), save it, and run `UnexpectedFactorial.jar` again. The output will be saved in the (wait for it...) `output.txt` file. Have fun!

If you do have NetBeans, simply open the project inside NetBeans, and run `UnexpectedFactorial.java` from the src folder. It can take input from either `Text.txt`, or System.in, with `Text.txt` having first priority.

repository: tfbninja/UnexpectedFactorial

repo_name: tfbninja/UnexpectedFactorial


text:
# MemoryExplorer

### Only for Windows 7 SP2 [x86]
---------------
    -  If you want to the different versions of windows7, you should replace the offsets of kernel objects in "symbols.h"
    -  But, Only for x86.

### Functions
----------------
    - It shows the contents of memory in the other process' virtual address space including the Kernel & User address.
    - It allows to manipulate the contents of the target process' address space.
    - It allows to find some patterns or coincident byte sequence in the memory.

repository: Git-SiN/MemoryExplorer

repo_name: Git-SiN/MemoryExplorer


text:
---
layout: post
title: Scraping web data using Rvest
tags: r, rvest
---

Rvest is a great package that I discovered recently that allows you to easily scrape the web. It's pretty powerful and allows a lot of options that can be seen in the documentation. Just a quick over example on how to use it:

		#Load the library
		library(rvest)

		#Scrape the website
		link = html("http://www.website.com")

		#Filter out the website for the elemnents and information desired
		link %>%
  			html_node("table tr td") %>%
  			html_text()

 The code above would scrape the website supplied. Then it would filter out from those elements, anything that matches in the html code table, tr, td. You can also filter it based on html classes, ids, and attributes.

 A quick overview on what classes, ids, and attributes are.

 Classes are noted with period in front of the class so in the case above, *.cat*. Ids are noted with the phone symbol in front so it would be *#cat*. Options are a little more tricky but the following with work with rvest: *div[options]* *div[options="dog"]* depending on how specific you want to be.

 Be sure to check out the docs, under the hood you can do a lot more things such as parsing out attributes and more.


text:
Java Identifiers

 All java variables must be identified with unique names.
These unique names are called identifiers

Java Data Types

Example

    int myNum = 5; // Integer (whole number)
    float myFloatNum = 5.99f; // Floating point number
    char myLetter = 'D'; // Character
    boolean myBool = true; // Boolean
    String myText = "Hello"; //String

 Data types are divided into two groups:

Primitive data types - includes byte, short,int,long,float,double,boolean and char

Non-Primitive data types - such as String,Arrays and Classes

Java Type Casting

Type casting is when you assing a value of one primitive data types to another type

    - Widenning casting (automatically) - converting a smaller type to a larger type size. byte -> short -> char -> int -> long -> float -> double

    - Narrwoing Casting (manually)- converting a larger type to a smaller size type
    double -> float -> long -> int -> char -> short -> byte

Widening Casting

Widening Casting is done automatically when passing a smaller size type to a larger size type:

Example:

public class MyClass {
    public static void main(String[] args) {
        int myInt = 9;
        double myDouble = myInt; // Automatic casting: int to double

        System.out.println(myInt); // Output 9
        System.out.println(myDouble); //out out 9.0
    }
}

Narrowing Casting

Narrowing casting must be done manually by placing the type in parentheses in front of the value:

Example:

public class MyClass {
    public static void main(String[] args) {
        double myDouble = 9.78;
        int myInt = (int) myDouble; // Manual casting: double to int

        System.out.println(myDouble); // Outputs 9.78
        System.out.println(myInt); // Outputs 9
    }
}

repository: Indra-Kumar-Chaudhary/java-programming

repo_name: Indra-Kumar-Chaudhary/java-programming


text:
# SecretsManger Versioning

A CLI Tool to manage and version [AWS Secrets](https://aws.amazon.com/de/secrets-manager/) with [SOPS](https://github.com/mozilla/sops)

## Overview

SecretsManager Version is a CLI Tool for Secrets in combination with SOPS. It helps you keep your secrets safe and versioned inside git projects.
The SecretsManager is capable of storing up to 20 tagged secret versions which SecretsManger-Versioning will make use of. The secrets will be versioned by using the MD5 Hash of the encrypted file. With this, every change of the SOPS file will be tagged with a unique key to reference. On top of that, each tag is connected with a Git project and Commit Hash to trace its origin.

## Prerequisites

- [AWS Account](https://aws.amazon.com/account/)
- [KMS Key](https://aws.amazon.com/kms/)
- [AWS CLI (optional)](https://aws.amazon.com/cli/)
- [SOPS](https://github.com/mozilla/sops)
- [Node 12 or higher](https://nodejs.org/en/)
- [GIT](https://git-scm.com/)

## Secret Management

Create a new git repository and open a new terminal there:

```sh
git init .
git remote add origin git@github.com:username/new_repo
```

Create a new sops file and encrypt it with your kms key:

```sh
sops --kms arn:aws:kms:region:account:key/xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx sops.json
```

Now run the following to test if the configuration works:

```
npx secretsmanager-versioning -f sops.json SecretName
```

You should be able to verify that a secret under this name in the currently logged-in account and region was created for you. You can also create a secret yourself and simply reference it. You can verify this by checking the secret in your console or by executing:

```sh
aws secretsmanager describe-secret --secret-id SecretName
```

You should be able to verify that the secret is tagged with a md5 hash and the current version should reference your recent commit.

## Usage

The secret can be used by referring to with the md5 hash. There are multiple ways to do this. One example is highlighted here.

Decrypted Sops File (sops.json)

```json
{
  "example": "supersecretstring"
}
```

### CDK

Add the md5-file dependency to your project and reference your sops file and Secret. After that you should be to reference a jsonField to get reference the secret value:

```ts
import { sync as md5 } from "md5-file";
const secretPath = "SecretName";
const versionId = md5("sops.json");
const secret = cdk.SecretValue.secretsManager(secretPath, {
  jsonField: "example",
  versionId: versionId,
}).toString();
console.log(secret); // {{resolve:secretsmanager:SecretName:SecretString:example::md5hashvalue}}
```

repository: bruecktech/secretsmanager-versioning

repo_name: bruecktech/secretsmanager-versioning


text:
---
layout: post
title:  "Atlas of Design 5"
date:   2020-12-01
categories: [cartography]
---

Just in case you needed to see my big dumb face, be sure to check out the 5th edition of
the [Atlas of Design](https://atlasofdesign.bigcartel.com). The latest volume is out now
and features tons lovely maps from some of the worlds best cartographers. While my map submission
didnt make the cut, I was humbled to be asked to contribute WORDS to the forward. The prompt
was:

>How does technology affect your work and design process? How has technology changed your design process over time How does it affect the way you think about your work in terms of aesthetics or achieving results?

![aod5]({{ site.url }}/static/projects/aod5.png)

Big thanks to the Atlas of Design staff! Very thankful for the opportunity to contribute.

Got questions or comments? Feel free to [email<EMAIL_ADDRESS>or hit me up on [twitter](https://twitter.com/jonahadkins).


text:
# A-Flask-web-app-for-inventory-management

*"An Inventory Management System powered by Flask"*

## Tech Stack

- Python
- Mysql
- Flask
- HTML
- CSS
- Jinja template

## Table of Contents

- [Installation](#installation)
- [Overview](#overview)
- [Usage](#usage)
    - [Setting up the database](#setting-up-the-database)
    - [Starting Things Up](#starting-things-up)
    - [Getting Into It](#getting-into-it)
        - [Adding products and locations](#adding-products-and-locations)
        - [Editing or deleting products and locations](#editing-or-deleting-products-and-locations)
        - [Moving things around](#moving-things-around)
- [License](#license)

## Installation

Clone the git repository:

```sourceCode console
$ git clone https://github.com/SASHA-PAIS/A-Flask-web-app-for-inventory-management.git

$ cd A-Flask-web-app-for-inventory-management
```

Install the necessary dependencies which include:

- flask
- flask_mysqldb
- yaml
- json
- MySQLdb
- decimal

## Overview

The _index/summary_ page covers the summary of the entire system as it includes the location and product information alongwith the count of the unallocated products. On the _products_ page, we can add/edit/remove products from the system. The _location_ page covers similar functionality in the context of locations or warehouses. We can perform movement of products on the _logistics_ page. It also maintains the history of the transactions in a tabular format.

## Usage

### Setting up the database

Create a database called inventory in mysql

![](docs/inv1.JPG)

Then create a db.yaml file in which you need to add the database name, mysql username, password and host name

![](docs/inv3.JPG)

### Starting Things Up

To run the application, make sure you are in the \~/A-Flask-web-app-for-inventory-management directory!

Run the app by typing the following command in your command prompt:

```sourceCode console
$ python -m flask run
```

![](docs/inv2.JPG)

or

```sourceCode console
$ python app.py
```

The application can be accessed at _localhost:5000_ in your browser

### Getting into it

A new system will look like this

![](docs/vid1.gif)

#### Adding products and locations

To add products, only the name and quantity are required.
Adding locations needs only the name to be added

![](docs/vid2.gif)

#### Editing products and locations

You can edit a location or product name if the new name is not empty or is not already present in the system.

You can also increase the quantity of the product, but not decrease it. When this happens, the product quantity gets updated with the new quantity in the _products_ table. The unallocated quantity of that product also increases by the difference of the old product quantity and the new product quantity.

![](docs/vid3.gif)

#### Moving things around

Products can be moved into and between warehouses *only after* they have been added to the system.

Initially, we consider the products to not be in any warehouse. Hence, we keep the from_loc field empty
and just enter the to_loc (destination) location.

Once the products are in some warehouse, they can be moved easily to some other warehouse.

![](docs/vid4.gif)

#### Deleting a location that has already been allocated some products

For all the products that currently exist in this particular location that has to be deleted, we first increase the unallocated quantities of these products by the quantity of the products that has been allocated in this location.

Then, we delete the records from the _logistics_ table where the _to_loc_ & _from_loc_ ids are the same as the location to be deleted.

Then this location is deleted from the _location_ table.

![](docs/vid5.gif)

#### Deleteing a product that has already been allocated

The record in the _logistics_ table, where the _prod_id_ is equal to the id of the product to be deleted, is removed first.

Then the product is deleted from the _products_ table.

![](docs/vid6.gif)

## License

This code has been released under the [MIT License](LICENSE).


text:
# Laravel Mix Auto Extract Vendors Plugin

[![downloads](https://img.shields.io/npm/dt/laravel-mix-auto-extract.svg)](http://npm-stats.com/~packages/laravel-mix-auto-extract)
[![npm-version](https://img.shields.io/npm/v/laravel-mix-auto-extract.svg)](https://www.npmjs.com/package/laravel-mix-auto-extract)
[![github-tag](https://img.shields.io/github/tag/ankurk91/laravel-mix-auto-extract.svg?maxAge=1800)](https://github.com/ankurk91/laravel-mix-auto-extract/)
[![license](https://img.shields.io/github/license/ankurk91/laravel-mix-auto-extract.svg?maxAge=1800)](https://yarnpkg.com/en/package/laravel-mix-auto-extract)

[Laravel Mix](https://github.com/JeffreyWay/laravel-mix) plugin to auto extract 3rd party dependencies as `vendor.js`.

> :mega: Notice: This feature has been added to Laravel Mix v4.0 now. :tada:

### What was the problem?
* Laravel Mix already has a `extract()` method which accepts an array of dependencies that you want to extract as `vendor.js`
* Whenever you install a new package, you also need to update this list to make it work.
* Read more on this [issue](https://github.com/JeffreyWay/laravel-mix/issues/1233)

### How does this plugin solve above issue?
* This plugin will auto extract all js dependencies coming from `node_modules` to `vendor.js` file.
* You just need to reference them in your code somewhere. For example:
```js
// app.js
import Vue from 'vue';
import axios from 'axios';
```
* Now `vue` and `axios` will be auto extracted to `vendor.js` file

## Requirements
* [Laravel Mix](https://github.com/JeffreyWay/laravel-mix) >=2.1.0 <4.0.0

## Installation
```bash
# npm
npm install laravel-mix-auto-extract --save

# yarn
yarn add laravel-mix-auto-extract
```

## Usage
Update your `webpack.mix.js`
```js
const mix = require('laravel-mix');
// Require this package
require('laravel-mix-auto-extract');
// Your code may go here
// mix.js('./resources/assets/js/app.js', './public/js/app.js')
// mix.version()
// Call this method at last
mix.autoExtract();
```
Then update your blade template
```blade
<script src="{{ mix('js/manifest.js') }}"></script>
<script src="{{ mix('js/vendor.js') }}"></script>
<script src="{{ mix('js/app.js') }}"></script>
```
Remove any reference to `extract()` method in `webpack.mix.js`

### Configuration Options
Here are the default options, all of them are optional.
```js
mix.autoExtract({
  vendorPath: 'js/vendor', // Don't suffix paths with `.js`
  manifestPath: 'js/manifest',
  excludeRegExp: /^.*\.(css|scss|sass|less|styl)$/,
  generateManifest: true,
});
```
Paths are relative to the default output directory, usually `./public`.

## :warning: Caution
Don't use `autoExtract()` method along with `extract()` method.

## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## License
[MIT](LICENSE.txt) License


text:
# Spring factories for Elasticsearch

Welcome to the Spring factories for [Elasticsearch](http://www.elasticsearch.org/) project.

Actually, since version 1.4.1, this project has been split in two parts:

* [Elasticsearch Beyonder](https://github.com/dadoonet/elasticsearch-beyonder/) which find resources in
project classpath to automatically create indices, types and templates.
* This project which is building Client beans using [Spring framework](http://projects.spring.io/spring-framework/).

From 5.0, this project provides 2 implementations of an elasticsearch Client:

* The REST client
* The Transport client (deprecated)

## Documentation

* For 5.x elasticsearch versions, you are reading the latest documentation.
* For 2.x elasticsearch versions, look at [es-2.x branch](https://github.com/dadoonet/spring-elasticsearch/tree/es-2.x).
* For 1.x elasticsearch versions, look at [es-1.4 branch](https://github.com/dadoonet/spring-elasticsearch/tree/es-1.4).
* For 0.x elasticsearch versions, look at [0.x branch](https://github.com/dadoonet/spring-elasticsearch/tree/0.x).

|   spring-elasticsearch  | elasticsearch |   Spring     | Release date |
|:-----------------------:|:-------------:|:------------:|:------------:|
|     5.0-SNAPSHOT        |  5.0 - 5.x    |    4.3.10    |  2017-07-??  |
|           2.2.0         |  2.0 - 2.4    |    4.2.3     |  2017-03-09  |
|           2.1.0         |  2.0, 2.1     |    4.2.3     |  2015-11-25  |
|           2.0.0         |      2.0      |    4.1.4     |  2015-10-25  |
|           1.4.2         |     < 2.0     |    4.1.4     |  2015-03-03  |
|           1.4.1         |      1.4      |    4.1.4     |  2015-02-28  |
|           1.4.0         |      1.4      |    4.1.4     |  2015-01-03  |
|           1.3.0         |      1.3      |    4.0.6     |  2014-09-01  |
|           1.0.0         |      1.0      |    3.2.2     |  2014-02-14  |

## Build Status

Thanks to Travis for the [build status](https://travis-ci.org/dadoonet/spring-elasticsearch):
[![Build Status](https://travis-ci.org/dadoonet/spring-elasticsearch.svg)](https://travis-ci.org/dadoonet/spring-elasticsearch)

## Getting Started

### Maven dependency

Import spring-elasticsearch in you project `pom.xml` file:

```xml
<dependency>
  <groupId>fr.pilato.spring</groupId>
  <artifactId>spring-elasticsearch</artifactId>
  <version>2.2.0</version>
</dependency>
```

If you want to set a specific version of the Rest client, add it to your `pom.xml` file:

```xml
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>rest</artifactId>
    <version>5.5.0</version>
</dependency>
```

If you want to use a transport client (deprecated), you must add it to your `pom.xml` file:

```xml
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>5.5.0</version>
</dependency>
```

If you want to try out the most recent SNAPSHOT version [deployed on Sonatype](https://oss.sonatype.org/content/repositories/snapshots/fr/pilato/spring/spring-elasticsearch/):

```xml
<dependency>
  <groupId>fr.pilato.spring</groupId>
  <artifactId>spring-elasticsearch</artifactId>
  <version>5.0-SNAPSHOT</version>
</dependency>
```

Don't forget to add if needed the following repository in your `pom.xml`:

```xml
<repositories>
    <repository>
        <id>oss-snapshots</id>
        <name>Sonatype OSS Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
```

### Logger

We are using [slf4j](http://www.slf4j.org/) for logging but you have to provide the logging implementation
you want to use and bind it.

For example for this project we are using for tests [log4j2](http://logging.apache.org/log4j/).
If you want to do so, add to your `pom.xml`:

```xml
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-1.2-api</artifactId>
    <version>2.7</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>2.7</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.7</version>
</dependency>
```

### Using elasticsearch spring namespace for XML files

In your spring context file, just add namespaces like this:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:elasticsearch="http://www.pilato.fr/schema/elasticsearch"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.pilato.fr/schema/elasticsearch http://www.pilato.fr/schema/elasticsearch/elasticsearch-5.0.xsd">
</beans>
```

### Getting a rest client bean

From 5.0, you can now get a REST Client implementation.

#### Define a rest client bean

In your spring context file, just define a client like this:

```xml
<elasticsearch:rest-client id="esClient" />
```

By default, you will get an [Elasticsearch Low Level Rest Client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-low.html)
connected to an Elasticsearch node already running at `localhost:9200`.

You can set the nodes you want to connect to:

```xml
<elasticsearch:rest-client id="esClient" esNodes="localhost:9200,localhost:9201" />
```

#### Injecting the rest client in your java project

You can use the rest client in your java classes.

```java
import org.elasticsearch.client.RestClient;

RestClient client = ctx.getBean("esClient", RestClient.class);
```

Better, you should use `@Autowired` annotation.

```java
// Inject your client...
@Autowired RestClient client;
```

### Getting a transport client bean (deprecated)

From 5.0, the Transport Client implementation is deprecated. It is now marked as `optional` so
you need to explicitly add it to your project as described in [Maven dependency chapter](#maven-dependency).

#### Define a client Transport bean

In your spring context file, just define a client like this:

```xml
<elasticsearch:client id="esClient" />
```

By default, you will get an [Elasticsearch Transport Client](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html)
connected to an Elasticsearch node already running at `localhost:9300` using `elasticsearch` as cluster name.

You can set the nodes you want to connect to:

```xml
<elasticsearch:client id="esClient" esNodes="localhost:9300,localhost:9301" />
```

**Important notes**

> Note that you should define the same clustername as the one you defined on your running nodes.
> Otherwise, your Transport Client won't connect to the node. See [Elasticsearch properties](#transport-client-properties-deprecated).

> Note also that you must define the transport client port (9300-9399) and not the REST port (9200-9299).
> Transport client does not use REST API.

#### Injecting transport client in your java project

Now, you can use the transport client in your java classes.

```java
import org.elasticsearch.client.Client;

Client client = ctx.getBean("esClient", Client.class);
```

Better, you should use `@Autowired` annotation.

```java
// Inject your client...
@Autowired Client client;
```

#### Transport Client properties (deprecated)

You can define your transport client properties using a property file such as:

```properties
cluster.name=myclustername
```

And load it in Spring context:

```xml
<util:properties id="esproperties"
    location="classpath:fr/pilato/spring/elasticsearch/xml/esclient-transport.properties"/>
```

Note that you can also define properties as follow:

```xml
<util:map id="esProperties">
    <entry key="cluster.name" value="newclustername"/>
</util:map>
```

<elasticsearch:client id="esClient" esNodes="localhost:9300,localhost:9301"
    properties="esproperties"/>

Injecting properties in client is now easy:

```xml
<elasticsearch:client id="esClient" properties="esproperties" />
```

You can also add plugins to the transport client in case it needs it:

```xml
<elasticsearch:client id="esClient" plugins="org.elasticsearch.plugin.deletebyquery.DeleteByQueryPlugin" />
```

## Automatically create indices

The following examples are documented using the Rest Client implementation `elasticsearch:rest-client` but you can
replace them with the Transport client by using `elasticsearch:client` instead.

### Managing indexes and types

If you want to manage indexes and types at startup (creating missing indexes/types and applying mappings):

```xml
<elasticsearch:rest-client id="esClient"
    mappings="twitter/tweet" />
```

This will create an [Elasticsearch Low Level Rest Client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-low.html)
that will check when starting that index `twitter` exists and `tweet` type is defined.

If you need to manage more than one type or index, just use a comma separated list:

```xml
<elasticsearch:rest-client id="esClient"
    mappings="twitter/tweet,twitter/user,facebook/user" />
```

If you add in your classpath a file named `es/twitter/_settings.json`, it will be automatically applied to define
settings for your `twitter` index.

For example, create the following file `src/main/resources/es/twitter/_settings.json` in your project:

```javascript
{
  "index" : {
    "number_of_shards" : 3,
    "number_of_replicas" : 2
  }
}
```

Also, if you define a file named `es/twitter/tweet.json`, it will be automatically applied as the mapping for
the `tweet` type in the `twitter` index.

For example, create the following file `src/main/resources/es/twitter/tweet.json` in your project:

```javascript
{
  "tweet" : {
    "properties" : {
      "message" : {"type" : "text", "store" : "yes"}
    }
  }
}
```

### Using convention over configuration

By default, the factory will find every mapping file located under `es` directory.
So, if you have a mapping file named `es/twitter/tweet.json` in your classpath, it will be automatically used by
the factory without defining anything:

```xml
<elasticsearch:rest-client id="esClient" />
```

You can disable this automatic lookup by setting the `autoscan` property to `false`:

```xml
<elasticsearch:rest-client id="esClient" autoscan="false" mappings="twitter/tweet" />
```

### Creating aliases to indexes

When creating an index, it could be useful to add an alias on it.
For example, if you planned to have indexes per year for twitter feeds (twitter2012, twitter2013, twitter2014) and you want
to define an alias named twitter, you can use the `aliases` property:

```xml
<elasticsearch:rest-client id="esClient"
    aliases="twitter:twitter2012,twitter:twitter2013,twitter:twitter2014" />
```

### Creating templates

Sometimes it's useful to define a template mapping that will automatically be applied to new indices created.

For example, if you planned to have indexes per year for twitter feeds (twitter2012, twitter2013, twitter2014) and you want
to define a template named `twitter_template`, you can use the `templates` property:

```xml
<!--
    We add also a facebook_template template just for showing how to
    define more than one template...
-->
<elasticsearch:rest-client id="esClient"
    templates="twitter_template,facebook_template" />
```

To configure your template you have to define a file named `es/_template/twitter_template.json` in your project:

```javascript
{
    "template" : "twitter*",
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "tweet" : {
            "properties" : {
                "message" : {
                    "type" : "text",
                    "store" : "yes"
                }
            }
        }
    }
}
```

### Changing classpath search path for mapping and settings files

By default, the factory look in `es` classpath folder to find if there is index settings or mappings definitions.
If you need to change it, you can use the `classpathRoot` property:

```xml
<elasticsearch:rest-client id="esClient" classpathRoot="myownfolder" />
```

So, if a `myownfolder/twitter/_settings.xml` file exists in your classpath, it will be used by the factory.

### Merge mappings

If you need to merge mapping for an existing `type`, set  `mergeMapping` property to `true`.

```xml
<elasticsearch:rest-client id="esClient" mergeMapping="true" />
```

If merging fails, the factory will not start ([BeanCreationException](https://github.com/SpringSource/spring-framework/blob/master/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java)
 will be raised).

### Merge settings

If you need to merge settings for an existing `index`, add a file named  `es/twitter/_update_settings.json` in your
classpath. The factory will detect it and will try to merge settings unless you explicitly set `mergeSettings` to `false`.

```xml
<elasticsearch:rest-client id="esClient" mergeSettings="false" />
```

If merging fails, the factory will not start.

### Force rebuild indices (use with caution)

For test purpose or for continuous integration, you could force the factory to clean the previous `indices` when starting the client.
It will *remove all your datas* for every index which has been defined. Just set  `forceMapping` property to `true`.

```xml
<elasticsearch:rest-client id="esClient" forceMapping="true" />
```

### Force rebuild templates (use with caution)

For test purpose or for continuous integration, you could force the factory to clean the previous `template` when starting the client.
Just set  `forceTemplate` property to `true`.

```xml
<elasticsearch:rest-client id="esClient" forceTemplate="true" />
```

### Asynchronous initialization

Client bean initialization is by default synchronously. It can be initialized asynchronously with the attributes `async` and `taskExecutor`.

```xml
<task:executor pool-size="4" id="taskExecutor"/>
<elasticsearch:rest-client id="esClient" async="true" taskExecutor="taskExecutor"/>
```
Asynchronous initialization does not block Spring startup but it continues on background on another thread.
Any methods call to these beans before elasticsearch is initialized will be blocked. `taskExecutor` references a standard Spring's task executor.

## Using Java Annotations

Let's say you want to use Spring Java Annotations, here is a typical application you can build.

`pom.xml`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>fr.pilato.tests</groupId>
    <artifactId>spring-elasticsearch-test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>fr.pilato.spring</groupId>
            <artifactId>spring-elasticsearch</artifactId>
            <version>5.0</version>
        </dependency>
    </dependencies>
</project>
```

`App.java`:

```java
package fr.pilato.tests;

import fr.pilato.spring.elasticsearch.ElasticsearchRestClientFactoryBean;
import org.elasticsearch.client.RestClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class RestApp {

    @Configuration
    public class AppConfig {
        @Bean
        public RestClient esClient() throws Exception {
            ElasticsearchRestClientFactoryBean factory = new ElasticsearchRestClientFactoryBean();
            factory.setEsNodes(new String[]{"<IP_ADDRESS>:9200"});
            factory.afterPropertiesSet();
            return factory.getObject();
        }
    }

    @Autowired
    private RestClient client;

    public static void main(String[] args) throws IOException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.scan("fr.pilato.tests");
        context.refresh();

        RestApp p = context.getBean(RestApp.class);
        p.run();

        context.close();
    }

    private void run() throws IOException {
        client.performRequest("GET", "/");
    }
}
```

## Old fashion bean definition

Note that you can use the old fashion method to define your beans instead of using `<elasticsearch:...>` namespace:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

    <util:map id="esproperties">
        <entry key="cluster.name" value="newclustername"/>
    </util:map>

    <!-- The Rest Client -->
    <bean id="esRestClient" class="fr.pilato.spring.elasticsearch.ElasticsearchRestClientFactoryBean" >
        <property name="esNodes">
            <list>
                <value>localhost:9200</value>
                <value>localhost:9201</value>
            </list>
        </property>

        <property name="autoscan" value="false" />
        <property name="mappings">
            <list>
                <value>twitter/tweet</value>
            </list>
        </property>
        <property name="classpathRoot" value="myownfolder" />
        <property name="forceMapping" value="true" />
        <property name="mergeSettings" value="true" />
        <property name="templates">
            <list>
                <value>twitter_template</value>
            </list>
        </property>
        <property name="forceTemplate" value="true" />
        <property name="aliases">
            <list>
                <value>twitter:twitter2012</value>
                <value>twitter:twitter2013</value>
                <value>twitter:twitter2014</value>
            </list>
        </property>
    </bean>

    <!-- The deprecated Transport Client -->
    <bean id="esTransportClient" class="fr.pilato.spring.elasticsearch.ElasticsearchTransportClientFactoryBean" >
        <property name="esNodes">
            <list>
                <value>localhost:9300</value>
                <value>localhost:9301</value>
            </list>
        </property>

        <property name="properties" ref="esproperties" />

        <property name="autoscan" value="false" />
        <property name="mappings">
            <list>
                <value>twitter/tweet</value>
            </list>
        </property>
        <property name="classpathRoot" value="myownfolder" />
        <property name="forceMapping" value="true" />
        <property name="mergeSettings" value="true" />
        <property name="templates">
            <list>
                <value>twitter_template</value>
            </list>
        </property>
        <property name="forceTemplate" value="true" />
        <property name="aliases">
            <list>
                <value>twitter:twitter2012</value>
                <value>twitter:twitter2013</value>
                <value>twitter:twitter2014</value>
            </list>
        </property>
    </bean>

</beans>
```

# Thanks

Special thanks to

- [Nicolas Huray](https://github.com/nhuray) for his contribution about
[templates](https://github.com/dadoonet/spring-elasticsearch/pull/4)
- [Nicolas Labrot](https://github.com/nithril) for his contribution about
[async](https://github.com/dadoonet/spring-elasticsearch/pull/30)

# License

This software is licensed under the Apache 2 license, quoted below.

	Copyright 2011-2017 David Pilato

	Licensed under the Apache License, Version 2.0 (the "License"); you may not
	use this file except in compliance with the License. You may obtain a copy of
	the License at

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

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