teleren/devto huggingface dataset:
Infer return type with generic Where clause in protocol and extensions.
Tags: swift, ios
Published: 2020-01-13 14:45:17

Let's look at the code:

```swift
extension UIView {
    class func loadFromNib<T: UIView>() -> T {
        guard let nib = Bundle(for: T.self)
            .loadNibNamed(String(describing: T.self), owner: nil, options: nil)?.first as? T else {
            fatalError("Missing nib for class.")
        }
        return nib
    }
}
```

The code gets the job done, it loads an `UIView` from `xib` file and returns the view. 

But at the call site, the return type is not inferred, we'll have to specify `UIView` Type like this

```swift
let view: ActionView = ActionView.loadFromNib()
```

to access the properties of `ActionView`. While `swift` can infer the type, I don't want to do this.

Instead the same function could be written as a `protocol` with `Where Clause` this enables `swift` to auto infer type.

```swift
protocol NibLoadable where Self: UIView {
    static func loadFromNib() -> Self
}

extension NibLoadable {
    static func loadFromNib() -> Self {
        guard let nib = Bundle(
            for: Self.self).loadNibNamed(
            String(describing: Self.self),
            owner: nil,
            options: nil
        )?.first as? Self else {
            fatalError("Missing nib for class.")
        }
        return nib
    }
}
```

Just conform to this protocol and you'll get the function with automatic type inferring.

With this implementation, the view type is auto inferred by `swift`.

```swift
let view = ActionView.loadFromNib() // view's type is auto inferred.
```
Daily Challenge #161 - Square into Squares
Tags: challenge
Published: 2020-01-13 14:30:18

---
title: Daily Challenge #161 - Square into Squares
published: true
description: Given a positive integral number n, return a strictly increasing sequence (list/array/string depending on the language) of numbers, so that the sum of the squares is equal to n²
tags: challenge
---

##Task

Given a positive integral number n, return a strictly increasing sequence (list/array/string depending on the language) of numbers, so that the sum of the squares is equal to `n²`.

If there are multiple solutions (and there will be), return as far as possible the result with the largest possible values:

###Examples

`decompose(11)` must return `[1,2,4,10]`. 

*Note that there are actually two ways to decompose*:
 
`11², 11² = 121 = 1 + 4 + 16 + 100 = 1² + 2² + 4² + 10²` but don't return `[2,6,9]`, since `9` is smaller than `10`.

For `decompose(50)` don't return `[1, 1, 4, 9, 49]` but `[1, 3, 5, 8, 49]` since `[1, 1, 4, 9, 49]` doesn't form a strictly increasing sequence.

##Note

Neither `[n]` nor `[1,1,1,…,1]` are valid solutions. If no valid solution exists, return `nil`, `null`, `Nothing`, `None` (depending on the language) or `[]` `(C)` ,`{}` `(C++)`, `[] (Swift, Go)`.

The function "decompose" will take a positive integer n and return the decomposition of `N = n²` as:

- [x1 ... xk] or
- "x1 ... xk" or
- Just [x1 ... xk] or
- Some [x1 ... xk] or
- {x1 ... xk} or
- "[x1,x2, ... ,xk]"

depending on the language (see "Sample tests")

*Note for Bash*

