teleren/devto huggingface dataset:
CentOS server setup guide for people from debian
Published: 2020-05-24 15:17:11

---
title: CentOS server setup guide for people from debian
published: true
date: 
tags: 
canonical_url: https://mmap.page/dive-into/centos/
---

A basic server setup guide for people from debian to CentOS.

## Software

`yum` is apt-get/aptitude on CentOS.

Remove not neccessary software:

```
yum grouplist
yum groupremove <wildcards>
yum list installed
yum remove <wildcards>

```

Upgrade system: (equivalent to `apt-get update && apt-get upgrade` on debian)

```
yum update

```

Add more packages:

http://wiki.centos.org/AdditionalResources/Repositories/RPMForge

Unlike Debian, Centos’s official package repo is very limited.

## Services

Check what is running:

```
chkconfig --list |grep '3:on' |awk '{print $1}' |sort

```

Use `chkconfig <service> off` to disable unnecessary services.

`chkconfig` is included as default in Centos.In Debian, you can install it via `apt-get install chkconfig`,though Debian people are likely to use `sysv-rc-conf` instead.

## Hostname

Make sure your `/etc/hosts` file have a line like:

```
127.0.0.1 <your-hostname>.example.com <your-hostname> localhost.localdomain localhost

```

And `/etc/sysconfig/network` have a line like:

```
HOSTNAME=your-hostname.example.com

```

Then run `hostname <your-hostname>.example.com`

Debian doesn’t use `/etc/sysconfig/network`.In Debian, you change hostname in `/etc/hostname`:

```
echo 'your-hostname' > /etc/hostname

```

Debian prefers to not include the `example.com` part.

## SSH

Same to Debian.

## Firewall

CentOS may enable iptables by default.You may want to disable it via `service iptables stop`or `/etc/init.d/iptables stop`.And disable its startup at boot time via `chkconfig`.

If you want to mess up with it, its configuration file is located at`/etc/sysconfig/iptables`, different to Debian.
A Path to from beginning to end
Tags: beginners
Published: 2020-05-24 15:17:03

As a beginner there are a lot of free resources out there to learn to code and there are also a lot of paid resources out there to learn the same thing... which I have found both in my journey to find exactly what i do want and do not want to do in coding. What started my interest was that i found at least three different lists of some number of free web sites to learn coding for free... and the lists just kept getting bigger, landing me in a literal sea of what to learn next and where...
   But then somehow i happened upon in one of those lists what is called a curated site (meaning it shows you the PATH, to get where you want to go) and this site showed all the free resources in order of how to get there. This site is called https://bent.io.com it has many different pathways for front-stack, back-end and full-stack developers and all the programs a person could want to learn and each program component has at least two of the best free web sites to learn what the person wants to learn. It was a goldmine for me. And i just wanted to share it with all of you beginners that are poor like me who have so much to learn but are not sure of the path to get there.
Thanks for reading,
Christine
Learning Golang 101
Tags: go, beginners
Published: 2020-05-08 05:33:34

### Go commands.
* go build compile package and dependencies
* go clean remove object files and cached files
* go get add dependencies to current module and install them
* go install compile and install packages and dependencies
* go list list packages or modules
* go run compile and run Go program.
* go test test packages
* go version print go version
* go fmt gofmt (reformat) package sources

