teleren/devto huggingface dataset:
Measuring Python Code Execution Time
Tags: python, performance
Published: 2020-04-10 15:43:27

---
title: Measuring Python Code Execution Time
published: true
description: How to measure the execution time of small python code snippets
tags: python, performance
---

Timing how long it takes for a code snippet to run is a good way to measure the performance of your code. Though this doesn't really give the accurate measurement of the performance of your code snippet, but it gives you an idea of the increase or decrease in the performance of your code snippet.

In this short post, I'll be giving you tips on how to use the timeit python module in measuring your python code snippet.

>timeit is a built-in Python module that provides a simple way to time small bits of python code. This Module can be used from the Command-Line Interface(CLI) or can be imported to your code and called.


##Using timeit within your code

```python
import timeit


def myFunction():
	
	for i in range(1000):
		print (i*i)

print(timeit.timeit(myFunction, number=1))
```
In the code, we are looping through a range of 100 and printing the multiple of each step. Then we printed the time it took the code to run once(number=1) using the timeit method of the timeit module. The function takes to arguments:
1. The name of the function to time
2. The number of times we want to run the run the function. When the number of time is set, it returns the time it took to run the function in the given number of times.

If we want to know how long it will take for the function to run 10 times, then we have to specify that in the number argument:

```python
import timeit


def myFunction():
	
	for i in range(1000):
		print (i*i)

print(timeit.timeit(myFunction, number=10))
```


>It's important to note that the output of running this code would be the number of times it took to run the myFunction function in seconds. If you would like to get home times it took to run once, you can set the value number argument to 1 or divide by the value of number set.

