text:
Handgrip: Enable generator helpers for Handlebars
=======

Handgrip is a simple wrapper the enables the use of generator  inside normal [Handelbars][handlebars] helper.

In addition to supporting generator functions, Handgrip keeps the order of executing generator helpers as you write them on template.

[![Build Status][travis-badge]][travis-url]
[![NPM version][npm-badge]][npm-package]
[![License][license-badge]][license]

Best suited/tested with [Koa][koa] or [co][co].

## Install
```javascript
$ npm install handgrip
```

## Generator Helpers
This is an example of basic usage of generator helper.
Return a generator function with `next` as the single argument, just like [Koa’s middleware][middleware.gif].
`yield next` tells Handgrip to continue parsing the rest of the template.

```javascript
var hbs = require("handgrip");
var request = require("co-request");

hbs.registerGeneratorHelper("ip", function() {
	return function *(next) {
		var ip = yield request("http://canihazip/s");

		yield next;

		return new hbs.SafeString(ip);
	};
});
```

Another interesting example of generator helper is to create composable component with Handgrip/Handlebars helpers.
Here, a CSS declaration helper will keep tracks of all component CSS on this page.

```html
<!doctype html>
<html>
<head>
{{css "bootstrap"}}
</head>

<body>
<nav>...</nav>
{{component "list"}}
{{component "carousel"}}
</body>
</html>
```

```javascript
var hbs = require("handgrip");

hbs.registerGeneratorHelper({
	// gathering all component CSS and write it in <head>
	css: function(name) {
		this._CSS = name.split(",");

		return function*(next) {
			yield next;

			var css = this._CSS.reduce(function(a, b) {
				return a + '<link href="' + b + '" rel="stylesheet" />';
			}, "");

			return new hbs.SafeString( css );
		};
	},
	// run component logic and
	// report its CSS
	component: function(name) {
		return function *(next) {
			this._CSS = this._CSS || [];
			if (name) this._CSS.push(name);

			// insert your magic here
			...
			yield next;

			return new hbs.SafeString( ... );
		}
	}
});
```

Nested generator helper is also supported. Checkout `test/` folder to see more example on that.

## Normal Helpers
`registerGeneratorHelper` does support normal Handlebars helper as well, just like using the plain Handlebars. Here is an example of registered multiple helper

```javascript
var hbs = require("handgrip");
var request = require("co-request");

hbs.registerGeneratorHelper({
	hello: function(name) {
		var out = '<b>' + name + '</b> says hello.';

		return new hbs.SafeString(out);
	},
	ip: function() {
		return function *(next) {
			var ip = yield request("http://canihazip/s");

			yield next;

			return new hbs.SafeString(ip);
		}
	}
});
```

## Compiling
#### Compile template string

```javascript
var handgrip = require("handgrip");

var tpl = handgrip.render(template, options);
var body = yield tpl(data);
```

`Handgrip.render` accepts the same parameters and `Handlebars.compile` and returns a generator function.

#### Convert Handblebars compiled `templateFn` to a Handgrip-compatible one

```javascript
var handlebars = require("handlebars");
var handgrip = require("handgrip");

// create a compile templateFn
// You could use handgrip.compile(...) as well
var tpl = handlebars.compile(template);

// convert to to Handgrip-compatible
var renderer = Handgrip.createRenderer(tpl);
var body = yield renderer(data);
```

`Handgrip.compile` is the same as `Handlebars.compile`.

## Implementaion and caveats (Must-see for layout users)
Handgrip keeps an array of generator functions for each `render` job.

When Handlebars finishes parsing the template, it replaces those generator helper with placeholder of UUIDs. Then Handgrip begins parsing the generator array and mutate the array as new generator helpers are found, finally Handgrip fills the results back to their corresponding places.

The common way of implementing layout (as found in [express-hbs][express-hbs] and [koa-hbs][koa-hbs]) is to render the template as string, then create another separate rendering process for layout. Unfornately, this trivial approach is not feasbile with the implementation of Handgrip, since splitting the rendering process means losing track of generator helpers in main template.

However, there is also an easy way of implementing layout with Handgrip.

Layout template:
```html
<!doctype html>
<html>
<head>
{{css}}
{{js}}
...
</head>
<body>
{{__body__}}
</body>
</html>
```

Main template:
```html
{{registerCSS "foo"}}
{{registerJS "bar"}}
{{pageTitle}}

{{#layout "layoutName"}}
	<!-- your content goes here -->
	...
{{/layout}}

```

Layout helper (JS):
```javascript
var hbs = require("handgrip");
hbs.registerHelper("layout", layout);

function layout(layoutName, options) {
	this.__body__ = options.fn.bind(null, this);

	// read layout file into template string
	var layoutTpl = findByName(layoutName);
	// this is the same as handlebars.compile(...)
	return hbs.compile(layoutTpl, this);
}
```

## Build
This is normally used on the server side, so there is no minified version (yet).

## Tests
Tested on

- Handlebars: 2.0.2, 3.0.3, 4.0.5
- co: 3.0+, 4.0+
- Node: 0.11.14, 4.4.x, 5.x, 6.x
- iojs: 1.0.2 or higher

Run the test

```bash
$ npm install
$ npm test
```

## License
Copyright (c) 2015 Jingwei "John" Liu

Licensed under the MIT license.

[koa]: https://github.com/koajs/koa/
[middleware.gif]: https://raw.githubusercontent.com/koajs/koa/master/docs/middleware.gif
[handlebars]: http://handlebarsjs.com
[co]: https://github.com/tj/co
[koa-hbs]: https://github.com/jwilm/koa-hbs
[express-hbs]: https://github.com/barc/express-hbs
[travis-badge]: https://img.shields.io/travis/th507/handgrip.svg?style=flat-square
[npm-badge]: https://img.shields.io/npm/v/handgrip.svg?style=flat-square
[license-badge]: http://img.shields.io/npm/l/handgrip.svg?style=flat-square
[travis-url]: https://travis-ci.org/th507/handgrip
[npm-package]: https://www.npmjs.com/package/handgrip
[license]: LICENSE


text:
## 0.4.0
* **(!!)** Queries now return a ResultSet object instead of a Dart list. Use `ResultSet.allResults` to get the previous behaviour.
* **(!!)** Renamed Document `jsonProperties` setter/getter to `json`
* **(+)** Document constructor's `data` accepts `FLValue`, a json string or json-encodable object as input
* **(+)** Documents now can hold a reference to the database and have `save`, `delete`, `expiration` methods
* **(+)** `FLArray` has two new constructors `fromList` and `fromJson`
* **(+)** `FLDict` has two new constructors `fromMap` and `fromJson`
* **(+)** `FLArray` and `FLDict` support keypath accessor similar to `FLValue` as `FLArray()` and `FLDict()`. Normal key access using `[]` is unchanged.
* **(+)** Implemented `CBLLog` class to manage messages that Couchbase Lite logs at runtime. Ability to control the `domain` and `level` of messages logged to either the `console`, `file` or a `callback` registered by the application.
* Fix mutable document's nested properties not being mutable
* Clean up listeners and other C callbacks implementation
* Fix database and document listeners on Android
* Fix blob `getContent` not returning the correct value
* Added tests for `Document`, `Blob` and the `Fleece` classes
* Lots of fixes and improvements in code structure and documentation

## 0.3.1
* Fix query parameter setter

## 0.3.0
* Added stream based API for Blobs
* Replicator conflict resolver
* Add keypath support for FLDict
* Fix FLDictEntryIterator not returning keys as strings
* Fix new document properties not being initialized
* Fix the way dll is included

## 0.2.0
*  **Blobs** - Added basic support for blobs
* Improve Document properties API
* Allow queries to be written as multiline strings
* Fix crash when updating already existing property of document
* Fix crash on Android when creating replicator
* Fix (live) queries not being released when removing change listeners

## 0.1.0+2
 * Moved the ffi bindings into their own library to improve the documetntation generated by dartdoc.

## 0.1.0
* **Database:** Open, Close, Copy, Compact, Delete, Batch operations, Change notifications, document change notifications, Buffered notifications
* **Document**
    CRUD - Create, Read, Udpdate, Delete, Save conflict handler, Document expiration, with automatic purge
    Fleece API for direct access to the binary data
* **Queries**
    [N1QL](https://www.couchbase.com/products/n1ql) query language, Query parameters, Explain, "Live queries" - change listener
* **Replication**
    Authentication: Basic and Session based, Pull/push filters, channels, Status listeners

branch_name: refs/heads/master

extension: md

gha_language: Dart

license_type: permissive


text:
---
date: 2018-08-05T04:32:25+02:00
title: Getting started
---

Let's setup your Planet Lia environment for Bounce Evasion game.

## 1. Download

* **Download Planet Lia CLI** for your operating system and unzip it into a folder of your liking. The tool is portable so you don't need to install it.
    * Windows
    * Linux
    * macOS
* Install Java on your system. Bounce Evasion game is written in Java and it needs it in order to run. On most system it is already installed.
* Setup programming language that you will use for writing your bot.
If you have used the language before, you most likely already have everything that you need.

## 2. Play a game

Open up a **Cmd.exe** or **PowerShell.exe** on Windows or a **Terminal** on Linux or macOS, **move to the unzipped Planet Lia CLI** directory and run the commands below.
First we will download the Bounce Evasion game and set it as our default game.
Then we will create a new starting bot `john` using programming language Java and will battle it against itself.
To choose a different language for your bot simply replace the ```java``` part of the first command with ```python3``` or ```kotlin```.
The first time you play a match with your bot it may take some time as a couple of libraries need to be downloaded, later runs will be much faster.

{{< multilang >}}

    <button class="tablinks tc1 active" onclick="changeLanguage(event, 'Cmd', 'tc1', 'cc1')">Windows cmd</button>
    <button class="tablinks tc1" onclick="changeLanguage(event, 'PowerShell', 'tc1', 'cc1')">Windows PowerShell</button>
    <button class="tablinks tc1" onclick="changeLanguage(event, 'Terminal', 'tc1', 'cc1')">Linux/macOS</button>

{{< highlight cmd >}}
lia.exe game download bounce-evasion
lia.exe game set bounce-evasion
lia.exe bot new java john
lia.exe play john john
{{< /highlight >}}

{{< highlight powershell >}}
.\lia.exe game download bounce-evasion
.\lia.exe game set bounce-evasion
.\lia.exe bot new java john
.\lia.exe play john john
{{< /highlight >}}

{{< highlight bash >}}
./lia game download bounce-evasion
./lia game set bounce-evasion
./lia bot new java john
./lia play john john
{{< /highlight >}}

After running the commands above, wait until the match is generated and voila, a browser window is opened displaying a replay of the generated match!
Also a new directory named `john` is created in your current working directory.
This directory contains all the code for your bot. We will dig into it in the next section.

## 3. Understand your bot

With your favorite text editor open up your bot's main file. If you have created `Java` bot then open up `john/src/MyBot.java`, if `Python3` then `john/my_bot.py` and if `Kotlin` then `john/src/MyBot.kt`.
You can also open the whole bot directory (eg. `john`) in an IDE. Check Using an IDE example to learn more.

**Read through the code to see how it works! If you need help, check out our API.**

Note that during the development you can structure your bot directory as you like, as long as the `MyBot` file acts as your "main" file.
This means that you can create additional files which you then import into `MyBot`.
To delete a bot, simply delete it's directory, in our case the directory named `john`.

## 4. Debug your bot

A more detail guide on how to debug your bot using a step debugger integrated into your favourite IDE, is available [here](/examples/debugging-your-code).

Note if you use the `-d` flag with `play` command (eg. `lia.exe play -d john john`), you can **get a very useful debug view** while the match is generating, as shown below.
It will let you to pause the match generation, step through it, view details of game entities, API calls and more.

## 5. Generate many matches at once

You can generate multiple matches using `-n` flag with `play` command as shown below.
By providing a number after `-n` flag you can specify how many matches you want to generate.
This is really useful for comparing quality of two bots as the end result also prints out the number of times each bot has won.

{{< multilang >}}

    <button class="tablinks tc2 active" onclick="changeLanguage(event, 'Cmd2', 'tc2', 'cc2')">Windows cmd</button>
    <button class="tablinks tc2" onclick="changeLanguage(event, 'PowerShell2', 'tc2', 'cc2')">Windows PowerShell</button>
    <button class="tablinks tc2" onclick="changeLanguage(event, 'Terminal2', 'tc2', 'cc2')">Linux/macOS</button>

{{< highlight cmd >}}
lia.exe play -n 20 john john
{{< /highlight >}}

{{< highlight powershell >}}
.\lia.exe play -n 20 john john
{{< /highlight >}}

{{< highlight bash >}}
./lia play -n 20 john john
{{< /highlight >}}

## Next up

Check out the game rules.

Next: **[Game rules](/game-rules)**

----

### Related:

* [Game rules](/game-rules)
* [API reference](/api/)

repository: planet-lia/bounce-evasion-docs

repo_name: planet-lia/bounce-evasion-docs


text:
---
layout: default
---

# 1995-12-22 - Re: ex encrypted script

## Header Data

From: "Beavis B. Thoopit"<EMAIL_ADDRESS>To<EMAIL_ADDRESS>(Jason Rentz)

Message Hash: 5140ab99727f557231e94aedb3ae9ff4de3be5b9b38c802dd9b4ac0763775557

Message ID<EMAIL_ADDRESS>Reply To<EMAIL_ADDRESS>UTC Datetime: 1995-12-22 03:59:25 UTC

Raw Date: Thu, 21 Dec 95 19:59:25 PST

## Raw message

```
{% raw  %}From: "Beavis B. Thoopit"<EMAIL_ADDRESS>Date: Thu, 21 Dec 95 19:59:25 PST
To<EMAIL_ADDRESS>(Jason Rentz)
Subject: Re: ex encrypted script
In-Reply-To<EMAIL_ADDRESS>Message-ID<EMAIL_ADDRESS>MIME-Version: 1.0
Content-Type: text/plain

> >| Is there a way to encrypt a script yet still allow it to be runnable?  I
> >| know that the simple answer is to write it in C and compile it but I don't
> >| have the means of doing that at the moment.  (i.e. there is not compiler on
> >| the system)
> >|
> >| I thought of a few simple protections but they all involve decrypting before
> >| running.
> >
> >	Ever hear of chmod?  chown?
> >Adam
>
> The vendor also has superuser access..  chmod chown won't protect it.. :(

I once had to obfuscate an awk script.  "Cryptography is Economics."  My
job was to make it difficult for the enemy to steal the source.  There
was a license agreement...

The simple answer of "no" is right in the strong sense, but there are
tricks to make life difficult for the amateur attacker.

My approach was a self-decrypting program.  The "real" script was
encrypted within the body of the encasing script.  For increased
obfuscation, decrypt only small pieces at a time.

{% endraw %}
```

## Thread

+ Return to [December 1995](/archive/1995/12)

+ Return to<EMAIL_ADDRESS>(Jason Rentz)](/authors/andr0id_at_midwest_net_jason_rentz_)"
+ Return to "["Beavis B. Thoopit" <beavis@bioanalytical.com>](/authors/beavis_b_thoopit_beavis_at_bioanalytical_com_)"
+ Return to<EMAIL_ADDRESS>(Dr. Frederick B. Cohen)](/authors/fc_at_all_net_dr_frederick_b_cohen_)"

