teleren/devto huggingface dataset:
Containers from scratch in 18 lines of code
Tags: containers, docker, showdev
Published: 2018-06-29 17:13:03

---
title: Containers from scratch in 18 lines of code
published: true
description: building a super simple container
tags: containers,docker,showdev
cover_image: https://thepracticaldev.s3.amazonaws.com/i/x7c4g7o8fc78vtdvut97.jpg
---

Ever wondered what a container is? 
One of the best way to answer this question is by building a container from scratch.

## Container
A container is an abstraction primarly made of three things:
* cgroups:
control what you can __use__ in a container
* namespaces:
control what you can __see__ in a container.  
For example the list of processes running in the containers, pid, hostname, etc. 
* networking: manage who you can __communicate__ with in a container

How does that look like in practice?
The best way to see it is by writing some code.


So let's do this. Let's create a small program which opens a bash in a new process.
__We want the process to have a new namespace.__
How can we test it if this works? We can type in the bash opened by our program `hostname newhostname` and see what the hostname is after we exit the program.

Let's see it in action. In the following example the program is called `namespace`.
You can find the code at the end of the article.

![console1](https://thepracticaldev.s3.amazonaws.com/i/wb850r39wkfewf4svn91.gif)
Before running the command my hostname is: `nicola`.
Then we run `sudo ./namespace` which starts the `container`.
Then we change the hostname in the container to `container`.
When we exit the program the host hostname is `nicola` again.
The container had its own namespace, nice!
You can also see that the pid in the container is `1`.

## Do it yourself
Give it a try. Copy the following code in a file named namespace.c for example.

```c
#define _GNU_SOURCE 
#include <sched.h>

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int child(void *args)
{
    printf("pid as seen in the child: %d\n", getpid());
    system("bash");
    
}

int main()
{
    int namespaces = CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWIPC|CLONE_NEWNS|CLONE_NEWNET;
    pid_t p = clone(child, malloc(4096) + 4096, SIGCHLD|namespaces, NULL);
    if (p == -1) {
        perror("clone");
        exit(1);
    }
    printf("child pid: %d./na	\n", p);
    waitpid(p, NULL, 0);
    return 0;
}
```

```bash
gcc namespace.c -o namespace
chmod +x namespace
sudo namespace

```

###Conclusion!
Admittedly this is a super simple container, but it should get you on the way to understand the container abstraction!

Thanks!

Follow me on [twitter](https://twitter.com/napicellatwit)
Ruby DebugHelper
Published: 2018-06-29 16:00:49

---
title: Ruby DebugHelper
published: true
description: 
tags: 
---

I will soon be putting up a new Ruby gem, <code>debug_helper</code>.

Any pre-release suggestions or comments will be appreciated.

The GitHub project is [here](https://github.com/BurdetteLamar/debug_helper#debug-helper).
Which Programming language are GitHub Apps mostly written in?
Tags: github, discuss
Published: 2018-06-29 15:56:28

---
title: Which Programming language are GitHub Apps mostly written in?
published: true
description: 
tags: GitHub, discuss
---

And I'm not talking about a REAL app that would replace or alternate GitHub's functionality. I'm talking about an app that extends and uses the functionality of GitHub, according to [developer.github.com/apps/marketplace](http://developer.github.com/apps/marketplace)

I'm not really familiar with developing an application as an extension of another application, but based on what I have read it can support node.JS as its programming language.

Some of these extensions if you look into the website show supports of other languages but I have no way of knowing or confirming if its the app itself that were written in these languages or they support applications that are written in these languages? 

So, what say you, the experts on this area, are GitHub Apps only written in node.js? If not, can they be written in other languages and what are these languages?
Follow Friday! (v3)
Tags: discuss, followfriday
Published: 2018-06-29 14:24:57

---
title: Follow Friday! (v3)
published: true
description: 
tags: discuss, followfriday
---

Below you can either write about **why someone might want to follow you** or **devs you think others should follow and why**. Feel free to do both.

Remember that mutual follows can message/pair via [DEV Connect](https://dev.to/connect), so you're encouraged to follow back and say hey 👋
How did you get out of the habit of copying/pasting code?
Tags: discuss, general, habits
Published: 2018-06-29 14:13:14

---
title: How did you get out of the habit of copying/pasting code?
published: true
description: How did you do it particularly when it saves time and does the job? 🤔 
tags: discuss, general, habits
---
Like the title describes, I would like to know how you got out of the (bad) habit, particularly when it saves time and does the job.
Let's talk about clients
Tags: discuss
Published: 2018-06-29 13:36:50

---
title: Let's talk about clients
published: true
description: 
tags: discuss
---

Hi,
I think there are freelancers here too.
So I really started this activity as a developer this year, and although I like working from everywhere and (sometimes) at times that suit us, I struggle.
Then I humbly come to you for help.
I'd like to know how you're doing:
- find clients
- what to do, what not to do
- If possible, is it better to meet the client when they contact you first?
- how do you establish your prices (are there apps that make your work easier?)
etc...
Here I would like us to linger more on the Internet but everything is good to take. Even on the field, it could help someone

Thank you
Makefile with help message
Tags: cli, makefile
Published: 2018-06-29 13:33:23

---
title: Makefile with help message
published: true
description: Self-documented Makefile
tags: cli, makefile
---

# The Makefile
The idea is pretty simple: Add comment to each target from Makefile
Here is the `clean` target from makefile:
```
clean:
    rm -f *.o
```
Help message here is redundant but in sake of completeness let's add it:
```
clean: ## Clean directory
    rm -f *.o
```
Now we need filter out all *docstrings*: here is the command for that:
```
ag '^[a-zA-Z_-]+:.*?## .*$$' --nofilename Makefile \
| sort \
| awk 'BEGIN{FS=": ## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
```
Here I'm using `silver-searcher` aka `ag`.
Seems complicated, yeah? So what does that command do?
- filters out lines basing on this regular expression: `'^[a-zA-Z_-]+:.*?## .*$$'`, namely  any string like "target_name: ##doc string".
- sorts output with command `sort`
- formats output with `awk` command `BEGIN{FS=": ## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}`

Let's look at that command. What do we have?
- BEGIN{FS=": ## "}
- {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}

    From the documentation: `A BEGIN rule is executed once only, before the first input record is read`. So it simply reads input and sets the Field separator to ": ##" to split input on two parts: before and after the FS.

    Second part just prints filtered output with formatting and colors.

One more thing -- we have to define default target to be executed when `make` command launched without arguments:
`.DEFAULT_GOAL := help`
Now we are ready.

Here is what we have as a result:

{% gist https://gist.github.com/alex-bender/2e2cee3d060d01d185a8 %}

Save that gist into `Makefile` and run `make` command in your terminal from the folder with Makefile. If everything is ok you will get formatted and colored output: all targets defined in Makefile:
```
$ make
clean                          Clean directory
help                           Help target
```

## Dependencies
But aware that `awk` and `silver-searcher` are required for that snippet to work.
(Btw, `ag` could be replaced with `grep`, if needed with some modifications I guess.)

And remember -- documentation's important!
How do you get started with new habits?
Tags: discuss
Published: 2018-06-29 13:32:39

---
title: How do you get started with new habits?
published: true
description: 
tags: discuss
---

I have been quite inspired by [this post](https://dev.to/ben/what-good-habits-are-you-trying-to-adopt-3hm8) lately, and it's good to see that we all are trying to adopt some new habits and be better!

But on a practical point of view, how do you get started with a new habit? How do you keep up with it until it becomes normal? What's the most difficult thing for you when trying to adopt a new habit?

Speaking for myself I usually try to prioritize the habits I'd like to adopt, I start with the most important one. Also I try to take on habits one at a time to avoid being too overwhelmed.
That being said, the main issue for me is time and energy. It's not rare that the habits I try to adopt start feeling like chores and feel more daunting and exhausting than beneficial. In that case I try not to be too hard on myself and keep up until I can see positive result for habit!

How about you?
Reinforcement Learning Applications
Tags: machinelearning, reinforcementlearni
Published: 2018-07-04 10:29:59

---
title: Reinforcement Learning Applications
published: true
tags: Machine Learning,Reinforcement Learni
canonical_url: https://perfectial.com/blog/reinforcement-learning-applications/
---

You might have read about [Reinforcement Learning](https://perfectial.com/blog/reinforcement-learning-applications/) when browsing through [stories about AlphaGo](https://techcrunch.com/2017/05/23/googles-alphago-ai-beats-the-worlds-best-human-go-player/) – the algorithm that has taught itself to play the game of GO and beat an expert human player – and might have found it fascinating.

However, as the subject’s inherently complex and doesn’t seem that promising from a business point of view, you might not have thought it useful to explore it deeply.

Well, turns out RL’s lack of practical benefits is a misconception; there are actually quite a few ways companies can use the technology right now.

_In this post, we’ll list possible reinforcement learning applications and explain without technical jargon how RL works in general._

## Supervised Learning, Unsupervised Learning, and Reinforcement Learning

![reinforcement-learning-applications](https://perfectial.com/wp-content/uploads/2018/06/img1-7.jpg)

So, in conventional **supervised learning** , [as per our recent post](https://dev.to/galyna_chekan/machine-learning-in-finance-and-how-to-apply-them-16hh), we have input/output (x/y) pairs (e.g labeled data) that we use to train machines with. Knowing the results for every input, we let the algorithm determine a function that maps Xs->Ys and we keep correcting the model every time it makes a prediction/classification mistake (by doing backward propagation and twitching the function.) We continue this kind of training until the results the algorithm produces are satisfactory.

In conventional **unsupervised learning** , we have data without labels and we introduce the dataset to our algorithm hoping that it’ll unveil some hidden structure within it.

**Reinforcement learning** solves [a different kind of problem](https://en.wikipedia.org/wiki/Reinforcement_learning%20target=_blank%20rel=). In RL, there’s an agent that interacts with a certain environment, thus changing its state, and receives rewards (or penalties) for its input. Its goal is to find patterns of actions, by trying them all and comparing the results, that yield the most reward points.

One of the key features of RL is that the agent’s actions might not affect the immediate state of the environment but impact the subsequent ones. So, sometimes, the machine doesn’t learn whether a certain action is effective until much later in the episode.


The post [Reinforcement Learning Applications](https://perfectial.com/blog/reinforcement-learning-applications/) appeared first on [Software Development Company Perfectial](https://perfectial.com).
Explain what really happening when you put final in a class Like I'm Five
Tags: explainlikeimfive
Published: 2018-06-29 13:10:17

---
title: Explain what really happening when you put final in a class Like I'm Five
published: true
tags: explainlikeimfive
---

Variable change to constant ?
And what about function ?

My question is about what happen deep in the langage. (PHP or java, whatever)
Magento 2 Auto Currency Switcher by FMEextensions
Tags: magento2, languageswitcher, currencyswitcher, magento2extension
Published: 2018-06-29 12:39:26

---
title: Magento 2 Auto Currency Switcher by FMEextensions
published: true
description: 
tags: Magento 2, language switcher, currency switcher, Magento 2 extension
---
Magento 2 auto currency switcher by FMEextensions is a highly useful Magento 2 extension which automatically changes the store's language & currency based on the visitor's location. The extension first auto detects every visitor's location from their IP and then redirects them to a personalized store view. This functionality allows Magento 2 users to browse the store in their regional language and also make purchases in local currency. This ultimately improves overall customer's shopping experience.

Apart from the basic language & currency switching functionality, [Magento 2 auto currency switcher](https://www.fmeextensions.com/geo-ip-default-language-currency-magento-2.html) offers other useful features. One of them is manual switching. The extension allows customers who do not want automatic redirection to manually select the store to switch to. Magento 2 language switcher also allows IP exceptions to exempt some customers from redirection at all.

###Features - Magento 2 Currency Switcher

Some of the features of this extension are highlighted below.

- Auto detect visitor's location
- Auto currency & language switching
- Allows auto & manual switching
- Supports IP exceptions
- Import Geo location database
- Prompt box in footer allows users to change currency manually
- Create groups of countries and assign countries for Geo targeting
Introducing Brand-New Connectivity Features in dbForge Tools for MySQL
Tags: mysql, database, developertools, databasetool
Published: 2018-06-29 12:26:39

---
title: Introducing Brand-New Connectivity Features in dbForge Tools for MySQL
published: true
description: Devart has announced a significant update of its numerous dbForge tools for MySQL with the support for MySQL Server v8.0, MariaDB v10.3, Tencent Cloud. 
tags: mysql, database, developer tools, database tool
---

Devart, a Czech software vendor of database tools and data connectivity solutions, has released upgraded versions of dbForge Schema Compare for MySQL, dbForge Data Compare for MySQL, dbForge Query Builder for MySQL, dbForge Data Generator for MySQL and dbForge Documenter for MySQL. The enhanced tools support the latest MySQL Server, v8.0, and MariaDB, v10.3. What’s more, they now offer the ability to connect to Tencent Cloud, a relational database cloud service. 

Here’s a closer look at the most noteworthy improvements implemented in updated dbForge tools for MySQL:
1) Benefit from all features of MySQL Server 8.0
With updated dbForge Tools for MySQL, users can now generate data, compare schema and data diffs, build queries on the latest server version. 
2) Enjoy working with the latest MariaDB v10.3
New releases of all dbForge tools for MySQL offer an ability to connect to MariaDB v10.3.
3) Hook up with Tencent Cloud effortlessly 
Using upgraded dbForge tools for MySQL, users can connect to Tencent Cloud, a relational database cloud service, and manage MySQL databases in the cloud smoothly.

Got interested? For more goodies about the extended connectivity of upgraded dbForge tools for MySQL,  http://blog.devart.com/whats-new-in-dbforge-mysql-tools-80.html .

About Devart

Devart is one of the leading developers of database tools and administration software, ALM solutions, data providers for various database servers, data integration and backup solutions. The company also implements Web and Mobile development projects.

For additional information about Devart, visit https://www.devart.com/ .
The single most usefull php trait I use in my projects
Tags: php, showdev, code
Published: 2018-06-29 10:49:53

---
title: The single most usefull php trait I use in my projects
published: true
description: php traits
tags: php, showdev, code
---

I use this very often to convert a class to array and json. I thought I should post it here, it may help someone. 😀

```php
trait Serializer
{
    public function toArray()
    {
        return get_object_vars($this);
    }
    public function toJSON()
    {
        return json_encode($this->toArray());
    }
}
```
### How to use it. 
Assuming you have a model of `Person` and would like to access it somewhere in your code as an array or json.

```php
class Person
{
    use Serializer;
    private $id;
    private $name;
    public function setName($name)
    {
        $this->name = $name;
    }
}

$person = new Person();
$person->setName("Isaac");

$arr = $person->toArray();
print_r($arr);

$json = $person->toJSON();
print_r($json);
```
I find this very convenient while developing rest api's.
React.js cheatsheet
Tags: development, cheatsheet, react
Published: 2019-07-17 12:43:18

---
title: React.js cheatsheet
published: true
tags: development,cheatsheet,react,reactjs
canonical_url: https://medium.com/@fabiofranzini/react-js-cheatsheet-52c639a43ddf
---

![](https://cdn-images-1.medium.com/max/1024/1*siRjmNAVnqwJ6ggFAmA3Og.png)<figcaption>React.js cheatsheet</figcaption>

Developing SharePoint solutions by using the SharePoint Framework (SPFx) we don’t have to use a specific framework but we are free to use whatever we want.

This is a huge benefit for developers but there are circumstances where actually this thing is not really true.

There are two cases when in fact we are almost forced to use Reactjs:

- Use the react.js controls developed for the “[Office UI Fabric](https://developer.microsoft.com/en-us/fabric)“ library
- Reuse tons of code already developed in the various examples and solutions for SPFx like, for example, the new “[SharePoint Starter Kit](https://github.com/SharePoint/sp-starter-kit)”.

OK, I have to then be able to figure out react.js!  
There are many resources to learn this framework, free online courses and not, official documentation, etc.

In fact, after learning the framework, which has a fairly simple learning curve, always need to have a cheatsheet to remember quickly the available APIs.

I share with you then this page that I found: [https://devhints.io/react](https://devhints.io/react)  
In fact on the main site you’ll find many cheatsheet for as many frameworks, but in this case, the one for react.js, I find it really interesting.
Moving JSON informations to a default JSON template [Solved]
Tags: help, c, json
Published: 2018-06-29 09:23:25

---
title: Moving JSON informations to a default JSON template [Solved]
published: true
description: 
tags: help, c#, JSON
---

Hi everyone, I'm working at this since last week and I still can't find a way to solve this problem.
I have to adapt <a href="https://pastebin.com/J2ZEsgE9"> this JSON</a> to the standards of <a href="https://pastebin.com/6zY446GR"> this one</a>.
I'm currently working in c# and this is the first JSON file adapted in c# classes:
<img src="https://thepracticaldev.s3.amazonaws.com/i/asu2bt5qtgn6ffoy8vaw.PNG">

The second file parsed in c# classes: 

<img src="https://thepracticaldev.s3.amazonaws.com/i/urc6w001tw7epj0v8707.PNG">

Basically I need to fill dynamically the second class with the informations of the first JSON.
From the first file I don't need "Intervals" and all the informations that you cannot find in the second file.

Hope I've been clear and not OT, thanks.
Doubled welcome email
Tags: meta
Published: 2018-06-29 09:05:37

---
title: Doubled welcome email
published: true
description: 
tags: meta
---
# Problem description:
I've changed my primary email address here and got the "Welcome to dev.to" email.
Again.
Because I'm already registered user.

# Proposition
Changing email should not trigger procedure of sending welcome email. Instead user should be notified about that change.
Friday Blast #44
Tags: fridayblast, links, post
Published: 2019-01-20 15:26:01

---
title: Friday Blast #44
published: true
tags: friday_blast,links,post
canonical_url: https://horia141.com/friday-blast-44.html
series: "Friday Blast"
---

[High-performance rate limiting (2016)](https://medium.com/smyte/rate-limiter-df3408325846) - how Smyte does rate-limiting, with a fairly custom rate-limiter. Truth be told, these usually aren’t found off-the-shelf.

[Ways to think about machine-learning (2018)](https://www.ben-evans.com/benedictevans/2018/06/22/ways-to-think-about-machine-learning-8nefy) - a more business-oriented view of ML/AI etc. It’s pretty interesting to compare them to databases and what they did for companies. As a sidenote, the very large corporations we’re seeing are in part _powered_ by advances in technology, which the authors touch a little. It’s very hard to operate a 100000 employee company with paper. What would ML tools do to this? Perhaps allow even larger ones. Perhaps make them smaller. At least in terms of human intelligence, if not machine one.

[Intel and the danger of integration (2018)](https://stratechery.com/2018/intel-and-the-danger-of-integration/) - for most of my tech career Intel has been a constant and big presence. Seems the chickens have finally come home to roost for some of the bad decisions the company has made before. TSMC & others are beating Intel in the fab game. It’s for sure not the end of the road - just look at Microsoft, but it’s going to be rougher sailing ahead.

[It’s time for an RSS revival (2018)](https://www.wired.com/story/rss-readers-feedly-inoreader-old-reader/) - I let this one simmer in [Feedly](https://feedly.com) a bit before posting it here. According to their stats, it’s been read about 4000 times. That’s pretty massive as a medium. Hopefully with the woes of Facebook or Twitter, and the [media industry in general](https://dev.to/horia141/subscription-purgatory-2plk-temp-slug-2373305), RSS readers _will_ see a comeback.

[The Redis protocol is pretty great (2018)](https://lethain.com//redis-protocol/) - A layman’s introduction to the Redis protocol.
Facts to consider before choosing a CI platform
Published: 2018-06-29 06:32:18

---
title: Facts to consider before choosing a CI platform
published: true
description: These are the 10 facts you can consider before choosing your Continuous Integration platform. 
tags: 
---


![10 Facts to consider while selecting CI tool](https://thepracticaldev.s3.amazonaws.com/i/w3yq9vizlz5shab0ekje.png)

Want to add some more points? Share your thoughts
When Wordpress isn't the right choice? Developers Perspective
Tags: wordpress, staticwebsites, blogging, enterprise
Published: 2018-06-29 05:00:29

---
title: When Wordpress isn't the right choice? Developers Perspective
published: true
description: Everyone uses WP for Cheap, fast and efficient skinning of websites, find a different way. Learn the pros and cons and convince your client you need something better. 
tags: Wordpress, Static Websites, Blogging, Enterprise  
---

How you go about building a website is a developer's task. Every project has use cases, and to be able to solve your clients needs and wants, you may choose Wordpress as your first and only option. 

Wordpress offers, support, community and plugins, code and many more assets which will get you up and running quickly meaning happy clients and happy profits. 

However you may see it, as a developer I don't often recommend Wordpress. 

You may think this is a crazy thought, writing code from scratch on behalf of my clients gives me more control and better results in the end for them.  

If you build with today's modern technology stacks the output will be great than the overall input, which will in return provide for your clients. 

As a developer I say push your limits, don't rely on templates to produce results for your clients. Always be creating and of course don't stop developing.