This is just the basic use case of the timeit module. There are other methods available on the timeit modules and can be found in the [python module documentation] (https://docs.python.org/2/library/timeit.html)

Hope this was helpful, feel free to contribute and let me know if I missed something.
May 15th, 2020: What did you learn this week?
Tags: weeklylearn, discuss, weeklyretro
Published: 2020-05-15 12:52:02

Photo by [Chris Benson](https://unsplash.com/@lordmaui?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/learn?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)

It's that time of the week again.

So wonderful devs, what did you learn this week? It could be programming tips, career advice etc.

<center>

![A cartoon brain with arms lifting weights saying "Knowledge is power!"](https://media.giphy.com/media/ijxKTF6iE4K4M/giphy.gif)

</center>

Feel free to comment with what you learnt and/or reference your TIL post to give it some more exposure.

{%tag todayilearned %}

And remember, if something you learnt was a big win for you, then you know where to drop it as well.👇👇🏻👇🏼👇🏽👇🏾👇🏿

{% link https://dev.to/jess/what-was-your-win-this-week-35in %}

<center>

![Bender from Futurama dancing](https://media.giphy.com/media/mIZ9rPeMKefm0/giphy.gif)

</center>
Get Clients While on Lockdown
Tags: freelancing, remote, beginners, career
Published: 2020-05-18 03:01:00

---
title: Get Clients While on Lockdown
published: true
date: 2020-05-15 12:49:00 UTC
tags: freelancing,remote,beginners,career
canonical_url: https://raddevon.com/articles/get-web-development-clients-while-on-lockdown/
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/3lqud6a39x3a93at23sd.jpg
---

{% youtube hSulX92JQM4 %}

Video Notes
-----------

OK, everybody. We’re going back to the drawing board. I tell new developers to start looking for freelance clients in-person. (By the way, if you’re not yet sold on freelancing, read [why I recommend it as the best way to start your career](https://raddevon.com/articles/inverted-career-path/).) I would _never_ recommend that right now. Instead, I have some other ideas about how you can still move forward, even when you can’t get in front of people.

Here are the four steps I describe in the video:

1.  **Decide who you will work for.** This is counterintuitive, so stay with me for a second. In order to get clients during the pandemic when you can’t go charm people in person with your wonderful personality, you need to pick a [niche](https://raddevon.com/articles/how-do-i-find-my-web-developer-niche/). That’s right. I want you to get clients by reducing the potential pool of people you can work for. Why you’d want to do this will hopefully make sense when you watch the video.
2.  **Discover their problems.** Learning what’s important to them lets you talk to them in a way they can understand. It also gives you some ideas of what you could build for them.
3.  **Get in front of them.** Not literally. They need to know you exist even though you can’t literally get in front of them. I’ll share some ideas for how you can do this while staying safe.
4.  **Show them your offer.** You’ve learned what their problems are. Now, offer to fix one of them using your magical web development skills. Again, you can’t do this in person, but I can show you how.

Once you’ve worked through the advice in this video, you’ll need a price for your offer. I’ve got you covered. Learn about my book [_Freelance Web Development Pricing_](https://raddevon.com/freelance-web-development-pricing-rates-estimating-projects-and-turning-a-profit/) and get the first chapter for free!
Cheatsheet for Razor Page
Tags: cheatsheet, razor, dotnet, razorpage
Published: 2020-05-14 09:04:30

# Keywords

### View
``` javascript
ViewData | ViewBag | TempData | @page | @model
@addTagHelper | @removeTagHelper | @Html.AntiForgeryToken()
RenderBody | RenderSection
Html.BeginForm("<Action>", "<Controller>")
Html.RenderPartialAsync("<Name of file with extension .cshtml>")
Html.DisplayNameFor(model => model.ReleaseDate)
Html.DisplayFor(model => model.Title)
```

### Model
``` javascript
ViewData | ViewBag | TempData | View() | Page()
IActionResult | ModelState | RedirectToPage
```

### Data Annotation
*Reference: https://dev.to/ssmak/test-2fl0*
``` javascript
[BindProperty] | [BindProperty(Name = "Name123")] | [BindProperty(SupportsGet = true)]
[Key] | [DisplayName] | [Column] | [StringLength], [Range], [RegularExpression]
[HttpPost] | [ValidateAntiForgeryToken]
```

### Tag Helper
*Reference: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/?view=aspnetcore-3.1*
``` javascript
asp-page | asp-page-handler | asp-route-<> | asp-action | asp-controller
asp-for | asp-items

/*
Use with <div>
e.g.
<div asp-validation-summary="All">
    <span>Please correct the following errors</span>
</div>
*/
asp-validation-summary

/*
Use with <span>
e.g
<span asp-validation-for="FirstName" class="myclass"></span>
*/
asp-validation-for

/*
Import partial view
*/
<partial name="_MenuPartial" />

/*
Import view component
*/
<vc:priority-list max-priority="2" is-done="false">
</vc:priority-list>
```

### Html Helper
``` javascript
Html.DisplayNameFor | Html.DisplayFor | Html.RenderPartialAsync
Html.Partial
```

<hr />

# Code References

### Form validation
``` html
<!-- asp-validation-summary, asp-for, asp-validation-for -->
<form method="post">
	<div asp-validation-summary="ModelOnly" class="text-danger"></div>
	<input type="hidden" asp-for="Products.ProductId" />
	<div class="form-group">
		<label asp-for="Products.ProductName" class="control-label"></label>
		<input asp-for="Products.ProductName" class="form-control" />
		<span asp-validation-for="Products.ProductName" class="text-danger"></span>
	</div>
</form>
```

### Import external JavaScript file
``` cs
@* @section, Scripts, Html.RenderPartialAsync  *@
@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
```

### Custom tag helper
``` cs
public class EmailTagHelper : TagHelper
{
	private const string EmailDomain = "contoso.com";

	// Can be passed via <email mail-to="..." />. 
	// Pascal case gets translated into lower-kebab-case.
	public string MailTo { get; set; }

	public override void Process(TagHelperContext context, TagHelperOutput output)
	{
		output.TagName = "a";    // Replaces <email> with <a> tag

		var address = MailTo + "@" + EmailDomain;
		output.Attributes.SetAttribute("href", "mailto:" + address);
		output.Content.SetContent(address);
	}
}
```
An Introduction to Remote Procedure Calls (RPC's)
Tags: distributedsystems, webdev, go
Published: 2020-05-15 12:30:20

I've started studying distributed systems in college and here's a beginners view on RPC's.


### What is a Remote Procedure call?
Remote Procedure calls are protocols that enable a program execute a service in a different address space or another computer for simplicity.These are normally referred to as subroutine calls or function calls.


**RPC's** are synchronous which means client programs requesting need to be suspended until the results of the subroutine call is returned.

In the OSI model, an RPC laps the transport layer and Application Layer.

### Types of RPC
1. The regular method in which the client continually pings the server until it responds.

2. The client requests and continues to process without having to wait for a response from the server. **note** : The server doesn't respond.

3. Sending non-blocking client calls in bulk.

4. Sending messages to many servers and receiving replies

5. Client makes a non-blocking client/server call , the server responds by invoking a procedure associated with the client.
What's the reach of a semi successful "Show HN" post on HackerNews (200 points)...
Tags: webdev, serverless, javascript
Published: 2020-05-15 12:14:19

I recently released my first hobby project to "production", with a `Show HN` post on HackerNews as the only public announcement. I was pretty shocked by the attention it received, and thought y'all might be interested in hearing about it.

During the process of development and release I hadn't really put much thought into how I would get the word out about the app I had built... Once it was finally live, I decided to post about it on HackerNews, thinking I'd be lucky to get a few hundred hits, and perhaps a couple of comments giving some snarky feedback on better ways to implement my idea.

What I ended up with was over **20,000** unique views in the first 24hrs, and a bunch of positive comments and great feature ideas from ~30 people in the HN community (also $15 in beer money!).

> I created the post at ~ 12:00 UTC 
> It peaked at #4 on the home page, with 68 points 3 hours in.
> It stayed on the front page (top 30) for ~12 hours, gaining ~150 points.
> It spent the next ~12 hours on the second page (top 60), ending up with 200 points (growth of the post stopped here).

Initial post to HackerNews was on 8th May, since then I've seen ~500 unique visits per day.

At the time, the hits I got were surprising. Although, in hindsight, perhaps it is expected from such a popular forum.

Interestingly, there was a big spike today—mainly new unique visits from China (~1,000 new on top on the average ~500 daily).

I don't intend for this post to be a brag. Before this experience, I had no reference for the kind of reach a post on HackerNews could have, and thought this would be interesting info to share.

I was also pleasantly surprised by how positive the feedback was on HN— genuinely great suggestions and feature ideas that I'm working on implementing now.

I hope this may serve as encouragement for other devs who might be anxious about sharing projects. Just do it!

It's worth mentioning that this is my first experience with a post on HN "trending"—your milage may vary :)
Drupal Development
Tags: Drupal, Drupal8
Published: 2020-05-15 12:07:20

Our pursuit of success is driven by an innovative approach followed by our expertise that helps you to redesign your enterprise solution. We align technology, speed, and agility to meet your business needs; for now and in the future too. 

We AddWeb Solution, an expert into Drupal development services are to streamline your enterprise process and deliver better. With the perfect blend of expertise and experience, we drive better value for you.
https://addwebsolution.com/drupal-development-services
Learn Python: Tuples
Tags: python, tuples, tutorial, beginners
Published: 2020-05-15 12:06:51

---
title: Learn Python: Tuples
published: true
description: Introduction to lists in Python
tags: python, tuples, tutorial, beginners
series: [Learn Python]
cover_image: https://images.pexels.com/photos/4050296/pexels-photo-4050296.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940
---

`Tuple` shares some similarities to `list`.
Just like a list, a tuple variable can hold multiple values.

However:
- There are no square brackets `[` `]`.
- The values are separated by a `,` .
- It is good practice to use brackets `(` `)` around the values, but it is not required. However, where python can't understand whether to evaluate the values as a tuple or a list, brackets will be required.

### Creating  new tuple.
```py
a_tuple = "Rishi", "Abee"
another_tuple = (1, 2)
```
![](https://i.imgur.com/tUU0QSC.png)

⚠️ NOTE: Leaving a trailing `,` at the end of a value will cause python to evaluate the variable as a tuple instead.
```py
a_string = "Rishi"
a_short_string_tuple = "Rishi",
a_short_number_tuple = 2,
```
![](https://i.imgur.com/b1Dp2bS.png)

Tuples can be added to a list.
💡 To help python better understand whether to evaluate the values as a tuple, brackets `(` `)` are required.
```py
a_list = ["Orange", "Yellow"]
a_tuple_inside_a_list= [('🍏', '🍎'), another_tuple, 'Hello']
```
![](https://i.imgur.com/mczut34.png)

### A Tuple is Immutable
Unlike a list, a tuple cannot be modified by appending values to it.
If we need to add values to a tuple, we will have to re-assign the same tuple a new value.
```py
# Adding to a tuple.
a_tuple = "Rishi", "Abee"
a_tuple = a_tuple + ("Python",)
print(a_tuple )
```
![](https://i.imgur.com/nrsRjzV.png)



<hr>
{% replit @rishiabee/learnpytuple %}
Kissjs first look: Building a todo app in 4 minutes
Tags: javascript, showdev, typescript, webdev
Published: 2020-05-15 12:05:10

This is a first look on how you will be building mobile apps with kissjs.

In this video I build a **fully working todo app** with data syncing between devices in 4 minutes.

I will explain the project structure and how kissjs works in the next videos. So make sure you [follow me on twitter](https://twitter.com/rallipi) to not miss any of them.
May 15 — Daily CodeNewbie Check-in Thread
Tags: codenewbie, checkin, beginners, discuss
Published: 2020-05-15 12:00:25

---
title: May 15 — Daily CodeNewbie Check-in Thread
published: true
description: A daily thread to ask questions, share progress, and stay accountable!
tags: codenewbie, checkin, beginners, discuss
series: Daily Checkin
---

You are encouraged to use this daily thread to:
- Ask for help (all questions encouraged)
- Explore topics you’re curious about
- Share something you’ve written or read
- Celebrate your wins
- Stay accountable to your goals
- Support your fellow programmers

Happy Coding!

---

_Interested in joining the twice-weekly live [#CodeNewbie Twitter chats](https://twitter.com/search?q=codenewbie)?  You can find us [on Twitter](https://twitter.com/search?q=codenewbie) each Wednesday at 9pm ET (1am GMT on Thursday) and Sunday at 2pm ET (6pm GMT)!_
Daily Developer Jokes - Friday, May 15, 2020
Tags: jokes, dailydeveloperjokes
Published: 2020-05-15 12:00:20

---
title: "Daily Developer Jokes - Friday, May 15, 2020"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
cover_image: "https://private.xtrp.io/projects/DailyDeveloperJokes/thumbnail_generator/?date=Friday%2C%20May%2015%2C%202020"
published: true
tags: #jokes, #dailydeveloperjokes
---

Generated by Daily Developer Jokes, a project by [Fred Adams](https://xtrp.io/) ([@xtrp](https://dev.to/xtrp) on DEV)

___Read about Daily Developer Jokes on [this blog post](https://xtrp.io/blog/2020/01/12/daily-jokes-bot-release/), and check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/).___
### Today's Joke is...
![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1258c00f974.png)

---
*Have a joke idea for a future post? Email ___[xtrp@xtrp.io](mailto:xtrp@xtrp.io)___ with your suggestions!*

*This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit.*

<!-- 
Joke text:
___Q:___ What does a baby computer call his father?

___A:___ Data!
 -->
Different types of JOINS in SQL Server
Tags: sql, sqlserver, joins
Published: 2020-05-13 16:04:48

**JOINS fundamentals**

In relational databases, such as SQL Server, Oracle, MySQL, and others, data is stored in multiple tables that are related to each other with a common key value. Accordingly, there is a constant need to extract records from two or more tables into a results table based on some condition. In SQL Server, this can be easily accomplished with the SQL JOIN clause.

JOIN is an SQL clause used to query and access data from multiple tables, based on logical relationships between those tables.
In other words, JOINS indicate how SQL Server should use data from one table to select the rows from another table.

![Basic SQL JOIN types] (https://www.devart.com/dbforge/sql/sqlcomplete/images/joins-types.png)

**Enjoying JOINS with SQL Complete**

[SQL Server JOINS](https://www.devart.com/dbforge/sql/sqlcomplete/sql-join-statements.html) are vitally important to master. As you progress from a database beginner to a more advanced user, you’ll continually need to fetch and combine data from more than one table. At this point, SQL Complete comes to the aid. Its code completion works well even for complex JOIN statements. You don’t need to memorize multiple column names or aliases, dbForge SQL Complete will suggest a full JOIN clause based on foreign keys, or conditions based on column names. These suggestions are available after the JOIN and ON keywords.

More than that, SQL Complete can prompt a complete SQL JOIN statement when you combine tables based on foreign keys. You can select a JOIN statement from the prompt list manually, in case you need a specific JOIN operation.
npm ERR! Unexpected end of JSON input while parsing near
Tags: errors, troubleshooting, npm, webdev
Published: 2020-05-15 11:40:21

---
title: npm ERR! Unexpected end of JSON input while parsing near 
published: true
description: npm ERR! Unexpected end of JSON input while parsing near 
tags: error, troubleshooting, npm, webdev
series: [Troubleshooting]
cover_image: https://images.unsplash.com/photo-1555861496-0666c8981751?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80
---

You are trying to create a new angular, react, vue app, and you end up with an error message saying: 

> npm ERR! Unexpected end of JSON input while parsing near 

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

There's a high chance that your `npm` cache been damaged.

Try:

```sh
npm cache clean --force
```
![](https://i.imgur.com/avXSCzt.png)

If you are a `windows` user, try deleting all files in this folder:
```
C:\Users{{your-username}}\AppData\Roaming\npm-cache
``` 

Then...

```sh
npm cache verify
```

If that doesn't work,  try updating to the lastest (understand the risks)
```
npm i npm@latest -g
```

I hope this helps!
Understanding Kubernetes: part 24 – Node operations
Tags: kubernetes, devops, docker, beginners
Published: 2020-05-15 11:34:17

---
title: Understanding Kubernetes: part 24 – Node operations
published: true
description: Serie of sketchnotes about Kubernetes. Explaining in a visual way Kubernetes principles.
tags: Kubernetes, DevOps, Docker, beginners
series: Understanding Kubernetes in sketchnotes
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/kzsrhgsvqvjsa2i3v97k.jpg
---

Understanding Kubernetes can be difficult or time-consuming. In order to spread knowledges about Cloud technologies I started to create sketchnotes about Kubernetes. I think it could be a good way, more visual, to explain Kubernetes (and others technologies).

We continue the serie of Sketchnotes about operations we can do to a Node: drain, cordon, uncordon...

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

If you are interested, I published all the sketchnotes on Kubernetes (and new ones!) to make a "book" of 120 pages: ["Understanding Kubernetes in a visual way"](https://gumroad.com/aurelievache#uCxcr).

As usual, if you like theses sketchnotes, you can follow me, and tell me what do you think. I will publish others sketchs shortly :-).
Laravel Queues Example Using Redis and Horizon
Tags: laravel, queues, redis, horizon
Published: 2020-05-15 11:32:37

Hello Artisan

In this tutorial i will show you a simple laravel app that interpret how to use Laravel Queues and how to run Laravel Queue with redis and Monitoring with Laravel Horizon. 

https://www.codechief.org/article/laravel-queues-example-using-redis-and-horizon
Getting a PWA to self-update
Tags: PWA, react, javascript
Published: 2020-05-15 11:23:02

So people have asked me to share how to make sure your PWA automatically updates itself, even on #iOS 12 (which preserves the state of your app even when quitting it).

In my case the app is stateless so I can allow myself to just reload the app without showing any prompts for update to the user. If your app is more complex you can show a prompt in every place I do `location.reload`, all other things should be relevant.

Here's the point to listen if the new ServiceWorker is available: https://github.com/dimaip/calendar/blob/ea68923793e8975a483aff8605f52e5c913b9344/app/serviceWorker.js#L26

When installing SW I do skipWaiting to make it take control immediately, without waiting for all tabs to be closed. Also I do `clients.claim` in order to take control of all the tabs that have no SW installed yet for some reason: https://github.com/dimaip/calendar/blob/ea68923793e8975a483aff8605f52e5c913b9344/app/service-worker.js#L6-L11

On every route transition I compare the current app's version with the version returned by app's version endpoint: https://github.com/psmb/calendar/blob/ea68923793e8975a483aff8605f52e5c913b9344/app/Routes.js#L24
If the versions differ I reload. This is especially important on iOS 12 where there's no way to make the app to reload from user actions.

On every deploy I tag a new version with `yarn version --patch`. Here's how I expose it server-side: https://github.com/psmb/calendar/blob/ea68923793e8975a483aff8605f52e5c913b9344/server.js#L73

I also display the version in the app, quite helpful when debugging: https://github.com/psmb/calendar/blob/ea68923793e8975a483aff8605f52e5c913b9344/app/containers/Main/BurgerMenu.js#L87

That's it! On every route transition I can be sure that the users have the latest version of the app.

Make sure you also read this related post how to deploy an app with code-splitting, or else you won't get very far with auto-updates! https://dev.to/dimaip/what-you-should-consider-before-deploying-an-app-with-code-splitting-1n76