For a completed list of commands. Please check [here](https://golang.org/cmd/go/). 

### Naming Conventions
* **The visibility of a name outside a package is determined by whether its first character is upper case.**
* Prefer simple name instead of a long name.
* Package name should be good: short, concise, evocative. By convention, packages are given lower case, single-word names; there should be no need for underscores or mixedCaps.
* The package name is the base name of its source directory; the package in src/encoding/base64 is imported as "encoding/base64" but has name base64,
* Go doesn't provide automatic support for getters and setters. Use `Owner` as an example, the getter method should be called `Owner` (upper case, exported), not `GetOwner`. A setter function, if needed, will likely be called `SetOwner`.
* By convention, one-method interfaces are named by the method name plus an -er suffix or similar modification to construct an agent noun: Reader, Writer, Formatter, CloseNotifier etc.
* The convention in Go is to use `MixedCaps` or `mixedCaps` rather than underscores to write multiword names.
Python Persistence
Published: 2020-05-24 15:16:12

---
title: Python Persistence
published: true
date: 
tags: 
canonical_url: https://mmap.page/python/persistence/
---

## tl;tr

If we care about compatibility with different Python versions,use `cPickle` with binary protocol and `fast` option.

Otherwise just use marshal.

## Performance

A benchmark of marshal, pickle, json, capnp for python 2.7 on my machine.

```
import timeit

md = "marshal.dumps({'people': [{'name': 'Alice'}]})"
im = 'import marshal'

p d= "pickle.dumps({'people': [{'name': 'Alice'}]})"

ip = 'import cPickle as pickle'

jd = "json.dumps({'people': [{'name': 'Alice'}]})"
ij = 'import json'

cd = "bm_capnp.AddressBook.new_message(people=[{'name': 'Alice'}])"
ic = 'import capnp; import bm_capnp'

def benchmark(d, i):
    return timeit.timeit(d, i, number=10000)

# Benchmarking
m = benchmark(md, im)
p = benchmark(pd, ip)
j = benchmark(jd, ij)
c = benchmark(cd, ic)

# Output result
output = "{name}: {time}".format

output(name='marshal', time=m)
output(name='(c)pickle', time=p)
output(name='json', time=j)
output(name="Cap'n Proto", time=c)

```

Cap’n Proto requires an additional schema file:

```
@0x934efea7f017fff0;

struct Person {
  name @0 :Text;
}

struct AddressBook {
  people @0 :List(Person);
}

```

Result:

```
marshal: 0.08457612991333008
(c)pickle: 0.31447696685791016
json: 0.7639560699462891
Cap'n proto: 0.4193081855773926

```

So marshal seems the fastest on my machine.

However, with binary protocol and `fast` option,`cPickle` is mostly as fast as `marshal`.

```
>>> md = 'marshal.dumps([1, 2, 3])'
>>> im = 'import marshal'
>>> pd = 'fp.dump([1, 2, 3])'
>>> ip = "import cPickle; fp = cPickle.Pickler(open('/tmp/1', 'wb'), 2); fp.fast = 1"
>>> timeit.timeit(md, im, number=1000)
0.012997150421142578
>>> timeit.timeit(pd, ip, number=1000)
0.017292022705078125

```

## Compatibility

### Compatibility with different Python versions

Marshal is for internal usage (`.pyc`).So its format may be modified on future versions of Python.Currently (up to Python 3.4.3), there are 4 versions of `marshal`.The current version can be viewed via `marshal.version`.

### Compatibility with other languages

Implemented in other languages:

- Ruby: [RMarshal](http://github.com/daeken/RMarshal)
- Go: [gopymarshal](https://github.com/hambster/gopymarshal)
- Perl: (read-only) https://github.com/gitpan/Python-Serialise-Marshal

## Export to JSON

To communicate with other programs,we can export to JSON.

On Python 2.7+, the `json` module from `stdlib`is [fast in encoding and decoding JSON](http://stackoverflow.com/a/15440843).No need to use other modules.
Composing binary functions with a fixed return type - wait, what?
Tags: functional, javascript, learning
Published: 2020-05-24 15:15:00

---
title: Composing binary functions with a fixed return type - wait, what?
published: true
description: 
tags: #functional #javascript #learning
---
Functonal programming is about composition. Ordinary composition of single-argument functions is trivial. It gets more interesting if we try to combine more complex function types of the real world. What about composing functions that compare two values and return a comparator?

First we don't want to rely on the `1`/`0`/`-1` comparator protocol but on a real tagged union:

```javascript
const Comparator = union("Comparator");

const LT = Comparator("LT", {valueOf: () => -1});

const EQ = Comparator("EQ", {valueOf: () => 0});

const GT = Comparator("GT", {valueOf: () => 1});

// monoid instance

const ctorEmpty = () => EQ;

const ctorAppend = tx => ty => 
  match(tx, {
    LT: _ => LT,
    EQ: _ => ty,
    GT: _ => GT
  });
```
Next we need a `Compare` type for functions that return a `Comparator`:

```javascript
const Compare = cmp => record(Compare, {cmp});

// monoid instance

const cmpEmpty = () => _ => _ => ctorEmpty();

const cmpAppend = tx => ty =>
  Compare(x => y => ctorAppend(tx.cmp(x) (y)) (ty.cmp(x) (y)));
```
Now we can combine several `Compare` based functions to define more complex comparing rules. We can do this because we implemented the monoid instances for both types:

```javascript
const isEven = x => (x & 1) === 0;

const byNatural = Compare(x => y =>
  x < y ? LT
    : x > y ? GT
    : EQ);

const byEven = Compare(x => y =>
  isEven(x) && !isEven(y) ? GT
    : !isEven(x) && isEven(y) ? LT
    : EQ);

const xs = [4, 8, 2, 5, 3, 9, 6, 1, 7, 0];

xs.sort(
  (x, y) =>
    cmpAppend(byEven)
      (byNatural).cmp(x) (y)); // [1, 3, 5, 7, 9, 0, 2, 4, 6, 8]
```
[run code](https://repl.it/repls/ImpartialInvolvedProgrammingmacro)

We use a destructive sort function, but that is okay for the time being.
Coding Challenges: How to get over the hump
Tags: codenewbie, interviewprep, javascript, 100daysofcode
Published: 2020-05-24 15:08:36

I have been hitting the coding challenges on Hackerrank pretty hard. At first I would google the parts of the problem and find that jazzy ES6 feature that would help make my code beautiful and succinct. Wouldn't that be nice. Problem was I didn't learning how to solve problems with code. I didn't understand how to solve problems with basic plain ole JS. 

This issue truly came to light when I signed up on Skillz and did a mock technical interview. As a very sociable person, talking with someone that has way more experience than me isn't intimidating, it's an opportunity. I took this opportunity to find out what my short comings would be. Everything was going great. My interviewer presented the problem he gives to every Junior hire at his firm. Then came the crickets. I stumbled through the iteration, eked out the if statements and created a poorly named variable that eventually returned correctly. Passing the verbal communication part and failed the coding part. Why couldn't I get it? I understood what needed to happen in the problem. Those jazzy ES6 features eluded me and Google Fu couldn't save this interview.

The feed back was simple, you don't know the basics well enough to pass a Junior interview. Not shocked but bummed out. The interviewer laid it out for me in very basic terms. Most data comes in form of objects, array or array of objects. Then it came the golden goose, Iterate through your data, filter out with comparison operator or save specific data to a well named variable and return data. This nugget was a true turning point. 

From that point on, a new approach to coding challenges was born. At first it was really hard, the commitment to avoiding Google eventually got me over the hump. Using the basics helped me understand JS more. Using skills that I have is more impressive then trying to impress with ES6 features I can't remember and don't understand. When I am writing more complex code in the future the basics will be the building blocks of those jazzy ES6 features. For now this what I got..
Deno Oak | REST API Tutorial
Tags: deno, webdev, tutorial, beginners
Published: 2020-05-24 14:57:55

If you are starting out on Deno, Oak is a net server you can start using for things like web servers, REST and API endpoints. It is similar to express which exists on nodejs, and you can create listen on different ports with routers as well. This tutorial takes you through the fundamentals for it.

{% youtube BAu7fnCbxAs %}
<center>[Youtube: Deno Oak](https://youtu.be/BAu7fnCbxAs)</center>

Included in this video are:
* Installing Deno Oak
* Performing a Hello World web server
* Adding logging
* Creating routes for API endpoints
* Setting up GET, POST, PATCH, DELETE endpoints

Oak:
https://github.com/oakserver/oak

Deno:
http://deno.land/

## Follow and support me: 
Special thanks if you subscribe to my channel :)
* [🎞️ Youtube](https://www.youtube.com/channel/UCvM5YYWwfLwpcQgbRr68JLQ?sub_confirmation=1)
* [🐦 Twitter](https://twitter.com/adrian_twarog)

## Want to see more:
I will try to post new great content every day. Here are the latest items:
* [Adobe XD to Fully Responsive WordPress Site](https://dev.to/adriantwarog/adobe-xd-to-fully-responsive-wordpress-site-16e0)
* [Adobe XD to HTML Full Process](https://dev.to/adriantwarog/adobe-xd-to-html-full-process-ao6)
* [Full Tutorial on how to use SASS to improve your CSS](https://dev.to/adriantwarog/full-tutorial-on-how-to-use-sass-to-improve-your-css-57on)
* [Creating a Mobile Design and Developing it](https://dev.to/adriantwarog/creating-a-mobile-design-and-developing-it-5c4o)
Build a Simple Web App using Go
Tags: go, webapplication, beginners
Published: 2020-05-24 14:57:01

Hello everyone, Today I would like to discuss building a simple hello world web app with Golang. Go is already has a web server built-in. The "net/http" package from the standard library contains all the things we need to do with the HTTP protocol. In this example, we will see how easy it is to run a web server that we can see in our browser.

For creating a webserver in go, we need to understand two main functions.

# Request Handler
  As the name suggests, the Request Handler is the one which receives all the http connections from the browser. The syntax of the Request Handler function is 
  
  ```func (w http.ResponseWriter, r *http.Request)```

  The handler function receives two arguments:

  1. http.Request - contains all details about the HTTP request including things like the URL, header or body fields.

  2. http.ResponseWriter - where we write out a response to.

  So first, we need to register a Handler function. 

# Request Listener
The Request Handler function can only receive the http connections. Along with that, we need a Request Listener which listens on a port and passes the connection to the Handler function. 

The syntax of a listner function is

```http.ListenAndServe(":3000", nil)```

The listener function receives two arguments:
1. port - The port to listen for the http connections.
2. handler - the handler to send all the connection. Typically the handler is nil.

# Hello World Web App
By understanding the above function, it is simple to create a web server. The code for a simple hello world web server looks like this

```
// main.go
package main

import (
	"fmt"
	"net/http"
)
func main() {
  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, World!")	
  })
  http.ListenAndServe(":3000", nil)
}
```

Run the main.go using the command ```go run main.go```

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

So, if we now go to the browser and open http://localhost:3000/ we can see the "Hello, World!" text which we are returning. 

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

In this example, the handler function is mapper to the root path which is "/". Likewise, we can create multiple routes and register them to their corresponding handlers.

All done! 🎉

That’s it for now guys. Will meet you guys again with another interesting topic.
Common Ethics for better coding !
Tags: beginners, python, codenewbie
Published: 2020-05-24 14:46:42

Last week I tried the Foobar challenge.

It is a set of coding challenges of five levels. Difficulty increases as we proceed each level. We can code the solutions in Python or Java. My weapon was Python.

I have completed 3 levels of the challenges (Further challenges are totally out of my reach!). Here are the lessons I learnt after attempting the challenge.

## 1. Make your concepts “crystal-clear”

![Alt Text](https://media.giphy.com/media/QMoXJjGPsmJ6Pdc596/giphy.gif)

The first challenge went quite easy. But during the second one I had to brush-up some points to be able to solve it. And that consumed my most of the time.

## 2. Solve the problem first

![Alt Text](https://media.giphy.com/media/UKkes2qN2T70s/giphy.gif)

Solving the question prior to coding gives us an idea of what and how to code. Starting to code in vague, leads to more confusion.

## 3. Test your code

![Alt Text](https://media.giphy.com/media/LmNwrBhejkK9EFP504/giphy.gif)

Testing the code lets us know how we can improve our code for the correct solution.

## 4. Take your time

![Alt Text](https://media.giphy.com/media/xih4bMlVJDGfra02eo/giphy.gif)

All work and no play makes Jack dull. Thinking about a problem for long time doesn’t help much. Take a break. Fresh up your mind and then get back to code !

![Alt Text](https://media.giphy.com/media/W23HteMtqFbJ8xAtP7/giphy.gif)

So, how’s the article ? Share your coding/learning experiences down in the discussion.

Thanks for reading !
Chapter 3: Equality For All
Tags: tdd, books, testing
Published: 2020-05-24 14:42:29



## Summary
Beck starts the chapter by introducing the concept of a value object. A value object cannot be mutated and so any message that changes the "value" in a value object should produce a new object.  `Dollar` is on its way to becoming a value object. The refactoring in the previous chapter made the `times` method return a new `Dollar` object instead of mutating the `amount`. 

Another property of a value object is responding to `equals`. This makes it comparable to other value objects of the same class. 

```java
public void testEquality() {
	assertTrue(new Dollar(5).equals(new Dollar(5)));
}
```

He first implements equals by hardcoding the return value of `equals`.

```java
public boolean equals(Object object) {
   return true;
}
```

He uses this as an opportunity to introduce _triangulation_.
Triangulation is adding a test to drive you towards a refactoring. A refactoring to a more generalized implementation. It's another tactic you can use when following the strategy of first making things work and then making things right. Beck says triangulation is useful when the refactoring is not obvious.

The second test is

```java
public void testEquality() {
	assertTrue(new Dollar(5).equals(new Dollar(5)));
	assertFalse(new Dollar(5).equals(new Dollar(6)));
}
```

He finishes by implementing a more generalized `equals`. He postpones implementing other properties of value objects because they are not immediately necessary, but he adds those things to his test list.

## Commentary

This chapter seems to be a way for Beck to introduce triangulation. However, he makes a few casual remarks that stood out to me. 

In trying to explain the value of using triangulation he asks:

> What axes of variability are you trying to support in your design?

I think this is a question that has many levels. There is the level of comparing instances of `Dollar`. There is the level of trying to add support for multiple currencies. There is another level of the whole WyCash bond portfolio management system. But I can only say "I think" because Beck does not offer any more explanation. Maybe it's just about comparing instances of `Dollar`.

Another remark is:

> That will let us make “amount” private, as all good instance variables should be

Why should instance variables be private? What makes that a better design? He continually drops lines like this as if the reader shares his context. It's one of the most frustrating parts of the book.

Beck could not have known that the book would be read by people who don't share his background or sensibilities. Programming wasn't as a big an industry as it was when he wrote the book and there weren't so many different people trying to become better programmers. This makes the book difficult for people without some background in the design ideas that he uses to navigate towards an implementation.
JavaScript App from Scratch
Tags: javascript, codenewbie
Published: 2020-05-24 14:42:14

A senior (and very kind) software engineer wisely told me, 

**"Just because you learned something once doesn't mean you'll remember it."**

Words I fell back on recently so as not to feel so discouraged. I do not remember what I learned two weeks ago, let alone two months ago. But that doesn't have to be the story I tell.

Setting up for a JavaScript app/project was like learning from scratch. My poor brain didn't even give me a boost.

For future-Anna-who-will-forget or for the rare gems reading (I appreciate you!), let's dig in to the steps for getting started.

**JavaScript App - Getting Set Up**

1) Make a new directory in your top-level project and cd into it. Name it what you wish - here I use `drumkit` but use `beast-mode` or whatever makes sense for your project.

```
mkdir drumkit
cd drumkit
```

2) In the new folder, create a single HTML page for your application, and a folder to hold your JavaScript files.

```
touch index.html
mkdir src
touch src/index.js
```

3) Start with a single JavaScript file. Later, you can split your code into multiple files for organization.

`touch src/index.js`

4) In index.html, you need to add some HTML. 

```
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
   Replace me with your glorious words! 
  </body>
</html>
```

5) Open this file in your browser to make sure things are working - run this command in your terminal:

`open index.html`

6) To get the JavaScript part of the project up and running, link the JavaScript file to your HTML page with a `<script>` tag:

```
<script src="src/index.js"></script>
```

7) To check that your JavaScript file is linked correctly, add a log statement, refresh, and view the result in the JavaScript console (in `src/index.js`).

`console.log("testing...")`

A thing of beauty, eh?

![Image showing browser with sample text and console message](https://dev-to-uploads.s3.amazonaws.com/i/25p9d01s8njps0mldm80.png)

8) At this point in the game, I like to connect to a new repo in GitHub. Helps hold me accountable and gives me practice using GitHub.

And I *still* need to refer here for the steps:

[Import a Project to Github](https://help.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line)

9) If you'll be creating your own styling, create your style.css file within the root directory (style.css). 

Then, within the file index.html, link to it:

`<link rel="stylesheet" href="style.css">`

Let's take a look:

![VS Code index.html showing build of page](https://dev-to-uploads.s3.amazonaws.com/i/f6b7igfe3oznbr0masmu.png)

That should get you started beautifully. 

The next steps will be up to, as you navigate through your own project and content. 

Here's hoping this helps give you a boost. If you have other tips to add, I will happily read them - please add in the comments below!