teleren/devto huggingface dataset:
TypeScript Tutorial - 'infer' keyword
Tags: tutorial, typescript, webdev, beginners
Published: 2019-04-12 12:00:42

---
title: TypeScript Tutorial - 'infer' keyword
published: true
tags: tutorial, typescript, webdev, beginners
canonical_url: https://blog.graphqleditor.com/advanced-typescript-tutorial-infer/
series: TypeScript Tutorials
cover_image: https://thepracticaldev.s3.amazonaws.com/i/17vpwjlkz8taqzifwq20.png
description: Basic usage of infer keyword in TypeScript
---

Hello, this is starting the article for advanced TypeScript tutorial series. Today I'll cover basic usage of:

```typescript
infer
```

 For me, it was hard to understand at the beginning what I can really do with `infer`. Let's start with a really basic example.

```typescript
type FlattenIfArray<T> = T extends (infer R)[] ? R : T
```

So let's analyze this code:

1. We check if our generic Type is the array
2. If it is array extract the real type from it
3. If it does not leave it as is

Still, it is not clear what infer is doing, so let's proceed with another example

```typescript
type Unpromisify<T> = T extends Promise<infer R> ? R : T
```

This one looks more clear as it doesn't have parenthesis:

1. We check if type extends Promise
2. If it does we extract the type from the promise
3. If it does not leave it as is

See? If you use extends only just to check if the type is a promise you would use

```typescript
type Unpromisify<T> = T extends Promise<any> ? T : never
```

And in infer instead of any keyword, you infer the value from type. Let's try with more advanced types then:

```typescript
type FuncWithOneObjectArgument<P extends { [x: string]: any }, R> = (
  props: P
) => R;

type DestructuredArgsOfFunction<
  F extends FuncWithOneObjectArgument<any, any>
> = F extends FuncWithOneObjectArgument<infer P, any> ? P : never;

const myFunction = (props: { x: number; y: number }): string => {
  return "OK";
};

const props: DestructuredArgsOfFunction<typeof myFunction> = {
  x: 1,
  y: 2
};
```

