text:
---
title: "How to Make Websites Interactive with JavaScript"
category: "Web Development"
date: 2019-03-26
published: "true"
slug: "make-websites-interactive-with-javascript-dom"
tags:
    - html
    - selectors
    - javascript
    - console
    - dom
    - beginner
    - high school lesson
---

Remember that every page on the internet is an HTML **document**. We can add HTML tags to the page, and use CSS to style our HTML. However, almost every modern website allows you to *interact* with it via clicking and typing.

In this post, we'll walk through the essentials of website interaction by discussing the DOM, or Document Object Model. First, we'll examine how to access the DOM using JavaScript query selectors. Afterwards, the focus will shift to manipulating the DOM through event listeners, callbacks, and class list methods.

## Goals

By the end of this post, you should know/be able to:

* Access HTML elements on a website using **querySelector()**
* Change the class of a selected element
* Change the inner content of a selected element

## Sequence

1. The Console
2. querySelector
3. Event Listeners
4. Class List Methods
5. Content Properties

## Prerequisites

* You have mastered how to use id, class, and element selectors in your CSS.
* You understand that you can associate multiple classes with a single element by separating the class names with a space.
* You understand what purpose variables serve in JavaScript, and can write custom functions

## The Console

Before we do anything serious, let's talk about every web programmer's best friend - the developer tools. Open up a new workspace in cloud 9 (you can also just start a new codepen if you don't want to go through all the setup). Make a new folder called javascript-reboot, cd into the directory, and create a new index.html and style.css file.

```bash
mkdir javascript-reboot
cd javascript-reboot
touch index.html style.css
```

Add the following code to your index.html file and preview it in your browser. Make sure to open the preview up in a new tab.

```html{numberLines: true}
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="style.css" type="text/css" />
  </head>
  <body>
    <div id="wrapper">
      <div class="row">
        <div id="phone1" class="item phone active">📱</div>
        <div id="phone2" class="item phone">📱</div>
        <div id="phone3" class="item phone">📱</div>
      </div>
    </div>

    <script type="text/javascript">
      console.log("JavaScript is working!")
    </script>

  </body>
</html>
```

Then paste this code in your style.css file.

```css{numberLines: true}
/* The first several elements that are styled are really just for the purpose of having */
/* Border-box sizing, Default to a sans-serif font throughout */
*, *:before, *:after {-webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } html { font-family: sans-serif; }

/* Black background color */
body {
  background-color: black;
}
/* put everything inside a wrapper so  */
#wrapper {
  width: 800px;
  max-width: 90%;
  margin: auto;
  background-color: rgba(255, 255, 255, 0.2);
  margin-top: 0;
  min-height: 100vh;
}
.row {
  padding-top: 25px;
  display: flex;
  width: 100%;
  flex-wrap: wrap;
  justify-content: space-around;
}
.item {
  border-radius: 10px;
  text-align: center;
  background-color: black;
  padding: 10px;
  margin: 20px;
  transition: 0.2s;
}
.phone {
  font-size: 100px;
}
.active {
  box-shadow: 0 0 35px white;
}
.hidden {
  display: none;
}
```

Preview the HTML file and open up the JavaScript console in your browser. To do that in chrome, click on the 3 dots in the top right corner of the browser, navigate to 'More Tools', and then click on 'Developer Tools'.

    Taken from the chrome devtools documentation.

In the new browser window that opens up, select the console tab and you should see our message, "JavaScript is working!" printed to the screen.

The console will be our primary feedback tool, and let us test out small JavaScript snippets in the browser.

## The Document Object Model (DOM)

We've talked a lot about using HTML and CSS together. Earlier, we also learned how to use JavaScript to draw shapes and make animations. But we haven't yet combined all three into a single project.

Whenever a web browser, like Chrome, renders an HTML file, it also creates JavaScript objects that store information about the file. If we type `document` into the console, we see a representation of entire web page stored in the `document` variable. The `document` variable also holds some **methods** (**functions** attached to **objects**) that allow us to query our HTML. We are treating the HTML document like an object, using methods to access and manipulate the data that the object stores.

## Querying the DOM

Let's get an element from the page and store it in a variable.  Then we'll console log that variable to make sure we got the element we were looking for. Edit the script in your HTML file to have the following code.

```html
<script type="text/javascript">
  console.log("JavaScript is working!")

  let firstPhone = document.querySelector('#phone1') // Get the phone using the same selector syntax we use for CSS selectors.
  console.log(firstPhone) // View the HTML for the phone in the console.
</script>
```

When you refresh the page, you'll notice that the `firstPhone` variable is storing a div. We grabbed that div using `document.querySelector('#phone1')`. The `querySelector` method allows us to *query* the document, or *ask a question*, about an element having the selector `#phone1`.

Using this method, we were able to capture the element with the attribute `id="phone1"` and print it to the console. Capture the remaining two phone divs in variables and console log them to confirm that you got them both.

Now, update the script with the following code. Before you refresh your page, what do you think will be printed in the browser? How many items will appear in the classList?

```js
console.log("JavaScript is working!")

let firstPhone = document.querySelector('#phone1')

console.log(firstPhone)
console.log(firstPhone.id)
console.log(firstPhone.classList)
```

Notice how we actually have access to a number of properties about the firstPhone div. The one we'll deal with most, is `firstPhone.classList`. It contains a list of all the classes assigned to that element. Using JavaScript, we'll update this classList by adding or removing values from it.

## Event Listeners

What's an event listener?

> An event listener is how we set up code that only runs when a certain event happens on a page - often an event which is driven by the user. One example is when you click on a button. What other event types might exist?

Event listeners can be attached to an element on the DOM like so:

```javascript
let firstPhone = document.querySelector('#phone1')

firstPhone.addEventListener('click', (e) => {
  console.log("first phone clicked!")
})
```

So what happened here? First, we used querySelector to grab the phone div from the HTML document. Then, created an event listener by passing two arguments to the `addEventListener` method. The first is the type of event we want to listen for (a click), and the second is a **callback** function that will run as soon as the event occurs.

### Pair Practice

1. Take the JavaScript that you've written so far.
2. Add a `<button>` to the HTML markup of the page.
3. Add an event listener to that button.
4. When the button is clicked, console.log the classLists of all three phones.

The activity you just completed is the core of building websites. Give the user a website to interact with, and change the site based on what the user does.

So what are the kinds of things we might want to do inside event listeners?

## Changing Styles Programmatically

One thing we can do is  modify the CSS styling of any element on the page. This is a clean strategy for creating animations and visual feedback. To do that, we're going to use the element's classList.

Look at the style.css file and examine the CSS code inside the `.active` selector. Notice how one of the phones on our screen is glowing? That's because only one phone div has been assigned the class of active.

What if our phone is blowing up too much, and we want to turn off notifications? Let's learn how to remove the active class. Inside our script, add the following code.

```javascript
let firstPhone = document.querySelector('#phone1')

firstPhone.addEventListener('click', (e) => {
  firstPhone.classList.remove('active')
  console.log("first phone clicked!")
})
```

When we click on the first phone, we see that it loses its glow! This is what happens when we manipulate the classList of a DOM element. But what if we're ready for our phone to start blowing up again? How we can add back the active class? Add this code below your previous snippet.

```javascript
let secondPhone = document.querySelector('#phone2')

secondPhone.addEventListener('click', (e) => {
  secondPhone.classList.add('active')
  console.log("second phone clicked!")
})
```

And now we can click on the second phone, and watch it glow. However, we aren't able to turn either phone on, and then off, and then on again, etc. Conditionals to the rescue.

```javascript
let thirdPhone = document.querySelector('#phone3')

thirdPhone.addEventListener('click', (e) => {

  if (thirdPhone.classList.contains('active')){
    thirdPhone.classList.remove('active')
  } else {
    thirdPhone.classList.add('active')
  }

  console.log("third phone clicked!")
})
```

Now we have the desired effect. There is an easier way, however.

### Pair Practice

1. Go ahead and add on/off glow event listeners for the other two phones as well.
2. Working together, see if you can have one of the event listeners use classList.toggle. Read about it at this link: https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/toggle
3. Create your own class and have one of the event listeners toggle that class instead.

## Content Properties

Let's say we wanted to change the contents of a main `<h1>` element on our page. We could modify its contents with the following JavaScript.

```js
document.querySelector('h1').innerHTML = 'My phone is blowing up!'
```

The `.innerHTML` property of any element holds text and any other HTML elements nested inside that element. We're able to update it here by setting it equal to a new string.

Play around with this codepen and complete the challenges below. Use the tools we've discussed here to modify this report card.

  See the Pen DOM Manipulation Report Card by Jeff Astor
  (@jastor11-the-decoder) on CodePen.

## Wrapping Up and Resources

There is more to the DOM than can fit in a single post, but this is enough to get you tinkering with your own sites. If you want continued practice, I recommend my students take advantage of the following resources.

+ Khan Academy Course on Interactive Websites - https://www.khanacademy.org/computing/computer-programming/html-css-js
+ Codecademy Course on Building Interactive Websites (I think you need a pro account actually. Had my students do their 7 day free trial to take this course.) - https://www.codecademy.com/learn/build-interactive-websites
+ MDN: Introduction to the DOM - https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction
+ The Odin Project: DOM Manipulation - https://www.theodinproject.com/courses/web-development-101/lessons/dom-manipulation
+ DOM Enlightenment (FOR FUTURE REFERENCE) - Full online book available for free on everything about the DOM. http://domenlightenment.com/


text:
---
layout: post
title: How to build an MVP
excerpt: "Let's think about the Minimum 'loVeable' Product"
modified: 2015-01-23
tags: [agiletrack, mvp]
comments: true
image:
  feature:
---

Overview

*  Auto generated table of contents
{:toc}

There are many terms that are thrown around willy nilly, and MVP, or Minimum Viable Product is another one of them.  Widely miss-applied, and used interchangeably with prototype, beta, alpha, etc, what actually is an MVP?  If a picture speaks a thousand words, I believe this one from fast monkeys and inspired by the great Spotify team sums it up really well.

This image: too good not to share around

## Minimum loVeable Product

I saw Spotify put another spin on the term MVP which I really like, they called it a Minimum loVeable Product.

The image talks about building a car.  The goal of the car is to get you from A to B.  So instead of first building a wheel that is of no use to anyone, a first MVP would be a Skateboard - it gets you from A to B a bit better than walking.  You get the idea.

An MVP delivers actual value to the business earlier, and provides more opportunity for the user to see it, try it, and give valuable feedback to help steer the product in the right direction as it grows.

## MVP Example

It is always tempting to break the MVP delivery and go above and beyond.  On a project our team was once asked to build a user login system.  We discovered the reason was because they wanted to restrict a section of their site to only a few staff members.

We thought about building a database driven user management system, complete with user administration and access profiles.  But then we stopped and thought about the MVP approach.  We ended up building a login page, with a username and password hard coded into the server.  It feels dirty and its not an ideal solution, however it got the business closer to what they wanted in a matter of hours rather than weeks.

We delivered something that helped them toward their goal very quickly.  We could then improve on that solution, one small step at a time, until the business was happy that they had everything they wanted.

## Case Study: Zappos

A great if not rather over the top success story of an MVP is the birth of Zappos.  The founder, Nick Swinmurn could not find a pair of shoes at the mall, then discovered that there were no major online shoe stores.  But is there a market there, will people actually buy shoes online?  (Remember this was the 90's, when movies were on tapes and research was done in libraries)

His MVP was simple; he went to a shoe store and took some pictures of shoes to put on a quick and dirty website.  If anyone bought the shoes, he returned to the store, bought them at full price and shipped them.

His MVP lead to being one of the worlds largest online shoe stores, selling for around $1.2 billion just 10 years after launch.

## Summary

Hopefully this post helps to give a slightly better understanding of building an MVP.  We will often tend to think of the big picture right away and go head first into the most complex all encompassing solution.  We need to keep questioning ourselves; can we instead deliver the Minimum loVeable Product that will help get the business even just a small step closer to their goal?

license: MIT

branch_name: refs/heads/master

extension: md

license_type: permissive


text:
# Sandman
[![Build Status](https://travis-ci.org/porthunt/sandman-aws.svg?branch=master)](https://travis-ci.org/porthunt/sandman-aws)

Sandman was designed to reduce the costs of your AWS SageMaker notebook instances. Using Sandman, you can configure which and when to stop them. You simply need to deploy Sandman's lambda functions and that's it, it will take care of the rest.

## Why
You might have in your organization a set of notebook instances that don't need to run 24/7. If you stop these instances in a certain period of time, you can save quite some money. Reducing the uptime from 24/7 to 16/5 can reduce up to 50% of your SageMaker notebook costs.

## Customizing
Before deploying, you can customize where to deploy the lambda functions and at which time you want to start/stop the instances. Open the file `variables.tf` and modify the default values. You can modify:
* The AWS region you want to deploy Sandman to.
* The start and stop schedules (aka when Sandman will start and stop your instances - UTC time).
* The python runtime (Sandman is compatible with Python >3.6).

#### Ignore instances
Sometimes you have instances that need to run 24/7. Sandman can **ignore** instances with the tag `sandman=ignore`. So if you have an instance that you don't want Sandman to touch, just **add this tag to your notebook instance**.

## How to deploy
To deploy Sandman on your account, you need to have awscli configured on your machine and then run `./deploy.sh`. This script will create:
* The policy that allows the lambda function to:
  * `sagemaker:StartNotebookInstance`
  * `sagemaker:StopNotebookInstance`
  * `sagemaker:ListNotebookInstances`
  * `sagemaker:ListTags`
  * `ec2:DescribeSubnets`
  * `ec2:DescribeVpcs`
  * `ec2:DescribeNetworkInterfaces`
* The role that uses the previous policy.
* The lambda functions to start and stop the notebook instances.
* Cloudwatch events that triggers the lambda functions.

```shell
$ git clone https://github.com/porthunt/sandman-aws.git
$ cd sandman-aws
$ vim variables.tf  # modify the variables
$ ./deploy.sh
```

## Removing Sandman
In case you don't want to have Sandman anymore, just run `./destroy.sh`.

## License
Sandman is completely unlicensed. Feel free to just modify it as you want.

license: Unlicense

repository: porthunt/sandman-aws

repo_name: porthunt/sandman-aws


text:
akutils
=========================

Andy's random collection of javascript utility functions.

### Installation

To install the stable version:

```
npm install --save f.lux-react
```

This assumes you are using [npm](https://www.npmjs.com/) as your package manager.

## Purpose

To make it easier for me to share and consume our own JavaScript. P

**Note:** If you are consuming the code here, be prepared for a bad time. APIs may appear or disappear and I may not follow semver strictly, though I will do my best to. This library is being published with my use cases in mind and is not necessarily meant to be consumed by the broader public. In order for me to move fast and ship projects, I've made the decision to not support everybody. I probably won't take your feature requests unless they align with our needs. There will be overlap in functionality here and in other open source projects.

repository: akrumel/akutils

repo_name: akrumel/akutils


text:
# Changelog

All notable changes to this project will be documented in this file. See
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.1.1](https://github.com/ng-apimock/protractor-plugin/compare/v2.1.0...v2.1.1) (2023-01-15)

### Bug Fixes

* 🐛 security fix for fetch dependency ([81d6d90](https://github.com/ng-apimock/protractor-plugin/commit/81d6d904555952cdbf591a676f830d86e4ae2319))

# [2.1.0](https://github.com/ng-apimock/protractor-plugin/compare/v2.0.0...v2.1.0) (2022-12-09)

### Features

* 🎸 update base-client ([7444f57](https://github.com/ng-apimock/protractor-plugin/commit/7444f5758e9ab8993b5dc88effd41807f10ddd55))
* 🎸 update to latest base-client ([6b377d5](https://github.com/ng-apimock/protractor-plugin/commit/6b377d5490d3fd00a61f7034da413f84b060eb97))

# [2.0.0](https://github.com/ng-apimock/protractor-plugin/compare/v1.1.0...v2.0.0) (2021-07-27)

### Features

* 🎸 test protractor support for create-preset ([332ca6e](https://github.com/ng-apimock/protractor-plugin/commit/332ca6eb67163c05c1e0a06efb9fbb55121c0938))

### BREAKING CHANGES

* 🧨 update to v3.*

# [1.1.0](https://github.com/ng-apimock/protractor-plugin/compare/v1.0.19...v1.1.0) (2020-07-08)

### Features

* 🎸 make endpoints base path configurable ([9a9cd21](https://github.com/ng-apimock/protractor-plugin/commit/9a9cd21fd23e9ad5f6b55c9f6a6856340cde548e)), closes [#15](https://github.com/ng-apimock/protractor-plugin/issues/15)

## [1.0.19](https://github.com/ng-apimock/protractor-plugin/compare/v1.0.18...v1.0.19) (2020-07-06)

### Bug Fixes

* 🐛 release ([08a2129](https://github.com/ng-apimock/protractor-plugin/commit/08a21294cec7ef99040a474afea01ad310e4e9d9))

## [1.0.18](https://github.com/ng-apimock/protractor-plugin/compare/v1.0.17...v1.0.18) (2020-07-06)

### Bug Fixes

* 🐛 release ([7661525](https://github.com/ng-apimock/protractor-plugin/commit/76615259c86b41643a1a43d1f71d2a8686652c0b))

repository: ng-apimock/protractor-plugin

gha_language: TypeScript

gha_license_id: MIT

repo_name: ng-apimock/protractor-plugin


text:
# caffeine-api-plugin
[Caffeine](https://github.com/ben-manes/caffeine) packaged as a Jenkins plugin for use by other plugins.

## Important information for plugin developers

This plugin currently hosts the 2.x line of Caffine.  The 3.x line has some minor API breakage and to ensure that you do not fall fowl of this when the plugin is upgraded you should follow the following rules.

1. Do not use any API that has been marked as `deprecated`
2. Avoid any API that is flagged as "incompatable" in the [release notes](https://github.com/ben-manes/caffeine/releases/tag/v3.0.0)

for some more information see [this GitHub issue](https://github.com/ben-manes/caffeine/issues/543)

## Maintainer Information

This plugin does not use `maven-release-plugin` but is released automatically on merging to the `master` branch using [JEP-229](https://github.com/jenkinsci/jep/blob/master/jep/229/README.adoc).

repository: aneveux/caffeine-api-plugin

repo_name: aneveux/caffeine-api-plugin


text:
---
#
# By default, content added below the "---" mark will appear in the home page
# between the top bar and the list of recent posts.
# To change the home page layout, edit the _layouts/home.html file.
# See: https://jekyllrb.com/docs/themes/#overriding-theme-defaults
#
layout: home
---
![image](/source/2021.jpg)

Recent favorite song

/source/little_apple.mp3

/source/baby.mp3

experimental results:
![image](/source/u.gif)

gha_language: HTML


text:
---
title: Logging In with Google on Brave Browser
description: "Learn how to fix issues with the Google authentication on the Brave browser when working with the Fiddler Everywhere web-debugging client."
type: how-to
slug: fiddler-everywhere-brave
publish: true
res_type: kb
---

## Environment

|   |   |
|---|---|
| Product  | Version |
| Fiddler Everywhere |  1.0.0 and above  |
| Brave Browser | all versions |

## Description

Fiddler Everywhere provides an option to use a unique Fiddler account or Google authentication. When using the Google authentication option with the Brave browser when set as the default OS browser, the fallback might fail silently due to the default adblock filters applied by the Brave configuration. How can I use Google authentication with Brave set as the default OS browser?

## Solution

You can configure a custom adblock filter in the Brave browser configuration. Use a filter exception to bypass the Fiddler endpoint and, as a result, complete the Google authentication process successfully.

To add an exception filter for the Fiddler Everywhere endpoint:

1. Open the Brave browser and in type `brave://adblock` in the address field. Brave opens the **Additional filters** configuration page.

1. Scroll down to the **Custom Filters** option. Type the following exception rule on a new line:

    ```Shell
    @@||localhost^$domain=getfiddler.com
    ```

1. Exit the page and restart Brave.

1. Start Fiddler Everywhere and use the Google authentication with Brave as a default OS browser.

## Alternative Solution

If adding an exception filter is a no-go, you can work around the issue by temporarily switching the default browser to another browser (for example, Chrome, Edge, Vivaldi, and so on), completing the Google authentication, and switching back the default OS browser to Brave.

To change the default browser on Windows 10:

1. Open the **Start** menu and type **Default Apps**.
1. Scroll to the **Web Browser** option and select your preferred web browser through the drop-down.

To change the default browser on macOS:

1. Choose **Apple menu** > **System Preferences**. Click **General**.
1. Click the **Default web browser** pop-up menu and select your preferred web browser through the drop-down.

To change the default browser on Ubuntu:

1. Open the **Settings** utility and move to the **Details** tab.
1. Click the **Default Applications** and select your preferred web browser through the drop-down.

repository: telerik/fiddler-everywhere-docs

gha_language: Shell

repo_name: telerik/fiddler-everywhere-docs


text:
# stripe-express

## Start

This will start the application, which will listen on port 3000:

```shell
node app.js
```

based on https://gist.github.com/rpaul-stripe/da40eeda0ca26a3580196a50e6f66762

repository: desforets/stripe-express

repo_name: desforets/stripe-express


text:
# Introduction

Official documentation for Anarock Leads API! You can use this set of APIs for pushing leads to host (passed with request object) database.

For any queries mail us at<EMAIL_ADDRESS>
# Authentication

> Code for creating hash using time_stamp. Hash is required to authenticate proper usage.

```php
// PHP
$key = 'KEY'; // the shared secret key here
$current_time = time();
$message = (string)$current_time;

// to lowercase hexits
$hash = hash_hmac('sha256', $message, $key);
```

```javascript
// NodeJS
const cryto = require('crypto');

const key =  'KEY'; // the shared secret key here
const time_stamp = Math.round((new Date()).getTime() / 1000);
const message = time_stamp.toString();

const hash = crypto.createHmac('sha256', key).update(message);

// to lowercase hexits
const hashInHex = hash.digest('hex');
```

```ruby
# ruby

auth_key = 'Key'
current_time = Time.current.to_i

hash =  OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), auth_key, current_time.to_s)
```

> Make sure to replace `KEY` with your API key.

Server uses SHA256 HMAC authentication method. The hash is created using current timestamp and your key as parameters.

Server expects two keys `hash` and `current_time` to be included in all API requests to server.

### KEY

This will be provided by your point of contact in ANAROCK team. Or you can request key by getting in touch with support team at<EMAIL_ADDRESS>
> You must replace __KEY__ with your personal API key.

> You must test first with __staging KEY__ and then only put in __production KEY_

# Sync Leads

## Post Lead to Anarock Database

```php
// PHP

$api_url = 'STAGING OR PRODUCTION URL'; // as mentioned on left under HTTP Request Heading

$key = 'KEY';
$current_time = time();
$message = (string)$current_time;

// to lowercase hexits
$hash = hash_hmac('sha256', $message, $key);

// you can use libraries like https://github.com/brick/phonenumber to format numbers before sending

$number = PhoneNumber::parse('+447123456789'); // phone number of the lead with +
$country_code = $number->getRegionCode(); // GB
$phone = $number->getNationalNumber(); //<PHONE_NUMBER>

$campaign_id = "UniqueString"; // String to Attribute the lead to specific project. contact ANAROCK team for this.

$postFields  = "";
$postFields .= "&name=".$name; // refer to query parameters section on left section
$postFields .= "&email=".$email;
$postFields .= "&source=".$utm_source;
$postFields .= "&sub_source=".$utm_campaign;
$postFields .= "&placement=".$utm_term;
$postFields .= "&purpose=buy";
$postFields .= "&current_time=".$current_time;
$postFields .= "&phone=".$phone; // Phone number without country code
$postFields .= "&country_code=".$country_code; // Standard ISO3166-1 alpha-2 code for a country.
$postFields .= "&hash=".$hash; // its mandatory to create hash using same timestamp as sent in current_time parameter
$postFields .= "&campaign_id=".$campaign_id;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$api_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            $postFields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
// print_r($server_output);
```

```javascript
// Javascript
const crypto = require('crypto');
const PhoneNumber = require( 'awesome-phonenumber' );
const axios = require('axios'); // using axios to make post request, you can use any other method/library you are comfortable with

const timeStamp = Math.round((new Date()).getTime() / 1000);
const message = timeStamp.toString()
const hash = crypto.createHmac('sha256', key).update(message).digest('hex')

const number = new PhoneNumber(number.toString()); // pass the number with + to the PhoneNumber Library
const phone = number.getNumber('significant');
const country_code = number.getRegionCode();

const campaign_id = 'UniqueString';// String to Attribute the lead to specific project. contact ANAROCK team for this.

return axios({
  url: 'STAGING OR PRODUCTION URL', // as mentioned on left under HTTP Request Heading
  method: 'POST',
  data: {
    phone: phone,
    country_code: country_code,
    current_time: timeStamp,
    hash: hash,
    campaign_id: campaign_id,
    ...other fields as given in the query parameters section
  }
})
```

```ruby
#Ruby

current_time = Time.current.to_i;
prod_key = PROD_KEY;
hash = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), prod_key, current_time.to_s);
params = {
 :name=>"ketan",
<EMAIL_ADDRESS> :purpose=>"buy",
 :phone=>"9819619866",
 :country_code=>"in",
 :current_time=> current_time,
 :hash=> hash,
 :campaign_id=>"42-Queens-Square-Sell-Do-Leads",
 :source_id=>1,
 :sub_source_id=>6,
 :channel_name=>"sell-do"
};
uri = URI.parse(url);
http = Net::HTTP.new(uri.host, uri.port);
http.use_ssl = true;
request = Net::HTTP::Post.new(uri.request_uri);
request.add_field('Content-Type', 'application/json');
request.body = params.to_json;
response = http.request(request);

```

> The above command returns JSON structured like this:

```json
{
  "status":"OK",
  "message":"success",
  "response":
    {
      "lead_id": 17863
    }
}
```

This endpoint is used to post a lead to __HOST__ database.

### HTTP Request

`staging`

`POST https://lead-webhook.staging.${HOST}/api/v0/CHANNEL_NAME/sync-lead`

--

`production`

`POST https://lead.${HOST}/api/v0/CHANNEL_NAME/sync-lead`

> Authentication keys are environment specific. Make sure you are using __Staging KEY__ in *Staging* environment and __Production KEY__ in *Production* environment

> example HOST: anarock.com

### CHANNEL_NAME

This will be provided by your point of contact from ANAROCK support team

### QUERY PARAMETERS

Parameter | Type | Mandatory | Description
--------- | ------- | ------- | -----------
name | String | - | Example "Rahul Kumar"
phone | String | True | phone number without country code. Example: "9988998899"
country_code | String | True | Standard ISO3166-1 alpha-2 code for a country. Link: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 You can also use libraries like, example: "IN" for India Defaults to "IN"
email | String | - | Exmaple<EMAIL_ADDRESS>purpose | String | True | "buy" This should be hardcoded
listing_id  | String | - |  Id of the product/listing/project/property for which lead is generated. Example: "111"
listing_name |  String | - | name of the project/property for which lead is generated. Example: "Runwal Green"
current_time | Integer | True | current epoch time in second(notmilisecond) Link: https://www.epochconverter.com/clock
hash | String | True | Generated in the section  above Hash should be created using the same time stamp as sent in the parameter `current_time`
city | String | - | Example "Mumbai"
locality | String | - | Example "Bandra West"
min_budget | Integer | - | exmaple 10000000
max_budget | Integer | - | exmaple 50000000
contact_date | Integer | - | epoch time(in second) at which lead has contacted
remarks | String | - | additional comment about lead
homeloan_required | Boolean | - | whether the lead is interested in home loan or not
is_otp_verified | Boolean | - | whether the lead is OTP verified or not
is_call_verified | Boolean | - | whether the lead is Call verified or not
credit_value | Stirng | - | credit/ cost of the lead. Exmaple: "250"
is_broker | Boolean | - | whether the lead submitted is of a broker or not
apartment_types |  String | - | comma separated bhk types where bhk type can be `1bhk/2bhk/3bhk/3+bhk/1rk`) example: "2bhk,3+bhk"
source | String | - |  `google`, `facebook`, `affiliate`, `emailer`, `linkedin`, `portals`,`twitter`, etc - this field should always contain primary origin or lead
sub_source | String | - | `google_display`, `google_search`, `facebook_brands`, `facebook_lead_gen`, `affiliate`  - this should identify the type of campaign either branding or performance
placement |  String | - | `utm_campaign` , `affiliate_name` e.g. taboola, nestoria, polyvalent, times_of_india, `portal_name` e.g. 99acres, magicbricks, housing  - this should tell exact campaign details be it google facebook etc. generally you should pass utm_campaign in this
extra_details | JSON | - | key-value pair which will contain any extra details for lead e.g. {"utm_medium: "something", "utm_source": "something", "keyword": "targetted keyword on google for the campaign"}
campaign_id | String | True | The is a unique identifier for the project you are sending the lead for. Should be collected from point of contact in ANAROCK team. Without this lead attribution will be incorrect.

> Remember — without proper __campaign_id__, leads will not be attributed to the correct project team. Always check with your point of contact that leads are attributed to the desired project only.

### PHONE NUMBER VALIDATION

Please format phone numbers before sending using one of the libraries below

Language | Link
------- | -------
PHP | https://github.com/brick/phonenumber
NodeJS | https://www.npmjs.com/package/awesome-phonenumber

# Check Successful Submission

```php
// PHP
$key = 'KEY';
$current_time = time();
$message = (string)$current_time;

// to lowercase hexits
$hash = hash_hmac('sha256', $message, $key);

$phone =<PHONE_NUMBER> // Phone number to test

$api_url = "https://lead-webhook.staging.<HOST>/api/v0/CHANNEL_NAME/last-lead-data?phone="+$phone+"&current_time="+$current_time+"&hash="+$hash

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
// print_r($server_output);
```

```javascript
// NodeJS
const crypto = require('crypto');
const timeStamp = Math.round((new Date()).getTime() / 1000);
const message = timeStamp.toString()
const hash = crypto.createHmac('sha256', key).update(message).digest('hex')

const phone =<PHONE_NUMBER> // valid mobile number
const host = 'anarock.com' // use correct host url

axios({
  method: "GET",
  url: `https://lead-webhook.staging.${host}/api/v0/CHANNEL_NAME/last-lead-data?phone=${phone}&current_time=${timeStamp}&hash=${hash}`
})
```

> This API will respond with following structured JSON:

```json
{
  "status":"OK",
  "message":"success",
  "response":{
      "lead_id":194466,
      "name":"name",
<EMAIL_ADDRESS>      "phone":"+9199999999",
      "country_code":"+91",
      "source":null,
      "sub_source":null,
      "placement":null,
      "extra_details":null,
      "project_name":"bkc test",
      "source_id": 1,
      "sub_source_id": 10
      }
    }
}
```

To check if a lead has been successfully submitted with all parameters captured correctly.

Use the following GET API

`staging`

`https://lead-webhook.staging.<HOST>/api/v0/CHANNEL_NAME/last-lead-data?phone=PHONE_NUMBER&current_time=CURRENT_TIME&hash=HASH`

--

`production`

`https://lead.<HOST>/api/v0/CHANNEL_NAME/last-lead-data?phone=PHONE_NUMBER&current_time=CURRENT_TIME&hash=HASH`

> Please ensure that you are getting the project name intended in the reponse given on the right.

repository: anarock/leads

repo_name: anarock/leads


text:
# Tracker-Webapp

This is a full-stack progress tracker webapp.
The application is split into two parts:

### Tracker-Server:
REST api providing all endpoints for the webapp. MonogDB is used to manage data storage and access.
The api is documented [here](https://github.com/LukasKuppers/Tracker-Webapp/blob/master/Tracker-Server/Controllers/README.md).

Framework used is .net Core.
### Tracker-Web:
All UI implemented using blazor webassebly (similar to react, but all code is C#!).

repository: LukasKuppers/Tracker-Webapp

gha_language: CSS

repo_name: LukasKuppers/Tracker-Webapp


text:
# Unit 2 - Module 6: Borrowing and Mutability

| Example | Description | Compiles? |
|---------|-------------|-----------|
| [01-59-socket](01-59-socket) | The TCP Socket gets closed when `_listener` goes out of scope | ✅ |
| [03-00-ruby-socket-example](03-00-ruby-socket-example) | An example IN RUBY that doesn't automatically close the TCP Socket | N/A* |
| [05-24-drop-trait](05-24-drop-trait) | Implementing the `Drop` trait | ✅ |

\* Ruby isn't compiled. This will run with `ruby socket.rb` if you have Ruby installed.

gha_license_id: NOASSERTION


text:
## Lab 00 - Setup

**Welcome to the first lab session.**

On this page, you will find a brief introduction for the lab and some administrative information.

The complete instructions are available in another GitHub repo, which you will **fork** (you will have your copy of the repo hosted on GitHub) and then **clone** (you will have a copy your your fork on your machine).

The repo is available at [SoftEng-HEIGVD/Teaching-HEIGVD-RES-2015-Labo-00](https://github.com/SoftEng-HEIGVD/Teaching-HEIGVD-RES-2015-Labo-00).

**Enjoy**.

### Objectives

There are **3 objectives** in this lab:

1. Start the **setup of your environment** for this course. We will not install all the tools required for the labs, but after today you should have the main ones up and running.

2. Introduce the **workflow** that we will use for many labs in this course. In this workflow, you will learn how to use **GitHub** and **git** to get the lab instructions, do your assignment and submit your work. This is a workflow that is very, very similar to what experienced developers do in a professional environment.

3. Present the concepts of **Behavior Driven Development** (BDD), Test Driven Development (TDD) and unit tests. For some of the labs, we will specify what you have to implement by giving you a list of automated tests. At the beginning, all the tests will fail. As you make progress with the assignment, your tests will turn green. When you submit your work, we will run the tests again to evaluate your work.

### Groups

It is very important that everyone has a fully functional environment. It is very important that everyone goes through all the steps of the workflow. For these reasons, we request that you do this lab individually. Of course, you are invited to discuss and help each other, but we expect a deliverable from everyone.

### Deadlines

1. **TODAY**. At the end of the session, you need to have your environment setup. You also must have created your fork on GitHub and cloned it on your machine. Finally, you must have been able to execute the tests with maven (more on this later). **If you have not managed to achieve these key objectives, come to us ASAP.**

2. **On Tuesday, February 24th**, we will make a first evaluation of the results. We will check the forks, run the tests on your code and have a look at the results. **Make sure that you have done a git push** on Monday evening at the latest! This will give us an indication of the class progress. **Please help us** and pay attention to this intermediate milestone!

3. **On Tuesday, March 3rd**, we will do the formal evaluation of your submissions. We will run the automated tests on your forks once again. We will **analyze the number of passing and failing tests**. This will give us a measure of your success.

### Grading

The goal of this first lab is to get familiar with the workflow and the supporting tools. The code that you have to write is trivial. We will not give you a formal grade for the lab.

**However**, we will keep track of your results and they will be used for the evaluation of your overall performance during the course. But more importantly: if you do not invest enough time in this lab, if you don't understand what is happening and don't master the tools, **you will suffer a lot** during the upcoming labs (and next year).

Please invest the time to achieve the lab objectives. Please come to us and let us know if you have issues or do not understand some of the tasks. If you have questions when you are working outside lab hours or if we are busy with someone else, open a discussion in the moodle forum.


text:
# Quote Machine

This project was part of Free Code Camp and utilizes JQuery with the Quotable REST API in order to deliver some inspirational quotes.

## Usage

Feel free to borrow any aspects you think would work for you.

## Contributing

I always appreciate feedback!

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

repository: CaryTanner/quote-machine

repo_name: CaryTanner/quote-machine


text:
# k-dropdown

**_`k-dropdown` is a part of the `k-dropdown` family of components._**

`k-dropdown` is Vuh's web component for a dropdown.

It receives instances of `k-dropdown-item` as its children, which are then displayed when the component is clicked.

<!-- Auto Generated Below -->

## Properties

| Property          | Attribute          | Description | Type                                     | Default     |
| ----------------- | ------------------ | ----------- | ---------------------------------------- | ----------- |
| `color`           | `color`            |             | `"primary" \| "secondary" \| "terciary"` | `'primary'` |
| `disabled`        | `disabled`         |             | `boolean`                                | `false`     |
| `helperText`      | `helper-text`      |             | `string`                                 | `''`        |
| `label`           | `label`            |             | `string`                                 | `undefined` |
| `validationState` | `validation-state` |             | `"" \| "error" \| "success"`             | `''`        |
| `variant`         | `variant`          |             | `"button" \| "input" \| "table"`         | `'button'`  |

----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*

repository: jf-gm/vuh-components-test

branch_name: refs/heads/main

repo_name: jf-gm/vuh-components-test


text:
Make sure you have docker and docker-compose installed and operational.

Note: as stated by Docker, docker-compose is [not yet recommended for production use](https://docs.docker.com/compose/production/) at this time.

Look for the `docker-compose.yml` file at the top level of the [Rocket.Chat Git repo](https://github.com/RocketChat/Rocket.Chat).  This is the ONLY file you will need from the repo.  You can create this file on your own machine by copy and pasting the content.

Open it with an editor and modify:

*  `ROOT_URL` to match your domain name or IP address

Start the mongodb server by:

````
docker-compose up -d mongo
````

Mongo supports 24 x 7 operations and live backup.  You should not need to restart it too frequently.  See  [mongodb documentations](https://docs.mongodb.org/manual/) for proper operation and management of a mongo server.

Once you're sure that mongodb is up and running:

````
docker-compose up -d rocketchat
````

Optionally, if you want to manage your messages and configuration information, edit the file again to uncomment the volume mounts.   Make sure you have a `data` subdirectory to mount and store the data.

Optiionally, if you want a bot, so you don't have to talk to yourself, after you've created an admin user and also a bot user, edit the file `docker-compose.yml` again to change the variables `ROCKETCHAT_USER` and `ROCKETCHAT_PASSWORD` in the hubot section and then start up hubot:

````
docker-compose up -d hubot
````

## Updating the docker image

To update the `rocketchat` docker image to the latest version, you can use the following commands. Your data should not be affected by this, since it's located in the `mongo` image.

```
docker pull rocketchat/rocket.chat:develop
docker-compose stop rocketchat
docker-compose rm rocketchat
docker-compose up -d rocketchat
```


text:
tessel-simple-negifuri
======================

simple negifuri with servo and tessel

## Setup

Connect your servo motor control line to Tessel `G4` port.

```
# setup this application.
$ git clone https://github.com/mia-0032/tessel-simple-negifuri.git
$ cd tessel-simple-negifuri
$ npm install
```

## Test Run

```
$ tessel run index.js
```

## Stand-alone Run

```
$ tessel push index.js
```

## Edit Program

If you edit program, you need to install coffee-script.

```
$ npm install -g coffee-script
```

And compile script after editting `index.coffee`.

```
$ coffee -c index.coffee
```


text:
---
layout: post
title: CSS Pre-Processor.Tuesday
---

 Responsive Images

  I didn’t have any idea of what’s CSS pre-processors before I taken the last class. I feel like the CSS pre-processors are very helpful and make things a lot easier. I really like the mixins and nesting part, because I no longer need to write much more codes and they make the codes a lot easier to read.
I would like to use them in my after works, because I ‘d like to learn new things especially it will make my life easier . However, I need more practices to do it well, because the form is little different than the original CSS. But I like how they organized the codes, I think I’m going love it.

See the Pen ICyse by evan (@evanlamb) on CodePen.

path: /_posts/2014-10-7-CSS Pre-Processor.md

filename: 2014-10-7-CSS Pre-Processor.md


text:
# Pre-work - TipCalculatorProper

TipCalculatorProper is a tip calculator application for iOS.

Submitted by: Poojan Dave

Time spent: 6 hours spent in total

## User Stories

The following **required** functionality is complete:

* [x] User can enter a bill amount, choose a tip percentage, and see the tip and total values.

The following **optional** features are implemented:
* [x] Settings page to change the default tip percentage.
* [ ] UI animations
* [ ] Remembering the bill amount across app restarts (if <10mins)
* [ ] Using locale-specific currency and currency thousands separators.
* [ ] Making sure the keyboard is always visible and the bill amount is always the first responder. This way the user doesn't have to tap anywhere to use this app. Just launch the app and start typing.

The following **additional** features are implemented:

- [x] List anything else that you can get done to improve the app functionality!
- [x] Added thousand currency splitter; adds a comma to properly show thousands as a value
- [x] Added a custom tip option
- [x] Added a split bill option; implemented it on the settings page
- [x] Shake gesture feature implemented; clears the bill and resets to default tip and split

## Video Walkthrough

Here's a walkthrough of implemented user stories:

Original GIF:

![animatedGIF](TipCalculatorGif.gif)

Updated GIF:

![animatedGIF](TipCalculatorGifUpdated.gif)

GIF created with [LiceCap](http://www.cockos.com/licecap/).

## Notes

Describe any challenges encountered while building the app.

I was not aware that there was a video tutorial with help on how to create a tip calculator. I made one myself at first, which was a challenge, but I learned a lot.
I also had issues since the video is pretty recent but still somewhat outdated. However, I was able to solve those situations by looking online for solutions. Since I was not too familiar with the syntax in swift, I had to learn it first. So, I learned the major concepts of Swift such as Optionals and general syntax.
This was a very fun project. I feel like I am going to learn a lot.

## License

    Copyright [2017] [Poojan Dave]

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

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

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

repository: pdave-sfsu/TipCalculatorProper

repo_name: pdave-sfsu/TipCalculatorProper


text:
---
title: BuSearchAgentSchedulesRequest
---
## ININ.PureCloudApi.Model.BuSearchAgentSchedulesRequest

## Properties

|Name | Type | Description | Notes|
|------------ | ------------- | ------------- | -------------|
| **StartDate** | **DateTime?** | Start date of the range to search. Date time is represented as an ISO-8601 string. For example: yyyy-MM-ddTHH:mm:ss[.mmm]Z | |
| **EndDate** | **DateTime?** | End date of the range to search. Date time is represented as an ISO-8601 string. For example: yyyy-MM-ddTHH:mm:ss[.mmm]Z | |
| **UserIds** | **List<string>** | IDs of the users for whose schedules to search | [optional] |
{: class="table table-striped"}

repository: MyPureCloud/platform-client-sdk-dotnet

gha_language: C#

repo_name: MyPureCloud/platform-client-sdk-dotnet


text:
Ramda Ruby
=============

This is ruby version of of Ramda library from (http://ramdajs.com)

[![Gem Version](https://badge.fury.io/rb/ramda-ruby.svg)](http://badge.fury.io/rb/ramda-ruby)
[![Travis badge](https://travis-ci.org/lazebny/ramda-ruby.svg?branch=master)](https://travis-ci.org/lazebny/ramda-ruby)
[![AppVeyor status](https://ci.appveyor.com/api/projects/status/ponccdax7aj4ufw2?svg=true)](https://ci.appveyor.com/project/lazebny/ramda-ruby)
[![Coverage Status](https://coveralls.io/repos/lazebny/ramda-ruby/badge.png)](https://coveralls.io/r/lazebny/ramda-ruby)
[![Code Climate Badge](https://codeclimate.com/github/lazebny/ramda-ruby.svg)](https://codeclimate.com/github/lazebny/ramda-ruby)
[![Inch CI](http://inch-ci.org/github/lazebny/ramda-ruby.svg)](http://inch-ci.org/github/lazebny/ramda-ruby)
[![Dependency Status](https://gemnasium.com/lazebny/ramda-ruby.svg)](https://gemnasium.com/lazebny/ramda-ruby)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)

Installation
------------

Add this line to your application's Gemfile:

```ruby
gem 'ramda-ruby'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install ramda-ruby

And then require:

```ruby
reuire 'ramda'
```

## Documentation

This gem tries to follow the same versions as ramdajs has.

[Implemeted Functions](docs/FUNCTIONS.md)

Currently this project doesn't have own documentation but it tries to follow
specification from http://ramdajs.com/docs/. You could use this resource as a
source of documentation. Examples exist in spec directory.

## Usage

TODO: Write usage instructions here

## 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/[USERNAME]/ramda-ruby.

## License

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

license: Ruby,MIT

repository: Eversilence/ramda-ruby

detected_licenses: Ruby MIT

repo_name: Eversilence/ramda-ruby


text:
# Transformation : JSON-to-XML and HTTP header injection

*Duration : 30 mins*

*Persona : API Team*

# Use case

You have an API Proxy that returns a JSON payload but a potential business partner has asked that you provide XML based on the Accept header provided by the client.  The backend does not support XML.  You don’t own the backend service and even if you did, by the time your team changed the backend and it passed all your enterprise integration tests, you would have lost the partner opportunity.

# How can Apigee Edge help?

The [JSON to XML Policy](http://docs.apigee.com/api-services/reference/json-xml-policy) in Edge converts request or response messages from JSON to XML.  The default configuration should work in most cases but the policy gives you fine-grained control over all of the conversion features, such as namespaces, attributes, array elements, null values, separators, and how to handle invalid characters.

In this lab, you will modify an existing API Proxy to allow a JSON backend to return XML to clients who request it.  To achieve this you will perform the following -

1. If a request has an Accept header of "application/xml"

    1. Remove the (XML) Accept header to allow the target to return JSON

    2. Implement the [JSON to XML Policy](http://docs.apigee.com/api-services/reference/json-xml-policy) to convert the response body from JSON to XML

    3. Inject a response header of "Content-type: application/xml".

# Pre-requisites

For this lab, you will need an API Proxy that returns JSON.  If you do not have an API Proxy available for this lab, revisit the lab "API Design : Create a Reverse Proxy with OpenAPI Specification" and then return here to complete these steps.

# Instructions

## Test existing API Proxy with different Accept Headers

* Go to [https://apigee.com/edge](https://apigee.com/edge) and log in. This is the Edge management UI

* Select **Develop → API Proxies**

![image alt text](./media/image_0.jpg)

* Find and open the Employee API Proxy that you want transform by clicking on it.

![image alt text](./media/image_1.png)

* Verify that the API Proxy is **deployed** to *test* environment.

* **Copy** the URL for the API Proxy from the Overview tab.

![image alt text](./media/image_2.png)

* Verify the API returns JSON data using the [Apigee Rest Client](https://apigee-restclient.appspot.com/) or any http client of your choosing

    * Open [Apigee Rest Client](https://apigee-restclient.appspot.com/)

    * Paste URL from **Overview** page.

    * Click **Send**.

![image alt text](./media/image_3.png)

* Make another request, this time with a header specifying that you ```Accept application/xml```.  This backend does not support XML clients so you receive a 404.

![image alt text](./media/image_4.png)

* Try making another request, explicitly setting the Accept header to ```application/json```.  It should return JSON as when you did not specify the header.

## Understanding the approach

The test has demonstrated that the backend service accepts requests with the header ```Accept: application/json``` or requests with no Accept header.  It fails for requests with the header ```Accept: application/xml```.

Our approach will be to implement four policies.  The first will read the Accept header of the request, the remaining three will implement the following logic, if and only if the first policy found the Accept header to be equal to ```application/xml```

1. Extract the *Accept* header

2. If extracted header matches ```application/xml```, replace Accept header with ```application/json``` to satisfy the backend.

…  invoke the backend.

3. If extracted header matches ```application/xml```, convert JSON to XML

4. If extracted header matches ```application/xml```, set the header ```Content-type: application/xml```.

## Open the API Proxy for Development

* Open the API Proxy and click the **Develop** tab.  All of our work will be performed in the "Default Proxy Endpoint’s All PreFlow".  To better understand Flows and the appropriate place to apply policies in Apigee Edge, Read [Understanding Flows](http://docs.apigee.com/api-services/content/understanding-flows-and-resources).

![image alt text](./media/image_5.png)

## Extract Original Accept Header

* From the **Develop** tab of the API Proxy.

* Click **Preflow** under Default Proxy Endpoint.

* Click **+Step** to add a policy to the Default Proxy Endpoint’s **Request** PreFlow.

* Select the [Extract Variables Policy](http://docs.apigee.com/api-services/reference/extract-variables-policy) from the list of policies.

* Enter *Display Name* as **Extract Accept Header**.

* Click **Add**

![image alt text](./media/image_6.png)

* The new policy is added with a default configuration.  Replace it with the code below which will extract the *Accept* header and put it into a variable *{OriginalAcceptHeader}*

```
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables continueOnError="false" enabled="true" name="Extract-Accept-Header">
    <DisplayName>Extract Accept Header</DisplayName>
    <Header name="Accept">
        <Pattern ignoreCase="true">{originalAcceptHeader}</Pattern>
    </Header>
</ExtractVariables>
```

![image alt text](./media/image_7.png)

## Overwrite Accept Header (conditionally)

* From the **Develop** tab of the API Proxy.

* Click **Preflow** under Default Proxy Endpoint.

* Click **+Step** to add a policy to the Default Proxy Endpoint’s **Request** PreFlow.

* Select the [Assign Message Policy](http://docs.apigee.com/api-services/reference/assign-message-policy) from the list of policies.

* Set the *Display Name* as **Remove Accept Header**.

* Click **Add**

![image alt text](./media/image_8.png)

* The new policy is added with a default configuration.  Like with the previous policy, replace it with the code below which will set the Accept header to *application/json*

```
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage continueOnError="false" enabled="true" name="Remove-Accept-Header">
    <DisplayName>Remove Accept Header</DisplayName>
    <Set>
        <Headers>
            <Header name="Accept">application/json</Header>
        </Headers>
    </Set>
</AssignMessage>
```

* Open the Apigee Rest Client and test the API with ```Accept: application/json```. It should succeed even if you send headers like “Accept: application/invalid”.  This is because this policy is not conditional, it **always** overwrites even invalid headers.  We will fix that now by making this new policy conditional.  It will only execute when the original request has a header of *application/xml*.

* The code snippet below is a conditional statement that control execution of the policies we add to flows.  Read this to learn all about [Conditions](http://docs.apigee.com/api-services/reference/conditions-reference) in Apigee.  Add the below code snippet into the configuration pane for the request flow, as depicted below.  It will cause the Remove-Accept-Header policy to be executed only when the original request passed in *application/xml*.

```
<Condition>originalAcceptHeader EqualsCaseInsensitive "application/xml"</Condition>
```

![image alt text](./media/image_9.png)

* Open the Apigee Rest Client and run the tests again.  We’ve altered the request so the backend will give a response when the client passes us ```Accept: application/json``` or ```Accept: application/xml```.  We’re halfway there.  In the next two steps of the lab we’ll handle converting the response to XML when the client requests it.

## Convert JSON to XML (conditionally)

This policy will be added similarly to the previous two but we will be applying it to the response flow because we want to alter the response that comes from the target server.

* From the **Develop** tab of the API Proxy…

* Click **Preflow** under Default Proxy Endpoint.

* Click **+Step** to add a policy to the Default Proxy Endpoint’s **Response** PreFlow.

![image alt text](./media/image_10.png)

* Select the [JSON to XML](http://docs.apigee.com/api-services/reference/json-xml-policy) from the list of policies.

* Leave the default Display Name and Name.

* Click **Add** to add the new policy in the Response flow.

* Select the new policy and replace its default code with the snippet below

```
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONToXML continueOnError="false" enabled="true" name="JSON-to-XML-1">
    <DisplayName>JSON to XML-1</DisplayName>
</JSONToXML>
```

![image alt text](./media/image_11.png)

* This policy should be conditional as well, based on the original request’s Accept Header.  Paste the condition below into the Default Proxy Endpoint’s PreFlow, inside the Step for the Json to XML Policy.

```
<Condition>originalAcceptHeader EqualsCaseInsensitive "application/xml"</Condition>
```

![image alt text](./media/image_12.png)

## Set Content-Type Header (conditionally)

This policy will also be added to the response flow because we want to assign a Header on the response message before it is sent to the client.

* From the **Develop** tab of the API Proxy.

* Click **Preflow** under Default Proxy Endpoint.

* Click **+ Step** to add a policy to the Default Proxy Endpoint’s **Response** PreFlow.

![image alt text](./media/image_13.png)

* Select the [Assign Message](http://docs.apigee.com/api-services/reference/assign-message-policy) from the list of policies.

* Set the *Display Name* to **Set Content-Type Header**.

* Click **Add** to add the new policy in the Response flow.

* Select the new policy and replace its default code with the snippet below

```
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage continueOnError="false" enabled="true" name="Set-Content-Type-Header">
    <DisplayName>Set Content-Type Header</DisplayName>
    <Set>
        <Headers>
            <Header name="Content-type">application/xml</Header>
        </Headers>
    </Set>
</AssignMessage>
```

* Make this policy depend on the same condition as the previous two, based on the original request’s Accept Header.  Paste the condition below into the Default Proxy Endpoint’s PreFlow, inside the Step for the Set-Content-Type-Header Policy.

```
<Condition>originalAcceptHeader EqualsCaseInsensitive "application/xml"</Condition>
```

# Lab Video

If you would rather watch a video that covers this topic, point your browser [here](https://youtu.be/xf9SVFBB4vg).

# Earn Extra-points

Try add a new Header on the response that contains a value you pass in as a Query Parameter.  For example.. [http://api.example.com/v1/myapi?debug=true](http://api.example.com/v1/myapi?debug=true) could cause your backend to respond with a Header that includes the client’s IP address (hint: the variable is called proxy.client.ip)

# Quiz

1. What policy do we use to get a variable from a request or response?

2. What would the result be if we switched the order of the two policies on the Request PreFlow?

# Summary

You’ve learned how to do the following;

* Use the Extract Variables Policy to extract a header and save it as a context variable.

* Use the Assign Message Policy to set Headers on the request and response.

* Use the JSON to XML Policy to convert JSON to XML

* Write conditional statements that affect flow logic based on context

# References

* Link to Apigee docs page

    * [Assign Message](http://docs.apigee.com/api-services/reference/assign-message-policy) Policy

    * [JSON to XML](http://docs.apigee.com/api-services/reference/json-xml-policy) Policy

    * [Extract Variables](http://docs.apigee.com/api-services/reference/extract-variables-policy) Policy

    * [Conditions](http://docs.apigee.com/api-services/reference/conditions-reference) in Apigee

* Apigee Rest Client

    * [https://apigee-restclient.appspot.com/](https://apigee-restclient.appspot.com/)

# Rate this lab

How did you link this lab? Rate [here](https://goo.gl/forms/gslNXeARKFThX8of1).

url: https://raw.githubusercontent.com/apigee/apijam/15436143911f711aa40f4c109badf5bae6911862/Archives/Archived_10-18-2019/Labs/Appendix/Transformation - JSON-to-XML - HTTP header injection/README.md

repository: apigee/apijam

repo_name: apigee/apijam


text:
# RTI: Testing Machine Translation via Referential Transparency

RTI is a inspired by a concept in functional programming: referential transparency.

To set up language parsers:
+ Download the [core NLP libarary](http://nlp.stanford.edu/software/stanford-corenlp-full-2018-10-05.zip).
+ Unzip the file and open the folder.
+ Run `java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -ServerProperties props.properties -preload tokenize,ssplit,pos,lemma,ner,parse -status_port 9000 -port 9000`

Read more information about RTI from the following paper:

+ Pinjia He, Clara Meister, Zhendong Su. [Testing Machine Translation via Referential Transparency](https://pinjiahe.github.io/papers/ICSE21.pdf), *International Conference on Software Engineering (ICSE)*, 2021.

repository: tjudoubi/TestTranslation

repo_name: tjudoubi/TestTranslation


text:
# HaloDB

[![Build Status](https://travis-ci.org/yahoo/HaloDB.svg?branch=master)](https://travis-ci.org/yahoo/HaloDB)
[![Download](https://api.bintray.com/packages/yahoo/maven/halodb/images/download.svg) ](https://bintray.com/yahoo/maven/halodb/_latestVersion)

HaloDB is a fast and simple embedded key-value store written in Java. HaloDB is suitable for IO bound workloads, and is capable of handling high throughput reads and writes at submillisecond latencies.

HaloDB was written for a high-throughput, low latency distributed key-value database that powers multiple ad platforms at Yahoo, therefore all its design choices and optimizations were
primarily for this use case.

Basic design principles employed in HaloDB are not new. Refer to this [document](docs/WhyHaloDB.md) for more details about the motivation for HaloDB and its inspirations.

HaloDB comprises of two main components: an index in memory which stores all the keys, and append-only log files on
the persistent layer which stores all the data. To reduce Java garbage collection pressure the index
is allocated in native memory, outside the Java heap.

![HaloDB](https://raw.githubusercontent.com/amannaly/HaloDB-images/master/images/halodb.png)

### Basic Operations.
```java
            // Open a db with default options.
            HaloDBOptions options = new HaloDBOptions();

            // Size of each data file will be 1GB.
            options.setMaxFileSize(1024 * 1024 * 1024);

            // Size of each tombstone file will be 64MB
            // Large file size mean less file count but will slow down db open time. But if set
            // file size too small, it will result large amount of tombstone files under db folder
            options.setMaxTombstoneFileSize(64 * 1024 * 1024);

            // Set the number of threads used to scan index and tombstone files in parallel
            // to build in-memory index during db open. It must be a positive number which is
            // not greater than Runtime.getRuntime().availableProcessors().
            // It is used to speed up db open time.
            options.setBuildIndexThreads(8);

            // The threshold at which page cache is synced to disk.
            // data will be durable only if it is flushed to disk, therefore
            // more data will be lost if this value is set too high. Setting
            // this value too low might interfere with read and write performance.
            options.setFlushDataSizeBytes(10 * 1024 * 1024);

            // The percentage of stale data in a data file at which the file will be compacted.
            // This value helps control write and space amplification. Increasing this value will
            // reduce write amplification but will increase space amplification.
            // This along with the compactionJobRate below is the most important setting
            // for tuning HaloDB performance. If this is set to x then write amplification
            // will be approximately 1/x.
            options.setCompactionThresholdPerFile(0.7);

            // Controls how fast the compaction job should run.
            // This is the amount of data which will be copied by the compaction thread per second.
            // Optimal value depends on the compactionThresholdPerFile option.
            options.setCompactionJobRate(50 * 1024 * 1024);

            // Setting this value is important as it helps to preallocate enough
            // memory for the off-heap cache. If the value is too low the db might
            // need to rehash the cache. For a db of size n set this value to 2*n.
            options.setNumberOfRecords(100_000_000);

            // Delete operation for a key will write a tombstone record to a tombstone file.
            // the tombstone record can be removed only when all previous version of that key
            // has been deleted by the compaction job.
            // enabling this option will delete during startup all tombstone records whose previous
            // versions were removed from the data file.
            options.setCleanUpTombstonesDuringOpen(true);

            // HaloDB does native memory allocation for the in-memory index.
            // Enabling this option will release all allocated memory back to the kernel when the db is closed.
            // This option is not necessary if the JVM is shutdown when the db is closed, as in that case
            // allocated memory is released automatically by the kernel.
            // If using in-memory index without memory pool this option,
            // depending on the number of records in the database,
            // could be a slow as we need to call _free_ for each record.
            options.setCleanUpInMemoryIndexOnClose(false);

            // ** settings for memory pool **
            options.setUseMemoryPool(true);

            // Hash table implementation in HaloDB is similar to that of ConcurrentHashMap in Java 7.
            // Hash table is divided into segments and each segment manages its own native memory.
            // The number of segments is twice the number of cores in the machine.
            // A segment's memory is further divided into chunks whose size can be configured here.
            options.setMemoryPoolChunkSize(2 * 1024 * 1024);

            // using a memory pool requires us to declare the size of keys in advance.
            // Any write request with key length greater than the declared value will fail, but it
            // is still possible to store keys smaller than this declared size.
            options.setFixedKeySize(8);

            // Represents a database instance and provides all methods for operating on the database.
            HaloDB db = null;

            // The directory will be created if it doesn't exist and all database files will be stored in this directory
            String directory = "directory";

            // Open the database. Directory will be created if it doesn't exist.
            // If we are opening an existing database HaloDB needs to scan all the
            // index files to create the in-memory index, which, depending on the db size, might take a few minutes.
            db = HaloDB.open(directory, options);

            // key and values are byte arrays. Key size is restricted to 128 bytes.
            byte[] key1 = Ints.toByteArray(200);
            byte[] value1 = "Value for key 1".getBytes();

            byte[] key2 = Ints.toByteArray(300);
            byte[] value2 = "Value for key 2".getBytes();

            // add the key-value pair to the database.
            db.put(key1, value1);
            db.put(key2, value2);

            // read the value from the database.
            value1 = db.get(key1);
            value2 = db.get(key2);

            // delete a key from the database.
            db.delete(key1);

            // Open an iterator and iterate through all the key-value records.
            HaloDBIterator iterator = db.newIterator();
            while (iterator.hasNext()) {
                Record record = iterator.next();
                System.out.println(Ints.fromByteArray(record.getKey()));
                System.out.println(new String(record.getValue()));
            }

            // get stats and print it.
            HaloDBStats stats = db.stats();
            System.out.println(stats.toString());

            // reset stats
            db.resetStats();

            // pause background compaction thread.
            // if a file is being compacted the thread
            // will block until the compaction is complete.
            db.pauseCompaction();

            // resume background compaction thread.
            db.resumeCompaction();

            // repeatedly calling pause/resume compaction methods will have no effect.

            // Close the database.
            db.close();
```
Binaries for HaloDB are hosted on [Bintray](https://bintray.com/yahoo).
``` xml
<dependency>
  <groupId>com.oath.halodb</groupId>
  <artifactId>halodb</artifactId>
  <version>x.y.x</version>
</dependency>

<repository>
  <id>yahoo-bintray</id>
  <name>yahoo-bintray</name>
  <url>https://yahoo.bintray.com/maven</url>
</repository>
```

### Read, Write and Space amplification.
Read amplification in HaloDB is always 1—for a read request it needs to do at most one disk lookup—hence it is well suited for
read latency critical workloads. HaloDB provides a configuration which can be tuned to control write amplification
and space amplification, both of which trade-off with each other; HaloDB has a background compaction thread which removes stale data
from the DB. The percentage of stale data at which a file is compacted can be controlled. Increasing this value will increase space amplification
but will reduce write amplification. For example if the value is set to 50% then write amplification will be approximately 2

### Durability and Crash recovery.
Write Ahead Logs (WAL) are usually used by databases for crash recovery. Since for HaloDB WAL _is the_ database crash recovery
is easier and faster.

HaloDB does not flush writes to disk immediately, but, for performance reasons, writes only to the OS page cache. The cache is synced to
disk once a configurable size is reached. In the event of a power loss, the data not flushed to disk will be lost. This compromise
between performance and durability is a necessary one.

In the event of a power loss and data corruption, HaloDB will scan and discard corrupted records. Since the write thread and compaction
thread could be writing to at most two files at a time only those files need to be repaired and hence recovery times are very short.

In the event of a power loss HaloDB offers the following consistency guarantees:
* Writes are atomic.
* Inserts and updates are committed to disk in the same order they are received.
* When inserts/updates and deletes are interleaved total ordering is not guaranteed, but partial ordering is guaranteed for inserts/updates and deletes.

### In-memory index.
HaloDB stores all keys and their associated metadata in an index in memory. The size of this index, depending on the
number and length of keys, can be quite big. Therefore, storing this in the Java Heap is a non-starter for a
performance critical storage engine. HaloDB solves this problem by storing the index in native memory,
outside the heap. There are two variants of the index; one with a memory pool and the other
without it. Using the memory pool helps to reduce the memory footprint of the index and reduce
fragmentation, but requires fixed size keys. A billion 8 byte keys
currently takes around 44GB of memory with memory pool and around 64GB without memory pool.

The size of the keys when using a memory pool should be declared in advance, and although this imposes an
upper limit on the size of the keys it is still possible to store keys smaller than this declared size.

Without the memory pool, HaloDB needs to allocate native memory for every write request. Therefore,
memory fragmentation could be an issue. Using [jemalloc](http://jemalloc.net/) is highly recommended as it
provides a significant reduction in the cache's memory footprint and fragmentation.

### Delete operations.
Delete operation for a key will add a tombstone record to a tombstone file, which is distinct from the data files.
This design has the advantage that the tombstone record once written need not be copied again during compaction, but
the drawback is that in case of a power loss HaloDB cannot guarantee total ordering when put and delete operations are
interleaved (although partial ordering for both is guaranteed).

### DB open time
Open db could take a few minutes, depends on number of records and tombstones. If the db open time is critical to your
use case, please keep tombstone file size relatively small and increase the number of threads used in building index.
See the option setting section in example code above. As best practice, set tombstone file size at 64MB and set build
index threads to number of available processors divided by number of dbs being opened simultaneously.

### System requirements.
* HaloDB requires Java 8 to run, but has not yet been tested with newer Java versions.
* HaloDB has been tested on Linux running on x86 and on MacOS. It may run on other platforms, but this hasn't been verified yet.
* For performance disable Transparent Huge Pages and swapping (vm.swappiness=0).
* If a thread is interrupted JVM will close those file channels the thread was operating on.
Therefore, don't interrupt threads while they are doing IO operations.

### Restrictions.
* Size of keys is restricted to 128 bytes.
* HaloDB don't support range scans or ordered access.

# Benchmarks.
[Benchmarks](docs/benchmarks.md).

# Contributing
Contributions are most welcome. Please refer to the [CONTRIBUTING](https://github.com/yahoo/HaloDB/blob/master/CONTRIBUTING.md) guide

# Credits
HaloDB was written by [Arjun Mannaly](https://github.com/amannaly).

# License
HaloDB is released under the Apache License, Version 2.0

repository: yahoo/HaloDB

gha_language: Java

repo_name: yahoo/HaloDB


text:
# MIRUReader

## Description

Identify 24-locus MIRU-VNTR for *Mycobacterium tuberculosis* complex (MTBC) directly from long reads generated by Oxford Nanopore Technologies (ONT) and Pacific Biosciences (PacBio). Also work on assembled genome.

## Requirements

* Linux
* primersearch from [EMBOSS](http://emboss.sourceforge.net/download/)
   * install from the official website or
   * install via conda `conda install -c bioconda emboss`
   * Ensure the primersearch command is in your device's environment path, where primersearch program can be executed directly by typing `primersearch` on the commandline
* [*pandas*](https://pandas.pydata.org/)
   * can be installed via conda `conda install pandas` or via PyPI `pip install pandas`
* [*statistics*](https://pypi.org/project/statistics/)
   * can be installed via PyPI `pip install statistics`

## Installation

`git clone https://github.com/phglab/MIRUReader.git`

## Change log
#### 13/09/2019
- Added a check to ensure primersearch is executable prior to MIRUReader program execution
- Updated documentation to the README

#### 04/07/2019
- Update output format for option '--details'.

#### 14/06/2019
- Auto convert fastq to fasta.

## Usage example

For one sample analysis:
```
python /your/path/to/MIRUReader.py -r sample.fasta -p sampleID > miru.txt
```

For multiple samples analysis:
1. Create a mapping file (mappingFile.txt) that looks like:

    sample_001.fasta sample_001 \
    sample_002.fasta sample_002 \
    ...

2. Then run the program:
```
cat mappingFile.txt | while read -a line; do python /your/path/to/MIRUReader.py -r ${line[0]} -p ${line[1]}; done > miru.multiple.txt
```

## Output example

```
sample_prefix   0154    0424    0577    0580    0802    0960    1644    1955    2059    2163b   2165    2347    2401    2461    2531    2687    2996    3007    3171    3192    3690    4052    4156    4348
sample_001      2       4       4       2       3       3       3       2       2       5       4       4       4       2       5       1       6       3       3       5       3       7       2       3
```

Notes:
* The program is compatible to Python 2 and Python 3.
* Accepted reads file format includes '.fastq', '.fastq.gz', '.fasta', and '.fasta.gz'.
* The program output is a tab-delimited plain text which can be copied to or opened in Excel spreadsheet.

## Full usage

| Main options | Description |
| ------------ | ----------- |
| -r READS | Input reads file in fastq/fasta format, can be gzipped or not gzipped |
| -p PREFIX | Sample ID required for naming output file. |
| --table TABLE | Allele calling table, default is MIRU_table. Can be user-defined in fixed format. However, providing custom allele calling table for other VNTR is not tested. |
| --primers PRIMERS | Primers sequences, default is MIRU_primers. Can be user-defined in fixed format. |

| Optional options | Description |
| ---------------- | ----------- |
| --amplicons | Use output from primersearch ("prefix.18.primersearch.out") and summarize MIRU profile directly. |
| --details | This option is for further inspection. It displays details of repeat count for each loci with total mismatch error in the primer sequences alignment. |
| --nofasta | Delete fasta file generated if your input read is in fastq format. |

## FAQ
1. **Why are there two MIRU allele calling tables (MIRU_table and MIRU_table_0580)?**

MIRU loci 0580 (MIRU_table_0580) consist of a different numbering system for determination of repeat numbers as compared to the other 23 MIRU locus (MIRU_table) for MTBC isolates.

## Troubleshooting
1. If an error message `OSError: primersearch is not found.` appears, please ensure your `primersearch` executable file is in your environment path (`echo $PATH`) and can be called directly.

repository: karubiotools/MIRUReader

repo_name: karubiotools/MIRUReader


text:
---
title:  Roman to Integer
tags: [LeetCode]
---

[13.  Roman to Integer](https://leetcode.com/problems/roman-to-integer/)
#### Solution - Cleaner Solution
[Reference](https://leetcode.com/problems/roman-to-integer/discuss/6537/My-Straightforward-Python-Solution)
1. If one letter is less than its latter one, this letter is subtracted.

1. Always remember to add the last letter.
```python
def romanToInt(self, s):
    roman = {'M': 1000,'D': 500 ,'C': 100,'L': 50,'X': 10,'V': 5,'I': 1}
    z = 0
    for i in range(0, len(s) - 1):
        if roman[s[i]] < roman[s[i+1]]:
            z -= roman[s[i]]
        else:
            z += roman[s[i]]
    return z + roman[s[-1]]
```

path: /_posts/2020-10-11- Roman to Integer.md

filename: 2020-10-11- Roman to Integer.md


text:
- Feature Name: drain_modes
- Status: completed
- Start Date: 2016-04-25
- Authors: Tobias Schottdorf<EMAIL_ADDRESS>- RFC PR: #6283
- Cockroach Issue:

# Summary

Propose two reduced modes of operation of a running CockroachDB node.

* `drain-clients` mode: the server lets on-going SQL clients finish (up to some
  deadline) and then politely refuses new work at the gateway in the manner
  which popular load-balancing SQL clients can handle best.
* `drain-leases` mode: roughly speaking, all range leases expire and new
  ones are not granted (in turn disabling most queues and active gossipping).

These modes are not related to the existing `Stopper`-based functionality and
are not one-way (i.e. a server can temporarily run in `drain-clients` mode).
Typically, to avoid unavailability, a server under maintenance will move from
running to `drain-clients` to both.

# Motivation

In our Stopper usage, we've taken to fairly ruthlessly shutting down service of
many components once `(*Stopper).Quiesce()` is called. In code, this manifests
itself through copious use of the `(*Stopper).ShouldQuiesce()` channel even when
not running inside of a task (or running long-running operations inside tasks).

This was motivated mainly by endless amounts of test failures around leaked
goroutines or deadlocking operations and has served us reasonably well, keeping
our moving parts in check.

However, not that we're looking at clusters and their maintenance, this simple
"drop-all" approach isn't enough. See, for example #6198, #6197 or #5279. This
small RFC outlines proposed changes to accommodate use cases such as

* clean shutdown: instead of dropping everything on the floor, politely block
  new clients and finish open work, then expire all leases to avoid a period
  of unavailability, and only then initiate shutdown via `stopper.Stop()`.
* draining data off a node (i.e. have all or some subset of ranges migrate
  away, and wait until that has happened).
  Used for decommissioning, but could also be used to change hard-drives
  cleanly (i.e. drain data off a store, clean shutdown, switch hdd, start).
* decommission (permanently remove), which is "most of the above" with the
  addition of announcing the downtime as forever to the cluster.
* drain for update/migration (see the `{F,Unf}reeze` proposal in #6166):
  Essentially here we'll want to have the cluster in drain-clients mode and then
  propose a `Freeze` command on all Ranges.

# Detailed design

Implement the following:

```go
// Put the SQL server into drain-clients mode within deadline, cancelling
// connections as necessary. A zero deadline undoes the effects of any
// prior drain operation.
(*pgwire.Server).DrainClients(deadline time.Time) error

// Put the Node into drain-lease mode if requested, or undo any previous
// mode change.
(*server.Node).DrainLeases(bool) error
```

The implementations should be straightforward and are kept brief.

## SQL/drain-clients mode:

Essentially `ServeConn` in the presence of a deadline should politely refuse
new connections with an appropriate error code such as

> 08004  SQLSERVER REJECTED ESTABLISHMENT OF SQLCONNECTION
> sqlserver_rejected_establishment_of_sqlconnection")

(http://www.postgresql.org/docs/9.0/static/errcodes-appendix.html)

and a similar appropriate error for existing connections which try to issue
SQL commands after the deadline has expired.

We should try to close existing connections while they're in-between
transactions (i.e. after a command finishes but before we send serverMsgReady).
If a command comes in while the server is draining, we should execute it and
then close afterwards. If no command comes in then we can just close the
connection (which will race against the possibility that a client is sending a
command at that time, but there's not much we can do about that in the
postgresql protocol).

We should also consider this in the context of file descriptor limits (#6230):
if we're close to the limit we would like to be able to shed load by draining
idle connections.

If there is no good support for these error codes, possibly the right solution
is to unbind the listener. @bdarnell commented:

> We should do some research about how widely-supported these error codes are.
For example, pgbouncer doesn't seem to do anything with them. I'm concerned
that in practice the best way to load balance clients may turn out to be a
tcp-level tool like haproxy, in which case we may have to use cruder techniques
(e.g. closing the listening socket, which would also imply re-separating pgport
from the unified port).

This is considered outside of the scope of the RFC, but issue #6295 was filed.

## Node/drain-leases mode:

`(*server.Node).DrainLeases(bool)` iterates over its store list and delegates
to all contained stores. `(*Replica).redirectOnOrAcquireLease` checks
with its store before requesting a new or extending an existing lease.

## Server/adminServer:

```go

type DrainMode int
const (
  DrainClient DrainMode = 1 << iota
  DrainLeases
)

// For example, `s.Drain(DrainClient | DrainLeases)`
(*server.Server).Drain(mode DrainMode) error
```

and hook it up from `(*adminServer).handleQuit` (which currently has no way of
accessing `*Server`, only `*Node`, so a shortcut may be taken for the time
being if that seems opportune.

# Drawbacks

# Alternatives

We could augment `*Stopper`, but that seems more trouble than it's worth since
the required functionality does not generalize well.

# Unresolved questions

repository: andrianj/cockroach

repo_name: andrianj/cockroach


text:
# Q1 2020 D&A Level Up Competition

The ```download_data.py``` file is provided to access the data for the competition.

Usage:
1. Open Terminal, navigate to your desired directory, and clone this repo
2. Navigate to the ```q12020-dna-level-up``` folder
3. Install **gsutil** by running ```pip install gsutil``` or by using whichever installer you prefer
4. Run ```python download_data.py preview``` to download one of the data files and ensure the download works properly
5. Run ```python download_data.py full``` to download all of the competition data (~7.5GB)


text:
# Train and visualize a model in Tensorflow

## Overview

This TensorFlow tutorial focuses on practical aspects of implementing and
training deep learning models.  We will follow, step by step, the
implementation of linear and nonlinear models with Tensorflow, focusing on the
impact of tuning hyperparameters and architectures. To keep track of results we
will use the visualization tool Tensorboard and show its functionalities.

### Objective

The goal of this tutorial is for you to learn how to build models in
Tensorflow. You will apply them to a standard document classification dataset,
and keep track of the experiments' performance with Tensorboard, a
visualization tool.

### Who is this course aimed to?

We strongly recommend to have covered some machine learning basic concepts
previously, as we wont cover them during the tutorial:

- What is a classifier? What is a logistic regression classifier?
- Basic evaluation: metrics like accuracy, precision, and recall. What is the
  train and test split for?
- What is gradient descent and what is a cost function?

## Technical requirements

This tutorial is based in [Jupyter notebooks](http://jupyter.org/) we uploaded
to the [Github platform](https://github.com/PLN-FaMAF/tensorflowTutorial2017).
The notebook named as [**Part 0:
Configuration**](https://github.com/PLN-FaMAF/tensorflowTutorial2017/blob/master/tensorflow_tutorial_0.ipynb)
(which can be rendered directly from Github) has all the software and data
requirements needed to configure the environment. It should be followed before
taking the tutorial in the conference.

### Course slides

The slides shown in the tutorial presentation are available [using this
link](https://docs.google.com/presentation/d/1IoIN5gJPFbvDv_IaIaLFwd6Y9RTVNAxz_5DIhLFZ4bA/edit?usp=sharing).

### Software

The software packages we are using are Python 3.5 (obtained through conda)
along Numpy, Scipy, Jupyter, and the
[Tensorflow](https://www.tensorflow.org/versions/r1.3/install/) (version 1.3)
libraries.

Please refer to the
[notebook](https://github.com/PLN-FaMAF/tensorflowTutorial2017/blob/master/tensorflow_tutorial_0.ipynb)
for detailed explanation.

### Dataset

The dataset we will use is a pre-processed version of the [20 Newsgroup
Corpus](http://qwone.com/~jason/20Newsgroups/) for document classification.
[Part 1 of the
tutorial](https://github.com/PLN-FaMAF/tensorflowTutorial2017/blob/master/tensorflow_tutorial_1.ipynb)
is optional and explains how this dataset is obtained.  In any case it is
possible to download the dataset directly to use in Tensorflow from part 2 and
after of the tutorial.

Please refer to the
[notebook](https://github.com/PLN-FaMAF/tensorflowTutorial2017/blob/master/tensorflow_tutorial_0.ipynb)
for detailed explanation and download link.

## Structure

The Jupyter notebooks of the tutorial contain code and explanations that the
attendees can download, execute and modify during the talk. It will comprise
the following parts:

### Introduction and environment setup

This part is covered by the [Part 0:
Configuration](https://github.com/PLN-FaMAF/tensorflowTutorial2017/blob/master/tensorflow_tutorial_0.ipynb)
notebook. It has the instruction to configure the environment and download the
dataset to use.

### Dataset preprocessing (optional)

This part is covered by the [Part 1: Dataset
Preprocessing](https://github.com/PLN-FaMAF/tensorflowTutorial2017/blob/master/tensorflow_tutorial_1.ipynb)
notebook. It explains the dataset we are using to experiment with Tensorflow
and how we process it to have the final version ready.

### Basic concepts of Tensorflow

This part is covered by the [Part 2: The Basics of
Tensorflow](https://github.com/PLN-FaMAF/tensorflowTutorial2017/blob/master/tensorflow_tutorial_2.ipynb)
notebook. It explains the implementation of a linear model using a Tensorflow
estimator to exemplify the different components of the Tensorflow pipeline.
This includes compilation of models and how Tensorflow is executing your code.

### Advanced concepts of Tensorflow

This part is covered by the [Part 3: Advanced
Tensorflow](https://github.com/PLN-FaMAF/tensorflowTutorial2017/blob/master/tensorflow_tutorial_3.ipynb)
notebook. In this we will extend the linear model previously built into a
multilayer perceptron using a custom built estimator (instead of the default
provided by Tensorflow) using layers. We will cover the graph of Tensorflow and
how to visualize it with Tensorboard.

### The benefits of Tensorboard

This part is covered by the [Part 4: Inspecting the
model](https://github.com/PLN-FaMAF/tensorflowTutorial2017/blob/master/tensorflow_tutorial_4.ipynb)
notebook.  We will present the Tensorboard interface and how we can use it to
make the experimentation process easier by collecting and visualizing the
results.

### Tensorboard for embeddings (bonus)

This final part is covered by the [Part 5: Document
embeddings](https://github.com/PLN-FaMAF/tensorflowTutorial2017/blob/master/tensorflow_tutorial_5.ipynb)
notebook. It explains how to use Tensorboard to visualize embeddings of
different kinds (in this case documents).

---

## About the authors

### [Milagro Teruel](https://cs.famaf.unc.edu.ar/~mteruel/)

> I'm a Computer Scientist based in Córdoba, Argentina. I'm currently pursuing a
> PhD in Computing under the direction of Laura Alonso Alemany at Universidad
> Nacional de Córdoba and Marcelo Luis Errecalde, from the Universidad Nacional
> de San Luis.

### [Cristian Cardellino](http://crscardellino.me)

> I have a degree in Computer Sciences from Universidad Nacional de Córdoba,
> Argentina, and I am finishing my PhD. in the area of machine learning applied
> to natural language processing.


text:
---
templateKey: blog-post
title: Pico de gallo
date: 2019-09-26T02:53:14.586Z
thumbnail: https://raw.githubusercontent.com/sarahannnicholson/gatsby-starter-netlify-cms/master/static/img/pico_de_gallo.jpg
description: Wonderful fresh salsa
tags:
  - mexican
---

# Ingredients

* 5-6 on the vine tomatoes
* 1/2 - 1  cucumber (size depending)
* half medium yellow onion or 2 medium shallots
* 1/2 - 1 bunch of cilantro
* 1/4 cup pickle juice
* 1 jalapeno
* 3-5 cloves of garlic
* salt and pepper
* juice of 1 lime (taste dependent)

# Method

1. Cut all ingredients as small as you can. Combine. Voila! \
   Try not to use a food processor, it becomes overly mixed and not very chunky

gha_language: JavaScript