teleren/devto huggingface dataset:
Javascript true false weirdness
Tags: javascript
Published: 2020-08-24 18:55:46

Recently I was trying to check true/false value for an object. I was pretty sure that an empty object is set to true in Javascript (as well as an empty array). 
However, when comparing an empty object to true, I always get false.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/t9sbsi1x1g5ukbhwh4up.png)
This was spotted quite late into my Javascript journey, so I would like to share it here
IntelliJ iDea Ultimate vs PyCharm..... which is better for what? 
Tags: python, pycharm, iltellij, help
Published: 2020-08-24 18:44:54

I’m getting started with Python/Django and I’ve started in on creating a project. 
I’ve been using Vue/React for a while. Python is reminding me a little bit of JavaScript (the syntax) and it’s really clicked so far. 
I’m learning more about modules,

Are they basically how JavaScript is with booleans, functions, lists, ect???


Between PyCharm and IntelliJ,
Which is better for what?
Sum of Left Leaves - Leetcode
Tags: python, binarytrees, leetcode
Published: 2020-08-24 18:30:33

Today's leetcode challenge was a binary tree question: sum all of the left leaves of a binary tree. 
```
Find the sum of all left leaves in a given binary tree.

Example:

    3
   / \
  9  20
    /  \
   15   7

There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.
```
My method was using dfs and recursion. I created a dfs function that had two parameters: a value for the node (root) and a boolean value for whether the node was left or not(left). Then I checked to see if the root had a left child or right child and if it was left. If true, I added the value of the node to a cache. I then used recursion to loop through all the left nodes and all the right nodes. In my main function, I set cache = [0] and called the dfs function with parameters of root, and False. 
```py
class Solution:
    def sumOfLeftLeaves(self, root: TreeNode) -> int:
        def dfs(root, left):
            if not root:
                return
            if left and not root.left and not root.right:
                cache[0] += root.val
            dfs(root.left, True)
            dfs(root.right, False)
        cache = [0]
        dfs(root, False)
        return cache[0]
```
Help choosing a laptop for work
Tags: discuss, help, computerscience
Published: 2020-08-24 18:19:17

I work remote for a small company and hence I need to buy my own machine. I am looking to buy a new laptop that allows me to work while I'm away from my working station.
After a bit of research I ended up with 2 possible solutions

1. Surface book 3 (15 inch, i7  1065G7  ,   GeForce® GTX 1660 Ti ) - 2500$

2. New Dell XPS 15 (15 inch, i17  10750H ,  GeForce® GTX 1650 Ti ) - 2100$

While the Surface has this nice feature to detach the screen (useless for work tho), the Dell has a newer processor)
My work consists mostly of running 2 virtual machines (currently using vagrant, but with new Windows I guess I can go WSL2), 2 or 3 instances of PHPStorm / IntelliJ, docker, 2 browsers etc

I have a hard time understanding which one would be the better choice for me. My impulse would tell me to pick the Surface, however I read one a couple of blog posts that the XPS is much more powerful and therefore much better for work.

Anyone here that has a better / deeper understanding that could help me make the better choice?
Two Sum - Leetcode
Tags: python, leetcode, hashtable, twopointer
Published: 2020-08-24 18:10:20

Today I'm going to go over three solutions to the popular leetcode question Two Sum. 

The question is this: given an array of numbers and a target number, return the indices of two numbers that add up to the target number. 

Solutions:
1. O(n^2) time, O(1) space
We can use two for loops to loop through the array and find the indices of the two numbers that add up to the target number. 
```py
class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        for i in range(len(nums)):
            for j in range(i+1, len(nums)):
                if nums[i] + nums[j] == target:
                    return [i, j]
```
2. O(n) time, O(n) space
We can use a hash table to store the numbers as keys and the indices as values. Then we check to see if the difference (target - number) is in the hash table. If it is, return both the index of the number and the index of the difference. 
```py
class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        values = {}
        for i, num in enumerate(nums):
            diff = target - num
            if diff in values:
                return [i, values[diff]]
            values[num] = i
        return []
```
3. O(nlogn) time, O(1) space
You can use the two pointer method. After sorting the array and creating an array of the numbers and their indices, create two pointers i and j where i = 0 and j = len(array)-1. If the sum is smaller than target, increment i, if larger, increment j. If equal, return the indices. 
```py
class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        i = 0
        j = len(nums) - 1
        sortedNums = sorted(zip(nums, range(len(nums))))
        while i < j:
            if sortedNums[i][0] + sortedNums[j][0] == target:
                return [sortedNums[i][1], sortedNums[j][1]]
            elif sortedNums[i][0] + sortedNums[j][0] < target:
                i += 1
            elif sortedNums[i][0] + sortedNums[j][0] > target:
                j -= 1

```
The .NET Docs Show: Open source .NET projects 👨🏻‍🦲
Tags: dotnet, opensource, dotnetdocsshow
Published: 2020-08-24 17:55:28

