text:
---
layout: default
title: (Task 5) Materials
permalink: /pathtracer/materials
parent: "A3: Pathtracer"
has_children: false
has_toc: false
---

# (Task 5) Materials

## Walkthrough

<video width="750" height="500" controls>
    <source src="videos/Task6_Materials.mp4" type="video/mp4">
</video>

Now that you have implemented the ability to sample more complex light paths, it's time to add support for more types of materials. In this task you will add support for two types of specular materials: mirrors and glass. These materials are implemented in `student/bsdf.cpp`.

- In the diagrams below, both `out_dir` and `in_dir` are pointing _away_ from the intersection point. This is so that we can more consistently consider their angles with respect to the surface normal.
- Remember that we are tracing rays _backwards_, from the camera into the scene. This is why the computed scattering direction (`in_dir`) corresponds with the _incoming_ light.

First, take another at the BSDF interface in `rays/bsdf.h`. There are a number of key methods you should understand in `BSDF`:

- `Scatter scatter(Vec3 out_dir)`: given `out_dir`, generates a random sample for `in_dir`. It returns a `Scatter`, which contains both the sampled `direction` and the `attenuation` for the in/out pair.
- `Spectrum evaluate(Vec3 out_dir, Vec3 in_dir)`: evaluates the BSDF for a given pair of directions. This is only defined for continuous BSDFs.
- `float pdf(Vec3 out_dir, Vec3 in_dir)`: computes the PDF for sampling `in_dir` from the BSDF distribution, given `out_dir`. This is only defined for continuous BSDFs.
- `Spectrum emissive()`: returns emitted light. This is only defined for the diffuse light source BSDF.

To complete the mirror and glass materials, you will only need to implement their `scatter` functions, as they are both discrete BSDFs (i.e. they have a finite number of possible `in_dir`s for any `out_dir`). Additionally, you will want to complete two helper functions:

