teleren/devto huggingface dataset:
Function Overloading in C++
Tags: cpp, todayilearned, computerscience, oop
Published: 2020-11-22 05:11:45

---
title: Function Overloading in C++
published: true
description: Overloading on parameters in C++
tags: cpp, todayilearned, computerscience, oop 
cover_image: https://images.unsplash.com/photo-1534368786749-b63e05c90863?ixlib=rb-1.2.1&auto=format&fit=crop&w=3450&q=80
series: Programming 101 with C++
---

One of the cool things about C++ is that **function names don't always have to be unique.**

As long as the **compiler can tell the two functions apart**, you can have functions with the same name and this is called **overloading**.

In C++, there is no need to twist names to include parameter information.

### Taking different number of arguments is a great way to distinguish overloads

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

It is common to have one overload of the function call another overload of the function.

### Return type can never be used to distinguish overloads

> You can overload on parameters, you can't overload on return types.

You **don't have to use the return value** of a function if you don't want to.

> add(3,2); // works

This is why we can't overload on return type. If you have two functions that take the **same type of parameters but have different return types** and you put in a line of code where you call the function but don't use the return type for assignment, the **compiler would be unable to decide which function to use**.

### Taking the same number of arguments, but of different type can be risky

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

* here argument passed is 'int'
* to the compiler the call could be to *bool test(double)* or to *bool test(bool)*.
* there is no overload of test which takes int, compiler needs to convert int to a valid argument
* and since it knows both how to convert an int into a double as well as to convert an int into a bool (value 0 is considered as false, rest all are considered to be true), **the compiler doesn't know what to choose.**

### Possible solution:
* explicitly convert the int to a double or a bool.
* write another overload function of test that takes integer parameters.

Please leave out comments with anything you don't understand or would like for me to improve upon.

Thanks for reading!
Docker install via Snap
Published: 2020-11-22 05:03:25

Often I forget steps required to install docker via snap. Here are the steps for record-keeping purpose:

# Preparation
`$ sudo apt-get update`

# Install docker
Install command: `$ sudo snap install docker`
Test: `$ docker --version` would show something like: `Docker version 19.03.11, build dd360c7`

