text:
# Micro Batching
Accelerators like GPUs can be used most cost efficiently for inference if they are steadily fed with incoming data.
TorchServe currently allows a single batch to be processed per backend worker.
In each worker the three computation steps (preprocess, inference, postprocess) are executed sequentially.
Because pre- and postprocessing are often carried out on the CPU the GPU sits idle until the two CPU bound steps are executed and the worker receives a new batch.
The following example will show how to make better use of an accelerator in high load scenarios.

For this we are going to assume that there are a lot of incoming client requests and we can potentially fill a bigger batch size within the batch delay time frame where the frontend collects requests for the next batch.
Given this precondition we are going to increase the batch size which the backend worker receives and subsequently split the big batch up into smaller *micro* batches to perform the processing.
We can then perform the computation on the micro batches in parallel as more than one batches are available to the worker.
This way we can already process a micro batch on the GPU while the preprocessing is applied to remaining micro batches.
The pros and cons of this approach are as follow:

Pros:

*  Higher throughput by better utilizing the available accelerator
*  Lower overall latency when enough requests are available for computation

Cons:

* Potentially higher latency and lower throughput if not enough requests are available

## Implementation
This example implements micro batching using a custom handler which overwrites the *handle* method with a MicroBatching object defined in __ts.utils.micro_batching__.
```python
class MicroBatchingHandler(ImageClassifier):
    def __init__(self):
        mb_handle = MicroBatching(self)
        self.handle = mb_handle
```
The MicroBatching object takes the custom handler as an input and spins up a number of threads.
Each thread will work on one of the processing steps (preprocess, inference, postprocess) of the custom handler while multiple threads can be assigned to process the same step in parallel.
The number of threads as well as the size of the micro batch size is configurable through the [model yaml config](config.yaml):
```yaml
batchSize: 32
micro_batching:
  micro_batch_size: 4
  parallelism:
    preprocess: 2
    inference: 1
    postprocess: 2
```
Each number in the *parallelism* dictionary represents the number of threads created for the respective step on initialization.
The micro_batch_size parameter should be chosen much smaller than the batch size configured through the TorchServe API (e.g. 64 vs 4)

## Example
The following example will take a ResNet18 image classification model and run the pre- and postprocessing in parallel which includes resizing and cropping the image.

First, we need to download the model weights:
```bash
$ cd <TorchServe main folder>
$ wget https://download.pytorch.org/models/resnet18-f37072fd.pth
```
Second, we create the MAR file while including the necessary source and config files as additional files:
```bash
$ torch-model-archiver --model-name resnet-18_mb --version 1.0 --model-file ./examples/image_classifier/resnet_18/model.py --serialized-file resnet18-f37072fd.pth --handler examples/micro_batching/micro_batching_handler.py --extra-files ./examples/image_classifier/index_to_name.json --config-file examples/micro_batching/config.yaml
```
Our MicroBatchingHandler defined in [micro_batching_handler.py](micro_batching_handler.py) inherits from ImageClassifier which already defines the necessary pre- and postprocessing.

Third, we move the MAR file to our model_store and start TorchServe.
```bash
$ mkdir model_store
$ mv resnet-18_mb.mar model_store/
$ torchserve --start --ncs --model-store model_store --models resnet-18_mb.mar
```

Finally, we test the registered model with a request:
```bash
$ curl http://<IP_ADDRESS>:8080/predictions/resnet-18_mb -T ./examples/image_classifier/kitten.jpg
```
In the next section we will have a look at how the throughput and latency of the model behave by benchmarking it with TorchServe's benchmark tool.

## Results
For the following benchmark we use [benchmark-ab.py](../../benchmarks/benchmark-ab.py) and a ResNet50 instead of the smaller ResNet18.
We ran this benchmark on an AWS g4dn.4xlarge instance with a single T4 GPU.
After creating the MAR file as described above we extract it into the model_store so we do not need to upload the file.
```bash
$ unzip -d model_store/resnet-50_mb model_store/resnet-50_mb.mar
```
Subsequently, we can run the benchmark with:
```bash
$ python3 benchmarks/benchmark-ab.py --config benchmarks/config.json
```
The config.json for the benchmark has the following content:
```json
{
    "url":"/home/ubuntu/serve/model_store/resnet-50_mb/",
    "requests": 50000,
    "concurrency": 200,
    "input": "/home/ubuntu/serve/examples/image_classifier/kitten.jpg",
    "workers": "1",
    "batch_size": 64
}
```
This will run the model with a batch size of 64 and a micro batch size of 4 as configured in the config.yaml.
For this section we ran the benchmark with different batch sizes and micro batch sized (marked with "MBS=X") as well as different number of threads to create the following diagrams.
As a baseline we also ran the vanilla ImageClassifier handler without micro batching which is marked as "NO MB".
![](assets/throughput_latency.png)
In the diagrams we see the throughput and P99 latency plotted over the batch size (as configured through TorchServe API).
Each curve represents a different micro batch size as configured through [config.yaml](config.yaml).
We can see that the throughput stays flat for the vanilla ImageClassifier (NO MB) which suggests that the inference is preprocessing bound and the GPU is underutilized which can be confirmed with a look at the nvidia-smi output.
By interleaving the three compute steps and using two threads for pre- and postprocessing we see that the micro batched variants (MBS=4-16) achieve a higher throughput and even a lower batch latency as the GPU is better utilized due to the introduction of micro batches.
For this particular model we can achieve a throughput of up to 250 QPS by increasing the number of preprocessing threads to 4 and choosing 128 and 8 as batch size and micro batch size, respectively.
The actual achieved speedup will depend on the specific model as well as the intensity of the pre- and postprocessing steps.
Image scaling and decompression for example is usually more compute intense than text preprocessing.

## Summary
In summary we can see that micro batching can help to increase the throughput of a model while decreasing its latency.
This is especially true for workloads with compute intense pre- or postprocessing as well as smaller models.
The micro batching approach can also be used to save memory in a CPU use case by scaling the number if inference threads to >1 which allows to run multiple instances of the model which all share the same underlying weights.
This is in contrast to running multiple TorchServe worker which each create their own model instance which can not share their weights as they reside in different processes.

repository: pytorch/serve

repo_name: pytorch/serve


text:
This is a BT 3.0 SH plugin to run an Estimote iBeacon on iOS 6 devices.
Use to test iBeacons on older phones

To use this plugin:

1) update the name of the class to your custom class

eg: change AT_BlankScreenA to your class name

2) Update your appDelegate

eg: from BT_appDelegate to yourappname_appDelegate

3) change the custom class of the .xib file

eg: change AT_BlankScreenA to your class name

Use the AT_BlankScreenB class to create a plugin to detect Estimote iBeacons on iOS 6 devices.

beacons-demo
============

Simple demo apps to simulate Apple iOS7 iBeacon feature on iOS6 devices.

In order to make the Broadcaster and Receiver apps communicate smoothly you should generate your own BLE service and characteristic UUIDs:

+ open Terminal app, run «uuidgen» to generate a UUID
+ assign the UUID value to SERVICE_UUID in BluetoothServices.h in *both* projects
+ run «uuidgen» once again to get a new UUID
+ assign the new UUID value to CHARACTERISTIC_UUID in BluetoothServices.h in *both* projects

license: MIT

repository: skompdev/beacons-demo

branch_name: refs/heads/master

extension: md

license_type: permissive

repo_name: skompdev/beacons-demo


text:
---
layout: post
title: "Investigating Label Noise Sensitivity of Convolutional Neural Networks for Fine Grained Audio Signal Labelling"
date: 2018-05-28 12:02:26
categories: arXiv_SD
tags: arXiv_SD CNN
author: Rainer Kelz, Gerhard Widmer
mathjax: true
---

* content
{:toc}

##### Abstract
We measure the effect of small amounts of systematic and random label noise caused by slightly misaligned ground truth labels in a fine grained audio signal labeling task. The task we choose to demonstrate these effects on is also known as framewise polyphonic transcription or note quantized multi-f0 estimation, and transforms a monaural audio signal into a sequence of note indicator labels. It will be shown that even slight misalignments have clearly apparent effects, demonstrating a great sensitivity of convolutional neural networks to label noise. The implications are clear: when using convolutional neural networks for fine grained audio signal labeling tasks, great care has to be taken to ensure that the annotations have precise timing, and are free from systematic or random error as much as possible - even small misalignments will have a noticeable impact.

##### Abstract (translated by Google)
我们测量细粒度音频信号标记任务中微小偏差的地面真实标签引起的少量系统和随机标签噪声的影响。我们选择演示这些效果的任务也被称为帧边复音转录或音符量化多f0估计，并将单声道音频信号转换为音符指示标签序列。它将表明，即使轻微的不对齐也有明显的效果，表明卷积神经网络对标记噪声具有很高的灵敏度。其含义很明确：当使用卷积神经网络进行细粒度音频信号标记任务时，必须非常小心以确保注释具有精确的时序，并尽可能避免系统性或随机性错误 - 即使很小的错位也会有明显的影响。