---
title: The .NET Docs Show: Open source .NET projects 👨🏻‍🦲
published: true
description:  The .NET Docs Show is joined by Isaac Levin for a conversation about .NET open source development, and a few interesting projects including PresenceLight as seen during Hanselman's Microsoft Build keynote.
tags: dotnet, oss, dotnetdocsshow
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/rali1z2c75vs399w31du.png
---

In this episode of [The .NET Docs Show](https://dotnetdocs.dev), Isaac Levin (<a href="https://twitter.com/isaacrlevin" target="_blank">@isaacrlevin</a>) discusses several of his open source .NET projects. As part of this week's #CheckUp, we share an MS Learn module for building [with Microsoft Graph](https://aka.ms/aspnet-graph) as it related to the PresenceLight project.

The #HallwayTrack was engaging and filled with demonstrations including [PresenceLight](https://github.com/isaacrlevin/PresenceLight), [GitHub stat tracker](https://github.com/isaacrlevin/GitHubStatTracker), and [Craigslist search](https://github.com/isaacrlevin/CraigslistSearch). We covered static websites, Azure Functions, Blazor WebAssembly (WASM), single file publishing, and much more!

## Quote

> There are definitely a lot of echo chambers in open source.

{% youtube 12XAjpuwByo %}

If you liked this video and would like to see some more of our .NET content, please subscribe to our [The .NET Docs Show YouTube Channel](https://www.youtube.com/channel/UCIy_nKrwrd-naf_MPWtXdLA) and [follow us on Twitter](https://twitter.com/dotnetdocsshow).

# #CheckUp

- [Build ASP.NET MVC web app with Microsoft Graph](https://aka.ms/aspnet-graph?WT.mc_id=devto-thedotnetdocs-dapine)

# Useful links

- [Isaac's URL list](https://www.theurlist.com/presencelight)
- [The .NET Docs Show](https://dotnetdocs.dev)
Why I Choose Nextjs For My Blog Project
Published: 2020-08-24 17:43:35

I had a goal this year to start a [blog](http://scholarswap.com/) where I would be writing about college student life or hire some educational experts who would write and make this information accessible to college students.

What inspired me to create my [college blog](https://scholarswap.com/posts/The-Benefits-and-Downsides-of-Living-on-or-Off-Campus/UG9zdERldGFpbE5vZGU6MTc=) using nextjs is because of Search Engine Optimization. Previously, I had created a blog using react only but when I pushed my blog into production and added some few posts, I realized they weren't being indexed properly even when I had react-helmet. 

This led me to look for other options and I settled with Nextjs. [Material UI](https://material-ui.com/) website inspired me because of how snappy it felt and when I used Wappalyzer I saw it was built using Nextjs.

I checked Material UIs github repo and I cloned their repo. I saw how they were optimizing their website with Nextjs. I took some few tips from that combined them with what I had learnt about Nextjs and that is how I ended up with [scholarswap](https://scholarswap.com)

The main advantage of Nextjs over react is on search engine optimization. Nextjs will nail that for you and all your quality posts such as [this one](https://scholarswap.com/posts/How-to-Create-a-Perfect-Study-Space/UG9zdERldGFpbE5vZGU6MjU=) will be easily discoverable in google.

Check out my blog and leave some comments whether I nailed it or what I can do to improve on it.
Getting Started with Morgan
Tags: 100daysofcode, javascript
Published: 2020-08-24 17:27:44

Morgan is a middleware function for logging information about the http request/response in a server application.
####Installation
```
$ npm install morgan
```
####Use
```javascript
const morgan = require('morgan');

app.use(morgan('dev'));
```
####Arguments.
Morgan takes two arguments: format and options.
FORMATS
You can defined your own format string or use the predefined formats. I like to keep things simple while learning a new concept hence i opted for the predefined formats. Here are a few predefined formats.
* `tiny` - logs out minimal information about the request.
status.
```javascript
app.use(morgan('tiny'));
```
* `dev` logs out concise output with color coded status.
```javascript
app.use(morgan('dev'));
```
* `combined` logs out Standard Apache combined log output (A lot of information that you probably don't care about).
```javascript
app.use(morgan('combined'));
```
For more formats refer to the [documentation](https://github.com/expressjs/morgan#api).

OPTIONS
Valid option (objects) accepted by morgan.
* `immediate` - information is logged on request instead of on response
* `skip` - determines if logging is skipped
* `stream` - Output stream for writing log lines

More on this in the [documentation](https://github.com/expressjs/morgan#api)

_Day 39_
How to use json-jbuilder in Rails
Tags: rails, beginners
Published: 2020-08-24 17:24:25

This post is just a mere attempt to log-in what I have learnt about json-jbuider and is not a tutorial but I know this will help those who have just began to learn Rails.

Okay then lets start!!

First of all Jbuilder is a template for rendering json responses. Rails comes preloaded with jbuilder gem which helps to create JSON structures. Lets see its use-case scenerio:

For example we are making a blog app in which we have a lot of articles and users who create those articles. So we have two models a User model and an Article model. A User model has many articles and an Article model belongs to User.In Article model we have a reference to the user model through user-id(basically author of the article). Now suppose we have a case where we need to show the list of articles with few details of each article including author information. In the articles controller we have the following action.

```
def index
  @articles = Article.all
end
```
Here <b>@articles</b> is an array containing all the articles and each article has the info corresponding to that particular row of the article table. We also need the author information but we have only the author id in the article table. This is the case where jbuider comes into flow.

By default rails looks for a template of the requested format. For rendering response to JSON query we will need a template. We make a template called index.json.jbuilder in the views/api/v1/aricles directory. This file contains the logic for populating the nested attributes of the article model(eg: user). Here we have namespaced the  directory because I think its better to have a clear seperation of our APIs.
In the index.json.jbuider add the following lines:

```
json.articles @articles do |article|
  json.partial "article", obj: article
end
```
In the above lines, we are defining a key in json called articles and we are taking the array <b>@articles</b> that we made in the articles controller and we are iterating over each article of the array and rendering a partial with an object "obj" containing the article details. Partial rendering is one of the plus points of using jbuilder.

As of now we dont have a partial so lets make one and name it "_article.json.jbuilder" in the same directory i.e views/api/v1/articles. Now lets add the following lines in the partial:

```
json.id obj.id
json.title obj.title
json.author do 
  json.user_id obj.user.id
  json.name obj.user.name
end
```

What is happening above is that we are structuring a json file where json.id , json.title, json.author are the keys . Here we are able to get user details other than the id.
There is one more way of doing this 

```
json.(obj, :id, :title) 
json.(obj.user, :id, :name) 

```

But I find the first one more useful.

I hope this article was useful and if there was anything I explained incorrectly or if there was a different apprach or if I missed anything do let me know. Thanks!!!
The Front End: S2-Ep #2
Tags: career, podcast, frontend
Published: 2020-08-24 17:21:38

All aboard the podcast train, The Front End is here with a shiny new episode.

Coming in hot for the second episode of season 2, Microsoft MVP [Pete Gallagher](https://www.petecodes.co.uk/), is a developer, public speaker, Pluralsight Author and owner of software consultancy PJG Creations.

Listen to the brand new episode here:

- Apple Podcasts > https://podcasts.apple.com/gb/podcast/the-front-end/id1499349107
- Pocket casts > https://pca.st/osul2zsa
- Spotify > https://open.spotify.com/show/4GuAxptrtY8Es5iHwp09dT
- Anchor > https://anchor.fm/the-front-end

## In this episode

Pete Gallagher has been a freelance consultant software engineer for many years and also organises Notts IoT, Dot Net Notts and sits on the board of LATi, a Loughborough organisation serving the technical community in the Midlands.

Pete talks about his journey into software from assembler language in coin sorting machines to freelancing, to organising successful tech meetups.

## Listening direct

Want to listen directly from here?

{% spotify spotify:episode:6VybW58nGHOeVP2QNmPUqg%}

## Want to be a guest or sponsor the show?

We're always happy to take requests for guests to talk about a range of different development topics from careers to origin stories, learning and professional growth, frameworks and more.

Similarly, we're looking for sponsors to fill promotional slots within the show. 

You can find out more here:

- [Being a guest](https://thefrontendpodcast.site/guests)
- [Sponsorship information](https://thefrontendpodcast.site/sponsorship)

Thanks for listening!
What do you use Redis for?
Tags: discuss, redis
Published: 2020-08-24 17:20:18

I was writing a blog post about Redis.

I want my friends and new devs to know:
* How they can reduce their database costs* by adding Redis to the tech stack.
* How they can use Redis to save development time.

*These costs include both Cash and Performance.

To give them ideas on how they can use Redis, I could only come up with the following-

* Cache - I use Redis as a Full Page Cache.
* Persistent Database - For a small project, it is the only database I use. Free 30mb Redis enterprise is helpful.
* Counter - Leader Boards, Simple analytics
* Session Storage - php `$_SESSION`, express session
* Message Broker: Real-Time stuff. Like sending not so important notification.
* Queue - Run a CRON job and process queue at regular interval.

### Can you guys share what you use it for?

It can be anything, including the ones I mentioned above.
Also, share your experience while using it 🙏🏽.

P.S.- Crazy Ideas are 🎁 for 🧠
Big O Basics
Published: 2020-08-20 16:13:08

As I prepare for technical interviews, I have learned how important it is to include data structures and algorithms into the daily schedule. Big O notation is always a subject that comes in the tech interview realm. I'll be going over some of the basic concepts as I have encountered as I begin wrapping my head around Big O concepts.

Big O is the language used to describe how long it takes for an algorithm to run. The efficiency of an algorithm can be measured by runtime and amount of space required for the algorithm to execute. 

Runtime is measured by how quickly the algorithm executes as the input gets larger or goes to infinity. 

There are some common runtimes you'll encounter as you learn about Big O. Here are some I've learned about. N or n is the size of the input. 

- O(1) means the algorithm will always execute in same amount of time or space no matter what the size (n) is. The runtime is constant. 

- O(N) or O(n) means the runtime grows in direct proportion to the size of the input n. The runtime will increase linearly as size n increases.

- O(N<sup>2</sup>) means the runtime grows in direct proportion to the square of the input size. This runtime can be seen in algorithms with nested loops.

- O(2<sup>N</sup>) means the runtime will double for every additional input N.

- O(log N) means the runtime will grow in proportion to the logarithm of the input size. 

Algorithms are typically described in their worst-case scenario. This means considering the longest amount of time or most space the algorithm would take to execute.

There is much more to cover regarding Big O, data structures, and algorithms. 

Resources:

[Interview Cake Big O](https://www.interviewcake.com/article/javascript/big-o-notation-time-and-space-complexity)

[Beginner's Guide to Big O](https://rob-bell.net/2009/06/a-beginners-guide-to-big-o-notation/#:~:text=Big%20O%20notation%20is%20used,on%20disk)

[Cracking the Coding Interview](http://www.crackingthecodinginterview.com/)
Observable Operators: Merge & Concat
Tags: javascript, beginners, webdev, codenewbie
Published: 2020-08-24 17:17:12


### Merge

Merge as the name suggests merges all given input Observables into output Observables without doing any operations on the input. The output Observable will `complete` when all the input Observables `complete`. If any input Observables have an error, that error is sent to the output Observable immediately.

```javascript
import Rx from 'rxjs';

const interval1 = Rx.Observable.interval(1000).map(i => `first: ${i}`);
const interval2 = Rx.Observable.interval(500).map(i => `second: ${i}`);

const combinedInterval = Rx.Observable.merge(interval1, interval2).take(10);

combinedInterval.subscribe(
    data => console.log(`${data}`)
);
```

We have combined two `interval` Observables into a `combinedInterval` Observable. The first interval will output every second and the second one will do it every half second. The output will be:

```console
second: 0
first: 0
second: 1
second: 2
first: 1
second: 3
second: 4
first: 2
second: 5
second: 6
```

`merge` also allows you to specify the concurrency of merged Observable. For example, if I combine 3 `interval` based Observables but I only want two of them to run at a time, I can pass a schedule(like) parameter.

```javascript
import Rx from 'rxjs';

const interval1 = Rx.Observable.interval(1000).map(i => `first: ${i}`).take(10);
const interval2 = Rx.Observable.interval(500).map(i => `second: ${i}`).take(5);
const interval3 = Rx.Observable.interval(500).map(i => `third: ${i}`).take(10);

const combinedInterval = Rx.Observable.merge(interval1, interval2, interval3, 2); // 2 at a time

combinedInterval.subscribe(
    data => console.log(`${data}`)
);
```

First and second Observable run concurrently until the five values from the second Observable has been emitted. Then the third Observable joins the first one in emitting values. The output will look like:

```console
second: 0
first: 0
second: 1
second: 2
first: 1
second: 3
second: 4
first: 2
third: 0
third: 1
first: 3
third: 2
third: 3
first: 4
third: 4
third: 5
first: 5
third: 6
third: 7
first: 6
third: 8
third: 9
first: 7
first: 8
first: 9
```

### Concat

Concat is slightly different from the merge. Both combine the Observables, but `concat` waits for one Observable to complete before it starts the next one. All the Observables concatenated run in sequence. Whereas in case of a merge, all of them run but provide a single stream of output.

```javascript
import Rx from 'rxjs';

const interval1 = Rx.Observable.interval(1000).map(i => `first: ${i}`).take(5);
const interval2 = Rx.Observable.interval(500).map(i => `second: ${i}`).take(5);

const combinedInterval = Rx.Observable.concat(interval1, interval2);

combinedInterval.subscribe(
    data => console.log(`${data}`)
);
```

So `concat` will combine the output but maintain the output order. The console log will be:

```console
first: 0
first: 1
first: 2
first: 3
first: 4
second: 0
second: 1
second: 2
second: 3
second: 4
```
How to achieve smooth box-shadow in CSS
Tags: html, css, beginners, webdev
Published: 2020-08-24 17:05:45

In this post we are going to look at how we can achieve Smooth and Dreamy box-shadow.

box-shadow `syntax` (x-offset y-offset blur color)

By Layering multiple shadows, we can create Smooth `box-shadow`.

```css
/* Default box-shadow */
  box-shadow:0px 6px 6px rgba(0, 0, 0, 0.11);

/* Multiple layering for smoother box-shadow */
  box-shadow:0px 2px 2px rgba(0, 0, 0, 0.15),
    0px 3px 3px rgba(0, 0, 0, 0.15),
    0px 6px 6px rgba(0, 0, 0, 0.15),
    0px 8px 8px rgba(0, 0, 0, 0.15);
}
```
In this example, We have used 4 shadows with 15% alpha. 

`Sharp` Shadows with Decreasing alpha. 
`Diffuse` Shadows with Increasing alpha. 

The `blur` radius if set to 0 the shadow will be sharp, the higher the number, the more blurred it will be. 


#### Tool: <https://brumm.af/shadows>

Happy Coding!😀
Hidden Feature Rails
Tags: rails
Published: 2020-08-24 17:03:46

Often, we discover an edge case, or know we want to improve some aspect of our code, but don’t have the time or energy to get to it right now. Hopefully we document these notes somewhere, but even if we do document them, there are some problems.
If we use an external task manager, these tasks could get out of sync with the actual codebase. And unless you leave a file and line number, you might not remember where exactly the issue is.
You might leave comments in your code, but those will inevitably be forgotten and ignored.

Rails comes with a hidden feature to help with managing your list of to-dos. As you’re writing code, you can leave one of these three notes:

____________________________________________________
"#TODO: handle edge case where x happens"
"#FIXME: this breaks under x condition"
"#OPTIMIZE: this takes 5 database queries"
____________________________________________________

And then, running rake notes (or rn if you’re making use of the aliases in the Aliases for Common Rails Commands section) will enumerate every note you’ve left in your code:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/h1ldxwk0wtxzihekjhon.png)

While you still have to take the initiative to go back and refactor your code, this will at least give a quick overview of what’s left to be done in your application and where to find it.

Don’t like the default TODO, FIXME and OPTIMIZE? You can also enumerate custom annotations:

rake notes:custom ANNOTATION=NOTE