- `Vec3 reflect(Vec3 dir)`: returns a direction that is the **perfect specular reflection** of `dir` about `{0, 1, 0}`. More detail about specular reflection can be found [here](http://15462.courses.cs.cmu.edu/fall2015/lecture/reflection/slide_028).

- `Vec3 refract(Vec3 out_dir, float index_of_refraction, bool& was_internal)`: returns the ray that results from refracting `out_dir` through the surface according to [Snell's Law](http://15462.courses.cs.cmu.edu/fall2015/lecture/reflection/slide_032). Your implementation should assume that when `in_dir` **enters** the surface (that is, if `cos(theta_out) > 0`) then the ray was previously travelling in a vacuum (i.e. index of refraction = 1.0). If `cos(theta_out) < 0`, then `in_dir` is **leaving** the surface and entering a vacuum.

Finally, when working with Snell's law, there is a special case to account for: total internal reflection. This occurs when a ray hits a refractive boundary at an angle greater than the _critical angle_. The critical angle is the incident \theta_i that causes the refracted \theta_t to be >= 90 degrees, hence can produce no real solution to Snell's Law. In this case, you should set `was_internal` to `true`.

---

## Step 1: `BSDF_Mirror`

Implement `reflect` and `BSDF_Mirror::scatter()`.

Because discrete BSDFs do not require Monte Carlo integration (we can simply analytically evaluate each possible direction), we do not implement `BSDF::pdf`. Perhaps more interestingly, we also do not require `BSDF::evaluate`. This is because evaluating the BSDF is only necessary when sampling directions from distributions other than the BSDF itself. When the BSDF is discrete, like a perfect mirror, we can assume other distributions never sample the single (infinitesimal) direction at which the BSDF is non-zero.

Therefore, we must update our path tracing procedure in `Pathtracer::sample_(in)direct_lighting`: when the BSDF is discrete (`BSDF::is_discrete`), we are not doing a Monte Carlo estimate, hence should not use `BSDF::pdf`. Instead, simply multiply the scattering attenuation and the incoming light. Note that failing to make this check will cause the invalid BSDF calls to abort.

## Step 2: `BSDF_Glass`

Implement `refract` and `BSDF_Glass::scatter()`.

Glass is a material that can both reflect and transmit light. As discussed in class, the fraction of light that is reflected vs. transmitted is governed by the dielectric (non-conductive) Fresnel equations. To simulate this, we may sample `in_dir` from either reflection or refraction with probability proportional to the Fresnel reflectance. For example, if the Fresnel reflectance is 0.9, then you should generate a reflected ray 90% of the time. Note that instead of computing the full Fresnel equations, you have the option to use [Schlick's approximation](https://en.wikipedia.org/wiki/Schlick's_approximation) instead.

In the description below,  and  refer to the index of refraction of the medium containing the incoming ray and the angle of that ray with respect to the boundary surface normal.  and  refer to the index of refraction of the new medium and the angle to the boundary normal of the transmitted ray.

The Fresnel equations state that reflection from a surface is a function of the surface's index of refraction and the polarity of the incoming light. Since our renderer doesn't account for polarity, we'll apply a common approximation of averaging the reflectance of light polarized in perpendicular and parallel directions:

The parallel and perpendicular terms are given by:

Therefore, for a dielectric material, the fraction of reflected light will be given by , and the amount of transmitted light will be given by .

Alternatively, you may compute  using [Schlick's approximation](https://en.wikipedia.org/wiki/Schlick%27s_approximation).

### Distribution Function for Transmitted Light

Although we described the BRDF for perfect specular reflection in class, we did not discuss the distribution function for transmitted light. Unlike reflection, refraction "spreads" or "condenses" a differential beam of light. Hence, a refraction event should change the radiance along a ray.

After using Snell's Law to find the direction of refracted rays, compute the BSDF attenuation using the distribution function found in Pharr, Jakob, and and Humphries's book [Physically Based Rendering](http://www.pbr-book.org/3ed-2018/Reflection_Models/Specular_Reflection_and_Transmission.html). It also includes a derivation based Snell's Law and the relation . Of course, you are more than welcome to attempt a derivation on your own!

---

## Tips

- Check your sphere intersection code, as you may have bugs there that were not exposed by rendering Lambertian spheres in Task 4.
- Check the behavior of your refract function when `index_of_refraction = 1.f`. This should not change the transmitted direction, hence make the glass sphere transparent.
- Test reflection and refraction separately, i.e. ignore the Fresnel coefficient and only refract or reflect. Once you've verified that those are correct, then go ahead and reintroduce the Fresnel coefficient and split rays between reflection  and refraction.

---

## Reference Results

When you are done, you will be able to render images with specular materials, like the Cornell Box with a metal and glass sphere (`cbox.dae`, 1024 samples, max depth 8):

---

## Extra Credit
- Add a more advanced parameterized BSDF, such as Blinn-Phong, GGX, or Disney. More information about evaluating and sampling each of these distributions can be found in [Physically Based Rendering](http://www.pbr-book.org/3ed-2018/) chapters 8 & 9.
- Add textures (either procedural or mapped) defining spatially varying BSDF attributes within an object. Refer to [Physically Based Rendering](http://www.pbr-book.org/3ed-2018/) chapter 10.


text:
+++
title = "4. Lifecycle"
weight = 20
template = "doc.html"
+++

In the last lesson we looked at a couple of useful things used as boilerplate in
most agents. Now we're going to get into the guts of how agents work, and start
looking at what the agent arms do. The first thing we'll look at is the agent's
state, and the three arms for managing it: `on-init`, `on-save`, and `on-load`.
These arms handle what we call an agent's "lifecycle".

## Lifecycle

An agent's lifecycle starts when it's first installed. At this point, the
agent's `on-init` arm is called. This is the _only_ time `on-init` is ever
called - its purpose is just to initialize the agent. The `on-init` arm might be
very simple and just set an initial value for the state, or even do nothing at
all and return the agent core exactly as-is. It may also be more complicated,
and perform some [scries](/docs/arvo/concepts/scry) to obtain extra data or
check that another agent is also installed. It might send off some `card`s to
other agents or vanes to do things like load data in to the `%settings-store`
agent, bind an Eyre endpoint, or anything else. It all depends on the needs of
your particular application. If `on-init` fails for whatever reason, the agent
installation will fail and be aborted.

Once initialized, an agent will just go on doing its thing - processing events,
updating its state, producing effects, etc. At some point, you'll likely want to
push an update for your agent. Maybe it's a bug fix, maybe you want to add extra
features. Whatever the reason, you need to change the source code of your agent,
so you commit a modified version of the file to Clay. When the commit completes, Gall updates the app as follows:

- The agent's `on-save` arm is called, which packs the agent's state in a `vase`
  and exports it.
- The new version of the agent is built and loaded into Gall.
- The previously exported `vase` is passed to the `on-load` arm of the newly
  built agent. The `on-load` arm will process it, convert it to the new version
  of the state if necessary, and load it back into the state of the agent.

A `vase` is just a cell of `[type-of-the-noun the-noun]`. Most data an agent
sends or receives will be encapsulated in a vase. A vase is made with the
[zapgar](/docs/hoon/reference/rune/zap#-zapgar) (`!>`) rune like
`!>(some-data)`, and unpacked with the
[zapgal](/docs/hoon/reference/rune/zap#-zapgal) (`!<`) rune like
`!<(type-to-extract vase)`. Have a read through the [`vase` section of the type
reference for details](/docs/userspace/gall-guide/types#vase).

We'll look at the three arms described here in a little more detail, but first
we need to touch on the state itself.

## Versioned state type

In the previous lesson we introduced the idea of composing additional cores into
the subject of the agent core. Here we'll look at using such a core to define
the type of the agent's state. In principle, we could make it as simple as this:

```hoon
|%
+$  my-state-type  @ud
--
```

However, when you update your agent as described in the [Lifecycle](#lifecycle)
section, you may want to change the type of the state itself. This means
`on-load` might find different versions of the state in the `vase` it receives,
and it might not be able to distinguish between them.

For example, if you were creating an agent for a To-Do task management app, your
tasks might initially have a `?(%todo %done)` union to specify whether they're
complete or not. Something like:

```hoon
(map task=@t status=?(%todo %done))
```

At some point, you might want to add a third status to represent "in progress",
which might involve changing `status` like:

```hoon
(map title=@t status=?(%todo %done %work))
```

The conventional way to keep this managable and reliably differentiate possible
state types is to have _versioned states_. The first version of the state would
typically be called `state-0`, and its head would be tagged with `%0`. Then,
when you change the state's type in an update, you'd add a new structure called
`state-1` and tag its head with `%1`. The next would then be `state-2`, and so
on.

In addition to each of those individual state versions, you'd also define a
structure called `versioned-state`, which just contains a union of all the
possible states. This way, the vase `on-load` receives can be unpacked to a
`versioned-state` type, and then a
[wuthep](/docs/hoon/reference/rune/wut#--wuthep) (`?-`) expression can switch on
the head (`%0`, `%1`, `%2`, etc) and process each one appropriately.

For example, your state definition core might initially look like:

```hoon
|%
+$  versioned-state
  $%  state-0
  ==
+$  state-0  [%0 tasks=(map title=@t status=?(%todo %done))]
--
```

When you later update your agent with a new state version, you'd change it to:

```hoon
|%
+$  versioned-state
  $%  state-0
      state-1
  ==
+$  state-0  [%0 tasks=(map title=@t status=?(%todo %done))]
+$  state-1  [%1 tasks=(map title=@t status=?(%todo %done %work))]
--
```

Another reason for versioning the state type is that there may be cases where
the state type doesn't change, but you still want to apply special transition
logic for an old state during upgrade. For example, you may need to reprocess
the data for a new feature or to fix a bug.

## Adding the state

Along with a core defining the type of the state, we also need to actually add
it to the subject of the core. The conventional way to do this is by adding the following immediately before the agent core itself:

```hoon
=|  state-0
=*  state  -
```

The first line bunts (produces the default value) of the state type we defined
in the previous core, and adds it to the head of the subject _without a face_.
The next line uses [tistar](/docs/hoon/reference/rune/tis#-tistar) to give it
the name of `state`. You might wonder why we don't just give it a face when we
bunt it and skip the tistar part. If we did that, we'd have to refer to `tasks`
as `tasks.state`. With tistar, we can just reference `tasks` while also being
able to reference the whole `state` when necessary.

Note that adding the state like this only happens when the agent is built - from
then on the arms of our agent will just modify it.

## State management arms

We've described the basic lifecycle process and the purpose of each state
management arm. Now let's look at each arm in detail:

### `on-init`

This arm takes no argument, and produces a `(quip card _this)`. It's called
exactly once, when the agent is first installed. Its purpose is to initialize
the agent.

`(quip a b)` is equivalent to `[(list a) b]`, see the [types
reference](/docs/userspace/gall-guide/types#quip) for details.

A `card` is a message to another agent or vane. We'll discuss `card`s in detail
later.

`this` is our agent core, which we give the `this` alias in the virtual arm
described in the previous lesson. The underscore at the beginning is the
irregular syntax for the [buccab](/docs/hoon/reference/rune/buc#_-buccab) (`$_`)
rune. Buccab is like an inverted bunt - instead of producing the default value
of a type, instead it produces the type of some value. So `_this` means "the
type of `this`" - the type of our agent core.

Recall that in the last lesson, we said that most arms return a cell of
`[effects new-agent-core]`. That's exactly what `(quip card _this)` is.

### `on-save`

This arm takes no argument, and produces a `vase`. Its purpose is to export the
state of an agent - the state is packed into the vase it produces. The main time
it's called is when an agent is upgraded. When that happens, the agent's state
is exported with `on-save`, the new version of the agent is compiled and loaded,
and then the state is imported back into the new version of the agent via the
[`on-load`](#on-load) arm.

As well as the agent upgrade process, `on-save` is also used when an agent is
suspended or an app is uninstalled, so that the state can be restored when it's
resumed or reinstalled.

The state is packed in a vase with the
[zapgar](/docs/hoon/reference/rune/zap#-zapgar) (`!>`) rune, like `!>(state)`.

### `on-load`

This arm takes a `vase` and produces a `(quip card _this)`. Its purpose is to
import a state previously exported with [`on-save`](#on-save). Typically
you'd have used a [versioned state](#versioned-state-type) as described above,
so this arm would test which state version the imported data has, convert data
from an old version to the new version if necessary, and load it into the
`state` wing of the subject.

The vase would be unpacked with a
[zapgal](/docs/hoon/reference/rune/zap#-zapgal) (`!<`) rune, and then typically
you'd test its version with a [wuthep](/docs/hoon/reference/rune/wut#--wuthep)
(`?-`) expression.

## Example

Here's a new agent to demonstrate the concepts we've discussed here:

```hoon
/+  default-agent, dbug
|%
+$  versioned-state
  $%  state-0
  ==
+$  state-0  [%0 val=@ud]
+$  card  card:agent:gall
--
%-  agent:dbug
=|  state-0
=*  state  -
^-  agent:gall
|_  =bowl:gall
+*  this  .
    def   ~(. (default-agent this %.n) bowl)
::
++  on-init
  ^-  (quip card _this)
  `this(val 42)
::
++  on-save
  ^-  vase
  !>(state)
::
++  on-load
  |=  old-state=vase
  ^-  (quip card _this)
  =/  old  !<(versioned-state old-state)
  ?-  -.old
    %0  `this(state old)
  ==
::
++  on-poke   on-poke:def
++  on-watch  on-watch:def
++  on-leave  on-leave:def
++  on-peek   on-peek:def
++  on-agent  on-agent:def
++  on-arvo   on-arvo:def
++  on-fail   on-fail:def
--
```

Let's break it down and have a look at the new parts we've added. First, the
state core:

```hoon
|%
+$  versioned-state
  $%  state-0
  ==
+$  state-0  [%0 val=@ud]
+$  card  card:agent:gall
--
```

In `state-0` we've defined the structure of our state, which is just a `@ud`.
We've tagged the head with a `%0` constant representing the version number, so
`on-load` can easily test the state version. In `versioned-state` we've created
a union and just added our `state-0` type. We've added an extra `card` arm as
well, just so we can use `card` as a type, rather than the unweildy
`card:agent:gall`.

After that core, we have the usual `agent:dbug` call, and then we have this:

```hoon
=|  state-0
=*  state  -
```

We've just bunted the `state-0` type, which will produce `[%0 val=0]`, pinning
it to the head of the subject. Then, we've use
[tistar](/docs/hoon/reference/rune/tis#-tistar) (`=*`) to give it a name of
`state`.

Inside our agent core, we have `on-init`:

```hoon
++  on-init
  ^-  (quip card _this)
  `this(val 42)
```

The `a(b c)` syntax is the irregular form of the
[centis](/docs/hoon/reference/rune/cen#-centis) (`%=`) rune. You'll likely be
familiar with this from recursive functions, where you'll typically call the buc
arm of a trap like `$(a b, c d, ...)`. It's the same concept here - we're saying
`this` (our agent core) with `val` replaced by `42`. Since `on-init` is only
called when the agent is first installed, we're just initializing the state.

Next we have `on-save`:

```hoon
++  on-save
  ^-  vase
  !>(state)
```

This exports our agent's state, and is called during upgrades, suspensions, etc.
We're having it pack the `state` value in a `vase`.

Finally, we have `on-load`:

```hoon
++  on-load
  |=  old-state=vase
  ^-  (quip card _this)
  =/  old  !<(versioned-state old-state)
  ?-  -.old
    %0  `this(state old)
  ==
```

It takes in the old state in a `vase`, then unpacks it to the `versioned-state`
type we defined earlier. We test its head for the version, and load it back into
the state of our agent if it matches. This test is a bit redundant at this stage
since we only have one state version, but you'll soon see the purpose of it.

You can save it as `/app/lifecycle.hoon` in the `%base` desk and `|commit %base`. Then, run `|rein %base [& %lifecycle]` to start it.

Let's try inspecting our state with `dbug`:

```
>   [%0 val=42]
> :lifecycle +dbug
>=
```

`dbug` can also dig into the state with the `%state` argument, printing the value of the specified face:

```
>   42
> :lifecycle +dbug [%state %val]
>=
```

Next, we're going to modify our agent and change the structure of the state so
we can test out the upgrade process. Here's a modified version, which you can
again save in `/app/lifecycle.hoon` and `|commit %base`:

```hoon
/+  default-agent, dbug
|%
+$  versioned-state
  $%  state-0
      state-1
  ==
+$  state-0  [%0 val=@ud]
+$  state-1  [%1 val=[@ud @ud]]
+$  card  card:agent:gall
--
%-  agent:dbug
=|  state-1
=*  state  -
^-  agent:gall
|_  =bowl:gall
+*  this  .
    def   ~(. (default-agent this %.n) bowl)
::
++  on-init
  ^-  (quip card _this)
  `this(val [27 32])
::
++  on-save
  ^-  vase
  !>(state)
::
++  on-load
  |=  old-state=vase
  ^-  (quip card _this)
  =/  old  !<(versioned-state old-state)
  ?-  -.old
    %1  `this(state old)
    %0  `this(state 1+[val.old val.old])
  ==
::
++  on-poke   on-poke:def
++  on-watch  on-watch:def
++  on-leave  on-leave:def
++  on-peek   on-peek:def
++  on-agent  on-agent:def
++  on-arvo   on-arvo:def
++  on-fail   on-fail:def
--
```

As soon as you `|commit` it, Gall will immediately export the existing state
with `on-save`, build the new version of the agent, then import the state back
in with `on-load`.

In the state definition core, you'll see we've added a new state version with a different structure:

```hoon
+$  versioned-state
  $%  state-0
      state-1
  ==
+$  state-0  [%0 val=@ud]
+$  state-1  [%1 val=[@ud @ud]]
+$  card  card:agent:gall
--
```

We've also changed the part that adds the state, so it uses the new version instead:

```hoon
=|  state-1
=*  state  -
```

In `on-init`, we've updated it to initialize the state with a value that fits the new type we've defined:

```hoon
++  on-init
  ^-  (quip card _this)
  `this(val [27 32])
```

`on-init` won't be called in this case, but if someone were to directly install
this new version of the agent, it would be, so we still need to update it.

`on-save` has been left unchanged, but `on-load` has been updated like so:

```hoon
++  on-load
  |=  old-state=vase
  ^-  (quip card _this)
  =/  old  !<(versioned-state old-state)
  ?-  -.old
    %1  `this(state old)
    %0  `this(state 1+[val.old val.old])
  ==
```

We've updated the `?-` expression with a new case that handles our new state
type, and for the old state type we've added a function that converts it to the
new type - in this case by duplicating `val` and changing the head-tag from `%0`
to `%1`. This is an extremely simple state type transition function - it would
likely be more complicated for an agent with real functionality.

Note: the `a+b` syntax (as in `1+[val.old val.old]`) forms a cell of the
constant `%a` and the noun `b`. The constant may either be an integer or a `@tas`.
For example:

```
> foo+'bar'
[%foo 'bar']

> 42+'bar'
[%42 'bar']
```

Let's now use `dbug` to confirm our state has successfully been updated to the new
type:

```
>   [%1 val=[42 42]]
> :lifecycle +dbug
>=
```

## Summary

- The app lifecycle rougly consists of initialization, state export, upgrade,
  state import and state version transition.
- This is managed by three arms: `on-init`, `on-save` and `on-load`.
- `on-init` initializes the agent and is called when it's first installed.
- `on-save` exports the agent's state and is called during upgrade or
  when an app is suspended.
- `on-load` imports an agent's state and is called during upgrade or
  when an app is unsuspended. It also handles converting data from old
  state versions to new state versions.
- The type of an agent's state is typically defined in a separate core.
- The state type is typically versioned, with a new type definition for each
  version of the state.
- The state is initially added by bunting the state type and then naming it
  `state` with the tistar (`=*`) rune, so its contents can be referenced
  directly.
- A `vase` is a cell of `[type-of-the-noun the-noun]`.
- `(quip a b)` is the same as `[(list a) b]`, and is the `[effects new-agent-core]` pair returned by many arms of an agent core.

## Exercises

- Run through the [example](#example) yourself on a fake ship if you've not done
  so already.
- Have a look at the [`vase` entry in the type
  reference](/docs/userspace/gall-guide/types#vase).
- Have a look at the [`quip` entry in the type
  reference](/docs/userspace/gall-guide/types#quip).
- Try modifying the second version of the agent in the [example](#example)
  section, adding a third state version. Include functions in the wuthep
  expression in `on-load` to convert old versions to your new state type.

license: MIT

branch_name: refs/heads/master

extension: md

license_type: permissive


text:
# d3-force-3d

[![NPM](https://nodei.co/npm/d3-force-3d.png?compact=true)](https://nodei.co/npm/d3-force-3d/)

Extended version of [d3-force](https://github.com/d3/d3-force) to support other dimensions besides 2D, via the method [*numDimensions*](#simulation_numDimensions), supporting the values 1, 2 or 3 (default to 2). Fully backwards compatible with [d3-force](https://github.com/d3/d3-force) (version [1.1.0](https://github.com/d3/d3-force/tree/v1.1.0)), and should just work as a drop-in replacement d3 module.

This module implements a [velocity Verlet](https://en.wikipedia.org/wiki/Verlet_integration) numerical integrator for simulating physical forces on particles. The simulation is simplified: it assumes a constant unit time step Δ*t* = 1 for each step, and a constant unit mass *m* = 1 for all particles. As a result, a force *F* acting on a particle is equivalent to a constant acceleration *a* over the time interval Δ*t*, and can be simulated simply by adding to the particle’s velocity, which is then added to the particle’s position.

In the domain of information visualization, physical simulations are useful for studying [networks](http://bl.ocks.org/mbostock/ad70335eeef6d167bc36fd3c04378048) and [hierarchies](http://bl.ocks.org/mbostock/95aa92e2f4e8345aaa55a4a94d41ce37)!

[](http://bl.ocks.org/mbostock/ad70335eeef6d167bc36fd3c04378048)[](http://bl.ocks.org/mbostock/95aa92e2f4e8345aaa55a4a94d41ce37)

You can also simulate circles (disks) with collision, such as for [bubble charts](http://www.nytimes.com/interactive/2012/09/06/us/politics/convention-word-counts.html) or [beeswarm plots](http://bl.ocks.org/mbostock/6526445e2b44303eebf21da3b6627320):

[](http://bl.ocks.org/mbostock/31ce330646fa8bcb7289ff3b97aab3f5)[](http://bl.ocks.org/mbostock/6526445e2b44303eebf21da3b6627320)

You can even use it as a rudimentary physics engine, say to simulate cloth:

[](http://bl.ocks.org/mbostock/1b64ec067fcfc51e7471d944f51f1611)

With this module update, you can also run the simulation in one, two or three dimensions:

[](https://bl.ocks.org/vasturiano/f59675656258d3f490e9faa40828c0e7)

To use this module, create a [simulation](#simulation) for an array of [nodes](#simulation_nodes), and compose the desired [forces](#simulation_force). Then [listen](#simulation_on) for tick events to render the nodes as they update in your preferred graphics system, such as Canvas, SVG or WebGL.

## Web Examples

This fork contains a small static web server example, demonstrating visualization of a few different data sets. See [Examples.md]() document for run instructions.

### Example code

The example demonstrates how you can write a simple web app that leverages this library.

- `/web/3d` 3D examples
- `/web/vr` VR examples
- `/web/data` the datasets used for visualizations
- `/web/lib` the `d3-force-3d` lib to be used

Enjoy :)


text:
# better_profanity
*Blazingly fast cleaning swear words (and their leetspeak) in strings*

[![release](https://img.shields.io/badge/dynamic/json.svg?label=release&url=https%3A%2F%2Fpypi.org%2Fpypi%2Fbetter-profanity%2Fjson&query=%24.info.version&colorB=blue)](https://github.com/snguyenthanh/better_profanity/releases/latest)
[![Build Status](https://travis-ci.com/snguyenthanh/better_profanity.svg?branch=master)](https://travis-ci.com/snguyenthanh/better_profanity)
![python](https://img.shields.io/badge/python-3-blue.svg)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=popout)](https://github.com/snguyenthanh/better_profanity/blob/master/LICENSE)

Inspired from package [profanity](https://github.com/ben174/profanity) of [Ben Friedland](https://github.com/ben174), this library is significantly faster than the original one, by using string comparison instead of regex.

It supports [modified spellings](https://en.wikipedia.org/wiki/Leet) (such as `p0rn`, `h4NDjob`, `handj0b` and `b*tCh`).

## Requirements
This package only works with `Python 3`.

## Installation
```
$ pip install better_profanity
```

## Unicode characters

Only Unicode characters from categories `Ll`, `Lu`, `Mc` and `Mn` are added. More on Unicode categories can be found [here][unicode category link].

[unicode category link]: https://en.wikipedia.org/wiki/Template:General_Category_(Unicode)

Not all languages are supported yet, such as *Chinese*.

## Wordlist
Most of the words in the default [wordlist](./better_profanity/profanity_wordlist.txt) are referred from [Full List of Bad Words and Top Swear Words Banned by Google](https://github.com/RobertJGabriel/Google-profanity-words).

The wordlist contains a total of __106,992 words__, including 317 words from the default [profanity_wordlist.txt](./better_profanity/profanity_wordlist.txt) and their variants by modified spellings.

Its total size in memory is 10.49+MB.

## Usage
It is highly recommended to call `profanity.load_censor_words()` at initialization, to reduce the runtime for the first `profanity.censor()` call.

```
from better_profanity import profanity

if __name__ == "__main__":
    profanity.load_censor_words()

    text = "You p1ec3 of sHit."
    censored_text = profanity.censor(text)
    print(censored_text)
    # You **** of ****.
```

All modified spellings of words in [profanity_wordlist.txt](./better_profanity/profanity_wordlist.txt) will be generated. For example, the word `handjob` would be loaded into:

```
'handjob', 'handj*b', 'handj0b', 'handj@b', 'h@ndjob', 'h@ndj*b', 'h@ndj0b', 'h@ndj@b',
'h*ndjob', 'h*ndj*b', 'h*ndj0b', 'h*ndj@b', 'h4ndjob', 'h4ndj*b', 'h4ndj0b', 'h4ndj@b'
```

The full mapping of the library can be found in [profanity.py](./better_profanity/profanity.py#L9-L18).

### 1. Censor swear words from a text
By default, `profanity` replaces each swear words with 4 asterisks `****`.

```
from better_profanity import profanity

if __name__ == "__main__":
    text = "You p1ec3 of sHit."

    censored_text = profanity.censor(text)
    print(censored_text)
    # You **** of ****.
```

### 2. Censor doesn't care about word dividers
The function `.censor()` also hide words separated not just by an empty space ` ` but also other dividers, such as `_`, `,` and `.`. Except for `@, $, *, ", '`.

```
from better_profanity import profanity

if __name__ == "__main__":
    text = "...sh1t...hello_cat_fuck,,,,123"

    censored_text = profanity.censor(text)
    print(censored_text)
    # "...****...hello_cat_****,,,,123"
```

### 3. Censor swear words with custom character
4 instances of the character in second parameter in `.censor()` will be used to replace the swear words.

```
from better_profanity import profanity

if __name__ == "__main__":
    text = "You p1ec3 of sHit."

    censored_text = profanity.censor(text, '-')
    print(censored_text)
    # You ---- of ----.
```

### 4. Check if the string contains any swear words
Function `.contains_profanity()` return `True` if any words in the given string has a word existing in the wordlist.

```
from better_profanity import profanity

if __name__ == "__main__":
    dirty_text = "That l3sbi4n did a very good H4ndjob."

    profanity.contains_profanity(dirty_text)
    # True
```

### 5. Censor swear words with a custom wordlist
Function `.load_censor_words()` takes a `List` of strings as censored words.
The provided list will replace the default wordlist.

```
from better_profanity import profanity

if __name__ == "__main__":
    custom_badwords = ['happy', 'jolly', 'merry']
    profanity.load_censor_words(custom_badwords)

    print(profanity.contains_profanity("Fuck you!"))
      Use both default and your custom wordlist
```
from better_profanity import profanity

if __name__ == "__main__":
    custom_badwords = ['happy', 'jolly', 'merry']
    profanity.add_censor_words(custom_badwords)

    print(profanity.contains_profanity("Happy you, fuck!"))
    # **** you, ****!
```

### 7. Censor Unicode characters
No extra steps needed!

```
from better_profanity import profanity

if __name__ == "__main__":
    bad_text = "Эффекти́вного противоя́дия от я́да фу́гу не существу́ет до сих пор"
    profanity.load_censor_words(["противоя́дия"])

    censored_text = profanity.censor(text)
    print(censored_text)
    # Эффекти́вного **** от я́да фу́гу не существу́ет до сих пор
```

## Limitations

1. As the library compares each word by characters, the censor could easily be bypassed by adding any character(s) to the word:

```
profanity.censor('I just have sexx')
# returns 'I just have sexx'

profanity.censor('jerkk off')
# returns 'jerkk off'
```

2. Any word in [wordlist](https://github.com/snguyenthanh/better_profanity/blob/master/better_profanity/profanity_wordlist.txt) that have non-space separators cannot be recognised, such as `s & m`, and therefore, it won't be filtered out. This problem was raised in [#5](https://github.com/snguyenthanh/better_profanity/issues/5).

## Testing
```
$ python tests.py
```

## Versions

- [v0.5.0](https://github.com/snguyenthanh/better_profanity/releases/tag/0.5.0) - Add the capability to add to the word list rather than replace it. #8
- [v0.4.0](https://github.com/snguyenthanh/better_profanity/releases/tag/0.4.0) - Add compatibility to all versions of Python 3.
- [v0.3.4](https://github.com/snguyenthanh/better_profanity/releases/tag/0.3.4) - Add significantly more swear words.
- [v0.3.3](https://github.com/snguyenthanh/better_profanity/releases/tag/0.3.3) - Fix incompatibility with Python 3.5.
- [v0.3.2](https://github.com/snguyenthanh/better_profanity/releases/tag/0.3.2) - Fix a typo in documentation.
- [v0.3.1](https://github.com/snguyenthanh/better_profanity/releases/tag/0.3.1) - Remove unused dependencies.
- [v0.3.0](https://github.com/snguyenthanh/better_profanity/releases/tag/0.3.0) - Add support for Unicode characters (Categories: Ll, Lu, Mc and Mn) [#2](https://github.com/snguyenthanh/better_profanity/pull/2).
- [v0.2.0](https://github.com/snguyenthanh/better_profanity/releases/tag/0.2) - Bug fix + faster censoring
- [v0.1.0](https://github.com/snguyenthanh/better_profanity/releases/tag/v0.1) - Initial release

## Contributing
Please read [CONTRIBUTING.md](./CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.

## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

## Special thanks to
- [Andrew Grinevich](https://github.com/Derfirm) - Add support for Unicode characters.

## Acknowledgments
- [Ben Friedland](https://github.com/ben174) - For the inspiring package [profanity](https://github.com/ben174/profanity).


text:
---
path: "/recipes/sourdough-bagels"
date: "2019-12-23"
title: "sourdough bagels"
time: "1 hour (overnight resting)"
ingredients: [
  "2 cups sourdough starter",
  "4 cups 00 flour",
  "1/2 tablespoon salt",
  "3 tablespoons honey (or barley malt syrup/maple syrup)",
  "1 cup warm water",
  "1 egg (for wash)",
  "Other toppings if desired - minced garlic, onion flakes, sesame seeds, poppy seeds",
]
method: [
  "Put all ingredients (excluding egg and other toppings) in food procressor with blade and process on high for 90 seconds.",
  "Turn dough out onto a floured surface and knead until together.",
  "Place in a glass bowl covered with a wet tea-towel and refrigerate overnight.",
  "Roll dough into a log and slice into 12 even segments. Using the palm of your hand roll each segment into a ball.",
  "Poke a hole through the middle - I use a plastic chop stick - and stretch into a doughnut shape using a finger.",
  "Boil water in a large saucepan and add 1 tablespoon of honey (or barley malt or maple syrup).",
  "Boil four bagels at a time for 30 seconds each side.",
  "Brush each bagel with egg wash and add desired toppings.",
  "Preheat oven to 200°C and bake for 20-25 mins.",
]
---

repository: dijonmusters/recipe-book

gha_language: JavaScript

gha_license_id: MIT

repo_name: dijonmusters/recipe-book


text:
# vip-js-sdk
Official JavaScript library for the WordPress.com VIP REST API

## Building

To compile the source code into a distributable bundle, simply run:

```
make build
```

This uses [Gulp](http://gulpjs.com/) and [Browserify](http://browserify.org/) to produce a JS file that includes all dependencies.

## Testing

Tests can be run with:

```
make test
```

## License

MIT – Copyright 2017 Automattic

repository: Automattic/vip-js-sdk

repo_name: Automattic/vip-js-sdk


text:
# Example websocket webapp
- Built for simple showcase
- Used [NG6-starter](https://github.com/gdi2290/NG6-starter) for boilerplate

# Notes
- This was my first experience with Angular 1.x.
- Learning and completion of app was done in 5 hours.
- No custom directives or services used.
- Tests have been updated from boilplates tests to include minimal cases created.
- Styling was all pure css, no framework used.

#### Assumptions
- User did not need to clear echo.
- User needed no other functionality other than echo.

#### Potential improvements
- Better/more test coverage.
- Include more possibilities for user interaction

repository: cavaloni/websocket-example

repo_name: cavaloni/websocket-example


text:
---
layout: post
title:  "PDE Methods in Control"
date: 2017-01-27
categories: past_event
tags: control
---

The week of 23-26 January I followed an outstanding course *Partial Differential Equation Methods in Control*, given by Prof. [Eduardo Cerpa](http://ecerpa.mat.utfsm.cl/), from the Mathematics Department of Universidad Técnica
Federico Santa María (Valparaíso, Chile). Sessions took place at [GIPSA](http://www.gipsa-lab.grenoble-inp.fr/le-laboratoire/presentation.php)-lab.

Below you will find some extra information.

> **Content:**
In this course we study controllability and stabilization methods for
infinite-dimensional systems described by partial differential equations
(PDEs). Classical PDEs as the transport equation, the heat equation, and
the wave equation are considered in detail. Moreover, other models as
the Korteweg-de Vries equation and the Kuramoto-Sivashinsky equation are
studied from a control viewpoint.

```
Schedule:

Monday 23
08:30-10:00
10:15-11:45

Tuesday 24
08:30-10:00
10h15:11h45

Wednesday 25
08:30-10:00
10:15-11h45
and
13:30-15:00
15:15-16:45

Thursday 26
08:30-10:00
10:15-11:45
```

I look forward to LaTeXing my handwritten notes! See the [advances in this SageMathCloud public link](https://cloud.sagemath.com/projects/b036e679-d20f-420a-8085-43cf6d6d95d2/files/main.pdf).

gha_language: TeX

gha_license_id: NOASSERTION


text:
---
date: 2018-11-25
title: Skipping Content
categories:
  - wanikani
description:
type: Document
---

**There is no way to speed up or skip content on WaniKani.**

Not even if you email us and promise you know 10,000+ kanji so you don't need to start at level 1.

There are a few reasons for this, though they may not be satisfactory to a master of kanji, such as yourself.

The WaniKani system is built upon mnemonics that use a lot of made up radicals that you almost definitely haven't learned. This information is used all throughout WaniKani's sixty levels. To use WaniKani effectively, you need to learn these, which means starting at the beginning.

Another issue comes from how difficult it would be to create a testing/skipping protocol that's good. We could make a so-so one, but in general we err on the side of "making sure you truly know things before moving on."

 That's your next step and you'll do just fine without WaniKani! Especially if you know 10,000 kanji, like geez, who are you?

If you know _some_ kanji (say, 100-200), then the first five levels or so should catch you up. That's about a month of time. In the grand scheme of learning the kanji, that's a drop in the bucket. Plus, we teach vocabulary too. Most likely, you'll be learning new information despite having a few hundred kanji under your belt. The first three levels are free, so worst case scenario is that you'll get to review and reinforce your kanji knowledge without having to pay a cent.

Not sure how to level up? Read all about it [here](/wanikani/getting-started/level-up/).

repository: rhettc/wanikani-knowledgebase

gha_language: HTML

repo_name: rhettc/wanikani-knowledgebase


text:
---
layout:     post
title:      ARLE Mini SLAM
author:     Abhay Pratap Singh
tags: 		4ilabs arle rosbot slam
category:   arle
subtitle:  	Using ROSbot SLAM
visualworkflow: true
---

# Using SLAM for ARLE Mini

### ARLE Mini :

 ARLE Mini is an autonomous open source robot capable of navigating using RPLidar powered by Intel NUC

 ARLE Mini is a miniature version of ARLE(Autonomous Robot for Library Enhancement) being developed for managing books in the institute library of Indian Institute of Technology, Guwahati. ARLE is aimed to be able to navigate autonomously in the library, identify books and racks using RFIDs, pick and place the books in the correct rack using an arm mounted on the bot.

ARLE Mini first build

### Modules used for Autonomous Movement

-	**Tf (tf2)**: Coordinate the transform library. It's one of the most important packages for ROS. Thanks to tf, you can manage all coordinate values, 	 including the position of the robot or relations between the camera and wheels. For treating various categories of coordinates, several distinctive concepts such 		as frame and tree are adopted.

- **slam_gmapping**: ROS wrapper for OpenSlam's Gmapping. gmapping is one of the most famous SLAM algorithms. While still popular, there are also several alternatives now for this function.

- **move_base**: Core module for autonomous navigation. This package provides various functions, including planning a route, maintaining cost maps, and issuing speed and direction commands for motors.
    Robot_state_publisher. Publishes the 3D poses of the robot links, which are important for a manipulator or humanoid. In the case of SAWR, the most important data maintained by this module is the position and orientation of the robot and the location of the camera relative to the robot’s position.

- **Robot_state_publisher**: Publishes the 3D poses of the robot links, which are important for a manipulator or humanoid. In the case of SAWR, the most important data maintained by this module is the position and orientation of the robot and the location of the camera relative to the robot’s position.

![sawr_graph]

[sawr_graph]: https://software.intel.com/sites/default/files/managed/5e/8c/Build-Autonomous-Mobile-Robot-Intel-RealSense-Camera-ROS-SAWR-fig13.png "SAWR ROS node graph viewed by rqt_graph"
{: width="1100px" style="float: none;"}

SAWR ROS node graph viewed by rqt_graph

Find some useful content on SLAM & Mapping for autonomous robots [here][intel_sawr]

[intel_sawr]: https://software.intel.com/en-us/articles/build-an-autonomous-mobile-robot-with-the-intel-realsense-camera-ros-and-sawr


text:
## Inspiration
![](graphicfiles/WebDesign.png)

So the idea of building such a project came from the fact that how ruthless we humans are in consuming the resources provided to us by nature. One such important resource is **water**.

Water is being wasted and polluted so much, that it is happening at a rate that we never imagined. So we decided to build a project which monitors the water consumption, the cleanliness of the water being thrown out, etc. and charges accordingly.

A very important thing to be noted here is that about water tampering which is a common problem across all over the world. With the implementation of blockchain on timely basis, we not only prevent people from unfair practices but also generate a credit distribution system to motivate them to take their steps in conservation of this precious resource and utilize them wisely.

> And guess what?\
> It record all this data on a blockchain, so it never alters once recorded!

## What it does?
![](graphicfiles/Variation.jpg)
![](graphicfiles/Variation2.jpg)

### The project basically does the following things:

- Take input from the camera, set on the flow of the water.
- Analyze the flow rate of water in `square pixels/frame` and measure the volume consumed.
- Accordingly measure the Performance Index, Flow Credits, etc.
- Record all these value onto the blockchain so it's immutable.
- Prevent any kind of _tampering_ by water industries and _monitor_ the water in efficient way and hence motivate them to follow the best practice and conserve water.
- Based on the consumption, the credit will be distributed to the consumers, which will motivate and help them consume the water resources in efficient and non-destructing manner.

## How we built it

> - The main function of real world observation is implemented through **OpenCV** using a camera. In the given code, we have implemented our project using pre-recorded video but that can be easily altered by changing the statement:
> cam=cv2.VideoCapture("videoname.mp4")
to
> cam=cv2.VideoCapture(0) #Or whatever external cam is being used

![OpenCV Working](https://github.com/sedhha/blocksquid/blob/master/graphicfiles/background.gif)

> - A very simple blockchain protocol is being implemented in Python for simplicity and learning friendly approach.

### This is how it works:

- `WatertypeDetermination.py` => A code to create histograms which then
will help in colour comparision. Add the path for cropped images of fresh water and waste water
- `WaterClassifier.py` => Necessary functions to execute water quality and flow rate.

![Flow Demo - OpenCV](https://github.com/sedhha/blocksquid/blob/master/graphicfiles/demo4.gif)
![Pixel Variation - OpenCV](https://github.com/sedhha/blocksquid/blob/master/graphicfiles/pixelvariation.gif)

- `blockchain.py` => File to start mining block
- `blockchainv0.py` => V0 of `blockchain.py`
- `codetodetectflowrate.py` => Press R to print selectedROI (while running the program) and some other variables code has all the explanation for the same

![ROI1](https://github.com/sedhha/blocksquid/blob/master/graphicfiles/selectroi.jpg)
![ROI2](https://github.com/sedhha/blocksquid/blob/master/graphicfiles/selectROI2.jpg)

## Challenges we ran into

> ### Major challenges we faced:
>
> - Reading the real world data i.e. _hardware -> software_
> - Writing the data to the blockchain accordingly by averaging out values.
> - Attempting to implement the NEAR API in our project.

## Accomplishments that we're proud of

> We're proud of the implementation that we did for writing the data from the hardware to the blockchain directly

## What we learned

- The major learning from this project we had, is the blockchain part. We learn how a blockchain can seamlessly integrate with the hardware and software as required.

## What's next for BlockSquid

> Further we would like to add more features such as a administrative dashboard, cost calculation and improve the throughput calculation.

## References

> - [Blockchain Demo (https://github.com/anders94/blockchain-demo/)](https://github.com/anders94/blockchain-demo/)
> - [Blockchain A-Z™](https://www.superdatascience.com/pages/blockchain)
> - [w3schools](https://www.w3schools.com/)

repository: pushkar-bharambe/blocksquid

repo_name: pushkar-bharambe/blocksquid


text:
---
# Documentation: https://wowchemy.com/docs/managing-content/

title: "Bridging the Gap Between Theory and Practice of Parallel Computing"
event: "The University of New Mexico Chapter of Sigma Xi"
event_url:
location:
address:
  street:
  city:
  region:
  postcode:
  country:
summary:
abstract:

# Talk start and end times.
#   End time can optionally be hidden by prefixing the line with `#`.
date: 2000-10-18T15:00:00-06:00
date_end: 2000-10-18T16:00:00-06:00
all_day: false

# Schedule page publish date (NOT event date).
publishDate: 2021-09-06T21:15:55-04:00

authors: []
tags: []

# Is this a featured event? (true/false)
featured: false

# Featured image
# To use, add an image named `featured.jpg/png` to your page's folder.
# Focal points: Smart, Center, TopLeft, Top, TopRight, Left, Right, BottomLeft, Bottom, BottomRight.
image:
  caption: ""
  focal_point: ""
  preview_only: false

# Custom links (optional).
#   Uncomment and edit lines below to show custom links.
# links:
# - name: Follow
#   url: https://twitter.com
#   icon_pack: fab
#   icon: twitter

# Optional filename of your slides within your event's folder or a URL.
url_slides:

url_code:
url_pdf:
url_video:

# Markdown Slides (optional).
#   Associate this event with Markdown slides.
#   Simply enter your slide deck's filename without extension.
#   E.g. `slides = "example-slides"` references `content/slides/example-slides.md`.
#   Otherwise, set `slides = ""`.
slides: ""

# Projects (optional).
#   Associate this post with one or more of your projects.
#   Simply enter your project's folder or file name without extension.
#   E.g. `projects = ["internal-project"]` references `content/project/deep-learning/index.md`.
#   Otherwise, set `projects = []`.
projects: []
---

{{<figure src="flyer.jpg">}}
{{<figure src="news.jpg">}}

IEEE Outstanding Young Engineering Award Talk, Cosponsored by the Electrical & Computer Engineering Department

**David Bader** is an Assistant Professor of EECE at the University of New Mexico (UNM).  He will review recent new engineering developments in parallel computing algorithms and parallel computers which may break the bottleneck of sequential computing for practical applications that require complex combinatorial optimization. He will demonstrate this ability to brdge this gap using problems such as aligning sequences and reconstructing evolutionary trees that arise in computational genomics and bioinformatics. David's recent research has produced a new, preliminary methodology for programming shared-memory machines and clusters of nodes. David is considered a "Mega Star" in EECE Dept., ranking in top 2 faculty, in funding, among all CE faculty.

The Science & Society Series of Talks is co-sponsored by the Sigma Xi Headquarters, the Office of the Associate Provost for Research, the Office of the Vice President for Health Sciences, the Colleges of Arts & Sciences, Education, Engineering, and Pharmacy, the Center for Radioactive Waste Management, the University Honors Program, the Department of Physics & Astronomy, the Divsion of Continuing Education, and the Albuquerque Section of the Institute of Electrical & Electronics Engineers.

gha_language: Shell


text:
# GANs with spectral normalization and projection discriminator
Modified [Preferred Networks' implementation of SNGAN with projection](https://github.com/pfnet-research/sngan_projection) to work with the original dataset.

## The notable changes are:
* add config files, image processing script, other misc files for working the original dataset.

* modify and add the scripts for custom evaluation (image generation) (ie. evatuation.py, evaluations/{}.py)

# Examples
to be come

repository: tramadol-hydrochloride/SNGAN

gha_language: Python

repo_name: tramadol-hydrochloride/SNGAN


text:
<!-- #include "./common/header.md" -->

# Update-VSTeamBuildDefinition

## SYNOPSIS

<!-- #include "./synopsis/Update-VSTeamBuildDefinition.md" -->

## SYNTAX

## DESCRIPTION

Reads a JSON file off disk or string and uses that file to update an existing build definition in the provided project.

You must call Set-VSTeamAccount before calling this function.

## EXAMPLES

### Example 1

```powershell
Update-VSTeamBuildDefinition -ProjectName Demo -Id 123 -InFile build.json
```

This command reads build.json and updates existing build definition with
id 123 from it on the demo team project.

### Example 2

```powershell
$b = Get-VSTeamBuildDefinition -ProjectName Demo -Id 23 -Raw
$b.variables.subscriptionId.value = 'Some New Value'
$body = $b | ConvertTo-Json -Depth 100
Update-VSTeamBuildDefinition -ProjectName Demo -Id 23 -BuildDefinition $body
```

## PARAMETERS

### Id

Specifies the build definition to update by ID.

To find the ID of a build definition, type Get-VSTeamBuildDefinition.

```yaml
Type: Int32
Required: True
Accept pipeline input: true (ByPropertyName)
```

### InFile

Path and file name to the JSON file that contains the definition to be updated. If the path is omitted, the default is the current location.

```yaml
Type: String
Required: True
Parameter Sets: File
Position: 1
Accept pipeline input: true (ByPropertyName)
```

### BuildDefinition

JSON string of build definition.

```yaml
Type: String
Required: True
Parameter Sets: JSON
Position: 1
Accept pipeline input: true (ByPropertyName)
```

<!-- #include "./params/projectName.md" -->

## INPUTS

## OUTPUTS

### None

## NOTES

<!-- #include "./common/prerequisites.md" -->

## RELATED LINKS

repository: MethodsAndPractices/vsteam

branch_name: refs/heads/trunk

gha_language: PowerShell

repo_name: MethodsAndPractices/vsteam


text:
### ST_DESTINATION

{{% bannerNote type="code" %}}
transformations.ST_DESTINATION(geom, distance, bearing, units)
{{%/ bannerNote %}}

**Description**

Takes a Point and calculates the location of a destination point given a distance in degrees, radians, miles, or kilometers; and bearing in degrees. This uses the Haversine formula to account for global curvature.

* `geom`: `GEOMETRY` starting point.
* `distance`: `FLOAT8` distance from the origin point.
* `bearing`: `FLOAT8` ranging from -180 to 180.
* `units` (optional): `VARCHAR(15)` units of length, the supported options are: miles, kilometers, degrees or radians. By default `units` is `kilometers`.

**Return type**

`GEOMETRY`

**Examples**

```sql
SELECT transformations.ST_DESTINATION(ST_MakePoint(-3.70325,40.4167), 10, 45);
-- POINT (-3.61964617436 40.4802614598)
```

```sql
SELECT transformations.ST_DESTINATION(ST_MakePoint(-3.70325,40.4167), 10, 45, 'miles');
-- POINT (-3.56862505482 40.5189626778)
```

repository: huq-industries/carto-spatial-extension

repo_name: huq-industries/carto-spatial-extension


text:
---
title: Shillelagh
subtitle: Transmutation cantrip
level: cantrip
tags: [druid, cantrip, transmutation]
cast: 1 bonus action
duration: 1 minute
components: V, S, M
range: Touch
---
Materials: mistletoe, a shamrock leaf, and a club or quarterstaff
The wood of a club or a quarterstaff you are holding is imbued with nature’s power. For the duration, you can use your spellcasting ability instead of Strength for the attack and damage rolls of melee attacks using that weapon, and the weapon’s damage die becomes a d8. The weapon also becomes magical, if it isn’t already. The spell ends if you cast it again or if you let go of the weapon.

repository: lester-lee/dnd

repo_name: lester-lee/dnd


text:
Recently a new version of Locust was released so I decided to use this as an excuse to refresh the docker image and show information on how to use it.
    The patch mentioned here was incorporated into Locust source codebase making this one obsolete.

    In addition, I decided to create a dedicated repository for the docker image for Locust. If you visit https://github.com/karol-brejna-i/docker-locust, you’ll notice that the repo is organized so it can maintain many versions of the image.

### Please, visit https://github.com/karol-brejna-i/docker-locust for the latest version of the docker image.

# Original content:
Dockerfile that prepares a patched version of Locust docker image (grubykarol/locust)

What it does is:
* pull Locust.io from GitHub
* go to last know good commit (as was known when implemented the fix)
* apply desired fix
* clean up

Usage identical to https://hub.docker.com/r/grubykarol/locust/.

The patch changes root-relative URLs in the web app (HTTP API, web page)
so it can be served behind a reverse proxy or Kubernetes ingress.


text:
# To do:

- Dynamic Array (with extra capacity at both ends)

# To decide

## About stacks

- which stack implementation to use

## About lists

- review compare current implementation to AbstractMutableList

# To review:

- koltin map implementation
- koltin priority queue implementation
- koltin set implementation
- koltin hash table implementation

- kotlin serialization (Serializable)
- RandomAccess
- Cloneable

- https://en.wikipedia.org/wiki/List_of_data_structures
- https://en.wikipedia.org/wiki/Collection_(abstract_data_type)

## Linear collections

- https://en.wikipedia.org/wiki/Circular_buffer
- https://en.wikipedia.org/wiki/Double-ended_priority_queue
- https://en.wikipedia.org/wiki/Priority_queue
- https://en.wikipedia.org/wiki/Stack_(abstract_data_type)
- https://en.wikipedia.org/wiki/Circular_buffer
- https://en.wikipedia.org/wiki/Double-ended_queue
- https://en.wikipedia.org/wiki/Doubly_linked_list
- https://en.wikipedia.org/wiki/Queue_(abstract_data_type)
- https://en.wikipedia.org/wiki/Linked_list

## Associative collections

- https://en.wikipedia.org/wiki/Hash_table
- https://en.wikipedia.org/wiki/Associative_array

### Sets

- https://en.wikipedia.org/wiki/Set_(abstract_data_type)

## Graphs

### Trees

- https://en.wikipedia.org/wiki/Heap_(data_structure)

branch_name: refs/heads/main


text:
# Why Docker?
 * [Why we built docker?](https://www.youtube.com/watch?v=3N3n9FzebAA&feature=youtu.be)
	  * Shipping software from A to B  has to be done reliably and automatically, i.e. **behaviour of same software should be same in both machines A & B. But this is not an easy task**.
	  * Software stack is complex, hardware infrastructure is also complex.
	  * Each software stack should run on each hardware infrastructure. Hence, it becomes like a matrix where each software component is multiplied by each hardware component.
	  * Current situation : Shipping software from A to B is brittle & labor-intensive. Also, matrix is resource-consuming.
# How to fix our current situation?
* Just like Shipping industry (ships, containers, etc.)
	* Example : Huge Coffee bags with ships, trains, etc to load coffee; basically how the infrastructure for shipping & goods being shipped is handled? Same as our current scenario
	* In 1950s, shipping industry fixed a standard box with fixed length, size, weight, etc. basically an API
	* Shipper: doesn't care about journey of the box, it only cares about packing and unpacking of goods from/to container.
* Infrastructure provider: doesn't care about packing & unpacking of goods in container but cares about loading/unloading of the containers irrespective of the contents of the containers.
* seperation of concerns gives automation; automation gives reliability & low costs
* **Idea: build containers for software!**
# But what about virtualenv, rvm, jar? Are they not some sort-of solves same problems?
* Yes, but they are insufficient
	* You can store all dependencies of Python in virtualenv but not system libraries
	* Meaning: there will be still some dependencies which you can't contain.
# What about VMs ?
* Yes, we can share a computer with all the dependencies in that computer BUT then as developer you are putting restrictions on the infrastructure hardware like for network hardware we should use this, etc.
	* Meaning no freedom for infrastructure providers.
	* Example: If I am giving coffee bags to shipping company, I should not enforce which crane to use.
* VMs are computationally heavy, i.e. lots of overhead is there.
# Can we get best of the both worlds?
* Sandbox the entire system
* without machine details
* without the performance hit
# Can it be done?
* Yes, it can be done because of namespacing in modern linux kernels
	* Sandboxing becomes FAST!
	* works with all languages & dev tools - REALLY FAST!
* Docker provides a **standard container format** for this hybrid sandboxing.
	* gives simple tools to developers to build his source code to containers, regardless of the language & dev tools
	* gives simple tools to operations to take the container regardless what's in it, and run it on many machines possible.


text:
## Balanced Parenthesis

Counting and matching opening and closing parentheses. Adding one extra ```)``` and breaking your code. We've all been through it. To help save future aspiring coders from this terrible agony, write a method, ```balanced_brackets```, which takes in a string
and returns true if it is a valid combination of opening and closing parentheses.

### Examples
```ruby
string = "(((hello)))"
balanced_brackets(string)
=> true

string = "(it's)((lit))((((fam))))"
balanced_brackets(string)
=> true

string = "(((((((lol))))"
balanced_brackets(string)
=> false

string = ")("
balanced_brackets(string)
=> false
```

repository: MrRogerino/dbc-whiteboarding

gha_language: Ruby

repo_name: MrRogerino/dbc-whiteboarding


text:
<!-- README.md is generated from README.Rmd. Please edit that file -->

# Reproducibility.in.Plant.Pathology

[![Travis-CI Build
Status](https://travis-ci.org/openplantpathology/Reproducibility_in_Plant_Pathology.svg?branch=master)](https://travis-ci.org/openplantpathology/Reproducibility_in_Plant_Pathology)
[![DOI](https://zenodo.org/badge/62676177.svg)](https://zenodo.org/badge/latestdoi/62676177)
[![Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)

This repository contains the data and code for our paper:

> Sparks, A.H., Del Ponte, E.M., Everhart, S., Foster, Z., Grünwald, N.
> (YYYY). *Title of paper*. Name of journal/book
> <https://doi.org/xxx/xxx>

Our pre-print is online here:

> Authors, (YYYY). *Title of paper*. Name of journal/book, Accessed 02
> Jun 2018. Online at <https://doi.org/xxx/xxx>

### How to cite

Please cite this compendium as:

> Sparks, A.H., Del Ponte, E.M., Everhart, S., Foster, Z.S.L., Grünwald,
> N., (2018). *Compendium of R code and data for ‘Status and Best
> Practices for Reproducible Research In Plant Pathology’*. Accessed 02
> Jun 2018. Online at <https://doi.org/10.5281/zenodo.1250665>

### How to download or install

#### The R package

This repository is organized as an R package. There is one R function,
`doi2bib()`, that is used in this repository, along with a bibliography
file of the articles that were examined that are located in
`inst/extdata` directory. We have used the R package structure to help
manage dependencies, to take advantage of continuous integration for
automated code testing and for file organisation.

You can download the compendium as a zip from from this URL:
<https://github.com/openplantpathology/Reproducibility_in_Plant_Pathology/archive/master.zip>

Or you can install this compendium as an R package,
Reproducibility.in.Plant.Pathology, from GitHub with:

``` r
# install.packages("devtools")
devtools::install_github("adamhsparks/Reproducibility_in_Plant_Pathology")
```

Once the download is complete, open the
`Reproducibility_in_Plant_Pathology.Rproj` in RStudio to begin working
with the package and compendium files.

The package has a number of dependencies on other R packages, and
programs outside of R. These are listed at the bottom of this README.
Installing these can be time-consuming and complicated, so we’ve
provided a Docker image that includes all the necessary software, code
and data to run our analysis. The Docker image may give a quicker entry
point to the project, and is more self-contained, so might save some
fiddling with installing things.

#### The Docker image

A Docker image is a lightweight GNU/Linux virtual computer that can be
run as a piece of software on Windows and OSX (and other Linux systems).
To capture the complete computational environment used for this project
we have a Dockerfile that specifies how to make the Docker image that we
developed this project in. The Docker image includes all of the software
dependencies needed to run the code in this project, as well as the R
package and other compendium files. To launch the Docker image for this
project, first, [install Docker](https://docs.docker.com/installation/)
on your computer. At the Docker prompt,
    enter:

    docker run -dp 8787:8787 adamhsparks/reproducibility_in_plant_pathology

This will start a server instance of RStudio. Then open your web browser
at localhost:8787 or or run `docker-machine ip default` in the shell to
find the correct IP address, and log in with rstudio/rstudio.

Once logged in, use the Files pane (bottom right) to navigate to
`Reproduciblity_in_Plant_Pathology` folder for this project, and open
the `.Rproj` file for this project. Once that’s open, you’ll see the
`analysis/paper` directory in the Files pane where you can find the R
markdown document, and knit them to produce the results in the paper.
More information about using RStudio in Docker is available at the
[Rocker](https://github.com/rocker-org)
[wiki](https://github.com/rocker-org/rocker/wiki/Using-the-RStudio-image)
pages.

We developed and tested the package on this Docker container, so this is
the only platform that we’re confident it works on, and so recommend to
anyone wanting to use this package to generate the vignettes, etc.

## Meta

Code: [MIT](http://opensource.org/licenses/MIT) year: 2018, copyright
holder: Adam H Sparks

Data: [CC-0](http://creativecommons.org/publicdomain/zero/1.0/)
attribution requested in reuse

### Licenses

We used [RStudio](http://www.rstudio.com/products/rstudio/) on macOS and
Ubuntu 17.10.

**Code :** See the [DESCRIPTION](DESCRIPTION) file

**Data :** [CC-0](http://creativecommons.org/publicdomain/zero/1.0/)
attribution requested in reuse

Adam H Sparks, Associate Professor, Centre for Crop Health
University of Southern Queensland
Toowoomba, Queensland 4350

(+61) (7) 4831 1948<EMAIL_ADDRESS><https://staffprofile.usq.edu.au/Profile/Adam-Sparks>


text:
# angular-webpack-quickstart
Simple starter for AngularJS and Bootstrap using Webpack. Created for
'Web applications' course at [Military University of Technology](http://www.wat.edu.pl/),
as a start point for students to learn about modern web development tools and creating web applications.

Starter contains AngularJS (1.x), Bootstrap (3.x) and is built (and served for development) by Webpack.

### Quick start
```bash
# Clone repository
git clone https://github.com/elwin013/angular-webpack-quickstart.git webapp
# change directory to webapp
cd webapp
# install dependencies
npm install
# start webpack server
npm start
```
Now you can open [localhost:8080](http://locahost:8080) in you browser.

At [localhost:8080/#/githubInfo](http://localhost:8080/#/githubInfo) you can access example page which loads data from GitHub API.

### Dependencies
> For version look into package.json!

To build:
* npm as a package manager,
* webpack with loaders (babel, css, file, html, style, url) and plugins (copy-webpack-plugin),
* webpack-dev-server,
* babel (babel-core, babel-preset-es2015),
* rimraf.

Running app:
* Angular, AngularUI Router,
* Bootstrap,
* jQuery.

### Running the app
After installing all dependencies (with `npm install`) you can run app:
```bash
npm start
```
It will run webpack server - build in memory, changes are watched, and app will
reload after change.

### Build deploy version
After installing all dependencies (with `npm install`) you can run build app:
```bash
npm run build
```
It will build application and store all data in `dist/ ` directory. Files are uglified and minified.

### Contribution
You're interested in contributing? Awesome!  I'll do my best to merge changes!

### License
[MIT](/LICENSE)


text:
## Overview
```
// concrete computation time definition
forall n, ceval st(n) t st'(n) -> T(n) = t

// asymptotic time bound for denotational semantics
exists a, N, forall n, n > N -> 0 < T(n) <= f(n) -> T = O(f)

// asymptotic time bound for hoare logic (syntax)
forall n, {{P(n)}} c {{Q(n)}} O(f(n))
```
## Hoare logic with asymptotic bound
```
// skip rule is the same
{{P(n)}} Skip {{P(n)}} O(1)

// assignment rules are the same
{{P}} X ::= E {{Q}} O(1)

// consequence rules are the same
P(n) |- P'(n) ->
{{P'(n)}} c {{Q'(n)}} O(f(n)) ->
Q'(n) |- Q(n) ->
{{P(n)}} c {{Q(n)}} O(f(n))

// sequence rule accumulates time
{{P(n)}} c1 {{Q(n)}} O(f(n)) ->
{{Q(n)}} c2 {{R(n)}} O(g(n)) ->
{{P(n)}} c1;;c2 {{R(n)}} O((f+g)(n))

// if rule only supports branches with same time bound
{{P(n) AND [[b]]}} c1 {{Q(n)}} O(f(n)) ->
{{P(n) AND NOT [[b]]}} c2 {{Q(n)}} O(f(n)) ->
{{P(n)}} If b Then c1 Else c2 EndIf {{Q(n)}} O(f(n)).

// while rule
// V stands for statements about loop variant
{{P(n) AND V(n) AND [[b]]}} c {{P(n) AND V(n')}} O(f(n)) ->
O(g(n)) satisfy T(n) = T(n') + O(f(n)) ->
{{P(n) AND V(n)}} While b Do c EndWhile {{P(n) AND V(0) AND NOT [[b]]}} O(g(n))
```

## Problems with Hoare While Linear
Not matter what we use, logical_var or Z, in loop body to specify the change of loop variant, there exists following problem:
- if we put the introduction of $v$ at the most front of the theorem, the property of loop body become too strong to be applied to the second step during induction.
- if we put the introduction of $v$ in the property of loop body, we are unable to extract any information about a1, a2, N.


text:
---
code: true
type: page
title: core:hotelClerk:removeRoomForCustomer
---

# core:hotelClerk:removeRoomForCustomer

| Arguments        | Type              | Description                                                                                |
| -----------------| ----------------- | -------------------------------------------------------------------------------------------- |
| `RequestContest` |
object
 | [requestContext](/core/2/protocols/api/context/requestcontext/) object |
| `room`           |
object
 | Joined room information in Koncorde format                                                   |

Triggered whenever a user is removed from a room.

---

## room

The provided `room` object has the following properties:

| Properties     | Type                 | Description             |
| -------------- | -------------------- | ----------------------- |
| `id`           |
string
    | Room unique identifier  |
| `index`        |
string
    | Index                   |
| `collection`   |
string
    | Collection              |

---


text:
---
title: Memory Functionality
page_title: Memory Functionality
description: Check our "Memory Functionality" documentation article for the RadCalculator {{ site.framework_name }} control.
slug: radcalculator_memoryfunctionality
tags: memory,functionality
published: True
position: 0
---

# Memory Functionality

__RadCalculator__ supports all native memory functionality the end user is accustomed with.

## Examples

* __Memory Plus (M+)__ - adds the current input into the memory. For example:

 1. Input - '3' -> M+ -> Memory Value - '3'

 1. Input - '6' -> M+ -> Memory Value - '9'

* __Memory Minus (M-)__ - substracts the current input value from the memory value. For example:

 1. Input - '5' -> M- -> Memory Value - '-5'

 1. Input - '6' -> M- -> Memory Value - '-11'

* __Memory Store (MS)__ - stores the current input value into the memory. For example:

 1. Input - '42' -> MS -> Memory Value - '42'

 1. Input - '82' -> MS -> Memory Value - '82'

* __Memory Recall (MR)__ - displays the value stored into the memory. For example:

 1. Input - '42' -> MR -> Memory Value - '42'

 1.  MR -> Displayed Value - '42'

* __Memory Clear (MC)__ - clears the memory value.

## See Also

 * [Clear Functionality]({%slug radcalculator-clearfunctionality%})

 * [Keyboard Support]({%slug radcalculator-keyboardsupport%})

repository: Eldoir/xaml-docs

repo_name: Eldoir/xaml-docs


text:
### Using Oracle instant client to interface with oracle

If oracle database is not installed in the PC running the python script,
Oracle Instant client is required for interfacing with Oracle database

### Steps to install Oracle instant client
* Download Oracle  Instant Client Package - Basic zip file
* Create an installation directory like ```c:\oml4rclient_install_dir```
* Copy the zip file to the installation directory like
```c:\oml4rclient_install_dir\instantclient-basic-windows.x64-<IP_ADDRESS>.0.zip```
* Unzip the zip file there. Now all the instant client files may in a folder like
```c:\oml4rclient_install_dir\instantclient_19_6```
* Include the above folder path in ```PATH``` and ```OCI_LIB64``` system environment variables

If we get an error in python something like "32 bit instant client not found", then remove the 64 bit files and folders and install a 32 bit version of instant client

We also need cx_Oracle module to interface with Oracle in python - https://oracle.github.io/python-cx_Oracle/
```
pip install cx_Oracle
```

### Links
* Official docs - https://docs.oracle.com/en/database/oracle/r-enterprise/1.5.1/oread/installing-oracle-database-instant-client.html#GUID-A61C2824-B9C7-4344-A7A2-E7FE0F05695D


text:
---
title: Completed JavaScript Data Structure Course, and Here is What I Learned About Binary Search Tree.
date: "2020-01-11"
slug: what-i-learned-about-binary-search-tree
updatedAt: "2021-06-20"
description: What is binary search tree? Let's identify whether it is suitable for storing vocabulary data.
featured: true
topics:
 - javascript
 - data-structure
featuredImage: './tree.jpg'
---

Photo by David Vig on Unsplash. This article is originally published on dev.to on  11 Jan 2020.

While taking [data structures and algorithms course on Udemy](https://www.udemy.com/course/js-algorithms-and-data-structures-masterclass/), I was trying to implement what I just learned onto my [Chrome extension project](https://chrome.google.com/webstore/detail/vocab-note/obnmagkhjbjbolndeminbibodlfjnabp?hl=en&gl=IE), because the main data of the Chrome extension was stored in an array inefficiently. However, I didn't know what is the best structure, and how I can make changes to the situation.

In this series of articles, we discuss implementations, the pros, and cons of each data structure so we can understand its features, and find out which is the best for the main data.

1.[Completed JavaScript Data Structure Course, and Here is What I Learned About Linked List.](https://dev.to/maikomiyazaki/completed-javascript-data-structure-course-and-here-is-what-i-learned-about-linked-list-11nm)
2.[Completed JavaScript Data Structure Course, and Here is What I Learned About Stack/Queue.](https://dev.to/maikomiyazaki/should-i-use-stack-queue-data-structures-in-javascript-io)

Here is the main data in an array as an example:

```javascript
// Result of console.log(main-data)
(4)[{...}, {...}, {...}, {...}]
0: {category: "cat1", id: "4", meaning: "information of the vocabulary.", tag: ["tag1", "tag2"], word: "Example Vocab 1"}
1: {category: "cat3", id: "3", meaning: "Hello World", tag: ["tag1", "tag4"], word: "Example Vocab 2"}
2: {category: "cat2", id: "2", meaning: "This is new vocabulary.", tag: ["tag4"], word: "Example"}
3: {category: "cat4", id: "1", meaning: "You can write anything.", tag: ["tag2", "tag4", "tag5"], word: "Sample"}
```

This takes time complexity of O(n) if we wanted to edit/delete each data.

Today we are going to discuss binary search tree and if we can implement it for the main data.

What is binary search tree look like?

As there is 'tree' in its name, the binary search tree looks like a tree if we visualize it.

![how Binary Search Tree look like](https://thepracticaldev.s3.amazonaws.com/i/9c064vw2e2atnyw6rntg.png)

Tree is one big group of data structure type and there are many categories within, such as binary trees, Heaps, etc. Each of trees has its own features but they are all **nonlinear data structures**, not likely arrays, linked lists, stacks and queues which are linear data structures.

Binary search tree is a special case of binary trees that each node can hold **0 to 2 children, but not more than 2**. And on top of that, they are sorted in a special order.

Like linked lists, each node can point out their children. As the rule, **left** pointer can only point out a node that is **smaller than the parent node**, and **right** pointer can only point out a node that is **larger than the parent**.

![binary search tree left and right rule](https://thepracticaldev.s3.amazonaws.com/i/4ehzly8kesxc96wb5uuk.png)

These features make binary search tree good at searching. For instance, when you want to find a node 23, you can start from the root node, and if it's not 23 and larger than 23, you only need to search left side of the root.

![why binary search tree good at searching](https://thepracticaldev.s3.amazonaws.com/i/ofgv33p5abxjagxw2leh.png)

Basic Implementation

Firstly, we define Node and BinarySearchTree. Node has properties of 2 children, and they are defined as left and right.

```javascript
class Node {
    constructor(val) {
        // store value into val property
        this.val = val;
        // initialize left child property empty
        this.left = null;
        // initialize right child property empty
        this.right = null;
    }
}
```

To define a binary search tree itself, we only need to define root property.

```javascript
class BinarySearchTree {
    constructor(){
        this.root = null;
    }
}
```

Searching

Searching only cost time complexity of **O(log n)** because every iteration, you can get rid of half of the nodes in one go. In other words, even you have a double amount of nodes in the tree, you only need to add one more iteration.

```javascript
find(val) {
    // define the root node as target
    let target = this.root,
    // Set found flag as false, and while loop runs when it is false
    let found = false;
    // Return false if nothing in the tree
    if (target === null) return false;
    // run while loop when target exists and also 4e2flag is false
    while (target && !found) {
        if (val < target.val) {
            // if the value we are looking for is smaller than the target value, point left child out as target
            target = target.left;
        } else if (val > target.val) {
            // if the value we are looking for is larger than the target value, point right child out as target
            target = target.right;
        } else if (val === target.val) {
            // if the value and the value of the target match, set found flag true
            found = true;
        }
    }
    return found;
}
```

Insertion

Inserting also takes **O(log n)** with the same reason as searching.

```javascript
insert(val) {
    // Create a node
    const node = new Node(val);
    if(this.root === null) {
        // if the tree is empty, append the node as root
        this.root = node;
        return this;
    } else {
        // otherwise set root node as target
        let target = this.root;
        while (true) {
            // if same node exists in the tree, return undefined
            if (val === target.val) return undefined;
            // Case 1: when the node we want to insert is greater than target
            if (node.val > target.val) {
                if (target.right === null) {
                    // if the target's right child is empty, set the node in there
                    target.right = node;
                    return this;
                } else {
                    // if there is no room at the right of target, set target.right as target
                    target = target.right;
                }
            }
            // Case 2: when the node we want to insert is lesser than target
            if (node.val < target.val) {
                if (target.left === null) {
                    // if the target's left child is empty, set the node in there
                    target.left = node;
                    return this;
                } else {
                    // if there is no room at the left of target, set target.left as target
                    target = target.left;
                }
            }
        }
    }
}
```

Deletion

To delete a node, we need to consider three situations and append different functions to each scenario.

1. **When deleting a leaf node**
   Set the parent node's pointer to the leaf node as null

2. **When deleting a node with one child**
   Set the parent node's pointer to the deleting node's child node

3. **When deleting a node with two children**
   Find the smallest leaf node in the right side of the parent node, then overwrite deleting node with the smallest leaf, and delete the smallest leaf node.

```javascript
delete(val) {
    const deleteNode = (node, val) => {
        if (!node) return undefined;
        if (node.val === val) {
            // Case1: When deleting a leaf node
            if (node.left === null && node.right === null) {
                return null;
            }
            // Case2: When deleting a node with one child
            else if (node.left === null) {
                return node.right;
            }
            else if (node.right === null) {
                return node.left;
            }
            // Case3: When deleting a node with two children
            else {
                let replacement = node.right;
                while(replacement.left !== null) {
                    replacement = replacement.left;
                }
                node.val = replacement.val;
                node.right = deleteNode(node.right, replacement.val);
                return node;
            }
        } else if (val < node.val) {
            // if the target value is larger than the value you are looking for,
            //move onto left child
            node.left = deleteNode(node.left, val);
            return node;
        } else {
            // if the target value is smaller than the value you are looking for,
            //move onto right child
            node.right = deleteNode(node.right, val);
            return node;
        }
    }
    this.root = deleteNode(this.root, val);
}
```

Conclusion: Is Binary Search Tree the best choice?

As searching/insertion/deletion take **O(log n)** complexity, I thought it can be the best choice to implement to my Chrome Extension, however, there are situations to take **O(n)** for each method. Unfortunately, that could be the case for the project.

With a binary search tree, there is a case to be unbalanced depends on the situation. for example, if the smallest node is appended to the root node, the rest of the node only stored on the right side.

If sorted data was inserted one by one? It would actually be a linked list.

![worst case with binary search tree](https://thepracticaldev.s3.amazonaws.com/i/d6znjxf47wa2kscgj397.png)

Therefore a binary search tree should be implemented with another method to keep the tree balanced, otherwise we may not be able to use the full potential.

I'm going to move forward to see if there's a better structure for my Chrome Extension project, but I'm going to keep binary search tree as one of the options.

url: https://raw.githubusercontent.com/miyazakimaiko/portfolio-blog-2021-2/85dd7d63e69d29d4cda3190e45c5d176e20236fd/content/blog/Completed JavaScript Data Structure Course, and Here is What I Learned About Binary Search Tree./index.md


text:
---
layout: post
title: ML Predicting the success of recipes
---

The main idea of this post, to highlight web scraping and machine learning using linear regression.

![recipes image]({{ site.url }}/images/recipes.png)

For the purpose of the second project for metis, I'll be taking the data set by using web scraping tool called BeautifulSoup, in order to apply the concepts that we have learned.

I have choose Allrecipes website which contain information about different food recipes.
This project uses libraries like Pandas, numpy, MatplotLib, seaborn, BeautifulSoup, statsmodels, sklearn and pickle.

### Challenge:
It all starts when a chef wanted to know if his recipes are gaining a massive popularity and success among people. For that amateur chef, I have used Allrecipes website data to predict recipes success, so he could start his new restaurant.

### Methodology
In order to create a decent model for predictions, the following list contain the main steps that we should take:

* Web scraping and data acquisition.
* Data cleaning and preprocessing.
* Feature engineering.
* Modeling using linear regression.
* Testing results.

### Data Acquisition
In general, the website has two types of templates, which made scraping more complicated. You can find them in these links [template1](https://www.allrecipes.com/recipe/13477/double-layer-pumpkin-cheesecake/) and [template2](https://www.allrecipes.com/recipe/8817/slow-cooker-chicken-cacciatore/). However, I cope with it by defining a scraping technique for each template separately. Finally, I got to collect more than 1000 observations and 9 features which will be explained more bellow:

![features image]({{ site.url }}/images/features.png)
![dataframe image]({{ site.url }}/images/dataframe.png)

**ratings** – The recipe's rating.

**title** – The recipe's title.

**made_it** – How many people have made this recipe.

> The **made_it** is our target.

**reviews** – The number of reviews for each recipe.

**no_photos** – The number of photos for each recipe.

**cals** – The amount of calories in each recipe.

**times** - The amount of time each recipe needs to be prepared in minutes.

**cats** - The recipe's category.

**servings** - The number of servings for each recipe.

### Pre-processing and Data Cleaning

Basically, I have spent a lot of time on this part because the scraping outcome was unclean and messy. Therefore, I had to deal with extra noisy information and change the others to numerical values.

Furthermore, I had to handle missing values that appeared in two columns (time and calories). Then I have checked for negative values after that I dropped two columns (title and cats). Finally I plot the pair plot for my features to visualize it and scan it by intuition. However, I figure out I had to apply power transformation for the whole features including the target in order to have them look like Gaussian Distribution.

![pairplot image]({{ site.url }}/images/pairplot.png)

After we apply all the cleaning part I have saved the data frame in a pickle file to reduce the amount of time in processing the data and to reach it at anytime when it's needed.

### Data Exploration and Visualization

After finishing the cleaning part, I start analyzing the data by creating a scatter plot for no_photos - which is one of the features that has a linear relationship towards the target also we can see it colored by each category in the following figure.

![eda image]({{ site.url }}/images/eda.png)

From the previous figure, we can see the drinks -in pink- has the least popularity with the least number of photos. Whereas, desserts -in dark blue- has the most popularity among people with the highest number of pictures.

### Modeling and Testing

In order to start our model we have to be sure that our target is a Gaussian like so it succeed to fit linear model. For that purpose I have plot my target -made_it- using histogram.

![target image]({{ site.url }}/images/target.png)

After that, I use heatmap plot to visualize correlations between features, also for discovering multicollinearity.

![heatmap image]({{ site.url }}/images/heatmap.png)

from the previous figure, there is a strong correlation between no_photos and reviews towards the target. In the other hand there is a weak correlation between cals, time and servings towards the target.

#### Baseline Model
 As the first step before creating our model, we need to split the data into training and testing sets by 80 and 20 respectively. By identifying X and Y values then using ```train_test_split``` with ```test_size=.2, random_state=42```

Then I create the linear Regression model using sklearn, after that I feed it with my training X and Y data.
Finally I calculate R^2 of 0.80 which was good.

Then I decided to apply cross validation technique using ``` KFold(n_splits=5, shuffle=True, random_state = 71) ``` and I end up with improved model performance by R^2 of 0.91 which is better than before.
So I test the model by using the test data set and I got R^2 of 0.93 and coefficients as follows:

![coefficients image]({{ site.url }}/images/coefficients.png)

The next figure illustrating the residual for the final model results. We can see it is randomized around the zero mean. which is a sign of a good model.

![residual image]({{ site.url }}/images/residual.png)

### Conclusion

To conclude, I recommend our chef to increase the number of recipes pictures as much as possible and encouraging him to focus on desserts, since its more popular. Moreover my model shows a good results of predicting the recipes success to help him to starts his new business.


text:
# Instagram Scraper

instagramScraper is an application written in Python that crawls and scrapes an instagram user's posts and comments.

It fetches a list of desired number of links to posts by any user, the caption for each post, the number of likes and the timestamp of when the post was done.
From the posts it saves the comments, username of the commenting person and the timestamp as well.

In order to get access to more posts, it also can log you in into your account.
If you use the authentication, the program will cache the user session by default so one doesn't need to create a new session every time.

With the database functionality you can save everything in a database. Here PostgreSQL.

Please use responsibly.

## Getting Started

Download the project via git clone and run the following:

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

### Prerequisites

selenium webdriver for Firefox: it requires the geckodriver, which needs to be installed before the below examples can be run. Make sure it’s in your PATH, e. g., place it in /usr/bin or /usr/local/bin.

You can download the executable here: https://github.com/mozilla/geckodriver/releases

psycopg2 for a PostgreSQL driver

### Limit recommendatios

Depending on your internet connection it is recommended to use time.sleep() so the drives has enough time to load the contents of the site.
The explicit brakes in this code are appropriate for an internet connection of 98 Mbps.

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

repository: magda-zielinska/instagramscraper

repo_name: magda-zielinska/instagramscraper


text:
# ISSpy

## Introduction

This project began when I wanted to illuminate my lifx bulb when the International Space Station is less than five minutes away. Open Notify was the only library I could find to provide this information. However it was not completely accurate - at least at my location (Melbourne, Australia)1.

1 https://github.com/open-notify/Open-Notify-API/issues/20

## Installation

There is no backwards capability with python2. Please use python3 if you want to use this library.

> pip install isspy

## Usage

For the moment, this library uses Spot The Station by default. Country, Region and City are given in the url for Spot the Station.
e.g https://spotthestation.nasa.gov/sightings/view.cfm?country=Australia&region=Victoria&city=Melbourne

    from isspy import isspy

    country = "Australia"
    region = "Victoria"
    city = "Melbourne"

    passes = isspy.ISSpy(country, region, city)

    #Returns list of passes as a dictionary
    print(passes.get_passes())

    #expected output
    [{'datetime': datetime.datetime(2019, 4, 20, 19, 14),
      'duration': 1,
      'elevation': 17,
      'approach_elev': 11,
      'approach_dir': 'N',
      'departure_elev': 17,
      'departure_dir': 'NNE'}]

## Future

Open-Notify also provides the current location of the ISS and the people aboard. I will incorporate this at a later date.

repository: hydrius/isspy

repo_name: hydrius/isspy


text:
---
name: Feature Request
about: Use this template for feature and enhancement proposals.
labels: 'enhancement'
title: "[FR]"
---
Thank you for submitting a feature request. **Before proceeding, please review MLflow's [Issue Policy for feature requests](https://www.github.com/mlflow/mlflow/blob/master/ISSUE_POLICY.md#feature-requests) and the [MLflow Contributing Guide](https://github.com/mlflow/mlflow/blob/master/CONTRIBUTING.rst)**.

**Please fill in this feature request template to ensure a timely and thorough response.**

## Willingness to contribute
The MLflow Community encourages new feature contributions. Would you or another member of your organization be willing to contribute an implementation of this feature (either as an MLflow Plugin or an enhancement to the MLflow code base)?

- [ ] Yes. I can contribute this feature independently.
- [ ] Yes. I would be willing to contribute this feature with guidance from the MLflow community.
- [ ] No. I cannot contribute this feature at this time.

## Proposal Summary

(In a few sentences, provide a clear, high-level description of the feature request)

## Motivation
- What is the use case for this feature?
- Why is this use case valuable to support for MLflow users in general?
- Why is this use case valuable to support for your project(s) or organization?
- Why is it currently difficult to achieve this use case? (please be as specific as possible about why related MLflow features and components are insufficient)

### What component(s), interfaces, languages, and integrations does this feature affect?
Components
- [ ] `area/artifacts`: Artifact stores and artifact logging
- [ ] `area/build`: Build and test infrastructure for MLflow
- [ ] `area/docs`: MLflow documentation pages
- [ ] `area/examples`: Example code
- [ ] `area/model-registry`: Model Registry service, APIs, and the fluent client calls for Model Registry
- [ ] `area/models`: MLmodel format, model serialization/deserialization, flavors
- [ ] `area/projects`: MLproject format, project running backends
- [ ] `area/scoring`: MLflow Model server, model deployment tools, Spark UDFs
- [ ] `area/server-infra`: MLflow Tracking server backend
- [ ] `area/tracking`: Tracking Service, tracking client APIs, autologging

Interfaces
- [ ] `area/uiux`: Front-end, user experience, plotting, JavaScript, JavaScript dev server
- [ ] `area/docker`: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
- [ ] `area/sqlalchemy`: Use of SQLAlchemy in the Tracking Service or Model Registry
- [ ] `area/windows`: Windows support

Languages
- [ ] `language/r`: R APIs and clients
- [ ] `language/java`: Java APIs and clients
- [ ] `language/new`: Proposals for new client languages

Integrations
- [ ] `integrations/azure`: Azure and Azure ML integrations
- [ ] `integrations/sagemaker`: SageMaker integrations
- [ ] `integrations/databricks`: Databricks integrations

## Details

(Use this section to include any additional information about the feature. If you have a proposal for how to implement this feature, please include it here. For implementation guidelines, please refer to the [Contributing Guide](https://github.com/mlflow/mlflow/blob/master/CONTRIBUTING.rst#contribution-guidelines).)

repository: criteo-forks/mlflow

repo_name: criteo-forks/mlflow


text:
Your colour is blue. You start with a town, which contains the central tower and multiple military buildings.

The Barracks (identified with a training dummy) trains militia and infantry spearmen and swordsmen, the Archery Range (identified with a target) creates militia and infantry bowmen, the Stable (identified with a horseshoe) creates bow, sword and spear cavalry.

To control units, left click them to select and right click to order them to move to a given tile. Click and drag with the middle mouse button to move the camera. Scroll to zoom.

repository: liambaloh/WarringTownships

repo_name: liambaloh/WarringTownships


text:
# Recycler
recycler is a tool to automate the creation of typed memory recyclers in golang

[![GoDoc](https://godoc.org/github.com/azr/generators/recycler?status.png)](https://godoc.org/github.com/azr/generators/recycler)

You can generate multiple type of recycler, they will have different names, but have the same signature :

* To generate pool backed recycler:
```
//go:generate recycler -type=<T> -output <file.go>
```

* To generate freelist backed recycler:
```
//go:generate recycler -type=<T> -size <buffer_size> -template freelist.gotpl
```

* To generate your own recycler:
```
//go:generate recycler -type=<T> -size <buffer_size> -template /path/to/recycler.tpl
```
available template vars will be `{{.Type}}` and `{{.Size}}`

Prs are welcome too !

repository: standardgalactic/generators

repo_name: standardgalactic/generators