text:
# SupportBeePS

A Powershell module wrapping the SupportBee ticketing API, https://supportbee.com/

This module was created for use in the Invoke-{your}RestMethod session at NIC 2018.

The SupportBee API supports several actions on your tickets, all documented here https://developers.supportbee.com/api

Note that most of the API calls and also the functions in this module requires an access token which needs to be retrieved from your SupportBee web portal.
If you don't want to have to add the token to every command you could easily adopt the functions to use a global variable or an environmental variable.

In this release the module supports the following functions:

- *Get-SBTicket*
- *New-SBTicket*
- *Set-SBTicket*
- *Get-SBComment*
- *New-SBComment*
- *Get-SBReply*
- *New-SBReply*
- *Get-SBLabel*
- *Add-SBLabel*

license: MIT

repository: rumart/SupportBeePS

branch_name: refs/heads/master

extension: md

license_type: permissive

repo_name: rumart/SupportBeePS


text:
# Referencing
If you use GENFIRE in your research, we kindly ask that you cite the following paper:

	1. Pryor, Jr., A., Yang, Y., Rana, A., Gallagher-Jones, M., Zhou,
	J., Lo, Y.H., Melinte, G., Chiu, W., Rodriguez, J.A., Miao, J.:
	GENFIRE: A generalized Fourier iterative reconstruction
	algorithm for high-resolution 3D imaging. Sci. Rep. 7, (2017)
	free-access version: https://arxiv.org/abs/1706.04309

You may also consider referencing the first published application of `GENFIRE`:

	2. Yang, Y., Chen, C.-C., Scott, M., Ophus, C., Xu, R., *Pryor, Jr.*,
	A., Wu, L., Sun, F, Theis, W., Zhou, J., et al.:
	Deciphering chemical order/disorder and material properties
	at the single-atom level. Nature 542 (7639), 75–79 (2017)


text:
# Change log

V1.6
--

- Arkii:
	- Fixed an issue that would cause freshly downloaded addon to alway be installed to the system folder.
	- Added a button to check for addon updates.

V1.5
--

- Nalin:
	- Fix a crash when retrieving the steam install path.

- Arkii:
	- Made the version number checking more robust.
	- Updated the links to the new one click download redirect page.

V1.4
--
- Nalin:
	- Check to see if we are running on the .NET 4.5 framework.
	- Better update handling for situations where a user has both the Steam version and the standard version installed.
	- Fixed creation of registry keys related to Melder One-Click Installs Meldii opens a UAC prompt to escalate its privileges.
	- Fixed a crash as reported by MadWarrior.

- Qowface
	- Close any open flyouts when opening a new one.

- FreakByte
	- Fixed Meldii.Statics.GetFirefallInstallPath.

- Arkii:
	- Added an option to check for patch on start or not.
	- Restarts as admin when updating.
	- Updated the mod check to test if any file would override an installed file.
	- Restores backed up files to the correct locations.
	- Added option to launch Firefall with Steam.
	- Added option to go to an addons installed folder on right click.

V1.3
--
- Nalin:
	- Fixed a crash if the Firefall patch servers where offline.
	- Firefall Update Handling, If a new Firefall version is detected, prompt the user to open the launcher and download it.
	- Made crash logs more informative.
	- Remove mods if we launch the patcher to update.

- Added the ability to change the theme used in Meldii.
- Not supported addons no longer count towards the number of addons to update display.
- Fixed an issue where a mod could uninstall default UI components, ooops.
- Remove commands are no longer ignored.

V1.2
--
- Nalin: Added direct download support for addons.
- Varixai: Fixed some typos.

V1.1
--
- Nalin: Implemented the ability to launch Firefall through Meldii.
- Nalin: Handle full URLs in the forum info generator

V1.0
--
Public Release


text:
## Warning

This folder contains unoptimized SVG icons which might include metadata/layers for easier modification.