+ 1995-12-21 (Thu, 21 Dec 95 12:25:51 PST) - [Re: ex encrypted script](/archive/1995/12/2bf46688a16d1a80b8756f2f9772f807b3603c4a725e57c67fa7dcbab389c5b8) -<EMAIL_ADDRESS>(Jason Rentz)_
  + 1995-12-22 (Thu, 21 Dec 95 19:59:25 PST) - Re: ex encrypted script - _"Beavis B. Thoopit"<EMAIL_ADDRESS>    + 1995-12-22 (Fri, 22 Dec 95 03:51:43 PST) - [Re: ex encrypted script](/archive/1995/12/4a32975266abf26da2e220d9979021d6ce76c3abbe86a370b1f4af1ef19f8559) -<EMAIL_ADDRESS>(Dr. Frederick B. Cohen)_

license: MIT

gha_license_id: MIT


text:
# Contributing

Fork the repo at https://github.com/impact-crater/impact-crater-core

## Branches
Use [git flow](http://nvie.com/posts/a-successful-git-branching-model/).

What's on ```master``` should always be published on npm. ```dev``` should contain what will be the next version of impact-crater.

New functionality/massive refactoring should occur in a feature branch.

Even if you have commit priveliges please commit and open pull requests for your branch so we can test/discuss things rather than committing straight to the repo.

repository: impact-crater/impact-crater-core

gha_language: JavaScript

repo_name: impact-crater/impact-crater-core


text:
# delphi-library-helper

[![Join the chat at https://gitter.im/delphi-library-helper/Lobby](https://badges.gitter.im/delphi-library-helper/Lobby.svg)](https://gitter.im/delphi-library-helper/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Delphi Library Helper - Tool to assist Delphi developers configuring library folders.

Installation Downloads
http://www.littleearthsolutions.net/?page_id=99

repository: progray/delphi-library-helper

repo_name: progray/delphi-library-helper


text:
---
layout: post
title: Arc Framework: Runthrough and Loose Ends
tags:
- arc
---

Today I'll be talking about [arc](https://github.com/ArcaneIngenuity/arc), which is the basis for War & Adventure. This will only be of interest to developers and techish sorts; others will have to wait until tomorrow when I'll post some visuals of engine work to date.

Working back toward visuals
---------------------------

I'm in a stage of heavy code refactoring at the moment. Visuals are almost all down, except for an item or two needed for testing. Here's why.

Arc is an open source framework I've written over the last few years to ease game development while keeping the developer close to the metal. Over the last few months I've ported it to C and improved it further to meet the task of implementing War & Adventure. Let's just jump in at the deep end.

Arc, as a real-time MVC framework, benefits us by its flexible configuration system. An ordinary `arc.config`, without user `Extension`s, might be so:

```

<?xml version="1.0"?>
<hub>
	<apps>
		<app class="AWarAdventure" id="WA">
			<model class="MRoot">
			</model>
			<view class="VRoot" id="root">
				...
				<view class="VMenu" id="menu">
					...
				</view>
				<view class="VPlayArea" id="play">
					<view class="VBeltBar" id="belt">
					</view>
				</view>
			</view>
			<ctrl class="CRoot" id="root">
				<ctrl class="CInput" id="input" model="&.input"/>
			</ctrl>
		</app>
	</apps>
</hub>

```

You can see the `<app/>` element which contains basic structure for this app. This allows us to review our app skeleton at a glance, noting how its various components tie together. Every `View` may contain sub-`View`s, forming a tree rooted on the `App`, and even `Ctrl`s (controllers) may optionally contain sub-`Ctrl`s. You can easily get away with just one root `Ctrl` e.g. just use `CRoot` per the above, while tying into your own  helper classes which needn't be implemented as `Ctrl`s. The benefit of implementing `CInput` as a `Ctrl` here is that I can handle input via a recognisable interface `Updater` which is the basis for `Ctrl`s and `View`s. As one becomes more familiar with arc, this interface becomes desirable to work with.

The real power in `arc.config` comes from its ability to include user-written `Extension`s via a very simple interface. Let's take another look at the XML, this time filling in contents of the `VRoot` and `VMenu` from the last example:

```

			<view class="VRoot" id="root">
				<extension class="XShaderLoader" id="shaderLoader">
					<shaders>
						<shader id="ui.vert" type="vertex"/>
						<shader id="ui.frag" type="fragment"/>
						<shader id="eye.vert" type="vertex"/>
						<shader id="eye.frag" type="fragment"/>
						<shader id="billboard.vert" type="vertex"/>
						<shader id="billboard.frag" type="fragment"/>
					</shaders>
					<programs>
						...
					</programs>
				</extension>
				<view class="VMenu" id="menu">
					<extension class="XUniformMap" id="uniformsByName">
						<uniforms>
							<uniform name="offset"
								model="&.position"
								type="UniformVector"
								typeNumeric="UniformFloat"
								componentsMajor="3"
								componentsMinor="0"
								elements="1">
							</uniform>
						</uniforms>
					</extension>
				</view>
				...
			</view>

```

See how the body of `<view>` `VRoot` is now an `<extension>`, and similar for `VMenu`? The `<extension>` as such is not part of the arc framework, but rather a user-created element that implements the `Extension` interface specified by arc, allowing arc to recognise an `Extension`, parse it, and slot it into its containing `View`. Now `VRoot` (the `View` in question) has runtime access to our custom `XShaderLoader` instance, while `VMenu` similarly has access to the `XUniformMap`. And since `VRoot` is the parent / container of `VMenu`, `VMenu` can also access its parent's shader information.... useful.

Extensions allow for user-written, easily-configurable code (instances) to be included in the otherwise limited MVC setup we saw in the first example.

This is where the real power of arc lies - write less code while having a better overview of the app. Rather than having discrete source (and header) files scattered all over the show, `arc.config` offers an architectural overview of your application, at a glance. ("arc" is short for "architecture".)

Why am I telling you all this? Well, have look here:

```
<ctrl class="CInput" id="input" model="&.general.input" />
...
<uniform name="offset"
	values="&.position"
	type="UniformVector"
	typeNumeric="UniformFloat"
	componentsMajor="3"
	componentsMinor="0"
	elements="1">
```

Both of these have something that looks like `&.<name>.<other name>` in them. This is a way to drill down through struct/class members and get a reference to some data we need to use,

 * in the 1st case as the base model used by a particular `Ctrl`,
 * in the 2nd case as the value to source an OpenGL uniform variable from, within the user extension known as `XUniformMap`.

At the moment, arc doesn't allow the second case. In the JavaScript version of arc this was trivial, but in C less so because C has no runtime type (member) information. Fortunately the majority of the groundwork has already been laid. I'm tweaking today and over the weekend to enable this.

In closing...
-------------

As I'm deep in this refactoring process at the moment, visuals are offline. Tomorrow I will get an older version of the framework/engine running just to show you fundamentals from earlier in October before I began blogging.


text:
# Space Impact

Author: Dhruv Agrawal

---

## Project Idea:

 For this project, I plan on replicating [Space Impact](https://www.youtube.com/watch?v=Oc5EoSdWZQo&feature=youtu.be),
 a game in older models of Nokia phones. It is similar to [Space Invaders](https://en.wikipedia.org/wiki/Space_Invaders)
 but occurs in horizontal space, thus taking gravity into account. I want to work on this project because growing up,
 I played **Space Invaders** a lot and this seems like a nice twist to it.

 ![GamePlay](https://cdn.toucharcade.com/wp-content/uploads/2013/04/mzl.ygudvigj.640x960-75-525x350.jpg)

## Functionality:

### Basic Gameplay:

 * A status bar at the top with the number of lives left and the current score.
 * A spaceship representing the user.
 * Enemy bots that kill the user on coming in contact.
 * A control key to shoot ammo
 * Arrow keys to help the user dodge the enemies.
 * A leaderboard when the game ends.

### Stretch Features:

 * A mini boss that takes more number of bullets to kill and can shoot back.
 * Conversion of enemy bots into collectible coins when killed.

## Rough Timeline

### Week 1:

 * Come up with the basic code organization.
 * Create classes for the user's spaceship and enemy bots.

### Week 2:

 * Set up the game engine with the status bar.
 * Write code to make the user's spaceship shoot ammo.

### Week 3:

 * Add enemy bots to the game using a similar logic to the spaceship.
 * Keep track of the user's score and add a leaderboard.

## Libraries:

 * [Cinder](https://libcinder.org): For creating the application, 2D graphics, and most functionality.
 * [Box2D](https://github.com/cinder/Cinder/tree/master/blocks/Box2D): For the game physics.
 * [SQLite](http://www.sqlite.org): For database management.


text:
TLS - what can go wrong?
========================

Key generation

 * [Debian weak keys](https://wiki.debian.org/SSLkeys)
 * [ROCA](https://crocs.fi.muni.cz/public/papers/rsa_ccs17)
 * Shared prime factors ([mining ps and qs](https://factorable.net/))
 * Shared non-private keys (e.g. using default keys shipped with applications)

RSA encryption handshake

 * [Bleichenbacher](http://archiv.infsec.ethz.ch/education/fs08/secsem/bleichenbacher98.pdf), [Klima](https://eprint.iacr.org/2003/052), [ROBOT](https://robotattack.org/) etc. attacks
 * SSLv2 Bleichenbacher attack ([DROWN](https://drownattack.com/))

RSA signature handshake

 * [RSA-CRT bug](https://securityblog.redhat.com/2015/09/02/factoring-rsa-keys-with-tls-perfect-forward-secrecy/) / modexp miscalculation (signature generation)
 * [Bleichenbacher signature forgery](https://www.ietf.org/mail-archive/web/openpgp/current/msg00999.html), [BERserk](http://www.c7zero.info/stuff/BERserk_eko10.pdf) (signature verification)

ECDSA / DSA handshake

 * Duplicate r (not found in the wild yet)

Static DH/ECDH handshake

 * [KCI](https://kcitls.org/)

Diffie Hellman

 * [Backdoor parameters](https://eprint.iacr.org/2016/644), some detectable (e.g. non-prime modulus), others not
 * [Logjam](https://weakdh.org/) (paper describes multiple attacks), too small parameters
 * [Ephemeral key reuse with small subgroup parameters](https://www.openssl.org/news/secadv/20160128.txt)
 * [DH/ECDH parameter confusion](https://www.cosic.esat.kuleuven.be/publications/article-2216.ps)

ECDHE

 * [Curveswap](https://eprint.iacr.org/2018/298.pdf)
 * [Invalid Curve attack](https://web-in-security.blogspot.com/2015/09/practical-invalid-curve-attacks.html) / ephemeral key reuse

Finished message

 * Lack of check, also partial lack of check, [Poodle has friends](https://yngve.vivaldi.net/2015/07/14/the-poodle-has-friends/)

CBC/HMAC

 * [BEAST](https://www.youtube.com/watch?v=-BjpkHCeqU0)
 * [Vaudenay's Padding Oracle](https://iacr.org/archive/eurocrypt2002/23320530/cbc02_e02d.ps) (impractical due to encrypted error messages)
 * [Canvel's timing oracle](https://www.iacr.org/cryptodb/archive/2003/CRYPTO/1069/1069.pdf)
 * [Lucky Thirteen](http://www.isg.rhul.ac.uk/tls/Lucky13.html), [Lucky Microseconds](https://eprint.iacr.org/2015/1129)
 * [LuckyMinus20](https://web-in-security.blogspot.com/2016/05/curious-padding-oracle-in-openssl-cve.html) (CVE-2016-2107)
 * [POODLE](https://www.openssl.org/~bodo/ssl-poodle.pdf) (SSLv3)
 * Lack of padding check in TLS 1.0 and later ([POODLE-TLS](https://www.imperialviolet.org/2014/12/08/poodleagain.html))
 * Partial padding checks, [More POODLEs in the forest](https://yngve.vivaldi.net/2015/07/14/there-are-more-poodles-in-the-forest/)
 * MACE / Lack of HMAC check, also partial checks [Poodle has friends](https://yngve.vivaldi.net/2015/07/14/the-poodle-has-friends/)

GCM

 * Duplicate or random nonces ([Forbidden attack](http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/Joux_comments.pdf), [Nonce-disrespecting adversaries](https://github.com/nonce-disrespect/nonce-disrespect))
 * Lack of ghash check (not found in the wild yet)

Small block size

 * [Sweet32](https://sweet32.info/)

RC4

 * [RC4 Biases](http://www.isg.rhul.ac.uk/tls/), cipher design problem, unfixable

Compression

 * [CRIME](https://en.wikipedia.org/wiki/CRIME) (TLS compression)
 * [BREACH](http://breachattack.com/) (HTTP compression)
 * [TIME](https://www.blackhat.com/eu-13/briefings.html#Beery), [HEIST](https://www.blackhat.com/us-16/briefings/schedule/#heist-http-encrypted-information-can-be-stolen-through-tcp-windows-3379) (TCP window trick, Javascript, timing + HTTP compression)

State machine errors

 * [SMACK](https://mitls.org/pages/attacks/SMACK), SkipTLS
 * [FREAK](https://censys.io/blog/freak)
 * [CCS Injection](http://ccsinjection.lepidum.co.jp/)

HTTP/HTTPS related

 * [SSL Stripping](https://moxie.org/software/sslstrip/)
 * Insecure redirects (e.g. https:// -> http://www. -> https://www.)

Parsing and validation logic issues

 * [Heartbleed](http://heartbleed.com/)
 * [STARTTLS command injection](https://www.kb.cert.org/vuls/id/555316/)
 * Version intolerance, large handshake intolerance, middlebox breakage, ...
 * [Frankencerts](https://www.cs.utexas.edu/~shmat/shmat_oak14.pdf#page=11)
 * [goto fail](https://www.imperialviolet.org/2014/02/22/applebug.html)

Sidechannels

 * [Timing side channel](https://users.ece.cmu.edu/~dbrumley/pdf/Brumley,%20Boneh_2003_Remote%20timing%20attacks%20are%20practical.pdf) allowing remote key recovery
 * Timing side channels against symmetric ciphers ([AES](https://cr.yp.to/antiforgery/cachetiming-20050414.pdf))
 * [Timing side channel](https://eprint.iacr.org/2011/232) allowing remote key recovery
 * CPU cache side channels allowing private key recovery across processes/VMs ([PortSmash (ECDSA and DSA keys)](https://eprint.iacr.org/2018/1060), [CVE-2018-0737 (RSA keys)](https://www.openssl.org/news/secadv/20180416.txt))

Others

 * [Insecure Renegotiation](https://tools.ietf.org/html/rfc5746)
 * [Triple Handshake](https://www.mitls.org/pages/attacks/3SHAKE)
 * [Virtual Host Confusion](https://bh.ht.vc/vhost_confusion.pdf)
 * [Cookie cutter](https://hal.inria.fr/hal-01102259/file/triple-handshakes-and-cookie-cutters-oakland14.pdf)
 * [SLOTH](https://www.mitls.org/pages/attacks/SLOTH)
 * Carry propagation bugs / math bugs (can cause RSA-CRT bug, [Squeezing a key through a carry bit](https://www.youtube.com/watch?v=HaUtPd-x7VM))

license: Unlicense

repository: hannob/tls-what-can-go-wrong

gha_license_id: Unlicense

repo_name: hannob/tls-what-can-go-wrong


text:
---
title: Lambda Introduction
position: 2
keywords:
- lambdas
---

As Javacord heavily benefits from [lambda expressions](https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html), this introduction gives you a quick overview, if you are not familiar with lambdas. Lambdas are used as a short form of [functional interface](https://docs.oracle.com/javase/8/docs/api/java/lang/FunctionalInterface.html) implementations.
Functional interfaces, are basically just interfaces with a single method definition. All listeners in Javacord, for example, are functional interfaces and look like this internally (simplified):
```java
/**
 * This listener listens to message creations.
 */
@FunctionalInterface
public interface MessageCreateListener {

    /**
     * This method is called every time a message is created.
     *
     * @param event The event.
     */
    void onMessageCreate(MessageCreateEvent event);

}
```

Before Java 8, you would have implemented this kind of listener as an [anonymous class](https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html), which would look like this:
```java
api.addMessageCreateListener(new MessageCreateListener() {
    @Override
    public void onMessageCreate(MessageCreateEvent event) {
        // Do stuff
        event.deleteMessage();
    }
});
```
In Java 8, this can be replaced with a lambda expression, which does exactly the same thing, but shortens your code. The method parameter (in this case `event`) is written in front of the `->` arrow, and the method body is written after it.
```java
api.addMessageCreateListener(event -> {
    // Do stuff
    event.deleteMessage();
});
```
> Hint: If the method has more than one parameter, it would look like this: `(param1, param2) -> { ... }`

There's even a shorter version: if you are only executing one statement, you can get rid of the `{ }` brackets as well:
```java
api.addMessageCreateListener(event -> event.deleteMessage());
```
However, the above method can be shortened even more, by replacing the lambda expression with a so called "[method reference](https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html)".
```java
api.addMessageCreateListener(MessageEvent::deleteMessage);
```

There are also plenty classes in Java 8, which benefit from lambda expressions. One example would be the Optional class, which is explained [here](/wiki/essential-knowledge/working-with-optionals/).

gha_language: SCSS


text:
---
layout: default
title:  "Add Custom Appium Options"
excerpt: "Learn how to add custom Appium options."
date:   2021-11-20 06:50:17 +0200
parent: ios-automation
permalink: /ios-automation/add-custom-appium-options/
anchors:
  example: Example
  explanations: Explanations
---
Example
-------
```csharp
[TestFixture]
public class CustomWebDriverCapabilitiesTests : IOSTest
{
    public override void TestsArrange()
    {
        App.AddAdditionalCapability("autoAcceptAlerts", "true");
        App.AddAdditionalCapability("showIOSLog", "true");
        App.AddAdditionalCapability("remoteDebugProxy", "12000");
    }

    [Test]
    public void ButtonClicked_When_CallClickMethod()
    {
        var button = App.Components.CreateByName<Button>("ComputeSumButton");

        button.Click();
    }
}
```

Explanations
------------
```csharp
App.AddAdditionalCapability("autoAcceptAlerts", "true");
App.AddAdditionalCapability("showIOSLog", "true");
App.AddAdditionalCapability("remoteDebugProxy", "12000");
```
BELLATRIX hides the complexity of initialisation of WebDriver/Appium and all related services. In some cases, you need to customise the set up of a Appium with using custom Appium options. Using the **App** service methods you can add all of these with ease. Make sure to call them in the **TestsArrange** which is called before the execution of the tests placed in the test class. These options are used only for the tests in this particular class.
**Note**: You can use all of these methods no matter which attributes you use- **IOS**, **IOSSauceLabs**, **IOSBrowserStack** or **IOSCrossBrowserTesting**.


text:
Date and Time Handling
-----------------------

### Objectives

In this chapter you'll learn the basics of the Date object including how to manipulate the
components of dates and times, work with local and international dates and times and
display dates and times in a limited number of formats. You'll learn how to extend the
reach of the Date object by performing custom formatting, add and subtract days,
calculate the difference between dates and work with time zones. You'll also learn some of
the design and implementation issues involved with storing date and time values. Finally,
the chapter introduces a couple of sample utility libraries that you can use to make the job
easier.

### The Date Object

In JavaScript, there are no built-in common date handling functions such as adding and
subtracting days/weeks/months/hour., date and time formatting, date and time
comparisons and long day/week/month names. The basic Date object methods only
handle the following:
- getting and setting the component parts of dates and times, e.g. year, month, day, hours, etc..
- getting local and international dates and times.
- returning dates and times in a limited number of string formats.

You can augment the Date prototype to add the features you need on the fly or add a
third party utility library that will do the job for you.

### Creating and Initializing Dates

The Date constructor can be left empty to return the current date and time for the
computer's local time zone, or you can use a constructor overload to initialize to a
particular date and time. When no parameters are passed to the constructor, the date is
initialized with the computer's current local date and time.

```javascript
var now = new Date();
```

You can pass year, month and day parameters to the constructor. The month parameter is
zero-based, i.e. where January is zero, February is one, etc. Unspecified times are initialized
to midnight.

```javascript
var newYears = new Date(2012, 0, 1);
```

This next overload takes a number of milliseconds from January 1st, 1970 GMT at midnight.

```javascript
var newYears = new Date(1325404800000);
```

**Note:** You can get the number of milliseconds for a Date by calling the getTime()
method. Milliseconds are useful for performing date calculations, e.g. intervals
between dates. You can also use the static Date.parse() method that takes a date
string and returns the number of milliseconds since the January 1st, 1970 GMT epoch.
The constructor overload that takes a string representation of the date is surprisingly
flexible. The possible formats are specified in RFC 2822. The examples here all resolve to
the same date.

```javascript
var newYears = new Date("Jan 1, 2012"),
newYears2 = new Date("January 1, 2012"),
newYears3 = new Date("1/1/2012"),
newYears4 = new Date("Sun Jan 01 2012");
```

Once the date is created, use the instance methods to revise component parts of the date.
The example below sets the date to New Years 2012 at midnight.

```javascript
newYears.setYear(2012);
newYears.setMonth(0);
newYears.setDate(1);
newYears.setHours(0);
newYears.setMinutes(0);
newYears.setMilliseconds(0);
```

Fun facts from 1970:
- World population 3.63 billion.
- A gallon of gas was 36 cents, or 0.125 a gallon of petrol in UK pounds sterling.
- A loaf of bread cost 25 cents, a dozen eggs 62 cents and a gallon of milk was $1.15.
- Average cost to buy a home was $23,450 or £4,975 in UK pounds sterling.
- Paul McCartney announces Beatles disbanding.
- Apollo 13 mission is aborted.
- Abdel Nasser of Egypt dies.
- 100,000 people demonstrate against the Vietnam war in Washington.
- The Concord makes first supersonic flight.
-
### Setting the Time

When a time isn't specified in the constructor, the time is set to midnight. Time
components are hour, minute, second, millisecond. To specify the entire date and time,
use the full set of parameters year, month, day, hour, minute, second, millisecond. This
next example sets the time to 13:30.

```javascript
var newYears = new Date(2012, 0, 1, 13, 30, 0, 0);
```

String constructor parameters can be set in 24 or 12 hour formats.

```javascript
var newYears = new Date("1/1/2012 13:30:00");
var newYears = new Date("1/1/2012 1:30:00 pm");
```

To specify a particular time zone, add an offset. The example places the time in the US and
Canada Pacific time zone.

```javascript
var newYears = new Date("1/1/2012 13:30:00 -8:00");
```

### Date as Strings

JavaScript includes a limited set of no-frills date-to-string methods. The table shows
examples of available methods, a short description and a sample of the output as it might
appear in the console.
|Method Example |Comments and Console Output|
|---|---|
|christmas.toString(); |Human readable, the entire date is output.|
|christmas.toDateString(); |Human readable, date portion only.|
|christmas.toTimeString() |Human readable, time portion only.|
|christmas.toLocaleString() |Uses current locales settings.|
|christmas.toISOString() |ISO 8601 format.|
|christmas.toUTCString() |Universal time format.|
|christmas.toJSON() |JavaScript Object Notation format. Requires JavaScript 1.8.5.|

### Custom Formatting Dates and Times

If you want more than standard date-to-string methods, you'll need to either parse and
format the dates yourself or use a third party utility library. To handle your own parsing,
use the methods that get the component parts of the Date: getFullYear(), getMonth()
and getDate(). Then concatenate the year, month and day together in a specific string
format that suits your purpose. The example below parses the date and reassembles the
pieces in yyyy-M-d format.

```javascript
var aDate = new Date(2012, 5, 2); // some random date
var year = aDate.getFullYear(); // four digit year
var month = aDate.getMonth(); // month number, zero based
var day = aDate.getDate(); // day number
console.log(year + "-" + month + "-" + day); // outputs "2012-5-2"
```

You can extend the base Date functionality by adding functions to the prototype. For
example, adding a new "toYMDString" to the prototype lets you call directly from the
Date object instance, just as if the method were part of the original object. The sample
code below gets the component parts of the Date object and simply reassembles the
pieces using string concatenation.

```javascript
// new function added to prototype
Date.prototype.toYMDString = function () {
"use strict";
var year = this.getFullYear(),
month = this.getMonth(),
day = this.getDate();
return year + "-" + month + "-" + day;
};
var aDate = new Date(2012, 5, 2);
console.log(aDate.toYMDString()); // outputs 2012-5-2
```

### Long Date Format

Long date formats, such as "Wednesday, June 27th, 2019", don't come out of the box and
require a bit more work. You will need the long day name "Wednesday", the long month
"June" and the day number formatted as an ordinal "27th" with the proper "th" suffix".
The long day and month names can be added as arrays to the Date prototype:

```javascript
Date.prototype.days = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
];
Date.prototype.months = [
"January",
"February",
"March", "April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
```

How about the part of the date that reads "27th". This is an ordinal representation of the
day of the month. The English language has rules that govern which suffix is used:
1st
2nd
3rd
4th
5th. . .
The general rule is that numbers ending in 1 should be suffixed with "st", those ending in 2
should use "nd", those ending in 3 should use "rd" and everything else ends in "th". As with
a much of the English language, there is always an exception to the rule: the numbers 11, 12
and 13 end in "th". The toOrdinal() method defined below augments the Number
prototype and takes these circumstances into account.

```javascript
Number.prototype.toOrdinal = function () {
"use strict";
// deal with 11th, 12th, 13th exceptions to rule
switch (this % 100) {
case 11:
case 12:
case 13:
return this + "th";
}
// get the suffix for the rightmost digit
switch (this % 10) {
case 1:
return this + "st";
case 2:
return this + "nd";
case 3:
return this + "rd";
default:
return this + "th";
}
};
```

The toOrdinal() method can be implemented in a number of ways, many of them
more succinct than this example. The pattern above was chosen to clearly show the
11th/12th/13th exception without burying the logic in a more terse expression.
To test out that the toOrdinal() method is working for all cases, use a for loop to generate
a series of ordinals.

```javascript
var i;
for (i = 0; i < 120; i += 1) {
console.log(i + " : " + i.toOrdinal());
}
```

The screenshot below shows a sample composite of the first 41 entries. Notice the suffixes
for numbers 1-11-21-31, 2-12-22-32 and 3-13-23-33. The 11th, 12th and 13th are exceptions
to the pattern and are correctly suffixed in the example.

![](../media/image32.jpg)

Now that you have the basic components for a long date format, you can add a new
prototype method that assembles the pieces.

```javascript
Date.prototype.toYMDString = function () {
"use strict";
// index into the days array
return this.days[this.getDay()] + ", " +
// index into the months array
this.months[this.getMonth()] + " " +
// return the day of month ordinal
this.getDate().toOrdinal() + ", " +
// use the four digit year
this.getFullYear();
};
```

To test the method, create a Date object and call the new toYMDString() method.

```javascript
var date = new Date(2019, 5, 27);
// output "Wednesday, June 27th, 2019"
console.log(date.toYMDString());
```
To test over a wider range of dates, increment the date inside a loop. At line 03 in the
code below, getDate() returns the current day of the month, then setDate() is used to
increment the date by one day.

```javascript
01 for(i = 0; i < 30; i += 1){
02 console.log(date.getDate() + " - " + date.toYMDString());
03 date.setDate(date.getDate() + 1);
04 }
```
A small sample of the output is shown in the screenshot below:

![](../media/image33.jpg)

### Time Format

The stock methods for returning the time as a string are toTimeString() and
toLocaleTimeString(). For any other format you'll need to use a third party library or build
your own. The process is similar to formatting the date in that you extract the basic hour,
minute and second components of the time, develop any descriptive fields you need and
finally reassemble the formatted time. The example below adds a new to12HourString()
method to the Date prototype.

```javascript
Date.prototype.to12HourString = function () {
"use strict";
// get the time components
var hour = this.getHours(),
minute = this.getMinutes(),
second = this.getSeconds(),
// convert from 24 to 12 hour
hour12 = hour > 12 ? hour - 12 : hour,
// determine the am/pm setting
amPm = hour > 12 ? "pm" : "am",
// zero pad the second
twoDigitSecond =
(second.toString().length === 1) ? "0" + second : second;
// format the time
return hour12 + ":" + minute + ":" + twoDigitSecond + " " + amPm;
};
```
The code snippet below tests the new method by displaying the twelve hour format time
every second.

```javascript
var interval = setInterval(function () {
"use strict";
console.clear();
console.log(new Date().to12HourString());
}, 1000);
```

### Date Calculations

The JavaScript object has no built-in methods for adding and subtracting dates. For
example, you can't take the stock Date object and get tomorrow's date with the syntax
used below:

```javascript
var date = new Date(2012, 5, 2);
var tomorrow = date.addDays(1);
```

JavaScript Date objects hold the number of milliseconds that have passed since midnight
of January 1, 1970 UTC (Universal Coordinated Time). Times previous to Jan 1, 1970 are
stored as a negative number of milliseconds. You can get the raw millisecond value of a
Date using the getTime() method. You can use this raw value to get the difference
between two dates or add days to a date.

### Add and Subtract Days

To get the number of milliseconds per day, multiply 1000 (one second of milliseconds) by
60 seconds by 60 minutes by 24 hours. Graft on a new method addDays to the prototype
that takes the number of days to add or subtract as a parameter. Create a new result date
and set its time using the number of milliseconds from the "this" date and add the number
of milliseconds for the number of days passed in as a parameter.

```javascript
// milliseconds for one day
// milliseconds/seconds/minutes/hours
Date.prototype.millisecondsPerDay = 1000 * 60 * 60 * 24;
// new function to prototype
Date.prototype.addDays = function (days) {
"use strict";
var result = new Date();
result.setTime(this.getTime() + (this.millisecondsPerDay * days));
return result;
};
```

To test the code, try adding and subtracting days. The sample below tests for the previous
and next day and displays the string using the toYMDString() method we created in the
Long Date Format section.

```javascript
var date = new Date(),
yesterday = date.addDays(-1),
tomorrow = date.addDays(1);
console.log("Today: " + date.toYMDString());
console.log("Yesterday: " + yesterday.toYMDString());
console.log("Tomorrow: " + tomorrow.toYMDString());
```

The output should look something like the screenshot below:

![](../media/image34.jpg)

### Number of Days Between Two Dates

To get the time span between any two dates, first subtract their millisecond values. The
example below subtracts the number of milliseconds for today's date from the date of
Christmas.

```javascript
var today = new Date(),
christmas = new Date(2012, 11, 25),
mils = christmas.getTime() - today.getTime();
// outputs<PHONE_NUMBER>5 on this particular run
console.log(mils);
```
This particular run output "15429080985", a value not exactly "suitable for framing". To get
the number of days, divide by the number of milliseconds-per-day:

```javascript
// divide out milliseconds, seconds, minutes and hours
var days = mils / (1000*60*60*24);
// outputs 178 days in<PHONE_NUMBER>5 milliseconds
console.log("days: " + days);
```

To extract days/hours/minutes/seconds, progressively divide into the total millisecond
difference between the two days. This gets you the total number of milliseconds to
Christmas, the total number of seconds to Christmas and so forth. Each field represents the
time to Christmas in its entirety.

```javascript
var today = new Date(),
christmas = new Date(2012, 11, 25),
mils = christmas.getTime() - today.getTime(),
secs = mils / 1000, // extract seconds
mins = secs / 60, // extract minutes
hrs = mins / 60, // extract hours
days = hrs / 24; // extract days
console.log("milliseconds: " + mils); //<PHONE_NUMBER>5
console.log("seconds: " + secs); // 15429080.985
console.log("minutes: " + mins); //<PHONE_NUMBER>5
console.log("hours: " + hrs); // 4285.855829166667
console.log("days: " + days); //<PHONE_NUMBER>152778
```

If you want the days/hours/minutes/seconds together to represent the days to Christmas,
as you would for a "countdown timer", remove each component part of the Date after
extracting that part. You can extract each part of the date, starting with the seconds using
the modulus operator to "peel off" a particular part. In the example below, we're not using
the milliseconds, so divide by 1000 to roll those milliseconds up into seconds. The modulus
operator "%" extracts the seconds portion of the date left over while leaving the minutes/
hours/days intact.

```javascript
var temp = christmas.getTime() - today.getTime();
temp /= 1000; // ignore milliseconds
var secs = temp % 60; // extract seconds
temp /= 60; // ignore seconds
```

This same pattern is repeated until all parts of the date are extracted, until only the
number of hours that evenly divide into a day are left. The final line of code extracts the
number of days by dividing the hours by 24.

```javascript
var today = new Date();
var christmas = new Date(2012, 11, 25);
var mils = christmas.getTime() - today.getTime();
mils /= 1000; // ignore milliseconds
var secs = mils % 60; // extract seconds
mils /= 60; // ignore seconds
var mins = mils % 60; // extract minutes
mils /= 60; // ignore minutes
var hrs = mils % 24; // extract hours
var days = mils / 24; // extract days
console.log("milliseconds: " + mils);
console.log("seconds: " + secs);
console.log("minutes: " + mins);
console.log("hours: " + hrs);
```

Given the sample run where the number of milliseconds difference is<PHONE_NUMBER>5, the
console output looks like the screenshot below.

![](../media/image35.jpg)

Let's enhance the built-in Date object to include a new getTimeSpan() method, where a
new custom TimeSpan object will contain the component parts of the remaining time.

```javascript
function TimeSpan() {
"use strict";
this.days = 0;
this.hours = 0;
this.minutes = 0;
this.seconds = 0;
}
```

A new getTimeSpan() method added to the Date prototype performs the same, "divide
and conquer" strategy as the last example but places the components parts into the
TimeSpan object.

```javascript
Date.prototype.getTimeSpan = function (date) {
"use strict";
// create a new TimeSpan
var result = new TimeSpan(),
// get the date difference in milliseconds
temp = date.getTime() - this.getTime();
temp /= 1000; // ignore milliseconds
result.seconds = temp % 60; // extract seconds
temp /= 60; // ignore seconds
result.minutes = temp % 60; // extract minutes
temp /= 60; // ignore minutes
result.hours = temp % 24; // extract hours
result.days = temp / 24; // extract days
return result;
};
```

Calling the new method is just a matter of passing the second Date object as a parameter
and displaying TimeSpan results.

```javascript
var today = new Date();
var christmas = new Date(2012, 11, 25);
var span = today.getTimeSpan(christmas);
console.log("Days: " + span.days);
console.log("Hours: " + span.hours);
console.log("Minutes: " + span.minutes);
console.log("Seconds: " + span.seconds);
```

### Time Zones

A time zone is a mapping between UTC (Coordinated Universal Time) and the time for a
particular location. For example, on the east coast of the United States, the time zone is
UTC - 5 hours. You can find the offset using the Date object's getTimezoneOffset() that
returns the number of minutes difference between UTC and the local time of the computer.
On the west coast of the United States, Pacific Standard Time is -8, and the offset returned
by the getTimezoneOffset() method is 480 minutes (8 hours) difference. The returned
offset is exactly opposite what you expect because it works "westward" from UTC. To get
the number of hours difference in the expected format, divide by 60 to get the number of
hours and negate the result.

```javascript
var today = new Date();
// returns -8
var offsetHrs = -(today.getTimezoneOffset() / 60);
```

![](../media/image36.jpg)

You may also see UTC expressed as GMT (Greenwich
Mean Time), the global time standard until the
introduction of UTC in 1972. GMT is for all practical
purposes the same as UTC. Fun fact: Greenwich is located
at zero degrees, zero minutes longitude.

### Date and Time Storage Issues

Storing time is a special challenge best worked out during the design phase of your
application. There is no one-size-fits-all strategy for persisting time, particularly if want to
use the time from the client machine. Imagine you are writing a bill paying application
that accepts payment from all over the world, then time stamps the online payments and
later displays historical reporting that includes the payment time. What could possibly go
wrong?
- Time zone offsets are not consistent. For example, the code sample above returns -7 (not -8) when run during the summer months when daylight savings time rules kick in.
- Time zones are subject to political changes over time. For example, Hawaii and eastern Kiribati are at roughly the same longitude but are a day apart. Also, the shift to daylight savings time doesn't occur at the same time for all locations. Brazil sets summer time" by decree each year. Israel has a law that requires summer to last at least 150 days.
- The time zone offset may not be a full integer value in all locations. The offset for some areas may be a half or three quarters of an hour, e.g. Newfoundland is UTC -3:30.
- You can't depend on the state of the client computer. How about the battery for the client computer's bios clock? Can you be sure of the operating system and that the OS has all the latest updates that impact the clock and time zones?

For these reasons you should distrust times reported by the client. If you have to store
times derived from the client machine via JavaScript, use the time-zone independent UTC
time. Consider storing the local time zone along with the UTC time to make historical
reporting easier. Better still, if the application has a server or web service layer, store UTC
times on the server. While you're at it, make sure the server hardware and operating system
clocks are set correctly to UTC. Also consider using NTP (Network Time Protocol, see www.
ntp.org) servers to keep the time updated. Check your accuracy requirements against how
the operating system's transitions to and from daylight savings time. Not all operating
system versions play nicely when arriving at the same time twice. Some systems even clock
at half speed during the transition to resolve the issue.

Displaying the time is a presentation task that should convert from the UTC time at the last
moment. In some cases you can side-step the issue of converting to local time by using
language that reflects interval, age or relative time, e.g. "This blog was posted 10 minutes
ago".

The Internet Assigned Numbers Authority keeps a database (formerly known as the
"Olson time zone database") of time zone history for representative locations
around the world. The database is updated periodically to reflect political changes.
Third party libraries such as js timezone detect contain similar data for easy use in
JavaScript. Be aware that such libraries may not be historically or geographically
precise, i.e. they do not perform geolocation, but instead pick the most populated
time zones.

### Utility Libraries

There are a number of utility JavaScript Date libraries out there, many of them open
source, that will take care of the usual date calculations for you. There are several
advantages to this route:
- You don't have to spend time developing the code.
- The more people that use these libraries, the more bugs will be surfaced and fixed.
- The code will likely include more rigorous input checking.
- You can examine the code to learn new techniques.

We'll take a look at two open source library examples date.js and moment. Both libraries
are currently available under the MIT License.

### datejs

"Comprehensive, yet simple, stealthy and fast."

If you're testing code in the console, you can either download date.js from www.datejs.
com and paste it right into the console or run something like the following sample to
create a script tag and point it to the file's location. Only run this bit of script once for the
session. At that point the library is loaded into memory and available for use.

```javascript
var script = document.createElement("script");
script.src = "http://datejs.googlecode.com/files/date.js";
script.type = "text/javascript";
document.head.appendChild(script);
```

date.js has a pleasing natural language syntax. Here are a few simple date manipulations
to add and subtract days and weeks.

```javascript
Date.today();
// seven days from now
Date.today().addDays(7);
// a week ago
Date.today().addWeeks(-1);
```

date.js has a comprehensive set of features that will cover most of your wish list. Here's just
a few of the things you can do with date.js:
- Add and subtract all components of a date including milliseconds, seconds, minutes, hours, days, weeks, months and years.
- Validate dates and parts of dates.
- Find if a date is between two other dates.
- Find if a date is in a leap year.
- Get the number of days in a month.
- Get time zone abbreviations for the local computer, e.g. "EST", "UTC".
- Get the UTC date offset, e.g. -8 if the time zone is in Pacific Standard Time.
- Find out if the current time zone has daylight savings and if daylight savings is currently in effect.

The following examples just scratch the surface. For more information, see the Getting
Started Guide or the API Documentation.

```javascript
// same day of month in january
var januaryDay = Date.today().january();
var message = Date.today().getMonthName() + " has " +
Date.today().getDaysInMonth() + " days";
// throws RangeError if it fails
Date.validateDay(31, 2012, 5);
// returns true if a date is between two other dates
var start = new Date(2012, 1, 1);
var end = new Date(2012, 7, 1);
if (Date.today().between(start, end)) {
console.log("date is in range");
}
```

### moment

"A lightweight (4.3k) javascript date library for parsing, manipulating, and formatting dates."

The moment library overlaps date.js somewhat but has a slightly different syntax and some
cool features. The "humanize" feature outputs date information in a human readable form,
e.g. "8 months ago", "in 7 days", "last Tuesday", etc. The moment library has support for
multiple languages and allows you to switch between them (you do apparently need to
supply your own translations though). Here are just a few moment examples:

```javascript
// output "last Tuesday at 3:42 PM"
moment().subtract('days', 3);
// outputs "8 months ago"
moment("2011-10-31", "YYYY-MM-DD").fromNow();
// outputs in 7 days
moment().add('days', 7).fromNow();
```

### Summary

In this chapter you learned the basics of the Date object including how to manipulate the
components of dates and times, work with local and international dates and times and
display dates and times in a limited number of formats. You learned how to extend the
reach of the Date object by performing custom formatting, add and subtract days,
calculate the difference between dates and work with time zones. You also learned some
of the design and implementation issues involved with storing date and time values.
Finally, the chapter introduced sample utility libraries to make the job easier.

path: /Date and Time Handling/readme.md


text:
---
title: "Batch Normalization"
categories:
  - Research
tags:
  - batch normalization
  - regularization
header:
  teaser: /assets/images/batch norm/batch norm.png
  overlay_image: /assets/images/batch norm/batch norm.png
  overlay_filter: 0.4
sidebar:
  nav: "dl"
author_profile: false
---

**'Batch Normalization'** is an basic idea of a neural network model which was recorded the state-of-the art (4.82% top-5 test error) in the [ImageNet competition ILSVRC2015](http://image-net.org/challenges/LSVRC/2015/).
It was published and presented in International Conference on Machine Learning (ICML) 2015 with a paper name 'Batch Normalization: accelerating Deep Network Training by Reducing Internal Covariate Shirt'.

{% include toc title="Table of Contents" icon="file-text" %}

# Introduction

## Summary
- **Problem Statement**
  - **Internal Covariate Shift**: Distribution of each layer's inputs changes during training, as the parameters of the previous layers change.
  - This slows down the training by requiring lower learning rates and careful parameter initialization.

- **Research Objective**
  - To address the internal covariate shift problem and accelerate the training of deep neural nets.

- **Solution Proposed: Batch Normalization**
  - Batch normalization takes a step towards reducing internal covariate shift, and in doing so dramatically accelerates the training of deep neural nets.
  - It accomplishes this via a normalization step that fixes the means and variances of each layer input in training mini-batch.

- **Contribution**
  - Batch normalization allows to use much *higher learning rates*, *less careful about initialization* and works as *regularization* (no need for dropout).

## Motivation
- **Stochastic gradient descent (SGD)** is a widely used gradient method using mini-batch for training a deep neural network.
  - Pros
    - The gradient of the loss over a mini-batch is an estimate of the gradient over the training set, whose quality improves as the batch size increases.
    - The computation over a mini-batch can be more efficient than computations for individual examples on modern computing platforms.
  - Cons
    - This requires careful tuning of the learning rate, and the initial parameter values.
    - One naive way to increase training speed is to increase the learning rate, but high learning rate usually leads to *gradient vanishing* or *gradient exploding*.

- **Internal Covariate Shift**: Distribution of each layer's inputs changes during training, as the parameters of the previous layers change.
  - Small changes to the network parameters amplify as the network becomes deeper.
  - The saturation problem and the resulting vanishing gradients are usually addressed by using ReLU, careful initialization, and small learning rate.

- If we could ensure that the distribution of nonlinearity inputs remains more stable as the network trains, then the optimizer would be less likely to get stuck in the saturated regime, and the training would accelerate.

# Reducing Internal Covariate Shift with Whitening
- **Whitening**: One naive approach to reduce internal covariate shift by normalizing the input distribution into normal distribution with zero mean and unit variance (LeCun 1998, Wiesler & Ney 2011).
  - With a given column data $$X\in R^{d\times n}$$, whitening transform is,

$$
\hat{X} = Cov(X)^{-1/2} X \\
Cov(X) = E[( X - E[X] ) ( X - E[X] )^\top ]
$${: .text-center}

- Drawbacks of whitening approach
  - It requires high computation since it needs to compute $$Cov(X)^{-1/2}$$ for normalizing multi variate normal distribution.
  - It needs more computation to decide mean and variance of all data in each training step.

# Batch Normalization Transform

## Two Simplifications
Since the full whitening of each layer's inputs is costly, we make **two simplifications**.
- **First simplification:** we will normalize each scalar feature independently, by making it have zero mean and unit variance.
  - For a layer with $$d$$-dimentional input $$x = (x^{(1)}, x^{(2)}, \ldots, x^{(d)})$$, we will normalize each dimension,

$$
\hat{x}^{(k)} = \frac{x^{(k)} - E[x^{(k)}]}{\sqrt{Var[x^{(k)}]}}.
$${: .text-center}

- Simply normalizing each input of a layer may change what the layer can represent.
  - e.g. normalizing the inputs of a sigmoid would constrain them to the linear regime of the non-linearity.
  - To address this, we make sure that the transformation inserted in the network can represent the identity transform.
  - For each activation $$x^(k)$$, a pair of parameters $$\gamma, \beta$$, which scale and shift the normalized value and are learned along with the original model parameters,

$$
y^{(k)} = \gamma \hat{x}^{(k)} + \beta.
$${: .text-center}

- **Second simplification**: Since we use mini-batches in stochastic gradient training, each mini-batch produces estimates of the mean and variance of each activation instead of those of full-batch.
  - This way, the statistics used for normalization can fully participate in the gradient backpropagation.

## Batch Normalizing Transform
- Refer to the transform $$BN_{\gamma, \beta} : x_{1...m} \rightarrow y_{1...m}$$ as the Batch Normalizing Transform.
  - When $$\epsilon$$ is a constant added to the mini-batch variance for numerical stability.

![Algorithm]({{ site.url }}{{ site.baseurl }}/assets/images/batch norm/algorithm.png){:height="80%" width="80%"}{: .align-center}

- **Chain rule** for batch normalizing transform
![Chain rule]({{ site.url }}{{ site.baseurl }}/assets/images/batch norm/chain rule.png){: .align-center}

## Training and Inference
- To Batch-normalize a network, we specify a subset of activations and insert the BN transform for each of them.
  - Specifically, after computing $$wx+b$$ and before computing activation function of each layer.
![Comparison]({{ site.url }}{{ site.baseurl }}/assets/images/batch norm/batch norm.png){: .align-center}

- The procedure for training batch-normalized networks.
  - Train the network by using BN transform with the sample mean and variance of mini-batch.
    - The normalization of activations that depends on the mini-batch allows efficient training, but is neither necessary nor desirable during inference.
    - We want the output to depend only on the input, deterministically.
  - Test the network by using BN transform with unbiased mean and variance estimator which are computed with saved sample mean and variance.
![Training]({{ site.url }}{{ site.baseurl }}/assets/images/batch norm/training.png){: .align-center}

## Contributions of BN
1. **BN networks can be trained with saturating nonlinearities**
  - It prevents small changes in layer parameters from amplifying as the data propagates through a deep network.
  - e.g. It helps the sigmoid nonlinearities to more easily stay in their non-saturated regimes

2. **More tolerant to increased training rates (higher learning rate)**
  - Reduce internal covariate shift, more resilient to the parameter scale
  - Faster convergence

3. **Less careful initialization**

3. **Regularization effect (Dropout is unnecessary)**
  - To amplify the effect of regularization, decide the mini-batch by shuffling the training data.

# Experiments
## Activations Over Time
- Figure 1(a) shows faster convergence and higher test accuracy of BN network.
- Figure 1(b) and (c) plot the activation value while training, and BN network have similar distribution from the beginning to the end.
![Result1]({{ site.url }}{{ site.baseurl }}/assets/images/batch norm/result1.png){: .align-center}

## ImageNet Classification
- Figure 2 and 3 compares Inception network by varying the learning rate, and BN network gives faster convergence and higher max accuracy.
![Result2]({{ site.url }}{{ site.baseurl }}/assets/images/batch norm/result2.png){: .align-center}{:height="80%" width="80%"}
![Result3]({{ site.url }}{{ site.baseurl }}/assets/images/batch norm/result3.png){: .align-center}{:height="80%" width="80%"}

- BN network achieves the state-of-the-art on ImageNet competition with small parameter tunning

![Result4]({{ site.url }}{{ site.baseurl }}/assets/images/batch norm/result4.png){: .align-center}
{: .full}

## Accelerating BN Nets
- *Increase learning rate*: faster convergence
- *Remove Dropout*: BN works as regularization
- *Shuffle training examples more thoroughly*: to get different model for generalization
- *Reduce the $$L_2$$ weight regularization*: BN works as regularization
- *Accelerate the learning rate decay*: BN nets trains faster
- *Remove Local Response Normalization*: not suitable for BN
- *Reduce the photometric distoritions*: because BN nets train faster and observe each training example fewer times, it is better to focus on more "real" images

# References
- Paper: Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift [[Link](http://proceedings.mlr.press/v37/ioffe15.pdf)]

filename: 2018-01-16-research-batch norm.md


text:
# Utf.js

Simply, it allows you to convert between UTF-8, 16, 32 and String. 1.5 KB when minified.

### Documentation

It has two groups of functions. The first group:

```javascript
// in: String
function FromString(str) {}
// in: Uint8Array/Array
function FromUTF8(str) {}
// in: Uint16Array/Array
function FromUTF16(str) {}
```

Each of them outputs an `Uint32Array` of UTF-32 for success, or a `[]` for error.

The second group:

```javascript
// out: String
function ToString(str) {}
// out: Uint8Array
function ToUTF8(str) {}
// out: Uint16Array
function ToUTF16(str) {}
```

They are passed an `Uint32Array` of UTF-32. `ToUTF8` and `ToUTF16` return a `[]` for error and `ToString` returns `""`.

### Sample Use

Let's say we want to encode a string as UTF-8 byte array. How do we do that?

```javascript
var utf8 = ToUTF8(FromString("hi! 😮"));
```

How to decode UTF-8?

```javascript
console.log(ToString(FromUTF8(utf8)));
```

Note: This is beta software


text:
# nebulo-web

Nebulo for Web, built with React.

## What You Need
1. Node/NPM
2. Patience :)

## Installation
1. Clone this repository.
2. Install dependencies with `npm install`
3. Run `npm start`

## License
MIT

repository: undertideco/nebulo-web

repo_name: undertideco/nebulo-web


text:
# Ruby Examples

This directory contains a collection of ruby example to help get you started using the Lob API. As always, feel free to [contact us](https://lob.com/support) directly if you have any questions.

## /csv_checks/

An example showing how to dynamically create checks from a CSV using HTML, variable data, and Lob's [Checks API](https://lob.com/services/checks).

## /csv_letters/

An example showing how to dynamically create letters from a CSV using HTML, a custom font, variable data, and Lob's [Letters API](https://lob.com/services/letters).

## /csv_postcards/

An example showing how to dynamically create postcards from a CSV using HTML, a custom font, variable data, and Lob's [Postcards API](https://lob.com/services/postcards).

## /checks.rb

An example showing how to create a check using Lob's [Checks API](https://lob.com/services/checks).

## /jobs.rb

An example showing how to create objects and jobs using Lob's [Jobs API](https://lob.com/services/sps).

## /letters.rb

An example showing how to create a letter using Lob's [Letters API](https://lob.com/services/letters).

## /postcards.rb

An example showing how to create a postcard using Lob's [Postcards API](https://lob.com/services/postcards).

## /verify/

An example showing how to verify an address using the [StreetAddress gem](https://github.com/derrek/street-address) and Lob's verify endpoint. This example saves verified addresses in a CSV file.

repository: dice-media-group/lob-ruby

repo_name: dice-media-group/lob-ruby


text:
![Capsule8](docs/images/capsule8.png?raw=true "Capsule8 logo")
==============================================================

Capsule8 performs advanced behavioral monitoring for cloud-native,
containers, and traditional Linux-based servers. This repository
contains the open-source components of the Capsule8 platform,
including the Sensor, example API client code, and command-line
interface.

## Status

Capsule8 is current in alpha and under active development. The gRPC
API is v0 and subject to change at any time, but we strive to keep the
sample code in `examples/` updated with any changes to the API.

## Docs

## Quickstart

For a quick demonstration of the capsule8 sensor's capabilities, start
up three terminal sessions to run the sensor, example telemetry
client, and target container as described below.

### Checkout latest code

```
$ git clone https://github.com/capsule8/capsule8.git
$ git submodule init && git submodule update
```

### Build the sensor

```
$ make
```

### Start the sensor

Start the Sensor and listen for API clients on the default local unix
socket:

```
$ sudo ./bin/sensor
I1004 18:55:23.111094    9617 version.go:33] Starting sensor (0.0.0+9b149e4)
I1004 18:55:23.111736    9617 sensor.go:121] Starting servers...
I1004 18:55:23.111746    9617 sensor.go:135] Sensor is ready
I1004 18:55:23.111761    9617 telemetry.go:29] Serving gRPC API on unix:/var/run/capsule8/sensor.sock
[...]
```

### Subscribe to telemetry for specified container images

The example telemetry client in `examples/telemetry` provides a
demonstration of how to use the Telemetry API. It subscribes to the
following telemetry:
- process lifecycle events (`fork`, `execve`, and `exit`)
- `open(2)` system call return values
- file open events for any file name matching the glob `*foo*`
- kernel function calls to `SyS_connect` involving IPv4 addresses and
  returning the parsed out `sockaddr` structure elements
- container lifecycle events (created, running, exited, destroyed)

If the `-image <glob>` argument is specified on the command-line, then
events will be filtered to only containers running images with names
matching the specified glob.

```
$ go build examples/telemetry/main.go
$ sudo ./examples/telemetry/telemetry -image busy*
Watching for container images matching busy*
event:<id:"978eec0f976c5c5b7867d9d3793bdb89e50e7d920ce3dc816659a4861722fc56" container_id:"4265413fa321921b3c6014f564811a17c9e376a17ade3e7026611ceba48ed955" sensor_id:"52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c649" sensor_sequence_number:3208 sensor_monotime_nanos:208974918639853 container:<type:CONTAINER_EVENT_TYPE_CREATED name:"/nostalgic_galileo" image_id:"c30178c5239f2937c21c261b0365efcda25be4921ccb95acd63beeeb78786f27" image_name:"busybox" > >
event:<id:"8fa21518ff0a2babaa72e6e07c760c0e6573d50787d351b57f47fd1da3606810" container_id:"4265413fa321921b3c6014f564811a17c9e376a17ade3e7026611ceba48ed955" sensor_id:"52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c649" sensor_sequence_number:5130 sensor_monotime_nanos:208975053166529 container:<type:CONTAINER_EVENT_TYPE_RUNNING host_pid:15217 > >
event:<id:"b631682fc0d56ff38e992f8b8afd2e964fc3a61377055bcb5abf46fd4038f37c" process_id:"fafb8d19c3ab7b6934b1fab8354decb50f2d982351984d81bb1b0ef8e6fcf586" process_pid:15217 container_id:"4265413fa321921b3c6014f564811a17c9e376a17ade3e7026611ceba48ed955" sensor_id:"52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c649" sensor_sequence_number:5164 sensor_monotime_nanos:208977310484246 container_name:"/nostalgic_galileo" image_id:"c30178c5239f2937c21c261b0365efcda25be4921ccb95acd63beeeb78786f27" image_name:"busybox" syscall:<type:SYSCALL_EVENT_TYPE_EXIT id:2 ret:3 > process_tid:15217 cpu:5 >
event:<id:"4095d65d394a23be9b574f36c92d9acb1c4ded13955e000657e5aac8570f1926" process_id:"fafb8d19c3ab7b6934b1fab8354decb50f2d982351984d81bb1b0ef8e6fcf586" process_pid:15217 container_id:"4265413fa321921b3c6014f564811a17c9e376a17ade3e7026611ceba48ed955" sensor_id:"52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c649" sensor_sequence_number:5170 sensor_monotime_nanos:208977310715127 container_name:"/nostalgic_galileo" image_id:"c30178c5239f2937c21c261b0365efcda25be4921ccb95acd63beeeb78786f27" image_name:"busybox" process:<type:PROCESS_EVENT_TYPE_FORK fork_child_pid:15298 > process_tid:15217 cpu:5 >
event:<id:"065d00a4e53195b0b8abdd71a1f1abdf1d233e98656f92f750f0661b1a145e92" process_id:"2a7536fb3b396281e05e4602f546745819a34741462a8aaeff7aca514f3b2898" process_pid:15298 container_id:"4265413fa321921b3c6014f564811a17c9e376a17ade3e7026611ceba48ed955" sensor_id:"52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c649" sensor_sequence_number:5196 sensor_monotime_nanos:208977312517716 container_name:"/nostalgic_galileo" image_id:"c30178c5239f2937c21c261b0365efcda25be4921ccb95acd63beeeb78786f27" image_name:"busybox" process:<type:PROCESS_EVENT_TYPE_EXEC exec_filename:"/bin/ls" > process_tid:15298 cpu:7 >
event:<id:"b7b23c45ad2c1d868be4754933bc8ad8af09ee473292a54ca1f077bd2a08c5ba" process_id:"2a7536fb3b396281e05e4602f546745819a34741462a8aaeff7aca514f3b2898" process_pid:15298 container_id:"4265413fa321921b3c6014f564811a17c9e376a17ade3e7026611ceba48ed955" sensor_id:"52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c649" sensor_sequence_number:5197 sensor_monotime_nanos:208977312711734 container_name:"/nostalgic_galileo" image_id:"c30178c5239f2937c21c261b0365efcda25be4921ccb95acd63beeeb78786f27" image_name:"busybox" syscall:<type:SYSCALL_EVENT_TYPE_EXIT id:2 ret:3 > process_tid:15298 cpu:7 >
[...]
event:<id:"faf7110112131d6797f7edb75f053926f05026792da1cf72b4efed50b2cf04a2" container_id:"4265413fa321921b3c6014f564811a17c9e376a17ade3e7026611ceba48ed955" sensor_id:"52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c649" sensor_sequence_number:6043 sensor_monotime_nanos:208979802583554 container:<type:CONTAINER_EVENT_TYPE_EXITED name:"/nostalgic_galileo" image_id:"c30178c5239f2937c21c261b0365efcda25be4921ccb95acd63beeeb78786f27" image_name:"busybox" exit_code:1 > >
event:<id:"ba6a5118c6314209ec317472355638106a127ccfb75c45adf00fc8c7d8c778ea" container_id:"4265413fa321921b3c6014f564811a17c9e376a17ade3e7026611ceba48ed955" sensor_id:"52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c649" sensor_sequence_number:6044 sensor_monotime_nanos:208979811686154 container:<type:CONTAINER_EVENT_TYPE_DESTROYED > >
```

### Generate events in a matching container

In order to generate matching telemetry, start a busybox container in another terminal:

```
$ docker run --rm -it busybox
docker run --rm -it busybox
/ # ls
bin   dev   etc   home  proc  root  sys   tmp   usr   var
/ # cat /foo
cat: can't open '/foo': No such file or directory
/ # exit
```

## Contributing

For contributing guidelines see [CONTRIBUTING](./CONTRIBUTING.md).

## FAQ

### How is this supposed to be used?

The Sensor is intended to be run on a Linux host persistently and
ideally before the host begins running application workloads. It is
designed to support API clients subscribing and unsubcribing from
telemetry dynamically to implement various security incident detection
strategies.

### What types of events can be subscribed to currently?

Container lifecycle, process lifecycle, raw system calls, file opens,
network activity, and kernel function calls.

### Kernel function calls?

You can subscribe to calls to a chosen exported function symbol and
receive telemetry events with named values of the data requested. This
data can include function call arguments, return values, register
values, and even values dereferences via offsets from any of them. For
a more detailed description of what's possible, see the Linux kernel
[kprobe docs](https://www.kernel.org/doc/Documentation/trace/kprobetrace.txt).

### What guarantees does the Sensor provide?

The Sensor provides telemetry events on a best-effort
basis. System-level events are intentionally monitored through
`perf_event_open(2)` such that an excessive volume of events causes
them to be dropped by the kernel rather than blocking the kernel as
the audit subsystem may do. This means that telemetry events, and even
some of the information within them, is "lossy" by design. We believe
that this is the right trade-off for monitoring production
environments where stability and performance are critical.

gha_language: Go


text:
---
layout: layouts/post.njk
title: This is what 6,000+ masks look like y'all!
date: 2020-04-04T00:04:11.489Z
tags:
  - Updates
excerpt: Our biggest collection of masks to date is going to some amazing organizations.
---
![6,000 masks in the back of an SUV](/images/91247654_10105332988066133_2859965580776046592_o.jpg)

THANK YOU TO EVERY CRAFTER, VOLUNTEER, AND DONOR WHO MADE THIS HAPPEN!!!

These masks will be benefiting [Compass Housing Alliance](https://www.compasshousingalliance.org/), [Seattle Housing Authority](https://www.seattlehousing.org/), [Northwest Kidney Centers](https://www.nwkidney.org/), [Kirkland Vision Center](https://www.facebook.com/kvcenter/?ref=gs&__tn__=%2CdK-R-R&eid=ARBQ5vKV8tMMkCOf51pZFyPHTuWcj-y7mbmxFMJEGkjeuifI3F-zacb2Bcv9UhjR29QCeKZ_ul2lbnR5&fref=gs&dti=2559223211033116&hc_location=group), [Community Health Care](https://www.commhealth.org/), [Plymouth Housing](https://plymouthhousing.org/),[ Catholic Community Services-Seattle/King County](https://ccsww.org/), and [Hopelink ](https://www.hopelink.org/)among others.

We are still going strong, and demand for masks is still growing. Please consider donating to help us continue to make these highly essential masks!

[gf.me/u/xrv4q5](http://gf.me/u/xrv4q5?fbclid=IwAR06Qq14VMYunDYq0Hlg4BBzQ2qJv0iqHRX9nQJaFYGNlAsTOynD0F2omew)

![Founder Candace Frank with a car full of masks](/images/91517167_10105332988265733_5776925553663672320_o.jpg)

branch_name: refs/heads/main

gha_language: Nunjucks


text:
# Bubble_sort
    This project is the first project in the ruby module in microverse. The  project aims at testing students understanding of blocks and methods in ruby
## GETTING STARTED
    To have a local version of this code running do the following:
- clone the repository
- install the ruby compiler and any preferred code editor of your choice
- Run the command ruby main.rb

## Built With

- Ruby

## Live Demo

[Live Demo<EMAIL_ADDRESS>
## Authors

**Imran Yousaf**

- GitHub: [@imran5644](https://github.com/imran5644)
- Twitter: [@imran56444](https://twitter.com/imran56444)
- LinkedIn: [Imran yousaf](https://www.linkedin.com/in/imran-yousaf-8777297b/)

##  Contributing

Contributions, issues, and feature requests are welcome!

## Show your support

Give a ⭐ if you like this project!

## License

This project is [MIT](./LICENSE.txt) licensed.


text:
# KN

    A port of Brian Romanowski's Java-based open source Kneser-Ney language model, according to Chen and Goodman's kneser-ney-mod-fix
    description, to nodejs using the 'natural' npm package.

## Usage [usage]

    var kn = require('../lib/kn'),
        _ = require('underscore'),
        NGramCountModel = kn.NGramCountModel,
        KneserNeyModFixModel2 = kn.KneserNeyModFixModel2,
        NGram = kn.NGram;

    // training is an array of strings (do not feed <s> </s> sentence delimiters, no '.')
    var ngcm = new NGramCountModel();
    for (var t=0;t<training.length;t++) ngcm.populate(training[t]);

    var kn = new KneserNeyModFixModel2(ngcm);
    var backoff = kn.calcBackoff();

    // create an bigram, you have to use indices from the count model (if they are there)
    var test = new NGram([ ngcm.index['i'], ngcm.index['have'] ]);

    // find any matching trigrams and their probability
    var hashes = backoff.forwardLookup[test.hash()];

    // need a way to print ngrams, yeah, should probably be 'in' NGram
    var printWords = function(ngram, index){
        var str = '';
        _.each(ngram.keys,function(key){
            str += index[key]+' ';
        });
        return str;
    };

    // print out the results
    _.each(hashes,function(h){

        // in this case, the input is a bigram, output is a trigram (stored in highOrderNGrams)
        console.log('\tmatch:',printWords(backoff.highOrderNGrams[h]));
    });

## Note

    Brian Romanowski's Copyright on the Java version from which this was adapted

        /*
         Copyright 2011 Brian Romanowski. All rights reserved.

         Redistribution and use in source and binary forms, with or without modification, are
         permitted provided that the following conditions are met:

         1. Redistributions of source code must retain the above copyright notice, this list of
         conditions and the following disclaimer.

         2. Redistributions in binary form must reproduce the above copyright notice, this list
         of conditions and the following disclaimer in the documentation and/or other materials
         provided with the distribution.

         The views and conclusions contained in the software and documentation are those of the
         authors.
         */

repository: jleibund/kn

repo_name: jleibund/kn


text:
+++
Description = "Arm Server Chips Taking Flight"
author = "mestery"
categories = ["arm", "servers", "datacenter"]
date = "2017-12-05T19:14:02Z"
socialsharing = true
tags = ["arm", "servers", "datacenter"]
title = "Arm Server Chips Taking Flight"
url = ""

+++
From an [article][1] from [The Next Platform][2] site:

> The Centriq 2400 is the culmination of over four years of work and
> investment, which according to the experts in the semiconductor
> industry we have talked to, easily took on the order of $100 million to $125
> million to make happen – remember there was a prototype as well as the
> first generation Amberwing chip – and probably several hundred chip
> engineers to design. And now, there is another credible Arm server processor
> in the datacenter fray alongside the ThunderX and ThunderX-2 from Cavium and
> the X-Gene 1 and X-Gene 2 from Applied Micro.

2018 and beyond is shaping up to be a very interesting time for the server chip
market. Couple this with Red Hat Enterprise Linux for ARM (see a great article
from Jon Masters [here][3]), and I can't wait for what is next.

[1]: https://www.nextplatform.com/2017/11/08/qualcomms-amberwing-arm-server-chip-finally-takes-flight/
[2]: https://www.nextplatform.com/
[3]: https://www.linkedin.com/pulse/reflections-building-rhel-arm-jon-masters?articleId=6335845856146706432#comments-6335845856146706432&trk=prof-post

repository: mestery/siliconloons

repo_name: mestery/siliconloons


text:
# Exercise Quality Prediction
Abimbola M
February 26, 2015

### Executive Summary

Using data from 4 accelerometers on 6 participants, a model with 99.7% accuracy was used to predict the quality of barbell lifts in 20 test subjects.

  - Some of the data were discarded due to missing information: variables with no data, Variables with identifiers and timestamps, and variables with greater than 80% correlation. The remaining data with 39 predictors were used for the rest of the analysis.
  - The labelled training set was further divided into a training and testing sets. 3 models were built and compared using their performance on the labelled testing set (a subset of the original training set). The random forest model outperforms boosting trees and support vector machine and very comparable with an ensemble model of the three previously mentioned models.
  - Classification of unlabelled test set was done with the random forest model. The quality prediction for each subject is the same for all the models and only 7 out the 20 subjects perfomed the lift exactly to specification.

### Background

Devices such as Jawbone Up, Nike FuelBand, and Fitbit collect large amount of data about personal activity. This information is popularly used to quantitfy particular activities but rarely the quality of such activities. This project uses data from accelerometers on the belt,forearm,arm, and the dumbell of 6 participants who were asked to perform barbell lifts correctly and incorrectly in 5 different ways.

The data and more information is available from the website here: http://groupware.les.inf.puc-rio.br/har (see the section the Weight Lifting Exercise Dataset).
The datasets can be downloaded here: [training](https://d396qusza40orc.cloudfront.net/predmachlearn/pml-training.csv) and [test](https://d396qusza40orc.cloudfront.net/predmachlearn/pml-testing.csv).

### Data Cleaning

Load caret and doParallel libraries.

```r
library(caret)
library(doParallel)
```

Load datasets

```r
train <- read.csv("pml-training.csv",sep=",", header=TRUE, stringsAsFactors=TRUE,
                  na.string=c("NA","#DIV/0!"))

test <- read.csv("pml-testing.csv",sep=",", header=TRUE, stringsAsFactors=TRUE,
                 na.string=c("NA","#DIV/0!"))
```

Check for missing data

```r
y <- apply(train,2,function(x){sum(is.na(x))})
table(y)
```

```
y
    0 19216 19217 19218 19220 19221 19225 19226 19227 19248 19293 19294
   60    67     1     1     1     4     1     4     2     2     1     1
19296 19299 19300 19301 19622
    2     1     4     2     6
```

The training dataset has 19622 observations and 160 variables and only 60 variables have no missing data for all the observations; remove the variables with missing data.

```r
## Remove columns with missing variables
train1 <- train[colSums(is.na(train)) == 0]
```

Examine the data structure

```r
str(train1); names(train1)
## Remove columns with identifiers, timestamps, and redundant dataset.
train1 <- train1[,-c(1:7)]
rm(train)
```

There are 53 variables left. For compuational efficiency, remove features that are higly correlated

```r
## Identify correlated predictors
descrCor <- cor(train1[,-53]) #exclude activity labels
highCorr <- sum(abs(descrCor[upper.tri(descrCor)]) > .80)
highCorr
```

```
[1] 19
```

Remove these 19 features that are higly correlated

```r
highlyCorDescr <- findCorrelation(descrCor, cutoff = .80)
train1 <- train1[,-highlyCorDescr]; dim(train1)
```

```
[1] 19622    40
```

In total 40 variables, including the dependent variable, are left for model training. The higly correlated variables could have been kept since they don't affect tree modeling significantly, but I removed them for computational efficiency.

### Modeling

Split the training set into two. I'm taking advantage of this fairly large set to check the performance of my models before the final test set prediction.

```r
set.seed(998)
inTraining <- createDataPartition(train1$classe, p = .75, list = FALSE)
training <- train1[inTraining,]
testing  <- train1[-inTraining,]
```

Generate seeds for resampling.

```r
#create a list of seed
set.seed(123)
seeds <- vector(mode="list",length=11)
for(i in 1:10) seeds[[i]] <- sample.int(1000,8)
seeds[[11]] <- sample.int(1000,1)
```

Register a backend for parallel computation

```r
cl <- makeCluster(detectCores())
registerDoParallel(cl)
```

My control parameters for training includes a YeoJohnson transformation (some variables have zeros and negative values) and removal of variables with near-zero-variance. The latter because the variables with lots of zeros and few unique values may have undue influence on the modeling.

```r
## Control parameters
ctrl = trainControl(method="cv",seeds=seeds,allowParallel=TRUE,
                    preProc=c("center","scale", "YeoJohnson", "nzv"))
```

####*Random Forest Model*

```r
rfGrid <- expand.grid(mtry=c(1,2,4,6))
Model1 <- train(classe ~ ., method = "rf", tuneGrid=rfGrid, trControl=ctrl, data=training)
Model1$finalModel
```

```

Call:
 randomForest(x = x, y = y, mtry = param$mtry)
               Type of random forest: classification
                     Number of trees: 500
No. of variables tried at each split: 6

        OOB estimate of  error rate: 0.61%
Confusion matrix:
     A    B    C    D    E class.error
A 4180    4    0    1    0 0.001194743
B   12 2829    6    0    1 0.006671348
C    0   19 2545    3    0 0.008570316
D    1    0   32 2376    3 0.014925373
E    0    0    1    7 2698 0.002956393
```

The final model has 500 trees and 6 variables tried at each split for prediction with an OOB estimate of 0.61%. This is pretty impressive! It leaves little room for improvement, but I will play around with other models.

![](Figs/plot1-1.png)

####*Generalized boosted model*

```r
gbGrid <- expand.grid(interaction.depth = c(1,2,4), n.trees = c(100,150,200), shrinkage = 0.1, n.minobsinnode = 20)
Model2 <- train(classe ~ ., method="gbm", data=training, trControl=ctrl, tuneGrid=gbGrid, verbose=FALSE)
Model2
```

```
Stochastic Gradient Boosting

14718 samples
   39 predictor
    5 classes: 'A', 'B', 'C', 'D', 'E'

No pre-processing
Resampling: Cross-Validated (10 fold)
Summary of sample sizes: 13246, 13245, 13246, 13247, 13247, 13247, ...
Resampling results across tuning parameters:

  interaction.depth  n.trees  Accuracy   Kappa      Accuracy SD
  1                  100      0.7893062  0.7333506  0.011186151
  1                  150      0.8287154  0.7832129  0.010561482
  1                  200      0.8520207  0.8126579  0.011809708
  2                  100      0.8901378  0.8609382  0.012669211
  2                  150      0.9179249  0.8961371  0.007730081
  2                  200      0.9346385  0.9172918  0.005702638
  4                  100      0.9492459  0.9357780  0.003693731
  4                  150      0.9654168  0.9562446  0.003570096
  4                  200      0.9760160  0.9696593  0.002882499
  Kappa SD
  0.014176297
  0.013419605
  0.015009138
  0.016048196
  0.009785022
  0.007219941
  0.004693748
  0.004525562
  0.003649636

Tuning parameter 'shrinkage' was held constant at a value of 0.1

Tuning parameter 'n.minobsinnode' was held constant at a value of 20
Accuracy was used to select the optimal model using  the largest value.
The final values used for the model were n.trees = 200,
 interaction.depth = 4, shrinkage = 0.1 and n.minobsinnode = 20.
```

The final model has 200 trees and an interaction depth of 4 with 97.8% accuracy, lower than the random forest model by 2%

![](Figs/plot2-1.png)

####*Support Vector Machine*

```r
Model3 <- train(classe ~ ., data = training, method = "svmRadial", tuneLength=4, trControl=ctrl)
Model3
```

```
Support Vector Machines with Radial Basis Function Kernel

14718 samples
   39 predictor
    5 classes: 'A', 'B', 'C', 'D', 'E'

No pre-processing
Resampling: Cross-Validated (10 fold)
Summary of sample sizes: 13246, 13247, 13247, 13247, 13247, 13246, ...
Resampling results across tuning parameters:

  C     Accuracy   Kappa      Accuracy SD  Kappa SD
  0.25  0.8668291  0.8310376  0.004866730  0.006145267
  0.50  0.9001227  0.8733053  0.006063174  0.007705653
  1.00  0.9257396  0.9058396  0.007762574  0.009869862
  2.00  0.9485000  0.9347553  0.006327748  0.008029365

Tuning parameter 'sigma' was held constant at a value of 0.01650208
Accuracy was used to select the optimal model using  the largest value.
The final values used for the model were sigma = 0.01650208 and C = 2.
```

The final model has a cost function of 2 and accuracy of 94.9%. Increasing the cost function may actually increase its accuracy but I will keep it this way to avoid overfitting.

![](Figs/plot3-1.png)

I wish I have a better way to reduce this plot to one box since the variables importance are the same across all classes of activity.

The top 10 variables on the importance scale are the same for models 1 and 2. Only 5 of the top 10 in the support vector model (model3) are shared with the other models. 3 of these 5 variables are the same: magnetdumbell in three dimensional plane(x,y,z). The top 3 important variables are the same for the the first 2 models and 1 of the 3 variables, pitchforearm, is the most important variable in Model3 prediction

####*Discriminant Model*
For curiosity sake, let's see how discriminant models perform. I already have a model with an OOB error rate of 0.61% so I am not expecting much.

```
Linear Discriminant Analysis

14718 samples
   39 predictor
    5 classes: 'A', 'B', 'C', 'D', 'E'

No pre-processing
Resampling: Bootstrapped (25 reps)
Summary of sample sizes: 14718, 14718, 14718, 14718, 14718, 14718, ...
Resampling results

  Accuracy   Kappa     Accuracy SD  Kappa SD
  0.6476778  0.554547  0.005758262  0.006968372

```

```
Quadratic Discriminant Analysis

14718 samples
   39 predictor
    5 classes: 'A', 'B', 'C', 'D', 'E'

No pre-processing
Resampling: Bootstrapped (25 reps)
Summary of sample sizes: 14718, 14718, 14718, 14718, 14718, 14718, ...
Resampling results

  Accuracy   Kappa      Accuracy SD  Kappa SD
  0.8653119  0.8296268  0.004361273  0.005597815

```

Unsurprisingly, the quadratic discriminant model performed better than the linear and both performed poorly compared to the three models above. They will not be considered further.

####*Perfomance testing*

```r
Pred1 <- predict(Model1, testing)
confusionMatrix(Pred1, testing$classe)$overall
```

```
      Accuracy          Kappa  AccuracyLower  AccuracyUpper   AccuracyNull
     0.9944943      0.9930352      0.9919995      0.9963687      0.2844617
AccuracyPValue  McnemarPValue
     0.0000000            NaN
```

```r
Pred2 <- predict(Model2, testing)
confusionMatrix(Pred2, testing$classe)$overall
```

```
      Accuracy          Kappa  AccuracyLower  AccuracyUpper   AccuracyNull
     0.9781811      0.9723990      0.9736942      0.9820853      0.2844617
AccuracyPValue  McnemarPValue
     0.0000000            NaN
```

```r
Pred3 <- predict(Model3, testing)
confusionMatrix(Pred3, testing$classe)$overall
```

```
      Accuracy          Kappa  AccuracyLower  AccuracyUpper   AccuracyNull
     0.9477977      0.9338612      0.9411986      0.9538570      0.2844617
AccuracyPValue  McnemarPValue
     0.0000000            NaN
```

The accuracy of the three models above on the testing set is the same as its performance on the training set. Time to answer the main question: how well are the 20 test subjects performing the barbell lifts?

####*Prediction of the unlabelled 20 test subjects*
The model with the best OOB estimate, random forest model, will be used to make the classification.

```r
##Test subjects classification
table(predict(Model1, test))
```

```

A B C D E
7 8 1 1 3
```

Since the accuracy of the 3 models are quite high, I wonder if they make the same prediction for each subject.

```r
identical(predict(Model1, test), predict(Model2, test), predict(Model3, test))
```

```
[1] TRUE
```

### Conclusion
Only 7 of the 20 test subjects performed the exercise exactly to specification.

branch_name: HEAD