teleren/devto huggingface dataset:
Function Declarations vs Expressions: A Quick Guide
Tags: beginners, javascript
Published: 2018-11-28 20:48:33

---
title: Function Declarations vs Expressions: A Quick Guide
published: true
tags: 
    - beginners
    - javascript 
canonical_url: https://carlanderson.xyz/function-declarations-vs-expressions-explained/
---

Here's the question: What's the difference between these two methods of creating a function?

```
function a() {
	//This is known as a function declaration
	console.log("Hello");
}

var b = function() {
	//This is known as a function expression
	console.log("World");
}
```

Both of these methods do _almost_ the same thing, however there is one major difference:

```
a(); // "Hello, World"
b(); // Error

function a() {
	console.log("Hello, World");
}

var b = function() {
	console.log("Hello, World");
}
```

Unlike Function Expressions, which behave much in the same way that any other variable assignment would, Function Declarations are affected by a JavaScript feature called _hoisting._

Hoisting is where JavaScript moves function and variable declarations to the top of their scope. This is so that developers can freely choose how they want to organise their code without worrying about where a function has been declared.

## Which one do I use?

Since both approaches are largely the same, it's less important which approach you use, and more important that you are consistent.

Personally, I prefer to use function declarations at the top level, and function expressions for any inner functions, like so:

```
function foo() {
	var bar = function() {
		console.log("Hello, World");
	}

	setTimeout(bar, 1000);
}
```

The only thing to note is that _due to hoisting, function declarations behave the same as_ `var`, so you need to use `let a = function() {}` to get functions to use block scoping (or `const`).