`decompose 50 returns "1,3,5,8,49"`
`decompose 4  returns "Nothing"


*Hint*
Very often xk will be n-1.

***
_This [challenge](https://www.codewars.com/kata/54eb33e5bc1a25440d000891) comes from g964 on CodeWars. Thank you to [CodeWars](<https://codewars.com/>), who has licensed redistribution of this challenge under the [2-Clause BSD License](<https://opensource.org/licenses/BSD-2-Clause>)!_

_Want to propose a challenge idea for a future post?  Email **yo+challenge@dev.to** with your suggestions!_
I'm here to encourage you, ask me anything!
Tags: ama, career, freelancing, webdev
Published: 2020-01-13 14:03:28

I started reading articles on dev.to 2.5 years ago and I'm still amazed how welcoming this community is, especially for beginners. 4 months ago I decided to give some love back and started to write one article per week. I was overwhelmed by all your reactions, follows and positive feedback and I'm wondering if I might encourage you from dev to dev in your current situation.

A little bit about myself: I'm a 30 y/o German software developer and consultant living in Berlin. I'm happily married and father of two sweeties. I studied Computer Engineering at the Technical University of Berlin - it took me 3 additional years to finish my studies, (partly) because I started working as a system administrator at the university itself and later as a freelancer in web development during my studies.

When getting my Masters degree, I had grown the number of projects I worked freelance for, so I decided to go full-time and that currently works very well for me and my family (very flexible working times, an average of 30-35 hours/week, home office).

I really don't know much, but I would love to help you by sharing my experience e.g. to the following topics:

- home office, balancing work and family (especially with kids)
- freelancing (get projects, get clients)
- programming (Javascript, Python, PHP, CSS, VueJS)

I don't want to give you cheap answers, so please forgive me if it may take me a while to answer 😇.
Using Codepen for more than CSS art
Tags: css, codenewbie, html, javascript
Published: 2020-01-13 13:57:02

Good day galera*,

Today I am writing about how I use [Codepen](https://codepen.io/).
 
Just in case you are not familiar with it:
>"CodePen is an online community for testing and showcasing user-created HTML, CSS and JavaScript code snippets."

When you open Codepen's main page, you see all sorts of beautiful CSS art that makes you wonder about how awesome CSS truly is and ponder about how you know nothing about CSS (or is that just me?).

Now, if you are like me, you know CSS but you are not at the artsy level (yet) and maybe you don't use it very much or at all. 
But you should!

Here the main things I use Codepen for:


1. To test concepts I am learning,
2. To test random code I got out of internet,
3. To share my code when I need some help.

Now I proceed to explain a bit about each bullet topic, because that is how this writing thing works lol


##To test concepts I am learning##
You are reading about things on a book or here at Dev.to as I do everyday, and learning some new things. 
And of course you want to try it ASAP to see how it works.
So you just open Codepen and do just that, as well as saving that piece of code for later.
Like when I was getting started with JavaScript and wanted to try the IF/ELSE by myself right away:
{% codepen https://codepen.io/p4chi/pen/mZGxWo %}

##To test random code I got out of internet##
We all do it. Do not tell me you don't, because you know you do.
Sometimes we just copy a piece of code out of StackOverflow or other place that google because we are a bit stuck and someone else was surely stuck about the same thing at some point.
BUT before pasting it in out code, we have to understand it folks. 
And maybe change it a bit.
And here comes Codepen again. 
Of course, you could just do it in your test editor, but doing it on Codepen means you can save it as a future reference and it is just easier.

Like earlier this week I had to figure out how to put an image inside a search box, so I got some code from I don't even remember where:
{% codepen https://codepen.io/p4chi/pen/NWPXymq %}

##To share my code when I need some help##
It is just easy to put your code there and give the link to my Brother so he can give me a push or a tip of where is the effing typo that I can't find but is messing with my code (usually, it is just a missing letter😅).
And again, have it saved somewhere.
I don't have a pen example of that because all mistaken are now fixed, but here is a pen of one of Elliot's rant (Mr. Robot anyone?).
{% codepen https://codepen.io/p4chi/pen/mowprV %}

###So yes...###
Codepen is a real nice tool for more than showing off your CSS skills (like dear {% user janetmndz %} do so well, seriously, [check her Codepen](https://codepen.io/janmez/) ), 
it is also a place where you can test, learn and share, and has been a very helpful tool in my #codeNewbie life.

That is all for today,
Happy Monday,
XOXO,
P.






* *galera is a work in Portuguese that folks, guys, you all... Got it?*
9 Game-Changing Tools That Every Developer 

Published: 2020-01-13 13:48:20

Software development is one of the most creative and challenging things to do. If you are also one of them who want to make their career in software development this article going to help you a lot.

In this article, I am mentioning 9 game-changing tools that every remote developer can’t live without.


From coding to designing these tools will help you in every aspect of software development.


Here are <a href="https://codersera.com/blog/9-game-changing-tools-that-every-remote-developer-cant-live-without/">9 must-have development tools.</a>
<ol>
<li>GitHub</li>
<li>Basecamp</li>
<li>Slack</li>
<li>Hubstaff</li>
<li>InVision</li>
<li>CodinGame</li>
<li>CodeChef</li>
<li>Appery.IO</li>
<li>dev.to</li></ol>
Finding Unused CSS and JS code using Google Dev Coverage Tab
Tags: googledevtools, optimization, webdevelopertools
Published: 2020-01-13 13:48:17

---
title: Finding Unused CSS and JS code using Google Dev Coverage Tab
published: true
description: There is a lot that Google dev tools could do, but this article will focus on identifying unused code. And of course, there are more than one way to find dead code, but this method is simpler as it doesnt require additional libraries
tags: googledevtools, optimization, webdevelopertools
cover_image: https://d220lq6zcuj7hx.cloudfront.net/wp-content/uploads/2020/01/Chrome-Coverage-Tab.jpg
---

There is a lot that Google dev tools could do, but this article will focus on identifying unused code. And of course, there are more than one way to find dead code, but this method is simpler as it doesnt require additional libraries. The very basic reason is performance improvement. The lesser the files, the faster the page loads.

**47 per cent of consumers expect a web page to load in two seconds or less. 40 per cent of consumers will wait no more than three seconds for a web page to render before abandoning the site**

Imagine all the users/customers you could lose visiting your website just because it doesn’t load in a few seconds. So it is really important that the files we send are minimal and does not contain junk.

[Read More](https://w3lessons.info/coverage-tab-of-google-dev-tools-to-find-dead-code/)
How to add commits to another person's PR on your Github repo
Tags: git, github, beginners
Published: 2020-01-13 13:45:59


## TLDR

```shell
git push git@github.com:remoteUser/remoteRepo localBranch:remoteBranch
```

## Explanation

The normal `git push` command usually looks like this:

```
git push origin branch
```

Pushing to another developer's branch follows a similar pattern: `origin` is the other person's repo, and `branch` maps your local branch to the same branch on their remote repo.

`origin` = `git@github.com:remoteUser/remoteRepo`

`branch` = `localBranch:remoteBranch`

Breaking down each variable:

`remoteUser` refers to the username of the developer who made the pr on your repo

`remoteRepo` refers to the name of the repo that the other developer is creating the PR from, usually, this is the same name as your repo.

`localBranch` refers to the branch name of your local copy of their remote branch

`remoteBranch` refers to the branch name of that their PR is originating from on their `remoteRepo`

Keep in mind, that you can only push to PRs from other developers on your repo if that developer selected "Allow edits from maintainers" when they created their PR.

## Example

Let's say you created the open source project, [Material Bread](https://github.com/codypearce/material-bread). After releasing the project, another developer, with the Github username [alburdette619](https://github.com/alburdette619), forks your project and creates a pull request with some new features. While reviewing `alburdette619`'s PR you realize that his changes will need to be documented in the project's README.

First, we need to fetch his changes into a branch on our local machine. We can do that using this command:

```shell
git fetch origin pull/branch/head:branchName
```

In this case, the branch on his PR is number `306`, and I want to name it `pr/306`:

```shell
git fetch origin pull/306/head:pr/306
```

We can now make changes on our local branch `pr/306` and commit them:

```shell
git commit -m "Update Readme with feature xyz"
```

Finally, we can push these changes to `alburdette619`'s PR with the new commit using the command defined at the top of the article.

```shell
git push git@github.com:remoteUser/remoteRepo localBranch:remoteBranch
```

The `remoteUser` is `alburdette619`, the `remoteRepo` is `material-bread`, the `localBranch` is `pr/306`, and the `remoteBranch` is `306`.

```shell
git push git@github.com:alburdette619/material-bread pr/306:306
```
What do you use for prototyping data structures?
Published: 2020-01-13 13:45:42

So far I've mostly used pen&paper. Tools for designing the data structure or graphing felt either a bit clunky or way too complex for my needs.

## What about you?

Recently, since I picked up typescript I found using interfaces just for this purpose to be quite useful. 

```js

