teleren/devto huggingface dataset:
Do away with weak, unowned self-access if you're not mutating self in itself.
Tags: ios, swift
Published: 2020-01-21 11:36:41

Do away with weak, unowned `self` access if you're not mutating self in itself. Capture interested properties of `self` in the `closure`.

Example:

```swift
// 1
let closure = { [weak self] in
  self?.navigationItem.rightBarButtonItems = [...]
}

or 

// 2
let anotherClosure = { [weak self] in
	let identifier = self?.identifier ?? "" // identifier is non-optional in SELF scope.
	let request = APIRequest(.../identifier)
  request.perform(...) { _ in
    
  }
}
```

In snippet 1 - the `self` is optionally chained. In snippet 2 - `identifier` is not optional in the normal `self` scope.

But just because the `self` is marked `weak` it's properties are also needed to chained optionally and results in many `optional checks`.

Another clean approach is just `capture the interested properties` of `self` in closures. 

The **snippet 1**  could be re-written as

```swift
let closure = { [navItem = navigationItem] in // could just capture as `[navigationItem] in` also
		navItem.rightBarButtonItems = nil // no self access and no ugly optional checks
}
```

most importantly accessing it through the local scoped `navItem` - you'll always get the `initial state` of the property you're capturing. [Attached a Swift `playground` demoing this powerful feature. Check out!](https://raw.githubusercontent.com/vnsam/SwiftTips/master/closure_scope_example.zip)

and the **snippet 2** could be written as

```swift
let anotherClosure = { [identifier] in
let request = APIRequest(.../identifier)
request.perform(...) { _ in ... }
}
```



**Note:** If you really need to `mutate self` then neccessay closure scoping (`weak, unowned`) is needed. This example shows clean way to act on properties of `self` . 

#### Another tip when calling functions of `self` from inside the closures is to keep a local copy of self before the closure.

```swift
func doSomethingWithSelf() {
  	let localSelf = self
  	
		let closure = { [localSelf] in
      	...
    }
}
```

This way the `localSelf` over the closure is destroyed when the function returns control.

#### You can also send `self` as an argument to the closure. This way no capturing/copying is needed. You still can act on `self`.

```swift
func perform<T: AnyObject>(_ reference: T, closure: @escaping (T) -> Void) {
    { [weak reference] in
        guard let strongReference = reference else { return }
        closure(strongReference)
    }()
}
```

and at the call site no `weak self` is needed since everything is handled __inside the function and the weak, strong casting is done in one place only.__ 

At the call site this looks like:

```swift
perform(self) { (reference) in
	reference.doSometing()
}
```

No more `weak self` dancing and un-neccessary `nil` checks. 🎉
Quick sort
Tags: algorithms, sorting, javascript, computerscience
Published: 2020-01-21 11:34:28

Quick sort is a comparison algorithm with great performance and time complexity considering its simplicity of implementation. I personally prefer the recursive implementation of quick sort which we will review in this post. Generally quick sort is like merge sort to some degree as both use a divide-and-conquer approach to sorting, essentially splitting the array in 2 and sorting each smaller side individually over and over until the arrays are fully sorted and then reconnected in the sorted order once again.

## Implementation

Below we can see an example implementation of quick sort using JavaScript.

```javascript
function quickSort(array) {
  if(array.length <= 1) return array;

  const pivot = array[0];
  const left = [];
  const right = [];

  for(const item of array.slice(1)) {
    if(item < pivot) {
      left.push(item);
    } else {
      right.push(item);
    }
  }

  return [...quickSort(left), pivot, ...quickSort(right)];
}
```

Quick sort is my go to algorithm most of the time if I have to implement something custom just because of how simple, efficient and surprisingly quick it is, pardon the pun. Note how the implementation is recursive and be aware of memory consumption on larger datasets.

In general, we have a circuit breaker condition to check if the input array has 1 or less items, if so, just return it. Otherwise if we have more than 1 item in the array, we take the first item as a `pivot` and for each item from the second item to the last, we check if the `item` is smaller than the `pivot` and if it is move it left, otherwise move it right. Finally we return a new array where we use recursion to sort the `left` and `right` arrays and placing the pivot in the middle.

## Use Case and Performance

Quick sort has a great [Big O time complexity](https://en.wikipedia.org/wiki/Big_O_notation) of `O(n log n)` on average which is also known as linearithmic time which is the fastest possible time complexity for a [comparison sort](https://en.wikipedia.org/wiki/Comparison_sort) algorithm. In the worst case the algorithm will run at `O(n²)` which is also known as quadratic time but this occurs seldomly for this algorithm.

Let's look at some example average runtimes from given input sizes:

| Input size | Time complexity (Big O)       |
|------------|-------------------------------|
| 10         | O(10 log 10) = O(10)          |
| 100        | O(100 log 100) = O(200)       |
| 1000       | O(1,000 log 1,000) = O(3,000) |

Compared to the [bubble sort](https://dev.to/jamesrweb/bubble-sort-3iid), [selection sort](https://dev.to/jamesrweb/selection-sort-1e57) and [insertion sort](https://dev.to/jamesrweb/insertion-sort-b3d) algorithms which we have covered so far in this series, these performance statistics are fantastic. Quick sort is great for datasets of most sizes too which makes it a great utility to have under your belt overall and as I mentioned above, generally, it is my go to algorithm when I *need* to implement something custom.
Pros and Cons of writing your own CMS
Tags: react, webdev, serverless
Published: 2020-01-21 11:00:26

While working on my own personal brand, grantwatson.app (which is still under development), one item came up for my consideration:

_How am I going to handle my blog portal?_


For this app, I wanted to use the fast and lightweight approach for development.
## The following is major techs used:
        * React
        * Firebase

Pretty straight forward. I have worked on a few smaller apps that I used Firebase to store small nodes of information and called them to the React UI, and if I wanted to use that same functionality in this current app, I went ahead and made the connections.

After a few iterations of my app, the issue of how to implement a blogging system was nagging at me. I should have considered using something like a headless CMS at the beginning, but I also did not want to scrap what I already created to start anew.

So, I began working on the CMS part. The struggle I am facing is simple, CMS engines like Strapi and Wordpress are pretty much ready out of the box. They also have most areas already covered and considered when it comes to API calls and delivery systems set in place.

The aspect of learning this on the go, and not having to worry about hosting two separate apps seem to be the only areas that is stopping me from using something like the two aforementioned CMS tools.
Did anyone integrate Smart2pay in Django and react native?
Tags: django, smart2pay, paymentmethod, reactnative
Published: 2020-01-21 10:56:02

I want to integrate Smart2pay with django and react native. I couldn't find any package or module for django/python. They just provide global API for that. I can do with API in the backend.
I need suggestion how I can do it and what will be the proper way to implement it with django ans react native. You are all open to give suggestions.
Thanks!
Oracle Apex Tutorials
Tags: apex, javascript, html, css
Published: 2020-01-21 10:37:40

Hello Guys,

I haven't  found something useful about Oracle Apex on Dev yet so if you are looking for Oracle Apex tutorials, then you can check the following resource:

[Oracle Apex Tutorials 5.0, 19.1 and 19.2](https://www.foxinfotech.in/2019/11/oracle-apex-tutorials-version-19-1-onwards.html)

I hope it will be helpful for you. :)
Insertion sort
Tags: algorithms, sorting, javascript, computerscience
Published: 2020-01-21 10:37:05

Using insertion sort, the elements are transferred one at a time to the right position. In other words, insertion sort creates the sorted array one item at a time using a ranking comparison of sorts.

## Implementation

Below we can see an example implementation of insertion sort using JavaScript.

```javascript
function insertionSort(input) {
  const output = [...input];

  for (let index = 1; index < output.length; index++) {
    let key = output[index];
    let inner = index - 1;

    while (inner >= 0 && output[inner] > key) {
        output[inner + 1] = output[inner];
        inner = inner - 1;
    }

    output[inner + 1] = key;
  }

  return output
}
```

We begin by cloning the input array and looping over each item beginning at index `1`. We get the item at index `1` and assign it to a `key` variable, then we create an `inner` variable which will, on the first iteration, be equal to `0`. The inner loop is then executed and checks if the `inner` item is larger than the `key`, if it is, we shift it to the right and if it isn't, we exit the loop using the `inner` as a circuit breaker. Next we assign the key to one position to the right, essentially as a pivot. In essence the outer loop looks left to right and the inner loop goes right to left from the current index minus 1, comparing items. Finally we return the `output` array.

## Use Case and Performance

Insertion sort has a [Big O time complexity](https://en.wikipedia.org/wiki/Big_O_notation) of `O(n²)` on average. This means that the time it takes to run the algorithm is the square of the size of the input array, otherwise known as [Quadratic Time](https://en.wikipedia.org/wiki/Quadratic_time).

Let's look at some example runtimes from given input sizes:

| Input size | Time complexity (Big O)  |
|------------|--------------------------|
| 10         | O(10²) = O(100)          |
| 100        | O(100²) = O(10,000)      |
| 1000       | O(1,000²) = O(1,000,000) |

In general, insertion sort has a similar set of use cases as [bubble sort](https://dev.to/jamesrweb/bubble-sort-3iid) and [selection sort](https://dev.to/jamesrweb/selection-sort-1e57) due to the time complexity. This means that it is best used on small to medium sized collections rather than large datasets.
windows 10 + xubuntu 18 + windows 10
Tags: desktop, productivity, webdev, discuss
Published: 2020-01-21 10:26:07

is running windows 10 natively and virtualbox hypervisor then an xubuntu 18 vm and a windows 10 vm making me more or less productive as a web developer ?

the use virtualisation of any kind (kvm,vmware,hyperv,docker,etc,etc) always takes my breath away
Why we should be a better version of ourselves
Tags: watercooler
Published: 2020-01-21 08:58:01

<a href="https://www.buymeacoffee.com/peacefullatom" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>

After years of thinking, experimentation, and observation, I came to some conclusions.

Here is one of them:

> Any human activity is a way to express yourself.

But on the other hand:

> Any human activity can be described as a process. And any process can be improved.

Now let's combine these two ideas:

> Any human activity is a process of expressing yourself that can be continuously improved.

So, the point is that we are changing the world by expressing ourselves, and that can be improved.

At this point, my interlocutor usually asks:

- Why should I improve myself?
- Why should I change the ways I'm expressing myself?
- Why do you think that I'm changing the world?

Or something similar.

And, again, here is my point of view:

1. For me, one of the ways of self-expression is to write code.
2. If I'm good at expressing myself, I also have these perks:
- I'm producing fast a high-quality code
- I have a bigger salary
- I can afford whatever I want

I hope that this will help to improve somebody's world.
Why laravel jobs are not being stopped even though I stop the supervisor?
Tags: help
Published: 2020-01-21 10:22:40

Hello guys I notice a weird behavior on laravel jobs. I try gracefully to stop them via `supervisorctl` but the jobs keep running!!!!

But, once I get the Laravel application down I manage to stop jobs to being dispatched. Do you have any idea why?

{% stackoverflow 59838853 %}
9 Ideas For Angular That Are Often Overlooked by Developers
Tags: angular, webdev, opensource, javascript
Published: 2020-01-21 10:22:18

Angular is undoubtedly the only JavaScript framework that evolved so much over the years and always remained at the helm of popularity. Though there are too many successful app projects built with Angular and there is a robust development community supporting this framework for years, many [Angular development services ](https://www.cmarix.com/angular-development-services-india.html?utm_source=Dev2.0) still complaint of several shortcomings and issues with Angular.

It is true that mitigating the complexity of the Angular has always been a big challenge for the developers. Though Angular is a fully equipped and powerful platform with everything a developer needs for building highly scalable and power-packed apps, often developers miss the key ways to optimise the Angular platform for optimum output.

Angular is exceptionally powerful and robust as a JavaScript framework and this also makes it a challenging development platform. This is why in spite of providing almost all tools and modern coding practices, [Angular developers](https://www.cmarix.com/hire-angular-developers.html?utm_source=Dev2.0) often require months of time to get used to the best practices that can yield them better results. Moreover, there are many development approaches that just didn’t care about these nooks and corners of Angular development but still managed to build powerful apps. If you don’t want to take side with such unverified approaches and risk your revenue potential, you need to come across the best development practices.

**Here we are going to explain some of the key measures and tips to make the best if Angular development language.**

**First Figure Out the App Domain and Know Your Limits**

Many Angular developers commit the mistake of coding the app first and fixing the issues later. This is a common mistake with many Angular developers. [Read more...](https://www.cmarix.com/9-ideas-for-angular-that-are-often-overlooked-by-developers/?utm_source=Dev2.0)
Top 3 Lessons for Students from the Life of Dr. Martin Luther King
Tags: onlinetutoring, martinlutherking, elearning, tutorial
Published: 2020-01-21 10:19:16

Though he may be dead, he lives in all of us today and continues to move us to our very core and spirit. Here are Top 3 Lessons for our students from the life of an influential civil rights leader and a truly charismatic personality.

Read more: https://www.tutoreye.com/blog/study-hacks/top-3-lessons-for-students-from-the-life-of-dr-martin-luther-king
Chingu Weekly Roundup Vol 102 - hello wonderful dev.to! 
Published: 2020-01-21 10:11:19

---
title: Chingu Weekly Roundup Vol 102 - hello wonderful dev.to! 
published: true
description: 
tags: 
---

![ChinguWeekly Cover Image](https://thepracticaldev.s3.amazonaws.com/i/locl1ugaqv3usaird6vt.png)
*Photo by Patrick Robert Doyle on Unsplash*

## News

🎉 Congratulations @honey 🐝 on the new developer contract! You've ABSOLUTELY earned this! 💯

🚀 Voyage-14 is finished & Voyage-15 is humming along.

🚀Voyage-16 starts on February 3rd. Feel free to sign-up at https://www.chingu.io/

💻500+ people are currently enrolled in a Chingu solo project adventure. Can't wait to see these projects!



## Shout-outs & Showcases
🔥Check out this sleek [product development landing page](https://sophiali.dev/15five-clone-ish/) that @ sophia built!
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/dpoghdop7zcawv6y7cf6.png)

📹Check out this interview with @nellie done by Mahtab Tadayon & Max Weber!

{% youtube 3H9wbsz4Y0g %}

🔥@jmwebdev working with 3D & perspective in CSS. [Check it out here](https://codepen.io/johnmeade-webdev/pen/bGNjoqq)!

🔥Check out this article by @RafaelDavish where provides tips based on his experience in a Chingu developer team: [3 Key Elements to Have a Successful Chingu Voyage](https://dev.to/rafaeldavish/3-key-elements-to-have-a-successful-chingu-voyage-2177)

🔥THROWBACK: Here's a project done by a Chingu team a few years ago:
[Acme - Sharpen Your Interview Skills](https://dev-questions.herokuapp.com/)
Stack:React, Node, Koa, MongoDB, webpack
Team: Heyjp, Paulina, Olga, Zsolti
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/pbq56lntpwuuv2u46f6h.png)

## Overheard in Chingu
*Random lines taken out of context from the Chingu community.*

>Hello, fellow coders!
I'm afraid I have to bake waffles today
My hobbies are coding, reading and physics! Although I find myself playing with my daughter and her PJ Masks toys more often then anything else.
I understand that development is hard and why people struggle at the beginning, that is my everyday story.
I've got a Gatsby site on my backlog
As a kid, my parents moved around often, so I have lived in Belgium, Uruguay and Canada.
I find algorithms interesting. The process of breaking problems into tiny bits.
I'm from Argentina but recently moved to Italy with my family.
Fellow German! Nice to meet you
i became a testing freak lately
I'm excited. I'm going to have a "standup". I'm not sure what much more I have to say aside from my name and what I'm up to

## Resources of the week
From @honey 🐝:
"Essentially a free gold mine of UI tips by the guys responsible for Refactoring UI. You'll want to read this if you want to elevate your designs. Essentially they're quick clear tips easy for anyone to use:
Steve Schoger design tips
@steveschoger has been dropping some great design tips lately so I started saving them. Really looking forward to his…twitter.com

## Quotes to go
*Taken from @rafaeldavish's above article*
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/hz31wdq7znyg3zs6h2cl.jpg)

See you next week!
Liquibase: Don't use ISO dates as changeset ids with yml
Tags: liquibase, java
Published: 2020-01-21 10:09:01

---
title: Liquibase: Don't use ISO dates as changeset ids with yml
published: true
description: Learning the hard way about liquibase changeset ids
tags: ["liquibase", "java"]
---
After upgrading a service from java 8 to java 11, our liquibase got crazy and tried to apply every change to the database from the beginning. But they were already applied and no changes were made to the database. 
We discovered that using ISO dates as identifiers of the changeset was a bad idea. The hard way.

## Liquibase Changesets

Changesets in liquibase are, as their name implies, a set of changes that must be applied at once in a database (or not at all).

In order that liquibase is able to distinguish when a changeset is already applied or not, it requires you to set a unique identifier.

By convention, we started to use the ISO date when the change was written (format yyyy-mm-dd). 

For example:
```
databaseChangeLog:
- changeSet:
    id: 2019-06-06
    author: sergiomoratilla
    comments: Adding new value to know which client was used to book.
    changes:
    - modifyDataType:
        tableName: reservation
        columnName: client
        newDataType: ENUM('WEB_DESKTOP', 'WEB_MOBILE', 'APP_ANDROID', 'APP_IOS', 'UNKNOWN') NOT NULL
```

Liquibase stores the applied changeset in a table called _DATABASECHANGELOG_ within your schema. So that, we were expecting a row

```
"2019-06-06"	sergiomoratilla	/liquibase/changelogs/this-example.yml ...
```

## It's a trap
Liquibase's YML parser decides to get the changeset id as a Date, and then use toString() to generate the id. That smells because you don't have control on that format... and this is exactly what happened.

Instead of storing "2019-06-06" we got "Wed Jun 06 00:00:00 GMT 2019". 

After upgrading to Java 11, the behaviour of toString() changed and now returns "Wed Jun 06 02:00:00 CEST 2019". It is exactly the same date so that this format is correct but it is a bit weak to trust your ids to default formatting.

## Solutions
Don't use ISO date as ids (if you are using yml format to configure that). Probably, most of you didn't already do that.

When we started to have several changes on the same date, we decided to change that format to yyyymmdd-n, where n is an incremental integer.

What if you are already using them? I suggest you to replace the ids in your changelogs files by the ids you already have in your database. And change your convention for new files!
SORRY but no your app cant POST tweets as me !
Tags: authentication, oauth, security, privacy
Published: 2020-01-21 09:50:09

SORRY no your app cant POST tweets as me ! GOODBYE !

have you been reading the smallprint on the 'connect this APP to this SMN' security permissions rights popups ?

many ask for permission to "post/tweet/write" as YOU !!!

[Nimbus](https://nimbusweb.me/) do it right by asking you to only give permission to read/write content "CREATED BY THIS APP"

```
View metadata for files in your Google Drive
View and manage Google Drive files and folders that you 
have opened or created with this app
```

OMG ubuntu do it WRONG ! it seems ive given them FULL access to my goog account

MAYBE ITS TIME CHECK YOU SECURITY SETTINGS TODAY

https://myaccount.google.com/security-checkup/
How to fix: "locale.Error: unsupported locale setting" on pip install
Tags: javascript, pip, python, fix
Published: 2020-01-21 09:49:22

If you see the following error while installing pip:
```java
Traceback (most recent call last):
     File "/usr/bin/pip", line 11, in <module>
       sys.exit(main())
     File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 215, in main
       locale.setlocale(locale.LC_ALL, '')
     File "/usr/lib/python2.7/locale.py", line 581, in setlocale
       return _setlocale(category, locale)
   locale.Error: unsupported locale setting
```
this means the environment variable `LC_ALL` is missing or invalid somehow.

### FIX :

run the following command:
```java
export LC_ALL=C
```
and retry installing again.

### What is LC_ALL?

`LC_ALL` is the environment variable that overrides the value of the `LANG` and the values of any other `LC_*` environment variables.

In a script, if you want to force a specific setting, as you don't know what settings the user has forced, your safest and generally only option is to force LC_ALL.

The `C` locale is for computers. In the `C` locale, characters are single bytes, the charset is ASCII, the sorting order is based on the byte values, the language is usually US English.
You generally run a command with `LC_ALL=C` to avoid the user's settings to interfere with your script. For example, if you want `[a-z]` to match the 26 ASCII characters from `a` to `z`, you have to set `LC_ALL=C`.

Hope this helps! :)