If you want to read some more about functions in JavaScript, you can check out [my guide to closures](https://carlanderson.xyz/why-are-closures-so-confusing/).

_Psst. If you want to get more of these, [you should sign up to my mailing list](https://pages.convertkit.com/de362bddba/e411d0e335)_
Tips And Tricks That I use in my demos and presentation with Docker
Published: 2020-03-12 18:40:14

---
title: Tips And Tricks That I use in my demos and presentation with Docker
published: true
date: 2018-11-28 18:00:00 UTC
tags: 
canonical_url: https://gamov.io/posts/2018/11/28/tips-and-tricks-that-i-use-in-my-demos-and-presentation-with-docker.html
---

Table of Contents

- [Delete every Docker containers](#delete-every-docker-containers)
- [Open shell in running container](#open-shell-in-running-container)
  - [Extra carriculum matterial: How to do the same in case of Docker Compose?](#extra-carriculum-matterial-how-to-do-the-same-in-case-of-docker-compose)

 ![me presenting](http://gamov.io/images/me_presenting.jpg)

Figure 1. A very small tip for you!

TL;DR

The sole purpose of this post is to help me to return here time to time if I forget some of the commands.If this would be useful for anyone - praise me on twitter - [http://twitter.com/gamussa](http://twitter.com/gamussa). 

Let’s start with a small but important thing - how to erase everything Docker and start clean.

## Delete every Docker containers

|NOTE:| Don’t do this if you’re on the plane. Downloading new images using the airline’s wifi will be the pain. Proceed with caution. You have been warned. |

How many time you have found yourself running out of space in your laptop, and you don’t know who’s eating all the space.Usual suspects here are maven or gradle directory jar’s directory and Docker images directory.

```shell
❯ du -sh ~/.m2
2.4G /Users/viktor/.m2 (1)

❯ du -sh ~/.gradle
2.8G /Users/viktor/.gradle (2)

❯ du -sh ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.raw
8.1G /Users/viktor/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.raw
```

| **1** | Should I nuke it? |
| **2** | I definitely use Gradle more |

Must be run first because images are attached to containers

```shell
docker rm -f $(docker ps -a -q)
```

Delete every Docker image

```shell
docker rmi -f $(docker images -q)
```

## Open shell in running container

If I have a container that already running I can use `docker exec` command to connect to it!

First, get the name of the existing container using `docker ps`

With `docker exec -it <container name> /bin/bash` to get a bash shell in the container

Essentially, use `docker exec -it <container name> <command>` to execute whatever command you specify in the container.

### Extra curriculum material: How to do the same in case of Docker Compose?


```shell
docker-compose run <container_name_in_yml_file> <command>.
```

E.g. to get a shell into your Kafka container, you might run `docker-compose run kafka1 /bin/bash`

To run a series of commands, you must wrap them in a single command using a shell

```shell
docker-compose run <name in yml> sh -c '<command 1> && <command 2> && <command 3>'
```

The `docker run` command accepts command-line options to specify volume mounts, environment variables, the working directory, and more.
DEV.to public API?
Tags: discuss, meta
Published: 2018-11-28 17:44:27

---
title: DEV.to public API?
published: true
description: Working with dev.to API
tags: discuss, meta
---

I've looked around and couldn't find any docs about dev.to API so I guess that it's not open for public at this point. @devteam Are there any plans on this? It would be interesting to see what can be built with data from here.
First Windows Container Service on AWS
Tags: cloudservices, aws
Published: 2022-06-20 20:30:32

---
title: First Windows Container Service on AWS
published: true
date: 2018-11-28 16:46:00 UTC
tags: CloudServices,AWS
canonical_url: https://duplocloud.com/blog/first-windows-container-service-on-aws/
---

This weekend while creating an EC2 host, I got excited seeing “Windows Server 2016 with Containers” option in the menu. Microsoft had launched Server 2016 OS earlier this month and now AWS has launched support for the same. I can now proudly say that Duplo is the first windows container service on AWS. I would congratulate Microsoft and Docker for the API parity they managed to achieve with Docker in Linux.

Duplo’s container management component always supported the concept of “allocation tags” by virtue of which adding support for Windows Containers was a trivial effort. I wish i could write more on what it took to add windows container management support in Duplo, but the fact is there ain’t much to write. It only took an evening which was also mostly spent around the logistics of baking an AMI with duplo agent, exposing the UI options etc. rather than any core code update. Watch a demo below.

https://youtu.be/XOvHqLtRD-Q

The ECS service in AWS is also expected to release the support before the end of 2016 as stated in their [blog](http://aws.amazon.com/blogs/aws/run-windows-server-2016-on-amazon-ec2/). In case of Azure i have always been confused about their container management story, they say they support both Mesos and Docker Swarm. Also I heard about them considering support for Kubernetes. But I wonder in a public cloud why does the customer care which container orchestration software creates his containers. More than scheduling the containers the important piece seems to be integration of the service with the cloud eco-system like IAM, LB, DNS, Storage etc. So does Microsoft really plan to do this ecosystem integration with these three container management solutions? Why wouldn’t they just do what AWS did i.e. create their own that works natively in their cloud. It would be interesting to learn more about this strategy as more details become available in future.

The post [First Windows Container Service on AWS](https://duplocloud.com/blog/first-windows-container-service-on-aws/) appeared first on [DuploCloud](https://duplocloud.com).
A science fiction terminal emulator 🚀
Tags: fun, shell, javascript, electron
Published: 2018-11-28 15:54:23

---
title: A science fiction terminal emulator 🚀
published: true
description: a electron based app which emulates a sci-fi terminal
tags: #fun #shell #javascript #electron 
---

{% github GitSquared/edex-ui %}

Hey, I can not describe how cool that is 😎
I love this kind of projects :)
My First Visual Studio Code Extension
Tags: showdev, typescript, opensource
Published: 2018-11-27 17:50:46

---
title: My First Visual Studio Code Extension
published: true
description: 
tags: showdev, typescript, opensource
---

Some two days ago, I was thinking about how to optimize my way of navigating code through keybindings and I got this idea: what if I could just "point" the editor to the right place, without necessarily figuring out *how* to get there?

My first idea was to divide the visible editor's area into a grid in which every cell would have an assigned keybinding. In case there's more precision needed, there could be a second, smaller grid, made just of the cell that you selected before.

As I played with this idea in my mind, I decided that it's not really that great  and not that easy to implement in a *usable* way. But then something else came to my mind...

Some months ago, when I was all about keyboard navigation and keybindings, I used a browser extension that allowed me to click on stuff based on 1-3 letter codes, popping up whenever I want to go somewhere.

![](https://addons.cdn.mozilla.net/user-media/previews/full/189/189541.png?modified=1530209463)

This way of navigating resonated much more with my inner dev and seemed much easier to implement for a complete noob such as me.

Of course, I started off by trying to find something like this implemented by someone else already, but I didn't really know what exactly should I search for, so after a few tries I've given up.

And so, yesterday and today, I've coded furiously, spending way too much time on this, but I have the basic idea working:

![](https://raw.githubusercontent.com/goyozi/visual-nav/d25d1f7dffff5f13f67c3d3104babea0fae40f4d/navigation.gif)

You simply press `Alt+A` and a list of "combinations" pops up in different places of your code. Once you type a character combination, you will be taken to the desired place in the code. While in "navigation mode", you can also scroll up and down using `f` and `j` keys respectively.

I have to admit that the code is far from perfect and it probably doesn't always work right. Still, at the same time, I'm super curious what other people (i.e. you!) think about it and I'm realistic enough to know that it will probably never be perfect.

So here it is, my first Visual Studio Code extension:
https://github.com/goyozi/visual-nav

Let me know what you guys think!
Design for Developers by Sarah Drasner starts soon!
Tags: webdev, design, workshop
Published: 2018-11-28 15:30:51

---
title: Design for Developers by Sarah Drasner starts soon!
published: true
description: Check it out on Frontend Masters
tags: webdev, design, workshop
---

{% twitter 1067796979470819328 %}

Sarah Drasner is hosting a workshop on FrontendMasters about design for developers! [Check it out](https://frontendmasters.com) then check out this #discuss by Jaime Rios:

{% link https://dev.to/papaponmx/flipping-the-coin-should-developers-design-26ie %}
Unsupervised clustering for faster pairwise distance computation
Tags: python, unsupervisedlearning
Published: 2018-11-28 15:27:00

---
title: Unsupervised clustering for faster pairwise distance computation
published: true
description: 
tags: Python, UnsupervisedLearning 
---

Recently at work, I was given a list of locations(around 70k+) with their lat and long coordinates. My task was to find the nearest point of all the points in the list.


My predecessor who developed the first version used the simplest and most straightforward way for this computation -- for each point, compute Euclidean distance with all other points. This computation takes about 30 minutes to finish as it involves 70k * 70k times float point computation. The results are stored into a huge nested list, which takes a lot of RAM as well.


However, this computation efficiency is not acceptable in both production and testing environment. The following algorithm was created for enhancing computation efficiency:

- Apply K-Means with k=100 cluster centres on this dataset
- For each point, instead of computing pairwise distance with all other points, only compute pairwise distance with points in the same cluster and the nearest point in the cluster will be the nearest point in the dataset.

For each cluster, computation is done ~ 700 * 700 times. Therefore in total, 70k * 700 times computation is done. The computation is 100 times faster.

In fact, K-means clustering is very effective and efficient as compare to pairwise distance computation. After this algorithm implemented, it took less than two minutes.

First time using unsupervised learning in non machine learning related domain. Excited and want to record this down. However in production this methodology is not utilised as the technical lead decides to reduce the number of candidate locations and only recompute when there are new location points added into the list.

Either solve the problem, or reduce the problem. Lessons for the day
Introducing Laravel Links Telegram Channel
Tags: laravel, telegram, developer, resources
Published: 2018-11-28 14:17:10

Hi All,
I have started a new Telegram Channel dedicated to publishing links related to Laravel. Eg. Tutorials, Projects, Articles, Tips, Code Examples and more.

If you are interested. Take a look at :
https://t.me/LaravelLinks
https://telegram.me/LaravelLinks
Most Popular Development Posts Of The Week (28 November 2018)
Tags: freelancing, webdev, javascript
Published: 2018-11-29 13:56:44

---
title: Most Popular Development Posts Of The Week (28 November 2018)
published: true
tags: freelancing,webdev,javascript
canonical_url: https://medium.com/daily-now/most-popular-development-posts-of-the-week-28-november-2018-509dfb98eac4
cover_image: https://cdn-images-1.medium.com/max/1024/1*XVVrcIfplgx4Fh9RVmTayg.jpeg
---

It’s not that we need new ideas, but we need to stop having old ideas

- [Best Gifts for Programmers, Developers, and Coders — Treat Yo Self 2018](https://app.dailynow.co/r/9eeff558af0d681ce1f292fdb86e09b0) by [Trey Huffine](https://medium.com/u/47e700e59e44)
- [The Hottest Black Friday Deals For Web Developers](https://app.dailynow.co/r/2f1b440a492a31bc25fccae2c62a555a)
- [Top 3 Programming Language To Watch Out in 2019](https://app.dailynow.co/r/4a4a0e937bda68b277cbde6c17c7883b) by [Pramod Chandrayan](https://medium.com/u/88fc3f34995a)
- [A Look At The Top Developers Skills In Demand For 2019](https://app.dailynow.co/r/4508ab4af5a14dc0a002f1488113c063) by [Paresh Sagar](https://medium.com/u/974c4ff429a2)
- [Everything you can do with Javascript](https://app.dailynow.co/r/fb8a24092719e61eb919e08e13c493a0) by [Brenn](https://medium.com/u/b29abf345025)
- [Wake Up At 5 am Every Day? Nope. This Is My Daily Routine After 90 Days Of Experiments](https://app.dailynow.co/r/126bb3513ccf834d6c9f91a96d78a8d4) by [Diana Li](https://medium.com/u/af913f17e0a2)
- [Sharing my first personal website](https://app.dailynow.co/r/1cd2ae6d4462029f7ea5d4dc52502501)
- [Tools for Developers](https://app.dailynow.co/r/a222ebbd99168f1c20e56836004b0bbc)
- [5 Ways To Earn Money From Your Home](https://app.dailynow.co/r/8a9bfc714be9d370c1c492e1407ffb14) by [Gary Fox](https://medium.com/u/1e1ce6e3d0a2)
- [Front-end first software development approach](https://app.dailynow.co/r/a2f2d1cd9fbf06eef6debfb15282f3d0) by [Adarsh Somani](https://medium.com/u/256f9e1d8d15)

* * *

[_Thanks to Daily_](https://www.dailynow.co/) _developers can focus on code instead of searching for news. Get immediate access to all these posts and much more just by opening a new tab._

![](https://cdn-images-1.medium.com/max/1024/1*m8Uf-6F4Q5AOp_wW6tbKSQ.jpeg)
guide to a student
Tags: anonymous
Published: 2018-11-28 13:38:22

---
title: guide to a student
published: true
tags: anonymous
---

_This is an anonymous post sent in by a member who does not want their name disclosed. Please be thoughtful with your responses.
Hi I am a new to programming and I am an undergraduate and I need to know what to learn first and I am quite in a situation of can't figuring out what and where to start can you please help me become a good programmer.
Minimum flux with useReducer
Tags: react
Published: 2018-11-28 12:20:03

---
title: Minimum flux with useReducer
published: true
description: 
tags: react
---

Inject state and dispatcher context by React.Context and `useContext`

```tsx
import React, { useReducer, useContext, Dispatch, ReactElement } from "react";
import ReactDOM from "react-dom";

type CounterState = {
  count: number;
};

const initialState: CounterState = { count: 0 };

function reducer(state: CounterState, action: any) {
  switch (action.type) {
    case "reset": {
      return initialState;
    }
    case "increment": {
      return { count: state.count + 1 };
    }
    case "decrement": {
      return { count: state.count - 1 };
    }
    default: {
      return state;
    }
  }
}

// Container
const CounterContext = React.createContext<CounterState>(null as any);
const DispatchContext = React.createContext<Dispatch<any>>(null as any);

function App({ initialCount }: { initialCount: number }) {
  const [state, dispatch] = useReducer(reducer, { count: initialCount });
  return (
    <CounterContext.Provider value={state}>
      <DispatchContext.Provider value={dispatch}>
        <Counter />
      </DispatchContext.Provider>
    </CounterContext.Provider>
  );
}

// Connected component
function Counter() {
  const state = useContext(CounterContext);
  const dispatch = useContext(DispatchContext);
  return (
    <div>
      Count: {state.count}
      <button onClick={() => dispatch({ type: "reset" })}>Reset</button>
      <button onClick={() => dispatch({ type: "increment" })}>+</button>
      <button onClick={() => dispatch({ type: "decrement" })}>-</button>
    </div>
  );
}

ReactDOM.render(<App initialCount={2} />, document.querySelector(".root"));
```
BackSlash
Published: 2018-11-28 12:12:59

---
title: BackSlash
published: true
description: 
tags: 
---

```Note that the backslash itself must be escaped in order to display as a backslash.```

![img](https://i.kym-cdn.com/entries/icons/original/000/026/401/55C85DB6-A0B4-4C58-B590-5DDBF1FBB56A.jpeg)
Correct sort character data as numeric
Tags: postgres
Published: 2018-11-28 10:38:20

---
title: Correct sort character data as numeric
published: true
description: My experience in sort data numeric data in char column in SQL query.
tags: PostgreSQL 
---

Today I found solve problem to sort data in correct order. I say about char data content numeric data.
For example:

```sql
with rawData (sCol) as (
select '10.1.1'
union all
select '1.1.1'
union all
select '2.1.1'
union all
select '2.10.1'
union all
select '2.2.1'
)
select * from rawData
```

|scol   |
|-------|
|10.1.1 |
|1.1.1  |
|2.1.1  |
|2.10.1 |
|2.2.1  |


If I use standard sort
```sql
with rawData (sCol) as (
select '10.1.1'
union all
select '1.1.1'
union all
select '2.1.1'
union all
select '2.10.1'
union all
select '2.2.1'
)
select * from rawData
order by scol
```
output:

|scol   |
|-------|
|10.1.1 |
|1.1.1  |
|2.10.1 |
|2.1.1  |
|2.2.1  |


This is not right, but if I use split it's very cood output
```sql
with rawData (sCol) as (
select '10.1.1'
union all
select '1.1.1'
union all
select '2.1.1'
union all
select '2.10.1'
union all
select '2.2.1'
)
select * from rawData
order by
split_part(sCol,'.',1)::numeric,
split_part(sCol,'.',2)::numeric,
split_part(sCol,'.',3)::numeric
```
Output

|scol   |
|-------|
|1.1.1  |
|2.1.1  |
|2.2.1  |
|2.10.1 |
|10.1.1 |


This is PostgreSQL code, but this technique can by used in other database.
A nice collection of often useful examples done in React Native
Tags: react, reactnative
Published: 2018-11-28 09:18:40

---
title: A nice collection of often useful examples done in React Native
published: true
description: Awesome React Native components and tools.
tags: react,React Native
---

A curated list of awesome React Native UI/UX libraries

https://reactnativeexample.com/

![reactnativeexample](https://thepracticaldev.s3.amazonaws.com/i/b2yotxrqr7hqe0j9dw74.jpg)
A Well-defined Path To DevOps Success
Tags: devops, agile, ci, cd
Published: 2018-11-28 06:45:08

---
title: A Well-defined Path To DevOps Success
published: true
description: The article describes the important facts required to acheive true DevOps success
tags: devops, agile, ci, cd
---

_The article is originally published on [DevOpsCube](https://devopscube.com/systematic-map-devops-success/)_

Enterprises are going through a digital transformation and for years and years delivering software is being a bit of a challenge, we see a lot of friction and because of this, a lot of firms have tried to be agile but everybody has adapted to agile in a local fashion. If you take a look at the total lifecycle of how an application goes from a developer’s machine all the way into a production server, and then to the end customer, that entire workflow is anything but Agile.

Since from many years, organizations have struggled to adopt Agile and become Agile.

#DevOps is here to the rescue.

####A systematic map on how to achieve DevOps success

![DevOps success](https://thepracticaldev.s3.amazonaws.com/i/1iabncla260vuzkex752.png)

You must always remember, zero-touch automation is the goal, that doesn’t mean that you have to be deploying straight to production but if you want to do it, you should be able to do it. It should be so easy that even an operation guy can do it with just a push of a button and not going SSH’ing bunch of servers.

##DevOps is broken into 4 different blocks,
###1. Provisioning
###2. Build, CI and Packaging
###3. Testing
###4. Release and Deploy

Along with 4 stages, this has to go through all environments as shown in the image.

The goal here should be moving the automation in your organization as far to the right as possible.

![DevOps key pillars](https://thepracticaldev.s3.amazonaws.com/i/w7kuavrlka5m7qnuikop.png)


##The automation is built on these 4 core pillars,

1. Job run-time: All your complete enterprise should be using a common image format, or a common image on which all your applications are getting built. This pillar is more of a making sure of packaging & what versions to be installed across the enterprise.

2. State: Just running a particular task is not enough, you need to know what are all the other tasks are running, when was it last run, stable version, artifacts like IP addresses in automation, docker container tags etc all of these things should be systemically available.

3. Visibility: You need to know how entire workflow is going on and not required to go to each thing to get the idea. You need to be able to see everything in a single pane. This helps visually get an overview of your application automation process & status.

4. Operations: This is more of explaining how do you do deployments, how do you do scale etc

This DevOps automation process is very well explained practically by [Shippable](https://www.shippable.com/devops-assembly-lines.html#download-whitepaper) CEO, Avi Cavale in his [Webinar](https://www.youtube.com/watch?v=j26OFEMlUm4)



Start figuring out the critical processes you can automate and do DevOps the right way to succeed big.