text:
# httlib-huffman

This crate implements [canonical Huffman] functionality for handling [HPACK]
format in [HTTP/2]. It exposes a simple API for performing the encoding and
decoding of [HTTP/2] header string literals according to the [HPACK] spec.

[![Documentation](https://img.shields.io/badge/-Documentation-blue?style=for-the-badge&logo=Rust)](https://docs.rs/httlib-huffman)
[![Source](https://img.shields.io/badge/-Source-lightgrey?style=for-the-badge&logo=GitHub)](https://github.com/xpepermint/httlib-rs/tree/main/huffman)

Header Compression format for [HTTP/2], known as [HPACK], foresees the use
of the Huffman algorithm for encoding header literal values. This
contributes to the additional decrease in the quantity of data, transferred
with each web request and response.

A [Huffman code] is a particular type of optimal prefix code that is
commonly used for lossless data compression. The process of finding or using
such a code proceeds by means of Huffman coding, an algorithm developed by
David A. Huffman. The output from Huffman's algorithm can be viewed as a
variable-length code table for encoding a source symbol (such as a character
in a file). The algorithm derives this table from the estimated probability
or frequency of occurrence (weight) for each possible value of the source
symbol. As in other entropy encoding methods, more common symbols are
generally represented using fewer bits than less common symbols. Huffman's
method can be efficiently implemented, finding a code in time linear to the
number of input weights if these weights are sorted.

[HPACK] compression entails a pre-created [canonical Huffman] code table
for encoding [ASCII] characters to the Huffman sequence. A
[canonical Huffman] code is a particular type of [Huffman code] with unique
properties that allow it to be described in a very compact manner. In the
aforementioned table are the Huffman codes for each [ASCII] character with a
length up to 32 bits (4x by 8 fields with value 0 or 1), in the form of
base-2 integer, aligned on the most significant bit (MSB is the bit farthest
to the left).

Each module covers this topic in more details so check the rest of the code
to learn more.

### Usage

Encoding:

```rs
use httlib_huffman::encode;

let mut sequence = Vec::new();
let text = "Hello world!".as_bytes();
match encode(&text, &mut sequence)?;
```

Decoding:

```rs
use httlib_huffman::decode;

let mut text = Vec::new();
let speed = 3;
let sequence = vec![168, 209, ...];
decode(&sequence, &mut text, speed).unwrap();
```

### Features

This crate splits functionalities into features so you can manually enable
or disable them as needed.

* `encode`: Enables encoding features (default).
* `decode1`: Enables decoding features for reading 1 bit at a time.
* `decode2`: Enables decoding features for reading 2 bits at a time.
* `decode3`: Enables decoding features for reading 3 bits at a time.
* `decode4`: Enables decoding features for reading 4 bits at a time (default).
* `decode5`: Enables decoding features for reading 5 bits at a time.
* `flatten`: Enables features for flattening Huffman table (default).
* `parse`: Enables features for parsing Huffman table (default).

```toml
[dependencies.httlib-huffman]
default-features = false
features = ["encode", "decode4"]
```

### Articles

* [HPACK: Huffman encoder](https://kristijansedlak.medium.com/hpack-huffman-encoder-explained-61102edd6ecc)
* [HPACK: Huffman translation matrix](https://kristijansedlak.medium.com/hpack-huffman-translation-matrix-f3cae44bfe8c)
* [HPACK: Huffman decoder](https://medium.com/@kristijansedlak/hpack-huffman-decoder-72d215788130)

[ASCII]: https://en.wikipedia.org/wiki/ASCII
[HPACK]: https://tools.ietf.org/html/rfc7541
[HTTP/2]: https://tools.ietf.org/html/rfc7540
[Huffman code]: https://en.wikipedia.org/wiki/Huffman_coding
[canonical Huffman]: https://en.wikipedia.org/wiki/Canonical_Huffman_code

License: MIT

repository: fulldecent/httlib-rs

repo_name: fulldecent/httlib-rs


text:
---
title: "Brown knows Pulse must notch up first win - March 2015"
date: 1970-01-01
description: "WELL TRAVELLED: Expat Wanganui netballer Jodi Brown is living in Dunedin while playing for the Pulse, from Wanganui Chronicle article 14/3/15..."
image: http://c1940652.r52.cf0.rackcdn.com/550610abff2a7c3613000548/JodiBrown,expatWHSnetballer.jpg
excerpt: ""
image_gallery:

---

For ex-pat Wanganui netballer and Silver Fern Jodi Brown, the most important matches to win in this season's ANZ Championship are the Kiwi derbies.

A netball nomad who has played in four of the five New Zealand squads in the transtasman competition, the 33-year-old shooter Brown joined Wellington's Mojo Pulse this season from the Southern Steel.

She commutes to the capital from Dunedin for training and games, and is gearing up for a big clash on Monday against the Mainland Tactix in Christchurch.

Currently at the bottom of the table after losses in the opening two rounds against the Melbourne Vixens (64-40) and Queensland Firebirds (52-46), the Pulse know they must register wins against fellow New Zealand teams to stay in the hunt come play-off time.

This year's finals format will be determined by the top three teams on each side of the Tasman in a new twist for the competition.

"While wins against the Australian teams are important and helpful, we know we have to beat the Kiwi teams to top the conference system," said Brown.

Legendary coach Lois Muir identified Brown, nee Te Huna, as a promising player when she was a teenager playing in Wanganui in 1998.

She moved to Wellington to complete her schooling and play for the Capital Shakers.

Earning her Silver Ferns call-up in 2002 and being part of the 2003 World Championship victory, she would later move to the Canterbury Flames, then the Auckland Diamonds, before captaining the Otago Rebels.

The introduction of the ANZ Championship in 2008 saw Brown on the move again - playing for the Tactix before the birth of her first child with her husband, top basketballer Markham Brown.

She went back to the Tactix, then switched to the Waikato/Bay of Plenty Magic in 2010, partnering Irene van Dyke, before withdrawing again to have her second child.

Brown made her fulltime comeback with the Southern Steel in 2012, but considers this move to the Pulse to be coming full circle.

"It's like coming back home.

"It's been a change of scenery ... new faces, new voices and I'm really enjoying it."

Brown stays with van Dyke when she's in the capital as they have a strong friendship which started when the giant South African moved to New Zealand.

"I had such a good time playing with her previously. We understand each other and have a telepathic sense between each other which also makes the playing side of things a little bit easier."

Brown remembers her old team the Tactix beat her current team in the upset of the season last year.

"I think they're really good.

"You don't really know what to expect and when it clicks for them it really clicks.

"If they can feed [shooter Mwayi] Kumwenda, then they're unstoppable. The key to winning against them is shutting down their attackers." -The game starts at 7.40pm on Monday, and will be shown on Sky Sport 1. The next home game will be March 30 against the Magic at Wellington's TSB Bank Arena.

license: MIT

url: https://raw.githubusercontent.com/wing5wong/artisan-whs-static/a974691b60f2aa58c92d8f0b5e7f22cd3f642a3d/source/_news/Brown knows Pulse must notch up first win - March 2015.blade.md

branch_name: refs/heads/master

extension: md

gha_language: Blade

gha_license_id: MIT

license_type: permissive


text:
# Confessions-client

[![style: styled-components](https://img.shields.io/badge/style-%F0%9F%92%85%20styled--components-orange.svg?colorB=daa357&colorA=db748e)](https://github.com/styled-components/styled-components)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/malcodeman/confessions-client/blob/master/LICENSE)

A mutually supportive community where deeply emotional things you can't tell people you know can be told.

![Screenshot](docs/images/screenshot.png)

## Usage

.env.development.local file should look like this:

```
REACT_APP_API_URL = http://localhost:4000
```

To start the app run:

```
yarn install
yarn start
```

Api is located [here](https://github.com/malcodeman/confessions-server).

## License

[MIT](./LICENSE)

repository: malcodeman/confessions-client

branch_name: refs/heads/main

gha_language: JavaScript

repo_name: malcodeman/confessions-client


text:
# vagrant-registry-generator

[![Build Status](https://travis-ci.org/Jalle19/vagrant-registry-generator.svg?branch=master)](https://travis-ci.org/Jalle19/vagrant-registry-generator)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Jalle19/vagrant-registry-generator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Jalle19/vagrant-registry-generator/?branch=master)

This is a simple tool that can be used to generate a static registry overview for Vagrant boxes stored on S3. It is
designed to be used together with the [packer-post-processor-vagrant-s3](https://github.com/lmars/packer-post-processor-vagrant-s3)
Packer post-processor.

## Installation

Go to https://github.com/Jalle19/vagrant-registry-generator/releases/latest, right-click the
`vagrant-registry-generator.phar` link, copy the URL and then run `wget <url>`. You can now run the tool using
`php vagrant-registry-generator.phar`.

## Requirements

The tool assumes your Vagrant boxes are stored on S3 in the following directory structure:

```
bucket/prefix
  - json/
    - organization/
      - boxName.json
  - boxes/
    - organization/
      - boxName/
        - version/
          - box.box
```

The bucket prefix is optional. If the prefix is omitted, the registry is written to the root of the bucket which means
you can easily enable the S3 static website hosting feature to access the registry.

## Usage

```
$ ./vagrant-registry-generator.phar --help
Usage:
  vagrant-registry-generator [options] [--] <registryPath> <outputPath>

Arguments:
  registryPath                 The path to the Vagrant registry (e.g. s3://my-bucket/my-prefix)
  outputPath                   The path where the output is generated (e.g. s3://my-bucket)

Options:
      --awsRegion[=AWSREGION]  The AWS region where your S3 bucket resides (required when using S3 paths). If not specified the value will be read from the AWS_REGION environment variable.
  -h, --help                   Display this help message
  -q, --quiet                  Do not output any message
  -V, --version                Display this application version
      --ansi                   Force ANSI output
      --no-ansi                Disable ANSI output
  -n, --no-interaction         Do not ask any interactive question
  -v|vv|vvv, --verbose         Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
 Static Vagrant registry generator
```

`registryPath` and `outputPath` should be in the form of `s3://bucket` or `s3://bucket/prefix`. You can also store the output locally
by passing a local path to `outputPath`, e.g. `./dist`.

You must specify AWS credentials using environment variables (either `AWS_PROFILE` or a combination of
`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_SESSION_TOKEN`).

To see what the program does, add `-vv` to the end of the command. Here's a sample of the output it produces on a
successful run:

```
[2016-06-06 17:01:48] NOTICE: Fetching manifest files
[2016-06-06 17:01:49] INFO: Parsing manifest file at json/foo/bar-vagrant.json
[2016-06-06 17:01:50] INFO: Parsing manifest file at json/foo/baz-vagrant.json
[2016-06-06 17:01:51] INFO: Parsing manifest file at json/foo/qux-vagrant.json
[2016-06-06 17:01:51] NOTICE: Attempting to fetch additional file metadata for each box
[2016-06-06 17:01:52] INFO: Fetching metadata for box at boxes/foo/bar-vagrant/0.1.0/packer_virtualbox-iso_virtualbox.box
[2016-06-06 17:01:52] INFO: Fetching metadata for box at boxes/foo/bar-vagrant/0.2.0/packer_virtualbox-iso_virtualbox.box
[2016-06-06 17:01:53] INFO: Fetching metadata for box at boxes/foo/baz-vagrant/0.1.0/packer_virtualbox-iso_virtualbox.box
[2016-06-06 17:01:53] INFO: Fetching metadata for box at boxes/foo/qux-vagrant/0.1.0/packer_vmware-iso_vmware.box
[2016-06-06 17:01:54] INFO: Fetching metadata for box at boxes/foo/qux-vagrant/0.2.0/packer_virtualbox-iso_virtualbox.box
[2016-06-06 17:01:54] NOTICE: Writing registry containing 3 manifest(s) from 1 organization(s)
[2016-06-06 17:01:54] INFO: Writing organization foo to registry
[2016-06-06 17:01:54] INFO: Writing manifest foo/bar-vagrant to registry
[2016-06-06 17:01:54] INFO: Writing manifest foo/baz-vagrant to registry
[2016-06-06 17:01:54] INFO: Writing manifest foo/qux-vagrant to registry
```

## Testing

Run the test suite by running `./vendor/bin/phpunit` from the project directory.

## License

MIT


text:
# Using ipvlan Interfaces with Docker Containers

These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) to build an environment for working with Docker containers using ipvlan interfaces. This configuration was tested using Vagrant 1.8.1, VMware Fusion 8.1.0, and version 4.0.5 of the Vagrant VMware plugin.

## Contents

* **machines.yml**: This is a YAML file containing the configuration data used by Vagrant when creating and provisioning VMs. This particular Vagrant environment requires six (6) values in this file for each VM: `name` (name to be assigned to the box as well as used for hostname), `box` (the name of the Vagrant box), `ram` (desired RAM), `vcpu` (number of virtual CPUs), `ip_addr` (the private IP address to be assigned to the second network interface; also controls whether a second interface is provisioned), and `docker` (set to "true" or "false"; controls whether Vagrant provisions Docker onto the VM).

* **README.md**: The file you're currently reading.

* **Vagrantfile**: This file is used by Vagrant to spin up the virtual machines for this environment. No changes need to be made to this document, as all the configuration data is found in other files (like `machines.yml`). However, if you are using a virtualization solution _other_ than VMware Fusion, you might need to make changes to this file.

## Instructions

These instructions assume you've already installed VMware Fusion, Vagrant, and the Vagrant VMware plugin. Please refer to the documentation for those products for more information on installation or configuration. Note that Internet access is required when using `vagrant up` to create this environment.

1. Use `vagrant box add` to install _both_ an Ubuntu 15.04 x86_64 box _and_ an Ubuntu 14.04 x86_64 Vagrant box. I have an Ubuntu 14.04 x86_64 base box you can use; to use my base box, add the box with `vagrant box add slowe/ubuntu-trusty-x64`. A Vagrant box you might consider using for Ubuntu 15.04 is the `bento/ubuntu-15.04` box.

2. Place the files from the `docker-ipvlan` directory of this GitHub repository into a directory on your local system. You can clone the entire "learning-tools" repository (using `git clone`) or just download the specific files from the the `docker-ipvlan` folder.

3. If necessary, edit `machines.yml` to specify the name of the Vagrant boxes downloaded in step 1. The VM definition for "docker-01" **must** use Ubuntu 15.04; the other VM may use any version of Ubuntu you prefer. You may also make changes to the private IP addresses or the RAM/CPU settings, although no changes are typically required.

4. Run `vagrant up` to instantiate the learning environment. This will spin up two (2) VMs based on the Vagrant boxes you downloaded in step 1 and specified in `machines.yml` in step 3. Vagrant will also appropriately configure each VM and start the necessary services. Depending on the speed of your system and your Internet connection, this may take a few minutes.

5. Use `vagrant ssh docker-01` to connect to the first Docker host and run the following commands to download and install the ipvlan plugin for Docker:

        git clone https://github.com/gopher-net/ipvlan-docker-plugin.git
        cd ipvlan-docker-plugin/binaries
        sudo ./ipvlan-docker-plugin-0.2-Linux-x86_64 \
        --ipvlan-subnet "<IP_ADDRESS>/24" \
        --gateway "<IP_ADDRESS>" --mode "l2" \
        --host-interface "eth1" -d &

    If you changed the private IP addresses in `machines.yml`, be sure to supply the appropriate IP address ranges from that file in the command above.

6. Run this command to create a network using the ipvlan plugin:

        docker network create -d ipvlan --subnet=<IP_ADDRESS>/24 \
        --gateway=<IP_ADDRESS> -o host_iface=eth1 -o mode=l2 testnet

    Note that the subnet, gateway, host interface, and mode specified here need to match what was provided when the plugin was launched in step 5.

7. Launch a Docker container attached to this new network with this command line:

        docker run -it --rm --net=testnet ubuntu

    This will drop you at a root prompt for an Ubuntu container. Use `ip addr list` to determine the IP address assigned to this container.

8. In a separate terminal window, switch to the directory where the files for this environment are stored and connect to the remote VM using `vagrant ssh remote-01`.

9. In the remote VM, ping the IP address of the container (obtained in step 7 when you launched the container).

10. From the container prompt, ping the IP address assigned to the remote VM (by default, <IP_ADDRESS>).

Enjoy!

repository: vugit/learning-tools

repo_name: vugit/learning-tools


text:
# apiserver [![build status](https://secure.travis-ci.org/kilianc/node-apiserver.png?branch=master)](http://travis-ci.org/kilianc/node-apiserver)

A ready to go, modular, multi transport, streaming friendly, JSON(P) API Server.

## Why use ApiServer and not [restify](https://github.com/mcavage/node-restify) or [express](https://github.com/visionmedia/express)?

Strong competitors I guess.

__Express__ targets web applications providing support for templates, views, and all the facilities the you probably need if you're writing a web app. __Restify__ let you "build "strict" API services" but it's too big and it concentrates on server to server API, that will not be consumed by your browser.

__ApiServer__ is rad. It is a slim, fast, minimal API framework, built to provide you a flexible API consumable both in the browser and from other apps. It ships with JSON, JSONP [__(GET/POST)__](https://github.com/kilianc/node-json-transport) transports and a powerful [fast routing engine](https://github.com/kilianc/node-apiserver-router) OOTB. The source code is small, heavily tested and decoupled. Your API source will be well organized in context objects, allowing you to keep it in a meaningful maintainable way.

### Killer features

* Streaming JSON(P) transport GET/POST browser friendly
* Fast routing system with cached routes
* Implicit route parameters [(rails like)](http://guides.rubyonrails.org/routing.html)
* Fully configurable custom routing
* API modules as Objects/Classes
* Payload paused by default
* Transports decoupled from the core
* Router decoupled from the core
* Compatible with [senchalabs/Connect](https://github.com/senchalabs/Connect) middleware

## Installation

    ⚡ npm install apiserver

```js
var ApiServer = require('apiserver')
```

# Quick look

The example below is intended to be a small sneak peek of the ApiServer API, modules and routes should be moved to separate files.

```js

var ApiServer = require('apiserver')

var apiServer = new ApiServer({ port: 8080 })

// middleware
apiServer.use(/^\/admin\//, ApiServer.httpAuth({
  realm: 'ApiServer Example',
  encode: true,
  credentials: ['admin:apiserver']
}))
apiServer.use(ApiServer.payloadParser())

// modules
apiServer.addModule('1', 'fooModule', {
  // only functions exposed
  options: {
    opt1: 'opt1',
    opt2: 'opt2',
    opt3: 'opt3'
  },
  foo: {
    get: function (request, response) {
      response.serveJSON({
        id: request.querystring.id,
        verbose: request.querystring.verbose,
        method: 'GET',
        options: this.options
      })
    },
    post: function (request, response) {
      request.resume()
      request.once('end', function () {
        response.serveJSON({
          id: request.querystring.id,
          verbose: request.querystring.verbose,
          method: 'POST',
          payload: request.body // thanks to payloadParser
        })
      })
    }
  },
  bar: function (request, response) {
    response.serveJSON({ foo: 'bar', pow: this._pow(5), method: '*/' + request.method })
  },
  // never exposed due to the initial underscore
  _pow: function (n) {
    return n * n
  }
})

// custom routing
apiServer.router.addRoutes([
  ['/foo', '1/fooModule#foo'],
  ['/foo/:id/:verbose', '1/fooModule#foo'],
  ['/foo_verbose/:id', '1/fooModule#foo', { 'verbose': true }],
  ['/bar', '1/fooModule#bar', {}, true] // will keep default routing too
])

// events
apiServer.on('requestStart', function (pathname, time) {
  console.info(' ☉ :: start    :: %s', pathname)
}).on('requestEnd', function (pathname, time) {
  console.info(' ☺ :: end      :: %s in %dms', pathname, time)
}).on('error', function (pathname, err) {
  console.info(' ☹ :: error    :: %s (%s)', pathname, err.message)
}).on('timeout', function (pathname) {
  console.info(' ☂ :: timedout :: %s', pathname)
})

apiServer.listen()
```

Server will respond to

    GET, POST http://localhost:8080/foo
    GET, POST http://localhost:8080/foo/5/true
    GET, POST http://localhost:8080/foo_verbose/5
    *         http://localhost:8080/bar
    *         http://localhost:8080/1/foo_module/bar

For full and detailed examples look at the [examples folder](https://github.com/kilianc/node-apiserver/tree/master/examples)

## Table Of Contents
* [Methods](#class-method-constructor)
  * [#()](#class-method-constructor)
  * [#addModule(version, moduleName, apiModule)](#class-method-addmodule)
  * [#use([route], middleware)](#class-method-use)
  * [#listen([port], [callback])](#class-method-listen)
  * [#close([callback])](#class-method-close)
* [Modules](#modules)
  * [Interface](#modules-interface)
  * [Examples](#modules-examples)
* [Middleware](#middleware)
  * [Interface](#middleware-interface)
  * [Transports](#transports)
* [Router](#router)
  * [Interface](#router-interface)
* [Bundled Middleware](#bundled-middleware)
  * [JSONTransport](#jsontransport)
  * [httpAuth](#httpauth)
  * [mutipartParser](#mutipartparser)
  * [payloadParser](#payloadparser)
* [How to contribute](#how-to-contribute)
* [License](#license)

# Class Methods

## Class Method: constructor

All options will be also passed to the the default transport (JSONTransport) [constructor](https://github.com/kilianc/node-json-transport#syntax), then add here your transport configuration.

### Syntax:

```js
new ApiServer([options])
```

### Available Options:

* __port__ - (`Number|String`: defaults to 8080) the server binding port
* __server__ - (`http(s).Server`: defaults http.Server)
* __timeout__ - (`Number`: defaults to 15000) milliseconds to wait before arbitrary closing the response
* __router__ - (`Object`: defaults to the standard [router](#router)) the routes manager conforms to the [router interface](#router-interface)
* __standardHeaders__ - (`Object`: below the default) response headers defaults, can be overwritten by the [transport](#transports)

```js
{
  'cache-control': 'max-age=0, no-cache, no-store, must-revalidate',
  'expires': 0,
  'pragma': 'no-cache',
  'x-server': 'ApiServer v' + ApiServer.version + ' raging on nodejs ' + process.version
}
```

### Example:

```js
var https = require('https'),
    ApiServer = require('apiserver')

apiserver = new ApiServer({
  port: 80,
  server: https.createServer(),
  standardHeaders: {
    'cache-control': 'max-age=0, no-cache, no-store, must-revalidate',
    'x-awesome-field': 'awezing value'
  },
  timeout: 2000,
  indent: ' ',              // transport
  domain: '.myservice.com',  // transport
  defaultRoute: '/:version/:module/:method'  // router
})
```

## Class Method: addModule

Adds a new [module](#modules) to to the current API set. It triggers the `router.update` method.

### Syntax:

```js
ApiServer.prototype.addModule(apiVersion, moduleName, apiModule)
```

### Arguments:

* __apiVersion__ - (`String`) the version of the API you want to add your module to, it will be the part of the url
* __moduleName__ - (`String`) the name of the module, this will be the second part of your derived routes, after a [case conversion](#modules)
* __apiModule__ - (`Object`) the module object conform to the [modules interface](#module-interface)

### Examples:

```js
var apiserver = new ApiServer()
apiserver.addModule('v1', 'user', userModule)
apiserver.addModule('v1', 'pages', pageModule)
apiserver.addModule('v2', 'user', userModule2)
```

## Class Method: use

Adds a middleware object to the [middleware chain](#middleware-chain). It triggers the `router.update` method.

Each middleware is associated to a `RegExp` used to test the API end-point route. If the route matches the `RegExp` the middleware will be a part of the chain and will be executed.

Read more about middleware [here](#middleware).

### Syntax:

```js
ApiServer.prototype.use([route], middleware)
```

### Arguments:

* __route__ - (`RegExp`: defaults to `/./`) regular expression that the route should match
* __middleware__ - (`Object`) the middleware object conforms to the [middleware interface](#middleware-interface)

### Examples:

```js
var apiserver = new ApiServer()
apiserver.use(new MyMiddleWare({ foo: 'bar', bar: true }))
apiserver.use(/(signin|signup)/, ApiServer.payloadParser())
apiserver.use(/^\/v1\/files\/upload$/, ApiServer.multipartParser())
```

## Class Method: listen
Bind the server to a port

### Syntax:

```js
ApiServer.prototype.listen([port], [callback])
```

### Arguments:

* __port__ - (`Number|String`) overwrite the constructor __port__ parameter
* __callback__ - (`Function`) called when the port is actually bound to the server

### Example:
_From this point on, all the examples will take the require statements as assumption_

```js
var apiserver = new ApiServer()
apiserver.listen(80, function (err) {
  if (err) {
    console.error('Something terrible happened: %s', err.message)
  } else {
    console.log('Successful bound to port %s', this.port)
  }
})
```

## Class Method: close
Unbind the server from the current port

### Syntax:

```js
ApiServer.prototype.close([callback])
```

### Arguments:

* __callback__ - (`Function`) called when the port is actually unbound from the server

### Example:

```js
var apiserver = new ApiServer()
apiserver.listen(80, onListen)

function onListen(err) {
  if (err) {
    console.error('Something terrible happened: %s', err.message)
  } else {
    setTimeout(function () {
      apiserver.close(onClose)
    }, 5000)
  }
}

function onClose() {
  console.log('port unbound correctly')
}
```

# Class Events

## Class Event: requestStart

Emitted when an API endpoint got hit.

### Event data

```js
apiserver.on('requestStart', function (url, requestTime) {

})
```

  * __url__ (`String`) - the `request.url`
  * __requestTime__ (`Number`) - when the API method was requested

## Class Event: requestEnd

Emitted when an API method closes the response, even with `response.end`.

### Event data

```js
apiserver.on('requestEnd', function (url, responseTime) {

})
```

  * __url__ (`String`) - the `request.url`
  * __responseTime__ (`Number`) - how log the API method took for closing the response

## Class Event: timeout

Emitted when an API method exceed the maximum allowed time ([see `timeout` option](#class-method-constructor)), before closing the response.

### Event data

```js
apiserver.on('timeout', function (url) {

})
```

  * __url__ (`String`) - the `request.url`

## Class Event: error

Emitted when a __sync__ error is triggered during the [middleware chain](#middleware-chain) execution, can be both your API, a transport or a simple middleware.

_You still have to deal with async errors_

### Event data

```js
apiserver.on('error', function (url, err) {

})
```

  * __url__ (`String`) - the `request.url`
  * __err__ (`Error`) - the error which triggered the event

# Modules

A module is a set of API __end-points__ grouped in the same __context__:

* __context__: a simple object
* __end-point__: function/method accessible by the object and scoped within the object

## Modules Interface

Each module method (API end-point) must implement this interface and expect request and response parameters

```js
function (request, response)
```

The request object is ["extendend"](https://github.com/kilianc/node-apiserver/blob/master/lib/apiserver.js#L99) ootb with the following members _(aliases in round brackets)_:

* __requestedAt (at)__: timestamp of the request
* __parsedUrl__: a parsed version of the request url with `url.parse`
* __pathname (path)__: the pathname that corresponds to the end-point route
* __querystring (qs)__: the querystring object parsed with [visionmedia/node-querystring](https://github.com/visionmedia/node-querystring)

As you can see, there is no callback to call, you have to deal directly with the response.

Take a look at your [transport documentation](#transports) and use the right method that ships within the response object. You can also roughly close and write to the response __stream__ in an edge case.

## Modules Examples

### Object literal

```js
var apiserver = new ApiServer()
```

```js
var userModule = {
  signin: function (request, response) {
    // rough approach
    response.writeHead(200)
    response.end('ok')
  },
  signout: function (request, response) {
    // JSON transport
    response.serveJSON({ foo: 'bar' })
  }
}
```

```js
apiserver.addModule('v1', 'user', userModule)
```

### Class

```js
var apiserver = new ApiServer()
```

```js
function UserModule(options) {
  this.database = options.database
  this.serviceName = options.serviceName
}

UserModule.prototype.signin = function (request, response) {
  var self = this
  self.database.searchUser(request.querystring.username, function (err) {
    if (err) {
      response.serveJSON({ success: false, err: err.message })
    } else {
      response.serveJSON({ success: true, message: 'welcome to ' + self.serviceName })
    }
  })
}

UserModule.prototype.signout = function (request, response) {
  // you can use the response as usual
  // a redirect for example
  response.writeHead(302, {
    'location': 'http://example.org/logout_suceesful'
  })
  response.end()
}
```

```js
var database = /* your db object*/
apiserver.addModule('v1', 'user', new UserModule(database, 'My Awesome Service'))
```

# Middleware

The concept of middleware is not new at all, you can find the same pattern in [senchalabs/Connect](https://github.com/senchalabs/Connect) in  [mcavage/node-restify](https://github.com/mcavage/node-restify) and in many others. A [middleware](http://en.wikipedia.org/wiki/Middleware) is a piece of software that adds (or patches) a feature into another software. Usually there is a common interface to implement, because the caller software, in this case our __ApiServer__, should know how to interact with the middleware.

_You should check out the [source code](https://github.com/kilianc/node-apiserver/tree/master/lib/middleware) for a large understanding, middleware is relatively easy to code._

## Middleware Chain

The __ApiServer__ uses [kilianc/node-fnchain](https://github.com/kilianc/node-fnchain) to [execute all the active middleware](https://github.com/kilianc/node-apiserver/blob/master/lib/apiserver.js#L132) and reach the API method (that actually is the last ring of the chain). This means that the order of the execution depends on the order you activated the middleware.

Each middleware can both exit with an error or explicitly stop the chain (not reaching your API method). This is useful in case of a precondition check (auth, sessions, DoS attack filter...), or just because you packed some shared code as middleware which must be executed before your API method.

At the middleware execution level, the response object is already patched with the default transport methods, so you can use these methods to write and close the response. Is a good practice to leave at the top of the chain the extra transports middleware.

```js
// constructor adds the default transport automatically
var apiserver = new ApiServer()

// let's ad first our custom transports
apiserver.use(/\.xml$/, myXMLTransport())
apiserver.use(/\.csv$/, myCSVTransport())
apiserver.use(/\.yml$/, myYAMLTransport())

// now activate our middleware
apiserver.use(/form/, ApiServer.payloadParser())
apiserver.use(/upload/, ApiServer.multipartParser())

...
```

__The request payload (the `data` event) is paused by default and can be resumed calling `request.resume()` at any level of execution: middleware, module, transport.__ Why? Because you should explicitly accept or refuse a payload, this way you will save memory not buffering useless data.

Take a look at both the [pause](http://nodejs.org/api/all.html#all_request_pause) and [resume](http://nodejs.org/api/all.html#all_request_resume) official docs.

_ApiServer is using [this patch](https://github.com/kilianc/node-buffered-request) to provide a robust buffered pause resume method, so you don't have do deal with the flying chunks after the pause call_

## Middleware Interface

Each middleware must implement this interface.

```js
module.exports = function (options) {
  return function (request, response, next) {
    // do sometihng async and when you're done call the callback
    options.count++
    next()
  }
}
```

A middleware basically, is a function that returns another function, this one must declare 3 paramaters:

* __request__: the server request already extended by the server
* __response__: the server response already extended by the transports
* __next__: a callback in the following form `function (err, stop)`

The `next` callback expects 2 parameters:

* __err__ - (`Error`) an error object that will throw a server error event and will close the response
* __stop__ - (`Boolean`) a flag that stops the internal chain, that means that your API method will never be called and your middleware should be able to correctly close the response. At this point you already have all the transports available, and you can freely use them.

## Transports

A transport is a particular middleware that "extends" the response object. It can provide new methods that allow you to serve your data to the client in different ways.

Usually this is how you send data back to the client:

```js
function (request, response) {
  response.writeHead(200, {
    'content-type': 'application/json'
  })
  response.end(JSON.stringify({ foo: 'bar' }))
})
```

This is for example how the default [JSONTransport](https://github.com/kilianc/node-json-transport) simplify the process

```js
function (request, response) {
  response.serveJSON({ foo: 'bar' })
})
```

Basically what a transport does, is to wrap your data around a meaningful format (JSON, JSONP, HTML, XML, CSV, ...) understandable by your clients. It takes care of all the small things that the raw response needs (headers, status codes, buffering, ...)

Transports must be at the top of the middleware chain, in order to allow other middleware to use them.

[JSONTransport](https://github.com/kilianc/node-json-transport) is the default one, is attached before the middleware chain execution and then is available at every level of execution. You don't need to allocate it directly, the server itself will allocate the transport passing as options the __ApiServer__ [constructor](#class-method-constructor) options object.

### Example

```js
module.exports = function (options) {
  function serve<FORMAT>(request, response, data, options) {
    response.writeHead(200, {
      'content-type': 'application/<FORMAT>'
    })
    response.end(<FORMAT>.stringify(data))
  }
  return function (request, response) {
    // attach some new method to the response
    response.serve<FORMAT> = serve<FORMAT>.bind(this, request, response)
  }
}
```

where `<FORMAT>` is the formatting method of your data.

# Router

Apiserver uses [apiserver-router](https://github.com/kilianc/node-apiserver-router) as default router, a fast routing system with integrated caching. It basically translates your API methods names in routes, doing some convenient case conversion. Also, it supports [(rails like)](http://guides.rubyonrails.org/routing.html) custom routes and implicit route parameters.

You can change the default behavior passing a custom router as `router` option in the ApiServer [constructor](#class-method-constructor).

## Example

```js
function UserModule(options) {
  this.options = options
}

// will be translated into /1/random_photo_module/create_album
UserModule.prototype.createAlbum = function (request, response) { ... }

// will be translated into /1/random_photo_module/upload_photo
// in this case we will overwrite the default path with a custom one
UserModule.prototype.uploadPhoto = {
  post: function (request, response) { ... }
}

// private method, skipped by the router
UserModule.prototype._checkFileExtension = function (request, response) { ... }

```

```js
apiserver.addModule('1', 'randomPhotoModule', new UserModule())
apiserver.router.addRoute('/photo/:caption', '1/randomPhotoModule#uploadPhoto')
```

N.B. the `moduleName` also will be translated

## Router Interface

Your custom router must implement the following interface.

```js
function Router () {
  ...
}

Router.prototype.update = function (modules, middlewareList) {
  ...
}

Router.prototype.get = function (request) {
  ...
}
```

The `get` method must return the the [middleware chain](#middleware-chain) associated with the `request` parameter, and eventually extend the `request` with new data (ex. implicit route parameters).

# Bundled Middleware

## JSONTransport

[JSONTransport](https://github.com/kilianc/node-json-transport) is the default transport bundled with ApiServer and we can call it the real __killer feature__.

It provides JSON and JSONP that work with both GET / POST methods.

### Examples

```js
// decontextualized API method
function (request, response) {
  response.serveJSON({ foo: 'bar' })
})
```

```js
// decontextualized API method
function (request, response) {
  response.serveJSON(['foo','bar', ...], {
    httpStatusCode: 404,
    httpStatusMessage: 'maybe.. you\'re lost',
    headers: {
      'x-value': 'foo'
    }
  })
})
```
```js
// decontextualized API method
function (request, response) {
  var count = 3
  var interval = setInterval(function () {
    if (count === 0) {
      clearInterval(interval)
      response.streamJSON()
    } else {
      count--
      response.streamJSON({ foo: 'bar' })
    }
  }, 200)
})
```

yields

```js
[
   { "foo": "bar" },
   { "foo": "bar" },
   { "foo": "bar" }
]
```

Read the full docs [here](https://github.com/kilianc/node-json-transport)

## payloadParser

The payload parser automatically __buffers__ the payload and parse it. It only works with __PUT POST OPTIONS__ http methods, because they are the only that can carryout a payload by specs definition.

Two kinds of payload can be parsed:

* `application/x-www-form-urlencoded`
* `application/json`

The following attributes will be attached to the request object:

* __body__: an object containing the parsed data
* __rawBody__: the raw payload as binary [buffer](http://nodejs.org/api/all.html#all_buffer)
* __parseError__: can be `null` or `Error` in case of parse error

### Syntax

```js
ApiServer.payloadParser()
```

### Example

```js
var apiserver = new ApiServer()
apiserver.use(/1\/my_module\/my_method_api$/, ApiServer.payloadParser())
apiserver.addModule('1', 'myModule', {
  'my_method_api': function (request, response) {
    request.resume()
    request.once('end', function () {
      if (request.parseError) {
        // :(
        console.error(request.parseError.message)
      } else {
        request.body // an object containing the parsed data
        request.rawBody // contains a binary buffer with your payload
      }
    })
  }
})
```

## multipartParser

The multipart-parser the attach the payload to a [felixge/node-formidable](https://github.com/felixge/node-formidable) `IncomingForm` object. It only works with __PUT POST OPTIONS__ http methods, because they are the only that can carryout a payload by specs definition.

Only a `multipart/form-data` payload is parsed and the following attribute will be attached to the request object:

* __form__ an IncomingForm object, [read how to deal with it](https://github.com/felixge/node-formidable#formidablefile)

The following attributes will be attached to the request object, *after the IncomingForm end event*:

* __body__: an object containing the parsed data
* __files__: array of uploaded files [instaceof formidable.File](https://github.com/felixge/node-formidable#formidablefile)
* __parseError__: can be `null` or `Error` in case of parse error

### Syntax

```js
ApiServer.multipartParser()
```

### Example

```js
var apiserver = new ApiServer()
apiserver.use(/1\/my_module\/my_method_api$/, ApiServer.multipartParser())
apiserver.addModule('1', 'myModule', {
  'my_method_api': function (request, response) {
    var fields = Object.create(null)
    request.resume()
    request.form.on('field', function (name, value) {
      fields[name] = value
    })
    request.form.on('file', function (name, file) {
      fields[name] = fs.readFileSync(file.path, 'utf8')
    })
    request.form.once('end', function () {
      // do something with your data
    })
  },
  'my_smarter_api': function (request, response) {
    request.resume()
    request.form.once('end', function () {
      // do something with your data
      request.body // fields
      request.files // files
      request.parseError // error
    })
  }
})
```

## httpAuth

The httpauth middleware acts as an auth precondition, checking the `authorization` headers sent with the request.

If the request doesn't pass the authorization check, httpAuth [will close the response](https://github.com/kilianc/node-apiserver/blob/refactor/lib/middleware/httpauth.js#L34) using the standard JSONTransport:

```js
response.serveJSON(null, {
  httpStatusCode: 401,
  headers: { 'www-authenticate': 'Basic realm=\'' + realm + '\'' }
})
```

This will trigger a user/password prompt in your browser

### Syntax

```js
ApiServer.httpAuth([options])
```

### Options
* __realm__: (`String`) the name of your service, this is used by the browser when it prompts for username and password
* __credentials__ - (`Array`) a list of strings (credentials), if your client is a browser you must use the form _username:password_
* __encode__: (`Boolean`: defaults to false) set to true if your client is a browser (will base64 encode)

### Example

```js
var apiserver = new ApiServer()
apiserver.use(/1\/admin\/.+/, ApiServer.httpAuth({
  realm: 'signin please',
  credentials: ['foo:password','bar:password', ...],
  encode: true // we suppose that at the other end of the wire we have a browser
}))
apiserver.addModule('1', 'admin', {
  'protectedApi': function (request, response) {
    // this will executed only if you provide valid credentials
  }
})
```

# How to contribute

__ApiServer__ follows the awesome [Vincent Driessen](http://nvie.com/about/) [branching model](http://nvie.com/posts/a-successful-git-branching-model/).

* You must add a new feature on his own topic branch
* You must contribute to hot-fixing directly into the master branch (and pull-request to it)

ApiServer follows (more or less) the [Felix's Node.js Style Guide](http://nodeguide.com/style.html), your contribution must be consistent with this style.

The test suite is written on top of [visionmedia/mocha](http://visionmedia.github.com/mocha/) and it took hours of hard work. Please use the tests to check if your contribution is breaking some part of the library and add new tests for each new feature.

    ⚡ npm test

and for your test coverage

    ⚡ make test-cov

## License

_This software is released under the MIT license cited below_.

    Copyright (c) 2010 Kilian Ciuffolo<EMAIL_ADDRESS>All Rights Reserved.

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

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

    THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    OTHER DEALINGS IN THE SOFTWARE.

repository: ilioner/TYZTorrentMagentTools

repo_name: ilioner/TYZTorrentMagentTools


text:
---
template: article.html
pageSlug: about
title: About Kalastatic
cta:
  title: Interested in learning more about us?
  cta: Contact us
  url: "/contact"
---

Kalastatic is a prototyping framework.

It can be (and has been) used to build beautifully crafted static sites at [Kalamuna](https://www.kalamuna.com).

However, its primary purpose is to put into practice [atomic web design](http://bradfrost.com/blog/post/atomic-web-design) principles to produce a [living styleguide](http://www.webdesignerdepot.com/2014/09/how-to-make-your-code-easily-maintainable-with-living-style-guides) that can be used to guide back-end implementations in a framework agnostic approach.

As such, it serves as a point of convergence between front-end development, back-end development, and content strategy.

We have [Drupal](https://www.drupal.org) in mind and are positioning the project to co-exist with Drupal themes – in particular [Kalatheme](https://www.drupal.org/project/kalatheme).

_**Kalastatic** is currently experimental.
Development is not guaranteed backwards compatible at this time, and therefore not recommended for a production environment._

## Project Goals

1. Designers and front-end developers should soar in their expressivity by focusing on their craft instead of struggling with poorly documented CMS APIs and configurations.
1. Provide tangible assets for clients and agencies early in the process to drive design thinking while staying nimble.
1. Demonstrate content and support content strategy in-situ early in the process.
1. Provide a litmus test against style regressions during development.
1. Lower the technological barrier to crafting small sites for agency-style projects

## Features

* [Documentation](https://github.com/kalamuna/kalastatic/wiki/)
* [Automated Deployments](https://github.com/kalamuna/kalastatic/wiki/Depolyment)
* Development
  * Easy installation, with minimal dependencies
  * Automated download of Bootstrap and other dependencies
  * Built in webserver
  * Livereload - saving files reloads the browser
  * [Remote device access](https://github.com/kalamuna/kalastatic/wiki/Testing-via-other-devices) - load your local on a mobile device!
* Design
  * Produces documented component library
  * Easy creation of extendable template variations with inheritance
  * Output production ready styles
* Convenience Utilities
  * [cache busting](https://github.com/kalamuna/kalastatic/wiki/Cache-Busting)
  * deep linking ([url fragments](https://github.com/kalamuna/kalastatic/wiki/Fragment-Identifiers))
  * character limit [filters](https://github.com/kalamuna/kalastatic/wiki/Filters)
  * splits CSS files for IE compatibility

## KalaStatic-Inspired Sites
* [kalamuna.com](http://kalamuna.com)
* [MaisonBK](http://maisonbk.ca)
* [Pinnacle Engines](http://pinnacle-engines.com)

repository: mixxmac/kalastatic

repo_name: mixxmac/kalastatic


text:
---
title: Interpreting jstat's number of Full GC events
date: 2016-02-04T23:58:26+01:00
excerpt: "How results of your measurements can drift from reality when you don't validate your assumptions"
tags:
  - JVM
---

*"You can't control what you can't measure"*[^1] and you want to control software you're running.
Nonetheless measuring is not enough, you also need to know how to interpret results of such measurements.

It's not hard to find examples of misinterpreted measurement results with the `free`[^2] command output being one of the most commonly misinterpreted ones.
Often lack of understanding of used terminology or it's ambiguity can be accounted for it.
For example let's look at `jstat` output for a Java process:

```sh
$ jstat -gc -t 4648 1s
Timestamp        S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT
           19.4 8704.0 8704.0  0.0   8704.0 69952.0  12416.7   240928.0   173395.8  154352.0 149283.9 22180.0 20722.4     27    0.594   8      0.231    0.825
```

Anyone knowing JVM Garbage Collection basics should have no trouble telling what those values mean, shouldn't he?
Well let's try: EC stands for Eden space Capacity, EU denotes Eden space Usage, S0C - Survivor space 0 Capacity, YGC - number of Young generation Garbage Collections, YGCT - Young generation Garbage Collection Time, and so on.

Pretty obvious, isn't it?
So let's gather statistics for the old generation (and metaspace) and answer the question how many Full GCs[^3] were performed?

```sh
$ jstat -gcold -t 5007 1s
Timestamp          MC       MU      CCSC     CCSU       OC          OU       YGC    FGC    FGCT     GCT
           11.7 113064.0 109246.8  16156.0  14883.7    174784.0    115285.4     13     4    0.079    0.368
```

If your answer is 4 you might be correct or far from being correct.
It all depends on which garbage collector the monitored Java process was using.
If it was using Parallel GC the answer would be 4, but since it was using CMS the answer is different, the answer is 2.

Not the number of garbage collection cycles but the number of garbage collection events.
The significance of `events` becomes evident if we compare 4 Full GC events reported by jstat to 2 CMS cycles that we can observe in the GC logs.

Let's take one more look at the GC logs, this time narrowing down our focus to single CMS cycle:

```sh
2.170: [GC (CMS Initial Mark) [1 CMS-initial-mark: 29844K(174784K)] 39075K(253440K), 0.0021170 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
2.172: [CMS-concurrent-mark-start]
2.185: [CMS-concurrent-mark: 0.013/0.013 secs] [Times: user=0.08 sys=0.00, real=0.02 secs]
2.185: [CMS-concurrent-preclean-start]
2.186: [CMS-concurrent-preclean: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2.186: [CMS-concurrent-abortable-preclean-start]
2.637: [CMS-concurrent-abortable-preclean: 0.169/0.451 secs] [Times: user=2.13 sys=0.05, real=0.45 secs]
2.637: [GC (CMS Final Remark) [YG occupancy: 54140 K (78656 K)]2.637: [Rescan (parallel) , 0.0284352 secs]2.666: [weak refs processing, 0.0001802 secs]2.666: [class unloading, 0.0051609 secs]2.671: [scrub symbol table, 0.0035550 secs]2.675: [scrub string table, 0.0008166 secs][1 CMS-remark: 29844K(174784K)] 83984K(253440K), 0.0391194 secs] [Times: user=0.21 sys=0.00, real=0.04 secs]
2.676: [CMS-concurrent-sweep-start]
2.688: [CMS-concurrent-sweep: 0.011/0.012 secs] [Times: user=0.06 sys=0.00, real=0.01 secs]
2.688: [CMS-concurrent-reset-start]
2.696: [CMS-concurrent-reset: 0.008/0.008 secs] [Times: user=0.04 sys=0.01, real=0.01 secs]
```

We can see that CMS performs its work in several phases and most of them run concurrently with our application.
Only Initial Mark and Final Remark are stop-the-world phases and those are the ones that get counted by jstat as Full GC events.

Should you measure something make sure you know what you really measure otherwise the results can keep you far from reality.
Always validate your assumptions and [RTFM](https://xkcd.com/293/)!

[^1]: Tom DeMarco
[^2]: [Linux is borrowing unused memory for disk caching what makes it looks like you are low on memory while you are not](http://www.linuxatemyram.com/)
[^3]: while we speak about ambiguity it's worth to note that there is no formal definition of Full GC nor Major GC in JVM Specification (kudos to [Bernd Eckenfels](https://twitter.com/eckes) for pointing this out)


text:
---
layout: post
title: "Continuous Integration"
description: "Automatic code test with Jekins"
category: Tool Development
tags: []
---
<link href="/css/ci.css" rel="stylesheet">
{% include JB/setup %}

Automatic code test with Jekins.

### Outline

+ Overview
+ Create Jenkins Project
+ Configure Jenkins Project
+ Create Webhook on Github
+ CGI Scripts on a Web Server
+ Acknowledgement

### Overview

It is critical to build and test your application at various stages of
its development.
Every once in a while you'll build the application
from the integrated codes
(assuming various components or units of the codes
have already passed unit test)
and run it on test data to make sure the application works as expected
and uncover bugs as early as possible.
Ideally you'd like to have a system that would trigger the build process
upon some specific events, such as the merge of a branch to the master branch
from a [GitHub](http://github.com) repository
if you have decided to always build the final application
with the codes from the master branch (the master branch is the default branch
created when you create a [GitHub](http://github.com) repository;
[please click here for more info](https://git-scm.com/book/en/v1/Git-Branching-What-a-Branch-Is)).
This is especially important if the codes are
contributed by multiple developers and
you want to ensure the integrated codes (and the product built from the codes)
in the master branch always in the working condition.

In development of bioinformatics applications,
we often build pipelines to manage workflows that integrate various tools
to process biological data for data mining and knowledge discovery,
such as processing sequence data for the identification of
genes or mutations associated with diseases.
In such cases, we need to test a pipeline every time new tools
are incorporated into the pipeline or parameters are changed for some tools.

Here we present a way
we implemented at the bioinformatics group
in the Department of Biomedical and Health Informactics
of the Children's Hospital of Philadelphia
([CHOP](http://www.chop.edu))
to automatically run a pipeline
with [Jenkins](https://jenkins.io/)
when changes to the pipeline codes are pushed or merged to
the master branch of the [GitHub](http://github.com) repository.
In this particular case,
the pipeline is coded in a snakefile and executed with
[snakemake](https://pypi.python.org/pypi/snakemake).
Snakemake is a general-purpose workflow management system coupled with
the [Python](https://www.python.org/) language.
Please read the
[tutorial](http://snakemake.bitbucket.org/snakemake-tutorial.html)
if you're not familiar with
[snakemake](https://pypi.python.org/pypi/snakemake).
Recipes of the pipeline come from more than one developer,
each writing and testing codes in separate branches
before pushing the codes and merging with the master branch,
the codes of which are used as the production copy.
Once the codes from a branch are merged into the master branch,
the test on the pipeline with the merged codes are automatically triggered
and the status of the test process will be reported to the developers
(see below).

Fig. 1 Create Jenkins Project

### Create Jenkins Project

[Jenkins](https://jenkins.io/) is an open source automation server
for building, testing and deploying projects. It works in similar ways
as [Travis CI](https://travis-ci.org/) except that the repository
can be from your internal [GitHub](http://github.com) enterprise server
and the tests are done on your own servers.
Here we assume you have a [Jenkins](https://jenkins.io/) server set up
and created an account on the server for you.

To set up your application under development for continuous integration
with [Jenkins](https://jenkins.io/),
the first step is to create a new project (item).
In this specific case,
we created a pipeline (Fig. 1).
You can create other kind of project appropriate for you.

### Configure Jenkins Project

Fig. 2 Set Notification Endpoints

Once a [Jenkins](https://jenkins.io/) project is created, you need to set its configuration.
Some settings described here are just for your reference and
you should set them to fit your case.

#### Check the following and set their parameters

   * Discard Old Builds
      * **Strategy**: Log Rotation
      * **max # of builds to keep**: 6
   * [GitHub](http://github.com) Project
      * **Project url**: http://github.research.chop.edu/BiG/grin/

#### Set Job Notifications

Add two notification endpoints (at job start or job completion) for [Jenkins](https://jenkins.io/) to send out a notice to a web CGI (Fig. 2). The CGI script [jenkinsjobs](#scripts)
can be downloaded from the links listed at the end of the blog.
Of course you need to point URL to your own web server.

   * **Format**: JSON
   * **Protocol**: HTTP
   * **Event**: Job Started **or** Job Completed
   * **URL**: http://mitomapd.research.chop.edu/cgi-bin/jenkinsjobs
   * **Timeout**: 30000(ms)
   * **Log**: -1 (send all log messages)

Fig. 3 Set Build Trigger

Then check the following options and, if needed, set the settings:

   * This build is parameterized (Fig. 3)

      This option is for branch specification.
      * select **String Parameter**
      * define the name of parameter to use (e.g. BRANCH)
      * set the default value (e.g. master)
      * write the description, if needed.
   * Prepare an environment for the run
   * Keep [Jenkins](https://jenkins.io/) Environment Variables
   * Keep [Jenkins](https://jenkins.io/) Build Variables
   * Execute concurrent builds if necessary

#### Build Triggers

Fig. 4 Set Build Trigger

Check **Trigger builds remotely (e.g., from scripts)** and set
**Authentication Token**. The token will be included in the URL
used to trigger the build (Fig. 4).

Please note that here you have the option to set the build to
be triggered by a push to a [GitHub](http://github.com) repository.
But we chose not to use this option because
we wanted to trigger the build
only by a push or merge to the master branch, not just a push to any branches.
The webhook you can set up at [GitHub](http://github.com) doesn't give you
the opiton to specify a specific branch.
(Actually for some unknown causes,
we could not get it to work after half dozen tries
to trigger a build on the [Jenkins](https://jenkins.io/) server
upon a push to the [GitHub](http://github.com) repository.)

#### Pipeline

You can specify how to run your pipeline when the build is triggered.
In our case, we chose to run the pipeline in a [Groovy](http://www.groovy-lang.org/) script
(selected **Pipeline script** and
check the box **Use Groovy Sandbox**) on a specific node, as shown below.

```
node ('respublica-slave') {
    // in Groovy
    stage 'Build'
    sh """
        # cd to the repository directory and check out the specified branch

        git checkout ${BRANCH}
        git pull

        # prepare your environments if necessary

        # our pipeline is coded in a snakefile
        snakemake
    """
}
```

### Create Webhook on Github

On the Github repository page, click **Settings** on the menubar,
then click **Hooks & services** in the left panel followed by clicking
**Add webhook** button at upper right.
On the **Webhoooks / Manage webhook** frame, specify

   * Payload URL: http∶//mitomapd.research.chop.edu/cgi-bin/jenkins?user=zhangs3&branch=master&token=grin_test@chop&url=http∶//jenkins-ops-dbhi.research.chop.edu/view/BiG/job/grin_master/buildWithParameters

     * **user**: the user account under which to run the build on [Jenkins](https://jenkins.io/).
See comments in the script **jenkins** on how to authenticate to the [Jenkins](https://jenkins.io/) server.
     * **branch**: the branch(s) a push of which will trigger the build
for the specified branch
on the [Jenkins](https://jenkins.io/) server.
You can specify more than one branch separated by commas (,) or semicolons (:).
You must sepcify at least one branch.
Here the master branch is specified.
     * **token**: the token from [Jenkins](https://jenkins.io/) project,
as specified in the configuration of the [Jenkins](https://jenkins.io/) project (see Fig. 4).
     * **url**: the URL for remotely triggering the build on [Jenkins](https://jenkins.io/).
Change the server name and the path to your [Jenkins](https://jenkins.io/) project to fit your case.

   * Content type: application/x-www-form-urlencoded

Note that you need to change the server and the path
to the CGI script **jenkins** in the
URL to fit your case. The script [jenkins](#scripts)
can be downloaded from the links listed below.

### CGI Scripts on a Web Server

Click the script names to get them.

   * Script to receive notice from [GitHub](http://github.com) and trigger the build on Jenkins:
[jenkins](https://github.com/spz1st/spz1st.github.io/blob/master/data/ci/jenkins)
   * Script to receive notifications from the [Jenkins](https://jenkins.io/) server and send notifications (Slack/Email):
[jenkinsjobs](https://github.com/spz1st/spz1st.github.io/blob/master/data/ci/jenkinsjobs)

### Acknowledgement

I'd like to thank Jeremy Leipzig
for his input and help
with the implemenation of the CI system
and the preparation of the blog, and thank LeMar Davidson
for his help with debugging the configuration
of the project on the [Jenkins](https://jenkins.io/) server.


text:
SQLean

SQLean (*/s_clean/*) is a simple SQLite database manager built on top of [better-sqlite3](https://www.npmjs.com/package/better-sqlite3) package. It's main purpose is to allow you to focus on writing **code** rather then messing with **queries**.

Working with a database on a low level is a nightmare since you have to convert your data to database format, then to query strings and vice verca.

With SQLean you can easily perform basic operations with database (select, insert, update, delete) passing data as objects and constructing `WHERE` clauses with code constructions instead of mixing strings with data.

SQLean also supports **entity system** allowing you to create relations between TypeScript classes with SQLite columns using modern decorator syntax. With this system you can forget about SQL-stuff at all and work directly with classes and instances, letting SQLean to do all insert, update, select, delete job behind the scenes.

Before you start:

* SQLean is intended to be used in TypeScript projects
* SQLean is synchronous (just as [better-sqlite3](https://www.npmjs.com/package/better-sqlite3))
* SQLean does not protect you from SQL-injections
* SQLean **always** automatically converts `camelCase` (code side) to `snake_case` (db side) and vice verca

## Quick links

1. [Install](#install)
2. [Opening database](#opening-database)
3. [Simple Queries](#simple-queries)
    * [Insert](#insert)
    * [Building `WHERE` clauses](#building-where-clauses)
    * [Select](#select)
    * [Update and Delete](#update-and-delete)
4. [Entity system](#entity-system)
    * [Creating entity](#creating-entity)
    * [Saving and Updating entity](#saving-and-updating-entity)
    * [Retrieving entity](#retrieving-entity)
    * [Deleting entity](#deleting-entity)
5. [Using better-sqlite3](#using-better-sqlite3)

## Install

```console
$ npm i sqlean
```

## Opening database

Let's assume you already have a SQLite database called `data.db` file with columns structure and maybe some data. A typical way  to create such databases is to use something like [DB4S](https://sqlitebrowser.org/).

First of all, we need to open the database file. It must be done before calling any other SQLean methods!

```typescript
import { Db } from "sqlean";

Db.Open('data.db');

// Do stuff with database
// ...

Db.Close(); // Optional. Can be omitted
```

## Simple Queries

The basic idea is simple. You just call a desired static method of `Db` class and pass data object which contains info about table, columns and where clauses.

### Insert

```typescript
let customerData = {
    customerId: 'cmtv',
    firstName: 'Peter',
    //secondName: 'Radko' // Allowed to be null in database
    age: 23,
    isPro: 1 // SQLite does not support Boolean values
};

Db.Insert({
    table: 'customer',
    columnValues: customerData
});
```

| customer_id | first_name | second_name | age | is_pro |
|-------------|------------|-------------|-----|--------|
| cmtv        | Peter      | *NULL*      | 23  | 1      |

### Building `WHERE` clauses

There are three ways to build `WHERE` clauses:

1 - Pure string clause:
```typescript
let where = `@firstName = 'Peter' AND 5 = 2`;

// first_name = 'Peter' AND 5 = 2
```

2 - Single array-clause:
```typescript
let where: WhereClause;

    where = ['@firstName', '=', 'Peter'];
            // WHERE first_name = $param0

    where = [2, '>=', 5];
            // $param0 >= $param1

    where = ['@customerId', 'LIKE', 'c%'];
            // customer_id LIKE $param0
```

3 - Group clauses in which you can combine all three ways:
```typescript
let where = AND(
    ['@firstName', '=', 'Peter'],
    OR(
        ['@customerId', 'LIKE', 'c%'],
        '2 >= 5'
    )
);

// (first_name = $param0) AND ((customer_id LIKE $param1) OR (2 >= 5))
```

There are two important things you should keep in mind.

First of all, everything prefixed with `@` will be converted to `snake_case` and left in query without quotes.

Secondly, notice how strings and numbers are converted into `$paramX` references in array-clauses.
When query run, the values will be automatically injected adding quotes for strings if needed. This works only in array-clauses.

### Select

Selecting one row:

```typescript
let cmtv = Db.Select.Get({
    table: 'customer',
    columns: '*',
    where: ['@firstName', '=', 'Peter']
});
```

```
{ customerId: 'cmtv', firstName: 'Peter', secondName: null, isPro: 1 }
```

Selecting multiple rows:

```typescript
let rows = Db.Select.All({
    table:      'customer',
    columns:    ['customerId', 'age'],
    where:      OR('2 = 2', [3, '>', 20])
});
```

```
[
  { customerId: 'nnagibin', age: 25 },
  { customerId: 'cmtv', age: 23 }
]
```

Notice how came casel column names automatically convert to snake case database column names and vice versa.

Return values can be plucked:

```typescript
Db.Select.All({
    table:      'customer',
    columns:    ['firstName'],
    pluck:      true
});
```

```
[ 'Nicholas', 'Peter' ]
```

### Update and Delete

The `UPDATE` and `DELETE` queries are built the same way we already discovered:

```typescript
Db.Update({
    table:          'customer',
    columnValues:   { firstName: 'Steve'},
    where:          ['@customerId', '=', 'cmtv']
});

Db.Delete({
    table:  'customer',
    where:  ['@customerId', '=', 'cmtv']
});
```

## Entity system

The Entity system utilizes JS decorators and since it is an experimental feature you need to enable them in `tsconfig.json`.
Moreover you also have to enable a feature for correct type casting from db values to class properties.

```json
"compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
}
```

### Creating entity

The entity is just a class extending `Entity` abstract class with some decorators on class and properties:

```typescript
import { Column, Entity, PrimaryKey, Table } from "sqlean"

@Table('customer')
class Customer extends Entity
{
    @PrimaryKey
    @Column
    customerId: string;

    @Column
    firstName: string;

    @Column
    secondName: string;

    @Column
    age: number;

    @Column
    isPro: boolean;
}
```

You can also override `pre/postSave/Delete/Get` methods to run additional queries when entity gets saved, deleted or retrieved from database.

### Saving and Updating entity

Both saving (inserting) and updating entity is done via `save()` method. Calling it cause updating database values. Keep in mind that changing primary key columns will result in creating a new row in column when saving!

```typescript
// Creating entity instance

let cmtv = new Customer;
    cmtv.customerId = 'CMTV';
    cmtv.firstName = 'Peter';
 // cmtv.secondName = 'Radko' // `second_name` column allowed to be null
    cmtv.age = 23;
    cmtv.isPro = true;

// Inserting entity to database

cmtv.save();
```

| customer_id | first_name | second_name | age | is_pro |
|-------------|------------|-------------|-----|--------|
| CMTV        | Peter      | *NULL*      | 23  | 1      |

```typescript
// Updating entity

cmtv.secondName = 'Radko';
cmtv.isPro = false;

cmtv.save();
```

| customer_id | first_name | second_name | age | is_pro |
|-------------|------------|-------------|-----|--------|
| CMTV        | Peter      | Radko       | 23  | 0      |

### Retrieving entity

Use `getById()` static method of your entity class to retrieve rows from database. The return value is an instance of entity class or `null` if no rows were found.

First argument can be a simple value for single primary key or an array of values for multi-column primary keys.
Optional second argument accepts column names to retrieve in case you don't wont to load heavy data from database.

```typescript
let cmtv = Customer.getById('CMTV');

let shortCmtv = Custom.getById('CMTV', ['customerId', 'age']);
```

```
Customer {
  customerId: 'CMTV',
  firstName: 'Peter',
  secondName: 'Radko',
  age: 23,
  isPro: 0
}

Customer { customerId: 'CMTV', age: 23 }
```

### Deleting entity

There are two ways to delete an entity: through its class or directly from instance:

```typescript
Customer.delete('CMTV');

/* OR */

let cmtv = Customer.getById('CMTV');
cmtv.delete();
```

## Using better-sqlite3

If you need to build complex SQL queries or access low-level database settings you can always access [better-sqlite3](https://www.npmjs.com/package/better-sqlite3) database instance directly by accessing `_db` property:

```typescript
import { Db, DB } from "sqlean";

Db.Open('data.db');

DB._db.pragma('cache_size = 32000');
DB._db.pragma('journal_mode = WAL');

DB._db.prepare('CREATE TABLE my_table (my_primary_key INTEGER NOT NULL, my_column TEXT, PRIMARY KEY(my_primary_key))').run();
```

Notice the small difference between `Db` class which is used to access SQLean static methods and `DB` singleton instance!

For more information about `_db` see official better-sqlite3 [docs](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md).

repository: CMTV/sqlean

repo_name: CMTV/sqlean


text:
# Reductions

In this lecture our goal is to develop ways to classify problems according to their computational requirements. We introduce the concept of reduction as a technique for studying the relationship among problems. People use reductions to design algorithms, establish lower bounds, and classify problems in terms of their computational requirements.

![image](../../media/Reductions-image1.jpg)

Desiderata - Something that is needed or wanted

![image](../../media/Reductions-image2.jpg)

![image](../../media/Reductions-image3.jpg)

![image](../../media/Reductions-image4.jpg)

![image](../../media/Reductions-image5.jpg)

![image](../../media/Reductions-image6.jpg)

## Designing Algorithms

![image](../../media/Reductions-image7.jpg)

![image](../../media/Reductions-image8.jpg)

![image](../../media/Reductions-image9.jpg)

![image](../../media/Reductions-image10.jpg)

![image](../../media/Reductions-image11.jpg)

![image](../../media/Reductions-image12.jpg)

SPT Scheduling - Shortest Processing Time Scheduling

![image](../../media/Reductions-image13.jpg)

![image](../../media/Reductions-image14.jpg)

## Establishing Lower Bounds

![image](../../media/Reductions-image15.jpg)

![image](../../media/Reductions-image16.jpg)

![image](../../media/Reductions-image17.jpg)

![image](../../media/Reductions-image18.jpg)

![image](../../media/Reductions-image19.jpg)

![image](../../media/Reductions-image20.jpg)

## Classifying Problems

![image](../../media/Reductions-image21.jpg)

![image](../../media/Reductions-image22.jpg)

![image](../../media/Reductions-image23.jpg)

![image](../../media/Reductions-image24.jpg)

![image](../../media/Reductions-image25.jpg)

![image](../../media/Reductions-image26.jpg)

![image](../../media/Reductions-image27.jpg)

![image](../../media/Reductions-image28.jpg)

![image](../../media/Reductions-image29.jpg)

![image](../../media/Reductions-image30.jpg)

![image](../../media/Reductions-image31.jpg)

![image](../../media/Reductions-image32.jpg)

![image](../../media/Reductions-image33.jpg)


text:
## Maximum Value of a String in an Array
[Leetcode](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array)

The value of an alphanumeric string can be defined as:

The numeric representation of the string in base 10, if it comprises of digits only.

The length of the string, otherwise.

Given an array strs of alphanumeric strings, return the maximum value of any string in strs.

Example 1:

Input: strs = ["alic3","bob","3","4","00000"]
Output: 5
Explanation:
- "alic3" consists of both letters and digits, so its value is its length, i.e. 5.
- "bob" consists only of letters, so its value is also its length, i.e. 3.
- "3" consists only of digits, so its value is its numeric equivalent, i.e. 3.
- "4" also consists only of digits, so its value is 4.
- "00000" consists only of digits, so its value is 0.
Hence, the maximum value is 5, of "alic3".

Example 2:

Input: strs = ["1","01","001","0001"]
Output: 1
Explanation:
Each string in the array has value 1. Hence, we return 1.

Constraints:

1 <= strs.length <= 100

1 <= strs[i].length <= 9

strs[i] consists of only lowercase English letters and digits.

repository: iajaykarthick/Algo-Repertoire

repo_name: iajaykarthick/Algo-Repertoire


text:
# ist-405-dev-wiki

Final Project for IST-405

Downloads:
---

VM: https://www.turnkeylinux.org/lamp
VMWare Player: https://www.vmware.com/products/workstation-player.html

Install Instructions:
---

git clone https://github.com/UsernameError3/ist-405-dev-wiki into /var/www/http/

mysql -u root -p
create database from SQL File, use "devwiki"
Add Table & Mock Data

Open Browser on Local Machine and go the VM's IP Address.

*Currently Broken


text:
---
title: "atom.io: opening a new document"
author: Vegar
layout: post
categories:
  - Development
published: true
date: "2015-03-20 11:46"
---

Opening documents in atom.io, is managed through the [`open` method of the `workspace`](https://atom.io/docs/api/v0.187.0/Workspace#instance-open) object.

To open a new document in atom.io, omit the URI parameter of the open call:

```coffee
{CompositeDisposable} = require 'atom'

module.exports = MyPackage =

    subscriptions: null

    activate: (state) ->
        # Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
        @subscriptions = new CompositeDisposable

        # Register command that toggles this view
        @subscriptions.add atom.commands.add 'atom-workspace', 'my-package:execute': => @execute()

    deactivate: ->
        @subscriptions.dispose()

    execute: ->
        # no URI given
        atom.workspace.open()
```
When saving the document, you will be prompted for a filename.

If you provide a URI to a non-existing file, a new document will be created with that filename. The file is not created before you hit the `save` command. You will not be prompted for filename.

```coffee
execute: ->
    # URI for non-existing URI given
    atom.workspace.open('c:\\temp\\temp.txt')
```

![](/images/2015/03/temp.txt_-_atom.png)

If you do not provide a full URI, just a name, it will use the current projects root folder. If no project is open, you will get a new un-named document.

```coffee
execute: ->
    # relative URI for non-existing file
    atom.workspace.open('newdoc')
```

At this time, this is [undocumented behavior](https://github.com/atom/atom/pull/6005), but hopefully, not for long.


text:
Learn C The Hard Way
=======

Exercise 34
----

Dynamic Array

The Plan
====

Learn about dynamic arrays, a very useful datastructure.

The Code
====

Starting with the header file to implement, then the test, then the implementation.

The Analysis
====

DArray Advantages
====

* Iteration:  You can just use a basic for-loop and ``DArray_count``
  with ``DArray_get``, and you're done.  No special macros needed, and
  it's faster because you aren't walking through pointers.
* Indexing:  You can use ``DArray_get`` and ``DArray_set`` to
  access any element at random, but with a ``List`` you have to go
  through N elements to get to N+1.
* Destroying:  You can just free the struct and the ``contents`` in
  two operations.  A ``List`` requires a series of ``free`` calls
  and walking every element.

DArray Advantages
=====

* Cloning: You can also clone it in just two operations (plus whatever
  it's storing) by copying the struct and ``contents``.  A list
  again requires walking through the whole thing and copying every ``ListNode``
  plus its value.
* Sorting: As you saw, ``List`` is horrible if you need to keep the
  data sorted.  A ``DArray`` opens up a whole class of great sorting
  algorithms, because now you can access elements randomly.
* Large Data: If you need to keep around a lot of data, then a ``DArray``
  wins since its base, ``contents``, takes up less memory than the same
  number of ``ListNode`` structs.

DArray Disadvantages
====

* Insert and remove on the front (what I called shift).  A ``DArray``
  needs special treatment to be able to do this efficiently, and usually it
  has to do some copying.
* Splitting or joining:  A ``List`` can just copy some pointers and
  it's done, but with a ``DArray``, you have copy all of the
  arrays involved.

DArray Disadvantages
====

* Small Data. If you only need to store a few elements, then typically the
  storage will be less in a ``List`` than a generic ``DArray``. This is because
  the ``DArray`` needs to expand the backing store to accommodate future
  inserts, while a ``List`` only makes what it needs.

Breaking It
====

* Forget to check the return value from malloc and then use the buffer.
* Getting the end and start count of the buffer wrong.  Easy to do an off-by-one here.
* Exploit the insert and delete costs to cause a denial of service.

Extra Credit
====

* Improve the unit tests to cover more of the operations, and test them
  using a for-loop to ensure that they work.
* Research what it would take to implement bubble sort and merge sort
  for DArray, but don't do it yet.  I'll be implementing DArray algorithms
  next, so you'll do this then.

Extra Credit
====

* Write some performance tests for common operations and compare them
  to the same operations in ``List``.  You did some of this already, but this
  time, write a unit test that repeatedly does the operation in question, and
  then in the main runner, do the timing.

Extra Credit
====

* Look at how the ``DArray_expand`` is implemented using a constant increase (size + 300).
  Typically, dynamic arrays are implemented with a multiplicative increase (size * 2), but I've
  found this to cost needless memory for no real performance gain.  Test my assertion
  and see when you'd want a multiplicative increase instead of a constant increase.

End Of Lecture 34
=====


text:
Code Formatting & Quality Rules
===============================

## Why?

In order to help reduce cognitive overhead when joining a new project started by another developer, we apply coding standards and formatting to all our code.

If everyone on the team can get on board with a particular style, we can make it easier to pass projects around and contribute to each others work.

## Git Hooks

You can use git hooks in a project to make sure that certain actions are always run before you commit any code. To do this, you need to add a script to a special folder in your git project.

Here is an example:

```
touch .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
```

This creates a new file under `.git/hooks/pre-commit` and then enabled execution on that file.

If you do you the `pre-commit` hook, you will be unable to commit any code unless the script runs with `exit 0`. If there are any exit codes other than `0`, git will block you from committing.

You can see an example of git hooks in use and how to write one using PHP `composer` under our [php-starter](https://github.com/invokemedia/php-starter) repo.

## Tools

The standards outlined here are broken down into 3 groups: formatting, linting, and testing.

**Note**: It seems like the Atom editor can be pretty difficult to configure with some of these tools. You have been warned.

### PHP

PHP has a community suggestions around different coding practices and standard. These are called *PHP Standard Recommendations* or *PSRs*.

#### Formating

Formatting for PHP code should be in the format described in [PSR-2](http://www.php-fig.org/psr/psr-2/). You should install and setup [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer) in your editor of choice and set the tool *to run on save*. You should make sure that the `--standard=PSR2` flag is always used when the command is run.

If you want to run the program from the command line, use the following command:

```
phpcs -n --standard=PSR2 --extensions=php --colors path/to/code
```

There is also a tool called [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) which will actually try and solve the issues for you without you having to do anything. This is akin to auto-formatting your code.

#### Linting

The PHP command line binary has a built-in linter. You can invoke it with `php -l`. By default, the linter does not accept multiple files. You can use the following command to lint a folder of files:

```
find path/to/code/ -name "*.php" -print0 | xargs -0 -n1 -P8 php -l
```

It is recommended that you setup your editor to *lint on save*.

If you want to use a sublime build system, you can use the following setup:

```
{
  "cmd": ["php", "-l", "${file}"],
  "path": "/path/to/php",
  "selector": "source.php,source.html,source.phtml,source.inc"
}
```

An additional optional tool would be [PHP Mess Detector](https://github.com/phpmd/phpmd). A simple command to run on your code would be `phpmd path/to/code text codesize,unusedcode,naming`.

You can setup the `phpmd` build tool in sublime with the following rule:

```
{
  "cmd": ["phpmd", "${file}", "text", "codesize,unusedcode,naming"],
  "path": "${PATH}",
  "selector": "source.php"
}
```

#### Additional Tools

If you are not using an IDE, but are using a text editor like vim, atom, or sublime, then you should consider installing [padawan](https://github.com/padawan-php/padawan.php).

From the docs:

> Padawan.php is an http server that parses your project and gives you completions. Padawan.php looks recursively for all php files of a composer project, parses doc-comments and function declarations of each class and creates an index from them. After that it autoupdates the index and gives you completion as you type.

You can use this tool in lieu of a full IDE.

#### Testing

Testing in PHP is typically done with [phpunit](https://phpunit.de/). Most frameworks have a mechanism for testing. So use the testing protocol outlined by the framework in use.

### Javascript (and JSON)

There are a variety of javascript linting and formatting tools. We will only cover one for each category.

#### Formatting

The first tool to setup is [js-beautify](https://github.com/beautify-web/js-beautify). This tool will format javascript and JSON files to make them easier to read and also easy to debug.

These are the rules for the formatter that Invoke uses:

```
{
  // exposed jsbeautifier options
  "indent_with_tabs": false,
  "preserve_newlines": true,
  "max_preserve_newlines": 4,
  "space_in_paren": false,
  "jslint_happy": false,
  "brace_style": "collapse",
  "keep_array_indentation": false,
  "keep_function_indentation": false,
  "eval_code": false,
  "unescape_strings": false,
  "break_chained_methods": false,
  "e4x": false,
  "wrap_line_length": 0
}
```

You should install the tool as a plugin in your editor and set the formatting to *apply on save*.

#### Linting

The linting tool we use is called [jshint](http://jshint.com/). It is run using the following rules:

```
{
  // Documentation: http://www.jshint.com/docs/options/
  "browser": true,
  "browserify": true,
  "node": true,
  "esnext": true,
  "jquery": true,
  "node": true,
  "globals": {
    "jQuery": true,
    "Vue": true
  },
  "strict": "implied",
  "undef": true,
  "unused": true
}
```

Just like the tools above, you should set this program up in your editor to *run on save*.

You can also add a `.jshintrc` file in your git project and the tool should look for that and use it.

#### Additional Tools

If you are not using an IDE, but are using a text editor like vim, atom, or sublime, then you should consider installing [ternjs](http://ternjs.net/).

Tern is a stand-alone code-analysis engine for JavaScript. It is intended to be used with a code editor plugin to enhance the editor's support for intelligent JavaScript editing. Features provided are:

* Autocompletion on variables and properties
* Function argument hints
* Querying the type of an expression
* Finding the definition of something
* Automatic refactoring

This can be incredibly helpful as you can essentially add IDE-like features to your projects. For example, if you want to use `Array.reduce`, but you forget the arguments, tern can show you the arguments, their types, and also a link to [documentation at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference). It can also infer types for your own functions and methods that exist in your projects.

#### Testing

##### Backend

For unit testing, [node-tap](http://www.node-tap.org/) is extremely simple and easy to get started.

*TODO: other testing types.*

##### Frontend

Our projects that require frontend testing typically use [nightwatchjs](http://nightwatchjs.org/). Nightwatch also allows you to take advantage of the [new headless browsing feature](https://developers.google.com/web/updates/2017/04/headless-chrome) in Chrome >58.

You can also run tests in [phantomjs](http://phantomjs.org/), which doesn't boot up a browser at all. But you should be careful with this as it is not a replacement for a real browser test.

Any frontend tests *should pass in all major browser versions*.

### Editorconfig

[Editorconfig](http://editorconfig.org/) is a cross-platform editor plugin to adjust your editor to handle files in a specific way.

It will look for a file called `.editorconfig` in the root of your project and then apply those settings to the editor.

Here are a set of defaults to use in any `.editorconfig` files:

```
# EditorConfig: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2

# PHP rules
[*.php]
indent_size = 4

[*.md]
trim_trailing_whitespace = false
```

These files should be committed to your git repository.

repository: invokemedia/code-quality

repo_name: invokemedia/code-quality


text:
### `cli/` folder: a `ledger-live` command-line version

> If you are a developer and need to work with latest version, [see this documentation instead](dev-with-cli.md) (typically if you want to test local changes).

**Ledger Live Common** exposes a command line tool (CLI) that can be used to test Ledger Live features in a terminal.

To install it, you will need to have an instance of [Node 12 (LTS)](https://nodejs.org/en/).

You can then install it with

```
npm i -g ledger-live
```

You can now run:

```
ledger-live
```

repository: LedgerHQ/ledger-live-common

branch_name: refs/heads/develop

gha_language: TypeScript

repo_name: LedgerHQ/ledger-live-common


text:
# ROI_Calculator
Return on investment calculator built using Angular 1 and Bootstrap CSS

Clone repo and run `npm install` to get all node dependencies, followed by `npm start` to run your local server.


text:
# Chicago ride-hail surge pricing analysis

Code in support of this post: [Reverse Engineering Ride-Hail Surge Pricing Trends in Chicago](https://toddwschneider.com/posts/chicago-ridehail-surge-pricing/)

## Usage

1. Download and import the TNP trips data file following the instructions in the root directory of this repo
2. Export trips to csv: `psql chicago-taxi-data -f export_trips_to_csv.sql`
3. Assorted R scripts can be run interactively from R terminal. `estimate_historical_surge_pricing.R` should be run first

## Data on Amazon S3

The exact `chicago_trips_20181101_20191231.csv` file I used for my post is available for download from a requester pays Amazon S3 bucket:

https://chicago-ridehail-data.s3.amazonaws.com/chicago_trips_20181101_20191231.csv.gz

The data is from Nov 1, 2018 through Dec 31, 2019, and around 11 GB as an uncompressed csv. [See here](https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html) for instructions on how to download from a requester pays S3 bucket.

## Note about performance and memory usage

The code is generally not optimized for performance or memory footprint. For example, although it uses `data.table::fread()` to read the csv file, it then uses `tidyverse` tibbles and `dplyr` the rest of the way. It would probably improve performance and memory footprint to use `data.table` more extensively. There are also plenty of extra variables that could be omitted. But the easiest solution is to throw more RAM at the problem...

I ran the code on a local machine with 64 GB RAM. If you need more RAM, I'd recommend Louis Astett's [RStudio AWS AMI](http://www.louisaslett.com/RStudio_AMI/). I was able to run the code on an r5.4xlarge EC2 instance. You could also try the [googleComputeEngineR package](https://cloudyr.github.io/googleComputeEngineR/), though I have not personally worked with it.

repository: toddwschneider/chicago-taxi-data

gha_language: R

repo_name: toddwschneider/chicago-taxi-data


text:
# tysserand

Fast and accurate spatial networks reconstruction.

![](./images/tysserand_main_figure.png)

*tysserand* is a Python library to reconstruct spatial networks from spatially resolved omics experiments. It is intended as a common tool where the bioinformatics community can add new methods to reconstruct networks, choose appropriate parameters, clean resulting networks and pipe data to other libraries.
You can find the article and supplementary information on [Bioinformatics](https://doi.org/10.1093/bioinformatics/btab490), and the freely available preprint (same text!) is on [BioRxiv](https://www.biorxiv.org/content/10.1101/2<IP_ADDRESS>5377v2).
A turorial is available [here](./examples/02-tutorial.ipynb)

*tysserand* is fast: it is 50 to more than 120 times faster than PySAL.
*tysserand* is accurate: it implements the best performing methods, tested on simulated and real bioimages.
*tysserand* is user friendly and interactive: it integrates tools to choose appropriate parameters and facilitates the use of napari-based interactive image visualization and network annotation.
*tysserand* is modular and opened to contributions: if you have an idea on how to improve reconstruction methods, create a particular one for a specific case, or make them even faster, join us!

## Installation

Simply do
```bash
pip install tysserand
```
If you want the latest features not published on PyPI run
```bash
pip install git+https://github.com/VeraPancaldiLab/tysserand.git
```

It is best practice to create a dedicated environment for each project.
To do it with pyenv:
```bash
# create environment
pyenv install 3.8.10
pyenv virtualenv 3.8.10 spatial-networks
# add environment to jupyterlab
pyenv activate spatial-networks
ipython kernel install --user --name=spatial-networks
```
or with Conda and Mamba:
```bash
# create environment
conda install mamba -n base -c conda-forge
mamba env create --file environment.yml
# add environment to jupyterlab
conda activate spatial-networks
ipython kernel install --user --name=spatial-networks
```
If you want to reproduce results in the publication, install also PySAL
```bash
pip install libpysal geopandas fiona shapely pyproj rtree
```

## Implemented methods

![Set of nodes](./images/publication_figures/mIF-nodes_positions.png)

### Delaunay triangulation

This method builds virtual cells centered arround each node and contacting each other to fully tile the space occupyied by the nodes. Edges are drawn between the nodes of contacting tiles.

![Edge lengths with *Delaunay* reconstruction](./images/publication_figures/mIF-Delaunay_distances.png)
![Trimmed network](./images/publication_figures/mIF-Delaunay_network.png)
![Network overlay on original tissue image](./images/publication_figures/mIF-Delaunay_superimposed.png)

### k-nearest neighbors

Each node is linked with its k nearest neighbors. It is the most common method used in single cell publications, althought it produces artifacts well visible on simple 2D networks.

![Edge lengths with *k-nearest neighbors* reconstruction](./images/publication_figures/mIF-knn_distances.png)

### radial distance neighbors

Each node is linked to nodes closer than a threshold distance D, that is to say each node is linked to all nodes in a circle of radius D.

![Edge lengths with *radial distance neighbors* reconstruction](./images/publication_figures/mIF-rdn_distances.png)

### Area contact

Nodes are the center of detected objects (like after cell segmentation) and they are linked if their respective areas are in contact or closer than a given distance threshold.
A parallelized version is implemented with the Dask library.

![*Contacting areas* reconstruction](./images/publication_figures/simulated_segmentation_image_size-600_hole_proba-0.1_noise_sigma-10.0_objects_network.png)

### Area contact *and* k-nearest neighbors

Areas are linked if they are in contact or closer than a given distance. Then, the remaining non connected areas are connected with their nearest neighbors.

repository: ComplexData/tysserand

repo_name: ComplexData/tysserand


text:
# Contributing Guidelines

## Setup

-   Fork Repository.

-   Clone Repository.

-   Setup [Metamask](https://metamask.io/) and enter the account mnemonic on the Contribute Page.

## Contributing

-   Have a look at the open issues. Pick an unassigned issue or create one.

-   Create a new branch and make changes.

-   Send a Pull Request after making changes.


text:
# kvdroid

**This project is experimental and not actively maintained.**

kvdroid is a simple experimental distributed key-value store in memory. It's primary purpose is to store large byte arrays chunked between multiple kvdroid-server instances and allow (userspace) zero-copy reads in client.

Features:
- type-safe client API (value types are []byte and Uint32 only)
- clients ring API with consistent hashing

Missing features:
- client pool
- high level API to manage byte array chunking

## Server set up

Clone the repo and build the server:
```
$ git clone https://github.com/JCapul/kvdroid
$ cd kvdroid
$ make
```
This will produce the executables ```kvdroid-server``` and ```kvdroid-stop``` in the build/bin directory.

To launch the server on localhost and default port (8001):
```
$ build/bin/kvdroid-server
```
Launch a daemonized server:
```
$ build/bin/kvdroid-server -daemonize
```
To stop the server:
```
$ build/bin/kvdroid-stop
```

## Client API basics

Get the go package:
```
$ go get github.com/JCapul/kvdroid
```

Create a client:
```golang
package main

import "github.com/JCapul/kvdroid"

func main() {
    kvdroid := kvdroid.NewClient([]byte(":8001")
```

Use ```SetBytes``` and ```GetBytes``` to store bytes.
```
    kvdroid.SetBytes("foo", []byte("bar"))
    b, err := kvdroid.GetBytes("foo")
    ...
```
Use ```GetBytesInto``` to read bytes directly into a user-defined byte slice, the call returns the number of bytes read:
```
    dst := make([]byte, 20, 20)
    n, err = client.GetBytesInto("foo", recv)
```

A set of API calls handle range of bytes similar to Redis SETRANGE/GETRANGE commands: ```SetBytesRange```, ```GetBytesRange```, ```SetBytesRangeInto```.

repository: JCapul/kvdroid

repo_name: JCapul/kvdroid


text:
# [RFMAN - RFID Admin Helpdesk] using- [SB Admin 2](http://startbootstrap.com/template-overviews/sb-admin-2/)
[![CDNJS](https://img.shields.io/cdnjs/v/startbootstrap-sb-admin-2.svg)](https://cdnjs.com/libraries/startbootstrap-sb-admin-2)

[SB Admin 2](http://startbootstrap.com/template-overviews/sb-admin-2/) is an open source, admin dashboard template for [Bootstrap](http://getbootstrap.com/) created by [Start Bootstrap](http://startbootstrap.com/).

## Creator RFMAN
* http://github.com/joisandresky
* http://instagram.com/dat_joee

## Creator SB Admin

Start Bootstrap was created by and is maintained by **[David Miller](http://davidmiller.io/)**, Owner of [Blackrock Digital](http://blackrockdigital.io/).

* https://twitter.com/davidmillerskt
* https://github.com/davidtmiller

Start Bootstrap is based on the [Bootstrap](http://getbootstrap.com/) framework created by [Mark Otto](https://twitter.com/mdo) and [Jacob Thorton](https://twitter.com/fat).

## Copyright and License
Copyright 2017-Now STMIK Bani Saleh.
Copyright 2013-2016 Blackrock Digital LLC. Code released under the [MIT](https://github.com/BlackrockDigital/startbootstrap-sb-admin-2/blob/gh-pages/LICENSE) license.

repository: joisandresky/rfman

repo_name: joisandresky/rfman


text:
Import SolidWorks model example (demo_PY_import_solidworks.cpp)  {#tutorial_demo_import_solidworks}
==========================

Learn how you can use few C++ lines of code to
load a mechanism that you exported from SolidWorks.

This tutorial shows how to:

- load a SolidWorks mechanism into Chrono::Engine
- retrieve pointers to SolidWorks exported parts, given their name
- show a realtime simulation with Irrlicht

\include demo_PY_import_solidworks.cpp