Posts for Snippets

Useful and effective code snippets for Vue, React, JavaScript, Laravel and more..
Deven
Deven wrote

Python upper(), lower(), isupper(), and islower() Methods example

Sometimes we may need to Convert String characters to uppercase and lowercase, for this purpose Python provides us two methods: The upper() string method converts all of the characters to uppercase The lower() string method converts all of the characters to lowercase upper() string method example code output lower() string method example code output isupper(), […]

July 25, 2020 in Python & Snippets
Deven
Deven wrote

Python Trim String Example | rstrip(), lstrip(), strip() Function

Sometimes we may need to Trim String, whitespace characters from the left side, right side, or both sides of a string. For this purpose Python provides three methods to Trim String. The strip() string method will return a new string without any whitespace characters at the beginning or end. The lstrip()  method will remove whitespace characters from the left […]

July 25, 2020 in Python & Snippets
Deven
Deven wrote

Snippets – React Fetch Hook example

This React Fetch hook is created by composing the useState and useEffect hooks. The three states of a fetch request in the above code snippet are: pending – when the request is pending data – data is retrieved successfully Error – something went wrong These states are managed inside useEffect hook.

July 23, 2020 in Snippets

Vue.js Snippets – Make API Request on User Input

Some applications like Gmail and Facebook have a search feature where as a user enters some input, the input is sent to the server and the results are used to provide the user with results closer to what the user is looking for. To implement this behaviour in Vue, we use a library called debounce […]

May 16, 2020 in Snippets

Vue.js Snippets – Display Loader while Fetching Content

When loading data in Vue.js applications, you may want to display some form of loading indicator so your users will know that something is happening. Vue.js provides us with the v-if directive which allows us to conditionally show/hide any piece of markup. In the snippet below, we have our data property loading which is set […]

May 15, 2020 in Snippets

How to Capitalize Text with JavaScript

In this article, you will learn to Capitalize Text with JavaScript. JavaScript has built-in methods like .toLowerCase() – to convert text to lower case – and .toUpperCase() – to convert text to upper case. However, there’s no built-in method to convert text to title case i.e. “How Are You”. However, we can combine .toUpperCase() with […]

May 7, 2020 in Snippets

Vue.js Snippets – Delete Item from List

There are a few common operations that are performed on lists: add a new item, search through the list, and deleting an item from a list. The snippet below shows how to delete an item from a list. list is an array of names. In the <template>, we render the list using v-for. For each […]

May 7, 2020 in Snippets

Vue Snippets – Conditional Style Binding

A common use for data binding is to conditionally alter the classes and styling of an element. The snippet below shows how this can be achieved: By default, the <p> tag is styled to have a red text color. However, <p> tags with the .active class get styled with a blue text. Since the data […]

May 6, 2020 in Snippets

JavaScript Snippet – Download Picture/Video

There are a couple of ways to download media assets on the web. One of them involves making an HTTP request to the location of the media asset and using JavaScript inbuilt methods to manipulate the asset. To get started, we add a button to our markup that would trigger the download. We add an […]

May 5, 2020 in Snippets

Vue Snippets – Search List Filter

Filters are part of many applications as it helps the user sort through a wide range of items. We can use the combination of v-model and computed properties to achieve this. In the snippet above, we have a list of items and an input field. As you type into the input field, the list gets […]

May 1, 2020 in Snippets

Vue Snippets – Add Data to List

Sometimes you have a list of items you would like to add to, based on some user interaction or event. The snippet below gives a base template to achieve this. In the snippet above, we have a list, an input field and a button. When the button is clicked, the value of the input field […]

May 1, 2020 in Snippets