Please visit the [Releases](https://github.com/marcopixel/r6operators/releases) tab, go to the [project website](http://r6operators.marcopixel.eu) or use `yarn build:icons` for optimized SVGs and PNG files.

gha_license_id: MIT


text:
_from freeCodeCamp_

In order to help us create more flexible functions, ES6 introduces default parameters for functions.
```
function greeting(name = "Anonymous") {
  return "Hello " + name;
}
console.log(greeting("John")); // Hello John
console.log(greeting()); // Hello Anonymous
```
The default parameter kicks in when the argument is not specified (it is undefined). As you can see in the example above, the parameter
name will receive its default value "Anonymous" when you do not provide a value for the parameter. You can add default values for as many
parameters as you want.

repository: Xiaoping-Li/Notes

path: /JavaScript/ES6/Default Parameters.md

filename: Default Parameters.md

repo_name: Xiaoping-Li/Notes


text:
# MultiRes

MultiRes is a pipeline for finding ancestral gene orders with duplications when
given a phylogenetic tree, a set of synteny blocks on the extant species, and a
set of contiguous ancestral regions on these synteny blocks.

MultiRes is distributed as a bash script which runs several Python routines in
sequence. MultiRes is free and open-source software. Code included in it may be
used in part or full by others.

## Usage
 . MultiRes.sh `<gene families>` `<synteny blocks>` `<tree>`
              `<CAR file>` `<copy number threshold>`
              `<segment length>` `<window length>` `<output dir>`

## Requirements
MultiRes uses the NetworkX module to work with graphs. It also includes the
weight computation module from ANGES (Jones et al. 2012), which requires numpy.

## Input
MultiRes takes as input the following data:

 A phylogenetic tree in NHX format.

 A set of gene families in the inferCARs format.

 A set of synteny blocks in the inferCARs format.

 Contiguous ancestral regions at the ancestor defined in terms of the
     synteny blocks.

 An integer copy number threshold.

 An integer segment length parameter L.

 An integer window length paramter l, with l <= L.

 An output directory.

Detailed explanation:
1. The tree must be in NHX format, with clearly labelled extant species. Branch
   lengths may be specified.  The ancestor must be given the name '@'.

2. The gene families must be specified in the inferCARs format, which is as
   follows.

   `><gene_id>`

   `<species_name>.<chromosome_name>:<start_position>-<stop_position> <orientation>`

    .

    .

    Here <gene_id>,<start_position> and <stop_position>  must be integers, and
    <orientation> must be one of '+' or '-'. The rest are strings.

3. The synteny blocks must also be specified in the inferCARs format (see gene
   family format for specification.  The lengths of the blocks (i.e.
   stop_position-start_position+1) are expected to be at least as long as those
   of the genes.

4. Contiguous ancestral regions (CARs) may be specified in the PQ-tree format
   output by ANGES (Jones et al. 2012), or in the format output by MGRA
   (Aleksyev and Pevzner 2009). The CARs must be halved, i.e. each synteny block
   must be directed.

5. The copy number threshold is used to filter the gene families by excluding
   those families which have high ancestral copy numbers, as computed by
   Sankoff-Roussea parsimony (Csuros 2008).

6. Segment length
7. Window length

   Segment length and window length are parameters used by the main method to
   partition the CARs. Larger parameters cause a dramatic increase in time
   complexity for mammalian genomes, without significantly affecting the
   accuracy. The user is advised to try the method with small parameters
   relative to the length of the longest CAR.

8. Self-explanatory

## Output
The final output of MultiRes, written in the output directory, is a file named
FINAL_GENE_ORDERS. The file contains a set of CARs, with names identical to the
CAR names in the original CAR file. The CARs consist of sequences of gene family
extremities: a gene family i has tail and head extremities identified by 2*i-1
and 2*i respectively. Furthermore, each extremity is labelled by a
`localization' label. For eg.

\#CAR2

1212.0 1211.0 1208.0 1207.0 1206.0 1205.0 1204.0 1203.0 705.0 706.0 | 1202.0
1201.0 1200.0 1199.0 1198.0 1197.0 1034.0 1033.0 1196.0 1195.0 1194.0 1193.0
1192.0 1191.0 1190.0 1189.0 1188.0 1187.0 1186.0 1185.0 | .. $.

Here, 1212.0 1211.0 are extremities of the same gene family, identified by the
localization label '0'. A subsequence which is bordered by '|' on both sides is
understood to be in the correct position, but with missing adjacencies
connecting it to the two subsequences flanking it. The '$' marks the end of the
CAR.

## References

 Alekseyev, Max, and Pavel A. Pevzner. "Breakpoint graphs and ancestral
genome reconstructions." Genome research (2009): gr-082784.

 Csűrös, Miklós. "Ancestral reconstruction by asymmetric Wagner parsimony
over continuous characters and squared parsimony over distributions."
Comparative Genomics. Springer Berlin Heidelberg, 2008. 72-86.

 Jones, Bradley R., et al. "ANGES: reconstructing ANcestral GEnomeS maps."
Bioinformatics 28.18 (2012): 2388-2390.

 Maňuch, Ján, et al. "Linearization of ancestral multichromosomal genomes."
BMC bioinformatics 13.Suppl 19 (2012): S11.

repository: ma-compbio/MultiRes

repo_name: ma-compbio/MultiRes


text:
# unet-steamworks
Example integration of Unity's UNET HLAPI and Steamworks P2P networking using Steamworks.NET.

Last tested with Unity 2017.2.0p2 on 26 November 2017

Read more here: http://spacewavesoftware.com/blog/2017/10/28/unity-unet-hlapi-and-steam-p2p-networking

repository: Saarg/unet-steamworks

repo_name: Saarg/unet-steamworks


text:
---
layout: post
title: hot changing disk in mdadm raid array
---

to hot change a disk in an mdadm array, the disk to remove is sdb, the disk to add is sdc:

HAVE A BACKUP OF YOUR DATA
really,
backup your data

Verify the configuration of the array:

    #cat /proc/mdstat

Clone the partition table on the news disk:
using sgdisk (install gdisk if you don't have it) backup the partition table of the source disk:

    sgdisk -b part.table /dev/sdb

the restore it on the destination disk, the -G switch is to generate new GUIDS for the partition since sgdisk also clones the GUIDS:

    sgdisk -l part.table -G /dev/sdc

verify that the partitions are ok.

Modify the RAID array:

remove the "old" disk:

    mdadm --manage /dev/md0 --fail /dev/sdb1
    mdadm --manage /dev/md0 --remove /dev/sdb1

add the "new" disk to the array:

    mdadm --manage /dev/md0 --add /dev/sdc1

Monitor the rebuild of the array:

    #cat /proc/mdstat
    [CUT]
    [==>..................]  recovery = 14% (nnnn/nnnnnnnn) finish=50.6min speed=57001K/sec
    [CUT]

Wait for the rebuild.
Patiently.


text:
## libTinyLogger

### Small Yet Flexible Logger In C.

This is a small logging library for small Linux projects. It logs messages from
a single process to a file and/or a stream such as stderr. It has many message
formats, including JSON and XML.

Thread safe. There are message formats with thread id and/or thread name
provided.

Custom message formats may be created without modifying the library. A timestamp
formatter with second, millisecond, microsecond and nanosecond resolution is
provided.

It may be compiled directly with a target program, or installed as a shared
library.

### Features:

- Output may be directed to a stream or a file.
- Messages are filtered by a log level.
- It produces output in a few different formats.
  - Pre-defined formats for systemd, standard and debug use.
  - Elapsed time can be used in place of date/time
  - Structured output in XML and JSON
  - User defined formatters are possible.
- thread safe, with formats that print thread id and name
- logrotate support. Flushes, closes, and re-opens a log file on receipt of a
  signal from logrotate.
- tested on 64 and 32 bit Linux
  - RHEL 8.1 4.18.0-193.1.2.el8_2.x86_64
  - Raspian Buster 4.19.97-v7l+

## Table of contents
1. [Getting Started](#getting_started)
2. [Examples](#examples)
   - [Hello world](#hello-world)
   - [Two streams](#two-streams)
3. [Output formats](#output-formats)
   - [basic](#log_fmt_basic)
   - [systemd](#log_fmt_systemd)
   - [standard](#log_fmt_standard)
   - [debug](#log_fmt_debug)
   - [debug_tid](#log_fmt_debug_tid)
   - [debug_tname](#log_fmt_debug_tname)
   - [debug_tall](#log_fmt_debug_tall)
   - [elapsed_time](#log_fmt_elapsed_time) (Elapsed time from channel
        initialization. Starting time may be reset).
   - [XML](#log_fmt_xml) (Structured format).
   - [JSON](#log_fmt_json) (Structured format).
4. [Memory dumps](#memory-dumps) Memory dumps may be used with any format.
5. [Other samples](#other-samples)
   - [Two stream output](#two-stream-output)
   - [Thread ID and name](#thread-id-name)
6. Additional Information
   - A [guide](guide/guide.md) (markdown in the guide subdirectory)

## Getting started
### Quick Start
There is a directory set up with a minimum build environment called
quick-start.
```
$ cd quick-start
$ ./setup.sh
$ make
```
This builds a static library called libtinylogger.a which can be linked to your
project. It also builds the examples, which demonstrate different features of
the library. Additional info in [quick-start](guide/quick-start.md).

### Installation as a library is optional
This is an Autotools package. For installation into /usr/local/lib,
installation is very easy. To see what get installed and where, install it in
"alternate root" by specifying DESTDIR when installing:
```
$ autoreconf -i
$ ./configure
$ make
$ DESTDIR=/tmp/destdir make install
```
libtinylogger static and dynamic libraries will be installed in $DESTDIR/usr/local/lib
and the header file will be installed into $DESTDIR/usr/local/include.

To actually install,
```
$ sudo make install
```
If you have doxygen, man pages can be made and installed into /usr/local/man.

## Examples
### The obligatory minimal program would be:

Source code: [hello_world.c](demo/hello_world.c)

~~~{.c}
    #include "tinylogger.h"

    int main(void) {
        log_info("hello, %s\n", "world");
    }
~~~

The output to stderr would be:

    2020-05-30 18:59:49.014 INFO    hello, world

### Output to two streams simultaneously

Source code: [second.c](demo/second.c)

-- The first stream is to stderr in systemd compatible format. It passes messages
of INFO and above.

-- The second stream logs to a file in debug format. It passes messages of TRACE
and above.

~~~{.c}
#include "tinylogger.h"

#define DEBUG_PATHNAME "/tmp/second.log"
int main(void) {
	/*
	 * Change main stderr format to systemd and add output to a file.
	 * Set a second file output stream to DEBUG_PATHNAME.
	 *  set log level to FINE
	 *  set format to debug
	 *  turn line buffering on (useful with tail -f, for example)
	 */
	LOG_CHANNEL *ch1 = log_open_channel_s(stderr, LL_INFO, log_fmt_systemd);
	LOG_CHANNEL *ch2 = log_open_channel_f(DEBUG_PATHNAME, LL_FINE, log_fmt_debug, true);
	log_notice("this message will be printed to both");
	log_info("this message will be printed to both");
	log_debug("this message will be printed to file only");
	log_finer("this message will not be printed at all");
	log_close_channel(ch1);
	log_close_channel(ch2);

	return 0;
}
~~~

The output to stderr for systemd would be:

~~~~~
    <5>this message will be printed to both
    <6>this message will be printed to both
~~~~~

The output to /tmp/second.log would be:

~~~
    2020-05-30 19:22:11.541 NOTICE  second.c:main:14 this message will be printed to both
    2020-05-30 19:22:11.541 INFO    second.c:main:15 this message will be printed to both
    2020-05-30 19:22:11.541 DEBUG   second.c:main:16 this message will be printed to file only
~~~

## Pre-configured output formats available

### basic
Output messages with just the user message.

```
eth0     AF_PACKET (17)
```

### systemd
Output messages in systemd compatible format. Systemd log messages have their
log level enclosed in angle brackets prepended to the user message. When viewed
through journalctl, timestamps are added, so only the log level and user message
are needed.

```
<7>eth0     AF_PACKET (17)
```

### standard
Output messages with timestamp, level and message.

```
2020-05-25 16:55:18.821 DEBUG   eth0     AF_PACKET (17)
```

### debug
Output messages with timestamp, level, source code file, function, and line
number, and finally the message.

```
2020-05-25 17:28:17.011 INFO   test-logger.c:main:110 eth0     AF_PACKET (17)
```

### debug_tid
log_fmt_debug with thread id added
```
2020-05-25 17:28:17.011 INFO   65623 test-logger.c:main:110 eth0     AF_PACKET (17)
```

### debug_tname
log_fmt_debug with thread name added
```
2020-05-25 17:28:17.011 INFO   thread_2 test-logger.c:main:110 eth0     AF_PACKET (17)
```

### debug_tall
log_fmt_debug with thread id and thread name added
```
2020-05-25 17:28:17.011 INFO   65623:thread_2 test-logger.c:main:110 eth0     AF_PACKET (17)
```

### elapsed_time
log_fmt_debug with elapsed time timestamp
```
0.000001665 INFO    formats.c:main:172 this message has elapsed time
0.000010344 INFO    formats.c:main:173 this message has elapsed time
0.000018740 INFO    formats.c:main:174 this message has elapsed time
```

### XML
Output messages in java.util.logging.XMLFormatter format.

```
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
<record>
  <date>2020-08-15T23:10:49.081-04:00</date>
  <millis>1597547449081</millis>
  <nanos>969853</nanos>
  <sequence>1</sequence>
  <logger>tinylogger</logger>
  <level>INFO</level>
  <class>xml.c</class>
  <method>main</method>
  <thread>389042</thread>
  <message>Special chars are escaped in the "<xml>" format. & it's msg #0.</message>
</record>
<record>
  <date>2020-08-15T23:10:49.082-04:00</date>
  <millis>1597547449082</millis>
  <nanos>112552</nanos>
  <sequence>2</sequence>
  <logger>tinylogger</logger>
  <level>INFO</level>
  <class>xml.c</class>
  <method>main</method>
  <thread>389042</thread>
  <message>Special chars are escaped in the "<xml>" format. & it's msg #1.</message>
</record>
</log>
```
### JSON
There is a companion [reader](https://github.com/ehetherington/JSON-LogReader)
for files produced in the JSON format.

Olson timezones may be enabled at compile time. The timestamps would then be:
```
    "isoDateTime" : "2020-10-23T13:00:35.509343545-04:00[America/New_York]",
```
See [guide/json-formatter.md](guide/json-formatter.md) for more information
and how to enable this feature.

Output message in json format.

```
{
  "records" : [  {
    "isoDateTime" : "2020-07-31T15:12:56.408789290-04:00",
    "timespec" : {
      "sec" :<PHONE_NUMBER>,
      "nsec" : 408789290
    },
    "sequence" : 1,
    "logger" : "tinylogger",
    "level" : "INFO",
    "file" : "json-hello.c",
    "function" : "main",
    "line" : 32,
    "threadId" : 164933,
    "threadName" : "json-hello",
    "message" : "hello world (msg 0)"
  },  {
    "isoDateTime" : "2020-07-31T15:12:56.408893063-04:00",
    "timespec" : {
      "sec" :<PHONE_NUMBER>,
      "nsec" : 408893063
    },
    "sequence" : 2,
    "logger" : "tinylogger",
    "level" : "INFO",
    "file" : "json-hello.c",
    "function" : "main",
    "line" : 32,
    "threadId" : 164933,
    "threadName" : "json-hello",
    "message" : "hello world (msg 1)"
  } ]
}
```

## Memory dumps
Regions of memory can be formatted to hex + ascii and appended to the user
message in all the above formats.

Instead of using log_info(...) and friends, log_memory(...) is available.

With a channel set up with the debug format,
```
log_memory(LL_INFO, buf, sizeof(buf), "hello, %s", "world");
```
produces:
```
2020-08-17 21:08:38.418 INFO    log_mem.c:main:55 hello, world
  0000  00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f  ................
  0016  10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f  ................
  0032  20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f   !"#$%&'()*+,-./
  0048  30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f<PHONE_NUMBER>:;<=>?
  0064  40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f  @ABCDEFGHIJKLMNO
  0080  50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f  PQRSTUVWXYZ[\]^_
  0096  60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f  `abcdefghijklmno
  0112  70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f  pqrstuvwxyz{|}~.
  0128  80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f  ................
  0144  90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f  ................
  0160  a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af  ................
  0176  b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf  ................
  0192  c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf  ................
  0208  d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df  ................
  0224  e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef  ................
  0240  f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff  ................
  0256  00 01 02 03 04 05 06 07                          .
```
The memory dump is appended to the normal user message, so the whole thing is
enclosed in a single message in XML or JSON formats.

With a channel set up with the JSON format, logging a 24 byte slice (for
brevity) of that memory region,
```
log_memory(LL_INFO, buf + 0x20, 24, "hello, %s", "world");
```
produces:
```
{
  "records" : [  {
    "isoDateTime" : "2020-08-17T21:08:38.418348026-04:00",
    "timespec" : {
      "sec" :<PHONE_NUMBER>,
      "nsec" : 418348026
    },
    "sequence" : 1,
    "logger" : "tinylogger",
    "level" : "INFO",
    "file" : "log_mem.c",
    "function" : "main",
    "line" : 61,
    "threadId" : 502942,
    "threadName" : "log_mem",
    "message" : "hello, world\n  0000  20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f   !\"#$%&'()*+,-./\n  0016  30 31 32 33 34 35 36 37                          01234567        "
  } ]
}
```

The hex dump samples were produced by a demo program called log_mem.c

## Other Samples
### Messages simultaneously logged by systemd/journalctl and to debug file

Note different formatting and extra "debug" level message due to different log level
filtering.

-- Output in systemd compatible format to stderr, logged by systemd and viewed by journalctl

```
    May 29 08:39:31 raspberrypi wol-broadcaster[519]: pkt from obscured-for-safety dot com (<IP_ADDRESS>:37329) was not a magic packet
    May 29 08:39:31 raspberrypi wol-broadcaster[519]: packet contents:
    May 29 08:39:31 raspberrypi wol-broadcaster[519]:   0000  47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a  GET / HTTP/1.1..
    May 29 08:39:31 raspberrypi wol-broadcaster[519]:   0010  48 6f 73 74 3a 20 77 77 77 0d 0a 0d 0a           Host: www....
```

-- The same messages logged to a debug file using standard output format. The
DEBUG message appears because this stream uses a different log level.

```
    2020-05-29 08:39:31.285 DEBUG   received pkt from obscured-for-safety dot com (<IP_ADDRESS>:37329)
    2020-05-29 08:39:31.285 INFO    pkt from obscured-for-safety dot com (<IP_ADDRESS>:37329) was not a magic packet
    2020-05-29 08:39:31.285 INFO    packet contents:
    2020-05-29 08:39:31.286 INFO      0000  47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a  GET / HTTP/1.1..
    2020-05-29 08:39:31.286 INFO      0010  48 6f 73 74 3a 20 77 77 77 0d 0a 0d 0a           Host: www....
```

### Message with thread id and thread name
This is the Linux thread id, not the pthread_id.
```
2020-05-25 17:28:17.011 DEBUG   65623:thread_2 test-logger.c:main:110 eth0     AF_PACKET (17)
```
The linux thread id is used rather than the posix thread id. It can be accessed, for instance, by:
```
$ ps H -C example-program -o 'pid tid cmd comm'
```
Examples with multiple threads and message formats that display thread id are:
[threads.c](demo/threads.c) and [beehive.c](demo/beehive.c).

repository: ehetherington/libtinylogger

repo_name: ehetherington/libtinylogger


text:
Bedrock Wiki

The Bedrock Wiki is a knowledge-sharing website for Technical Bedrock, containing documentation, tutorials, and general how-to information.
Here, you can contribute to this amazing, open-source resource!

Visit the website!             Join the discord!

# Contributing

## Discord

Please join the [discord](https://discord.gg/XjV87YN), which is where all wiki-communication takes place. While small changes and new articles do not need permission, large-scale changes should go through community review.

## Using GitHub

It is beyond the scope of this readme to teach the proper use of Git and GitHub, but you can always reach out personally for help. Some steps to get you started though (google steps if unsure):
 - `make github account`
 - `fork the repository`
 - `make changes, commit changes, push changes`
 - `create pull requests`

## Commits and Pulls

Please provide proper commit messages when contributing, this will make it much easier to approve pull requests. Don't change anything in the config unless you really need to.

## Contributing without GitHub

Want to submit an article, but can't be bothered to learn Git, or GitHub? You can send me markdown articles directly, and I will add them manually.

## Running Locally
You can locally test the website by [installing Jekyll](https://jekyllrb.com/docs/installation/#guides) and then running  `bundle install` and `bundle exec jekyll serve`.

Assuming the Ruby dependencies installed correctly, the local server will run and you should see `http://<IP_ADDRESS>:4000`
printed out.

You can now make changes to any of the markdown files and you'll see the changes reflected at that URL in your browser! Note the site can take several seconds to rebuild, so have an eye on your terminal window

# Formatting tools

Various formatting options (such as buttons and labels) come from out up-line theme: [just the docs](https://pmarsceill.github.io/just-the-docs/). Go there to learn about these tools.

## Codeblock Filepaths

You can annotate your code-blocks with filepath information, using the following format:

```
{% include filepath.html path="RP/textures/item_texture.json" %}
```jsonc
{
	"resource_pack_name": "tut",
	"texture_name": "atlas.items",
	"texture_data": {
		"meal": {
			"textures": "textures/items/meal"
		},
		"gem": {
			"textures": "textures/items/gem"
		}
	}
}
\```
```

You can also add a local path:

`{% include filepath.html path="example.json" local_path="minecraft:entity/description%}`

## File Tree Viewer

There is a number of CSS classes, which help build the directory structure.

Example:
```html
<div markdown="0" class="folder-structure">
    <ul>
        <li><span class="folder">BP</span>
            <ul>
                <li><span class="folder">items</span>
                    <ul>
                        <li><span class="file">gem.item.json</span></li>
                        <li><span class="file">meal.item.json</span></li>
                    </ul>
                </li>
            </ul>
        </li>
        <li><span class="folder">RP</span>
            <ul>
                <li><span class="folder">items</span>
                    <ul>
                        <li><span class="file">gem.item.json</span></li>
                        <li><span class="file">meal.item.json</span></li>
                    </ul>
                </li>
                <li><span class="folder">texts</span>
                    <ul>
                        <li><span class="file">en_US.lang</span></li>
                    </ul>
                </li>
                <li><span class="folder">textures</span>
                    <ul>
                        <li><span class="file">item_texture.json</span></li>
                        <li><span class="folder">items</span>
                            <ul>
                                <li><span class="image">gem.png</span></li>
                                <li><span class="image">meal.png</span></li>
                            </ul>
                        </li>
                    </ul>
                </li>
            </ul>
        </li>
    </ul>
</div>
```

Result:

BP

items

gem.item.json

meal.item.json

RP

items

gem.item.json

meal.item.json

texts

en_US.lang

textures

item_texture.json

items

gem.png

meal.png

## CSS classes

### folder-structure

Changes unordered list style, so it resembles directory tree.

### folder

Adds folder emoji before element.

### file

Adds text file emoji before element.

### image

Adds image emoji before element.

## Structure generator

There is also automatic structure generator at [https://stirante.com/dir-converter/converter.html](https://stirante.com/dir-converter/converter.html).

The text area on the left accepts a list of paths delimited by new line. After clicking the convert button, the HTML should be generated in text area on the right side.

To generate the output in the first example, use this input:
```
RP/texts/en_US.lang
RP/textures/item_texture.json
RP/items/meal.item.json
BP/items/meal.item.json
BP/items/gem.item.json
RP/items/gem.item.json
RP/textures/items/gem.png
RP/textures/items/meal.png
```

### File links

To link file inside directory structure to an element, add `#<id>` after file path like this:

```
RP/texts/en_US.lang
RP/textures/item_texture.json
RP/items/meal.item.json#rp_meal_item
BP/items/meal.item.json#bp_meal_item
BP/items/gem.item.json#bp_gem_item
RP/items/gem.item.json#rp_gem_item
RP/textures/items/gem.png
RP/textures/items/meal.png
```

This will result in this output:
```html
<div markdown="0" class="folder-structure">
    <ul>
        <li><span class="folder">BP</span>
            <ul>
                <li><span class="folder">items</span>
                    <ul>
                        <li><a href="#bp_gem_item" class="file">gem.item.json</>
                        </li>
                        <li><a href="#bp_meal_item" class="file">meal.item.json</>
                        </li>
                    </ul>
                </li>
            </ul>
        </li>
        <li><span class="folder">RP</span>
            <ul>
                <li><span class="folder">items</span>
                    <ul>
                        <li><a href="#rp_gem_item" class="file">gem.item.json</>
                        </li>
                        <li><a href="#rp_meal_item" class="file">meal.item.json</>
                        </li>
                    </ul>
                </li>
                <li><span class="folder">texts</span>
                    <ul>
                        <li><span class="file">en_US.lang</>
                        </li>
                    </ul>
                </li>
                <li><span class="folder">textures</span>
                    <ul>
                        <li><span class="file">item_texture.json</>
                        </li>
                        <li><span class="folder">items</span>
                            <ul>
                                <li><span class="image">gem.png</>
                                </li>
                                <li><span class="image">meal.png</>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
            </ul>
        </li>
    </ul>
</div>
```

# Icons

Icons made by Freepik from www.flaticon.com

# Using Panels

There are three kinds: Info, Warning, and Error

Use like this:

```
{% include warning.html
  contents='Animation Controllers "reset" when an entity reloads (player join/leave, chunk reload, etc). This means that it will "jump" back to the default state. You should always have logic in your default state that can handle restarting any critical animations.'
%}
```

Or like this:
```

```

  Remember! Render controllers work based on short-names. If you want to use the cow render controller, you need to provide the short-names it is using. In this case, you will need to provide:

    - `default` geometry

    - `default` texture

    - `default` material

```

repository: SmokeyStack/bedrock-wiki

branch_name: refs/heads/gh-pages

repo_name: SmokeyStack/bedrock-wiki


text:
## 5 - Clear loop

In the previous tutorials we created stuff that rendered a sprite and changed the color on things. In this tutorial, we will clear the screen to a black color.

To clear the screen, we should set the color of the border and the main screen to a given color, like black, and then we must clear the characters on the screen. This can be done by setting them to the character SPACE.

To do this, first we put the index for black into the accumulator, and store this into the border and the main screen.
````
    processor   6502
org    $1000

        lda #$00
sta $d020
sta $d021
````

Next we copy the value in the accumulator into the x-register.

````
tax
````

Then we put the value of `#$20` in to the accumulator. `#$20` is the value of the SPACE character.
````
lda #$20
````

Now we are ready to put the value inserted in the accumulator into every character on the screen memory. This will be done by creating a loop that goes through the entire screen memory. The screen memory is located at `$0400` and ends at `$07FF`.

Linus Åkerlund of Fairlight shared a smart way of looping through the screen memory. Before the loop starts, x contains the value 0. If we decrement it, it will become `FF` (`255`), and then go all the way down to 0 again, setting all the characters to space in the range `0400-04FF`, `0500-05FF`, `0600-06FF` and `0700` to `07FF`.
````
loop:   sta $0400,x
sta $0500,x
sta $0600,x
sta $0700,x
dex
bne loop
````

The last instruction is new; bne will jump (branch) to loop if `X` is not zero. That means that when we start, `X` will be 0, and right before the bne operation, we will decrease it so it contains `FF`. This means that the loop will go all the way from `FF` to `00` before exiting the loop.

Listing 5.1 – Clear loop
````
    processor   6502
org    $1000

        lda #$00
sta $d020
sta $d021
tax
lda #$20
loop:   sta $0400,x
sta $0500,x
sta $0600,x
sta $0700,x
dex
bne loop
````

That’s it for clearing the screen. When the clear loop is done, you can continue doing what else you want the program to do.


text:
# Schedule shift work
This script schedules shift work by using pulp, a linear problem solver.

In order to schedule, it is necessary first to prepare an Excel file or
a tab-delimited text filled out the conditions and indivisual requests.

Each shift type name must be a single character and defined as a string,
e.g. 'DNGO'(Day, Night, Graveyard, Off, etc), in Japanese '日夜明休'.

Also you may want to specify the shift patterns good and prohibitted.

# Reference
https://qiita.com/SaitoTsutomu/items/a33aba1a95828eb6bd3f
https://qiita.com/SaitoTsutomu/items/e79ad9ca61a82d5482fa


text:
# _Pig-Dice_

#### _This application was built to allow the user to play a dice game called Pig-Dice. The application allows the player to either play a one-player or two-player mode. November 7th 2019_

#### By _Calvin Will & Diego Rojas_

## Description

_This application allows one or two players to play the game pig dice. In the game, the user can click a button to roll dice and then decide if they want to keep rolling, or add the points they scored to their total points. The goal of each player is to score 100 points before their opponent._

| Behavior our program should handle  | Input   | Output  |
|---|---|---|
| Input Names  | "John"  | "john"  |
| Switch between game modes | Click player mode | player v. player or player v. AI |
|  Click buttons | button click  | dice function to calculate roll  |
| Add dice roll to current turn | dice number | accumulative dice roll total |
| Add turn score to player score | click pass button | player score + turn score |
| Switch between player turn and AI turn | click pass button | AI takes its turn |
| Pass button  | pass click | game will toggle between players |
|  AI attempts to win using strategy | AI turn | AI rolls dice in an attempt to win game |

## Setup/Installation Requirements

* _Clone from github_
* _Open in a web browser_

## Known Bugs

_Currently there are no known bugs._

## Support and contact details

_If you have any questions, comments, or concerns, email the creators at<EMAIL_ADDRESS>or<EMAIL_ADDRESS>
## Technologies Used

* _HTML_
* _CSS_
* _JavaScript_
* _Bootstrap_
* _JQuery_

### License

*This work is licensed under MIT*

Copyright (c) 2019 **_Calvin Will and Diego Rojas_**

gha_language: JavaScript


text:
STC - C99 Standard Container library
====================================

Introduction
------------

An elegant, fully typesafe, generic, customizable, user-friendly, consistent, and very fast standard container library for C99. This is a small headers only library with the most used container components, and a few algorithms:
- **stc/carray.h** - Dynamic generic **multi-dimensional array**, implemented as a single contiguous section of memory.
- **stc/cbitset.h** - Bitset similar to c++ std::bitset or boost::dynamic_bitset.
- **stc/clist.h** - A genric circular **singly linked list**. Can be used as a **queue** as it supports *push_back(), push_front(), and pop_front()*. It also contains various *splice* functions and *merge sort*.
- **stc/cmap.h** - A generic **unordered map / set** implemented as open hashing without tombstones. Highly customizable and fast.
- **stc/cstr.h** - Compact and powerful **string** class.
- **stc/cvec.h** - Dynamic generic **vector** class, works well as a **stack**.
- **stc/cstack.h** - **stack** adapter, currently works with *cvec*.
- **stc/cqueue.h** - **queue** adapter, currently works with *clist*.
- **stc/cpqueue.h** - **priority queue** adapter. Works with *cvec*.
- **stc/cptr.h** - Support for pointers in containers, and a reference counted shared pointer **csptr**.
- **stc/coption.h** - Implementation of a **getopt_long()**-like function, *coption_get()*, to parse command line arguments.
- **stc/crandom.h** - A few very efficent modern random number generators *pcg32* and my own *64-bit PRNG* inspired by *sfc64*. Both uniform and normal distributions.
- **stc/cfmt.h** - Implementation of **c_print()** with c++20 *std::format*-like formatting, including automatic detection of argument types.
- **stc/ccommon.h** - A common include file with a few general definitions.

The usage of the containers is quite similar to the C++ standard containers, so it should be easy if you are familiar with them.

All containers mentioned above, except cstr_t and cbitset_t, are generic and therefore typesafe (similar to templates in C++). No casting is used. A simple example:
```C
#include <stc/cvec.h>
#include <stc/cfmt.h>

using_cvec(i, int);

int main(void) {
    cvec_i vec = cvec_i_init();
    cvec_i_push_back(&vec, 1);
    cvec_i_push_back(&vec, 2);

    c_foreach (i, cvec_i, vec)
        c_print(1, " {}", *i.val);
    cvec_i_del(&vec);
}
```
Using containers with complex element types is simple:
```C
#include <stc/cstr.h>
#include <stc/cvec.h>

typedef struct {
    cstr_t name; // dynamic string
    int id;
} User;

void User_del(User* u)
    { cstr_del(&u->name); }
int User_compare(User* u, User* v)
    { int c = strcmp(u->name.str, v->name.str); return c != 0 ? c : u->id - v->id; }

using_cvec(u, User, User_del, User_compare);

int main(void) {
    cvec_u vec = cvec_u_init();
    cvec_u_push_back(&vec, (User) {cstr_from("admin"), 0}); // cstr_from() allocates string memory
    cvec_u_push_back(&vec, (User) {cstr_from("usera"), 1});
    c_foreach (i, cvec_u, vec)
        c_print(1, "{}: {}\n", i.val->name.str, i.val->id);
    cvec_u_del(&vec); // free everything
}
```
Motivation
----------

The aim of this project was to create a small **Standard Container Library for the C99 language**. It should
- be easy to use, have intuitive naming and consistency across the library.
- be type safe. Have minimal usage of casting and void* pointers.
- be highly efficient. Both in speed and memory usage.
- be customizable without losing efficiency. E.g. inline replacable compare, hash, allocation functions per container type instantiation.
- have a fairly small code base, and easy to install, deploy and maintain.
- avoid bloat. It should not try to cover all thinkable functions, but limit itself to the most useful and commonly used.

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

Because it is headers only, files can simply be included in your program. The functions will be inlined by default. You may add the project folder to CPATH environment variable, to let gcc, clang, and tinyc locate the headers.

If containers are extensively used accross many translation units with common instantiated container types, it is recommended to build as a library, to minimize executable size. To enable this mode, specify **-DSTC_HEADER** as compiler option, and put all the instantiations of the containers used in one C file, like this:
```C
#define STC_IMPLEMENTATION
#include <stc/cstr.h>
#include <stc/cmap.h>
#include <stc/cvec.h>
#include <stc/clist.h>
#include "Vec3.h"

using_cmap(ii, int, int);
using_cset(ix, int64_t);
using_cvec(i, int);
using_clist(v3, Vec3);
...
```
Performance
-----------

The library is very efficent. Containers have templated intrusive elements. One of the most performance critical containers is the **cmap / cset**. Luckily, cmap is among the fastest C/C++ map implementations available, see **examples/benchmark.c**

Compiled with clang.exe -O3 -x c++, v10.0 on windows, Ryzen 7 2700X CPU. Similar results with VC and g++.

- **CMAP** = stc/*cmap*
- KMAP = klib/*khash*
- UMAP = *std::unordered_map*
- SMAP = *spp::sparse_hash_map*
- BMAP = *ska::bytell_hash_map*
- FMAP = *ska::flat_hash_map*
- RMAP = *robin_hood::unordered_map*
- HMAP = *tsl::hopscotch_map*
```
Random keys are in range [0, 2^24), seed =<PHONE_NUMBER>:

Unordered maps: 30000000 repeats of Insert random key + try to remove a random key:
CMAP: time:  4.35, sum:<PHONE_NUMBER>00000, size: 8153497, erased 10922466
KMAP: time:  3.37, sum:<PHONE_NUMBER>00000, size: 8153497, erased 10922466
UMAP: time: 11.19, sum:<PHONE_NUMBER>00000, size: 8153497, erased 10922466
SMAP: time: 14.21, sum:<PHONE_NUMBER>00000, size: 8153497, erased 10922466
BMAP: time:  5.00, sum:<PHONE_NUMBER>00000, size: 8153497, erased 10922466
FMAP: time:  4.68, sum:<PHONE_NUMBER>00000, size: 8153497, erased 10922466
RMAP: time:  3.16, sum:<PHONE_NUMBER>00000, size: 8153497, erased 10922466
HMAP: time:  4.49, sum:<PHONE_NUMBER>00000, size: 8153497, erased 10922466

Unordered maps: Insert 30000000 index keys, then remove them in same order:
CMAP: time:  3.27, erased 30000000
KMAP: time:  2.86, erased 30000000
UMAP: time: 15.80, erased 30000000
SMAP: time: 22.60, erased 30000000
BMAP: time:  7.93, erased 30000000
FMAP: time:  5.91, erased 30000000
RMAP: time:  3.22, erased 30000000
HMAP: time:  5.91, erased 30000000

Unordered maps: Insert 30000000 random keys, then remove them in same order:
CMAP: time:  3.16, erased 13971002
KMAP: time:  4.05, erased 13971002
UMAP: time: 10.77, erased 13971002
SMAP: time: 13.77, erased 13971002
BMAP: time:  5.27, erased 13971002
FMAP: time:  4.41, erased 13971002
RMAP: time:  3.21, erased 13971002
HMAP: time:  4.50, erased 13971002

Unordered maps: Iterate 30000000 random keys:
CMAP: time:  0.23, size: 13971002, sum<PHONE_NUMBER>191145
UMAP: time:  3.32, size: 13971002, sum<PHONE_NUMBER>191145
SMAP: time:  0.33, size: 13971002, sum<PHONE_NUMBER>191145
BMAP: time:  0.60, size: 13971002, sum<PHONE_NUMBER>191145
FMAP: time:  0.56, size: 13971002, sum<PHONE_NUMBER>191145
HMAP: time:  0.51, size: 13971002, sum<PHONE_NUMBER>191145
```
From these tests *cmap*, *robin_hood* and *khash* are almost equally fast. std::unordered_map is horrible. With random numbers in 0 - 2^20 range, khash performs worse, though:
```
Unordered maps: 30000000 repeats of Insert random key + try to remove a random key:
CMAP: time:  1.93, sum:<PHONE_NUMBER>00000, size: 524809, erased 14738434
KMAP: time:  7.28, sum:<PHONE_NUMBER>00000, size: 524809, erased 14738434

Unordered maps: Insert 30000000 random keys, then remove them in same order:
CMAP: time:  1.16, erased 1048576
KMAP: time:  2.62, erased 1048576
```
Memory efficiency
-----------------

The containers are memory efficent, i.e. they occupy as little memory as practical possible.
- **cstr**, **cvec**: Type size: one pointer. The size and capacity is stored as part of the heap allocation that also holds the vector elements.
- **clist**: Type size: one pointer. Each node allocates block storing value and next pointer.
- **cmap**: Type size: 4 pointers. cmap uses one table of keys+value, and one table of precomputed hash-value/used bucket, which occupies only one byte per bucket. The open hashing has a default max load factor of 85%, and hash table scales by 1.5x when reaching that.
- **cset**: Same as cmap, but this uses a table of keys only, not (key, value) pairs.
- **carray**: carray1, carray2 and carray3. Type size: One pointer plus one, two, or three size_t variables to store dimensions. Arrays are allocated as one contiguous block of heap memory.

cmap discussion
---------------

**cmap/cset** uses open hashing and is among the fastest hash-tables for C and C++. The default max load-factor is 0.85.

You can customize the destroy-, hash-, equals- functions, but also define a convertion from a raw/literal type to the key-type specified. This is very useful when e.g. having cstr as key, and therefore a few using-macros are pre-defined
for cmaps with cstr_t keys and/or values:

- *using_cmap_strkey(tag, valuetype)*
- *using_cmap_strval(tag, keytype)*
- *using_cmap_str()* // cstr_t -> cstr_t
- *using_cset_str()* // cstr_t set

To customize your own cmap type to work like these, you may want to look at **examples/advanced.c**. It demonstrates how to use a custom struct as a hash map key, by using the optional parameters to using_cmap().

Example usages
--------------
The examples folder contains further examples.

**cvec** of *int64_t*.
```C
#include <stc/cvec.h>
#include <stc/cfmt.h>

using_cvec(ix, int64_t); // ix is just an example type tag name.

int main() {
    cvec_ix bignums = cvec_ix_init(); // use cvec_ix_init() if initializing after declaration.
    cvec_ix_reserve(&bignums, 50);

    c_forrange (i, int, 1, 50)
        cvec_ix_push_back(&bignums, i * i * i);

    cvec_ix_pop_back(&bignums); // erase the last

    c_forrange (i, int, 1, cvec_ix_size(bignums))
        bignums.data[i] /= i; // make them smaller

    c_foreach (i, cvec_ix, bignums)
        c_print(1, " {}", *i.val);
    cvec_ix_del(&bignums);
}
// Output:
 1 8 13 21 31 43 57 73 91 111 133 157 183 211 241 273 307 343 381 421 463 507 553 601 651 703 757 813 871<PHONE_NUMBER> 1123 1191 1261 1333 1407 1483 1561 1641 1723 1807 1893 1981 2071 2163 2257 2353
```
**cvec** of *cstr_t*.
```C
#include <stc/cfmt.h>
#include <stc/cvec.h>

using_cvec_str();

int main() {
    cvec_str names = cvec_str_init();
    cvec_str_emplace_back(&names, "Mary");
    cvec_str_emplace_back(&names, "Joe");
    cstr_assign(&names.data[1], "Jake"); // replace "Joe".

    // Use push_back() rather than emplace_back() when adding a cstr_t type:
    cstr_t tmp = cstr_from_fmt("%d elements so far", cvec_str_size(names));
    cvec_str_push_back(&names, tmp); // tmp is moved to names, do not del() it.

    c_print(1, "{}\n", names.data[1].str); // Access the second element

    c_foreach (i, cvec_str, names)
        c_print(1, "item: {}\n", i.val->str);
    cvec_str_del(&names);
}
// Output:
Jake
item: Mary
item: Jake
item: 2 elements so far
```
**cstr** string example.
```C
#include <stc/cfmt.h>

int main() {
    cstr_t s1 = cstr_from("one-nine-three-seven-five");
    c_print(1, "{}.\n", s1.str);

    cstr_insert(&s1, 3, "-two");
    c_print(1, "{}.\n", s1.str);

    cstr_erase(&s1, 7, 5); // -nine
    c_print(1, "{}.\n", s1.str);

    cstr_replace(&s1, cstr_find(&s1, "seven"), 5, "four");
    c_print(stderr, "{}.\n", s1.str);

    // reassign:
    cstr_assign(&s1, "one two three four five six seven");
    cstr_append(&s1, " eight");
    printf("append: %s\n", s1.str);

    cstr_t full_path cstr_init;
    c_print(&full_path, "{}/{}.{}", "directory", "filename", "ext");
    c_print(2, "{}\n", full_path.str); // 2 = stderr

    c_del(cstr, &s1, &full_path);
}
// Output:
one-nine-three-seven-five.
one-two-nine-three-seven-five.
one-two-three-seven-five.
one-two-three-four-five.
append: one two three four five six seven eight
directory/filename.ext
```
**cmap** of *int => int*, and **cmap** of *cstr_t* => *cstr_t*
```C
#include <stdio.h>
#include <stc/cmap.h>
#include <stc/cfmt.h>

using_cmap(ii, int, int);
using_cmap_str();

int main() {
    // -- map of ints --
    cmap_ii nums = cmap_ii_init();
    cmap_ii_put(&nums, 8, 64); // similar to insert_or_assign()
    cmap_ii_emplace(&nums, 11, 121);

    c_print(1, "{}\n", cmap_ii_find(&nums, 8)->second);
    cmap_ii_del(&nums);

    // -- map of str --
    cmap_str strings = cmap_str_init();
    cmap_str_emplace(&strings, "Make", "my");
    cmap_str_emplace(&strings, "Rainy", "day");
    cmap_str_emplace(&strings, "Sunny", "afternoon");
    c_push_items(&strings, cmap_str, { {"Eleven", "XI"}, {"Six", "VI"} });

    c_print(1, "size = {}\n", cmap_str_size(strings));
    c_foreach (i, cmap_str, strings)
        c_print(1, "{}: {}\n", i.val->first.str, i.val->second.str);
    cmap_str_del(&strings); // frees all strings and map.
}
// Output:
64
size = 5
Rainy: day
Sunny: afternoon
Six: VI
Make: my
Eleven: XI
```
**cset** of *cstr*.
```C
#include <stc/cfmt.h>
#include <stc/cmap.h>

using_cset_str(); // cstr set. See the discussion above.

int main() {
    cset_str words = cset_str_init();
    cset_str_insert(&words, "Hello");
    cset_str_insert(&words, "Sad");
    cset_str_insert(&words, "World");

    cset_str_erase(&words, "Sad");

    // iterate the set of cstr_t values:
    c_foreach (i, cset_str, words)
        c_print(1, "{} ", i.val->str);
    cset_str_del(&words);
}
// Output:
Hello World
```
**clist** of *int64_t*. Similar to c++ *std::forward_list*, but can do both *push_front()* and *push_back()* as well as *pop_front()*.
```C
#include <stdio.h>
#include <stc/cfmt.h>
#include <stc/clist.h>

using_clist(fx, double);

int main() {
    clist_fx list = clist_fx_init();
    c_push_items(&list, clist_fx, {
        10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0
    });
    // interleave push_front / push_back:
    c_forrange (i, int, 1, 10) {
        if (i & 1) clist_fx_push_front(&list, (float) i);
        else       clist_fx_push_back(&list, (float) i);
    }

    printf("initial: ");
    c_foreach (i, clist_fx, list)
        c_print(1, " {:.16}", *i.val);

    clist_fx_sort(&list); // mergesort O(n*log n)

    printf("\nsorted: ");
    c_foreach (i, clist_fx, list)
        c_print(1, " {:10f}", *i.val);

    clist_fx_del(&list);
}
// Output:
initial:  9 7 5 3 1 10 20 30 40 50 60 70 80 90 2 4 6 8
sorted:  1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90
```
**cpqueue** priority queue demo:
```C
#include <stdio.h>
#include <stc/cfmt.h>
#include <stc/cpqueue.h>
#include <stc/crandom.h>

using_cvec(i, int64_t);
using_cpqueue(i, cvec_i, >); // adaptor type, '>' = min-heap

int main()
{
    size_t N = 10000000;
    crand_rng64_t rng = crand_rng64_init(1234);
    crand_uniform_i64_t dist = crand_uniform_i64_init(0, N * 10);

    cpqueue_i heap = cpqueue_i_init();
    // Push ten million random numbers to priority queue, plus some negative ones.
    c_forrange (N)
        cpqueue_i_push(&heap, crand_uniform_i64(&rng, &dist));
    c_push_items(&heap, cpqueue_i, {-231, -32, -873, -4, -343});

    // Extract and disply the fifty smallest.
    c_forrange (50) {
        c_print(1, "{} ", *cpqueue_i_top(&heap));
        cpqueue_i_pop(&heap);
    }
    cpqueue_i_del(&heap);
}
// Output:
 -873 -343 -231 -32 -4 3 5 6 18 23 31 54 68 87 99 105 107 125 128 147 150 155 167 178 181 188 213 216 272 284 287 302 306 311 313 326 329 331 344 348 363 367 374 385 396 399 401 407 412 477
```
**cqueue** adapter container. Uses singly linked list as representation.
```C
#include <stc/cqueue.h>
#include <stc/cfmt.h>
#include <stdio.h>

using_clist(i, int);
using_cqueue(i, clist_i);

int main() {
    cqueue_i queue = cqueue_i_init();

    // push() and pop() a few.
    c_forrange (i, 20)
        cqueue_i_push(&queue, i);

    c_forrange (5)
        cqueue_i_pop(&queue);

    c_foreach (i, cqueue_i, queue)
        c_print(1, " {}", *i.val);

    cqueue_i_del(&queue);
}
// Output:
 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
```
**carray**. 1d, 2d and 3d arrays, allocated from heap in one memory block. *carray3* may have sub-array "views" of *carray2* and *carray1* etc., as shown in the following example:
```C
#include <stdio.h>
#include <stc/carray.h>
#include <stc/cfmt.h>

using_carray(f, float);

int main()
{
    carray3f a3 = carray3f_init(30, 20, 10, 0.0f);  // define a3[30][20][10], init with 0.0f.
    *carray3f_at(&a3, 5, 4, 3) = 3.14f;         // a3[5][4][3] = 3.14

    carray1f a1 = carray3f_at2(&a3, 5, 4);      // sub-array a3[5][4] (no data copy).
    carray2f a2 = carray3f_at1(&a3, 5);         // sub-array a3[5]

    c_print(stdout, "{}\n", *carray1f_at(&a1, 3));       // a1[3] (3.14f)
    c_print(stdout, "{}\n", *carray2f_at(&a2, 4, 3));    // a2[4][3] (3.14f)
    c_print(stdout, "{}\n", *carray3f_at(&a3, 5, 4, 3)); // a3[5][4][3] (3.14f)
    // ...
    carray1f_del(&a1); // does nothing, since it is a sub-array.
    carray2f_del(&a2); // same.
    carray3f_del(&a3); // free array, and invalidates a1, a2.
}
// Output:
3.140000
3.140000
3.140000
```
Finally, a demo of **cmap**, **cvec**, **cstr** and **random**: Normal distribution with a random mean and standard deviation, which may produce this:
```
  55 *
  56 **
  57 ****
  58 ******
  59 *********
  60 **************
  61 ********************
  62 ***************************
  63 ************************************
  64 ********************************************
  65 *****************************************************
  66 *************************************************************
  67 ********************************************************************
  68 ************************************************************************
  69 *************************************************************************
  70 ************************************************************************
  71 *******************************************************************
  72 *************************************************************
  73 *****************************************************
  74 ********************************************
  75 ***********************************
  76 ***************************
  77 ********************
  78 **************
  79 **********
  80 ******
  81 ****
  82 **
  83 *
Normal distribution with mean=69, stddev=5. '*' = 10811 samples out of 10000000.
```
Code:
```C
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stc/cmap.h>
#include <stc/cvec.h>
#include <stc/cfmt.h>
#include <stc/crandom.h>

using_cmap(ii, int, int);

static int compare(cmap_ii_value_t *a, cmap_ii_value_t *b)
{
    return c_default_compare(&a->first, &b->first);
}
using_cvec(mi, cmap_ii_value_t, c_default_del, compare);

cvec_mi make_normal_dist(crand_rng64_t* rng, crand_normal_f64_t* dist, int n);
void display_hist(cvec_mi hist, int scale, int mean, int stddev);

int main(int argc, char* argv[])
{
    // Seed with a real random value, if available
    crand_rng64_t rng = crand_rng64_init(time(NULL));

    // Choose random mean and standard deviation
    crand_uniform_i64_t mean_dist = crand_uniform_i64_init(-99, 99),
                        sdev_dist = crand_uniform_i64_init(5, 12);

    int mean = (int) crand_uniform_i64(&rng, &mean_dist);
    int stddev = (int) crand_uniform_i64(&rng, &sdev_dist);

    // Setup a normal distribution:
    crand_normal_f64_t norm_dist = crand_normal_f64_init(mean, stddev);

    int samples = 10000000, scale = 74;
    cvec_mi hist = make_normal_dist(&rng, &norm_dist, samples);
    display_hist(hist, scale, mean, stddev);

    cvec_mi_del(&hist);
}

cvec_mi make_normal_dist(crand_rng64_t* rng, crand_normal_f64_t* dist, int n)
{
    cmap_ii mhist = cmap_ii_init();
    c_forrange (n) {
        cmap_ii_emplace(&mhist, (int) round(crand_normal_f64(rng, dist)), 0).first->second += 1;
    }

    // Transfer cmap entries to a cvec, sort and return it.
    cvec_mi hist = cvec_mi_init();
    c_foreach (i, cmap_ii, mhist) {
        cvec_mi_push_back(&hist, *i.val);
    }
    cvec_mi_sort(&hist);
    cmap_ii_del(&mhist);
    return hist;
}

void display_hist(cvec_mi hist, int scale, int mean, int stddev)
{
    cstr_t bar = cstr_init();
    int n = 0; // samples
    c_foreach (i, cvec_mi, hist)
        n += i.val->second;
    c_foreach (i, cvec_mi, hist) {
        int k = (int) (i.val->second * stddev * scale * 25ull / 10 / n);
        if (k > 0) {
            cstr_take(&bar, cstr_with_size(k, '*'));
            c_print(1, "{:4} {}\n", i.val->first, bar.str);
        }
    }
    c_print(1, "Normal distribution with mean={}, stddev={}. '*' = {:.0f} samples out of {}.\n",
           mean, stddev, n / (2.5 * stddev * scale), n);
    cstr_del(&bar);
}
```


text:
test-db-sharding
================
This is a test project for database sharding based on Postgres, it has the following properties:
 - Shards can be spread across database and schema, each schema is a shard and a database can contain multiple schemas.
 - Every shard is assigned with an Id (shardId), internally shardId is mapped to host+database+schema
 - Shards can be added dynamically at runtime, schema must be initialized prior to addition
 - Every model object contains a shardId, which determines its placement in database system, this is not needed by the sharding system, however required by correlation in other places
 - A context (ThreadLocal) containing the current shardId must be setup prior to any database operations
 - Internally, a special datasource containing concrete datasources is used to provide routing behavior
 - The real datasource is determined when a transaction is started, and no more switch will happen during the transaction. This goes unfortunately for both operations across shema and database. This is fundamentally a limitation of Spring JTA implementation. To overcome this, additional design will be required at service layer.
 - Adequete checks have be built in, in order to avoid objects with wrong shardId being stored in wrong shard
 - Specific to Hibernate, a default shard must be setup in one of the databases (schema: public), this is for initialization reasons

TODO
====
 - Add better shard management
 - Add a service and RESTful layer
 - Add automatic schema initialization mechanism


text:
# Promoting APIs Through CICD

WSO2 API Manager (WSO2 API-M) allows you to maintain multiple
environments running on the same WSO2 API-M version. This feature allows
you to import and export APIs between your environments. For example, if
you have an API running in the development environment, you can import
it and export to the test(QA) environment. Thereby, APIs do not have to
be created from scratch in different environments.

### Getting Started

After running the CLI tool make sure to add an environment before you
start working with the import/export CLI commands, because all APIs and
applications need to be imported or exported to a specific environment.

#### Running the CLI tool

##### Step 1 - Deploy the API import/export tool

1.  Download the latest version of WSO2 API Manager
    from http://wso2.com/products/api-manager/.

2.  Start WSO2 API Manager.
3.  Download the latest WSO2 API import/export tool
    (`api-import-export-2.6.0-v10.war`) from [here]({{base_path}}/assets/attachments/learn/api-import-export-2.6.0-v10.war).

    -   Note that the import/export tool attached is specific to this
        version of WSO2 API Manager.

    -   Make sure to delete all previous versions of the web app (e.g.,
        `api-import-export-2.6.0-v10.war`), both the compressed and the
        extracted files, before copying over the new web app.

    -   This version of the API Import and Export web application is         compatible with the WSO2 **WUM **updates from July 8, 2019           onwards. For more
        information on updating WSO2 API Manager, see [Updating WSO2 API
        Manager](https://docs.wso2.com/display/AM260/Updating+WSO2+API+Manager).
    -   The previous version of the web application which is compatible
        with WUM updates that are prior to the above mentioned date can
        be download from [here]({{base_path}}/assets/attachments/learn/api-import-export-2.6.0-v10.war).
    -   Note that API update support in targeted environment is
        available only with the api-import-export-2.6.0-v10.war version.

4.  Copy the downloaded `api-import-export-2.6.0-v10.war` file to   the `<API-M_HOME>/repository/deployment/server/webapps` folder. The file is automatically deployed as hot deployment is enabled.

##### Step 2- Run the CLI tool

1.  Navigate to the API Management Tooling page
    - https://wso2.com/api-management/tooling/
2.  Click **Download** under **Dev-Ops Tooling**.

    ![](../../assets/img/103328894/126567324.png)
3.  Select a generated archive suitable for your platform (i.e., Mac,
    Windows, Linux) and extract it the CLI tool that you downloaded to a
    desired location and `cd` into it.

4.  Navigate to the working directory where the executable CLI Tool
    resides.

5.  Execute the following command to start the CLI tool.

    ```
    ./apimcli
    ```

6.  Add the location of the extracted folder to your system's `$PATH`
    variable to be able to access the executable from anywhere.

    For further instructions execute the following command.

    ```
    apimcli --help
    ```
##### Global flags for CLI tool

    The following are some global flags that you can use with the CLI tool.

    ```
        --verbose
            Enable verbose logs (Provides more information on execution)
        --insecure, -k
            Allow connections to SSL sites without certs
        --help, -h
            Display information and example usage of a command
    ```

#### Adding an environment

You can add environments by either manually editing the
`$HOME/.wso2apimcli/main_config.yaml` file or by running the following
CLI command.

```
apimcli add-env
```

The directory structure for the configuration files (
`$HOME/.wso2apimcli` ) will be created upon execution of the `apimcli`
command.

1.  Make sure that WSO2 API Manager is started and that the CLI
    import/export tool is running.
2.  Run the following CLI command to add an environment.

    -   **Command Format**

        -   **Linux Format**

            ```
            apimcli add-env -n <environment-name> \
                                    --registration <registration-endpoint> \
                                    --apim <API-Manager-endpoint> \
                                    --token <token-endpoint> \
                                    --import-export <endpoint-for-environment> \
                                    --admin <admin-REST-API-endpoint> \
                                    --api_list <API-listing-REST-API-endpoint> \
                                    --app_list <application-listing-REST-API-endpoint>
            ```
    -   **Mac Format**
            ```
            apimcli add-env -n <environment-name> --registration <registration-endpoint> --apim <API-Manager-endpoint> --token <token-endpoint> --import-export <endpoint-for-environment> --admin <admin-REST-API-endpoint> --api_list <API-listing-REST-API-endpoint> --app_list <application-listing-REST-API-endpoint>
            ```

        **Flags:**

        -   Required flags:
            -   `--name, -n`
                There are no short flags for the following flags.
            -   `--registration`
            -   `--apim`
            -   `--token `
            -   `--import-export`
            -   `--admin`
            -   `--api_list`
            -   `--app_list`

    -   **Example**
        ```
        apimcli add-env -n production \
                              --registration https://localhost:9443/client-registration/v0.14/register \
                              --apim https://localhost:9443 \
                              --token https://localhost:8243/token \
                              --import-export https://localhost:9443/api-import-export-2.6.0-v10 \
                              --admin https://localhost:9443/api/am/admin/v0.14 \
                              --api_list https://localhost:9443/api/am/publisher/v0.14/apis \
                              --app_list https://localhost:9443/api/am/store/v0.14/applications
        ```

    -   **Response**
        -   *Response Format*
        ```
        Successfully added environment '<environment-name>'
        ```
        -   *Example Response*
        ```
        Successfully added environment 'production'
        ```

#### Removing an environment

1.  Make sure that WSO2 API Manager is started and that the CLI
    import/export tool is running.
2.  Run the following CLI command to remove an environment.

    -   **Command Format**
    ```
    apimcli remove-env -n <environment-name>
    ```
    ```
    apimcli remove-env --name <environment-name>
    ```
     **Flags:**
    -   Required flags
         -   `--name, -n`

    -   **Example**
    ```
    apimcli remove-env -n production
    ```
    -   **Response**
        -   **Format**
        ```
        Successfully removed environment '<environment-name>'
        Execute 'apimcli add-env --help' to see how to add a new environment
        ```

        -   **Example**
        ```
        Successfully removed environment 'uat'
        Execute 'apimcli add-env --help' to see how to add a new environment
        ```

#### List environments

1.  Make sure that WSO2 API Manager is started and that the CLI
    import/export tool is running.
2.  Run the following CLI command to list the environments.
    There are no flags for the following CLI command.

    -   **Command**
    ```
    apimcli list envs
    ```
    -   **Response**
    ```
    Environments available in file '/Users/kim/.wso2apimcli/main_config.yaml'

    +------------+------------------------+-----------------------------------------------------------+------------------------------+
    |    NAME    |   PUBLISHER ENDPOINT   |                   REGISTRATION ENDPOINT                   |        TOKEN ENDPOINT        |
    +------------+------------------------+-----------------------------------------------------------+------------------------------+
    | dev        | https://localhost:9443 | https://localhost:9443/client-registration/v0.14/register | https://localhost:8243/token |
    | production | https://localhost:9444 | https://localhost:9444/client-registration/v0.14/register | https://localhost:8244/token |
    +------------+------------------------+-----------------------------------------------------------+------------------------------+
    ```

### Migrating APIs to different environments

#### Exporting an API

1.  Make sure that WSO2 API Manager is started and that the CLI
    import/export tool is running.
2.  Run the following CLI command to export an existing API as a `.zip`
    archive.

    -   **Command Format**
        ```
        apimcli export-api -n <API-name> -v <version> -r <provider> -e <environment> -k
        ```
        ```
        apimcli export-api --name <API-name> --version <version> --provider <provider> --environment <environment> --insecure
        ```
        **Flags:**

        -   Required flags:
            -   `--name, -n`
            -   `--version, -v`
            -   `--provider, -r`
            -   `--environment, -e`
            -   `--insecure, -k : This allows connections to SSL sites without certificates`

    -   **Example**
        ```
        apimcli export-api -n PhoneVerification -v 1.0.0 -r admin -e dev -k
        ```
    -   **Response**
        ```
        Succesfully exported API!
        Find the exported API at /Users/kim/.wso2apimcli/exported/apis/dev/PhoneVerification_1.0.0.zip
        ```

#### Importing an API

When you import an API, regardless the status of the imported API it
will be added with the created state and you need to sign in to the
Publisher and publish the API.

You can use the archive created in the previous section to import APIs
to an API Manager instance.

1.  Make sure that WSO2 API Manager is started and that the CLI import/export tool is running.

    For Secure Endpoint Enabled APIs:
    If you have enabled secure endpoints when creating the API and your
    username or/and password differs in the two environments, please
    follow the steps below before importing the API.

    1. Unzip the .zip archive created in the previous section.

    2. Go to the `<API-name-version>/Meta-information` directory and open
    the `api.json` file.
    For example, ` PhoneVerification_1.0.0/Meta-information` directory and
    open the `api.json` file.

    3. Modify the `endpointUTPassword` with your endpoint password and save
    the `api.json` file.

    4. Compress the `PhoneVerification_1.0.0 `folder to a folder named
    `myExportedAPI.        `

-   Run the following CLI command to import an API.

    -   **Command Format**
    ```
    apimcli import-api -f <environment>/<file> -e <environment> -k
    ```
    ```
    apimcli import-api --file <environment>/<file> --environment <environment> --insecure
    ```
    **Flags:**
    -   Required flags:
        -   `--file, -f : The file path of the exported API. For example, if your file path is `/Users/kim/.wso2apimcli/exported/apis/dev/PhoneVerification\_1.0.0.zip.,
            then you need to enter `dev/PhoneVerification_1.0.0.zip` as
            the value for this flag.
        -   `--environment, -e : The environment to which you what to import the API to.`
        -   `--insecure, -k : This allows connections to SSL sites without certificates`

    -   **Example**
    ```
    apimcli import-api -f dev/PhoneVerification_1.0.0.zip -e production -u admin -p admin -k
    ```
    -   **Response**
    **Sample Response**
        ```
        ZipFilePath: /Users/kim/.wso2apimcli/exported/apis/dev/PhoneVerification_1.0.0.zip
        Successfully imported API 'dev/PhoneVerification_1.0.0.zip'
        Succesfully imported API!
        ```

    You must add a parameter named `--preserve-provider` to the CLI
    command and set its value to false if the API is imported to a
    different domain than its exported one. This parameter sets the
    provider of the imported API to the user who is issuing the CLI
    command. Here's an example:

    -   **Command Format**
    ```
    apimcli import-api -k -f <environment>/<file> -e <environment> -u <username> -p <password> --preserve-provider <preserve_provider>
    ```
    ```
    apimcli import-api --insecure --file <environment>/<file> --environment <environment> -u <username> -p <password> --preserve-provider=<preserve_provider>
    ```
    The username and password are optional flags. You will be prompted
    to enter your credentials if you do not provide these flags.

    **Flags:**

    -   Required flags:
        -   `--insecure, -k : This allows connections to SSL sites without certificates`
        -   `--file, -f`
        -   `--environment, -e : The environment to which you what to import the API to.`
        -   `--preserve-provider (This does not have a short flag)`
    -   Optional flags:
        -   `--username, -u `
        -   `--password, -p`

    -   [**Example**](#Example-preserve)
    ```
    apimcli import-api -k -f dev/PhoneVerification_1.0.0.zip -e production -u admin -p admin --preserve-provider=false
    ```
    The `--preserve-provider` flag is used to decide whether to keep the
    actual Provider as the provider of the API or change the provider to
    the user who is importing the API to a different environment.

    As an example, If `--preserve-provider` is set to true, when
    importing an API created by user-1 in environment-1 will be
    preserved as the provider when and after importing that API to
    environment-2 by user-2. If `--preserve-provider` is set to false,
    when importing that API created by user-1 to the environment-2, the
    provider will be changed (not preserved) to user-2 who is importing
    the API.

    !!! note
    Troubleshooting
    After importing, if the APIs are not visible in the API Publisher
    UI, do the following to re-index the artifacts in the registry.

    1.  Rename the `<lastAccessTimeLocation>` element in
        the `<API-M_2.6.0_HOME>`/`repository/conf/registry.xml` file. If
        you use a **clustered/distributed API Manager setup**, change
        the file in the API Publisher node. For example, change
        the `/_system/local/repository/components/org.wso2.carbon.registry/indexing/lastaccesstime` registry
        path
        to `/_system/local/repository/components/org.wso2.carbon.registry/indexing/lastaccesstime_1.                              `

    2.

        For more information, see [Upgrading the API Manager to
        2.6.0](https://docs.wso2.com/display/AM260/Upgrading+from+the+Previous+Release_2xx).

#### Importing/exporting an API in a tenanted environment

The environments that you create will be common to the admin and the
tenants. Therefore, you do not need to create environments again when
exporting and importing APIs between tenanted environments.

-   To export an API from a tenant, follow the steps in [Export an
    API](#MigratingtheAPIstoaDifferentEnvironment-ExportanAPI). Use the
    tenant-specific encoded credentials in the CLI command. Here's an
    example:

    -   [**Command Format**](#Format-exportAPITenant)
    -   [**Example**](#Example-exportAPITenant)
    -   [**Response**](#ResponseExportAPITenant)

    ```
    apimcli export-api -n <API-name> -v <version> -r <provider> -e <environment> -u <username> -p <password> -k
    ```

    ```
    apimcli export-api --name <API-name> -version <version> --provider <provider> --environment <environment> --username <username> --password <password> --insecure
    ```

    The username and password are optional flags. You will be prompted
    to enter your credentials if you do not provide these flags.

    **Flags:**

    -   Required flags:
        -   `--name, -n`
        -   `--version, -v`
        -   `--provider, -r`
        -   `--environment, -e :                            The environment to which you what to export the API to.                         `
        -   `--insecure, -k : This allows connections to SSL sites without certificates                         `
    -   Optional flags:
        -   `--username, -u`
        -   `--password, -p`

    ```
    apimcli export-api -n PizzaShackAPI -v 1.0.0 -r<EMAIL_ADDRESS>-e dev -u<EMAIL_ADDRESS>-p chris123 -k
    ```

    **Sample Response**

    ```
    Succesfully exported API!
    Find the exported API at /Users/kim/.wso2apimcli/exported/apis/dev/PizzaShackAPI_1.0.0.zip
    ```

-   To import the API in another tenant, follow the steps in Importing
    an API. Use the encoded credentials for this tenant in the CLI
    command. Here's an example:

    The page: **Migrating the APIs and Applications to a Different
    Environment** was found, but the multiexcerpt named
    '**importAPIcreated**' was not found. Please check/update the page
    name used in the 'multiexcerpt-include macro.

    -   [**Command Format**](#FormatImportAPI)
    -   [**Example**](#ExampleImportAPI)
    -   [**Response**](#ResponseImportAPITenant)

    ```
    apimcli import-api -f <environment>/<file> -e <environment> -u <username> -p <password> --preserve-provider <preserve_provider>
    ```

    ```
    apimcli import-api --file <environment>/<file> --environment <environment> --username <username> --password <password> --preserve-provider <preserve_provider>
    ```

    The username and password are optional flags. You will be prompted
    to enter your credentials if you do not provide these flags.

    **Flags:**

    -   Required flags:
        -   `--file, -f`
        -   `--environment, -e : The environment to which you what to import the API to.`
        -   `--insecure, -k : This allows connections to SSL sites without certificates                         `
        -   `--preserve-provider`
    -   Optional flags:
        -   `--username, -u `
        -   `--password, -p`

    ```
    apimcli import-api -f dev/PizzaShackAPI_1.0.0.zip -e production -u<EMAIL_ADDRESS>-p nick123 --preserve-provider=false -k
    ```

    ```
    ZipFilePath: /Users/kim/.wso2apimcli/exported/apis/dev/PizzaShackAPI_1.0.0.zip
    Successfully imported API 'dev/PizzaShackAPI_1.0.0.zip'
    Succesfully imported API!
    ```

    Note that the `--preserve-provider` flag value should be set
    to `false`.

#### List APIs

1.  Make sure that WSO2 API Manager is started and that the CLI
    import/export tool is running.
2.  Run the following CLI command to list the APIs.

-   [**Command Format**](#FormatListAPI)
-   [**Example**](#Example-listAPI)
-   [**Response**](#Response-listAPI)

```
apimcli list apis -e <environment> -u <username> -p <password> -k
```

```
apimcli list apis --environment <environment> --username <username> --password <password> --insecure
```

**Flags:**

-   Required flags:
    -   `--environment, -e`
    -   `--insecure, -k                     `
-   Optional flags:
    -   `--username, -u `
    -   `--password, -p`

        The username and password are optional flags. You will be
        prompted to enter your credentials if you do not provide these
        flags.

```
apimcli list apis -e dev -u admin -p admin -k
```

```
Environment: dev
No. of APIs: 2
+-------------------+---------+--------------+-----------+----------+--------------------------------------+
|       NAME        | VERSION |   CONTEXT    |  STATUS   | PROVIDER |                  ID                  |
+-------------------+---------+--------------+-----------+----------+--------------------------------------+
| PhoneVerification | 1.0.0   | /phoneverify | PUBLISHED | admin    | 2f25b332-4007-4c83-8249-b14b8af04848 |
| PizzaShackAPI     | 1.0.0   | /pizzashack  | PUBLISHED | admin    | 59e81b69-24d2-4fc4-9aaa-40665e119261 |
+-------------------+---------+--------------+-----------+----------+--------------------------------------+
```

###  Reset user

1.  Make sure that WSO2 API Manager is started and that the CLI
    import/export tool is running.
2.  Run the following CLI command to reset user details.

    -   [**Command Format**](#Format-ResetUser)
    -   [**Example**](#Example-ResetUser)
    -   [**Response**](#ResponseClearUser)

    ```
    apimcli reset-user -e <environment>
    ```

    ```
    apimcli reset-user --environment <environment>
    ```

    **Flags:**

    -   Required flags
        -   `--environment, -e`

    ```
    apimcli reset-user -e dev
    ```

    ```
    Successfully cleared user data for environment: dev
    ```

### Check the version of the CLI

1.  Make sure that WSO2 API Manager is started and that the CLI
    import/export tool is running.
2.  Run the following CLI command to check the version of the CLI.
    There are no flags for the following CLI command.

    -   [**Command**](#Format-CLIver)
    -   [**Example**](#Example-CLIver)

    ```
    apimcli version
    ```

    ```
    apimcli Version: 1.1.0
    ```

### Set HTTP request timeout

1.  Make sure that WSO2 API Manager is started and that the CLI
    import/export tool is running.
2.  Run the following CLI command to set the HTTP request timeout.

    -   [**Command Format**](#Format-RstTime)
    -   [**Example**](#Example-RstTime)

    ```
    apimcli set --http-request-timeout <http-request-timeout>
    ```

    **Flags:**

    -   `--http-request-timeout`

    ```
    apimcli set --http-request-timeout 10000
    ```

### Set export directory

1.  Make sure that WSO2 API Manager is started and that the CLI
    import/export tool is running.
2.  Run the following CLI command to the change the default location of
    the export directory.

    -   [**Command Format**](#Format-expDir)
    -   [**Example**](#Example-expDir)

    ```
    apimcli set --export-directory <export-directory-path>
    ```

    **Flags:**

    -   `--export-directory`

    ```
    apimcli set --export-directory /Users/kim/Downloads/MyExports
    ```

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

### Understanding the API import/export tool

The API import/export tool uses a RESTful API, protected by basic
authentication.

Only the following types of users are allowed to access the API
import/export tool.

-   A user with the admin role.
-   A user with a role that has the API-M Admin, Login, and API Create
    permissions.

    Click here to see a screen shot of the
    above listed permissions.

To allow access to the import/export feature only for a particular
tenant, log in to WSO2 API Manager's Management Console and add the
downloaded archive file as a web application to the server.

The 'admin' role is the default role which is specified in the Realm
configuration in the `<API-M-HOME>/repository/conf/user-mgt.xml`   file.
It will be changed if you have changed the value of the `<AdminRole>`
parameter as shown below.

```
<Realm>
        <Configuration>
        <AddAdmin>true</AddAdmin>
            <AdminRole>admin</AdminRole>
         .....
       </Configuration>
</Realm>
```

#### The export functionality

The API export functionality retrieves the information required for the
requested API from the registry and databases and generates a ZIP file,
which the exporter can download. This exported ZIP file has the
following structure:

The structure of the ZIP file is explained below:

Sub directory/File
Description

Meta Information

api.json: contains all the basic information required for an API to be imported to another environment

swagger.json: contains the API swagger definition

Documents

docs.json: contains the summary of all the documents available for the API

Add the uploaded files for API documentation also

Image
Thumbnail image of the API

WSDL
WSDL file of the API

Sequences
The sequences available for the API

#### The import functionality

The import functionality uploads the exported ZIP file of the API to the
target environment. It creates a new API with all the registry and
database resources exported from the source environment. Note the
following:

-   The lifecycle status of an imported API will always
    be `CREATED` even when the original API in the source environment
    has a different state. This is to enable the importer to modify the
    API before publishing it.
-   Tiers and sequences are provider-specific. If an exported tier is
    not already available in the imported environment, that tier is not
    added to the new environment. However, if an exported sequence is
    not available in the imported environment, it is added.
-   The importer can decide whether to keep the original provider’s name
    or replace it. Set the ` --preserve-provider  `flag to true to keep
    it. If you set it to false, the original provider is replaced by the
    user who is sending the CLI command.
-   Cross-tenant imports are not allowed by preserving the original
    provider. For example, if an API is exported from tenant A and
    imported to tenant B, the value of the `--preserve-provider` flag
    must always be `false`.

repository: HiranyaKavishani/docs-apim

repo_name: HiranyaKavishani/docs-apim


text:
# FaithVision

FaithVision is designed to navigate and guide the visually impaired peoples in day to day operations. This version can identify objects in the live mobile camera feed and speak them using an android app.

This is a 24 hour hack developed as team *Faith3.0* during the HackGSF 2017, a hackathon organised by [GSF India](http://www.gsfaccelerator.com/) in Bengaluru. Team members were - [Akhil Ahuja](), [Ritvik Vipra]() and [myself]().

# Implementation Details

- `IP Webcam` android application is used to capture the live video and serve it on a url.
- `ip_webcam.py` keep hitting that url to get a frame at a moment and upload it to a EC2 instance. `~/.ssh/UbuntuServerPrivateKey.pem` is the key for connecting to that instance.
- `main_script.py` runs on that EC2 instance which process that frame image using Tensorflow's Object Detection APIs and write the results on a file `text.json` (using a file for directly storing makes it unfit for multiple users, but this was quickest way for hackathon).
- `android/FaithVision` (an android app) hits the url serving that json file from the server instance. It then send the parsed text to the `AWS Polly` which returns the audio in `.mp3` and plays it. The app is just the accordingly modified version of the demo applicatioin available on the Polly's site.

# Instructions to run

1. Open `IP Webcam` app and click on start server
2. Run `ip_webcam.py` on a machine (on same network)
3. Run tensorflow script on EC2 instance.
4. Open FaithVision android app for demo.

# Licence

[MIT License](https://nks.mit-license.org/)

repository: krsoninikhil/faith-vision

repo_name: krsoninikhil/faith-vision


text:
# [Salmefelt](https://www.salmefelt.com)

## Requirements
`make` - I have GNU Make 3.81 installed.

`npm >5.2.0` - Comes with `npx`, which is used in the Makefile.

`node >12.13.0` - Used to generate elm files from json.

`elm 0.19.1`

`ImageMagick` - Used to optimize images. I have version 7.0.9-16 installed.

## Run
``` bash
# Generate translations and optimize imges
make generate

# Run development server
make develop
```

## Build
```
make build
```

repository: WhileTruu/salmefelt-em

gha_language: Elm

repo_name: WhileTruu/salmefelt-em


text:
# Kinesis Output Plugin

[![Build Status][badge-travis]][travis]
[![Gem info][badge-gem]][rubygems]

This is a plugin for [Logstash](https://github.com/elasticsearch/logstash). It will send log records to a [Kinesis stream](https://aws.amazon.com/kinesis/), using the [Kinesis Producer Library (KPL)](https://docs.aws.amazon.com/kinesis/latest/dev/developing-producers-with-kpl.html).

**This version is intended for use with Logstash 2.x. Please use a [1.5.x](https://github.com/samcday/logstash-output-kinesis/tree/1.5) version of this plugin for Logstash 1.5.x compatibility.**

## Configuration

Minimum required configuration to get this plugin chugging along:

```nginx
output {
  kinesis {
    stream_name => "logs-stream"
    region => "ap-southeast-2"
  }
}
```

This plugin accepts a wide range of configuration options, most of which come from the underlying KPL library itself. [View the full list of KPL configuration options here.][kpldoc]

Please note that configuration options are snake_cased instead of camelCased. So, where [KinesisProducerConfiguration][kpldoc] offers a `setMetricsLevel` option, this plugin accepts a `metrics_level` option.

### Metrics

The underlying KPL library defaults to sending CloudWatch metrics to give insight into what it's actually doing at runtime. It's highly recommended you ensure these metrics are flowing through, and use them to monitor the health of your log shipping.

If for some reason you want to switch them off, you can easily do so:

```nginx
output {
  kinesis {
    # ...

    metrics_level => "none"
  }
}
```

If you choose to keep metrics enabled, ensure the AWS credentials you provide to this plugin are able to write to Kinesis *and* write to CloudWatch.

### Authentication

By default, this plugin will use the AWS SDK [DefaultAWSCredentialsProviderChain](https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html) to obtain credentials for communication with the Kinesis stream (and CloudWatch, if metrics are enabled). The following places will be checked for credentials:

 * `AWS_ACCESS_KEY_ID` / `AWS_SECRET_KEY` environment variables available to the Logstash prociess
 * `~/.aws/credentials` credentials file
 * Instance profile (if Logstash is running in an EC2 instance)

If you want to provide credentials directly in the config file, you can do so:

```nginx
output {
  kinesis {
    # ...

    access_key => "<REDACTED_AWS_ACCESS_KEY>"
    secret_key => "KX0ofakeLcredentialsGrightJherepOlolPkQk"

    # You can provide specific credentials for CloudWatch metrics:
    metrics_access_key => "<REDACTED_AWS_ACCESS_KEY>"
    metrics_secret_key => "KX0ofakeLcredentialsGrightJherepOlolPkQk"
  }
}
```

If `access_key` and `secret_key` are provided, they will be used for communicating with Kinesis *and* CloudWatch. If `metrics_access_key` and `metrics_secret_key` are provided, they will be used for communication with CloudWatch. If only the metrics credentials were provided, Kinesis would use the default credentials provider (explained above) and CloudWatch would use the specific credentials. Confused? Good!

#### Using STS

You can also configure this plugin to use [AWS STS](https://docs.aws.amazon.com/STS/latest/APIReference/Welcome.html) to "assume" a role that has access to Kinesis and CloudWatch. If you use this in combination with EC2 instance profiles (which the defaults credentials provider explained above uses) then you can actually configure your Logstash to write to Kinesis and CloudWatch without any hardcoded credentials.

```nginx
output {
  kinesis {
    # ...

    role_arn => "arn:aws:iam::123456789:role/my-kinesis-producer-role"

    # You can also provide a specific role to assume for CloudWatch metrics:
    metrics_role_arn => "arn:aws:iam::123456789:role/my-metrics-role"
  }
}
```

You can combine `role_arn` / `metrics_role_arn` with the explicit AWS credentials config explained earlier, too.

All this stuff can be mixed too - if you wanted to use hardcoded credentials for Kinesis, but then assume a role via STS for accessing CloudWatch, you can do that. Vice versa would work too - assume a role for accessing Kinesis and then providing hardcoded credentials for CloudWatch. Make things as arbitrarily complicated for yourself as you like ;)

### Building a partition key

Kinesis demands a [partition key](https://docs.aws.amazon.com/kinesis/latest/dev/key-concepts.html#partition-key) be provided for each record. By default, this plugin will provide a very boring partition key of `-`. However, you can configure it to compute a partition key from fields in your log events.

```nginx
output {
  kinesis {
    # ...
    event_partition_keys => ["[field1]", "[field2]"]
  }
}
```

#### Randomised partition keys

If you don't care about the ordering of your logs in the Kinesis stream, you might want to use a random partition key. This way, your log stream will be more or less uniformly spread across all available shards in the Kinesis stream.

```nginx
output {
  kinesis {
    randomized_partition_key => true
  }
}
```

### Record Aggregation

The [Amazon KPL library can aggregate](https://docs.aws.amazon.com/kinesis/latest/dev/kinesis-kpl-concepts.html#d0e3423) your records when writing to the Kinesis stream. **This behaviour is configured to be enabled by default.**

If you are using an older version of the Amazon KCL library to consume your records, or not using KCL at all, your consumer application(s) will probably not behave correctly. See [the matrix on this page](https://docs.aws.amazon.com/kinesis/latest/dev/kinesis-kpl-integration.html) for more info, and read [more about de-aggregating records here](https://docs.aws.amazon.com/kinesis/latest/dev/kinesis-kpl-consumer-deaggregation.html).

If you wish to simply disable record aggregation, that's easy:

```nginx
output {
  kinesis {
    aggregation_enabled => false
  }
}
```

### Backpressure

This plugin will enforce backpressure if the records passing through Logstash's pipeline are not making it up to Kinesis fast enough. When this happens, Logstash will stop accepting records for input or filtering, and a warning will be emitted in the Logstash logs.

By default, the threshold for blocking is 1000 pending records. If you want to throw more memory / CPU cycles at buffering lots of stuff before it makes it to Kinesis, you can control the high-watermark:

```nginx
output {
  kinesis {
    max_pending_records => 10000
  }
}
```

## Known Issues

### Noisy shutdown

During shutdown of Logstash, you might get noisy warnings like this:

```
[pool-1-thread-6] WARN com.amazonaws.services.kinesis.producer.Daemon - Exception during updateCredentials
java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at com.amazonaws.services.kinesis.producer.Daemon$5.run(Daemon.java:316)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
```

This is caused by [amazon-kinesis-producer#10](https://github.com/awslabs/amazon-kinesis-producer/issues/10)

### Noisy warnings about `Error during socket read`

While your Logstash instance is running, you may occasionally get a warning on stderr that looks like this:

```
[2015-10-20 06:31:08.441640] [0x00007f36c9402700] [error] [io_service_socket.h:229] Error during socket read: End of file; 0 bytes read so far (kinesis.us-west-1.amazonaws.com:443)
```

This is being tracked in [amazon-kinesis-producer#17](https://github.com/awslabs/amazon-kinesis-producer/issues/17). This log message seems to just be noise - your logs should still be delivering to Kinesis fine (but of course, you should independently verify this!).

## Developing

Ensure you have JRuby 1.7.x installed. [rvm](https://rvm.io/) is your friend :)

```sh
bundle install
bundle exec rake
```

### Updating KPL

Change the dependency version in `build.gradle`, and then run `gradle copylibs`. Make sure to check in all the updated JARs! Yes, we put them in the repo :(

## Contributions

Are more than welcome. Raising an issue is great, raising a PR is better, raising a PR with tests is best.

## License

[Apache License 2.0](LICENSE)

[travis]: https://travis-ci.org/samcday/logstash-output-kinesis
[rubygems]: https://rubygems.org/gems/logstash-output-kinesis
[kpldoc]: https://github.com/awslabs/amazon-kinesis-producer/blob/v0.10.1/java/amazon-kinesis-producer/src/main/java/com/amazonaws/services/kinesis/producer/KinesisProducerConfiguration.java#L38

[badge-travis]: https://img.shields.io/travis/samcday/logstash-output-kinesis.svg?style=flat-square
[badge-gem]: https://img.shields.io/gem/v/logstash-output-kinesis.svg?style=flat-square

repository: modolabs/logstash-output-kinesis

gha_language: Ruby

gha_license_id: NOASSERTION

repo_name: modolabs/logstash-output-kinesis