text:
---
layout: page
title: Group 09
nav_order: 14
description:
---

# Analyzing Regional Trends in Police Stop Data Across the United States
### Names: Rishabh Parekh, Emmy Yu, Manu Prakasam

## **About the Data: Ethical Data Collection**
Publicly-available Standardized Stop Data from: https://openpolicing.stanford.edu/data/

The Stanford Open Policing Project data are made available under the [Open Data Commons Attribution License](https://opendatacommons.org/licenses/by/summary/), which allows us to:
>To Share: To copy, distribute and use the database.

To Create: To produce works from the database.

To Adapt: To modify, transform and build upon the database.

The Stanford Opening Policing Project data comes from the [working paper](https://5harad.com/papers/100M-stops.pdf):

 **E. Pierson, C. Simoiu, J. Overgoor, S. Corbett-Davies, D. Jenson, A. Shoemaker, V. Ramachandran, P. Barghouty, C. Phillips, R. Shroff, and S. Goel. (2019) “A large-scale analysis of racial disparities in police stops across the United States”.**

The accompanying [README](https://github.com/stanford-policylab/opp/blob/master/data_readme.md) file describes how the data was standardized and cleaned for privacy and secruity reasons. Descriptions of the column meanings are also given.

 With the given data, we will have access to race of the individual, location, and time of each stop a police officer makes. The information of location can give us a general idea of an individual's socioeconomic background based on the neighborhood they are in.

Furthermore, using the race of the individual, we can find the total number of stops per race. We will also calculate the proportion of total number of stops and the population of that specific race in the area. This can show us if there is a disproportionate rate of interactions with the law enforcment and minorities.

Using the Stanford Open Policing data, we will also compare the three distinctly different cities: San Francisco, Pittsburgh, and New Orleans. This will allow us to see if policing is similar or different across the nation, and will further give us a general idea of the relationship between minorities and law enforcement.

### **Standardizing the Data:**
Certain columns that are common across all cities (and lend themselves to interesting analyses) were selected and merged to create one DataFrame for easier analysis and plotting.

Each row in the cleaned data represents a stop. Coverage varies by location. From the original Open Policing data, fields with an asterisk were removed for public release due to privacy concerns. All columns except ```raw_row_number```, ```violation```, ```disposition```, ```location```, ```officer_assignment```, any city or state subgeography (i.e. county, beat, division, etc), ```unit```, and ```vehicle_{color, make, model, type} ```are also digit sanitized (each digit replaced with "-") for privacy concerns. These columns from the original dataset were removed for the purpose of our analysis.

# **Exploratory Data Analysis**

```python
sf_crime_to_merge = sfcrime[["date", "time", "subject_age", "subject_race", "subject_sex", "type", "outcome", "citation_issued", "reason_for_stop"]]
sf_crime_to_merge = pd.DataFrame(sf_crime_to_merge)
sf_crime_to_merge["city"] = "San Francisco"
```

```python
pitt_crime_to_merge = pittcrime[["date", "time", "subject_age", "subject_race", "subject_sex", "type", "outcome", "citation_issued", "reason_for_stop"]]
pitt_crime_to_merge = pd.DataFrame(pitt_crime_to_merge)
pitt_crime_to_merge["city"] = "Pittsburgh"
```

```python
nola_crime_to_merge = nola_crime[["date", "time", "subject_age", "subject_race", "subject_sex", "type", "outcome", "citation_issued", "reason_for_stop"]]
nola_crime_to_merge = pd.DataFrame(nola_crime_to_merge)
nola_crime_to_merge["city"] = "New Orleans"
```

```python
#Exploratory Data Analysis Dataframe
eda_merged = (sf_crime_to_merge.append(pitt_crime_to_merge)).append(nola_crime_to_merge)
```

```python
eda_merged
```

      date
      time
      subject_age
      subject_race
      subject_sex
      type
      outcome
      citation_issued
      reason_for_stop
      city

      0
      2014-08-01
      00:01:00
      NaN
      asian/pacific islander
      female
      vehicular
      warning
      False
      Mechanical or Non-Moving Violation (V.C.)
      San Francisco

      1
      2014-08-01
      00:01:00
      NaN
      black
      male
      vehicular
      citation
      True
      Mechanical or Non-Moving Violation (V.C.)
      San Francisco

      2
      2014-08-01
      00:15:00
      NaN
      hispanic
      male
      vehicular
      citation
      True
      Mechanical or Non-Moving Violation (V.C.)
      San Francisco

      3
      2014-08-01
      00:18:00
      NaN
      hispanic
      male
      vehicular
      warning
      False
      Mechanical or Non-Moving Violation (V.C.)
      San Francisco

      4
      2014-08-01
      00:19:00
      NaN
      white
      male
      vehicular
      citation
      True
      Mechanical or Non-Moving Violation (V.C.)
      San Francisco

      ...
      ...
      ...
      ...
      ...
      ...
      ...
      ...
      ...
      ...
      ...

      512087
      2017-12-31
      00:48:00
      28.0
      black
      female
      vehicular
      arrest
      False
      TRAFFIC VIOLATION
      New Orleans

      512088
      2017-12-31
      00:48:00
      25.0
      black
      male
      vehicular
      arrest
      False
      TRAFFIC VIOLATION
      New Orleans

      512089
      2017-12-31
      00:48:00
      23.0
      black
      male
      vehicular
      arrest
      False
      TRAFFIC VIOLATION
      New Orleans

      512090
      2017-12-31
      00:48:00
      25.0
      black
      male
      vehicular
      arrest
      False
      TRAFFIC VIOLATION
      New Orleans

      512091
      2017-12-31
      12:49:00
      37.0
      black
      female
      vehicular
      citation
      True
      TRAFFIC VIOLATION
      New Orleans

1691720 rows × 10 columns

```python
plt.figure(figsize=(12,6))
ax = sns.countplot(x="city", hue="subject_race", data=eda_merged)
plt.title('Frequency of Stops by Race')
plt.legend(loc = 'upper right')
plt.show()
```

![png](output_17_0.png)

From the figure above, it is clear that the demographic range differs significantly across out three target locations: San Francisco, Pittsburgh, and New Orleans. It is important to note that the frequency of stops by race have some correlation to the racial demographics in these cities. For example, there is a large spike in stops for Blacks in New Orleans compared to both San Francisco and Pittsburgh. However, data from the [Demographic Statistical Atlas](https://statisticalatlas.com/United-States/Overview) shows that New Orleans has 58.9% Black population compared to San Francisco's 5.4% and Pittsburgh's 24.3%.

```python
#The lengths of the datasets differ by location, with San Francisco having the greatest number of citations.
eda_merged.groupby('city').count()[['citation_issued']]
```

      citation_issued

      city

      New Orleans
      512092

      Pittsburgh
      274555

      San Francisco
      905070

```python
eda_time = eda_merged.copy()
eda_time['date'] = pd.to_datetime(eda_time['date'])
eda_time['year'] = eda_time['date'].dt.year
eda_grouped = eda_time.groupby(['city','year']).count()[['citation_issued']].reset_index()

plt.figure(figsize=(15,8))
sns.countplot(x='city', hue='year', data=eda_time)
plt.title('Frequency of Stops by Year Across Locations')
plt.legend(loc = 'best')
plt.show()
```

![png](output_20_0.png)

From the barchart above, it can be seen that the greater dataset lengths are not entirely due to a higher number of stops made by police. As seen in the DataFrame above, San Francisco has the highest number of citations issued. The SF data also contains data from 2007-2016, where the 2016 end data is  partial data. The Pittsburgh data is from 2008-2018, where the beginning and end years contains partial data as well. The New Orleans data contains the years 2010-2018 (partial 2018, data collection ended before end of year). **Therefore, for fair comparisons and aggregations against locations, data will be limited to the years 2010-2015.**

```python
#taking only the stops from 2010-2015
inclusive_years = [2010, 2011, 2012, 2013, 2014, 2015]
eda_standard = eda_time[eda_time['year'].isin(inclusive_years)]
eda_standard.head()
```

      date
      time
      subject_age
      subject_race
      subject_sex
      type
      outcome
      citation_issued
      reason_for_stop
      city
      year

      0
      2014-08-01
      00:01:00
      NaN
      asian/pacific islander
      female
      vehicular
      warning
      False
      Mechanical or Non-Moving Violation (V.C.)
      San Francisco
      2014.0

      1
      2014-08-01
      00:01:00
      NaN
      black
      male
      vehicular
      citation
      True
      Mechanical or Non-Moving Violation (V.C.)
      San Francisco
      2014.0

      2
      2014-08-01
      00:15:00
      NaN
      hispanic
      male
      vehicular
      citation
      True
      Mechanical or Non-Moving Violation (V.C.)
      San Francisco
      2014.0

      3
      2014-08-01
      00:18:00
      NaN
      hispanic
      male
      vehicular
      warning
      False
      Mechanical or Non-Moving Violation (V.C.)
      San Francisco
      2014.0

      4
      2014-08-01
      00:19:00
      NaN
      white
      male
      vehicular
      citation
      True
      Mechanical or Non-Moving Violation (V.C.)
      San Francisco
      2014.0

```python
plt.figure(figsize=(12,6))
ax = sns.countplot(x="city", hue="subject_sex", data=eda_standard)
plt.title('Frequency of Stops by Gender')
plt.legend(loc = 'upper right')
plt.show()
```

![png](output_23_0.png)

In this figure showing the frequency of stops by gender across the three cities, it is clear that although the SF dataset contains the most number of stops, the division of stops by gender is fairly consistent across the cities. Stops of males constitutes more than half of the data in each location.

```python
eda_merged['year'] = pd.DatetimeIndex(eda_merged["date"]).year
plt.figure(figsize=(12,6))
ax = sns.countplot(x="subject_race", hue="outcome", data=eda_merged.sort_values(by=['outcome', 'subject_race']))
plt.title('Type of Police Stop by Race: Total')
plt.legend(loc = 'upper left')
plt.show()
```

![png](output_25_0.png)

```python
plt.figure(figsize=(12,6))
sf = eda_merged.loc[eda_merged["city"] == "San Francisco"]
ax = sns.countplot(x="subject_race", hue="outcome", data=sf.sort_values(by=['outcome', 'subject_race']))
plt.title('Type of Police Stop by Race: San Francisco')
plt.legend(loc = 'upper left')
plt.show()
```

![png](output_26_0.png)

**Note:** The San Francisco dataset does not have an "unknown" category option listed for the subject's race.

According to the 2018 US Census Bureau, San Francisco County's population was 40% Non-Hispanic White, 5.4% Hispanic White, 5.2% Black or African American, 34.3% Asian, 8.1% Some Other Race, 0.3% Native American and Alaskan Native, 0.2% Pacific Islander and 6.5% from two or more races. Based on this data, it's interesting to note the relatively low count of AAPI subjects stopped based on their percentage of the population, and the relatively high count of black and Hispanic subjects stopped based on their percentage of the population.

```python
plt.figure(figsize=(12,6))
pitt = eda_merged.loc[eda_merged["city"] == "Pittsburgh"]
ax = sns.countplot(x="subject_race", hue="outcome", data=pitt.sort_values(by=['outcome', 'subject_race']))
plt.title('Type of Police Stop by Race: Pittsburgh')
plt.legend(loc = 'upper left')
plt.show()
```

![png](output_28_0.png)

In Pittsburgh, the two races with the most significant percentages are black and white. We see relatively similar trends for these two races, with one small difference being that more black subjects receive more warnings than citations and more white subjects receive citations than warnings. This could indicate a number of different things, including more black subjects are unecessarily stopped or for smaller infractions. An additional note, given Pittsburgh's population  ~65% white and ~24% black (from the Demographic Statistical Atlas referenced earlier), we see a higher relative count of stops for black subjects than the demographics of the city would predict given an even distribution of stops across race.

```python
plt.figure(figsize=(12,6))
nola = eda_merged.loc[eda_merged["city"] == "New Orleans"]
ax = sns.countplot(x="subject_race", hue="outcome", data=nola.sort_values(by=['outcome', 'subject_race']))
plt.title('Type of Police Stop by Race: New Orleans')
plt.legend(loc = 'upper right')
plt.show()
```

![png](output_29_0.png)

An interesting difference between New Orleans and our other cities is the very high rate of arrests relative to citations and warnings. San Francisco has the lowest relative rate of arrests, followed by Pittsburgh, with New Orleans having a rate of arrest nearly at par with citations and warnings.

We then took a look to see if there were trends year over year.

```python
plt.figure(figsize=(10,6))
sf_years = sf['year'].value_counts()
sns.lineplot(data=sf_years, label='SF')
pitt_years = pitt['year'].value_counts()
sns.lineplot(data=pitt_years, label='Pittsburgh')
nola_years = nola['year'].value_counts()
sns.lineplot(data=nola_years, label='New Orleans')
plt.ylim(ymin=0)
plt.xlabel("Year")
plt.ylabel("Count")
plt.title("Stops Over Time By Cities")
plt.legend()
plt.show()
```

![png](output_32_0.png)

We see some interesting trends in stop count by year that vary by city. NOLA is up and down but decreasing, SF is decreasing over time for the most part and Pitt saw a trend upward followed by a trend downward, resulted in an arc-like graph. We then took a deeper look into New Orleans to see if time trends differed by race, but we did not find any immediately striking results.

```python
plt.figure(figsize=(10,6))
nola_black = nola.loc[nola["subject_race"] == "black"]
nola_black = nola_black['year'].value_counts()
sns.lineplot(data=nola_black, label="black")
plt.ylim(ymin=0)
nola_white = nola.loc[nola["subject_race"] == "white"]
nola_white = nola_white['year'].value_counts()
sns.lineplot(data=nola_white, label="white")
plt.ylim(ymin=0)
plt.xlabel("Year")
plt.ylabel("Count")
plt.title("Stops in New Orleans Over Time by Race")
plt.legend()
plt.show()
```

![png](output_34_0.png)

We then decided to take a look at if an analysis of time of day versus stoppage rates by race produced any interesting results.

```python
plt.figure(figsize=(10,6))
with_time_sf = sfcrime.copy()
with_time_sf['subject_race'] = with_time_sf['subject_race'].replace(['asian/pacific islander', 'hispanic', 'black', 'other'], 'non-white')
with_time_sf['time'] = pd.to_datetime(with_time_sf['time'])
with_time_sf['time'] = with_time_sf['time'].dt.hour
sns.countplot(x='time', hue='subject_race', data=with_time_sf.sort_values(by='subject_race'))
plt.xticks(rotation=70)
plt.title('Count of Stops by Race Throughout Time of Day (SF)');
```

![png](output_37_0_new.png)

For the majority of the day in San Francisco, the ratio between the number of non-white subjects stopped and the number of white subjects stopped stays relatively constant with slightly more non-white subjects stopped. We then see  that this gap widens between the hours of 10pm and midnight.

```python
plt.figure(figsize=(10,6))
with_time_nola = nola_crime.copy()
with_time_nola['subject_race'] = with_time_nola['subject_race'].replace(['asian/pacific islander', 'hispanic', 'black', 'other', 'unknown'], 'non-white')
with_time_nola['time'] = pd.to_datetime(with_time_nola['time'])
with_time_nola['time'] = with_time_nola['time'].dt.hour
sns.countplot(x='time', hue='subject_race', data=with_time_nola.sort_values(by='subject_race'))
plt.xticks(rotation=70)
plt.title('Count of Stops by Race Throughout Time of Day (New Orleans)');
```

![png](output_39_0_new.png)

We see relatively similar ratios throughout the day in New Orleans.

```python
plt.figure(figsize=(10,6))
with_time_pitt = pittcrime.copy()
with_time_pitt['subject_race'] = with_time_pitt['subject_race'].replace(['asian/pacific islander', 'hispanic', 'black', 'other', 'unknown'], 'non-white')
with_time_pitt['time'] = pd.to_datetime(with_time_pitt['time'])
with_time_pitt['time'] = with_time_pitt['time'].dt.hour
sns.countplot(x='time', hue='subject_race', data=with_time_pitt.sort_values(by='subject_race'))
plt.xticks(rotation=70)
plt.title('Count of Stops by Race Throughout Time of Day (Pittsburgh)');
```

![png](output_41_0_new.png)

In Pittsburgh, we see the most interesting results. Throughout the day time hours we see more white subjects stopped. However, as it gets into night time, we see a greater percentage of those stopped being non-white and from midnight to 3am, non-white subjects make up a majority of those stopped. However in contrast to New Orleans and San Francisco, the number of people stopped is far lower at night versus the day.

From these graphs, we find that the relative rates of stoppage for non-white versus white subjects change dependent on the time of day in San Francisco and Pittsburgh. This difference in ratio dependent on time of day could possibly indicate police bias and warrants further study to determine the cause.

## **Modeling**
#### Modeling and analysis will be evaluated based on appropriateness to question, clarity in explanation of model and the reasons for using it, and the exposition of the relationship between the team’s modeling efforts and the conclusions the team draws.

In particular, we seek to see if there is underlying discrimination (eg. racial, gender, etc) based on the frequency of stops in each of these cities. From the Exploratory Data Analysis performed above, it is already clear that each of the select cities: San Francisco, Pittsburgh, and New Orleans has varying demographics and distribution of stops.

Since our goal of identifying possible underlying discrimination in policing is a broad topic, here are some variables that we took into consideration:

- **Severity of the Crime** (ie. if the stop resulted in a warning, citation, or an arrest in order of increasing severity)
- **Time of Day** (ie. when does the crime occur? is there a distinction between crimes occuring during night or day?
- **Type of Stop** (ie. pedestrian, vehicular, etc)
- **Subject Age** (ie. age of the person stopped)

**To promote fair comparisons, the following considerations were taken into account during standardization/cleaning of the data:**

- Based on the availability of data, only data from the years 2010-2015 will be used.
- By the sheer volume of data, and since the total number of citations varied in each of the cities, a random sample of 200,000 stops will be taken from each city.
- "Unknown" or NaN values listed under subject race will be dropped from the datasets.
- Implementing a the 24-hour time, where the minutes become fractions of the hour.
- Implement One-Hot Encoding on the "outcomes" column for its 3 outcomes: arrest, citation, and warning and on the "type" column for its 2 types: vehicular, pedestrian.

```python
sfcrime = sfcrime[["date", "time", "subject_age", "subject_race", "subject_sex", "type", "outcome", "citation_issued", "warning_issued", 'arrest_made', "reason_for_stop"]]
sf_crime = sfcrime.iloc[sfcrime.dropna().index, :]
random.seed(30)
sf_crime_resampled = sf_crime.sample(200000)
```

```python
sf_crime_resampled[['citation_issued',"warning_issued", "arrest_made"]] = sf_crime_resampled[['citation_issued',"warning_issued", "arrest_made"]].astype(int)
sf_crime_resampled['vehicular'] = (sf_crime_resampled['type']=='vehicular').astype(int)
sf_crime_resampled['pedestrian'] = (sf_crime_resampled['type']=='pedestrian').astype(int)

sf_crime_resampled['time'] = pd.to_datetime(sf_crime_resampled['time'])
sf_crime_resampled['time'] = sf_crime_resampled['time'].dt.hour + sf_crime_resampled['time'].dt.minute/60
sf_crime_resampled.head()
```

      date
      time
      subject_age
      subject_race
      subject_sex
      type
      outcome
      citation_issued
      warning_issued
      arrest_made
      reason_for_stop
      vehicular
      pedestrian

      496292
      2011-04-23
      1.966667
      30.0
      asian/pacific islander
      male
      vehicular
      warning
      0
      1
      0
      Moving Violation
      1
      0

      697863
      2013-09-05
      1.500000
      26.0
      white
      male
      vehicular
      citation
      1
      0
      0
      Moving Violation
      1
      0

      543063
      2011-10-04
      23.833333
      20.0
      asian/pacific islander
      female
      vehicular
      warning
      0
      1
      0
      Moving Violation
      1
      0

      478772
      2011-02-21
      14.000000
      26.0
      hispanic
      male
      vehicular
      citation
      1
      0
      0
      Moving Violation
      1
      0

      183677
      2008-05-29
      12.216667
      60.0
      white
      male
      vehicular
      citation
      1
      0
      0
      Mechanical or Non-Moving Violation (V.C.)
      1
      0

```python
nola_crime = nola_crime[["date", "time", "subject_age", "subject_race", "subject_sex", "type", "outcome", "citation_issued", "warning_issued", 'arrest_made', "reason_for_stop"]]
nola_crime = nola_crime.iloc[nola_crime.dropna().index, :]
random.seed(30)
nola_crime_resampled = nola_crime.sample(200000)
```

```python
nola_crime_resampled[['citation_issued',"warning_issued", "arrest_made"]] = nola_crime_resampled[['citation_issued',"warning_issued", "arrest_made"]].astype(int)
nola_crime_resampled['vehicular'] = (nola_crime_resampled['type']=='vehicular').astype(int)
nola_crime_resampled['pedestrian'] = (nola_crime_resampled['type']=='pedestrian').astype(int)

nola_crime_resampled['time'] = pd.to_datetime(nola_crime_resampled['time'])
nola_crime_resampled['time'] = nola_crime_resampled['time'].dt.hour + nola_crime_resampled['time'].dt.minute/60
nola_crime_resampled.head()
```

      date
      time
      subject_age
      subject_race
      subject_sex
      type
      outcome
      citation_issued
      warning_issued
      arrest_made
      reason_for_stop
      vehicular
      pedestrian

      441600
      2013-11-05
      18.500000
      23.0
      black
      male
      vehicular
      arrest
      1
      0
      1
      TRAFFIC VIOLATION
      1
      0

      308926
      2017-08-01
      16.966667
      22.0
      black
      female
      vehicular
      citation
      1
      0
      0
      TRAFFIC VIOLATION
      1
      0

      327897
      2017-08-14
      1.733333
      49.0
      black
      female
      vehicular
      warning
      0
      1
      0
      TRAFFIC VIOLATION
      1
      0

      476436
      2015-12-02
      17.066667
      27.0
      black
      male
      vehicular
      warning
      0
      1
      0
      TRAFFIC VIOLATION
      1
      0

      464300
      2017-11-22
      23.900000
      20.0
      black
      male
      vehicular
      arrest
      0
      0
      1
      TRAFFIC VIOLATION
      1
      0

```python
pitt_crime = pittcrime[["date", "time", "subject_age", "subject_race", "subject_sex", "type", "outcome", "citation_issued", "warning_issued", 'arrest_made', "reason_for_stop"]]
pitt_crime = pitt_crime.iloc[pitt_crime[['subject_race', 'subject_age']].dropna().index, :]
pitt_crime = pitt_crime.sample()
pitt_crime
```

      date
      time
      subject_age
      subject_race
      subject_sex
      type
      outcome
      citation_issued
      warning_issued
      arrest_made
      reason_for_stop

      47015
      2018-02-20
      20:59:00
      46.0
      white
      NaN
      pedestrian
      NaN
      False
      False
      False
      narcVice vehicleCodeViolation

Upon further analysis of the Pittsburgh dataset, there were too many null values to use this dataset. Since our chosen features included the the subject age and race, simply dropping the null values meant that a majority of the dataset was also discarded. In the cell above, only one instance included information on both the race and the age. If the outcome null values were also dropped in this instance, none of the stops in the Pittsburgh dataset would be viable for our analysis.

**Therefore, our model and analysis will be limited to San Francisco and New Orleans.**

## **Logistic Regression Classifier**

### **Why logistic regression?**
We have incorporated logistic regression and naive bases to the analysis regarding the overall accuracy and fairness of police stops as it pertains to race. The inputs that we would receive would be both categorical and quantitative. Furthermore, we chose a no-regularization logistic regression for the baseline of the model. Since this analysis aims to perform classification, the essence of a logistic regression model is designed on a certain event that would exist or not. In our project, the logistic regression model aims to delineate between a binary result (1 for white vs. 0 for non-white individuals). In essence, underlying racial discrimination will be classified based on trends in features that will predict if the police stop was for a white individual or non-white minority individual. A similar analysis may also be done based on gender. Furthermore, logistic regression would be used to find the relationships between dependent variables and other independent or nominal variables.

To implement logistic regression, the subject_race column is transformed into a binary format: 1 for white vs. 0 for non-white individuals.

```python
sf_crime_resampled['race_binary'] = (sf_crime_resampled['subject_race'] == 'white').astype(int)
sf_crime_resampled.head()
```

      date
      time
      subject_age
      subject_race
      subject_sex
      type
      outcome
      citation_issued
      warning_issued
      arrest_made
      reason_for_stop
      vehicular
      pedestrian
      race_binary

      496292
      2011-04-23
      1.966667
      30.0
      asian/pacific islander
      male
      vehicular
      warning
      0
      1
      0
      Moving Violation
      1
      0
      0

      697863
      2013-09-05
      1.500000
      26.0
      white
      male
      vehicular
      citation
      1
      0
      0
      Moving Violation
      1
      0
      1

      543063
      2011-10-04
      23.833333
      20.0
      asian/pacific islander
      female
      vehicular
      warning
      0
      1
      0
      Moving Violation
      1
      0
      0

      478772
      2011-02-21
      14.000000
      26.0
      hispanic
      male
      vehicular
      citation
      1
      0
      0
      Moving Violation
      1
      0
      0

      183677
      2008-05-29
      12.216667
      60.0
      white
      male
      vehicular
      citation
      1
      0
      0
      Mechanical or Non-Moving Violation (V.C.)
      1
      0
      1

```python
nola_crime_resampled['race_binary'] = (nola_crime_resampled['subject_race'] == 'white').astype(int)
nola_crime_resampled.head()
```

      date
      time
      subject_age
      subject_race
      subject_sex
      type
      outcome
      citation_issued
      warning_issued
      arrest_made
      reason_for_stop
      vehicular
      pedestrian
      race_binary

      441600
      2013-11-05
      18.500000
      23.0
      black
      male
      vehicular
      arrest
      1
      0
      1
      TRAFFIC VIOLATION
      1
      0
      0

      308926
      2017-08-01
      16.966667
      22.0
      black
      female
      vehicular
      citation
      1
      0
      0
      TRAFFIC VIOLATION
      1
      0
      0

      327897
      2017-08-14
      1.733333
      49.0
      black
      female
      vehicular
      warning
      0
      1
      0
      TRAFFIC VIOLATION
      1
      0
      0

      476436
      2015-12-02
      17.066667
      27.0
      black
      male
      vehicular
      warning
      0
      1
      0
      TRAFFIC VIOLATION
      1
      0
      0

      464300
      2017-11-22
      23.900000
      20.0
      black
      male
      vehicular
      arrest
      0
      0
      1
      TRAFFIC VIOLATION
      1
      0
      0

**To perform modeling and analysis on our dataset, the dataset will be split into a training, validation, and test set:**

- Training set 70%
- Validation set 15%
- Test set 15%

### ***San Francisco***

```python
#SF features matrix
X_sf = sf_crime_resampled[['subject_age', 'time', 'citation_issued', "warning_issued", "arrest_made", 'vehicular', 'pedestrian']]
y_sf = sf_crime_resampled['race_binary']
```

```python
# Train/Test Split
X_sf_train, X_sf_test, y_sf_train, y_sf_test = train_test_split(X_sf, y_sf, train_size = .70, test_size = .30)

# Train/Validation Split
X_sf_test, X_sf_validate, y_sf_test, y_sf_validate = train_test_split(X_sf_test, y_sf_test, train_size = .50, test_size = .50)
```

```python
log_reg = LogisticRegression()
log_model = log_reg.fit(X_sf_train, y_sf_train)
log_pred = log_model.predict(X_sf_train)
log_reg_confusion_matrix = confusion_matrix(y_sf_train, log_pred)
```

![png](output_54_1.png)

![png](output_54_2.png)

```python
log_model.score(X_sf_validate, y_sf_validate)
```

    0.5872

### ***New Orleans***

```python
#New Orleans features matrix
X_nola = nola_crime_resampled[['subject_age', 'time', 'citation_issued', "warning_issued", "arrest_made", 'vehicular', 'pedestrian']]
y_nola = nola_crime_resampled['race_binary']
```

```python
# Train/Test Split
X_nola_train, X_nola_test, y_nola_train, y_nola_test = train_test_split(X_nola, y_nola, train_size = .70, test_size = .30)

# Train/Validation Split
X_nola_test, X_nola_validate, y_nola_test, y_nola_validate = train_test_split(X_nola_test, y_nola_test, train_size = .50, test_size = .50)
```

```python
log_reg = LogisticRegression()
log_model = log_reg.fit(X_nola_train, y_nola_train)
log_pred = log_model.predict(X_nola_train)
```

```python
log_reg_confusion_matrix_nola = confusion_matrix(y_nola_train, log_pred)
# Plot non-normalized confusion matrix
plt.figure()
plot_confusion_matrix(log_reg_confusion_matrix_nola, classes=class_names,
                      title='Confusion Matrix')

# Plot normalized confusion matrix
plt.figure()
plot_confusion_matrix(log_reg_confusion_matrix_nola, classes=class_names, normalize=True,
                      title='Normalized Confusion Matrix')
```

![png](output_60_1.png)

![png](output_60_2.png)

```python
log_model.score(X_nola_validate, y_nola_validate)
```

    0.7420666666666667

## **Ridge Regression Classifier**

### **Why Ridge Regression?**
Ridge regression is a type of squared loss regression used when the number of predictors exceeds the number of observations (eg. p>n) and when the model experiences multicollinearity. Since both p>n and multicollinearity are issues when using linear least squares regression, ridge regression would be used instead. Ridge regression works by using a shrinkage estimator that essentially would produce new estimates that are "shrunk" to the population's true parameters. It is a L2 "squared" regularization that adds a penalty equal to the squared magnitude of the coefficients. A tuning parameter 𝜆  would determine the strength of this penalty. The constraints put on each of the estimators helps to shrink extreme variance and fluctuations; this sacrifices training accuracy for a model that is likely to generalize better. In other words, ridge regression introduces enough bias that shrinks variance to make estimates closer to the true population values.

Here, we try to improve upon the logistic model. RidgeClassifier is a classifier variant of the Ridge regressor (provided by scikit-learn), and can be much faster than logistic regression. It is used below in place of the **sklearn.linear_model.Ridge()** model.

### ***San Francisco***

```python
ridge = RidgeClassifier()
ridge_model = ridge.fit(X_sf_train, y_sf_train)
ridge_pred = ridge_model.predict(X_sf_train)
```

```python
ridge_confusion_matrix_sf = confusion_matrix(y_sf_train, ridge_pred)
# Plot non-normalized confusion matrix
plt.figure()
plot_confusion_matrix(ridge_confusion_matrix_sf, classes=class_names,
                      title='Confusion Matrix')

# Plot normalized confusion matrix
plt.figure()
plot_confusion_matrix(ridge_confusion_matrix_sf, classes=class_names, normalize=True,
                      title='Normalized Confusion Matrix')
```

![png](output_66_1.png)

![png](output_66_2.png)

```python
ridge_model.score(X_sf_validate, y_sf_validate)
```

    0.5870333333333333

### ***New Orleans***

```python
ridge_nola = RidgeClassifier()
ridge_nola_model = ridge_nola.fit(X_nola_train, y_nola_train)
ridge_nola_pred = ridge_nola_model.predict(X_nola_train)
```

```python
ridge_confusion_matrix_nola = confusion_matrix(y_nola_train, ridge_nola_pred)
# Plot non-normalized confusion matrix
plt.figure()
plot_confusion_matrix(ridge_confusion_matrix_nola, classes=class_names,
                      title='Confusion Matrix')

# Plot normalized confusion matrix
plt.figure()
plot_confusion_matrix(ridge_confusion_matrix_nola, classes=class_names, normalize=True,
                      title='Normalized Confusion Matrix')
```

![png](output_70_1.png)

![png](output_70_2.png)

```python
ridge_nola_model.score(X_nola_validate, y_nola_validate)
```

    0.7420666666666667

## **One-Hot Encoding**

What follows are our attempts at one-hot encoding ```reason_for_stop``` and using resultant columns as additional features as a means of improving accuracy.

In modeling the New Orleans dataset, the logistic model and the ridge regression model scored a validation accuracy of 74.6%.

### **Evaluation Methods**
Our two methods of evaluating our results are using confusion matrices and using the **model.score()** function. In our confusion matrix, we see our true negatives at (0,0) in the matrix, false negatives at (1,0), false positives at (0,1), and true positives at (1,1). True negatives are non-white subjects predicted to be non-white, false negatives are white subjects predicted to be non-white, false positives are non-white subjects predicted to be white, and true positives are white subjects predicted to be white. **model.score()** returns the mean accuracy on the given test data and labels.

### **Interpretation of Results**
We see higher accuracies for our New Orleans models because our models are predicting all values to be non-white. For the New Orleans dataset, this results in higher accuracy because majority of the dataset population (and city population) is non-white. In San Francisco on the other hand, a plurality of the population is white. Thus, our scores just indicate what the percentage of non-white subjects within the dataset. It is of note however, that the percentage of non-white subjects within the dataset is higher than the overall percentage of people of color in New Orleans, suggesting that people of color are stopped at a higher rate than white people, even when you control for percentage of the population.

### **Reflecting on the Chosen Models**
The accuracy of our predictive models for San Francisco are low, in which the model only predicts correctly a little more than half the time. While this may be consequence of the chosen features or the choice of the classifier itself, considerations should also be taken that the features simple do not correlate well with race. Therefore, even adding additional features to the model did not increase the accuracy by a significant amount. Training on additional noise would work to decrease the accuracy. In other words, rather than there being a problem with the model, there may just be little to no underlying racial discrimination in the features that we chose to train the model on.

### **Potential Improvements**
- **Oversampling:** An imbalance in the dataset can be seen from the proportion of whites to other ethnicities. Especially in the New Orleans data set, there are considerably more non-white individuals than white individuals in the sampled training set, which leads the models to tend to exclusively predict subject_race as non-white. A potential solution is to oversample rows with white subjects in our training data to increase the likelihood that the model will predict a white subject. Since one of the primary goals of model validation estimation of how it will perform on unseen data, oversampling correctly is critical.

- **Bootstrapping** Given the imbalance in the datasets (especially in the case of New Orleans) between the white and non-white populations, a method to create more variability in the data would be to bootstrap (random sampling with replacement). In this way, the model would be able to train on more data without having to collect additional data.

- **Important Null values:** In standardizing the data from both the San Francisco and New Orleans datasets, all the Null/NaN/None values were dropped. However, there may be underlying patterns to these dropped values. More exploratory data analysis could be performed to see why certain values failed to appear in the given datasets.


text:
# Josh's 2019 Talk on Web Performance

Hi there!

### Code Snippets

The code samples shown in the presentation can be found in [presentation/code](https://github.com/joshwcomeau/talk-2019/tree/master/presentation/code). They may or may not run. They're mostly meant to be examples, but if something caught your eye in them, have at it!

### Accordion

The live-running code for the accordion can be found in [src/components/Accordion](https://github.com/joshwcomeau/talk-2019/tree/master/src/components/Accordion).

### Twitter Like Button

My twist on the Twitter "like" animation can be found in [src/components/LikeButton](https://github.com/joshwcomeau/talk-2019/tree/master/src/components/LikeButton). The Sprite variant can be found in [src/components/LikeSprite](https://github.com/joshwcomeau/talk-2019/tree/master/src/components/LikeSprite)

### OffscreenCanvas

My talk only briefly mentioned OffscreenCanvas, and truthtfully it's not something I have a perfectly-isolated demo for... but I use it extensively in [Tinkersynth](https://github.com/joshwcomeau/tinkersynth), and its source is open!

---

Thanks, hope you enjoyed my talk!

license: MIT

branch_name: refs/heads/master

extension: md

license_type: permissive


text:
---
date: '2019-04-07T21:05:06+09:00'
tags: [ en, flor, workflow, ruby ]
---

## flor workflow engine

[flor](https://github.com/floraison/flor) is a workflow engine. It's written in Ruby.

A workflow engine is a host for workflow executions, business processes that might last from a few minutes to multiple years.

Such an engine takes as input workflow definitions and an initial set of data and controls the execution "flow" until success or failure.

### tl&dr

Look at [flor's readme](https://github.com/floraison/flor#readme), at its one Ruby file [doc/quickstart0](https://github.com/floraison/flor/tree/master/doc/quickstart0), or at its more <strike>frameworky</strike> complex [doc/quickstart1](https://github.com/floraison/flor/tree/master/doc/quickstart1).

### workflow definitions

At its core, flor is an interpreter for the flor workflow language. The "work" in "workflow" is assumed by taskers. Flor and its language deal with the control flow between taskers.

Flor doesn't use a Ruby DSL or a BPMN diagram to represent its workflows. The flor language is a programming language dedicated to workflows. It has its advantages and disadvantages, as with all pieces of software, we shall hopefully iterate towards a language that covers a large part of its community needs.

Here is an example reporting workflow, it involves five human participants and two automated taskers:
```python
alice 'prepare feedback forms'
concurrence
  eric 'gather customer feedback' timeout: '8d'
  fred 'gather customer feedback' timeout: '8d'
  greg 'gather customer feedback' timeout: '8d'
anonymize_feedback _
loop
  alice 'prepare report'
  brent 'validate report'
  break _ if f.valid
submit_report _
brent 'close report'
```
This example of workflow definition routes work from Alice, [fans out](https://github.com/floraison/flor/blob/master/doc/procedures/concurrence.md) to Eric, Fred, and Greg, giving them each 8 days to gather customer feedback. Once all have replied (or 8 days have elapsed), the feedback is anonymized. A back and forth between Alice and Brent is started, until Brent deems the report ready for submission (by setting the field `valid` to true). Finally Brent closes the report.

The flow definition weaves in calls to taskers, moving tasks from one to the next.

Any number of workflow executions can coexist in a flor instance. A workflow execution in a given version can coexist with a workflow execution following the same definition or any other definition. Executions following the same definition but in different versions can coexist.

### taskers

A tasker is a piece of Ruby code that is called to perform a task. Here is the code behing the `anonymize_feedback _` above:
```ruby
class Acme::AnonymizeFeedbackTasker < Flor::BasicTasker

  def task

    Acme::Models::Forms   #
      .where(exid: exid)  #
      .each(&:anonymize)  # access DB (Sequel style) and anonymize each
      .each(&:save)       # form related to this execution (exid)

    reply                 # hand back task to flor
  end
end
```

The flor language and the taskers try to be orthogonal. Taskers should be easy to test on their own and be usable from multiple workflow definitions.

When flor is set up with a HashLoader, it's fairly easy to directly bind tasker implementations to the names appearing in the workflow definition:
```ruby
FLOR = Flor::Unit.new(
  loader: Flor::HashLoader,
  sto_uri: 'postgres://flor:xxx@localhost/flor')

%w[ alice eric fred greg brent ].each do |user|
  FLOR.add_tasker(user, Acme::HumanTasker)
end
FLOR.add_tasker(:anonymize_feedback, Acme::AnonymizeFeedbackTasker)
FLOR.add_tasker(:submit_report, Acme::SubmitReportTasker)
```

Human taskers are usually placing the incoming task into a worklist, let users edit it and then, when they're done with it, return the task to flor. There is the [florist](https://github.com/floraison/florist) project providing a vanilla flor worklist, but it's work in progress.

### launching

In the case of a web application, the launch of a new workflow execution usually happens in a controller, here is an example [Sinatra](http://sinatrarb.com) POST endpoint:
```ruby
post '/xhr/reports/' do

  exid = FLOR.launch(
    REPORT_FLOW,
    payload: prepare_payload(request))

  content_type 'application/json'
  { exid: exid }.to_json
end
```
Behind the scene, that simply puts a launch message in flor's database and returns quickly the `exid` for the new workflow execution.

### two kinds of configuration

More advanced flor deployments might favour the configuration tree approach demonstrated in [flor/quickstart1/](https://github.com/floraison/flor/tree/master/doc/quickstart1). Taskers and flows are placed in a tree hierarchy mimicking an organization's domain and subdomains. (What stands behind a subflow or a tasker might thus depend in which (sub-)domain the flow is launched).

The example in this post is based on the straightforward [flor/quickstart0/](https://github.com/floraison/flor/tree/master/doc/quickstart0) which spans a simple Ruby file.

### two kinds of setup

The simplest way to deploy flor is within the web application it serves, in the same Ruby process. That's what I use in production, thanks to the wonderful [JRuby](https://www.jruby.org/).

A more classical setup is to have 1 or more Ruby processes dedicated to the web application and 1 or more Ruby processes for flor, a worker process. That's totally fine. The flor unit in the web processes can be instantiated without being started, while the flor unit in the worker processes is started. The flor units share the same database and communicate via it. (See [doc/multi_instance.md](https://github.com/floraison/flor/blob/master/doc/multi_instance.md)).

### flor characteristics

* Written in Ruby
* Not tied to any (web) framework
* Only one major dependency, the excellent [Sequel](https://sequel.jeremyevans.net)

Ruby might be deemed a slow language, but it's fast enough when thinking of business processes spanning long periods of times.

### flor features

* Has support for timeouts and [time scheduling](https://github.com/floraison/flor/blob/master/doc/procedures/schedule.md)
* Workflows can be cancelled completely or in part
* Workflows can be re-applied with newer versions of part of their definition
* Errors handlers can be set at various levels
* Workflows can wait for signals
* etc

### over

If you have any question, please ask in the [flor Gitter room](https://gitter.im/floraison/flor) or via the [GitHub issues](https://github.com/floraison/flor/issues).

repository: jmettraux/blog

gha_language: Ruby

repo_name: jmettraux/blog


text:
# Observatorium

[![CircleCI](https://circleci.com/gh/observatorium/observatorium.svg?style=svg)](https://circleci.com/gh/observatorium/observatorium)
[![Go Doc](https://godoc.org/github.com/observatorium/observatorium?status.svg)](http://godoc.org/github.com/observatorium/observatorium)
[![Go Report Card](https://goreportcard.com/badge/github.com/observatorium/observatorium)](https://goreportcard.com/report/github.com/observatorium/observatorium)

This project is an API server for Observatorium.
The API provides an authenticated and authorized, multi-tenant interface for writing and reading observability signals, i.e. metrics and logs.

## Backends

The Observatorium API server fulfills requests by proxying reads and writes to a backend for each type of observability signal.

### Metrics

The Observatorium API server can serve read and write requests for Prometheus metrics.
In order to handle requests for metrics, a compatible backend must be configured.

#### --metrics.read.endpoint

The backend from which to read metrics can be specified with the `--metrics.read.endpoint` flag.
Compatible backends must implement the Prometheus HTTP API, e.g. Prometheus, Thanos querier, Cortex, etc.

#### --metrics.write.endpoint

The backend to which to write metrics can be specified with the `--metrics.write.endpoint` flag.
Compatible backends must implement the Prometheus remote-write API, e.g. Thanos receiver, Cortex, etc.

### Logs

The Observatorium API server can serve read and write requests for logs.
In order to handle requests for logs, a compatible backend must be configured.

#### --logs.read.endpoint

The backend from which to read logs can be specified with the `--logs.read.endpoint` flag.
Compatible backends must implement the Loki read API, e.g. Loki.

#### --logs.tail.endpoint

The backend from which to tail logs can be specified with the `--logs.tail.endpoint` flag.
Compatible backends must implement the Loki tail API, e.g. Loki.

#### --logs.write.endpoint

The backend to which to write logs can be specified with the `--logs.write.endpoint` flag.
Compatible backends must implement the Loki write API, e.g. Loki.

## Usage

[embedmd]:# (tmp/help.txt)
```txt
Usage of ./observatorium:
  -debug.block-profile-rate int
    	The percentage of goroutine blocking events that are reported in the blocking profile. (default 10)
  -debug.mutex-profile-fraction int
    	The percentage of mutex contention events that are reported in the mutex profile. (default 10)
  -debug.name string
    	A name to add as a prefix to log lines. (default "observatorium")
  -log.format string
    	The log format to use. Options: 'logfmt', 'json'. (default "logfmt")
  -log.level string
    	The log filtering level. Options: 'error', 'warn', 'info', 'debug'. (default "info")
  -logs.read.endpoint string
    	The endpoint against which to make read requests for logs.
  -logs.tail.endpoint string
    	The endpoint against which to make tail read requests for logs.
  -logs.tenant-header string
    	The name of the HTTP header containing the tenant ID to forward to the logs upstream. (default "X-Scope-OrgID")
  -logs.write.endpoint string
    	The endpoint against which to make write requests for logs.
  -metrics.read.endpoint string
    	The endpoint against which to send read requests for metrics. It used as a fallback to 'query.endpoint' and 'query-range.endpoint'.
  -metrics.tenant-header string
    	The name of the HTTP header containing the tenant ID to forward to the metrics upstreams. (default "THANOS-TENANT")
  -metrics.write.endpoint string
    	The endpoint against which to make write requests for metrics.
  -rbac.config string
    	Path to the RBAC configuration file. (default "rbac.yaml")
  -tenants.config string
    	Path to the tenants file. (default "tenants.yaml")
  -tls.cipher-suites string
    	Comma-separated list of cipher suites for the server. Values are from tls package constants (https://golang.org/pkg/crypto/tls/#pkg-constants). If omitted, the default Go cipher suites will be used. Note that TLS 1.3 ciphersuites are not configurable.
  -tls.healthchecks.server-ca-file string
    	File containing the TLS CA against which to verify servers. If no server CA is specified, the client will use the system certificates.
  -tls.healthchecks.server-name string
    	Server name is used to verify the hostname of the certificates returned by the server. If no server name is specified, the server name will be inferred from the healthcheck URL.
  -tls.min-version string
    	Minimum TLS version supported. Value must match version names from https://golang.org/pkg/crypto/tls/#pkg-constants. (default "VersionTLS13")
  -tls.reload-interval duration
    	The interval at which to watch for TLS certificate changes. (default 1m0s)
  -tls.server.cert-file string
    	File containing the default x509 Certificate for HTTPS. Leave blank to disable TLS.
  -tls.server.key-file string
    	File containing the default x509 private key matching --tls.server.cert-file. Leave blank to disable TLS.
  -web.healthchecks.url string
    	The URL against which to run healthchecks. (default "http://localhost:8080")
  -web.internal.listen string
    	The address on which the internal server listens. (default ":8081")
  -web.listen string
    	The address on which the public server listens. (default ":8080")
```

branch_name: refs/heads/main


text:
# addressbook example

A Rust port of [this C++ sample code](https://github.com/sandstorm-io/capnproto/blob/v0.5.3/c%2B%2B/samples/addressbook.c%2B%2B).

Try it like this:

```
$ cargo run write | cargo run read
```

repository: llogiq/capnpc-rust

gha_language: Rust

repo_name: llogiq/capnpc-rust


text:
# React-Redux Todo-App

In this project, I made a Collaborative Todo-App using [React-Redux](https://react-redux.js.org/). In this App, you can assign the Todos for the other person. The Assignee can mark the respected Todo as Done, can edit and delete them also. There would be two parts, one is Projects, where all Projects would be shown, in which the user lie, and the second one is Todos-part, where user can have a look over all the Todos for a particular project. All the Todos are currently storing in the Redux-State, called Store.

## Requirement and Execution
1. First and foremost, open your terminal and type `git clone https://github.com/yogendra3236/React-Redux-Todo-App.git` to clone this repository.

2. Install the necessary dependencies to your app by running `npm install` on the terminal.

3. Launch the development build of the app, by running `npm start` on the terminal.

4. Visit http://localhost:3000 to use the app.
5. Start the Backend server as well. Go to [this repo](https://github.com/yogendra3236/Collaborative-Todo-Backend), to clone it, and after navigating the directory, type `npm install` to install the necessary dependencies.

6. Now, you can start your Backend server, by typing `nodemon server.js` or `node server.js`.

Happy Coding :)

repository: yogendrajs/React-Redux-Todo-App

repo_name: yogendrajs/React-Redux-Todo-App


text:
SWI2C Library
====================

This library implements a software (bit-bang) I2C interface. It was written without any platform-specific code, and should therefore work on any controller platform supported by the Arduino or Energia IDEs.

The MSP430G2 and MSP430FR4133 LaunchPads do not support using both hardware SPI and hardware I2C at the same time. This became a roadblock in one of my projects as I needed to use both types of interfaces for the devices I was using. I tried several different software I2C libraries, but each one that I tried had a shortcoming that was not acceptable for my application:
-  Hardcoded delays
   - Hardcoded delays should not be necessary at the "slow" signaling speeds inherent in a software-based I2C solution
- Lack of or incorrect support of clock stretching
- Improper pin mode settings for indicating a "HIGH" value on SCL or SDA
  - Since I2C is an open-collector design that requires pull-up resistors, a "high" value on the data and clock lines should be implemented by putting the pin in `INPUT` mode. `INPUT` mode does not drive the bus high or low,  and allows the pull-ups to assert the high level.

This library implements the I2C protocol without using any hardcoded delays, properly supports clock-stretching, and uses INPUT mode for a HIGH level.
  - Note that internal protection diodes on the input pins will clamp the signal line to a max of about 0.5 V above the chip's Vcc level. In other words, you cannot use `INPUT` mode to deal with voltage level differences between chips. This library does not support mixing 5V and 3.3V logic without the appropriate level-shifting circuitry.

This library is not a drop-in replacement for Wire. You will therefore need to write your own code for modules that need to use this library. However, the interface is kept simple while still providing low-level signaling functionality to allow tailoring to your specific application.

Since this is a software-based implementation, the clock speed is significantly reduced compared to a hardware-based I2C controller. Expect a clock speed of about 25 KHz when using an 8 MHz controller.

Usage
-----

_Be sure to review the example sketch included with the library._

First, **include** the library header file:

    #include "SWI2C.h"

Next, **instantiate** an object for each I2C device using SWI2C. The device address and I2C pins are defined in the object constructor, so you need a separate object for each device. Note that this is different from the way that the Wire library operates.

`sda_pin` is the pin number for the SDA signal, `scl_pin` is the pin number for the SCL signal, and `deviceID` is the 7-bit device address of the I2C device represented by this object instance. `deviceID` does *not* include the read/write bit.

    SWI2C myDevice(uint8_t sda_pin, uint8_t scl_pin, uint8_t deviceID);

Then, **initialize** the hardware before using the I2C device:

    myDevice.begin();

#### High Level Library Methods ####

The following library functions are used to read and write data to the device:

    int myDevice.writeToRegister(int regAddress, uint8_t data);

Writes an 8-bit `data` value to device register `regAddress`. The function always returns 1.

    int myDevice.write2bToRegister(int regAddress, uint16_t data);

Writes a 16-bit `data` value to device register `regAddress`. The first byte written is the least signifcant byte of `data`. The function always returns 1.

    int myDevice.write2bToRegisterMSBFirst(int regAddress, uint16_t data);

Same as `write2bToRegister()`, except that the first byte written is the most signifcant byte of `data`. The function always returns 1.

    int myDevice.read1bFromRegister(int regAddress, uint8_t* data);

Reads 8-bit value from register address `regAddress` into the location pointed to by `data`. The function always returns 1.

    int myDevice.read2bFromRegister(int regAddress, uint16_t* data);

Reads 16-bit value from register address `regAddress` into the location pointed to by `data`. The function always returns 1. This function assumes that the first byte received is the least significant byte.

    int myDevice.read2bFromRegisterMSBFirst(int regAddress, uint16_t* data);

Same as `read2bFromRegister()`, except the first byte received is the most significant byte.

    readBytesFromRegister(int regAddress, uint8_t* data, uint8_t count);

Reads `count` number of bytes from from register address `regAddress` into `data`. `data` must defined to have at least `count` elements. Bytes received are placed in `data` LSB first (i.e., the first byte received is put in data[0], second byte is data[1], etc.).

#### Lower Level Methods ####

Although general I2C communication can be done with the above `readFrom` and `writeTo` methods, there may be times where more direct control of the protocol is required. The following public methods are also available in the SWI2C class:

    void sclHi();
    void sclLo();
    void sdaHi();
    void sdaLo();

The above functions are self-explanatory -- they set the SCL or SDA lines HIGH or LOW.

    void startBit();
Signals a START bit on the I2C bus.

    void writeAddress(int r_w);
Writes the 7-bit device address along with either a read (1) or write (0) bit, for a total of 8 bits.

    uint8_t checkAckBit();
Returns the value of the ACK bit received (either 1 or 0). This function is also used to send a NACK from the master when reading the last byte from the slave device.

    void writeAck();
Writes an ACK bit -- used by the master between bytes of a multi-byte read operation. The final byte is indicated by an ACK from the master (see `checkAckBit()` above).

    void writeRegister(int regAddress);
Writes the 8-bit `regAddress` value to the SDA bus.

    void stopBit();
Signals a STOP bit on the I2C bus.

    uint8_t read1Byte();
Returns an 8-bit value read from the I2C bus.

    uint16_t read2Byte();
Returns a 16-bit value read from the I2C bus. This first byte received is assumed to be the least significant byte.

    void writeByte(int data);
Writes an 8-bit `data` value to the I2C bus.

    void setStretchTimeout(unsigned long t);
Sets the clock stretching timeout to `t` milliseconds. The default timeout is 500 ms when the SWI2C object is created. If the timeout value is set to zero, then the library will wait indefinitely for the clock to be released by the device.

    unsigned long getStretchTimeout();
Read the current clock stretching timeout value.

    unsigned long checkStretchTimeout();
Check if a previous clock operation resulted in a timeout. Returns non-zero if the timeout was reached waiting for the SCL line to go high. The error will remain set internally until this function is called. Reading the value (by calling this function) clears the error.

Implementation Details
----------------------

The library does not use any platform-specific code. All I/O functions use standard Arduino `pinMode()`, `digitalRead()`, and `digitalWrite()` functions. Reading and writing to the I2C device is accomplished by stringing together the basic signaling primitives specified by the protocol.

There are no hardcoded delays in the code. In order to support clock-stretching, there is a busy-wait loop in the `sclHi()` method which waits until the SCL line actually goes high before exiting the function. There is a default timeout of 500 ms before the wait times out and the function returns. This delay can be changed on a per-device basis (`setStretchTimeout()`). It can also be set to zero if no timeout is desired (which could potentially cause the library to "lock up" if the I2C device does not properly release the SCL line).

#### Future Updates ####

Future potential library updates:
- Additional error checking
- Generic size of read/write data bytes
  - This is currently possible using the lower-level functions contained in the library. A future update may include a single-function-call method in addition to the current single and 2-byte data reads and writes.

References
---------------------

+ NXP [I2C Bus Specification and User Manual](https://www.nxp.com/docs/en/user-guide/UM10204.pdf)
+ Texas Instruments [I2C Application Report](http://www.ti.com/lit/an/slva704/slva704.pdf)
+ [Clock Stretching](https://www.i2c-bus.org/clock-stretching/)


text:
# Microservices
TheConnMan's venture into microservices

This repo represents a collection of microservices for a very basic distributed message processing system. The app will be boring, but the system will be cool (I hope).

![Frontend](/resources/Frontend.png)

Screenshot of Kitematic showing a few of the Docker containers running

![Kitematic](/resources/Kitematic.png)

## Architecture Diagram
![Poorly Drawn Architecture Diagram](/resources/Architecture.jpg)

## Toolstack
- AngularJS
- Node.js
- RabbitMQ
- Grails
- MySQL
- Docker

## Usage
- Set up Docker for your machine
- Run `docker-compose up -d`
- Wait until all containers are up and the **rest-server** logs read:
  > Grails application running at [http://localhost:8080](http://localhost:8080) in environment: production

- Go to the Docker VM IP address
- [Optional] Scale up or down the worker count with `docker-compose scale worker=x` where `x` is the number of workers you want running

## License
MIT as always

repository: TheConnMan/microservices

repo_name: TheConnMan/microservices


text:
# Apple iPhone SE - Rotation

This project is created by **CodingStartup** as a tutorial. Tutorial video can be found here:
- YouTube: [https://www.youtube.com/watch?v=JG09YV_VuAI](https://www.youtube.com/watch?v=JG09YV_VuAI)
- BiliBili: [https://www.bilibili.com/video/BV1JA411t7E9](https://www.bilibili.com/video/BV1JA411t7E9)

CodePen version of this project can be found at [https://codepen.io/stevenlei/pen/wvKYwgZ](https://codepen.io/stevenlei/pen/wvKYwgZ).

## Installation

Ensure you have a recent version of [node & npm](https://nodejs.org/en/download/) or [yarn](https://yarnpkg.com/en/docs/install) installed.

All of the following steps run on the command line within this directory. You can substitute `npm` for `yarn` depending on your preferences.

Install all the necessary packages:

```
npm install
```

## Build

To build for distribution:

```
npm run build
```

All of the final output will be dropped into the [/dist/](./dist) folder.

## Server

Run a local server that will automatically compile your code & refresh when you save a change!

```
npm run serve
```

---

## CodingStartup Channels

Please subscribe to my channel, thank you for your support!

- YouTube Channel: [https://www.youtube.com/codingstartup](https://www.youtube.com/codingstartup)
- BiliBili Channel: [https://space.bilibili.com/451368848](https://space.bilibili.com/451368848)

repository: codingstartup/iphone-se-rotation

repo_name: codingstartup/iphone-se-rotation


text:
# Contributing to Gisida

The following is a set of guidelines for contributing to Gisida. Changes to this document can be proposed via a pull request.

### Table of contents

[Branch naming](#branch-naming)

[Creating an issue](#creating-an-issue)

[Don't](#dont)

## Branch naming

A branch is named by separating various parts with a forward slash. The structure of a branch name is as follows

`group-token/issue-number_awesome-branch-name`

e.g **feature/300_layer-builder**

The following are tokens that can be used and their meaning:

**bug**: Malfunctions that should be fixed to comply with the expected behaviour

**enhancement**: Improvement of an existing feature

**feature**: A new feature

## Creating an issue

### Before creating an issue

- Use the search feature to make sure there issue doesn’t already exist. If this does happen though, close the less thorough issue and include a comment e.g **Duplicate of #123**

### How do I create a good issue?

- Keep the titles short and descriptive. Have the specific details in the issue descripion.

- Avoid issues that contain too much detail. Split a complex issue.

- Mention relevant people _@username_ if necessary.

- Add information that can help clarify the issue e.g screenshots of Javascript errors and warnings.

- In case of a bug, give as details as possible of how to reproduce the bug and the expected behaviour.

## Don't Do

- Don't create a merge request if your source branch has commented out code.

- Don't use long and descriptive names when creating issues and pull requests.

repository: onaio/gisida

gha_language: JavaScript

repo_name: onaio/gisida


text:
## YYYY

### What

Yet another Yan Yan Yahuoku, another unofficial web client of [Japanese Yahoo! Auction](https://auctions.yahoo.co.jp/), [hosted on HEROKU](https://yyygql.herokuapp.com/), [source code on GitHub](https://github.com/piglovesyou/yyy).

### Why

It's hard to list articles **only newly posted** in Yahoo! Auction. Officially it provides a notification system on specific keywords, but I want to check up one by one in their pictures in some kinds, such as apparel.

### How

JSDom scraping + Twitter login + Redis storage. In YYYY you can query articles and **archive** them to not be listed anymore, so that you can always list new products.

[This](https://github.com/piglovesyou/yyy/blob/master/src/data/schema.js#L216) is the core logic to collect articles with archives in mind. The cursor handles seamless pagination in background.

#### Technology Stack

* Node
	* Server-side Rendering
	* GraphQL
    * Apollo Server
	* Apollo Client
		* Optimistic response
		* Skelton screen
	* React
    * react-list
    * react-list-lazy-load
	* JSDom for scraping, since Yahoo! Auction stopped to provide API in early 2018 :(
	* [React Starter Kit](https://github.com/kriasoft/react-starter-kit) as a project base structure
* Redis
* Twitter API
* Heroku

### License

MIT

repository: piglovesyou/yyy

gha_license_id: MIT

repo_name: piglovesyou/yyy


text:
# Using the BitPay plugin for ZenCart

## Prerequisites

* Last Cart Version Tested: 1.5.1

You must have a BitPay merchant account to use this plugin.  It's free to [sign-up for a BitPay merchant account](https://bitpay.com/start).

## Installation

Download the zip file for this plugin, unzip the arcive and copy the files into the ZenCart directory on your webserver.

## Configuration

* Create an API key at bitpay.com under your My Account section.
* In Admin panel under "Modules > Payment > Bitcoins" click Install.
* Fill out all configuration information:
  * Verify that the module is enabled.
  * Set the API key to the value you created in step 1.
  * Select a transaction speed.  The high speed will send a confirmation as soon as a transaction is received in the bitcoin network (usually a few seconds).  A medium speed setting will typically take 10 minutes.  The low speed setting usually takes around 1 hour.  See the bitpay.com merchant documentation for a full description of the transaction speed settings: https://bitpay.com/downloads/bitpayApi.pdf

  * Choose a status for unpaid and paid orders (or leave the default values as defined).

  * Verify that the currencies displayed correspond to what you want and to those accepted by bitpay.com (the defaults are what bitpay accepts as of this writing).

  * Choose a sort order for displaying this payment option to visitors.  Lowest is displayed first.

## Usage

When a shopping chooses the Bitcoin payment method, they will be presented with an order summary as the next step (prices are shown in whatever currency they've selected for shopping). Upon receiving their order, the system takes the shopper to a bitpay.com invoice where the user is presented with bitcoin payment instructions.  Once payment is received, a link is presented to the shopper that will take them back to your website.

In your Admin control panel, you can see the orders made with Bitcoins just as you would any other order.  The status you selected in the configuration steps above will indicate whether the order has been paid for.

**Note:** This extension does not provide a means of automatically pulling a current BTC exchange rate for presenting BTC prices to shoppers.


text:
# Dice-Simulator
Dice Simulator using python and tkinter

For the application we used the Tkinter module present in python which helps develop the Graphic User Interface (GUI) environment for the application. Python offers a fast and easy way of creating GUI applications when combined with Tkinter. Tkinter provides various widgets such as frames, labels, buttons, check buttons, radio buttons, entries and combo boxes.

Function used : random.randint() : This function generates a random number in the given range.


text:
---
title: "ABOUT"
permalink: /about/
layout: single
subtitle: "about me"
date: 2021-02-07 22:44
# background:
tag: [Github io]
---

> I'm a ... !

# ☎ Contact information

📧<EMAIL_ADDRESS>
🔖  instagram

🔗 LinkedIn

# **👩🏻💻** Work experience

## Title

***Company**, Location – (Dates)*

Your description here

# 🛠 Skills

## 💻 Technology

### Javascript ⭐⭐⭐⭐

<!-- My "native" programming language, I've worked with it for over 6 years. I've used it in the front-end with React and Redux, in the back-end for APIs with Node, Express and Hapi.js and for testing automation using Mocha and later on, Jest. -->

## 🗣 Languages

### Korean 🇰🇷

Native speaker

### English 🇺🇸

# 📜 Articles and Talks

# 📚 Education

## SKKU

*2019*


text:
# Third Party Notices and Information

## Node modules

License and other copyright information for each module is included in the image under `node_modules/{module}`.

More information for each package can be found at `https://www.npmjs.com/package/{package}`.

## Gatsby's blog starter

License and other copyright information is included in `licenses/gatsby-starter-blog`.

More information can be found in [the project's code repository](https://github.com/gatsbyjs/gatsby-starter-blog).

repository: GregBrimble/elder-cactus

repo_name: GregBrimble/elder-cactus


text:
# Short description
Custom Business Rule + sample application for retrieving report data as an html table to send it via mail.

# Custom Business Rule for retrieving report data
## State
Beta version, needs more testing but works quite well.
## Remarks
1. An `InternalError: Object reference not set to an instance of an object.` may be thrown if:
    -  The user does not have permissions for the (private) view / the view does not exist
    - Some fields/calculated fields will cause this error, when the report data is retrieved using the API. This needs more testing to identify the problems.
    - For some reason the default `created` columns cause an error, but a calculated field returning the value does work

If this error is throws you can verify that the error is caused by the API by using the OpenAPI interface at [Portal_address]/api

2. The columns Step, Form and Workflow return the Id instead of the name. A workaround for this is to create a calculated field which just returns STP_Name,DTYPE_Name,WF_Name

## Sample SQL statement executed for a report
The below statement is executed once a report is accessed. Calculated columns are named underscoreNumber (_##) and added to the statement.
```sql
exec sp_executesql N' SELECT * FROM (
SELECT

  /*COLUMNS*/
WFD_ID,
CONVERT(varchar(20),WFD_ID) as WFD_ID_String,
WFD_Signature,
DEF_ID,
WFD_RowVersion,
ISNULL(TranslatesSteps.TRANS_Name,ISNULL(SecondaryTranslatesSteps.TRANS_Name,STP_Name)) as STP_Name,
STP_ID,
isnull(
    (select top 1 isnull(WFT_UserName,WFT_User) from dbo.WFElementTasks  where WFT_WFDID=WFD_ID and WFT_WFHID is null and WFT_Isfinished=0 and WFT_AssignTypeID in (1,2) and WFT_OrgID is null and WFT_User = @currentloginname),
    (select top 1 isnull(WFT_UserName,WFT_User) from dbo.WFElementTasks where WFT_WFDID=WFD_ID and WFT_WFHID is null and WFT_Isfinished=0 and WFT_AssignTypeID in (1,2) and WFT_OrgID is null order by isnull(WFT_UserName,WFT_User))
  ) as AssignedPerson,
dbo.ClearWFElemAdvLanguage(ISNULL(WFD_AttChoose16, ''''), ''en'') as WFD_AttChoose16,
dbo.ClearWFElemIDAdv(ISNULL(WFD_AttChoose16, '''')) as WFD_AttChoose16_ID,
ISNULL(WFD_AttChoose16, '''') as WFD_AttChoose16_BPS,
datediff(d,WFD_EnterToCurrentStepDate,dbo.GetDbDate()) as WFD_StepDuration,
ISNULL(WFD_AttText1, '''') as WFD_AttText1,
dbo.ClearWFElemAdv(ISNULL(WFD_AttChoose6, '''')) as WFD_AttChoose6,
dbo.ClearWFElemIDAdv(ISNULL(WFD_AttChoose6, '''')) as WFD_AttChoose6_ID,
ISNULL(WFD_AttChoose6, '''') as WFD_AttChoose6_BPS,
ISNULL(WFD_AttText3, '''') as WFD_AttText3,
dbo.ClearWFElemAdv(ISNULL(WFD_AttChoose7, '''')) as WFD_AttChoose7,
dbo.ClearWFElemIDAdv(ISNULL(WFD_AttChoose7, '''')) as WFD_AttChoose7_ID,
ISNULL(WFD_AttChoose7, '''') as WFD_AttChoose7_BPS,
dbo.ClearWFElemAdv(ISNULL(WFD_AttChoose2, '''')) as WFD_AttChoose2,
dbo.ClearWFElemIDAdv(ISNULL(WFD_AttChoose2, '''')) as WFD_AttChoose2_ID,
ISNULL(WFD_AttChoose2, '''') as WFD_AttChoose2_BPS,
STP_ID as WFD_Image,
ISNULL(TranslatesDoctypes.TRANS_Name,ISNULL(SecondaryTranslatesDoctypes.TRANS_Name,DTYPE_Name)) as DTYPE_Name,
DTYPE_ID,
ISNULL(TranslatesWorkflows.TRANS_Name,ISNULL(SecondaryTranslatesWorkflows.TRANS_Name,WF_Name)) as WF_Name,
WF_ID,
CONVERT(varchar(16),WFD_TSInsert, 121) as WFD_TSInsert,
CONVERT(varchar(16),WFD_TSInsert, 121) as WFD_TSInsert_DateOnly,
WFD_TsInsert as _1
/*ROWNUMBER*/
, ROW_NUMBER() OVER ( ORDER BY WFD_ID DESC ) as RowNumber /*ROWNUMBER_END*/
  /*COLUMNS_END*/
FROM V_WFElements as wfelems

    LEFT JOIN Translates AS TranslatesSteps ON (STP_ID = TranslatesSteps.TRANS_ELEMID AND TranslatesSteps.TRANS_OBJID = 5 AND TranslatesSteps.TRANS_LANID = 10)
LEFT JOIN Translates AS SecondaryTranslatesSteps ON (STP_ID = SecondaryTranslatesSteps.TRANS_ELEMID AND SecondaryTranslatesSteps.TRANS_OBJID = 5 AND SecondaryTranslatesSteps.TRANS_LANID = 0)
LEFT JOIN Translates AS TranslatesWorkflows ON (WF_ID = TranslatesWorkflows.TRANS_ELEMID AND TranslatesWorkflows.TRANS_OBJID = 3 AND TranslatesWorkflows.TRANS_LANID = 10)
LEFT JOIN Translates AS SecondaryTranslatesWorkflows ON (WF_ID = SecondaryTranslatesWorkflows.TRANS_ELEMID AND SecondaryTranslatesWorkflows.TRANS_OBJID = 3 AND SecondaryTranslatesWorkflows.TRANS_LANID = 0)
LEFT JOIN Translates AS TranslatesDoctypes ON (DTYPE_ID = TranslatesDoctypes.TRANS_ELEMID AND TranslatesDoctypes.TRANS_OBJID = 13 AND TranslatesDoctypes.TRANS_LANID = 10)
LEFT JOIN Translates AS SecondaryTranslatesDoctypes ON (DTYPE_ID = SecondaryTranslatesDoctypes.TRANS_ELEMID AND SecondaryTranslatesDoctypes.TRANS_OBJID = 13 AND SecondaryTranslatesDoctypes.TRANS_LANID = 0)

WHERE WFD_ID IN (
 select wfd_id from WFElements JOIN WFDocTypes ON WFD_DTYPEID = DTYPE_ID JOIN WFSteps ON WFD_STPID = STP_ID
  where WFD_DTYPEID in (69) and WFD_STPID in (171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,199,200,341,342,343,457,458) /*ADVANCEDINNERSEARCH*/ and WFD_IsFinish=0    AND (1=1 )

)

  ) AS Results WHERE RowNumber > @lowerBand AND RowNumber < @upperBand  ORDER BY WFD_ID DESC ',N'@currentloginname nvarchar(36),@lowerBand int,@upperBand int',@currentloginname=N'dummy',@lowerBand=0,@upperBand=51
```

## Test project
I wanted to concentrate on testing, therefore the testing project reads a configuration file with the necessary information. Because of sensitive information this file is stored in the temp folder. Steps to create the file:
1. Build the project
2. Run the PowerShell script `ReportSubscriptions\ReportSubscriptions.Test\WriteConfigurationFile.ps1` and provide the requested information.

Afterwards you can run the testing project.

# Application
State: alpha
WEBCON BPS Version: 2<IP_ADDRESS>

The current application is an alpha version for testing the business rule.
The configuration of the plugin requires the client id and secret of a registered application.
See https://community.webcon.com/posts/post/examples-of-using-rest-api/109 for more details.
![Plugin configuration](./doc/plugin.png)

You can test the plugin by starting a workflow, provide a recipient some subject and the address to the report/view.
The API supports also private views.
![Plugin configuration](./doc/workflowInstance.png)

A sample report and the received mail:
![Plugin configuration](./doc/sample.png)


text:
### MVC net core backend

This backend was made in less than 30 minutes from scratch.

Usage:

- Open the visual studio solution.
- (eventually) install the needed packages from NuGet (Entity Framework Core, Entity Framework Sql In Memory, Entity Framework Sql Server).
- run the solution.

Once the solution is running as expected (without any error), take a look at the localhost assigned port and keep track of it.

- Go back to the quasar project.
- Open the envConfig.json file.
- Edit the API key to match what said above (localhost and port).
- Run the quasar frontend application:
  - `npm run dev`
- Play around with the application.

### Testing

No automated testing was implemented. However, every endpoint was tested with Postman.

Import the POSTMAN collection inside the POSTMAN folder to take advantage of the sample requests.

repository: briosheje/todoMvcFrontend

repo_name: briosheje/todoMvcFrontend


text:
# Understanding Operator Imports

A problem you may have run into in the past when consuming or creating a public library that depends on RxJS is handling operator inclusion. The most predominant way to include operators in your project is to import them like below:

```js
import 'rxjs/add/operator/take';
```

This adds the imported operator to the `Observable` prototype for use throughout your project:

[(Source)](https://github.com/ReactiveX/rxjs/blob/master/src/add/operator/take.ts)

```js
import { Observable } from '../../Observable';
import { take } from '../../operator/take';

Observable.prototype.take = take;

declare module '../../Observable' {
  interface Observable<T> {
    take: typeof take;
  }
}
```

This method is generally *OK* for private projects and modules, the issue arises when you are using these imports in say, an [npm](https://www.npmjs.com/) package or library to be consumed throughout your organization.

### A Quick Example

To see where a problem can spring up, let's imagine **Person A** is creating a public Angular component library. In this library you need a few operators so you add the typical imports:

*some-public-library.ts*
```js
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/concatMap';
import 'rxjs/add/operator/switchMap';
```

**Person B** comes along and includes your library. They now have access to these operators even though they did not personally import them. *Probably not a huge deal but it can be confusing.* You use the library and operators, life goes on...

A month later **Person A** decides to update their library. They no longer need `switchMap` or `concatMap` so they remove the imports:

*some-public-library.ts*
```js
import 'rxjs/add/operator/take';
```

**Person B** upgrades the dependency, builds their project, which now fails. They never included `switchMap` or `concatMap` themselves, it was **just working** based on the inclusion of a 3rd party dependency. If you were not aware this could be an issue it may take a bit to track down.

### The Solution

Instead of importing operators like:

```js
import 'rxjs/add/operator/take';
```

We can instead import them like:

```js
import { take } from 'rxjs/operator/take';
```

This keeps them off the `Observable` prototype and let's us call them directly:

```js
import { take } from 'rxjs/operator/take';
import { of } from 'rxjs/observable/of';

take.call(
  of(1,2,3),
  2
);
```

This quickly gets **ugly** however, imagine we have a longer chain:

```js
import { take } from 'rxjs/operator/take';
import { map } from 'rxjs/operator/map';
import { of } from 'rxjs/observable/of';

map.call(
  take.call(
    of(1,2,3),
    2
  ),
  val => val + 2
);
```

Pretty soon we have a block of code that is near impossible to understand. How can we get the best of both worlds?

### Pipeable Operators

RxJS now comes with a [`pipe`](https://github.com/ReactiveX/rxjs/blob/755df9bf908108974e38aaff79887279f2cde008/src/Observable.ts#L305-L329) helper on `Observable` that alleviates the pain of not having operators on the prototype. We can take the ugly block of code from above:

```js
import { take, map } from 'rxjs/operators';
import { of } from 'rxjs/observable/of';

map.call(
  take.call(
    of(1,2,3),
    2
  ),
  val => val + 2
);
```

And transform it into:

```js
import { take, map } from 'rxjs/operators';
import { of } from 'rxjs/observable/of';

of(1,2,3)
  .pipe(
    take(2),
    map(val => val + 2)
  );
```

Much easier to read, right? This also has the benefit of greatly reducing the RxJS bundle size in your application. For more on this, check out [Ashwin Sureshkumar's](https://twitter.com/Sureshkumar_Ash) excellent article [Reduce Angular app bundle size using lettable operators](https://hackernoon.com/rxjs-reduce-bundle-size-using-lettable-operators-418307295e85).

repository: rjohnvictor/learn-rxjs

gha_language: TypeScript

repo_name: rjohnvictor/learn-rxjs


text:
**NOTE: Make sure you have already cloned original `emba` repository in the `emba` directory**

**NOTE: If you are using docker desktop on a Mac or windows machine. Remove line `network_mode: host` from docker-compose.yml**

**NOTE: If you are using docker desktop windows machine. The database host inside env would be `host.docker.internal`**

**NOTE: For now our compose file is compatible with docker-compose version `1.27.x`. `1.28.x` and `1.29.x` are already available and by default you will end up with latest version unless you specify explicitly while installing. Please install version`1.27.x` untill we fix this**

### Updating environment variables
Refer to `template.env`, you will see the following env variables
```                                                                                1,1           All
1. DATABASE_NAME: Name of the sql database
2. DATABASE_USER: User of the database
3. DATABASE_PASSWORD: For for logging in to the database
4. DATABASE_HOST: host of the database
5. DATABASE_PORT: port
6. MYSQL_ROOT_PASSWORD: Root password. Always equal to DATABASE_PASSWORD for our dev setups
```

We are not maintaining a central copy for now. Till then please main your own copy wherever you setup your dev environment.

### Building and running containers

1. Build your image
`docker-compose build`

2.  Bring your containers up
`docker-compose up -d`

4. Now you can exec into the mysql container and create your database.
```
docker exec -it amos-ss2021-emba-service_auth-db_1 bash
mysql -p
```
When prompted for a password enter the value in `MYSQL_ROOT_PASSWORD`
`Create database <value in DATABASE_NAME>`

5. Restart your containers. This additional step is neccessary since there is no dependency between the containers. And django would try to connect to DB not there yet and fail.
`docker-compose restart emba`

6. Exec into your emba-django container
`docker exec -it amos-ss2021-emba-service_emba_1 bash`

7. Run migrations
```
python3 manage.py makemigrations uploader users
python3 manage.py migrate
```

### Testing Django setup

Test if django application (uWSGI workers) came up
`curl -XGET 'http://<IP_ADDRESS>:8000'`
You should get a response like this:
```<!-- Base Template for home page-->
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <h1>EMBArk home!</h1>
</body>
```

### Updating code
Whenever you change any code in `embark`(django project). You will have to make it live. Since all our code is mounted through compose.
Developers just need to run the following command -
`docker-compose restart emba`

### Exec inside the containers

If you want to run something from inside the container like a shell script to analyze some firmware
1. Paste that firmware inside directory `embark`
2. Exec(Enter) into your container with `docker exec -it amos-ss2021-emba-service_emba_1 bash`
3. Run your script.


text:
# Project description

Modeling and implementation of a Graph Database that represents a dataset collected from Facebook by Stanford University (access [here](https://snap.stanford.edu/data/ego-Facebook.html)) with the Python language. The dataset consists of users, info about their profiles and friendship between them.

# Deployed here

http://viniciuscosta110.pythonanywhere.com/

# Sketch of the graph
![alt text](https://github.com/mateuslatrova/Social-Circles-Graph-Database/blob/main/socialCirclesSketch.jpg)

## :rocket: Technologies

This project was developed with:

- [MySQL](https://www.mysql.com/)
- [Jupyter Notebook](https://jupyter.org/)
- [Cytoscape](https://dash.plotly.com/cytoscape)
- [Networkx](https://networkx.org/)
- [Matplotlib](https://matplotlib.org/)
- [Pandas](https://pandas.pydata.org/)


text:
Ansible Role: vim
=========

This role will:

- clone latest vim code from github, compile and install
- install vimrc file and plugins

Requirements
------------

The target hosts need to have `apt` or `homebrew` to install deb packages.

Role Variables
--------------

Refer to `defaults/main.yml`

Dependencies
------------

None

Example Playbook
----------------

    - name: test role
      hosts: vagrant
      roles:
        - role: vim
          config_src: ~/.vim/vimrc

Also refer to `tests/test.yml`

License
-------

MIT

Author Information
------------------

guoqiao, a Python Developer living in New Zealand.

repository: guoqiao/ansible-role-vim

gha_language: Vim script

repo_name: guoqiao/ansible-role-vim


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

title: "Generating Plausible Counterfactual Explanations for Deep Transformers in Financial Text Classification"
authors: ["Linyi Yang", "Eoin Kenny", "James Ng", "Yi Yang", "Barry Smyth", "Ruihai Dong"]
date: 2020-10-23T00:00:00+08:00
doi: "10.1145/3366423.3380128"

# Schedule page publish date (NOT publication's date).
publishDate: 2020-10-23T00:00:00+08:00

# Publication type.
# Legend: 0 = Uncategorized; 1 = Conference paper; 2 = Journal article;
# 3 = Preprint / Working Paper; 4 = Report; 5 = Book; 6 = Book section;
# 7 = Thesis; 8 = Patent
publication_types: ["1"]

# Publication name and optional abbreviated publication name.
publication: "Proceedings of the COLING-20, 28th International Conference on Computational Linguistics"
publication_short: "In *COLING 2020*"

abstract: ""

# Summary. An optional shortened abstract.
summary: "This paper proposes a novel methodology for producing plausible counterfactual explanations, whilst exploring the regularization benefits of adversarial training on language models in the domain of FinTech. Exhaustive quantitative experiments demonstrate that not only does this approach improve the model accuracy when compared to the current state-of-the-art and human performance, but it also generates counterfactual explanations which are significantly more plausible based on human trials. "

tags: []
categories: []
featured: true

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

#url_pdf: "https://www.aclweb.org/anthology/P19-1276"
url_preprint: "https://arxiv.org/abs/2010.12512"
url_code: "https://github.com/YangLinyi/Explainable-Financial-Text-Classification"
url_dataset: "https://github.com/YangLinyi/Explainable-Financial-Text-Classification"
url_poster:
url_project:
url_slides:
url_source:
url_video:

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

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

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

repository: YangLinyi/academic-kickstart-linyi

repo_name: YangLinyi/academic-kickstart-linyi


text:
# Roof By DXF

Generates a Roof from a DXF Polyline and supplied elevation and thickness values.

|Input Name|Type|Description|
|---|---|---|
|DXF|https://hypar.io/Schemas/InputData.json|DXF format closed LWPolylines representing a roof edge and openings within or aligned with the perimeter.|
|Roof Elevation|number|Roof elevation relative to the zero plane.|
|Roof Thickness|number|Thickness of the Roof.|

|Output Name|Type|Description|
|---|---|---|
|Area|Number|Area of the Roof.|

## Additional Information

repository: hypar-io/BuildingBlocks

gha_language: C#

repo_name: hypar-io/BuildingBlocks


text:
The NodeJS example provided in R1_RESTful_API.js uses the following libraries:
node-rest-client (npm install node-rest-client)
mongodb (https://www.mongodb.org)

The project has examples for most key functions of the API as both GET and POSTS.
There is no requirement to utilize MongoDB for the project, simply leave that code remarked out and/or remove as you see fit.

Future:
Will add code to read/write output from/to csv files for ease of integration.


text:
SimpleJavaCrypter

Simple tool with GUI that can handle following tasks: file and text encryption/decryption, hash sum calculation and file checksum verifier, text encoding. Supports AES128, AES256, DES, 3DES, MD2, MD5, SHA1, SHA224, SHA256, SHA384, SHA512.

## Description

SimpleJavaCrypter is a program written in java which combines a number of useful functions: encryption/decryption of text and files with various algorithms, file and text hashsum calculation and file checksum verifier. There are several encryption algorithms available right now: AES-128, AES-256, DES, 3DES and SimpleCipher. The last one is a simple experimental encryption algorithm that can handle encryption and decryption of the text. Only English language is currently supported. Encryption is performed by an elementary algorithm which randomly changes chars in the given text. Text decryption is done by reverse algorithm. This encryption algorithm is currently under development and would need further work. List of all currently supported algorithms you can see below.

## Features

* Text encryption/decryption.
* File encryption/decryption.
* Generate random keys and secret combinations.
* Get current key.
* Encrypt/decrypt text and files with your own key.
* Simple, nice and adjustable GUI.
* Text hash-sum calculation.
* File hash-sum calculation.
* File checksum verifier.
* GUI drag and drop is supported.
* Dark theme.

## Supported encryption algorithms

* AES128
* AES256
* DES
* 3DES
* SimpleCipher (*under development*)

## Supported hashing algorithms

* MD2
* MD5
* SHA1
* SHA224
* SHA256
* SHA384
* SHA512

## Screenshots

Basic graphical user interface.

Application home page

![SimpleJavaCrypter](https://raw.githubusercontent.com/MasterFlomaster1/SimpleJavaCrypter/master/content/home.png)

## Usage

Text encryption/decryption example:

![SimpleJavaCrypter](https://raw.githubusercontent.com/MasterFlomaster1/SimpleJavaCrypter/master/content/usage1.gif)

File encryption/decryption example:

![SimpleJavaCrypter](https://raw.githubusercontent.com/MasterFlomaster1/SimpleJavaCrypter/master/content/usage2.gif)

## TODO

1) ~~Simplify and improve existing GUI solution, to make it more pretty looking.~~
2) Add more encryption algorithms to work with.
3) ~~Add file encryption/decryption option.~~
4) Finish SimpleCipher algorithm.
5) ~~Add hash calculator function.~~
6) ~~Add file hash checking function.~~
7) ~~Add css.~~
8) Add multithreading.
9) Add more hashing algorithms.

## Requirements

Java 8 and above.

## Contributing and support

Feel free to contribute by opening issues or creating a pull request. Any help is appreciated :)

repository: VSmng/SimpleJavaCrypter

gha_language: Java

repo_name: VSmng/SimpleJavaCrypter


text:
---
title: Understanding CSS3 box-sizing property
date: 2013-07-10
tags:
  - css3
---
Each HTML element is represented as a rectangular box, it consists of margins, borders, padding, and the actual content. The default CSS box model used to calculate widths and heights of elements, the width/height of an element gives the width/height of the content of the box, excluding padding and border.

![Box Model](/assets/posts/box-model.png)

and they are calculated like this:

```Width = width + padding-left + padding-right + border-left + border-right```
```Height = height + padding-top + padding-bottom + border-top + border-bottom```

so if we take this as an example :

```css
.box {
    width: 300px;
    padding: 10px;
    border: 5px solid #e9573f;
    margin: 10px;
}
```
the width of the rendred box will be calculated like this :

```300px (width) + 20px (left + right padding) + 10px (left + right border) + 20px (left + right margin) = 350px```

which will give us a box with 350px width, so in this case you have to change the width of the box to 270px, and this is where the box-sizing property comes to the rescue.

```box-sizing``` allows you to switch box models :

* content-box: This is the default style as specified by the W3C. The width and height properties are measured including only the content, but not the border, margin, or padding.

* border-box: The width and height properties include the padding and border, but not the margin. This is the box model used by IE when the document is in Quirks mode.

* padding-box : The width and height properties include the padding size, and do not include the border or margin (only in Firefox).

To save you time, you can apply it using the universal selector

```css
* {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}
```

```box-sizing``` is pretty well supported but partially and i mean that only Firefox support the three models, the others browsers only support content-box and border-box since the padding-box value has been added to the spec very recently.

    <dfn title="firefox">
21.0
</dfn>
    <dfn title="chrome">
26.0
</dfn>
    <dfn title="opera">
15.0
</dfn>
    <dfn title="ie">
8.0
</dfn>
    <dfn title="safari">
5.1
</dfn>


text:
# WikiWhatsThis Browser Extension

Tested with,

```bash
> npm -v
6.14.8
> node -v
v12.19.0
```

## Development Setup
```bash
git clone https://github.com/galtay/wikiwhatsthis.git
cd wikiwhatsthis/extension
npm install
```

## Beta Users
```bash
npm run update
npm run build
```

Navigate to `chrome://extensions` in your Chrome browser.
Turn on developer mode using the toggle in the upper right.
Click the `Load unpacked` button in the upper left.
Point the file finder that opens to the `wikiwhatsthis/extension/webpack-dist` directory.
To monitor the loading of the extension click on `Inspect views background page`.
This might crash. If it does, click `Load unpacked` and give it another try.
The background page view should open a pop-up that shows logging messages.
You may see some warning like `DevTools failed to load SourceMap` or sklearn warnings about version mismatch and inconsistent stop words. This is OK.
The last message from extension loading is `reading xbm25.npz`.
Once this is complete, you should see the option `WikiWhatsThis - Suggest` when you right click on highlighted text in your browser. If you do not see this option, try reloading the tab or restarting the browser.
Sometimes you have to right-click and ask for suggestions more than once before it works.
If it does work, you will see a popup of suggested Wikipedia pages.
If you've gotten this far, thank the computer development gods and yourself for being an awesome beta user :)

## Commands
> 🔨builds
> 👀watches
> 📦packages

|                  |                                                     |
| :--------------- | :-------------------------------------------------- |
| `npm start`      | 🔨 and 👀 files to the `webpack-build` directory     |
| `npm run build`  | 🔨 the 📦 extension to the `webpack-dist` directory. |
| `npm run update` | Download the latest models and pyodide packages.    |

repository: kensho-technologies/wikiwhatsthis

gha_language: Python

repo_name: kensho-technologies/wikiwhatsthis