teleren/devto huggingface dataset:
3 Things You Should Know About gh
Tags: gh, github
Published: 2020-09-20 21:05:05

<span>Photo by <a href="https://unsplash.com/@yancymin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Yancy Min</a> on <a href="https://unsplash.com/s/photos/github?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>

`gh` has been released.
In this article, I would like to introduce 3 things you should know when you use it.


## 1. `gh pr` has `diff` but it's not useful as well as web
`gh pr` has diff command that shows us differences between a new PR and master. However, it only has a color option, so all diffs are listed on the same window which is hard to review if the change has many lines. So I think right now, `gh pr diff` is for a small change.

The following is a diff when I added a new markdown file.
```zsh
$ gh pr diff
```

![](https://storage.googleapis.com/zenn-user-upload/o49ddn62edu2beykac65m53hm82j)


## 2. Can not approve of our own PR
`gh pr` has `review` command that allows us to review a PR and give `comment`, `approval`, `request change` which is very useful. However, we can not approve of our own PR.
This functionality totally makes sense to team development.

```zsh
$ gh pr review 1
? What kind of review do you want to give? Approve
? Review body <Received>
? Submit? Yes
failed to create review: Can not approve your own pull request
```


## 3. Default Editor is`nano`
`gh` sets `nano` as default editor.
I don't use `nano`, but use `vim` on Terminal. Also, use VSCode.
I'm using VScode for `gh` because VScode has a preview function for markdown. So, it is helpful to edit a new PR's body when I open a new PR.

```zsh
$ gh config set editor "code --wait"

# vim
$ gh config set editor vim

```

![](https://storage.googleapis.com/zenn-user-upload/kqpfb91uaflswmcdivs2pqp5ua1m)
Visualising documentation: JavaSript array.of
Tags: javascript, beginners, tutorial, codenewbie
Published: 2020-09-20 20:51:24

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/t3jfeqz6kz58z4m6w3ya.jpg)

Today’s function is array.of(), mdn description [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of). 

This function creates an array from whatever it has been given. Sounds a lot like [array.from()](https://dev.to/charlottebrf_99/visualising-documentation-javascript-array-from-12n3) right? 

The difference is array.of can take multiple parameters, so works especially well if there are many things to add to the array, i.e. numbers. Whilst array.from can only takes one parameter, so works well especially with a string to split each char into an element in the array. 

Another difference between array.from is that if array.of is passed an array and a function it won't apply the function to each element in the array like array.from but instead stores the function in the array. 

Would welcome any comments on good situations to use this function. 

I've done my own version of the docs with sketches together. Here’s the folder for [array.of](https://github.com/cfereday/javascript-core-functions/tree/master/arrays/do%20not%20mutate/returns%20a%20new%20array/of). Check out the [readme](https://github.com/cfereday/javascript-core-functions) to see how you can run the examples.
10 Lines of Code
Tags: python, productivity, github, motivation
Published: 2020-09-19 19:21:57

I've faced a problem when I've started learning programming. That problem was: I thought need to have deep understanding in every field to do projects and make cool stuffs. That's true but we're not bound to anything so I started learning coding hard, but after a few week I loose my motivation to do so as it was not clear to me that how coding is going to help me something that i like. 
Solving some patterns is not my aim... 

I figured out it's not necessary to have deep understanding to do some small projects, I can use the knowledge I've to create something cool. Which will give me: 
1. motivation of doing something new 
2. Make me think how program solves real live problem

And it worked!

I've created a online development and research club in collaboration with Mozilla Campus Club. In the first event we'll develop 10 #python projects in 10 lines of code. 

10 Projects:

1. Password Protech PDF 
2. Windows Notification 
3. Merge Multiple PDF 
4. Voice Recorder
5. Random Password Generator(App)
6. Audio Visualization Tool(GUI)
7. Extract mp3 from mp4
8. Link Shortener
9. Terminal Tricks
X. Birthday Reminder

Keynote Video: https://www.youtube.com/watch?v=B0_0gK_CUpM
GitHub org: https://github.com/qxresearch/qxresearch-event-1

Join #qxresearch:
- Mozilla Group: https://community.mozilla.org/en/groups/qx-research
- Telegram Group: https://t.me/qxresearch
Hello world v2
Tags: webdev, python, tutorial, discuss
Published: 2020-09-20 20:31:40

---
title: Hello world v2
published: true
description: Hello world v2 aims to cover more basic syntax of a programming language.
tags: #webdev #python #tutorial #discuss
cover_image: https://i.ibb.co/k8ttLTM/image.png
---

We know that "Hello world" is the simplest code example to demonstrate how to output a simple message in a programming language.

This "version 2" aims to cover more basic syntax.

It is a One-Page Code Example of:
- String handling, length, spliting, template string.
- Characters, char codes handling.
- Array, array items accessing, looping.
- Number, casting, basic math calculation.
- Function, returning a value.
- JSON, parsing.
- From: http://b.link/hello-world-v2 (please keep this link)

## In different Programming Languages

[Python 3.7+](https://syntax.wiki/python3)
- [Live example](http://b.link/hello-world-v2-python3)

Javascript - [In Progress](https://syntax.wiki)

Typescript - [In Progress](https://syntax.wiki)

(Please [open a PR](https://github.com/ngduc/syntax.codes) to add for other languages here)

## Github link

https://github.com/ngduc/syntax.codes/blob/master/docs/articles/hello-world-v2.mdx

Please comment with any idea or feedback. Thanks.
Mitype ⌨️ - Typing Speed Test Right In Your Terminal
Tags: showdev, hacktoberfest, python, productivity
Published: 2020-09-20 20:07:38

Who doesn't like to type fast? I made mitype with an intention to test typing speed and hence improve it at the ease of one command.

Feel free to contribute 💚
{% github mithil467/mitype %}


### Features-
- Supports several languages like English and German
- Choose your own text files
- Or randomly pick up a sample from 6000 entries
- View results and replay after every test
- Choose difficulty level
- Has cross-platform support
- Works with both python 2 and python 3
- Uses in-built python modules only
- Available on [pypi](https://pypi.org/project/mitype/) allowing easy install
- Colored highlights
- Runs on [web](mitype.mithil467.repl.run), although the latency is kinda high

### How to get it?
`pip install mitype`

### How to run it?
Choose random text:
`mitype`
To choose a sample file:
`mitype -f <your_file>`
Choose a difficulty level:
`mitype -d <N>`
Choose a text ID:
`mitype -i <ID>`

### Built with
- **Python** and all its inbuilt modules
- **Curses** library - Easily capture keystrokes
- **Sqlite3** - Database for storing text
- Text provided by [typeracerdata.com](typeracerdata.com)

Mitype is open to feedback, contributions and new ideas 💡
🌟 Star the repo on [GitHub](https://github.com/Mithil467/mitype)!
Ruby on Sinatra
Tags: ruby, leadership, womenintech
Published: 2020-09-20 20:01:34

Hi! 
what a crazy year... I started this journey with Flatiron School on March 2020 right when the pandemic hit and IT HAS BEEN HARD!
I am very proud of myself I am keeping up with my learning, I created a web app with Ruby with Sinatra and Active Record and it turned out pretty decent
I would like to talk about what I've learned so far with this project.
1. MVC it's basically separation of concerns where your files are going to go super organized and if you have to debug or come back to your code will be easier to find.
Models, Views and Controllers 

**Models:** Where the logic is, they are generally written by Ruby Classes, connecting the databases to persist it.

**Views:** Where the User and the web app connect, they are written as **.erb** files by HTML and CSS.

**Controllers:** Are written in Ruby and consist of 'routes' that take requests sent from the browser, run code based on those requests by using models, and then render the .erb (views) files for the user to see.

**PARAMS[:]=** It takes your input from a form using a hash to create new objects from my application to my controllers file using HTTP requests.

**REST:** Representational State of Transfer, an architectural style design for distributed hypermedia.

I also applied many HTTP request methods to my project such as, POST(read), GET(read),UPDATE(edit) and DESTROY.

**ACTIVE-RECORD BASE:** It gives access to a number of methods to a number of methods that assist in working with the database.

**SINATRA ACTIVE-RECORD:** Extends Sinatra with methods and Rake Tasks to deal with sqlite3 database.

**Validations:** I used **authenticate** so my users have exclusive access to their data, as well as securing my password **has_secure_password** by using BCRYPT GEM.

I hope this post gives some value. 

My project will be available right below

https://github.com/sarisgar28/pet_tracker
Use Prometheus-net 
Tags: dotnet
Published: 2020-09-20 19:12:38

<sub><span>Photo by <a href="https://unsplash.com/@marius?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Marius Masalar</a> on <a href="https://unsplash.com/s/photos/data?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span></sub>

In my last post, i have shown how to export performance counters. One option was to use [prometheus-net](https://github.com/prometheus-net/prometheus-net) project.

In order to use it, we need
- publish metrics
- a Prometheus server
- a Grafana server


## Publish metrics

In order to publish metrics for a .Net Core 2 AspNetCore project, we just have to add **prometheus-net.AspNetCore** package, and in the Configure method of the Startups.cs class, to add

```csharp
            app.UseMetricServer();
            app.UseHttpMetrics();
```

And, this just add an API served on "/metrics" endpoint on the default port.

## Prometheus server

In order to get a Prometheus server, we can use Docker 

```bash
docker run \
    -p 9090:9090 \
    -v /path/to/config:/etc/prometheus \
    prom/prometheus
```
In order to scrape data from our server, we need to modify the Prometheus configuration to add the published metrics.

```yaml
global:
  scrape_interval: 15s
  scrape_timeout: 10s
  evaluation_interval: 15s
alerting:
  alertmanagers:
  - scheme: http
    timeout: 10s
    api_version: v1
    static_configs:
    - targets: []
scrape_configs:
- job_name: prometheus
  honor_timestamps: true
  scrape_interval: 15s
  scrape_timeout: 10s
  metrics_path: /metrics
  scheme: http
  static_configs:
  - targets:
    - localhost:9090
- job_name: backend
  honor_timestamps: true
  scrape_interval: 15s
  scrape_timeout: 10s
  metrics_path: /metrics
  scheme: http
  static_configs:
  - targets:
    - localhost:8080
```

I have discovered [this tool](https://github.com/juliofalbo/docker-compose-prometheus-service-discovery) to use Service Discovery on Docker-Compose, but not yet used it.

## Grafana server

In order to get a Grafana server, we can use Docker
```bash
docker run -d -p 3000:3000 grafana/grafana
```
The default login / password is admin / admin.

We need to add the Prometheus as a data source and then the [dashboard](https://grafana.com/grafana/dashboards/10427), by using the id 10427 in Grafana.

![Grafana dashboard](https://dev-to-uploads.s3.amazonaws.com/i/9s6efxdw4pbmah6hkovn.png)


Hope this helps !
Smarter document management using OCR
Tags: beginners, python, computerscience, machinelearning
Published: 2020-09-20 19:27:43

Many businesses (including my own) suffer from unproductive processes, such as manual data processing. These issues can be solved through automation, using structural systems such as CRM and custom tools. Throughout the years I've dealt with complex environments that require a lot of data processing, analysis and reporting. And "data" can mean anything that's digital.

Some time ago I faced a client who had thousands of unstructured documents, these piled up throughout the years. And it has become a very unproductive environment especially when information had to be retrieved, but couldn't happen efficiently. Fortunately technology can help us. OCR stands for Optical Character Recognition, it's a machine learning discipline focusing on extracting text from images/pictures.

Suppose you have hundreds of files, and most of these are copies of passports, contracts and invoices. Some images were made by phone, some were scanned, some are PDF files containing text and/or images. The demo screenshots below illustrate how we can extract text/keywords from these kinds of documents.

![ocr passport image](https://dev-to-uploads.s3.amazonaws.com/i/njo3q0k7coh8ias08nvf.png)

![ocr pdf image](https://dev-to-uploads.s3.amazonaws.com/i/b47rqz59owjz7un3trwj.png)

Using the extracted text/keywords we can process these files according to our own business rules, such as rename/copy/move/backup; but we can also send/upload these files to some other pipeline for further processing. Keep in mind that OCR is pretty good but it's not perfect, it works best when images are clear and don't contain strange characters. Most languages are supported.

```python
# Basic usage of our OCR library

import ocr

your_file = './demo_files/doc1.pdf'
text = ocr.process(your_file)

# your business rules
if 'CONTRACT' in text:
  ...
else:
  ...
```

As easy as that, you only need basic python knowledge to get started. For more information visit our Git repository.

https://github.com/healzer/PyCRM

The "PyCRM" project is a collection of useful tools, tips and tricks for your business. These can be used in almost any industry that has some digital processes: managing clients/data, data extraction & analysis, reports, process automation, etc.
Web analytics from scratch - Part 2: The Client
Published: 2020-09-20 19:10:36

_Originally published [here](https://maxniederman.com/scratch-analytics/2-the-client) on my blog._

_This is Part 2 of this series. You can read the first part [here](https://maxniederman.com/scratch-analytics/1-page-views)_

### Tracker Client

Now that we have a server which can keep track of our analytics data, we need to add a client which will tell the server the page has been loaded.
This is extremely simple since we only have to send a single request with two JSON properties when the page loads:

```js
var analytics = async (apiBase) => {
  await fetch(`${apiBase}/tracker`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ url: location.href }),
  });
};
```

Then we can just load and call it like this:

```html
<script src="analytics.js"></script>
<script>
  analytics("http://yourserver.com");
</script>
```

And that's really all it takes to implement our super-simple analytics on the client side. This has the added benefit that the bundle size of the client is negligible (<250B unminified).

### Getting Analytics Data

We have a way to collect and store analytics data, but now we need a way to get it.

We can already look at the data using `redis-cli` like this:

```
> HGETALL <YOUR_HOST>:resources
1) "/"
2) "42"
3) "/index.html"
4) "7"
```

However, this isn't a great solution for quickly looking at analytics data. We want some way to present this data to the user nicely. We can do this by adding an endpoint to our API to get this data:

```ts
fastify.get("/data", async (req, reply) => {
  const resources = await fastify.redis.hgetall(`${req.query?.host}:resource`);
  return { resources };
});
```

Now if we call this by making an HTTP request with a `host` query parameter and get back some JSON like this:

```json
{
  "/": "42",
  "/index.html": "7"
}
```

Now you might notice that the numbers are, in fact, strings. This is because Redis stores everything as a string, so we'll need to cast it to a number:

```ts
// Helper function to cast Object values
const castValues = <T>(
  object: Record<string, unknown>,
  castFn: (value: unknown) => T
): Record<string, T> =>
  Object.fromEntries(
    Object.entries(object).map(([key, val]) => [key, castFn(val)])
  );

fastify.get("/data", async (req, reply) => {
  const resources = await fastify.redis.hgetall(`${req.query?.host}:resource`);

  // Cast values to numbers
  return { resources: castValues(resources, Number) };
});
```

Now it'll reply this:

```json
{
  "/": 42,
  "/index.html": 7
}
```

---

In the next part of this series, we'll add more statistics and work on a visual dashboard.
Service Worker registration
Tags: 100daysofcode, javascript, pwa
Published: 2020-09-20 18:59:54

I learnt how to register a service worker.

Here is how its done:
```javascript
if('serviceWorker' in navigator){
  window.addEventListener('load', () => {
    navigator.serviceWorker
    .register('sw.js')
    .then(reg => console.log(reg))
    .catch(err => console.log(err))
  })
}
```
Code explained:

The condition in the if statement checks if the browser supports service workers. Inside the if statement we attach an event listener to listen for the load event. The event fires when the page has loaded then calls a `register()` function which takes the service worker file as an argument. My service worker is named sw.js. If it successfully registered you log out the response else you log out an error. 

The service worker file will contain some code which I'll add once I get it all working.

_That's it for Day 66_
_Let's do this again tomorrow_
send() in ruby to call dynamic methods
Tags: ruby, webdev, rails
Published: 2020-09-20 18:44:03

For newbies in Ruby or Rails programming you will find this method `.send` being used at many places. You will find many tutorials and blogs explaining what it does and when to use. 

To get myself an idea what is it. I had to go through lot of them. So, anyone who is new to ruby or meta programming. I will tell you a straight away answer what is it.

.send() is a method in Ruby to call any method without knowing its name. In your day to day coding you will have mainly two usage of it. 

1. **Dynamic Method Calls:** If you want to call any dynamic method instead of writing if-else logic again and again.

2. **Private Method Calls:** If you really really want to call a private method. Its been called private method for a reason. So, don't use it for hack around. Use it only when its really needed.

`.send` excepts first argument as method name and later if their is an argument to be passed to that method.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mrbu7swfa5nnyxkb47dv.png)

So, instead of writing like this in above code. 

```
if word == "awful"
 puts "Claw-ful"
elsif word == "perfect"
 puts "Purr-fect"
end
```
we can use the above code using `.send`. This is just short and simple code, but it might be useful when you have tidy if else logics in your code.

If you find it helpful. Don't forget to drop some loves and comments. Thanks!
What I learned from my first month as a Junior Developer
Tags: beginners, webdev, watercooler
Published: 2020-09-20 18:43:49

First a bit about me, I just started my Junior year at Utah Valley University studying Full Stack Web Development. In August I landed my first EVER programming job! One of my friends from school was able to get me an interview where he worked, and they liked me enough that they gave me a job offer and I took it. 

When I first started I had absolutely no idea what to expect. And one month in, oh man have I learned a lot! 

One of the biggest things I have learned is that imposter syndrome is real. I have learned a lot in my classes from school and in my personal side projects, and would consider myself a decent programmer. But the biggest struggle is feeling like I have no idea what I am doing, even though I know I have done more complicated things before. 

After thinking about it, I can point to one thing that has caused this feeling. Learning the structure of the application and how everything works together. I feel like I spend about 80% of my time learning how every function and file works together and about 20% of my time adding/fixing what needs to be done. 

Even though this has caused discouragement on my end. I have realized that my colleagues and boss have not expected me to come in and have a perfect understanding withing the first day or even first week. They expect me to come with the with questions when I cannot figure something out or do not know how a certain part of the framework works. 

#Advice
So, the thing that I would tell any new programmer is that no one expects you to know everything right off the bat. Give yourself time to learn the structure of the app you are working on. Give your best effort to figure things out on your own, and if you still can understand it, ask for help understanding. Don't ask them do to it for you, ask questions so you can go back and do it yourself. The other most important advice would be, don't give up. They hired you for a reason, they saw something in you. Try to see that thing in yourself.
Everybody has a testing environment
Tags: quote, motto, production, testing
Published: 2020-09-20 18:42:14

---
title: Everybody has a testing environment
published: true
description: 
tags: quote, motto, production, testing
---

> **Everybody has a testing environment.**
> Some people are lucky enough enough to have a totally separate environment to run production in.

From [@stahnma](https://twitter.com/stahnma/status/634849376343429120)

I love this motto, and you?
Still Nothing Rendering...
Published: 2020-09-20 18:31:46

I fixed my unreachable code problem but I still have that other problem of nothing rendering.  

I was also getting an "undefined" error on React itself, so I turned the script into an ES6 module and `imported` React which fixed that problem.  But still nothing actually gets rendered.  

And on CodePen, I get this error:
```
Uncaught TypeError: Cannot read property 'className' of undefined
```
on the line
```js
Button.propTypes.className.isRequired();
```
Why is that?

Also note that on CodePen, changing it into a module wasn't needed.

Anyway, please help me out here as well.  Thanks.
Coding w/ Music
Published: 2020-09-20 18:29:50

Music always gets me in the mood to wire in and block out my surroundings, focusing on the code in front of me with the tunes as my auditory guide.

Although it may distract you as well, if you are the type that can get past that then you may find it a rather comforting addition to your environment while you're grinding away. It's like listening to music while studying! 

A couple songs I love to start out with when I open VS Code are: 

https://soundcloud.com/charles-thefirst/chynna-the-conversation-charlesthefirst-remix

https://soundcloud.com/a40ounce/tiedye-ky-hit-em-from-the-top-rope-feat-duke-blazer

Any and all recommendations for new tunes to code to are welcome!
Handle Missing Data of a Dataset
Tags: machinelearning, datascience, python
Published: 2020-09-20 18:18:04

**Concepts:** we have to replace the missing data as the mean value by its all of features.

*At first we can replace the missing field by "NAN"*
for that we need , 
**Step 01:** from sklearn.impute import SimpleImputer 

**Step 02:** #create object of Imputer class 
imputer = SimpleImputer(missing_values= np.NAN, strategy= 'mean', fill_value=None, verbose=0, copy=True)

**Step 03:** #fitting imputer objects in matrix
imputer = imputer.fit(X[: , 1:3])

Here , X defines the which columns missing value will be replaced

**Step 04:** Transform the fitting ,
X[:, 1:3] = imputer.transform(X[:, 1:3]) 

**Step 05:** Find the output by print X
print(X)