Intellisense for props works like this:
![](https://thepracticaldev.s3.amazonaws.com/i/17vpwjlkz8taqzifwq20.png)

You can make use of it inferring React Component props for example or another function that uses destructured params.
Handling files with Drupal (CSV import)
Published: 2019-04-12 10:22:39

---
title: Handling files with Drupal (CSV import)
published: true
description: Drupal allows pretty smooth file management API for developers.
tags: 
---

Drupal allows pretty smooth file management API for developers.. Here is a small piece of code in which I tried to take CSVs as input, process them to get the data and insert the values into the database.[Read more](https://www.innoraft.com/blogs/handling-files-drupal-csv-import)
Implement subscription security 
Tags: azure, security
Published: 2019-04-11 16:12:37

---
title: Implement subscription security 
published: true
description: Implement platform protection
tags: #Azure, #Security
---
**Create Azure resource locks**
- Management locks help you prevent accidental deletion or modification of your Azure resources
- You can manage these locks from within the Azure portal
- To view, add, or delete locks, go to the RESOURCE MANAGEMENT section of any resource's settings blade
- When you apply a lock at a parent scope, all resources within that scope inherit the same lock

**Configure resource-level access policies**
- Azure Policy is a service in Azure that you use to create, assign, and manage policies
- Unlike RBAC, Azure Policy is a default allow and explicit deny system
- Azure Policy has several permissions, known as operations, in two resource providers:
    - Microsoft.Authorization
    - Microsoft.PolicyInsights
- Several built-in roles grant permission to Azure Policy resources
- If none of the built-in roles have the required permissions, you can create a custom role

**Configure subscription-level policies in Azure Policy**
- An Azure subscription is a logical unit of Azure services that is linked to an Azure account
- Azure management groups provide a level of scope above subscriptions
- Management groups enable:
    - Organizational alignment for your Azure subscriptions through custom hierarchies and grouping
    - Targeting of policies and spend budgets across subscriptions and inheritance down the hierarchies
    - Compliance and cost reporting by organization (business/teams)
- All subscriptions within a management group automatically inherit the conditions applied to the management group
Building out Azure Container Registry in Terraform
Tags: cloud, codeproject, gettingstarted, terraform
Published: 2019-04-26 12:46:18

---
title: Building out Azure Container Registry in Terraform
published: true
tags: Cloud,CodeProject,Getting started,Terraform
canonical_url: 
---

So I’ve previously done posts on the TerraForm template that I built to support creating a kubernetes cluster. The intention behind this was to provide a solution for standing up a kubernetes cluster in Azure Government. To see more information on that cluster I have a blog post [here](http://mackbytes.azurewebsites.net/2018/09/07/terraform-kubernetes-template/).

Now one of the questions I did get with it, is “How do we integrate this with Azure Container Registry?” And for those not familiar, Azure Container Registry is a PaaS offering that Azure provides that allows you to push your container images to a docker registry and not have to manage the underlying VM, patching, updates, and other maintenance. This allows you to just pay for the space to store the container images, which admittedly are very small.

The first part of implementing this logic was to create the Container Registry in TerraForm by using the following.

A key note is that the use of the “count” variable is to enable that this registry will not be created unless you create a “lkma” which is the VM that operates as the master.

```
resource "azurerm\_container\_registry" "container-registry" { count = "${lookup(var.instance\_counts, "lkma", 0) == 0 ? 0 : 1}" name = "containerRegistry1" resource\_group\_name = "${azurerm\_resource\_group.management.name}" location = "${var.azure\_location}" admin\_enabled = true sku = "Standard" depends\_on = ["azurerm\_role\_assignment.kub-ad-sp-ra-kv1"] }
```

So honestly didn’t require that much in the way of work. For the next part it is literally just adding a few lines of code to enable the connection between the registry and the kubernetes cluster. Those lines are the following :

```
echo 'Configure ACR registry for Kubernetes cluster' kubectl create secret docker-registry \<SECRET\_NAME\> --docker-server $5 --docker-email $6 --docker-username=$7 --docker-password $8 echo 'Script Completed'
```

So really that is about it. I’ve already made these changes to the GitHub template, so please check it out. The above lines of code allow a user principal information that I pass to the script to be used to connect the azure container registry to my cluster. That’s really about it.
Facebook direct links for Firefox is back!
Tags: firefox, facebook, opensource, security
Published: 2019-04-12 12:40:37

---
title: Facebook direct links for Firefox is back!
published: true
tags: Firefox,facebook,Open Source,Security
canonical_url: https://daniele.tech/2019/04/facebook-direct-links-for-firefox-is-back/
---

Let's talk again about one of my browser extension, this time to not get tracked so much on Facebook!

The post [Facebook direct links for Firefox is back!](https://daniele.tech/2019/04/facebook-direct-links-for-firefox-is-back/) appeared first on [Daniele Mte90 Scasciafratte](https://daniele.tech/eng).
Great developers are raised, not hired
Tags: career, developer
Published: 2019-04-12 08:47:59

---
title: Great developers are raised, not hired
published: true
description: Every company on the market is looking for the best talent. Companies are waiting when “the talent” will appear from nowhere as if there were some secret talent factory. The ideal candidate will have all necessary technical skills, will be a good “culture fit” and will perform well with little or no supervision. But there is a problem...

tags: career, developer
---

Every company on the market is looking for the best talent. Companies are waiting when “the talent” will appear from nowhere as if there were some secret talent factory. The ideal candidate will have all necessary technical skills, will be a good “culture fit” and will perform well with little or no supervision. 

[But there is a problem...](https://sizovs.net/2019/04/10/the-best-developers-are-raised-not-hired/)
What is testing?
Tags: beginners, tutorial, learning, devtips
Published: 2019-05-31 10:16:20

---
title: What is testing?
published: true
tags: beginners, tutorial, learning, devtips
canonical_url: https://www.codetips.co.uk/beginner/what-is-testing/
---

> It doesn't matter if you've been coding for five minutes, or five decades, you'll never write software that is perfect.

 ![What is testing?](https://images.unsplash.com/photo-1509228627152-72ae9ae6848d?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjExNzczfQ)

That doesn't mean you won't write good software, but it will have bugs (defects) and it's important you accept that early on.

Computers will do what we tell them to but they're not smart enough (yet) to do what we mean.

At some point, you'll make a (hopefully) small oversight, or a wrong assumption and you'll create a bug. It may never materialise; some bugs only happen under weird circumstances, so you may get lucky, but one day you may start getting some weird results and you'll have to find out why.

A simple example of this is a [function](https://codetips.co.uk/beginner/what-is-a-function/) that accepts two numbers and divides them.

<!--kg-card-begin: markdown-->
```
function divide(num1, num2) {
  num1 / num2
}

```
<!--kg-card-end: markdown-->

Seems pretty straight forward. Nothing could go wrong with these three lines of code, right? Wrong.

What if `num2` was zero? In [mathematics](https://www.mathsisfun.com/numbers/dividing-by-zero.html) - dividing by zero doesn't make sense. Try it - open up a calculator and try and divide any number by zero.

In programming - dividing by zero can have unintended consequences. It could cause unexpected or false results, or, in some cases/languages, it could even crash your application.

Now imagine your application has thousands of lines of codes, not just three, and you should start to understand how bugs can get introduced; regardless of how careful you are.

This is why developers test. We come up with "test cases" (like running our `multiply` function with a zero) and we observe how it reacts. If it doesn't react how we were expecting, we fix the code.

In six months time, when we've forgotten that you shouldn't divide by zero, and we decide to change the `multiply` function, we run our "test cases" again and we'll see that it produced an unexpected result and we've avoided breaking our application.

Test cases are usually written as code too, so they can be automated. We'll go through this process in much more detail in a later article - this was just an introduction to what testing is, and why it's so important.

Testing does not alleviate the chance for bugs, it only serves as an aid to increase our confidence in the code we've written. You should always be looking for opportunities to improve your tests or your code, and you should **always** remember, regardless of how many tests you have, or however long you've been a developer for:

> It doesn't matter if you've been coding for five minutes, or five decades, you'll never write software that is perfect.
MAKERS, FIND YOUR SUGAR
Tags: mindset, developers
Published: 2019-04-12 07:17:05

---
title: MAKERS, FIND YOUR SUGAR
published: true
description: Find something that will help you forward, gives you energy, and lets you have a change of mind from time to time
tags: mindset, developers, 
cover_image: https://thepracticaldev.s3.amazonaws.com/i/myejackl5c58ho2c8lue.png
canonical_url: https://www.shipharder.com/makers-find-your-sugar/
---

Sugar is sweet and can give you energy.
It can also make bad coffee taste better.

Every entrepreneur, maker, and developer doing side projects needs his/her own "sugar".

Although this sounds simple, finding the sweet spot (pun intended) can be difficult.

Some examples of "healthy sugar":

👉🏻Find a book that you can enjoy and learn from and that helps you to reach your goals.
👉🏻Do a small project that you enjoy coding on and that will teach you something.
👉🏻Listen to a podcast that inspires you and lets you switch down for 30 minutes.
👉🏻Go to a tech hub or a lunch meeting and talk to people about their problems and where you (or your idea) might help and have some social time.

Keep your "sugar" time-boxed, useful, and something enjoyable.

That way, you'll have something to go back on when you're stuck during your other efforts or simply to have a change of mind in between.

Code Hard, Ship Harder ✌🏻️ - Shipharder.com

_This article originates from [Shipharder.com](https://www.shipharder.com/makers-find-your-sugar/)
Friday Blast #68
Tags: fridayblast, links, post
Published: 2019-04-14 16:45:53

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

[Why we build CockroachDB on top of RocksDB (2019)](https://www.cockroachlabs.com/blog/cockroachdb-on-rocksd/) - an insightful post from the CockroachDB team about how they use [RocksDB](https://rocksdb.org/) as the storage layer for single nodes. RocksDB is a embedded KV-store in the vein of LevelDB, Sqlite etc. which uses [LSM](https://en.wikipedia.org/wiki/Log-structured_merge-tree) storage. For me it’s also interesting how this separation seems to be more-and-more common. Use a well known storage layer, and build only the value-added thing on top of it. Especially since said storage layer would deal with platform idiosyncrasies like `fsync` bugs etc. MySQL and even Postgres have been used this way, but they’re obviously more heavyweight.

[Exploring distributed systems theory: availability and consistency (2019)](https://hackernoon.com/exploring-distributed-system-theory-availability-and-consistency-e8c59e0875cd) - a nice read overall for linking the abstract (and fuzzy) nature of the CAP theorem with the real systems you’ll see. The best part was the discussion of a “CP” system like etcd/ZooKeeper and how trading off Availability just means not being able to have “perfect” availability - responding to _every_ query with some sort of success data. But not going into “stupid”” availability - like not responding to _any_ query. Systems like that usually are deployed in groups of `3` or `5`. And when a partition occurs, they’re designed to choose consistency. So the nodes outside the quorum won’t be able to handle writes - hence they won’t be _available_. But the system as a whole is still in a _decent_ functioning state of _reduced_ availability.

[The end of the beginning #youtube (2018)](https://www.youtube.com/watch?time_continue=7&v=RF5VIwDYIJk) - a presentation by Benedict Evans from Andreessen Horowitz on the “future” of _tech startups_ (as they know them at least). The main idea is that while IT has managed to affect a great deal of fields - with the biggest winners being in ecommerce and advertising - we haven’t even scratched the surface of what could be done. The hard part only comes from here in fact, but there’s the potential of affecting the whole global economy, from agriculture to logistics and medicine.

[Kubernetes in 5 mins #youtube (2017)](https://www.youtube.com/watch?v=PH-2FfFD2PU) - what it says on the box. A short guide for what is useful about K8s.
LeetCode 238. Product of Array Except Self
Tags: java, array
Published: 2019-04-12 05:41:02

---
title: LeetCode 238. Product of Array Except Self
published: true
description: Solution + explanation for problem 238
tags: java, array
series: LeetCode in Java
---

```java
public class Solution {
    public int[] productExceptSelf(int[] nums) {
        int len = nums.length;
        int[] ans = new int[len];

        for (int i = 0, temp = 1; i < len; i++) {
            ans[i] = temp;
            temp *= nums[i];
        }
        for (int i = len - 1, temp = 1; i >= 0; i--) {
            ans[i] *= temp;
            temp *= nums[i];
        }

        return ans;
    }
}
```

After the first for loop, `nums[i]` is equal to the product of the numbers from `0` to `i - 1`. At each iteration of the second for loop, `nums[i]` is multiplied by the product of the numbers from `i + 1` to `len - 1`. Therefore, after the two for loops, `nums[i] = nums[0] * nums[1] * ... * nums[i-1] * ... * nums[i+1] * ... * nums[len-1]`.

_Time Complexity_: `O(n)`

_Extra Space_: `O(1)`
Health issues you face being a Developer 🏥
Tags: discuss, health
Published: 2019-04-12 05:09:43

---
title: Health issues you face being a Developer 🏥
published: true 
tags: discuss, health 
---

You may be a JavaScript  Developer or a Ruby Developer, but there is one thing common about us all, and it's the way we work. We all use computers, we all type, we all sit for long hours on a chair, and we all stare at a screen for an awfully long period on time.


I discovered my Dev lifestyle affecting my health two years ago, and since then I have changed it a lot. In one of my previous articles here, I shared my experience of deteriorating eyesight and how I fixed it. 

{% link https://dev.to/sarthology/the-definitive-guide-to-protecting-your-eyes-for-developers-22jm %}

Through this post, I came to know that many other devs have faced this problem as well. 

So it’s a request to all experienced developers to share their story and tell us how you fixed your health problems or learned to to live with them. 

This will help aware the young developers, who are just beginning their careers, to make better health choices. 

Okay then, let’s start the discussion.

![](https://media0.giphy.com/media/l378gW7GaWG6Leeas/giphy.gif?cid=19f5b51a5cb018cb4655484f2e6e3ec2)
Tweak Advice to Match Your Situation 
Published: 2019-04-12 04:10:44

---
title: Tweak Advice to Match Your Situation 
published: true 
description: 
tags: 
series: Humility
---

I try to post recommendations that I believe in and believe will be beneficial to others.

However I don't work in every situation. I also know there are always exceptions even well known situations. 

I'm wanting people to think about the situation they are in and how different views may help to improve their work even if the specifics don't fully work for them, and help me to remember to do the same. 

I expect I'll make similar posts to keep this humility in the minds of readers.
Add file extensions to your dynamic imports to reduce size
Tags: webperf, javascript, beginners, webpack
Published: 2019-04-12 00:43:06

UPDATE: Here's a codesandbox with this situation: https://codesandbox.io/s/webpack-dynamic-import-duplication-array-gv0gq

## TL;DR

Instead of writing dynamic imports like this

```js
import(`./my-path/${fileName}`)
```

Write them like this

```js
import(`./my-path/${fileName}.ext`);
```

It will reduce the bundle size!

## Long explanation

Yesterday I was reading the generated code by webpack and found something interesting:

```js
var map = {
  "./en/_extras": [
    3,
    0
  ],
  "./en/_extras.js": [
    3,
    0
  ],
  "./en/color": [
    8,
    5
  ],
  "./en/color.js": [
    8,
    5
  ],
  // The rest of the files
};
```

That `map` object represent every possible chunk for an specific dynamic import, and it was twice the size I expected.

Then it hit me: I didn't wrote the file extension in my dynamic imports. When I did it, each of those objects reduced its sizes to match the numbers of files!

It's not like it will massively reduce your bundle size, but it's something you could get for free!
OO Ruby Concepts Part 2, Object Attributes
Tags: ruby, beginners
Published: 2019-04-11 22:17:47

---
title: OO Ruby Concepts Part 2, Object Attributes 
published: true 
description: 
tags: #ruby #beginners  
--- 
Last [post](https://dev.to/donnacamos88/oo-ruby-concepts-i-object-behavior-308a) I discussed objects and their behavior. This post will cover the attributes of an object and how to manipulate them to cause a certain behavior. 
   Every object has attributes. To make this clear, I looked up the definition of "Attribute" on Google and here's what it said: 

at·trib·ute

verb
1.
regard something as being caused by (someone or something).
"he attributed the firm's success to the efforts of the managing director"

noun
1.
a quality or feature regarded as a characteristic or inherent part of someone or something.
"flexibility and mobility are the key attributes of our army" 

Let's stick with our Cat class from the previous post and give it two attributes, name and breed, using the 'setter' and 'getter' instance variable methods. 
```ruby
class Cat # Object 
  def name=(garfield) #setter 
  @name = garfield 
  end 
  def name #getter 
      @name 
  end 
  def breed=(tabby) #setter 
     @breed = tabby 
  end 
  def breed #getter 
     @breed 
  end 
 end 
 
garfield = Cat.new("Garfield") 
garfield.name # "Garfield" 
```
This block of code contains both a "setter" and "getter" method which writes or sets the attribute and then reads or gets the attribute for the object to use. This code is long and becomes repetitive very quickly and unless you need to customize it, there's a better way to set and get attributes. 
 We use macro programming to accomplish this. Macros are a tool that allow programmers to reuse code. Attribute readers and writers are macros that implement this same code above with only two lines of code. 
```ruby 
class Cat 
   attr_writer :name, :breed  #setter
   attr_reader :name, :breed  #getter 
end 
```
As you can see, much more efficient. William Strunk, in his classic book "The Elements of Style" said, **"Omit needless words"**. Macros in programming **omit needless code** and allow the attributes to be added much more seamlessly. The attribute writer and reader can be further condensed with the attribute accessor like this: 
```ruby 
class Cat 
    attr_accessor :name, :breed # setter and getter all in one line
end 
```
Now let's make a new cat, with a name and breed and make it "Meow!" using the attribute accessor.  
```ruby 
class Cat 
    attr_accessor :name, :breed 
    def meow 
    puts "Meow!" 
    end 
end 

garfield = Cat.new 
Cat.name = "Garfield" 
garfield.name # Garfield 
garfield.breed = "Tabby" 
garfield.breed # Tabby 
garfield.meow # Meow! 
```
How Do You Handle Product Specs?
Tags: discuss
Published: 2019-04-11 21:20:22

---
title: How Do You Handle Product Specs?
published: true
description: 
tags: discuss
---

I once knew a product manager who made infographics out of all their specs. This was obviously a time consuming process. It took him hours to do what could normally be done in minutes.

It obviously made team communication easier (and more fun). The savings in meeting time alone may not have made that investment worth it, but I believe it also reduced miscommunication which meant less time was spent by developers building the wrong thing.

I've never seen anyone else do this though. What are your opinions of this approach? How do you normally see your product specs written up?