interface User {
    id: string
    email: string
    location: Location
    avatar: string
    name: string
    geoBin: string //uber h3?
    friends: string[] //friend user id array
}

/**
 * Can even use jsdoc for stuff
 */
interface Location {
    longitude: number
    latitude: number
}

interface Listing {
    owner: string //userId
    created: number //ts
    updated: number //ts
    geoBin: Location
    system: string[] //array or string, array for more
    online: boolean
    description: string //markdown
}

```
node pug dynamic html tables
Tags: node, pug, dynamic, htmltable
Published: 2020-01-13 13:32:14

here is an example of a pug STATIC html table 

https://www.nodejsera.com/library/pug/pug-tables.html

here is an example of a node pug DYNAMIC html table 

TABLE.PUG 
```
table
  each r in tdata
    tr
      each c in r
        td=c
```

NODE.JS        
```
const pug = require('pug');
  var html = await pug.renderFile('./templates/table.pug', { tablerows: [[1, 2], [3, 4]] })
```

INDEX.HTML 
```
<table><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table>
```

see

https://pugjs.org/language/iteration.html

you can even embed MARKDOWN in PUG

https://dev.to/patarapolw/pug-with-markdown-is-magic-yet-underrated-4dla
Chrome Extension Developers: Monitor Comments
Tags: extensions, chrome
Published: 2020-01-13 13:16:45

If you are a Chrome Extension developer, you've probably felt the frustration of checking your extension every so often in the developer dashboard and find that someone has asked a question or left feedback you needed to address.  To that end, I wrote the [Chrome Extension Monitor](https://chrome.google.com/webstore/detail/chrome-extension-monitor/jddpjpcmobdoiebpfngoonaahikakkbc).  I wrote this extension to monitor my [Media Bias/Fact Check](https://chrome.google.com/webstore/detail/official-media-biasfact-c/ganicjnkcddicfioohdaegodjodcbkkh?hl=en) extension. 

Unfortunately, there is no way to gather the details from the web store from this extension itself (cors issues with Google API calls). Instead, I had to create a proxy service in [Firebase](https://firebase.google.com/) that proxies each request through a serverless function to gather the data. 

Check it out and let me know what you think?  I'm looking for feedback for improvement.
Functional Programming Part 1 – Intro to functional programming
Tags: javascript, codenewbie, beginners, webdev
Published: 2020-01-13 13:12:10

In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. (WIKI)

Do you understand anything of it ? If not then I think we are then same! I also don’t understanding anything when I first read this meaning. What is mutable data ? or what is the meaning of this? Why it even used ?Let’s start will what is a mutable data ?

Mutable data means you can change this data. Like – suppose we’ve a variable a=5 and in later we change the value and put 10 in a by a=10.

But In functional programming, we don’t use mutable data. Instead we use immutable data. We can’t change a data after we declare it. In JavaScript we use – const for declare immutable data, which you can’t change!

Now do you know why we use functional programming ? Let me tell you the reasons
- Improve modularity
- Less code code redundancy
- More easier to solve complex problems
- More maintainable
- More Efficiency & some more

If you are using JS and used features like map or reduce. Do you know one thing?

You’re already using the functional programming!

Do you like today’s topic ?

You can see the graphical version here
{% instagram B7BnAuHAQIb %}

Originally it published on [nerdjfpbblog](https://blog.nerdjfpb.com/functional-programming-part-1/). You can connect with me in [twitter](https://twitter.com/nerdjfpb) or [linkedin](https://www.linkedin.com/in/nerdjfpb/) !
Development with Walkie Talkies doesn't sound fun.
Tags: work, dev, communication
Published: 2020-01-13 13:08:59

---
title: Development with Walkie Talkies doesn't sound fun.
published: true
description: Push to talk on MS Teams sounds like a nightmare
tags: work, Dev, communication
---

This is the second article I've seen about Microsoft Teams supporting a walkie talkie like "push to talk" feature with there right Samsung phone. 

https://news.samsung.com/us/samsung-microsoft-verizon-partner-digitally-enable-frontline-workers/

I happen to be a big fan of Microsoft for the last few years. They're making a lot of smart decisions to win credibility with developers that wrote them off as enemies of open source long ago.

But I first saw this feature in an ad that says something like "reach your co-workers 24/7" and that just sounds awful.

Chat apps like Slack, Teams and Zoom have brought alot of value to distributed teams - and I'm glad we have them. But nothing comes without downsides, and I also think we need to worry any the disappearance of "deep work". 

I'm not for saying everyone should be undisturbed with their headphones on all the time, but I do think we need to intentionally limit and manage or connectivity (so... 'Yes' to being undisturbed with our headphones in *more* of the time than we are now). 

Turning my phone into a virtual walkie talkie feels like a big step in the wrong direction.

What do you think? Am I just being a grumpy old curmudgeon? Is bad news for productivity? Or is it just a cool new feature?
Understanding API and why it matters for you
Tags: api
Published: 2020-01-13 13:01:02

---
title: Understanding API and why it matters for you
published: true
description: 
tags: API
---
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/9wqz12xnb2dj3aa3qp0y.png)

API stands for Application Programming Interface. It is a concept in software technology that deals with multiple applications interacting with and obtaining data from one another. In simpler words, your internet experience runs on APIs. 
APIs help you compare the best prices for air tickets, allow you to embed a map into your store’s website (just like for [Peshawari Chappal](https://www.peshawarichappals.pk)) and process your online credit card payments. 

**Type of APIs**

There are multiple types of APIs, which includes:

Public APIs: companies like Shopify and Slack release these APIs for developers. These companies share a certain set of inputs that allow you to achieve the desired output. 

Private APIs: Used internally at a company. When a company has multiple software products, these private APIs allow the software to interact with each other. You can change the components of a private API to suit the requirements of your company.  

**How does an API relate to social?**

All major social media sites have APIs. While you are not allowed to use them to copy the company’s original service and sell it as your own software, you can build on them to improve the experience. 

For instance, Twitter’s API allows you to access certain features of a public profile. You can design a program using an API that would help you to search for someone’s username and it will pull up the profile page. Instead of you having to visit the Twitter office every time you have a request, the API makes it easier for you to run the program and pull up the relevant profile. 

**Are APIs important to you?**

As I said earlier, your internet experience runs on APIs. Instead of accessing five different apps or services, five separate times, you can use a single software to access all five at the same time. In other words, APIs streamline your process.
Doing more vs doing better programming and how to avoid burnout
Tags: todayilearned, career, programming, agile
Published: 2020-01-13 13:00:21

*TL;DR notes from articles I read today.*

### [Programming: Doing it more vs doing it better](http://bit.ly/2NkzT6t)

- The best way to get better at writing software is to write more software, not to seek perfection at every shot.
- Put more thought into your design systems - strive to write readable, maintainable code without bugs.
- Don’t assume that you will one day churn out beautiful code effortlessly. Instead, learn to review and test more thoroughly and refactor sooner than later. 
- Quit the struggle of trying to get faster at engineering. Taking your time to think and revising as you go helps you write better code. 
- However, realize it is impossible to do the last while meeting objectives; instead, apply diligence over the long-term. 

*[Full post here](http://bit.ly/2NkzT6t), 4 mins read*

---

### [Stretching, executing, coasting - and pacing yourself to avoid burnout](http://bit.ly/30f1Em4)

- Look at how professional athletes build their careers. They pace themselves to optimize performance and ensure the longevity of their careers. We, software developer can (and should) do the same too - use the model of stretching, executing and coasting just as they do. 
- Stretching is the most fun mode where you learn things quickly, apply them as you go, step up to new challenges, and move out of your comfort zone to accelerate learning. However, if you stretch too long and you will slow down or burn out. 
- Executing is the normal way of working where you use your existing skills and experience to get things done well, without continuously stretching. To get your manager’s support on this mode, list additional things you do and establish your intention to delegate or say no. 
- Coasting implies doing less or lower-quality work than you are capable of, say, as a short breather after a big project or because of personal circumstances.  

*[Full post here](http://bit.ly/30f1Em4), 5 mins read*

---

### [7 things you don’t know about agile architecture](http://bit.ly/384Nhnf)

- Design the project so that introducing changes is not expensive. 
- Don’t spend too much time designing. Start building, learn and progress. Build in feedback loops in every development cycle. 
- Don’t mistake fast initial development for sustainable agility. You want to arrive sooner at the right end product rather than simply going faster.
- Work in smaller teams, as bigger ones are less flexible and need more communication making them less agile. Know that more people does not guarantee earlier completion.
- Avoid using speculation on future requirements to add complexity to projects. However, past changes can be clues to future needs, so watch for change hotspots and high defect density.  

*[Full post here](http://bit.ly/384Nhnf), 6 mins read*

---

*[Get these notes directly in your inbox every weekday by signing up for my newsletter, in.snippets().](https://mailchi.mp/appsmith/insnippets?utm_source=devto&utm_medium=post08&utm_campaign=is)*