teleren/devto huggingface dataset:
how to pass command line arguments with Python
Tags: python
Published: 2019-08-10 00:49:57

---
title: how to pass command line arguments with Python
published: true
description: 
tags: python
---

Once you have written a few programs with Python you will want to pass arguments into those programs when your run the program (at invocation).

That is done with Python using the sys module. You will need to import that module into your program before you try to access arguments passed on the command line.

There are a LOT of other things in the sys module of use. See here for all the other stuff: https://docs.python.org/3/library/sys.html

To print the arguments to your program out you will need to access a variable called sys.argv. Argv is short for argument values.

```python
import sys
print(sys.argv)
```

The main thing to notice is that the type of sys.argv is a list of strings. sys.argv[0] is the name of your Python script.

If you ran the Python program listed above like this:

```
python myprogram.py 1 a b
```

Then sys.argv[0] (or the first element in the list) will be the name of your Python script.

```
['myprogram.py', '1', 'a', 'b']
```

Notice that sys.argv is a list of strings. If your program passes a number (as I did in the example) the number will come to your Python program as a string.
Why wake up at 4 am may not work for you? 
Tags: productivity, career, feeling
Published: 2019-08-10 00:05:24

Why do you think getting up early might be good for you? Why do some executives wake up at 4 am?  
Some people cite the benefits below waking up before everyone: 

* Minimal distractions before sunrise 
* Nobody's sending you messages 
* There's less to see on social media 

But be smart, for most people waking up at 4 am will not work because the big question is not what time you get up, or how many hours you sleep but it is about what you will do while you are awake. I am sure that if you analyze how you are spending your time for a month you will find that in some moments you are wasting a lot of your time.

So if you believe that things are not happening don't think you need to wake up early but think about how to optimize your time. Set goals for your day and try to avoid everything that doesn't contribute to that goal. 

If you dream about something, and say you want to achieve something, your actions need to reflect that. If you want to be above average you need to do what the average does not do. So think about it. **Your future will simply reflect what you do today**.
Working On The Wrong Problem
Tags: meta
Published: 2019-08-14 18:46:29

---
title: Working On The Wrong Problem
published: true
tags: meta
canonical_url: https://stephencharlesweiss.com//2019-08-10/working-wrong-problems/
---

Working with code is an extraordinarily satisfying experience. Not in the minute-to-minute. At that scale, it can be infuriating. The code won’t compile. It trips on an unexpected bug. So on and so forth. However, when things _do_ work, I’m rewarded with a flood of endorphins. This is a big factor in why I love what I do. It’s like I get to sit at a slot machine all day and get constant hits of endorphins without gambling or risking my financial future.

The endorphins are a response to solving problems and solving problems _feels_ good. Solving problems are not, however, always the best outcome. Not because it’s better to have unsolved problems, but because sometimes they are the wrong problem to be working on. In those cases, I’ll still get the reward, but I didn’t accomplish anything — or at least I didn’t get closer to the ultimate goal of software that delivers value.

In the course of a long day, it’s likely that the wrong problems will rear their head, call out and demand to be solved. Whether working on a personal project, and certainly in a professional setting, it’s important to resist their call, ignore them as much as possible, and when that fails, having a practice in place to step back and evaluate the approach with some regularity.

These strategies can be a simple as writing down a plan in advance and referring back to it, using a Pomodoro timer to limit the amount of time you’ll allow yourself to burn on a problem, and, my favorite, talking to friends and colleagues about the approach.

Solving problems feels good. Solving the _right_ problems feels _great_.
Vanilla JS equivalent for counting number of child elements using className
Tags: javascript, jquery, webdev, showdev
Published: 2019-08-18 08:59:30

---
title: Vanilla JS equivalent for counting number of child elements using className
published: true
tags: ['javascript', 'jquery', 'webdev', 'showdev']
canonical_url: https://learnwithparam.com/blog/how-to-count-html-elements-using-classname-in-javascript/
description: How to count the number of child elements using classnames in javascript. It is very easy with jQuery, but do you know how to do it in javascript, lets learn it today.
---

Sometimes, we learn lot of bigger things but miss on small learnings. I want to create small posts on vanilla JS to do things without libraries or frameworks on simple pages.