# Post-install task
From an archived [this](https://github.com/docker-archive/docker-snap) url, follow these steps: 

### Create and join the docker group:
* `$ sudo addgroup --system docker`
* `$ sudo adduser $USER docker`
* `$ newgrp docker`

### Restart
* `$ sudo snap disable docker`
* `$ sudo snap enable docker`

### Test
`docker --rm -p 80:80 seoul4/hostnameprint`
How to Solve a Coding Challenge
Tags: beginners, algorithms, javascript, computerscience
Published: 2020-11-22 04:58:05

Recently I've been doing LeetCode's weekly contests and I recommend anyone wanting to practice for interviews do them as well. The contests are great because they mimic the environment of a real interview. You are given a set amount of time (often 90 minutes) to solve several problems that increase in difficulty. The tests do a good job of imitating a high pressure environment rather than practicing problems in a lax setting.

After repeatedly taking these contests I feel that I've nailed down a method that works for me for solving problems and wanted to share. Anyway lets jump into how I solve each problem.

1. Take the time to read the problem 2-3 times until I'm confident I understand it. If I have a few confusions I continue to the next step anyway which is...
2. Examine the test cases and make sure I understand why the test inputs lead to the test outputs.
3. If you're given the expected time complexity you can narrow down approaches they want you to use. For example, if they want you to do an O(log n) search you can first try a binary search.
4. At this point I think about how I'm going to approach the problem while looking at the provided code as well as the provided constraints. 
5. Always try to think of edge cases that could cause problems before you code as well as while you are coding

Thanks for reading! I'd love to hear what works for you when you're solving a coding problem and how what you think I should do differently.
Type Safety in Functions
Tags: cpp, beginners, computerscience, oop
Published: 2020-11-22 04:52:36

---
title: Type Safety in Functions
published: true
description: Parameter type and return type rules
tags: cpp, beginner, computerscience, oop 
cover_image: https://images.unsplash.com/photo-1598948339458-99387ad5b26e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2550&q=80
series: Programming 101 with C++
---

> C++ is a type safe language.

When you call a function, the **parameters it takes have types**. You provide the arguments and sometimes they need to be converted to the type of the parameters used. This conversion can be 
* possibly risky in which case the **compiler will warn**
* passing a double (1.2) to a function which takes int parameter

The **return value** from the function might also be converted as part of assigning the value and this too could lead to compiler warnings if data is being thrown away.

Type safety rules apply everywhere in C++, from variables, to expressions as well as to functions.

Please leave out comments with anything you don't understand or would like for me to improve upon.

Thanks for reading!
Pure CSS Page Transition Effect
Tags: css, html, webdev
Published: 2020-11-22 04:52:04

The transition effect of page in CSS is the transition between sections or pages used for a given website. It creates a good browsing experience among the users. When applied correctly, they can provide a sense of liveliness and help significantly with navigation. Today, I am sharing the code of a snippet based on how to create a pure CSS page transition effect. Only plain HTML and CSS were used while doing this project. First, I made a simple navbar, and then I used the target attribute and the CSS transform property to create this simple page transition effect. <a href="https://www.codingflicks.com/2020/11/pure-css-page-transition-effect.html">Download the Source Code</a>
Drawing a Giraffe with CSS
Tags: css, html, codepen, illustration
Published: 2020-11-22 04:35:38

---
title: Drawing a Giraffe with CSS
published: true
description: The process for drawing a cartoon of a giraffe in HTML and CSS.
tags: css,html,codepen,illustration
---

Yesterday I did a quick cartoon of a giraffe using HTML and CSS:

{% codepen https://codepen.io/alvaromontoro/pen/vYKqyNM %}

The process went like this:

1. Drew the snout by doing an ellipse and adding some rotation
2. The head is a rotated oval
3. A pseudo-element of the snout made a circle for the nose, and added some shadows to duplicate it
4. For the mouth, we used another pseudo-element of the snout, we made it into an ellipse and use the bottom border for the line.
5. The eyes are a rounded pseudo-element of the head and its shadow
6. Then for the hair, another pseudo-element of the head shaped like an ellipse and with an inset box-shadow.
7. Both ears are a single element and its `::after` by making them squares with opposite rounded corners.
8. The horns were placed behind the head but in a position that makes them look like one is on top and the other one behind.
9. A really tall rectangle made the neck
10. A similar rectangle made the mane, with a small rotation and cropping small triangles to make it irregular.
11. Finally, for the dots in the neck, we use a neck pseudo-element and a bunch of box-shadows :)

Here there is a timelapse video of the process:

{% youtube TFaNwRpMUhg %}
Build creative Readme for your Github profile 
Tags: github, opensource, codewithgauri
Published: 2020-11-22 04:24:16

If you regularly use Github and watch others profile, so you might have noticed, that some people have some attractive stats, Tools logos in their profiles.

So through this post i am going to share some cool stuffs for your Github profile with you.

You can check here :https://blog.codewithgauri.tech/blog/how-to-build-creative-readme-for-your-github-profile/
Get nearest time slot in the past (in Magento2)
Tags: magento2
Published: 2020-11-22 03:54:16

Let's assume that you have a list of Time Slots generated within the 30 minutes intervals. You need to get the closest time slot in the past based on the current server time.

eg: 
Start Time: 14:00
End Time: 18:00
Interval: 30 (minutes)

Output:
```
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
```

Current time: 17:26 (you can get the current server time from the Magento DateTimeFactory)

So the output will be **17:00**.
Why? because we have 30minutes intervals in our time list. Therefore according to the current time _17:26_ the previous closest time slot is _17:00_

>How to get the current Date/Time from Magento core
```
use \Magento\Framework\Stdlib\DateTime\DateTimeFactory;

/**
 * @var DateTimeFactory
*/
protected $dateTimeFactory;

public function __construct(
    DateTimeFactory $dateTimeFactory
)
{
    $this->dateTimeFactory = $dateTimeFactory;
}

public function getClosestTimeSlot()
{
    $dateModel = $this->dateTimeFactory->create();
    $currTime = date('H:i', strtotime($dateModel->gmtDate()));
  
    $openingTime = '14:00';
    $closingTime = '18:00';
    $interval = 30; //in minutes

    $timeSlots = [];
    //set the intervals based on the $timeSlotLength
    $nextInterval = '+' . $interval . 'minutes';

    $strOpeningTime = strtotime($openingTime);
    $strClosingTime = strtotime($closingTime);
    
    while ($strOpeningTime <= $strClosingTime) {
       array_push($timeSlots, date('H:i', 
       $strOpeningTime));
       $strOpeningTime = strtotime($nextInterval, $strOpeningTime);
    }  

    //sets the array to be returned with the lowest time slot 
      from time slot array
    $timeArray = [
        'lower '=> min(current($timeSlots), $currTime)
    ];

    //store the closest lower time slot to the $timeArray
    foreach ($timeSlots as $ts) {
        if ($currTime > $ts)
            $timeArray['lower'] = $ts;
    }

    return $timeArray['lower']; //output will be 17:00
}

```
cheers!!
Technical Speaking Tips, and all the above
Tags: speaking, tips, interview
Published: 2020-11-22 03:52:49

I had an interview a week ago and it was terrible to say the least. I know one of the biggest issues for me during the interview was speaking, I wasn't able to speak confidently and when I tried I kept jumping all over the place and confused my interviewer. Obviously, the most given advice you'll hear in anything you want to get better at is practice… practice...practice. The thing is, I have practiced, I have practiced speaking to family members, I have spoken to inanimate objects, I have tried recording myself, I even took a class in college for speaking and sadly it's still hard for me. I will say though, from the beginning of my *practice to improve speaking* journey I have gotten ALOT better since then. I'm getting more comfortable with speaking and it's helped boost my confidence. I wanted to write this blog to share with you a few tips and tricks that have helped me and hopefully will benefit you in your future rendezvous. They are simple, but these tiny things will make the biggest difference. 

First and foremost, it is very important to take deep breaths. When you take deep breaths it calms your nerves(if any) and allows you to think clearly and take control of what you're going to do next. After you have accomplished this and feel like you have gained control of your body, speak slowly. To stop yourself from rambling on and on, address one question at a time. A trick I use when answering technical questions is using the STAR method, *"S (Situation) = Describe the background situation/circumstances in which the example took place. T (Task) = Describe the task at hand and/or particular problem or issue to be resolved [avoid judgmental statements and just stick to the facts]. A (Action) = Explain the specific action/s you took to complete the task/solve the problem. R (Result) = Explain the results of your action."* (Learn, flatiron online resource). Practice this and it will allow you to stay on track with answering the question and not ramble. 

Practicing good posture even if it's a phone interview or a zoom meeting where the interviewer can't see all of you. Keeping good posture allows you to stay focused and confident. Maintaining good posture will also actually remind you to keep a good breathing technique. I'd like to also add is, remember to dress the part. Studies show that dressing the part helps keep your mindset in that role. *"Once you’re in the right mindset, you’ll notice a difference in your voice and language with your body language included. With a nice outfit on, you’ll find yourself sitting up straighter as you confidently explain your strengths."* (Dresswelldowell, online doc, Chanele)

Lastly, I want to add that even though it's hard try your best to think positively, believe in yourself. For introverts especially, I feel you man. It's hard i know, but like i said at the beginning of this blog, anything hard and anything you want to get better at requires practice. I hope you all the best of luck!
Code Smell 31 - Accidental Methods on Business Objects
Tags: oop, codenewbie, programming, healthydebate
Published: 2020-11-22 03:03:30

*Adding persistence, serialization, displaying, importing, exporting code to an object bloats its protocol and brings coupling.*

# Problems

- Readability

- Coupling

- Maintainability

# Solutions

1. Keep your objects clean.

2. Decouple business objects.

3. Separate accidental concerns: Move Persistence, Formatting, Serialization to special objects.

4. Keep essential protocol using [bijection](https://maximilianocontieri.com/the-one-and-only-software-design-principle).

# Examples

- Persistence

- Identifiers

- Serialization

- Formatting

# Sample Code

## Wrong

{% gist https://gist.github.com/mcsee/11c5f7da7d9c54a05456102e128d010d %}

## Right

{% gist https://gist.github.com/mcsee/47847ea77875bb6f6e5e1cba2e914b05 %}

# Detection

It is difficult (but not impossible) to create linting rules based on naming and hinting for suspect names.

# Exceptions

- Some frameworks force us to inject dirty code in our objects. (For example identifiers).

We should try to use better languages/frameworks.

# Tags

- Declarative

# Conclusion

We are very used to see business objects polluted. This is normal. We need to reflect on the consequences and coupling from these designs.


# Credits

Photo by <a href="https://unsplash.com/@robertbye">Robert Bye</a> on <a href="https://unsplash.com/s/photos/mess">Unsplash</a></span>

* * *

> Simple things should be simple, complex things should be possible.

Alan Kay
Why?
Published: 2020-11-22 02:21:28

As I embark on the software engineering journey with Flatiron, I continuously ask myself 'why?'. The first response that comes to mind is "to help myself and others".

I don't have a traditional exposure to tech and computer programming. Each time I tried my hand at it, I failed miserably. Having teachers that didn't care and discouraged me didn't help either. It wasn't until I joined the Flatiron learning community that programming became feasible for me. 

I want to help myself and others. Technology has an increasingly important role in my life and within society, I want to have a better understanding of how technology works. I want to have more control over the technology in my life instead of it having control over me.

I want to help others by building programs that gives them access to quality education. I don't know how I am going to do that just yet, but I am getting one step closer with each programming concept I learn.
[crypto][nodejs] my encrypt/decrypt file cli tool
Tags: crypto, node, javascript
Published: 2020-11-22 00:54:34

By using crypto library for nodejs, i tried to encrypt/decrypt files using this library and it's work very fine, here is my little cli tool in my github :
https://nodejs.org/api/crypto.html

https://github.com/tkhadir/node-crypt-helper

By the way i'm wondering if it's good for an information system to backup database and store this in encrypted form and decrypt this database when we want to analyze it or get data from it.

we can imagine lot of securing tools using this library, share with me your ideas if you have.

Thank you.
Quick Tip: How to Enable Syntax Highlighting on Dev.to
Tags: beginners, writing, codenewbie
Published: 2020-11-22 00:49:56

I recently wrote this in response to another post here. 

Most of you probably already are taking advantage of this, but I thought it might help someone, so here we are. 

Consider specifying the language in your markdown code blocks because Dev.to has syntax highlighting! 

You can do this by adding the language after the first three backticks at the start of your code block.

This text (in the Dev.to editor)...

![Screen Shot 2020-11-21 at 6.48.45 PM](https://dev-to-uploads.s3.amazonaws.com/i/ligj8w2jr75jnlnjwvvh.jpg) 

...produces a code block with highlighting:

```js
const fn = () => {
  const x = "hello"
  return 3 + x
}
```

Without the `js` after the backticks, you get non-highlighted code:

```
const fn = () => {
  const x = "hello"
  return 3 + x
}
```

It works with a LOT of different languages, not just JavaScript!

The parser unfortunately makes it difficult to explain, but hopefully, the picture is clear enough!
Easier way to get a copy of array as argument
Tags: javascript
Published: 2020-11-22 00:49:32

Have you ever created a function where you receive an array as argument and created a copy of it because you didn’t want to touch the original one?

If so, you probably did something like this:

```javascript
function (items) {
  const newItems = [...items]
  // mutate newItems here
  return newItems
}
```

The sad thing about this code is that after you had a hard time thinking about a cool name for the argument, you have to ditch it and work with a not so cool variable name 🙁.

You could create another name for the argument and then use your cool name in the variable you will work with 🤔.

```javascript
function (itemsArg) {
  const items = [...itemsArg]
  // mutate items here
  return items
}
```

But there is a better way.

```javascript
function ([...items]) {
  // mutate items here
  return items
}
```

This way you have created a copy of the array in the function’s argument list 😃.
Learning Julia (8): About Dict Type
Tags: julia, dict, hashtable
Published: 2020-11-22 00:38:50

> Dict is the standard dictionary. Its implementation uses `hash` as the hashing function for the key, and `isequal` to determine equality. Define these two functions for custom types to override how they are stored in a hash table.

I plot in my neo4j db the sub-graph about **Dict** type to get a better understand of its type hierarchy:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/jjlrqoup3xiqw8lcx9gs.PNG)

**Dict** is quite similar to dictionary in Python. So I just show some of my test code below.

```julia
d1 = Dict("a"=> 11, "b" => 22, "c" => 33)
println("d1: $d1, type: ", typeof(d1))

ks = keys(d1)  # get all keys of dict

println("ks: $ks, type: ", typeof(ks))

arr_ks = collect(keys(d1))  # put all keys into a list

arr2_ks = [k for (k,v) in d1]   # array comprehension from a dict
println("arr_ks: $arr_ks, arr2_ks: $arr2_ks")

vs = values(d1)
println("vs: $vs, type: ", typeof(vs))


arr_vs = [v for (k,v) in d1]   # array comprehension from a dict

println("arr_vs: $arr_vs")

d1["d"] = 44    # add new item to a dict

for (key, val) in d1
    println("  key: $key, value: $val")
end

println(haskey(d1, "a"))    # to check if dict has a certain key
pop!(d1, "d")               # remove an item

println("d1: $d1, type: ", typeof(d1))
println(haskey(d1, "d"))
```
Execution output:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5v58quux9i326i72voz2.PNG)


```julia
d2 = Dict(:a=> 11, :b => 22, :c => 33)           #  symbol-keys
println("d2: $d2")
println(keys(d2))

for (key, val) in d2
    println("  key: $key, value: $val")
end
println(d2[:a])

try 
    d2["d"] = 44         # try to add a string-key to a dict with symbol-keys
    println("d2: $d2")
catch e
    print(e)
end

```
Execution output:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mv3q8ibqwya14pqxejqs.PNG)
What are the Single Page Applications or SPA ?
Published: 2020-11-22 00:24:43

This is my first post here, so... wish me luck. :)

The single page application or "SPA" for its acronym in English they are application build whit Js, the allow us to load our content only once, that is, the HTML, CSS and Js files are sent only once to the browser and that is where our entire application will live, So that the app it does not need to be recharged, therefore, if you need to navigate in the app, you navigate between sections and not in the pages.


###**Advantages**

* They are easy of debugger.
* They are east to create.


###**Disadvantages**

* They are not SEO frendly

* It is not recommended  for large applications (One Large application is one that has more than 1000 users and more than 50 sections on the app).
I started studying Swift
Tags: swift, beginners
Published: 2020-11-22 00:00:48

---
title: I started studying Swift
published: true
description:
tags: swift, beginner
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/x5bldppycikxhbcbjrcx.jpeg
---

I have never been attracted by the mobile development but yet, a few days ago, I decided to start studying Swift to develop apps for the Apple ecosystem.

The last time I develop a mobile app it's been at the University. My app was an academic transcript - I developed it for myself initially - where students could see they grades and some statistics like the average.

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

But at some point I didn't find the mobile development so interesting. I was interested in the web development: web apps, front end mainly.
At the moment I am an Application engineer at [The LEGO Group](https://www.lego.com/), where I work in a "full JavaScript" codebase. It's a paradise.

But, as I said, a few days ago I convinced myself to give another try with the mobile development starting with Swift. I was watching at the Apple event [One More Thing](https://www.youtube.com/watch?v=5AwdkGKmZ0I) where Apple announced the new M1 processor and the [Universal Apps](https://techcrunch.com/2020/11/10/ios-apps-can-run-on-apples-new-apple-silicon-macs/): iPhone and iPad apps can run on Macs now. I found it interesting so I quickly updated my Macbook Air installing [Big Sur](https://www.apple.com/uk/macos/big-sur/) and some updates for Xcode. Then I got started.

## My first steps

I am totally new to Swift and to the Apple apps. So I searched for a good entry level course. I found the 100 Days of Swift vert comprehensive - __thanks Paul__.

{% twitter 1273812094006280192 %}

Other resources I found interesting for an entry level:

- https://www.codecademy.com/learn/learn-swift
- https://www.raywenderlich.com/ios/
- https://developer.apple.com/documentation/
- https://www.youtube.com/user/CodeWithChris

Well then.. Good luck to me!

![Good luck!](https://media.giphy.com/media/kVaj8JXJcDsqs/giphy.gif)