##### URL
[http://arxiv.org/abs/1805.10880](http://arxiv.org/abs/1805.10880)

##### PDF
[http://arxiv.org/pdf/1805.10880](http://arxiv.org/pdf/1805.10880)


text:
<!-- @format -->

# Signed-Code

A template system for code generation.

## Installation

Install this module with the following command:

```sh
npm install signed-code
```

Add the module to your package.json dependencies:

```sh
npm install --save signed-code
```

Add the module to your package.json dev-dependencies:

```sh
npm install --save-dev signed-code
```

## Quick Start

```TS
import signedCode from "signed-code";
import SignedCode from "signed-code/SignedCode";
import SignedCodeBuilder from "signed-code/SignedCodeBuilder";

// Define the code template through the template function `signedCode`
const codeBuilder = (values): SignedCodeBuilder => signedCode`/**
 * Some sample code
 *
 * // Explain how to re-generate the code
 * ${signedCode.commandAnnotation("npm run gencode")}
 *
 * // Add required hash to recognize when code is out of date
 * ${signedCode.hashAnnotation()}
 *
 * // Add version to force re-generation when needed
 * ${signedCode.versionAnnotation(1)}
 */

// Define named manual sections for partially generated code.
// Code written here won't be calculated in the hash.
// Multiple of these are allowed each with a different name.
${signedCode.manualSection("import")}

// Write any value give into the template
const values = ${JSON.stringify(values)};

export default values;
`;

// Load already existing code
const previousCode = await SignedCode.load("/tmp/export.js");

// Get the hash from the old code
const previousHash = previousCode.getDerivedHash();

// Re-generate new code
const codeBuilder = codeGenTemplate([1, 2, 3, 4]);

// Add the manual sections from the old code to the newly generated code
codeBuilder.addPreviousCode(previousCode);

// Serialize the newly generated code into a string
const signedCode = codeBuilder.getCode();

// Get the hash from the new code
const newHash = signedCode.getDerivedHash();

// Avoid writing to disk if nothing changed
if (previousHash !== newHash) {
    await signedCode.save(apiRoutesFilePath);
    console.log("Done updating code.");
} else {
    console.log("Nothing to update.");
}
```

This code generates:

```TS
/**
 * Some sample code
 *
 * // Explain how to re-generate the code
 * @generated npm run gencode
 *
 * // Add required hash to recognize when code is out of date
 * @signed-hash 70541b0db6e93343bc6569604e0c4585
 *
 * // Add version to force re-generation when needed
 * @signed-version 1
 */

// Define named manual sections for partially generated code.
// Code written here won't be calculated in the hash.
// Multiple of these are allowed each with a different name.
// <Manual-Section START import>

// <Manual-Section END>

// Write any value give into the template
const values = [1, 2, 3, 4];

export default values;
```

## Check if code needs re-generation

```TS
import signedCode from "signed-code";
import SignedCode from "signed-code/SignedCode";
import SignedCodeBuilder from "signed-code/SignedCodeBuilder";

// Define the code template through the template function `signedCode`
const codeBuilder = (values): SignedCodeBuilder => signedCode`...`;

// Load already existing code
const code = await SignedCode.load("/tmp/export.js");

// Get the hash from the old code (from the hash annotation)
const previousHash = code.getContentHash();
const currentHash = code.getDerivedHash();
// Compare previousHash and currentHash

// Or check directly:
const isInvalid = code.isInvalid();

// Resign code, getting serialized string
const source = code.resign();
```

repository: marcelerz/signed-code

repo_name: marcelerz/signed-code


text:
# Changelog
Starting March 17, 2018 all notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Lazy Loading

## [1.1.4] - 2018-03-017
### Added
- This changelog!

### Changed
- Updated packages to fix vulernable dependency -- [ssri](https://nvd.nist.gov/vuln/detail/CVE-2018-7651)

repository: GusMonkeySoft/ng-simple-slideshow

repo_name: GusMonkeySoft/ng-simple-slideshow


text:
# net 15
Copyright (c) 2018 Bart Massey

Network server for "15" game in Rust. Start the server and play via

            telnet localhost 10015

The goal of "15" is to pick any three numbers that add up to
15 from the pool. The first person to have such a collection
in their hand wins. If neither player manages it before the
pool is exhausted, it's a draw.

There's a clever trick for playing perfect "15" as a
human. The server plays heuristically, so while you
can beat it you have to play carefully.

There are two branches in this repo. This one, `main`
contains a simple threaded version of the service. The
`async` branch contains a version written using
`async`/`await`.

This program is licensed under the "MIT License".
Please see the file LICENSE in the source
distribution of this software for license terms.

branch_name: refs/heads/main


text:
# Record Splitter Transform

Description
-----------
Given a field and a delimiter, emits one record for each split of the field.

Configuration
-------------
**Field to Split:** The field containing the value to split. (Macro-Enabled)

**Delimiter:** The delimiter that should be used to split the field. (Macro-Enabled)

**Output Field:** The name of the field in the output schema. (Macro-Enabled)

branch_name: refs/heads/develop

gha_language: Java


text:
# MakerBit

[![Build Status](https://travis-ci.org/1010Technologies/pxt-makerbit.svg?branch=master)](https://travis-ci.org/1010Technologies/pxt-makerbit)

![MakerBit](https://github.com/1010Technologies/pxt-makerbit/raw/master/icon.png "MakerBit")

The MakerBit connects to the BBC micro:bit to provide easy connections to a wide variety of sensors, actuators and other components.
This MakeCode extension includes our complete set of extensions for the MakerBit board.

http://makerbit.com/

| ![MakerBit](https://github.com/1010Technologies/pxt-makerbit/raw/master/MakerBit.png "MakerBit") | ![MakerBit+R](https://github.com/1010Technologies/pxt-makerbit/raw/master/MakerBit+R.png "MakerBit+R") |
| :----------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: |
|                                            _MakerBit_                                            |                                   _MakerBit+R with motor controller_                                   |

## Extensions & Notes

Bluetooth is disabled by default to save memory.

[MakerBit-Touch](https://github.com/1010Technologies/pxt-makerbit-touch)

[MakerBit-Motor](https://github.com/1010Technologies/pxt-makerbit-motor)

[MakerBit-MP3](https://github.com/1010Technologies/pxt-makerbit-mp3)

[MakerBit-LCD1602](https://github.com/1010Technologies/pxt-makerbit-lcd1602)

[MakerBit-Ultrasonic](https://github.com/1010Technologies/pxt-makerbit-ultrasonic)

[MakerBit-IR-Receiver](https://github.com/1010Technologies/pxt-makerbit-ir-receiver)

[MakerBit-IR-Transmitter](https://github.com/1010Technologies/pxt-makerbit-ir-transmitter)

[MakerBit-Pins](https://github.com/1010Technologies/pxt-makerbit-pins)

[MakerBit-HC-SR04-Clap](https://github.com/1010Technologies/pxt-makerbit-hc-sr04-clap)

## License

MIT

## Supported targets

- for PXT/microbit

## Build and Publish

Install (Mac):

```
git clone https://github.com/1010Technologies/pxt-makerbit.git
cd pxt-makerbit
sudo npm install -g pxt
pxt target microbit
pxt install
```

Build:

```
pxt build
```

Release/publish:

```
pxt bump
```

gha_language: TypeScript

gha_license_id: MIT


text:
# CrudResponder

### Embrace CRUD interface for your models

We should keep controllers skinny and don't repeat ourself, right? But this scaffolded action doesn't look very DRY:
```ruby
def create
  @post = Post.new(post_params)

  respond_to do |format|
    if @post.save
      format.html { redirect_to @post, notice: 'Post was successfully created.' }
      format.json { render :show, status: :created, location: @post }
    else
      format.html { render :new }
      format.json { render json: @post.errors, status: :unprocessable_entity }
    end
  end
end
```
You can make it simpler if you don't need to respond to anything but html, or use  [`responders`](https://github.com/plataformatec/responders) gem.

Let's assume we need only html and also add flash message on error:
```ruby
def create
  @post = Post.new(post_params)

  if @post.save
    redirect_to @post, notice: 'Post was successfully updated.' }
  else
    flash[:alert] = "Error updating post<EMAIL_ADDRESS>    render :edit
  end
end
```
But it's still not DRY because we have to repeat this code in every controller, and even a different action of the same controller:
```ruby
def update
  @post = Post.find(params[:id])

  if @post.update(post_params)
    redirect_to @post, notice: 'Post was successfully created.'
  else
    flash[:alert] = "Error creating post<EMAIL_ADDRESS>    render :new
  end
end
```
But the only differences between these actions are:
* Method called on a model
* Action on success
* Action on error
* Text in flash message on success
* Text in flash message on error

And they are repeated over and over again. Let's extract these differences:
```ruby
def create
  @post = Post.new(post_params)
  crud_respond @post # will call save, set flashes and redirects/render appropriately
end

def update
  @post = Post.find(params[:id])
  @post.assign_attributes(post_params)
  crud_respond @post # also call save
end

def destroy
  @post = Post.find(params[:id])
  crud_respond @post # call destroy because called from destroy action
end

```
Method to call on the object determined by the name of controller's action.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'crud_responder'
```

And then execute:

```Shell
  $ bundle install
```
Or install it yourself as:

```Shell
  $ gem install crud_responder
```
Generate initial files:

```Shell
$ rails g crud_responder:install
```

## Usage

Include `CrudResponder` into your `ApplicationController` (or whatever base controller you have). Note: generator already has included CrudResponder to Application controller.
```ruby
class ApplicationController
  include CrudResponder
end
```

Use `crud_respond` method with object you need to create, update or destroy. Optionally, you can pass options to this method to override default redirect and render actions
```ruby
def create
  @post = Post.new(post_params)
  crud_respond @post, success_url: root_path, error_action: :custom_new_action
  # will redirect to root_path in case of success or render :custom_new_action otherwise
end
```
By default you will be redirected to object show, objects index or back in this order. And render :new when creating object and :edit when updating.

You can specify `error_url` instead of `error_action` to be redirected instead of action render in case of error:
```ruby
def create
  @post = Post.new(post_params)
  crud_respond @post, success_url: root_path, error_url: 'https://google.com'
  # will redirect to root_path in case of success or to https://google.com otherwise
end
```
You can specify custom flash messages:
```ruby
def create
  @post = Post.new(post_params)
  crud_respond @post, success_message: 'Yep :)', error_message: 'Nope :('
  # will render flash 'Yep :)' on success or 'Nope :(' on failure instead of default ones
end
```

You can also specify per-controller default options:
```ruby
private

def crud_responder_default_options
  { success_url: root_path }
  # will redirect to `root_path` for every successful request in this controller
end
```

If  you need to create a bunch of objects (not just one) you can create wrapper class with same interface. For example, uploading multiple files:
```ruby
# app/controllers/media_items_controller.rb
class MediaItemsController < ApplicationController
  def create_multiple
    @media_item_multiple = MediaItem::CreateMultiple.new(media_item_create_multiple_params)
    crud_respond @media_item_multiple, success_url: media_items_path
  end

  private

  def media_item_create_multiple_params
    params.require(:media_item_create_multiple).permit(:description, files: [])
  end
end

# app/models/media_item/create_multiple.rb
class MediaItem::CreateMultiple
  include ActiveModel::Model

  attr_accessor :description, :files
  validates :files, presence: true

  def save
    return false unless valid?
     Also, you are forced to think in terms of CRUD interface to models and REST to controllers.

## TODO

* Support for pure API controllers (which is much simpler)
* Testing

Note about pure API controllers. I already use this idea:
```ruby
# somewhere in base controller for API
protected

def result(object, method = :save, options = {})
  method = :destroy if caller[0][/`.*'/][1..-2] == 'destroy'
  serializable_attrs = *options.fetch(:serializable_attrs, :id)
  if object.send method
    object_json(object, serializable_attrs)
    respond_with object, location: (method == :destroy ? nil : object_url(object))
  else
    fail UnprocessableEntityError, object.errors.full_messages.to_sentence
  end
end

def object_url(object)
  polymorphic_url(object)
rescue NoMethodError
  "there is no show route for #{object.class.name} object"
end

def object_json(object, serializable_attrs)
  object.instance_exec(serializable_attrs) do |attrs|
    @_s_attrs = attrs
    def to_json(*) # don't want to return the whole object on create/update
      hash = {}
      @_s_attrs.each do |attr|
        hash[attr] = try(attr) if try(attr)
      end
      hash.any? ? JSON.generate(hash) : ''
    end
  end
end
```
I'm thinking of extracting this as well plus adding support for [ActiveModelSerializers](https://github.com/rails-api/active_model_serializers).
Any feedback is welcome.

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/olegantonyan/crud_responder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.

## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

gha_language: Ruby


text:
# lead-to-contact
Script to connect your Intercom account with your HubSpot account. Converts leads to contacts. This script will run with Python3.x+

## Dependencies
The following is a list of python3 packages required to run the script
```shell
pip install json
pip install requests
```

repository: parthvshah/lead-to-contact

repo_name: parthvshah/lead-to-contact


text:
![](wautils.gif)

# Wild Apricot Flask Utilities
Web interface for maker space tool sign-offs implemented in python flask with Wild Apricot oauth and rest on the back end.

The Nova Labs Maker Space evaluated Wild Apricot as a possible solution for member managment. While CiviCRM was ultimately chosen. Methods for implementing a fairly complex tool sign-off system was explored.

[Wild Apricot](https://www.wildapricot.com/) is a commercial member management system for non-profits and clubs. It provides **oAuth** for authentication and a RESTful API.  If you prefer to code your web applications using **Python+Flask** I hope you find this useful to look at.

## Install
 ```git clone (this repo)
 cd (this repo)
 python3 -m venv venv
 source venv/bin/activate
 pip3 install -r requirements.txt

 ```
## Run
```python3 app.py```
Connect by browsing to http://localhost:8080

## Walk through
On page load, flask delivers **wautils.js** which implements the UI. On the server, **app.py** implements a series of RESTful endpoints.  When the user clicks on **login**, it call **/authorize/wildapricot** Which checks with wildapricot for a valid oauth session and token. If none exists, the user will be redirected to the wild   apricot login/password window to be authenticated.

Once authenticated, the flask server establishes a login session and renders the **utils** page. It checks with wildapricot to determine if the user has wild apricot admin credentials. If so, the user is allowed to continue to the **utils** page. Currently, the only functionality is signoffs and a link is provided.

For all pages, the server makes a call to wildapricot to establish if the user has wilapricot admin credentials and congratulates the user if they do. The  **signoffs** page is restricted to admins and will not render unless the user is authorized.

Once at the signoffs is loaded, **wautils.js** Begins to make use of the very powerful **get_any_endpoint** call to the server. At this point the server acts as a simple pass-through to wildpapricot. Any API endpoint implemented by wildapricot could be  easily implemented in the js.
The signoffs page requests a list of all contact fields available via the**contactfields** endpoint.  Tool sign-offs are implemented as a series of checkboxes in wildapricot. The users names and signoffs are rendered. If the user clicks on the edit button for  a user, they are sent to a page where they can edit the users individual signoffs. the **save** button will update the user's record.

gha_language: Python


text:
# Creating A Validator

{% hint style="info" %}
Before we proceed, we need to create a new Validator Wallet which will need to be funded with 10001 ONE
{% endhint %}

## 1. Creating A New Validator Wallet

You need to provide a local account name of your choice and provide a passphrase. When creating an account, the CLI will ask you to provide a passphrase to encrypt the keystore file:\
\
**./hmy keys add \[LOCAL ACCOUNT NAME] --passphrase** example :

```
./hmy keys add mylocalaccountname --passphrase
```

{% hint style="danger" %}
Remember your passphrase. You will need it to decrypt the account keystore in order to send transactions & perform other actions.

 You may want to create a backup of this file.

You can check the list of wallets (local accounts) with the following command:

```bash
./hmy keys list
```

Example output from above command:

```bash
#NAME                                  ADDRESS
example-account1                      one1wh4p0kuc7unxez2z8f82zfnhsg4ty6dupqyjt2
```

### Checking Account Balance

Use the following command to check your balance : **./hmy --node="\[API\_endpoint]" balances \[ONE ADDRESS]** ex:

{% tabs %}
{% tab title="Mainnet" %}
```bash
./hmy --node="https://api.s0.t.hmny.io" balances one1u6c4wer2dkm767hmjeehnwu6tqqur62gx9vqsd
```
{% endtab %}

{% tab title="Testnet" %}
```bash
./hmy --node="https://api.s0.b.hmny.io" balances one1u6c4wer2dkm767hmjeehnwu6tqqur62gx9vqsd
```
{% endtab %}
{% endtabs %}

## 2. Creating a Validator

{% hint style="info" %}
For you to create a Validator successfully, it needs to have 10000 ONE tokens plus the necessary fees to create the validator transaction on chain. For this reason, we recommend that you send at least 10001 ONE tokens to your `--validator-addr`before you continue.

 **Extra white spaces in the command could cause errors.**

Name, identity, details, security-contact and website need to be put in double quotes if there are more than one word separated by space (example --name "John the validator").
{% endhint %}

The CLI will prompt you to enter your BLS key file password.

`--validator-addr` is the validator ONE address **(string)**

`--amount` is the initial amount of ONE you want to stake **(float)**

`--bls-pubkeys` takes a comma-separated list of BLS public keys **(string)**

`--name` will be the name displayed on the Staking Explorer **(string)**

`--identity` unique identifier for the validator **(string)**

`--details` is the description of the validator **(string)**

`--security-contact` is security contact for the validator **(string)**

`--website` will be the website displayed on the Staking Explorer **(string)**

`--max-change-rate` is the maximum rate change the validator can do to their commission rate every epoch **(float)**

`--max-rate` is the maximum commission rate that the validator can set **(float)**

`--rate` is the commission rate of the validator **(float)**

`--max-total-delegation` is the maximum amount of ONE that can be delegated to this validator **(float)**

`--min-self-delegation` is the minimum amount of ONE the validator must stake to itself **(float)**

{% hint style="danger" %}
`--max-rate` and `--max-change-rate` cannot be changed later.

`--min-self-delegation` has to be at least 10,000 ONE.
{% endhint %}

{% hint style="info" %}
`--rate`, `--max-rate`, and `--max-change-rate` accepts numbers between 0 and 1 representing percentages
{% endhint %}

{% hint style="info" %}
If you have a Keybase account, we recommend you use your [Keybase public key fingerprint ](managing-a-validator/adding-a-validator-logo.md#using-keybase-recommended)as your validator's identity. The field is unique, ensuring that other validator's can not attempt to impersonate you. This data will also help with some awesome integrations & features in the future!
{% endhint %}

repository: harmony-one/docs-home

repo_name: harmony-one/docs-home


text:
## Integrating Amazon API Gateway private endpoints with on-premises networks

Read the blog about this application:
[Integrating Amazon API Gateway private endpoints with on-premises networks](https://aws.amazon.com/blogs/compute/integrating-amazon-api-gateway-private-endpoints-with-on-premises-networks/)

### Requirements for deployment

* AWS CLI
* AWS SAM CLI
* AWS credentials that provide the necessary permissions to create the resources. This example uses admin credentials.
* Amazon VPN or AWS Direct Connect with routing rules that allow DNS traffic to pass through to the Amazon VPC.

### Deploying

In the terminal, use the SAM CLI guided deployment the first time you deploy

1. Navigate to the cloned repo directory. Alternatively, use the sam init command and paste the repo URL.

3.	Build the AWS SAM application:
```bash
sam build
```
4.	Deploy the AWS SAM application:
```bash
sam deploy –guided
```

## Cleanup
1. Open the CloudFormation console
1. Locate the stack using the name entered in SAM deployment.
1. Select the radio option next to it
1. Select **Delete**
1. Select **Delete stack** to confirm

## Security

See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.

## License

This library is licensed under the MIT-0 License. See the LICENSE file.


text:
# Website performance with Sitespeed.io
[![Regression Test - Performance (Sitespeed.io) Test](https://github.com/Webperf-se/webperf_core/actions/workflows/regression-test-sitespeed.yml/badge.svg)](https://github.com/Webperf-se/webperf_core/actions/workflows/regression-test-sitespeed.yml)

Add small description of what this test is.

## What is being tested?

We will startup the URL specified with a normal browser for X iterations with different subtests.
You specify the number of iterations to use in your [config.py file](../config-py.md), 3 iterations or more are recommended to get most stable rating.
The subtests we use are:
* Desktop (Configured as: Laptop size, full network speed of the system)
* Mobile (Configured as: Mobile size, 3G Fast network speed)

For every subtest we are using following metrics are used:
* [SpeedIndex](https://docs.webpagetest.org/metrics/speedindex/)
* [TTFB (Time to First Byte)](https://web.dev/ttfb/)
* [TBT (Total Blocking Time)](https://web.dev/tbt/) [Alternative reference](https://developer.chrome.com/docs/lighthouse/performance/lighthouse-total-blocking-time/#how-lighthouse-determines-your-tbt-score)
* [FCP (First Contentful Paint)](https://web.dev/fcp/)
* [LCP (Largest Contentful Paint)](https://web.dev/lcp/)
* [CLS (Cumulative Layout Shift)](https://web.dev/cls/)
* FirstVisualChange
* VisualComplete85
* Load

The URL are only rated on "Desktop" and "Mobile", the others are only there to give you hints on what can improve.
We are using different values to rate the URL depending on it is for the subtest "Desktop" or "Mobile", you can read more about them below:

### Desktop rating metrics
For `SpeedIndex`, `FirstVisualChange`, `VisualComplete85` and `Load` you will get 5.0 points if you are at or below `500ms`, after that you will get penalty for every ms you are above.
For `CLS (Cumulative Layout Shift)` you will get 5.0 points if you are at or below `0.1ms`, 3.0 points if you are at or below `0.25ms`, else you will get 1.0.
For `LCP (Largest Contentful Paint)` you will get 5.0 points if you are at or below `500ms`, 3.0 points if you are at or below `1000ms`, else you will get 1.0.
For `FCP (First Contentful Paint)` you will get 5.0 points if you are at or below `1800ms`, 3.0 points if you are at or below `3000ms`, else you will get 1.0.
For `TBT (Total Blocking Time)` you will get 5.0 points if you are at or below `200ms`, 3.0 points if you are at or below `600ms`, else you will get 1.0.
For `TTFB (Time to First Byte)` you will get 5.0 points if you are at or below `250ms`, 3.0 points if you are at or below `450ms`, else you will get 1.0.

### Mobile rating metrics
For `SpeedIndex`, `FirstVisualChange`, `VisualComplete85` and `Load` you will get 5.0 points if you are at or below `1500ms`, after that you will get penalty for every ms you are above.
For `CLS (Cumulative Layout Shift)` you will get 5.0 points if you are at or below `0.1ms`, 3.0 points if you are at or below `0.25ms`, else you will get 1.0.
For `LCP (Largest Contentful Paint)` you will get 5.0 points if you are at or below `1500ms`, 3.0 points if you are at or below `2500ms`, else you will get 1.0.
For `FCP (First Contentful Paint)` you will get 5.0 points if you are at or below `1800ms`, 3.0 points if you are at or below `3000ms`, else you will get 1.0.
For `TBT (Total Blocking Time)` you will get 5.0 points if you are at or below `200ms`, 3.0 points if you are at or below `600ms`, else you will get 1.0.
For `TTFB (Time to First Byte)` you will get 5.0 points if you are at or below `800ms`, 3.0 points if you are at or below `1800ms`, else you will get 1.0.

### Customization and Advices

If you want to test the impact of a change before implementing it on your server in production you can configure webperf-core to simulate the change first.
You can do this by changing copy `SAMPLE-sitespeed-rules.json` and creating `sitespeed-rules.json` and changing it's content.

This file can contain 1 or more subtests.
Below is an example that will be showed in review as `mobile, no images`.
Property `use_reference` tells webperf-core if it should only show lines that are are improvment (`use_reference = True`) or if it should show all lines.
In below example we tell webperf-core to show all lines.
There are possible to change HTML or HTTP Response Headers of document (pages), in below example we add/change header `Content-Security-Policy`
to not allow any images.

```
    {
        "name": "mobile, no images",
        "use_reference": false,
        "headers": [
            {
                "name": "Content-Security-Policy",
                "value": "img-src%20\"none\";"
            }
        ]
    }
```

This is an other example showing a subtest that changes the HTML.
In this case replacing all `<script ` with `<script defer `.
```
    {
        "name": "mobile, defer scripts",
        "use_reference": true,
        "htmls": [
            {
                "replace": "<script ",
                "replaceWith": "<script defer "
            }
        ]
    }
```

You can have up to 10 headers changes and 10 HTML changes in every subtest.
There are no limit on how many subtests you can have.

## Read more

* https://www.sitespeed.io/documentation/sitespeed.io/

## How to setup?

This section has not been written yet.

### Prerequirements

* Fork this repository

### Setup with GitHub Actions

Read more on the [general page for github actions](../getting-started-github-actions.md).

### Setup Locally

* Follow [general local setup steps for this repository](../getting-started-local.md)

#### Using NPM package

##### On Linux:
* Update apt-get `sudo apt-get update -y` ( Not needed if you have latest version )
* Install image library `sudo apt-get install -y imagemagick libjpeg-dev xz-utils --no-install-recommends --force-yes`
* Upgrade PIP `python -m pip install --upgrade pip` ( Not needed if you have latest version )
* Install setuptools `python -m pip install --upgrade setuptools`
* Install ... `python -m pip install pyssim Pillow image`
* Install ffmpeg `sudo apt install ffmpeg`
* Download and install Node.js (v1 version 18.x)
* Download and install Google Chrome browser
* Install SiteSpeed NPM package ( `npm install sitespeed.io` )
* Set `sitespeed_use_docker = False` in your `config.py`

(You can always see [GitHub Actions SiteSpeed](../../.github/workflows/regression-test-sitespeed.yml) for all steps required line by line)

##### On Windows:

* Upgrade PIP `python -m pip install --upgrade pip` ( Not needed if you have latest version )
* Install setuptools `python -m pip install --upgrade setuptools`
* Install ... `python -m pip install pyssim Pillow image`
* Download and Install ffmpeg `https://ffmpeg.org/download.html#build-windows`
* Install SiteSpeed NPM package ( `npm install sitespeed.io` )
* Set `sitespeed_use_docker = False` in your `config.py`

#### Using Docker image

* Make sure Docker command is globally accessible on your system.
* Set `sitespeed_use_docker = True` in your `config.py`

## FAQ

No frequently asked questions yet :)


text:
# [PROJECT TITLE](http://richardprice.com)

(http://richardprice.com)

Hello World Example

## Quickstart

To get going with "Hello World" you can: open helloWorld.html in the browser of your choice.

## Dependencies

N/A

### File Structure

Copyright (c) 2014 Richard Price.

repository: richexperiences/helloWorld

repo_name: richexperiences/helloWorld


text:
---
layout: post
title:  "Learning SQL Part 2"
date:   2020-07-04 15:30
tags: sql database
navigation: true
class: post-template
current: post
---

Here are more notes from my SQL course on youtube.

I'm going to disect the below query:

```sql
SELECT *
FROM student
ORDER BY student_id DESC
LIMIT 2;
```

In this query, we are selecting everything in the student table. We are ordering it by student id in descending order, and we are asking for only 2 rows.

When you use the SELECT keyword we are getting data returned to us from the database

### Filtering

Can use the WHERE keyword again to filter our data being returned from the database, like below:

```sql
SELECT *
FROM student
WHERE major = 'Biology' OR major = 'Chemistry';
```

Note that you can also use comparison operators in your SQL queries:

<, >, <=, >=, =, <>, AND, OR

Where <> in this case means "not equal to".

The IN keyword is used here:

```sql
SELECT *
FROM student
WHERE name IN ('Claire', 'Kate', 'Mike');
```

This statement is basically saying "where the name is one of these values" that we have in the parentheses.

### Adding a foreign key

When creating the employee table for a new company database, we couldn't make any foreign keys since the table didn't exist yet. Now we are going back to add the foreign keys:

```sql
/*just including this query for reference*/
CREATE TABLE employee(
    emp_id INT PRIMARY KEY,
    first_name VARCHAR(40),
    last_name VARCHAR(40),
    birth_day DATE,
    sex VARCHAR(1),
    salary INT,
    super_id INT,
    branch_id INT
);

ALTER TABLE employee
ADD FOREIGN kEY(branch_id)
REFERENCES branch(branch_id)
ON DELETE SET NULL;
```

In the above query, we are altering the employee table. We are adding a foreign key to branch_id. It is referencing the branch table (which hasn't been created at this point)

### AS keyword

To get data from your database but under a different column name, do this. In this example we want to get first name, but we want it to be called forename, and last name, but we want it to be called surname. We use the AS keyword.

```sql
SELECT first_name AS forename, last_name AS surname
FROM employee;

```

### DISTINCT keyword

If we wanted to find all the different genders that employees are stored as,

```sql
SELECT DISTINCT sex
FROM employee;
```

In this case it just returns M and F.

### SQL functions

There are functions in SQL as well.

COUNT: returns the count of something - we could count the number of employees in our company by using:

```sql
SELECT COUNT(emp_id) FROM employee;
```

AVG: find the average of something, like:
```sql
SELECT AVG(salary) FROM employee;
```

SUM: finds the sum

### Wildcards

LIKE: put an expression inside, defining a pattern that matches whatever you're searching in

Special characters:
% means "any number of characters",
_ means "one character"

Use the special characters to define patterns.

The below query is saying "return any client name that has any number of characters and then LLC"

```sql
SELECT *
FROM client
WHERE client_name LIKE '%LLC';
```

To get all birthdays in October, use _ four times to give any four digit year and include 10 for the month of October.
```sql
SELECT *
FROM employee
WHERE birth_day LIKE '____-10%';
```

### UNION

Use UNION to combine results of multiple SELECT statements into one result. Everything will be returned in one table.

Here we are grabbing all names and branches. Both need to be the same data type and same number of columns.

```sql
SELECT first_name
FROM employee
UNION
SELECT branch_name
FROM branch;
```

### JOIN

JOIN is used to combine rows from two or more tables. There are four different types of JOIN. The below is an "inner" join.

```sql
SELECT employee.emp_id, employee.first_name, branch.branch_name
FROM employee
JOIN branch
ON employee.emp_id = branch.mgr_id;
```

Here when we say JOIN it means join the employee table and the branch table together into one table, on a specific column that the tables have in common. Combine them when the branch manager id is equal to the employee id.

LEFT JOIN: we include all rows from the "left" table, or the table we are selecting "from". A left join would look like...

```sql
SELECT employee.emp_id, employee.first_name, branch.branch_name
FROM employee
LEFT JOIN branch
ON employee.emp_id = branch.mgr_id;
```

...and it would return all the rows from the employee table, where we are selecting from.

RIGHT JOIN: does the opposite of above, it would include all the rows from the branch table no matter what.

Full outer join: can't do it in MySQL, but it is a left and right join combined.

## What happens when data is deleted?

ON DELETE SET NULL: if data is deleted in one table, set another related value to null

In our CREATE TABLE code...
```sql
CREATE TABLE branch(
    branch_id INT PRIMARY KEY,
    branch_name VARCHAR(40),
    mgr_id INT,
    mgr_start_date DATE,
    FOREIGN KEY(mgr_id) REFERENCES employee(emp_id) ON DELETE SET NULL
);
```
...we are saying "if the branch manager employee id is deleted, set the manager id in this table to NULL".  So if we go to the employee table and delete a branch manager, their id in the branch table will be set to NULL. We're able to do this because it is a foreign key and not totally essential to the table.

ON DELETE CASCADE: if data is deleted, delete the whole row

```sql
CREATE TABLE branch_supplier(
    branch_id INT,
    supplier_name VARCHAR(40),
    supply_type VARCHAR(40),
    PRIMARY KEY(branch_id, supplier_name),
    FOREIGN KEY(branch_id) REFERENCES branch(branch_id) ON DELETE CASCADE
);
```

In our example, there are suppliers that supply product to different branches of the company.  In this situation, if we deleted a branch, all rows in the branch_supplier table associated with the branch would be deleted.

This is important for primary keys, because a primary key cannot be null.

gha_language: HTML


text:
# FaceTracking
An example app with AVFoundation camera support and face features tracking written in Swift 3.0.

Below an example how it works.

<img src="https://github.com/DroidsOnRoids/FaceTracking/blob/master/app_example.PNG" width="300">

repository: DroidsOnRoids/FaceTracking

gha_language: Swift

repo_name: DroidsOnRoids/FaceTracking


text:
# Django

## Install
#### Setup virtualenv environment
- `mkdir ~/.virtualenvs`
- `python3 -m venv ~/.virtualenvs/djangodev`
- `sudo apt-get install python3-pip`
- `pip3 install virtualenv`
- `virtualenv --python=`which python3`
- `~/.virtualenvs/djangodev`
- `source ~/.virtualenvs/djangodev/bin/activate`

#### Setup django project
- `django-admin startproject mysite`

#### Connecting to postgres
- `pip install psycopg2`
- Go to project/settings.py and change:
  - `TIME_ZONE = 'Europe/Berlin'`
  - the DATABASE part:

```
DATABASES = {
    'default': {
        'ENGINE':  'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydb',
        'USER': 'postgres',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '',
    }
}
```
- run `python manage.py migrate`
  - This should create the default tables in your db, that you should see using pgAdmin3
  - Now that your **environment** – a “project” – is set up, you’re set to start doing work.

## Part 1 - First View
**Application setup**
- `python manage.py startapp polls`

**urls**
- The **environment** `urls.py` is responsible for the routing. It uses regex to match the URL parts and then return the requested views.
  - In this case we want to **forward** requests coming to the "poll" project to the poll project's url router.
  - The include function does exactly that. It strips the matched part from `url.../polls/blah` and thus forwards `/blah` to the polls.urls.
  - All Django wants is that HttpResponse. Or an exception.

  ```python
  urlpatterns = [
      url(r'^polls/', include('polls.urls')),
      url(r'^admin/', admin.site.urls),
  ]
  ```

- Then in the `polls/url.py` we define the following:

 ```python
 urlpatterns = [
     url(r'^$', views.index, name='index'),
 ]
 ```
    - If there is nothing behind the `/` we return the index.

## Part 2 - Models and Data management
#### Managing models
- Django classes that extend `model.Model` will be your tables.
- And the classes' props will be your columns in the table.

- You can use an optional first positional argument to a Field to designate a human-readable name. (As done in `pub_date`)

  ```python
  class Question(models.Model):
      question_text = models.CharField(max_length=200)
      pub_date = models.DateTimeField('date published')

  class Choice(models.Model):
      question = models.ForeignKey(Question, on_delete=models.CASCADE)
      choice_text = models.CharField(max_length=200)
      votes = models.IntegerField(default=0)
  ```

- Finally we need to tell our project (mysite) that ie needs to consider the polls project's configuration when doing migrations. To include the app in our project, we need to add a reference to its configuration class in the INSTALLED_APPS. --> mysite/settings.py `INSTALLED_APPS = ['polls.apps.PollsConfig', ...]` (See polls/apps.py --> class PollsConfig)
- In the end apply the changes via `python manage.py makemigrations
`
- You see the resulting file in the polls/migrations folder. To see them in pure SQL format you can run `python manage.py sqlmigrate polls 0001`
- Run `python manage.py check` as a final test to see if we don't mess up anything with the migration.
- Finally `python manage.py migrate`

#### Managing data in the DATABASE
- Once you’ve created your data models, Django automatically gives you a database-abstraction API that lets you create, retrieve, update and delete objects.

- In dir containing manage.py: `export DJANGO_SETTINGS_MODULE="mysite.settings"`
- `python`
- `import django` --> (wait a bit, be patient)
- `django.setup()`

```python
from polls.models import Question, Choice
Question.objects.all() # = SELECT * From Question

# Creating a Question
from django.utils import timezone
q = Question(question_text="What's new?", pub_date=timezone.now())
q.save()
q.id # After save q has an assigned id.
Question.objects.all() # <QuerySet [<Question: Question object>]> --> unhelpful
```

- To make it more descriptive we add info to our model.py --> `def __str__(self): return self.question_text`
- Once done so, restart the shell via `python manage.py shell`

```python
from polls.models import Question, Choice
q = Question.objects.get(pk=1)
q.choice_set.all() #Display choice_set
q.choice_set.create(choice_text='Not much', votes=0)
q.choice_set.create(choice_text='The sky', votes=0)
q.choice_set.create(choice_text='Just hacking again', votes=0)
q.choice_set.all()

c = q.choice_set.filter(choice_text__startswith='Just hacking')
c.delete()
q.choice_set.all()
```

#### Django admin
- Run `python manage.py createsuperuser` to set up the credentials.
- Run the server `python manage.py runserver`
- `http://<IP_ADDRESS>:8000/admin/`
- Our question model is not seen in the admin interface. To add it go to `admin.py` and add the following:

```python
from django.contrib import admin
from .models import Question
admin.site.register(Question)
```

## Part 3 Writing view templates

#### Decoupling view from python code - Returning a template
- There’s a problem here, though: the page’s design is hard-coded in the view. If you want to change the way the page looks, you’ll have to edit this Python code. So let’s use Django’s template system to separate the design from Python by creating a template that the view can use.
  - Create a `templates` diretory in `polls`, and create a `polls` inside `templates`. Add an `index.html` to this folder. n other words, your template should be at `polls/templates/polls/index.html`. Later you will refer to this as `polls/index.html`
  - Insert the django HTML [template](https://docs.djangoproject.com/en/1.11/intro/tutorial03/)

  ```python
  {% if latest_question_list %}
      <ul>
      {% for question in latest_question_list %}
          <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
      {% endfor %}
      </ul>
  {% else %}
      <p>No polls are available.</p>
  {% endif %}
  ```

  - And make the `view.py` to load our template. Note that we are passing `latest_question_list` in the context, thus it is available in our HTML template as a variable.

  ```python
  from django.template import loader
  from .models import Question

  def index(request):
      latest_question_list = Question.objects.order_by('-pub_date')[:5]
      template = loader.get_template('polls/index.html')
      context = {'latest_question_list': latest_question_list}
      return render(request, 'polls/index.html', context)
      # return HttpResponse(template.render(context, request))
  ```

  - The `render()` method provides a shortcut for rendering the context and returning it as an HttpResponse. and returning it as an HttpResponse.

#### Decoupling view from python code - Returning an error
- Assume that the user is looking for a question with an ID, that doesn't exist. We want to raise a 404 error by rendering it:

  ```python
  def detail(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    return render(request, 'polls/detail.html', {'question': question})
  ```

- Add `{{ question }}` to `polls/detail.html`.
- Now `http://<IP_ADDRESS>:8000/polls/1/` should be okay, but `/2/` should give you a 404 page.

- Now you might want to change the `detail.html` to the following:

  ```python
  <h1>{{ question.question_text }}</h1>
  <ul>
  {% for choice in question.choice_set.all %}
      <li>{{ choice.choice_text }}</li>
  {% endfor %}
  </ul>
```
  - question.choice_set.all is interpreted as the Python code question.choice_set.all(), which returns an iterable of Choice objects and is suitable for use in the {% for %} tag.
  - See the [full template guide](https://docs.djangoproject.com/en/1.11/topics/templates/)

- Note that `<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>` in `index.html` is still tightly coupled. Since in `polls/urls.py` we have defined the mappings this can be rewritten as: `<li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li>`
- However what happens when you have "detail" url in many of your applications? --> NAMESPACE is the answer. --> Add `app_name = 'polls'` above your `urlpatterns`. Now you can change the referencing in `index.html` to `<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>`

## Part 4 Writing forms
#### The voting form
Let's modify detail.html

```python
<h1>{{ question.question_text }}</h1>

{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}

<form action="{% url 'polls:vote' question.id %}" method="post">
{% csrf_token %}
{% for choice in question.choice_set.all %}
    <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" />
    <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br />
{% endfor %}
<input type="submit" value="Vote" />
</form>
```

- The above template displays a radio button for each question choice. The value of each radio button is the associated question choice’s ID. The name of each radio button is "choice". That means, when somebody selects one of the radio buttons and submits the form, it’ll send the POST data choice=value where value is `{{ choice.id }}` the ID of the selected choice. This is the basic concept of HTML forms.
- Since we’re creating a POST form (which can have the effect of modifying data), we need to worry about Cross Site Request Forgeries. Thankfully, you don’t have to worry too hard, because Django comes with a very easy-to-use system for protecting against it. In short, all POST forms that are targeted at internal URLs should use the {% csrf_token %} template tag.

Let's vire up the vote in the url configuration: `url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),` and change our vote function:

```python
def vote(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    try:
        selected_choice = question.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        # Redisplay the question voting form.
        return render(request, 'polls/detail.html', {
            'question': question,
            'error_message': "You didn't select a choice.",
        })
    else:
        selected_choice.votes += 1
        selected_choice.save()
        # Always return an HttpResponseRedirect after successfully dealing
        # with POST data. This prevents data from being posted twice if a
        # user hits the Back button.
        return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))

def results(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    return render(request, 'polls/results.html', {'question': question})
```
- Request.POST is a dictionary-like object that lets you access submitted data by key name. Request.POST values are always strings.
- request.POST['choice'] will raise KeyError if choice wasn’t provided in POST data. --> check!

Add the `results.html` that we will use:

```python
<h1>{{ question.question_text }}</h1>

<ul>
{% for choice in question.choice_set.all %}
    <li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li>
{% endfor %}
</ul>

<a href="{% url 'polls:detail' question.id %}">Vote again?</a>
```

#### Django's generic views:
- These views represent a common case of basic Web development: getting data from the database according to a parameter passed in the URL, loading a template and returning the rendered template. Because this is so common, Django provides a shortcut, called the “generic views” system.
- First, open the polls/urls.py URLconf and change it like so:

```python
app_name = 'polls'
urlpatterns = [
    url(r'^$', views.IndexView.as_view(), name='index'),
    url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
    url(r'^(?P<pk>[0-9]+)/results/$', views.ResultsView.as_view(), name='results'),
    url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
]
```

- Note that the name of the matched pattern in the regexes of the second and third patterns has changed from <question_id> to <pk>.
- Also change the views.py

```python
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views import generic

from .models import Choice, Question

class IndexView(generic.ListView):
    template_name = 'polls/index.html'
    context_object_name = 'latest_question_list'

    def get_queryset(self):
        """Return the last five published questions."""
        return Question.objects.order_by('-pub_date')[:5]

class DetailView(generic.DetailView):
    model = Question
    template_name = 'polls/detail.html'

class ResultsView(generic.DetailView):
    model = Question
    template_name = 'polls/results.html'

def vote(request, question_id):
    ... # remains the same
```
- Each generic view needs to know what model it will be acting upon. This is provided using the model attribute.
- The DetailView generic view expects the primary key value captured from the URL to be called "pk", so we’ve changed question_id to pk for the generic views.
- The template_name attribute is used to tell Django to use a specific template name instead of the autogenerated default template name.
- In previous parts of the tutorial, the templates have been provided with a context that contains the question and latest_question_list context variables. For DetailView the question variable is provided automatically – since we’re using a Django model (Question), Django is able to determine an appropriate name for the context variable. However, for ListView, the automatically generated context variable is question_list. To override this we provide the context_object_name attribute, specifying that we want to use latest_question_list instead.

## Part 5 - Testing
#### Testing functionality
- But in the code: Question.was_published_recently() method returns True if the Question was published within the last day (which is correct) but also if the Question’s pub_date field is in the future .
- We will place the tests in the `polls/test.py`

```python
import datetime

from django.utils import timezone
from django.test import TestCase

from .models import Question

class QuestionModelTests(TestCase):

    def test_was_published_recently_with_future_question(self):
        """
        was_published_recently() returns False for questions whose pub_date
        is in the future.
        """
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)
        self.assertIs(future_question.was_published_recently(), False)
```

- Run the tests with `python manage.py test polls`. Note that for testing a new DB is created.
- Now fix the bug in `polls/models.py`

```python
def was_published_recently(self):
    now = timezone.now()
    return now - datetime.timedelta(days=1) <= self.pub_date <= now
```

#### Testing a view
- The polls application is fairly undiscriminating: it will publish any question, including ones whose pub_date field lies in the future. We should improve this. Setting a pub_date in the future should mean that the Question is published at that moment, but invisible until then.
- Django provides a test Client to simulate a user interacting with the code at the view level. We can use it in tests.py or even in the shell.
- Open up the python shell and execute the following:
  - `from django.test.utils import setup_test_environment`
  - `setup_test_environment()`
    - setup_test_environment() installs a template renderer which will allow us to examine some additional attributes on responses such as response.context that otherwise wouldn’t be available.
  - `from django.test import Client`
  - `client = Client()`
  - `response = client.get('/')`
  - `response.status_code` --> prints 404
  - `from django.urls import reverse`
  - `response = client.get(reverse('polls:index'))`
  - `response.status_code`

#### Improving our view
- The list of polls shows polls that aren’t published yet (i.e. those that have a pub_date in the future). Let’s fix that. We need to amend the get_queryset() method and change it so that it also checks the date by comparing it with timezone.now().

```python
from django.utils import timezone

def get_queryset(self):
    """
    Return the last five published questions (not including those set to be
    published in the future).
    """
    return Question.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[:5]
```

#### Testing the new view

```python
from django.urls import reverse

def create_question(question_text, days):
    """
    Create a question with the given `question_text` and published the
    given number of `days` offset to now (negative for questions published
    in the past, positive for questions that have yet to be published).
    """
    time = timezone.now() + datetime.timedelta(days=days)
    return Question.objects.create(question_text=question_text, pub_date=time)

class QuestionIndexViewTests(TestCase):
    def test_no_questions(self):
        """
        If no questions exist, an appropriate message is displayed.
        """
        response = self.client.get(reverse('polls:index'))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "No polls are available.")
        self.assertQuerysetEqual(response.context['latest_question_list'], [])

    def test_past_question(self):
        """
        Questions with a pub_date in the past are displayed on the
        index page.
        """
        create_question(question_text="Past question.", days=-30)
        response = self.client.get(reverse('polls:index'))
        self.assertQuerysetEqual(
            response.context['latest_question_list'],
            ['<Question: Past question.>']
        )

    def test_future_question(self):
        """
        Questions with a pub_date in the future aren't displayed on
        the index page.
        """
        create_question(question_text="Future question.", days=30)
        response = self.client.get(reverse('polls:index'))
        self.assertContains(response, "No polls are available.")
        self.assertQuerysetEqual(response.context['latest_question_list'], [])

    def test_future_question_and_past_question(self):
        """
        Even if both past and future questions exist, only past questions
        are displayed.
        """
        create_question(question_text="Past question.", days=-30)
        create_question(question_text="Future question.", days=30)
        response = self.client.get(reverse('polls:index'))
        self.assertQuerysetEqual(
            response.context['latest_question_list'],
            ['<Question: Past question.>']
        )

    def test_two_past_questions(self):
        """
        The questions index page may display multiple questions.
        """
        create_question(question_text="Past question 1.", days=-30)
        create_question(question_text="Past question 2.", days=-5)
        response = self.client.get(reverse('polls:index'))
        self.assertQuerysetEqual(
            response.context['latest_question_list'],
            ['<Question: Past question 2.>', '<Question: Past question 1.>']
        )
```

- What we have works well; however, even though future questions don’t appear in the index, users can still reach them if they know or guess the right URL. So we need to add a similar constraint to DetailView.
- In `polls/view.py`

```python
class DetailView(generic.DetailView):
    ...
    def get_queryset(self):
        """
        Excludes any questions that aren't published yet.
        """
        return Question.objects.filter(pub_date__lte=timezone.now())
```

- In `test.py`:

```python
class QuestionDetailViewTests(TestCase):
    def test_future_question(self):
        """
        The detail view of a question with a pub_date in the future
        returns a 404 not found.
        """
        future_question = create_question(question_text='Future question.', days=5)
        url = reverse('polls:detail', args=(future_question.id,))
        response = self.client.get(url)
        self.assertEqual(response.status_code, 404)

    def test_past_question(self):
        """
        The detail view of a question with a pub_date in the past
        displays the question's text.
        """
        past_question = create_question(question_text='Past Question.', days=-5)
        url = reverse('polls:detail', args=(past_question.id,))
        response = self.client.get(url)
        self.assertContains(response, past_question.question_text)
```

## Part 6 - Styling
#### Customizing look and feel
- Static files should be stored in `django.contrib.staticfiles`
- Create a new directory: `polls/static/polls` and create a file named `style.css`

Add the following to the `index.html`

```html
{% load static %}

<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />
```

And the following to `style.css`

```css
li a {
    color: green;
}
```

## Part 7 - Tuning the admin interface
- Any time you want to add some "model class" to the admin interface you will do the following:
  - create a model admin class
  - pass it as the second argument to `admin.site.register()`

```python
from django.contrib import admin
from .models import Choice, Question

class ChoiceInline(admin.TabularInline):
    model = Choice
    extra = 3

class QuestionAdmin(admin.ModelAdmin):
    fieldsets = [
        (None,               {'fields': ['question_text']}),
        ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
    ]
    inlines = [ChoiceInline]
    list_display = ('question_text', 'pub_date', 'was_published_recently')
    list_filter = ['pub_date']
    search_fields = ['question_text']

admin.site.register(Question, QuestionAdmin)
```

-  “Choice objects are edited on the Question admin page. By default, provide enough fields for 3 choices.”
- By default, Django displays the str() of each object. But sometimes it’d be more helpful if we could display individual fields. To do that, use the list_display admin option, which is a tuple of field names to display.
- We added an extra column "was_published_recently" to the admin interface, however sorting for it is not yet working. For this we had to define the following function in the `polls/models.py`

```python
def was_published_recently(self):
       now = timezone.now()
       return now - datetime.timedelta(days=1) <= self.pub_date <= now
   was_published_recently.admin_order_field = 'pub_date'
   was_published_recently.boolean = True
   was_published_recently.short_description = 'Published recently?'
```


text:
# Jenkins on DC/OS
[![velocity](http://velocity.mesosphere.com/service/velocity/buildStatus/icon?job=public-jenkins-dcos-master)](http://velocity.mesosphere.com/service/velocity/job/public-jenkins-dcos-master/)
[![Docker Stars](https://img.shields.io/docker/stars/mesosphere/jenkins.svg)][docker-hub]
[![Docker Pulls](https://img.shields.io/docker/pulls/mesosphere/jenkins.svg)][docker-hub]

Run a Jenkins master on Mesos and Marathon, using Docker and Nginx.

## Overview
This repo contains a [Dockerfile](Dockerfile) that runs Jenkins inside a Docker
container and uses [Nginx][nginx-home] as a reverse proxy. It also provides
several Jenkins plugins and a basic Jenkins configuration in order to get you
up and running quickly with Jenkins on DCOS.

## Included in this repo
Base packages:
  * [Jenkins][jenkins-home] 1.651.3 (LTS)
  * [Nginx][nginx-home] 1.9.9

Jenkins plugins:
  * [ansicolor][ansicolor-plugin] v0.4.2
  * [artifactory][artifactory-plugin] v2.4.7
  * [build-name-setter][build-name-setter-plugin] v1.6.3
  * [build-pipeline][build-pipeline-plugin] v1.5.2
  * [build-timeout][build-timeout-plugin] v1.16
  * [cloudbees-folder][folders-plugin] v5.7
  * [credentials][credentials-plugin] v1.26
  * [credentials-binding][credentials-binding-plugin] v1.7
  * [embeddable-build-status][embeddable-build-status-plugin] v1.9
  * [ghprb][ghprb-plugin] v1.32.2
  * [git][git-plugin] v2.4.4
  * [git-client][git-client-plugin] v1.19.6
  * [github][github-plugin] v1.18.1
  * [github-api][github-api-plugin] v1.72.1
  * [greenballs][greenballs-plugin] v1.15
  * [job-dsl][job-dsl-plugin] v1.44
  * [jobConfigHistory][jobConfigHistory-plugin] v2.13
  * [jquery][jquery] v1.11.2-0
  * [mailer][mailer-plugin] v1.16
  * [matrix-project][matrix-project] v1.7
  * [marathon][marathon-plugin] v1.3.1
  * [mesos][mesos-plugin] v0.13.0
  * [monitoring][monitoring-plugin] v1.59.0
  * [parameterized-trigger][parameterized-trigger-plugin] v2.30
  * [plain-credentials][plain-credentials] v1.1
  * [rebuild][rebuild-plugin] v1.25
  * [role-strategy][role-strategy-plugin] v2.2.0
  * [saferestart][saferestart-plugin] v0.3
  * [saml][saml-plugin] v0.5
  * [scm-api][scm-api-plugin] v0.2
  * [script-security][script-security-plugin] v1.17
  * [ssh-credentials][ssh-credentials-plugin] v1.11
  * [timestamper][timestamper-plugin] v1.7.4
  * [token-macro][token-macro-plugin] v1.12.1
  * [workflow-step-api][workflow-step-api] v1.15

## Creating the WAR
The included `pom.xml` file is used to create a WAR file containing the plugins
listed above. To assemble the WAR file, run the [maven][apache-maven] command:
`mvn package`.

## Packaging
Jenkins is available as a package in the [Mesosphere Universe][universe].
To make changes to the Jenkins package, submit a pull request against the
Universe.

## Installation
To install Jenkins for the DCOS, perform the following steps.

  1. Run `dcos package update`
  2. Run `dcos package install jenkins`

Jenkins should now be available at <http://dcos.example.com/service/jenkins>.
See [Getting Started][getting-started] for more in-depth instructions and
configuration options.

## Releasing
To release a new version of this package:

  1. Update [the Jenkins conf][jenkins-conf] to reference the current release of
  the [jenkins-dind][jenkins-dind] Docker image (if needed).
  2. Update the Jenkins release version in [pom.xml](pom.xml).
  3. Add some release notes to [CHANGELOG.md](CHANGELOG.md)
  4.
  5. Once [the build][jenkins-build] has successfully completed, submit a new
  pull request against [the Universe][universe] referencing the new tag.

[apache-maven]: https://maven.apache.org
[ansicolor-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/AnsiColor+Plugin
[artifactory-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Artifactory+Plugin
[build-name-setter-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Build+Name+Setter+Plugin
[build-pipeline-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Build+Pipeline+Plugin
[build-timeout-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Build-timeout+Plugin
[credentials-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Plugin
[credentials-binding-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Binding+Plugin
[docker-hub]: https://hub.docker.com/r/mesosphere/jenkins
[embeddable-build-status-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Embeddable+Build+Status+Plugin
[folders-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Folders+Plugin
[getting-started]: http://mesosphere.github.io/jenkins-mesos/docs/
[ghprb-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin
[git-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin
[git-client-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Git+Client+Plugin
[github-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin
[github-api-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+API+Plugin
[greenballs-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Green+Balls
[jenkins-conf]: /conf/jenkins/config.xml
[jenkins-dind]: https://github.com/mesosphere/jenkins-dind-agent
[jenkins-home]: https://jenkins-ci.org/
[job-dsl-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin
[jobConfigHistory-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/JobConfigHistory+Plugin
[jquery]: https://wiki.jenkins-ci.org/display/JENKINS/jQuery+Plugin
[mailer-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Mailer
[matrix-project]: https://wiki.jenkins-ci.org/display/JENKINS/Matrix+Project+Plugin
[marathon-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Marathon+Plugin
[mesos-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Mesos+Plugin
[monitoring-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Monitoring
[nginx-home]: http://nginx.org/en/
[parameterized-trigger-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin
[plain-credentials]: https://wiki.jenkins-ci.org/display/JENKINS/Plain+Credentials+Plugin
[rebuild-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Rebuild+Plugin
[role-strategy-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Role+Strategy+Plugin
[saferestart-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/SafeRestart+Plugin
[saml-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/SAML+Plugin
[scm-api-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/SCM+API+Plugin
[script-security-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Script+Security+Plugin
[ssh-credentials-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/SSH+Credentials+Plugin
[jenkins-build]: https://velocity.mesosphere.com/service/velocity/job/public-jenkins-mesos-master/
[timestamper-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Timestamper
[token-macro-plugin]: https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin
[universe]: https://github.com/mesosphere/universe
[workflow-step-api]: https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin

repository: kamoljan/jenkins-dcos

repo_name: kamoljan/jenkins-dcos


text:
# CSSE 1001 - LOLO

Private repository for Raghav Mishra's **CSSE1001 Assignment 3**, a rip-off of the game *LOLO*

![LOLO](http://i.imgur.com/WmDp1VS.png)


text:
---
title: "Artificial Intelligence, What is it?"
date: "2020-02-19T20:29:10.000Z"
template: blog
tags: Education
image: "./media/what-is-artificial-intelligence.jpg"
---

<block-quote>_"The original question, 'Can machines think?' I believe to be too meaningless to deserve discussion.”_
[**Alan Turing**](https://www.goodreads.com/author/show/87041.Alan_Turing) - [**Mechanical Intelligence.**](https://www.goodreads.com/work/quotes/764008)</blockquote>

We used to say that computers were obedient, that it was strictly what we programmed it step by step, like a recipe for cooking. Today **artificial intelligence** manages to find results and conclusions without being explicitly programmed, but they discover them by making an **automatic** analysis of the data that is offered to them. Is this good or bad for humanity? Let’s talk about it!

<title-2>Artificial Intelligence is...</title-2>

A collection of advanced technologies that allow machines** to sense, comprehend, act and learn. It is configured to transform the studies, medicine, business and the apps in ways never seen before (only in science fiction). When this technology is implemented in the correct way, it helps to improve productivity, solve problems and reduce costs, unlocking more creative work and creating new growth opportunities.

<title-2>Advantages of AI</title-2>

*   Exploration capacity.
*   Reduction of errors.
*   Increased personalization of the information received.
*   Better performance than humans.
*   Faster information processing.

<title-2>Disadvantages of AI</title-2>

*   Vulnerable to attacks.
*   Risk related to system hacking
*   Abilities of people will diminish.
*   Robots as effective weapons.
*   Economic problems.

[![artificialintelligence](media/artificial-intelligence.png)](#)

<title-3>Have you heard about the Turing test?</title-3>

First of all, who is Turing? Turing was a British mathematician and logician. He is considered one of the fathers of computing and modern computing. During Second World War worked on decipher the Nazi codes, particularly The Enigma Machine. Then designed one of the first digital programmable electronic computers. If you want to know more about his history and how he designed a machine capable of deciphering Nazi codes, I recommend you watch the movie “The Imitation Game”.

The Turing test is a series of questions that an interrogator (human) must ask questions to a computer and to a person without knowing who is the human and which is the machine, the idea is that if the person asking cannot differentiate between the human being and the machine, it must be considered an intelligent entity.

An inverse form of the Turing test is widely used on the internet as the CAPTCHA test (an acronym for “Completely Automated Public Turing test to tell Computers and Humans Apart”) that is designed to determine if a user is a human and not a computer.

Artificial intelligence is flourishing in many areas: robots investigating the progress of climate change, virtual assistants and computers that control the world of finance.

**Google**

Since 2012, YouTube offers the possibility to subtitle the videos automatically. The platform recognizes what people said in a video and creates subtitles. Once you have the text, it can be translated into any of the 55 languages that Google Translate. To train and improve their voice recognition systems, both Google and its competitors, Amazon and Apple, need hundreds of voice hours recorded in real situations. This is one reason why virtual assistants like Siri, Google Assistant or Alexa are free: they allow these companies to obtain hundreds of thousands audio hours recorded by users in their day to day.

Google showed a new assistant system based on artificial intelligence, if you were already surprised by all the functions that google assistant has, you will be amazed by the new intelligent voice that they have developed called google duplex, which will make the calls that you indicate, Google Duplex makes reservations appointments like to cut your hair x day x hour or reserve a table in a restaurant. If you want to know more I invite you to see the Google Keynote I / O 2018 on Google developers Channel - Youtube.

In the future you will not only ask voice recognition questions to Google Assistant with your mobile phone or with Google Home devices, you will also do the same with your car’s Internet of Things (IoT) device and with any other IoT gears such as mirrors, smart TVs, your fridge and so on.

<block-quote>_“Sometimes it is the people no one can imagine anything of who do the things no one can imagine.”_
[**Alan Turing**](https://www.goodreads.com/author/show/87041.Alan_Turing)</block-quote>

repository: cobuildlab/cobuildlab-web

gha_language: JavaScript

repo_name: cobuildlab/cobuildlab-web


text:
# Temperature and Humidity Viewer

## About The Project
In this project, we use DHT22 sensor to detect the current temperature and humidity indoor. After connectiong the sensor with the raspberry pi, a Python package called "Adafruit_DHT" is used to read the temperature and humidity data from the raspberry pi. At the same time, we are using postgreSQL as the database that connected to flask. For each measure, the data will be recorded in the database as well. After there are enough data in the database, we may add a dashboard on the front end to show how the temperate and humidity change in a certain period. To have this dashboard available on the page, we are hoping user can adjust their indoor temperature and humidity to keep health.

## Prerequisites
### Hardware

* Raspberrypi
* Micro SD card
* Raspberrypi power supply
* DHT22 Temperature/Humidity Sensor

### Software
* Python
* Adafruit_DHT

### Assembly
The DHT22 will have three pins(+, -, data) that we need to connect to the raspberry pi. We will use raspberry pi ZERO WH as example to show how to connection these three pins to pi. First, we connect the "+" pin to pin 2(the top right pin, 5V) on raspberry pi. The "-" pin we need to connect to pin 6(GND). The last pin is the data pin that used to send data from DHT22 to raspberrypi. We connect this to pin 7(GPIO4). Your connections should look like the following:
![assembly_img](./assembly.jpeg)

### Software Setup
> Install the packages to read the data
```shell
$ pip install Adafruit_DHT
```

> Read data in python
```python3
import Adafruit_DHT
sensor = Adafruit_DHT.DHT22
#4 stands for GPIO4 pin on raspberry pi
pin = 4
humidity,temperature = Adafruit_DHT.read_retry(sensor, pin)
```

repository: konantian/Raspberry-Projects

repo_name: konantian/Raspberry-Projects


text:
# Communication

## Slack

You can [request an invitation to our Slack](https://slack.omaps.app/).

## Telegram

You can join [our group on Telegram](https://telegram.omaps.app/).

## Zoom

We have a recurring weekly community meeting every Tuesday at [21:00 UTC+3 Europe/Moscow time zone](https://www.worldtimebuddy.com/?qm=1&lid=524901,212,8&h=524901&date=2020-12-27&sln=21-21.5&hf=0). We will use this meeting to communicate updates to the project, listen to feedback from the OMaps community, and also collect requirements/use cases for new features.

Please join via [Zoom link](https://us02web.zoom.us/j/81251433560?pwd=SGtJc3lUaHE3Z1pFV0gxMHc0STIxdz09#success)

## Code of Conduct

The OMaps community abides by the [CNCF code of conduct](CODE_OF_CONDUCT.md).

repository: rawder/organicmaps

repo_name: rawder/organicmaps


text:
### [CVE-2010-2252](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-2252)
![](https://img.shields.io/static/v1?label=Product&message=n%2Fa&color=blue)
![](https://img.shields.io/static/v1?label=Version&message=n%2Fa&color=blue)
![](https://img.shields.io/static/v1?label=Vulnerability&message=n%2Fa&color=brighgreen)

### Description

GNU Wget 1.12 and earlier uses a server-provided filename instead of the original URL to determine the destination filename of a download, which allows remote servers to create or overwrite arbitrary files via a 3xx redirect to a URL with a .wgetrc filename followed by a 3xx redirect to a URL with a crafted filename, and possibly execute arbitrary code as a consequence of writing to a dotfile in a home directory.

### POC

#### Reference
- http://lists.gnu.org/archive/html/bug-wget/2010-05/msg00023.html
- http://lists.gnu.org/archive/html/bug-wget/2010-05/msg00031.html

#### Github
No PoCs found on GitHub currently.

repository: trickest/cve

repo_name: trickest/cve


text:
List

This document is written for C programmers. Since you’re reading this, chances are that you know a list is used for store items in a mutable way. This software provides complete list system.

This is just a single header file: list.h. All you need to do is copy the header file into your project, and:
```C
#include "list.h"
```
Since list is a header file only, you don't need to link any code. It's very portable, easy to use, and very fast integration.

Features

```C
LIST_PUSH(list, data_element, function)
MAP_LIST(list, map_fct, arg)
MAP_LIST_WITH_BREAK(list, map_fct, arg)
MAP_LIST_WITH_MATCH(list, map_fct, match_fct, arg)
DELETE_ALL_LIST(list)
LIST_POP(list)
LIST_REMOVE_WITH_DATA(head_list, node, match_fct)
```

Overview

Each item has a free function for free the data only.
```C
typedef struct s_list t_list;

typedef struct          s_list
{
  void                  *data;
  free_function         free;
  struct s_list         *next;
}                       t_list;
```
For more informations, check out test.c.

Some good features are comming, keep an eye on it.


text:
# Golang Assertions

Small multipurpose assertions library for Golang

[![Go Report Card](https://goreportcard.com/badge/github.com/jramonrod/go-test)](https://goreportcard.com/report/github.com/jramonrod/go-test)
[![Build Status](https://travis-ci.org/jramonrod/go-test.svg?branch=master)](https://travis-ci.org/jramonrod/go-test)
[![codecov](https://codecov.io/gh/jramonrod/go-test/branch/master/graph/badge.svg)](https://codecov.io/gh/jramonrod/go-test)

## Installation

Simple as
> go get github.com/jramonrod/go-test

## Documentation
https://godoc.org/github.com/jramonrod/go-test/assertions

repository: jramonrod/go-test

repo_name: jramonrod/go-test


text:
+++
date = "2021-03-26T10:00:00-07:00"
publishdate = "2021-03-26T10:00:00-07:00"
draft = false
title = "Release 2021.10"
images = ["https://crunch.io/img/logo-1200x630.png"]
+++

### Crunch web application

- Added feature to show values on a time plot when the user has Display > Values selected in the extended panel of the Display Controller (in early access).
- Updated horizontal bar graphs so that labels on an axis are no longer truncated.
- Added hint text to alert users who have any profile analyses saved to a deck, since these analyses cannot be exported via the "Export from deck" panel.
- Added a "Fit to tile" option, which is available in the Edit panel for saved analyses that have the 'time plot' visualization type (in early access).

### API Endpoints and API Reference

- Changed several user-level permissions to enable better sharing and editing of datasets.
- Fixed a bug that occurred when searching for personal variables.
- Improved the dataset scripts endpoint by including the script ID on the shoji tuple.
- Enhanced the `POST /api/account/users/` endpoint to enable granting users the ability to edit datasets separately from creating datasets.

### SDKs (`rCrunch`, `pyCrunch`, and `sCrunch`)

- Added the ability to perform backfill replacements without a filter in sCrunch (full column).
- Added Python 3.4 support to sCrunch.
- Released sCrunch version 0.9.3.

### Crunch Automation

- Added the ability to use reference functions to act on a variable number of input variables for the `RENAME` command. See the [documentation](https://help.crunch.io/hc/en-us/articles/360042247331-RENAME-command) for more information.
- Improved support for Unicode characters in Crunch Automation strings.

### Help desk and website improvements

- Added more descriptive information on how to use the [CREATE MULTIPLE DICHOTOMY WITH RECODE command](https://help.crunch.io/hc/en-us/articles/360044567952-CREATE-MULTIPLE-DICHOTOMY-WITH-RECODE-command).
- Updated the [Crunch Automation basics](https://help.crunch.io/hc/en-us/articles/360041769292-Crunch-Automation-basics) article with better examples.

repository: Crunch-io/ta-da

branch_name: refs/heads/src

gha_language: CSS

repo_name: Crunch-io/ta-da


text:
---
layout: post
title: "Sex Bed"
date: 2004-06-22 13:40
comments: true
categories: Life in General
author: Oliver Thylmann
---

I just found <a title="m a x - l o n g i n . c o m" href="http://www.max-longin.com/index2.html">m a x - l o n g i n . c o m via [Gizmodo](http://www.gizmodo.com/). It's a Bed designed by Max Longin and it kind of hangs in the air, movable, only attached via 4 strings. To translate the german page: "This progressive sleepingplace doesn't inhibit the movements of lying or loving, but balances them out, leading them peace." The bed costs almost 4000 EURs.

So for 4000 EURs you can have the earth moving whenever you turn arround in your sleep. And then you have the "loving" bit, which might be a lot more interesting.

extension: markdown


text:
# WaveRL
A package for training RL agents to perform active damping on a model of a vibrating bridge.  [Link to project presentation](https://docs.google.com/presentation/d/11RFd_cj0aX3AAjNP0hrgOwF8einq7tsvyfX5sfljVik/edit?usp=sharing)

## Contents
* src/ :  This folder contains the code for the environments as well as scripts for training and rolling out agents
	* train.py :  This script trains an agent (see example below)
	* rollout.py : This script rolls out a trained agent (see example below)
	* visualize.py : This script produces visualizations of a rolled out agent (see example below)
	* environments/ : This folder contains code for the environments.
		* finite_diff_wave.py : This is a class definition for a simulator of one dimensional wave equation with finite difference methods.
		* active_damping_env.py : This is a class definition for an OpenAI gym environment simulating an oscillating bridge
* configs/
	* config.yml : This file holds the default parameters for the scripts and environments
* tests/
	* config_test.py :  A unnittest test fixture that can be used to make sure `configs/config.yml` has all the appropriate keys and valid parameter settings
* trained_agents/ : A folder for storing trained agents
* rollouts/ : A folder for storing rollouts of trained agents and associated visualizations.  Currently includes an example rollout and visualizations of a trained agent.
* install_stable_requirements.sh : a shell script for installing all the necessary packages
* conda_requirements_baseline.yaml : A specification of the conda environment

## Setup
First, [Install Conda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/)

Then update and install the following system packages:

### Ubuntu Instructions:
```
sudo apt-get update && sudo apt-get install cmake libopenmpi-dev python3-dev zlib1g-dev openmpi-bin mpich lam-runtime
```
### Mac OS X Instructions:
Installing the necessary C-libraries is easiest with [Homebrew](https://brew.sh/), so install this first:
```
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```
Then install cmake and openmpi.
```
brew install cmake openmpi
```
### Setting up the conda environment

Clone the repository and change into the repo folder
```
git clone https://github.com/jaberkow/WaveRL.git
cd WaveRL
```

Make a conda environment and activate it:

```
conda create -n WaveEnv python=3.6
conda activate WaveEnv
```
Install the packages from `requirements.txt`

```
pip install -r requirements.txt
```
### Tests

If any changes are made to the default values in `configs/config.yml` , run the following command

```
python tests/config_test.py
```
To make sure that all the parameter values are valid.

## About the environment

This package simulates an oscillating bridge by modelling it with the one-dimensional [wave equation](https://en.wikipedia.org/wiki/Wave_equation), which is simulated using a [finite difference solver](https://en.wikipedia.org/wiki/Finite_difference_method).  The action space of the environment represents pistons that apply a force to actively dampen vibrations in the bridge.  The reward signal is proportional to the decrease in energy of the system.  One episode of the environment involves 3 phases:  1) A "warmup phase" where an external force is applied to the system to cause oscillations 2) An "equilibriation" phase where the oscillations settle in to stable patterns and 3) A dampening phase where the agent attempts to dampen the oscillations.

Here is an example of a single episode, the red line is the bridge and the green line reprents a smoothed profile of the forces applied to the bridge by the pistons.

![](rollouts/example_visualization.gif)

## Training an agent

To train an agent for 40,000 timesteps on the vibrating bridge environment and save it as `trained_agents/damping_agent.pkl`, run the following command:

```
python src/train.py -n 40000 -m trained_agents/damping_agent
```
Training may produce deprecationg warnings due to the version of TensorFlow used in the current release of the stable baselines package, which can be ignored.  This command will also produce a TensorBoard folder at `/tensorboard_log` that can be visualized by running the following command from the same directory and following the instructions in the terminal:

```
tensorboard --logdir tensorboard_log/
```
## Rolling out a trained agent

To rollout a trained agent that is stored at `trained_agents/damping_agent.pkl` for 60 steps, run the following command:

```
python src/rollout.py -n 60 -i trained_agents/damping_agent.pkl -f rollouts/damping_rollout.npz
```

The rollout will be saved as `rollouts/damping_rollout.npz`, which can be changed by passing `-f <filename>` to the above command.  Note that the trajectories produced will have length equal to the number of rollout steps + the number of warmup steps + the number of equilibriation steps (values of which are set in `/configs/config.yml`).

## Visualizing a rollout

To visualize a rollout saved in `rollouts/damping_rollout.npz`, run the following command:

```
python src/visualize.py -i rollouts/damping_rollout.npz -f rollouts/damping_visualiztion
```

This will produce two files `rollouts/damping_visualiztion.png` which plots the trajectory of the energy over the episode and `rollouts/damping_visualiztion.gif` which is an animation of the bridge and the impulse force.  The visualizations, png or gif, can be viewed from the command line in linux with

```
animate <path_to_file>
```
and in MacOS with

```
qlmanage -p <path_to_file>
```

## Evaluating a trained agent

In order to evaluate the quality of a trained agent, one can measure how many damping steps it takes the agent to dissipate a certain percentage of the energy in the bridge.  The following script takes the agent stored at `trained_agents/damping_agent.pkl` and measures how many damping steps it takes to dissipate 75% of the bridge's energy (relative to the average during the equilibriation phase) for 20 different initializations.  The results are stored at `trained_agents/agent_evaluation.npy`

```
python src/evaluate.py -r 20 -t 0.25 -i trained_agents/damping_agent.pkl -f trained_agents/agent_evaluation
```

## Exploring parameter values

The parameters that govern the vibrating bridge environment (as well as default parameters for training and rollout) are set in `configs/config.yml`.  There are several parameters that may be interesting to alter:

* wave_speed :  This value controls how fast a wave propagates along the bridge.  Larger values yield a more 'taut' bridge and smaller values yield a 'looser' bridge.  Must be strictly greater than zero.
* force_width :  Currently the piston forces are modeled as having Gaussian profiles centered at discrete points with widths given by this parameter.  Decreasing this value will the make the forces more point-like.  Must be strictly greater than zero.
* num_force_points :  The number of pistons.  Increasing this parameter while decreasing the force_width model's an active damping system capable of more fine grained control.  Must be a positive int.
* timepoints_per_step : How many steps of the simulator dynamics to run with a fixed value of the piston forces.  Increasing this parameter decreases the power of the agent/damping system to respond quickly.  Must be a positive int.

### Rolling out an agent trained on an environment with different parameters

If you are interested in judging how well an agent trained with one set of parameters governing the vibrating bridge environment generalizes to an environment with different parameters you can train an agent, then change **some** parameters (see below) in the configuration file (`/configs/config.yml`), and roll out the `.pkl` file of the trained agent in the normal way.  However, several parameters **must** remain constant between training and rolling out, or else the OpenAI gym will throw an error because the observation/action spaces have changed.  These fixed parameters are as follows:

* num_lattice_points
* num_force_points
* min_force
* max_force
* min_u
* max_u

repository: jaberkow/WaveRL

repo_name: jaberkow/WaveRL