teleren/devto huggingface dataset:
Convert: Medium Markdown Dev.to
Tags: productivity, automation
Published: 2020-02-05 02:12:16

Recently, I've been writing in Dev.to and Medium.

I have found it's a hassle to keep both sites in sync. Sometimes I tweak here or there.

One of the things I like a lot about Dev.to is that you write in straight markdown. When you edit an article you edit directly the Markdown.

As a huge plus, you can install tools like [Grammarly](https://www.grammarly.com/) that help you identify typos or other grammar mistakes. Grammarly also comes with a handy browser add-on you can install and it will check your article as you type in Dev.to.

This is not true for Medium. Not true about writing in plain Markdown and not true for Grammarly either.

That is why I like to write primarily in Dev.to and later import articles into Medium.

# Medium to Markdown

Though it can feel markdown-ish, Medium does not give an option way to obtain the markdown of your article back.

If you're not afraid of the CLI there is, however, a very interesting `npm` tool I've just learned about: `mediumexporter`.

It's very easy to use (Thanks @macropus for [such an useful post](https://medium.com/@macropus/export-your-medium-posts-to-markdown-b5ccc8cb0050)!):

1. If you yet don't have `npm`, [install it](https://www.npmjs.com/get-npm).
2. After installing npm, run `npm install -g mediumexporter`
3. Finally, download your article with `mediumexporter https://medium.com/medium-url > your_article.md`

After executing that last command, you'll find your Medium article in the current directory under the name `your_article.md`.

# Markdown to Medium

Sometimes you have a nice markdown document you want to import to Medium. Fortunately, you can import your Dev.to story to Medium going to Stories->Import Story.

However, there is also another very nice tool called [markdowntomedium.com](https://markdowntomedium.com/) that takes care of your beautiful code snippets and automatically posts them to Github.

> How does it work?
>
>This tool takes the pain out of importing a Markdown post into Medium by doing the manual labor for you (creating a gist on Github of your markdown). It also scans your Markdown file for any code blocks and extracts them into their own gists so Medium can syntax highlight them.

# Automatically updating a Medium story with a revised markdown

I haven't figured out how to automatically update a Medium article from a revised markdown. 

AFAIK, Medium does not have a way to reimport a story. If it were possible, then the "Markdown to Medium" method would work. 

So, for now, I just export the Medium story to markdown and compare it with the revised markdown article. I then modify the Medium article change by change, one by one. It's a hassle, but it is what it is.

Do you have a better method? If so, I'd like to know about it.
The Rest of the Story: 
Machine Code and Why Zero is a 
false-y Value in Javascript
Published: 2020-02-05 02:02:19

 


When I was a small boy in the sixties,  I would often secretly listen to my small, hand-sized transistor radio under the covers in bed after my parents read me my bedtime story and turned off the lights.  I wanted the party to continue, so I would turn in KCBS and listen to the news.  One of my favorite radio programs went on at about 9:30pm most nights: Paul Harvey’s “The Rest of the Story.”  The pattern of the stories were always the same: a chance meeting, or an odd circumstance that nobody would pay attention to that lead to some very important event or discovery. From tales of the origin of Coca-Cola, or accounts of Elvis Presley’s childhood, Paul Harvey would give you the backstory.


## What is Machine Code exactly?

“The Rest of the Story” now brings us to machine code.
Machine code is a computer program written in a way that only a computer can understand.  It’s what your Javascript, Ruby, Python or any other “higher-level” language’s code looks like on its way down to the “basement” of the computer’s CPU where it will be processed.

Machine code looks like this:

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

Machine code is the lowest level of programming detail visible to the human eye.  However, machine code is so unreadable that the United States Copyright Office cannot identify cannot identify whether a particular encoded programmed in machine code is an original work of authorship.

As you can see from the image above, machine code is written in base 2 with just two numbers: 1 and 0*.

Think of it:  As you look at the image above, each position is either a one or a zero. No other choices.

One or zero

Uno o cero

Eins oder Null

What other binary systems can you think of?

Hot and cold..

Happy and sad….

How about a 
“primitive” binary value in our dear Javascript?

Anyone remember Mr. George Boole?

That’s right!  Boolean values (Thank you, Mr. Boole!)

You can think of zero as the “off” value which corresponds to false

One is then the “on” value corresponding to true.

So Javascript has “remembered”  Machine Code toiling away in the “basement” of the CPU. We can imagine JS wanting to make Machine Code’s life a little easier by keeping zero as a false-y value as Machine Code would interpret zero in its own language.


And now you know the rest of the story.


## And For Good Measure:

In 1995 Brendan Eich was working at Netscape Communications Corporation and wanted to put a language into the browser.  The language was first called Mocha and then renamed to LiveScript.  A few months later Netscape and Sun Microsystems did a licence agreement and called the new language JavaScript.  The idea was to make it a complementary language to go with the already existing and popular Java.  Some said it was also a marketing ploy meant to ride on the coattails of the very popular Java programming language.








*Machine code can also be expressed in a hexadecimal format(base 16)
I Wrote Redundant Code with Apology Comment
Tags: bestpractices, codequality
Published: 2020-02-04 20:48:56

_Today I wrote redundant code with apology comment, and it was the right thing to do._

Here is a piece of code that I wrote today. It is a pretty obvious "DRY violation". To the extent that I had to write a comment explaining it. So that hopefully no one would refactor it out later.

```fsharp
type Condition =
    | Org of OrgType
    | ...

// raison d'être: ...
let org x = Org x
let ...
```

In F#, with the code above, these two things are equivalent.

```fsharp
org Ops = Org Ops // true
```

Even worse, the one on the left incurs the overhead of an extra function call (if the compiler doesn't optimize that away). There is no good engineering reason for having the extra helper functions. But there is a compelling human reason.

### Readability

These types are used to specify access control. They are designed to be used in a sortof code-as-configuration file. Let's compare what each looks like. First without the helper functions.

```fsharp
match command with
| ApproveAudit { AuditId = auditId; FileIds = fileIds } ->
    [
        Org Admin
        Roles [ SuperUser; Standard ]
        Access AdminToAudit auditId
        for fileId in fileIds do
            Access UserFile fileId
    ]
```

Now let's see what it looks like using the helpers.

```fsharp
match command with
| ApproveAudit { AuditId = auditId; FileIds = fileIds } ->
    [
        org Admin
        roles [ SuperUser; Standard ]
        access AdminToAudit auditId
        for fileId in fileIds do
            access UserFile fileId
    ]
```

In the latter example, the casing and color differences really help improve the readability of this particular code. You can quickly distinguish the conditions from their values.

Since the subject matter here is access control, I want this to be as easy as possible to get right! And the latter code's readability is better toward that end.

> In truth, I made this discovery by accident. I expected I would need to write certain things as functions, so I started that way. When I later realized they would fit cleanly into data types, I started to convert everything over and realized it was less legible.

----

This example illustrates something that comes up regularly. Trite rules like DRY or "no apology comments, rewrite the code instead" are helpful guidelines, but by themselves they cannot lead you to good solutions for every problem. And taken as absolutes they turn into weapons of civil war against fellow devs.

Follow best practices, but don't let best practices keep you from better solutions.
How to save disk space when using PM2
Tags: node, pm2, logs, space
Published: 2020-02-05 00:37:28

**TL;DR:** Run `pm2 install pm2-logrotate`

> _PM2 is a process manager for Node.js, usually used in production_

Yesterday I've ran into a problem on one of the production machines that I manage. Suddenly, the database stopped working and soon I found out that **I was almost out of disk space.**

![Running df-h on a Linux machine](https://dev-to-uploads.s3.amazonaws.com/i/4j1v2un2bhbwiwqlvhgk.png)

At first sight, I've checked my database records: all ok, as big as I was expecting.

Then, I had to start _`du -h`ing_ my largest directories to check what was taking so much space from my disk. I found the guilty one to be the **`~/.pm2/logs` folder**, and instantly realized that my app's logs where just stacking up there. I solved temporarily with `pm2 flush`, but had to look for a way for that not to happen again.

And, then, I've found this guy: https://github.com/keymetrics/pm2-logrotate

It's as easy as running `pm2 install pm2-logrotate` on your machine. Done! PM2 will start to **limit its logs size**, by default to **10 megabytes**, but it's easily configurable with something like `pm2 set pm2-logrotate:max_size 1K`. You can read more about the option [here](https://github.com/keymetrics/pm2-logrotate).
How can I send a variable from AngularJS to Java?
Tags: angular, javascript
Published: 2020-02-05 00:18:52

Hi everyone. Im using the angular tag since its the only one, I dont know if it includes AngularJS as well... I've been trying to send a variable inside of a JS Controller to my Java server using $http, but I cant get it to work: once I try it out, I cant enter the HTML view in which this JS code is used, so the problem is coming from the JS controller. Here's what I am doing and the code, based on trying to adapt these two resources:

https://docs.angularjs.org/api/ng/service/$http
http://hello-angularjs.appspot.com/angularjs-http-service-ajax-post-code-example

```javascript
angular
.module('myApp')
.controller('MessageController', MessageController);

MessageController.$inject = ['$scope', '$stateParams', '$uibModalInstance', 'MessageTemplate', 'JhiLanguageService'];

onFormatChange.$inject = ['$resource', '$http', 'ServerURL']; // should it be vm.onFormatChange.$inject instead? 

function MessageController ($scope, $stateParams, $uibModalInstance, MessageTemplate, JhiLanguageService) {
    var vm = this;
    vm.isSaving = false;

    vm.text = 'Activated'; // this is the only variable
                           // im trying to send to Java

    function onSaveSuccess (result) {
        // a console.log
    }

    function onSaveError (error) {
        // a console.log
    }

    // this function gets called from the HTML via ng-change
    vm.onFormatChange = function () {
        vm.text = vm.status ? 'Deactivated' : 'Activated';

        // Sending vm.text (as "format") to the server 
        $http.post(ServerURL + 'api/format/', {
            format: vm.text // should it be format = vm.text?
            }. {withCredentials: true,
                headers: {
                    'Content-Type': 'application/json; charset=utf-8',
                    'Access-Control-Allow-Origin': true,
                    'X-Requested-With': 'XMLHttpRequest'
                }
        }).then(onSaveSuccess, onSaveError);
    }
}
What is Speed Index?
Tags: performance, webperf, webdev
Published: 2020-02-05 00:10:50

---
title: What is Speed Index?
published: true
description: "Speed Index measures how long it takes visible content to appear on your webpage, but it's not that simple."
tags: ["performance","webperf","web-development"]
canonical_url: https://perfbeacon.com/blog/what-is-google-lighthouse-speed-index-metric/
cover_image: https://perfbeacon.com/static/1cd06b5eaa49a88e8462db0940427ff8/51ce9/speed.jpg
---

Originally published at [PerfBeacon.com](https://perfbeacon.com/blog/what-is-google-lighthouse-speed-index-metric/).

Everyone wants a faster website, but not all metrics measure "speed" the same way. Speed Index is particularly interesting because it can give two websites that load in exactly the same amount of time vastly different scores.

## What is it though?

Speed Index measures how quickly visible content loads. Lower scores are better.

It's different to regular performance metrics such as Time to First Byte (TTFB) and First Contentful Paint (FCP) because it tries to assign a score to a page's user experience.

As a user, you typically visit a webpage because you want to see its content. Visiting a website that loads its content slowly is generally a frustrating experience, and we're more likely to abandon a page that takes ages to show anything. 

Speed Index rewards pages that provide a good user experience (that is, show visible content as soon as possible), and punishes pages that download all of their assets before displaying anything.

## Got an example?

Imagine two websites. 

Website A is a classic, pre-JavaScript, PHP-based website from the 2000s that shows content progressively, from top to bottom as the browser receives data. Website A takes 5 seconds to complete loading.

Website B is a React app built in 2019 that is only capable of showing content once its JavaScript bundle is downloaded and executed. Website B also takes 5 seconds to complete loading.

Website A immediately shows content, and progressively loads more images and text as the browser receives the full HTML, while Website B only shows the user a spinner for several seconds before loading the entirety of its content. 

Website A's Speed Index measurement is much faster than Website B, as the user experience is much better.


## How is it calculated?

Speed Index is calculated by first recording a video of the webpage loading, then comparing the distance between histograms of each individual frame to the final frame.

WebPageTest's documentation goes into detail about how it's calculated [here](https://sites.google.com/a/webpagetest.org/docs/using-webpagetest/metrics/speed-index).
MySQL server has gone away
Tags: mysql, macos, terminal
Published: 2020-02-05 13:52:14

---
title: MySQL server has gone away
published: true
date: 2020-02-05 00:00:00 UTC
tags: mysql, macOS, terminal
canonical_url: 
---

Another quick one for today.

After a little while developing on and against Windows, I am back developing on the lovely macOS.

I have a local install of MySQL and when I connected to it via my terminal using `mysql -u root` I would connect ok but as soon as I tried to do anything I would get the following error.

![screenshot](https://i.imgur.com/GZILrCL.png)

```bash
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 102
ERROR:
Can't connect to the server
```

This turned out to be an easy fix, one of the first debugging steps was to restart the MySQL service on my machine followed by restarting the MySQL process.

```bash
sudo killall mysqld
mysql.server start
```

I was then able to connect via `mysql -uroot`!

Success 🎉
Partial Types in TypeScript
Tags: typescript
Published: 2020-02-05 00:00:00

---
title: Partial Types in TypeScript
date: "2020-02-05T00:00:00.000Z"
tags: ["typescript"]
---

The `Partial<T>` utility type (added in [TypeScript 2.1](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#mapped-types)) allows you to take an existing type and make all of its properties optional. This can help in situations where you want to have some flexibility without removing strictness across the board.

Consider the following interface:

~~~typescript
interface ChocolateBar {
	readonly manufacturer: string;
	readonly name: string;
	readonly price: Money;
}
~~~

As specified, all properties of `ChocolateBar` are required for the interface contract to be satisfied. (Incidentally, don't use the `Number` type for monetary values - [introduce a type](https://martinfowler.com/eaaCatalog/money.html).)

Inevitably, there will occasions where strictness like this can make life awkward. What if you want to be able to selectively update the values of a chocolate bar? Well, you might write something along the lines of:

~~~typescript
interface KeyValuePair {
	readonly key: string;
	readonly value: any;
}

const updateChocolateBar(bar: ChocolateBar, props: KeyValuePair[]): ChocolateBar {
	props.forEach(({ key, value }) => bar[key] = value);
	return bar;
}
~~~

While this may be sufficient, each `KeyValuePair` is ambiguous e.g. `{ "paws": 4 }` is perfectly valid. Ambiguous code is more difficult to reason about, test, and maintain.

A better approach is to use a Partial type:

~~~typescript
interface KeyValuePair {
	readonly key: string;
	readonly value: any;
}

const updateChocolateBar(bar: ChocolateBar, props: Partial<ChocolateBar>): ChocolateBar {
	return { ...bar, ...props };
}
~~~

Here, `Partial<ChocolateBar>` creates a type with all properties of `ChocolateBar` set to optional, effectively producing:

~~~typescript
interface ChocolateBar {
	readonly manufacturer?: string;
	readonly name?: string;
	readonly price?: Money;
}
~~~

Why is this approach superior?

1. The `ChocolateBar` contract is only altered for this _specific case_
1. `updateChocolateBar()` communicates its own contract more effectively, is less ambiguous in use, and straightforward to test
My Python Journey
Tags: python
Published: 2020-02-04 23:57:36

I will be taking up a challenge of writing what ever I learn. Let's say my personal diary of my python journey. So today, because I wish to dive into Data Analysis and then Machine Learning, I asked my self, how should I kick start this journey?, Ehmmmm, data right ?, a Data Analyst must know how to get data, so I started learning web scraping to get data. I scrapped a book website and was able to get all books, its title, cost and rating. Getting the genre was quite hectic. Haven't figured that yet but I guess I will. That's today, see you tomorrow diary.
Check out my Brainfuck engine
Tags: csharp, dotnet
Published: 2020-02-04 23:31:06

Hi! 
Check out my Brainfuck interpreting engine written in .NET, it also supports validation of Brainfuck code & can analyze semantical structure of code.
I would like you to advise me on how to improve my engine.
Link: https://github.com/nikolayresh/Brainfuck-Runner
Understanding the concept behind AIML
Tags: aiml, xml
Published: 2020-02-04 23:26:41

![main image](https://res.cloudinary.com/developerayo/image/upload/v1551555821/aiml.png)

What is AIML?

AIML or Artificial Intelligence Markup Language is an XML base language used for creating chatbots(AI), it is always saved with the extension (.aiml).

The tag always used in AIML used to specify a new function is the <mark style="background-color: #9a69c2;">category</mark> tag which has two other tags running under it that i s the <mark style="background-color: #9a69c2;">pattern</mark> tag and the <mark style="background-color: #9a69c2;">template</mark> tag. Inside the template tage we cound also have other tags inbute “Depnds on the type of BOT you are building” eg <mark style="background-color: #9a69c2;">set</mark>, <mark style="background-color: #9a69c2;">br/</mark>, <mark style="background-color: #9a69c2;">srai</mark>…etc

But note something just as in HTML or any other programming Language or Scripting Language Even Markup Languages have a closing tag, here in AIML there is really not much a difference, the closing tags are <mark style="background-color: #9a69c2;">/category</mark>, <mark style="background-color: #9a69c2;">/template</mark>, <mark style="background-color: #9a69c2;">/srai></mark>, <mark style="background-color: #9a69c2;">/set</mark>…etc


## Example

```AIML
<category><pattern>WHO IS ABRAHAM LINCOLN</pattern>

<template>was a great President of the United States, during the American Civil War.<br/>

</template>

</category>
```
When the user inputs this in on some very close to this, the bot will respond to the input

“WHO IS ABRAHAM LINCOLN” with the response “was a great President of the United States, during the American Civil War.”.

Now lets create a simple bot using AIML

```html
<!DOCTYPE html>
<html>
<body>

<em>Emphasized text</em><br>
<strong>Strong text</strong><br>
<code>A piece of computer code</code><br>
<samp>Sample output from a computer program</samp><br>
<kbd>Keyboard input</kbd><br>
<var>Variable</var>

</body>
</html>

```

```AIML
<?xml version=”1.0" encoding=”UTF-8"?>

<aiml version=”1.0">

<category><pattern>Hi</pattern>

<template>Hi, I’m Oscar I was developed by Shodipo Ayomide 2017, <br/>How may I be of help</template>

</category>

<category><pattern>What are you </pattern>

<template>I said, My name is Oscar and I was developed by Shodipo Ayomide ok! </template>

</category>

<category><pattern>Why are you rude </pattern>

<template>Oh sorry, Please forgive my manners do not report me PLEASE!!! </template>

</category>

<category><pattern>ok </pattern>

<template>PLEASE!!! </template>

</category>

</aiml>
```
## Now lets explain Templates

A template specifies the response to a matched pattern.

**I am Oscar by name**

A template may use variables such as

You told me you are <mark style="background-color: #9a69c2;">get name=”user-age”</mark> years old
which will fetch the users age if in db.

Thanks for reading! 🔥🚀 </br>