teleren/devto huggingface dataset:
Interview Prep #6: Rotate Image
Tags: career, beginners, cpp, computerscience
Published: 2020-01-15 16:36:31

## Problem

We are given an image in the form of an n-by-n matrix and we are supposed to rotate it by 90 degrees.

```
Example:

input:
1 2 3
4 5 6
7 8 9

output:
7 4 1
8 5 2
9 6 3
```

## Solution

At first rotating the whole matrix might sound like a complicated task. But it is not! It becomes really trivial if we break the problem down. We will break the matrix rotation down into layers rotation and then rotate layer-by-layer. Now, rotating layer-by-layer can be further broken down into rotating 4 numbers of the layer at a time.

![Matrix Rotation](https://thepracticaldev.s3.amazonaws.com/i/oin631jjg0pyokvhge85.jpg)

```c++
void rotate_4(long& a, long& b, long& c, long& d) {
  // helper function
  // [a, b, c, d] => [d, a, b, c]
  long temp = b;
  b = a;
  a = c;
  c = temp;
  temp = d;
  d = a;
  a = temp;
}

void rotate_matrix(vector<vector<long>>& m) {
  // nxn matrix
  int n = m.size();
  // l = number of layers
  int l = (n + 1) / 2;
  for (int i = 0; i < l; ++i) {
    for (int j = i; j < n - i - 1; ++j) {
      cout << j << endl;
      // If the following line does not make sense, just consider a small example
      rotate_4(m[i][j], m[j][n - i - 1], m[n - i - 1][n - j - 1], m[n - j - 1][i]);
    }
  }
}
```

> References: Cracking the Coding Interview - Gayle Laakmann McDowell
Feel free to comment out a solution in your favorite programming language!
Have a marvelous day 😄
Made something! It's called ImmersiveReaderView, a new control for UWP apps to make reading easier & more accessible to everyone
Tags: a11y, javascript, dotnet, opensource
Published: 2020-01-15 16:26:52

Immersive Reader is an awesome service from Microsoft that makes text easier to read. But since the service is only in preview, it's only available to websites. This control changes that. It allows modern Windows developers to integrate the Immersive Reader into their UWP applications with one line of XAML.

A PR is open to add this to the immersive reader SDK. Fingers crossed that it gets completed soon!  https://github.com/microsoft/immersive-reader-sdk/pull/164
How to detect crashes in Android Apps
Tags: android, crashes, apps, mobileapps
Published: 2020-01-15 16:16:37

Crashes dent the user experience of your mobile app which might trigger users to uninstall the app. Here @donpeter06 explains how developers can make use of Finotes to detect and reproduce the crashes in Android apps.

https://www.blog.finotes.com/post/how-to-detect-crashes-in-android-apps
Django emails in development
Tags: django, python, discuss
Published: 2020-01-15 16:14:44

I am working on a project that uses Django email backend and I receive an email in the terminal every time an email is sent. Right now, the whole email in the terminal is showing in one line irrespective of where I used different `<p>` tags. I want to know, is there's a way I can preview emails the same way they would be sent to the users?
JavaScript Big Combination Problem
Tags: javascript, mathematics, es6, todayilearned
Published: 2020-01-15 16:14:15

A recent [CodeSignal Challenge](https://app.codesignal.com/challenge/a8GNsYr8FQxZmMhJj?solutionId=MZQa7pP2nzgzzoSev) was to calculate 1000C500 (mod 1e9+7) and I got defeated =(

All my trials exceeded the time limit.. Here is the best JS solution by [psr](https://app.codesignal.com/challenge/a8GNsYr8FQxZmMhJj?solutionId=MZQa7pP2nzgzzoSev)
, could anyone explain what happens in this line??? I learnt ES6 but got no idea about this syntax...
```javascript
f[o = n + 1/k] = o in f
```

full solution for reference, please tell me to delete this if I violated any rule...
```javascript
f = countWays = (n, k) => f[o = n + 1/k] = o in f
    ? f[o]
    : k 
        ? n && (f(--n, k) + f(n, k - 1)) % (1e9 + 7)
        : 1
```
What I learned so far by writing 14 posts everyday
Tags: motivation, devjournal
Published: 2020-01-15 14:59:05

What I learned so far by writing 14 posts everyday

# Pros

- To collect topics about which I write a post everyday, I became more eager to keep studying (someone says that now method became more important than its purpose. But, What I can get as a result is the most important :smile:)
- To submit a post everyday, I came to be more careful with time management
- I'm feeling I became A little bit more familiar with English language

# Cons

- So hard! (just because I work everyday, too!)
- Each post is likely to be shorter and less informative
- ...It's 11:46 p.m. now...hurry up...

# What I should do for better performance

- Acquire fluency in English so that I can write faster
- Learn how to summarize and visualized what I learn everyday
- Learn how to write posts informative to others 

As for third task, the reason is that I'm "taking a room" in this community site. Even if they are so open-minded, here is not my personal space. In addition, I want to give back something to others as anonymous people on the web did for me when I was a newbie.)
Daily Challenge #163 - Significant Figures
Tags: challenge
Published: 2020-01-15 15:31:51

---
title: Daily Challenge #163 - Significant Figures
published: true
series: Daily Challenge
description: How many significant figures are in a given number?
tags: challenge
---
###Setup
Write a function that takes a number and returns the number of significant figures in a given number.

Significant Figures are the meaningful digits in a measured or computed value.
All non-zero digits are significant
4.357 has 4 significant figures
152.63 has 5 significant figures

Zeroes at the beginning of a number are not significant
0215 has 3 significant figures
0.6 has 1 significant figure

 Trailing zeroes in a number with a decimal point are significant
78.200 has 5 significant figures
20.0 has 3 significant figures

Trailing zeroes in a number without a decimal point are not significant
1200 has 2 significant figures
345000 has 3 significant figures

All zeroes between significant figures are significant
90.09 has 4 significant figures
5050 has 3 significant figures

Constraints:
The type of the given number will be string.
You must return the number of significant figures as type int.
No blank strings will be given.

###Tests
1
003
3000
404
050030210
0.1
0.0

Good luck and have fun!

***
_This [challenge](https://www.codewars.com/kata/5d9fe0ace0aad7001290acb7) comes from ljgecko1230 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!_
How to setup emberjs in ubuntu? | Ember 101
Tags: ember, ubuntu
Published: 2020-01-15 15:29:04

---
title: How to setup emberjs in ubuntu? | Ember 101
published: true
description: 2020 Editon of how to setup or install emberjs 3.15 in ubuntu 18.04
tags: emberjs, ubuntu
series: Ember 101
---

This post covers a simple apporach on how to setup emberjs in unbutu.

**Prerequisites**
This guide assumes that you are using Ubuntu 18.04. Note: Throughout this post, we are gonna install either LTS or latest version of the packages.

## Step 1: Install Nodejs
First refresh your local pacakge index

`sudo apt update`

Then copy-paste the following line to install LTS version of nodejs which is 12.14.1 at the time of writing.

`curl -sL https://deb.nodesource.com/setup_12.14.1 | sudo -E bash -
sudo apt install -y nodejs`

## Step 2: Install NPM
Now type the following line in your terminal to install the npm

`sudo apt install npm`

NPM helps you with installing and managing nodejs modules.
Now time to check both nodejs and npm are installed successfully or not by typing the following line in your terminal.

`node -v`
*output:*
`12.14.1`
`npm -v`
*output:*
`6.13.4`

## Step 3: Install Emberjs
we are almost there, now you can install emberjs by using this single line command.

`npm install -g ember-cli`

Please verify the ember installation by typing this command in your terminal

`ember --version`

*output:*
`
ember-cli: 3.15.1
node: 12.14.1
os: linux x64`

If you see the above output in your terminal, Congrats you are succesfully installed Emberjs in your machine.

## Step 4: Create an new ember app
You can use the following command to create a new ember app. 

`ember new ember-hello-app`

Once its done, now go into the application directory

`cd ember-hello-app`

Run

`ember serve`

After couple of seconds you will see the output like below 

`
Livereload server on http://localhost:7020
Serving on http://localhost:4200/`

Check the app by opening the url `http://localhost:4200/`


Hurray!! Now emberjs app is successfully running in your machine. Please leave a comment if you have any issues.
I hope you find this post useful. If you want to see more emberjs related posts give a heart.
Holidays 2019 - Episode 4.5
Tags: privacy, security, podcast, cybersecurity
Published: 2020-01-15 15:25:24

---
title: Holidays 2019 - Episode 4.5
published: true
description: In Episode 4 of the Your Secure Life Podcast, Garrett shares privacy and security news from October 2019.
tags: privacy, security, podcast, cybersecurity
canonical_url: https://yoursecure.life/episodes/holidays-2019.html
cover_image: https://yoursecure.life/images/episode-4-5-holidays-2019_YSL-Podcast.png
series: "Your Secure Life Podcast"
---
## Episode 4.5 of the Your Secure Life podcast.

In Episode 4.5 of the Your Secure Life Podcast, Garrett takes a break for the 2019 Holiday season.

## Watch the Episode

{% youtube oUZINa-AQ9c %}

## Listen to the Episode

[Website](https://yoursecure.life/episodes/holidays-2019.html) | [Apple/iTunes](https://yoursecure.life/apple) | [Spotify](https://yoursecure.life/spotify) | [Google](https://yoursecure.life/google)

## Read the Transcript

Hey there.

This is Garrett and you are listening to the Your Secure Life podcast.

This is a special episode. This episode is an in between episode.

So, [last episode](https://dev.to/garrett/privacy-and-security-news-from-october-2019-episode-4-3863) we had a news recap of what had happened in October and it is now November and I am going to take a break for all of December.

Sort of.

What I'm actually going to do is spend my time getting everything organized.

I have over a half a year, I've over six months worth of content planned for the podcast, and so I want to get a jump on that and get as much of it written at one time as possible, recorded and then scheduled.

And then in between on the weeks that are news-related, I'll just have to record those every two weeks.

And so that way I can get ahead and everything can get organized.

Same with [Approaching Utopia](https://a15a.co) and [my business, my OSINT stuff](https://garrettmickley.com) is going to be on pause for the month, and all of my client work is on pause for the month.

So basically December, I'm just taking the time to get everything organized for 2020 and then we're going to kick it off first week of January.

Whatever the first Friday of January is going to be the next episode of the Your Secure Life podcast, which is going to be about how to come up with a good password.

I know that in [episode one](https://dev.to/garrett/password-managers-are-safer-and-more-convenient-for-you-kgc) we talked about using password managers so that you don't need to remember any of your passwords, but you do need to remember one password and that's whatever the password is to get into your password manager.

So we're going to talk about that and we're going to get that done.

So have a good holiday season and I will see you in January, 2020 let's do it.

---

Sometimes stuff pulls the wool over our eyes and gets us. Sometimes our information gets out there other ways (like through breaches). We can minimize the damage with just a few actions. [Get the free 5 step guide to clean up your digital footprint.](https://garrett-mickley.ck.page/6bb0cf1d4c)
How to retrieve tokenID from acess_token (Personal Access Token) 
Tags: laravel, passport, oauth2, php
Published: 2020-01-15 15:25:19

---
title: How to retrieve tokenID from acess_token (Personal Access Token) 
published: true
description: This post describes how you can get the tokenId attached to a generated personal access token with Laravel/Passport.
tags: Laravel, Passport, OAuth2, PHP
---

## The gist
I am assuming you are already aware of how **Laravel/Passport** works.

Let's say you have generated a lot of personal access tokens that are associated to a specific user and you would like to delete a specific token without having to delete all the other tokens. 

I am sure you are thinking, I will just get the token associated with the user using the relationship already defined if you use the **HasAPiKeys** from **Laravel/Passport**. 

That is well and good if the user is also serving as a client in your api. But if it is just a Personal Access Token you can't retrieve the access token of created for that user (unless you get it from the header, but that won't really help solve your problem since you still have to know which token matches a particular ID) because of how **Laravel/Passport** is designed. 

![What to do? ](https://media.giphy.com/media/mBjulVQHWumozyk6O2/giphy.gif)

To bypass this scenario you can use the following code below.

Forgive me for using an image instead of embedded code 😅. Let me know below if this helps. 



![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/ow960v83s9zjui89k8yj.png)

Thanks to  {% user mstfakdgn %}


I was able to figure it out.
users per sq km for 3G, 4G & 5G mobile networks
Tags: 4g, 5g, mobile
Published: 2020-01-15 15:22:37

apparently 5G supports 1M / sq km

https://voippix.wordpress.com/2020/01/15/2g-3g-4g-and-5g-users-sq-km/

does anyone know how many 3G and 4G can support ?
Office Online 'The file is locked for shared use' error
Published: 2020-01-15 15:18:52

#Short breakdown

After editing files in Office Online (Office 365 and OnPrem) in a chromium based browser you might experience the following: 
 
 The file is locked for shared use by ...

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/87w5lhgv56z4mh22pcpr.png)

#Background

chromium based browsers all have the flag `allow-sync-xhr-in-page-dismissal`. This flag can be found under

* Edge chromium: `edge://flags`
* Chrome: `chrome://flags`

Recently it seems the default value for ths flag has been changed to ["disabled"](https://www.chromestatus.com/feature/4664843055398912). Furthermore this flag will be removed from both Chrome and [Edge](https://docs.microsoft.com/en-us/deployedge/microsoft-edge-policies#allowsyncxhrinpagedismissal). If this functionality is disabled, users will frequently experience issues where recently edited office documents are locked for editing by other users and metadata cannot be changed by the current user from the web interface. 

Office Online seems to rely on this functionality to unlock documents when you navigate away from the document editor interface. If not able to unlock a document, an exclusive lock will remain on the document until it expires after 30 minutes.

If you cannot reproduce the error currently, you can try to change the flag to "disabled" and you should be able to consistently reproduce the error. 


#How to reproduce 

Note: use a chromium based browser

1) in a document library, create a new document 

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/qxybkvd71vkzmuflsgy8.png)

2) edit the document if you like, return to the document library when done

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/r9u2ezjd7en8jbedlpxv.png)

3) now try to add a title to your document

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/xr2s8t6ytcxxdfkxi0mt.png)

4) the file is locked for editing. Note that other users will not be able to edit the document at all since the current user will have an exclusive lock
Svelte Router SPA now supports route localisation
Tags: svelte, javascript, spa
Published: 2020-01-15 15:15:29

---
title: Svelte Router SPA now supports route localisation
published: true
description: Svelte Router is a routing library for Svelte Single Page Applications. Now in version 5.2.0 it supports localisation.
tags: svelte, javascript, spa
cover_image: https://images.unsplash.com/photo-1491118217331-c147f566d809?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1000
---

Today I've released version 5.2.0 of [Svelte Router](https://github.com/jorgegorka/svelte-router). 

It's an easy to use routing library for Single Page Applications developed with Svelte JS.

The biggest feature in this version is support for **route localisation**.

### Features

* Define your routes in a single interface
* Layouts global, per page or nested.
* Nested routes.
* Named params.
* Localisation.
* Guards to protect urls. Public and private urls.
* Track pageviews in Google Analytics (optional).
* Use standard <a href="/about-us">About</a> elements to navigate between pages (or use <Navigate /> for bonus features).

This is an example of how to define routes:

```javascript
routes = [
        {
          name: '/',
          component: PublicIndex
        },
        { name: 'login', component: Login, lang: { es: 'iniciar-sesion' } },
        { name: 'signup', component: SignUp, lang: { es: 'registrarse' } },
        {
          name: 'admin',
          layout: AdminLayout,
          lang: { es: 'administrador' },
          nestedRoutes: [
            {
              name: 'report',
              component: ReportsIndex,
              lang: { es: 'informes' }
            },
            {
              name: 'employees',
              component: EmployeesIndex,
              lang: { es: 'empleados' },
              nestedRoutes: [
                {
                  name: 'show/:id',
                  component: ShowEmployeeLayout,
                  lang: { es: 'mostrar/:id', it: 'mostrare/:id' },
                  nestedRoutes: [
                    {
                      name: 'index',
                      component: ShowEmployee
                    },
                    {
                      name: 'calendar/:month',
                      component: CalendarEmployee,
                      lang: { es: 'calendario/:month', de: 'kalender/:month' }
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
```

What started as a small project has become now a full featured routing library for Svelte applications.

What's next in my TODO is refactoring some parts of the library to make the code easy to read and understand. It has a comprehensive suite of tests so it shouldn't be much of a problem.

If you use it in a project please send me your comments, suggestions and ideas here: https://github.com/jorgegorka/svelte-router/issues
Speed up macOS terminal
Published: 2020-01-15 15:06:21

MacOS does ASL (Apple System Log) log lookup each time you open a tab in the terminal (you can confirm that by running `sudo fs_usage | grep 'asl.*login'` in a tab and open another one, clear buffer in the first one and open a new tab again to see it indeed does look up each time). There's a way to prevent that though. I'm not sure how important those logs are, the only thing that changed for me was "Last login" disappearance.

### iTerm 2:

1. Open Preferences - Profiles.
2. Choose your profile (`Default` by default 😜).
3. In the "General" tab, change `Command` from `Login shell` to `/bin/bash` (or any other `*sh` you're using).

You can confirm that iTerm does not lookup ASL logs anymore with `sudo fs_usage | grep 'asl.*login'` in one tab. Opening tabs should not show output that contain lines looking like `private/var/log/asl/2020.01.12.U501.asl`, though it may contain something like this:

```text
17:58:04  stat64            /usr/lib/system/libsystem_asl.dylib                                              0.000008   login
17:58:04  stat64            /usr/lib/libsasl2.2.dylib                                                        0.000010   login
17:58:04  stat64            private/etc/asl/.noquota                                                         0.000024   login
```

That's fine because it does not look up for `private/var/log/asl`.

### Terminal.app:

A bit complicated this time.

1. Create a symlink of your shell (e.g. `/bin/bash`) to `/usr/local/bin/bash` (e.g. `ln -s /bin/bash /usr/local/bin/bash`). You have to do that because Terminal.app will execute `/usr/bin/login` which does the ASL lookup if your shell is a default one (default shells are defined in `/etc/shells`, hence why we link it to `/usr/local/bin`, because shells in this folder are not defined in the file). Non-default shell will make Terminal.app execute `/usr/bin/login -q`, and `-q` skips ASL log look ups completely.
2. Open Preferences - General.
3. Change `Shells open with` to `Command` and put `/usr/local/bin/bash` there.
4. Add `-bash` (or `-zsh` or `-fish`) to Profiles - Basic (Default) - Shell - Ask before closing. This will prevent popups like this when you're trying to close a tab:

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/ijct0lwupq38gw62ds9e.png)

You're done, confirm that you don't look up ASL logs using methods I described above.
Phoyisa
Tags: djmaphorisa, kabzadesmall, amapiano
Published: 2020-01-15 14:53:18


Check out this new Sound making rounds on the internet which is an unreleased track by <a href="https://fakazaamapiano.com/tag/Dj-Maphorisa/">Dj Maphorisa</a> titled Phoyisa (Hamba No Maphorisa). This new exclusive track features industries finest <a href="https://fakaza2019.org/tag/Kabza-de-Small/">Kabza de Small</a> , <a href="https://fakaza2019.org/tag/Cassper-Nyovest/">Cassper Nyovest</a> and introducing Qwestakufet. <a href="#"><a href="https://fakazaamapiano.com/">Kabza De Small</a> teases his fans with a snippet of the song on instagram a few days ago and we have here the full track banger <a href="https://fakaza2019.org/">Amapiano</a> track.
Be sure to cop this dope track which will definitely make it to the top of your playlist and share with friends, what a great way to end the year for DJ Maphorisa.
Backend data is really slow returned.
Tags: electron, javascript, node
Published: 2020-01-15 14:49:07

---
title: Backend data is really slow returned.
published: true
description: Electron node(c++ backend) file usage
tags: Electron, JavaScript, Node.js
---


Hi folks,
I am looking for solution to quick returns backend data. I am calling remote.reqiure('....node file path') in react component . This data returns take too much time. How can i handle this issue? Do you have any idea?
Thanks,
strings in python2 and python3
Tags: python
Published: 2020-01-15 14:46:37

---
title: strings in python2 and python3
published: true
description: bytes and strings
tags: python
---

I have written a lot of code in Python2. Not as much in Python3.

One thing I used Python for a lot is to quickly convert string values into base64 encoding. https://en.wikipedia.org/wiki/Base64

In Python2 that looks something like this (using the repl)
```python
Python 2.7.5 (default, Oct 30 2018, 23:45:53) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import base64
>>> base64.b64encode("test")
'dGVzdA=='
```

Sadly that quickly typed sequence does not work in Python3. Sigh.

The base64 module from Python2 used to take a string as an argument to the b64encode call. https://docs.python.org/2/library/base64.html

In Python3 that has changed and it now accepts a "bytes-like-object."
https://docs.python.org/3/glossary.html#term-bytes-like-object

And out of the box a string is not a bytes-like-object. So you have to convert it to use the string with b64encode.

Again using the Python repl now with Python3
```python
Python 3.7.5 (default, Nov  6 2019, 11:03:32) 
[Clang 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> s="test"
>>> import base64
>>> bytes(s,"utf-8")
b'test'
>>> base64.b64encode(bytes(s,"utf-8"))
b'dGVzdA=='

```

Sadly more things to type with your fingers. But not fast and loose with the data types.