It is very easy to count number of elements using jquery. First we will see it in jQuery and then on vanilla JS.

```html
<ul>
  <li class="li-node">Children 1</li>
  <li class="li-node">Children 2</li>
  <li class="li-node">Children 3</li>
  <li class="li-node">Children 4</li>
  <li class="li-node">Children 5</li>
</ul>
```

### Count using jQuery

```js
$('.li-node').length;
```

### Count using Vanilla JS

```js
document.querySelectorAll('.li-node').length;
```

`document.querySelectorAll` select all the elements with class name and returns an array of html element, then we can use the array `length` property to find the count.

{% codepen https://codepen.io/Param-Harrison/pen/ZgqpWd %}

Hope you learned a simple trick in vanilla JS 😎
Plain emails are a win-win
Published: 2019-08-14 18:17:18

---
title: Plain emails are a win-win
published: true
tags: 
canonical_url: 
---

If you’ve ever had to develop transactional HTML emails with slick designs, you’llknow that it’s a complete mess. The incompatibilities between email clients are way worsethan what you see with different browsers. Testing emails is extremely difficult, andthere’s a seemingly endless number of problems with various clients.

Luckily there’s a really simple solution to this problem: just send plaintransactional emails instead with minimal/no design. Email clients were never designedfor complex layouts and graphics. Instead of abusing the format for something its notintended for, let’s respect it and use it to our advantage instead.

Before we go on, of course there are cases where it makes sense to design complex HTML emails forbetter readability. For example, I’m planning to add a regular email reportto [Plausible](https://plausible.io) in the future. Such a report needs to fit a lot ofdata in a scannable format, so I will probably lean towards a designed email template.

However, most transactional emails don’t require design. Here’s the emailyou receive when you reset your password on Plausible:

![Plausible password reset](https://plausible.io/blog/assets/images/plausible_password_reset.png)

No fuss, straight to the point without any distracting elements. It’s hard to see howadding colours, logos and buttons to the email would improve it.

### More than just time savings

Avoiding the complexity of HTML templates can save a lot of time in design and development.An even greater win is that plain emails also have[better deliverability and response rates](https://blog.hubspot.com/marketing/plain-text-vs-html-emails-data).

HMTL elements and images have a negative effect on deliverability because they tend to trigger spamfilters. Over-designed emails can definitely feel spammy to the reader as well, not just the AI.I’m guessing it’s due to the ridiculous amount of unsolicited marketing emailsthat we all receive on a daily basis. They are almost exclusively complex HTML templates withloads of images.

Plain emails get more responses because they feel much more personal than HTML emails. Peopleassociate designed emails with marketing and one-way mass communication. On the other hand, plainemails look like the emails you get from a coworker or a friend. It feels more natural to hit‘reply’ on them.

This is why plain emails are a win-win: not only do they simplify the development process but theyalso reach more people. My takeaway is that we should only get into complex HTML templates if they are completelynecessary to enhance the user experience. We should accept that using them sacrifices deliverability,open rates, and development time. The upside of using email designs must be huge to outweightoutweigh the negative consequences of using them.
How Does The Internet Work? Part 1: Browsing a Website
Tags: webdev, beginners
Published: 2019-08-09 23:49:08

Who doesn't use the internet at least once during the day? Almost everyone, right? You start by opening up your browser (Firefox, chrome, safari...etc.), write down your favourite website's __URL__ (DEV, Google...etc.)  in the browser's address bar, you hit go and BOOM the website shows up, but have you ever considered how does this happen? what happens behind the scenes so once you gave the browser the website address, it shows up?

Understanding how the Internet works is very important. Lots of people usually skims through the surface of the concepts behind the working mechanism of the internet without fully understanding how everything works together. Without these foundations, it becomes very difficult to think about performance, optimizing sites and so on. Therefore, I decided to share with you what I know about that, and I decided to post it as a series so that the post won't take you too much time reading it.

###        Part 1:                 Browsing a Website

#### (A) Finding out The Domain's IP Address
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/lh66syyh8zu9d9fathnm.png)
When you enter a website URL (Google.com ...E.g.) in your browser URL bar and hit the go button, the browser first needs to know the __IP address__ of this domain you want to visit in order to navigate to it. Therefore, the browser checks its cache which keeps __DNS__ records for (2-30 minutes). If it is not there, the browser sends a request to your internet router asking it _"Who is this Google.com fellow?"_ Your router does the same by checking its own cache for __DNS__ records. If it is not there either, it sends the same request to your __ISP__ asking the same question _"Do you know this google.com?"_ Your __ISP__  sends the same request one more time to its __DNS__ cache. The __DNS__ replies back to the ISP: _"I don't know who google.com is but I have its address, here it is 127.217.7.23"_. The __ISP__ returns the __IP Address__ back to the router which in turn sends it back to your browser. 


#### (B) Navigating to the Website
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/htfpa6huhiyb5vv4kurl.png)
Once the browser receives the __IP Address__, it sends a __HTTP request__ to that address asking for establishing a connection between the browser and the website's web servers. The Web servers handle the request, and reply back to the browser by sending the website's __HTML, CSS and JavaScript__ which the browser renders so that you can view the website's page as it should be.

Cover Image Icon License: [icons8](https://icons8.com/) Free License.
JS 2019 features I am excited about
Tags: javascript, frontend, webdev, es2019
Published: 2019-08-09 23:23:59

---
title: JS 2019 features I am excited about
published: true
description: latest JS features published with ES2019 and see how they solve problems and I am most excited about
tags: JS, frontend, webdev, es2019
---

[TC39](https://github.com/tc39/proposals) over the past few years have been giving yearly updates to the JS. This works much better than throwing a ton of updates very years. This gives developers an opportunity to learn in a better and even from the browser point of view making the features available. 

From the 2019 feature set, below are a few that I am most excited about.

### 1. `trimStart()` and `trimEnd()`

Added on the `String` prototype

This allows trimming of whitespace at the start and end of a string. We already have the `trim()` function but this does it at both ends. There can be a use case where you might keep the whitespace at either end.

```javascript
const paddedStr = ' How new trim functions work '
paddedStr.trimStart() // prints 'How new trim functions work '
paddedStr.trimEnd() // prints ' How new trim functions work'
paddedStr.trim() // prints 'How new trim functions work'

```

### 2. `flat()`

Added on the `Array` prototype

This helps with flattening of multi-dimensional arrays. It takes an optional parameter that tells the function how many levels deep we want to flatten. The default value is 1.

```javascript
const oneLevelNesting = ['bread', ['peanut butter', 'jelly'], 'bread'];
oneLevelNesting.flat() // ['bread', 'peanut butter', 'jelly', 'bread']

const twoLevelNesting = ['bread', [['peanuts', 'oil'], ['strawberries', 'sugar']], 'bread'];
twoLevelNesting.flat() //  ['bread', ['peanuts', 'oil'], ['strawberries', 'sugar'], 'bread']
twoLevelNesting.flat(2) // ['bread', 'peanuts', 'oil', 'strawberries', 'sugar', 'bread']

```

### 3. Optional `catch` binding
Optional catch binding allows you to write a try/catch without having to use the error parameter with `catch`.


```javascript
//before
try {
   doSomething()
} catch(error) {
   console.log("Not using the error parameter here but have to include it")
}
// after
try {
   doSomethingElse()
} catch {
   console.log("No param? No Problem!")
}
```

There are other features other than these like [`flapMap()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap), [` Object.fromEntries`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries), another one is adding a description to `Symbol` property. Personally, I have not found the need for these in my experience.

*For a deeper understanding of all these features I recommend watching [`javascript-es2019-in-practice`](https://egghead.io/courses/javascript-es2019-in-practice) on egghead.io.*

Would love to hear thoughts of others on what features are they most excited about.
The Psychology of a Programmer
Tags: psychology, devlive, reality
Published: 2019-08-09 22:30:58

Program, what an interesting concept more than a word. It has been used so endlessly in the life of you and I so many times, that is has become uncountable. If we begin to deconstruct it, therefore to understand its core, we can say that it is a specific set of operations of tasks, commanded or ordered for a computer to perform. Tonight, this definition haunts me, as I read it again and again, you ask why, because unconsciously it has become a purpose of my life which I never even knew. 

Now I as a programmer, has repeated this for more than 10 years and that which you repeat whether knowing or unknowingly becomes not just a part of you but it starts as a habit and penetrates to every instance of your life, wherever is extended. To my understanding of today, I have viewed life as a set of operations or tasks, which I command for it to perform. Do you understand where it leads us as a programmer in life. I as a programmer have been labelled the impractical, the unknowing, the stubborn, aggressive and much more. Life cannot be viewed as a set of instructions, operations or tasks and certainly it has mostly not been in command to my wishes. It has always been a multiple episode of natural yet very spontaneous or radical change. 

I have been in resistance to it because when programs don't operate as commanded, they throw errors and with experience you can tell too, they are very ugly, the errors. Now think about for a moment, when life doesn't operate as commanded and starts spewing out all sorts of errors, they are ugly. This mathematical conclusion will suggest that resistance is futile and should have been avoided at all times, for I should have let reality be real. Towards the stream of life, one should not be life rocks, sitting still, taking the pressure of the flow of the water, gushing, crushing down on it but like water itself should one become, so we flow naturally in whatever way it is.
Finding your tribe - RESOURCES / LINKS (DDD Melb 19)
Published: 2019-08-09 21:54:49

Thanks to everyone who joined my session at DDD Melbourne 2019.
  
My talk "Finding your tribe - It all begins with community" mentioned a bunch of great dev community groups who are doing awesome things.  Here is a list of all the communities and people that I referenced:

These are the groups I mentioned that are really popular:
[Melbourne Python MeetUp] (https://www.meetup.com/en-AU/Melbourne-Python-Meetup-Group/)
[Data Science Melbourne] (https://www.meetup.com/en-AU/Data-Science-Melbourne/)
[Google Cloud Melbourne] (https://www.meetup.com/en-AU/gdg-cloud-melbourne/)
[Melbourne Startup Society] (https://www.meetup.com/en-AU/Melbourne-Startup-Society/)
[The Entrepreneur Club Melbourne] (https://www.meetup.com/en-AU/The-Entrepreneur-Club-Melbourne/)
[Melbourne Silicon Beach]
(https://www.meetup.com/en-AU/Melbourne-Silicon-Beach/?chapter_analytics_code=UA-61050816-29),    [Discussion Group]  (https://groups.google.com/forum/#!forum/sil) 


These are the community groups that are innovating and shaking things up:
[Women Who Code Melbourne] (https://www.womenwhocode.com/melbourne)
[HackUp Melbourne] (https://www.meetup.com/en-AU/hackup-melbourne/)
[Power BI Sydney]  (https://www.meetup.com/en-AU/Sydney-Power-BI-User-Group/events/past/)
[Men Championing Change Sydney] (https://www.meetup.com/en-AU/Men-Championing-Change-Meetup/) 

Some people to check out live coding on Twitch:
[Kym Phillpotts]  (https://www.twitch.tv/kymphillpotts)
[Noopkat] (https://www.twitch.tv/noopkat)
[Jim Bennett] (https://www.twitch.tv/jimbobbennett)

A great online initiative:
[HacktoberFest]  (https://hacktoberfest.digitalocean.com/)

Hackathons:
[Hackathons Australia] (https://www.hackathonsaustralia.com/)
[She Hacks 2019 Sydney]  (https://www.meetup.com/en-AU/Girl-Geek-Sydney/events/261586661/)
[Microsoft Global Hack] (https://news.microsoft.com/transform/at-the-microsoft-global-hackathon-customers-break-something-to-make-something/)

Champion/Ambassador Programs: 
[Microsoft MVP] (https://mvp.microsoft.com/)
[Docker Captains] (https://www.docker.com/community/captains)
[AWS Community Heroes] (https://aws.amazon.com/developer/community/heroes/?community-heroes-all.sort-by=item.additionalFields.sortPosition&community-heroes-all.sort-order=asc)
[Cloud Native Computing Foundation (CNCF) Ambassadors] (https://www.cncf.io/people/ambassadors/)
[Google Developer Experts] (https://developers.google.com/community/experts/)
[Java Champions] (https://community.oracle.com/community/groundbreakers/java/java-champions)

Thank you
Desiderata
Tags: watercooler, offtopic, discuss, career
Published: 2019-08-09 21:09:22

---
title: Desiderata
published: true
description: 
tags: watercooler, offtopic, discuss, career
---

Desiderata

Go placidly amid the noise and haste,
and remember what peace there may be in silence.
As far as possible without surrender
be on good terms with all persons.
Speak your truth quietly and clearly;
and listen to others,
even the dull and the ignorant;
they too have their story.

Avoid loud and aggressive persons,
they are vexations to the spirit.
If you compare yourself with others,
you may become vain and bitter;
for always there will be greater and lesser persons than yourself.
Enjoy your achievements as well as your plans.

Keep interested in your own career, however humble;
it is a real possession in the changing fortunes of time.
Exercise caution in your business affairs;
for the world is full of trickery.
But let this not blind you to what virtue there is;
many persons strive for high ideals;
and everywhere life is full of heroism.

Be yourself.
Especially, do not feign affection.
Neither be cynical about love;
for in the face of all aridity and disenchantment
it is as perennial as the grass.

Take kindly the counsel of the years,
gracefully surrendering the things of youth.
Nurture strength of spirit to shield you in sudden misfortune.
But do not distress yourself with dark imaginings.
Many fears are born of fatigue and loneliness.
Beyond a wholesome discipline,
be gentle with yourself.

You are a child of the universe,
no less than the trees and the stars;
you have a right to be here.
And whether or not it is clear to you,
no doubt the universe is unfolding as it should.

Therefore be at peace with God,
whatever you conceive Him to be,
and whatever your labors and aspirations,
in the noisy confusion of life keep peace with your soul.

With all its sham, drudgery, and broken dreams,
it is still a beautiful world.
Be cheerful.
Strive to be happy.

Max Ehrmann, Desiderata, Copyright 1952.
MAD: Game DevLog #4, Main Menu, Camera Shake and Enemies
Tags: gamedev, unity3d, csharp
Published: 2019-08-09 20:21:48

---
title: MAD: Game DevLog #4, Main Menu, Camera Shake and Enemies
published: true
description: Main Menu, Perlin Noise and Graphics.
tags: gamedev, unity, csharp
cover_image: https://thepracticaldev.s3.amazonaws.com/i/1hmvtgbaf6qsglmusfac.png
series: MAD Game DevLog
---

Hello everyone!

Here's what we did for our 4th devlog:

---

We've added a game menu to the game it is interactive and it's working without any code at all. Thanks to Brackeys for making awesome tutorials, here's the one we used for the menu: https://www.youtube.com/watch?v=zc8ac_qUXQY

---

After creating the main menu, we wanted to juice up the game a little and we've researched a ways to shake the camera when a bomb explodes. 

The fist approach was naive and it didn't work. I was taking the camera's position and moving it randomly, which felt robotic. Luckily for us, Unity has a built in perlin noise generator for [Cinemachine](https://unity.com/unity/features/editor/art-and-design/cinemachine), the package we use for managing cameras.

The Perlin noise was developed by Ken Perlin and it is:

> a technique used to produce natural appearing textures on computer generated surfaces for motion picture visual effects.

Unity also lets us tune the generator by modifying its amplitude and frequency parameters, which makes it very convenient to use.

---

Last but not least we weren't satisfied with the enemies, we still have some bugs with their behavior but Andrei was there to fix them. 

What I did instead was to try to make some decent enemy sprites in Aseprite, Cosmigo Pro Motion doesn't work on my Mac :(. 

![](https://thepracticaldev.s3.amazonaws.com/i/c2c63qusqinlosn1hlst.gif)

Since I don't have enough practice my sprites don't look that good, I tried to keep them as simple as possible and I've only used two key frames when animating them.


If you want to start making Pixel Art there are lot of free tutorials on the internet. Here's some to get you started:

* https://blog.studiominiboss.com/pixelart
* https://onimille.tumblr.com/archive

---

Thanks for reading and have a nice day!