Skip to content

Instantly share code, notes, and snippets.

View MirzaLeka's full-sized avatar
:octocat:

Mirza Leka MirzaLeka

:octocat:
View GitHub Profile
@MirzaLeka
MirzaLeka / benchmark-js.md
Created January 21, 2023 17:00
Benchmark JavaScript Code

Benchmark JavaScript Commands

Using console.time() & console.timeEnd() you can measure how long it takes for your code to execute.

console.time('any-name-you-want');

for (var i = 0; i < 1000_000; i++) {}

console.timeEnd('the-same-name-as-above')
@MirzaLeka
MirzaLeka / aws-sqs-guide.md
Last active January 29, 2023 23:05
AWS SQS Guide

AWS SQS Guide

Amazon Simple Queue Service (SQS) lets you send, store, and receive messages between software components at any volume, without losing messages or requiring other services to be available.

Messages stored in SQS can be pulled out by other services such as EC2, Lambda, etc. Upon pulling, message is deleted from the queue.

image

@MirzaLeka
MirzaLeka / react-hooks-async-await.md
Created February 5, 2023 15:21
React Hooks Async Await

React Hooks with Async Await

Learn how to use Async Await with common React Hooks

UseEffect

State

const [ APIData, setAPIData ] = useState<APIInterface>();
@MirzaLeka
MirzaLeka / circle-ci-ci-cd.md
Created March 26, 2023 12:15
Circle CI JavaScript / Node.js Setup (CI/CD)

Circle CI JavaScript Setup (CI/CD)

Circle CI is Continuous integration Continuous delivery platform. Alternative to Github Actions. The service is free to use, but there are paid packages as well.

Setting up Circle CI

  • Go to Circle CI and create an account (sign up with Github)
  • Connect your repository

Extending Core Classes in C#, JavaScript & TypeScript

This article will teach your how to extend the core array class with custom methods in various languages. To apply this we'll make use of:

  • Extension Methods (C#)
  • Prototypes and Classes (JavaScript)
  • Types and Prototypes and Classes (TypeScript)

We're going to make a new method isEmpty that is going to check if the array, list or collection is empty. So when a consumer calls this method it will return true or false.

@MirzaLeka
MirzaLeka / NestJS DI.md
Last active April 30, 2023 18:44
Nest.js Depdendency Inversion example

Nest.js Dependency Inversion with Abstract classes

The Motivation

In strictly typed object-oriented languages such as Java or C#, it's a common practice to invoke a method from a service by calling an interface as opposed to an actual service. This pattern is useful when swapping dependencies on the fly (like logging to the console or to the database) or unit testing, as we're not bounded to work with actual classes, but rather abstractions.

The Problem

EF Core Query All Paramaters that are not null

If you find yourself in a situation where you have multiple parameters where you can query:

  • by one param
  • combination of params
  • all params

And you want to execute just one DB call and avoid querying with params that are NULL, do the following:

@MirzaLeka
MirzaLeka / removeItemFromArrayJS.md
Last active July 16, 2023 19:04
Find and remove item from an array using ES6/7

Remove Item from Array in JavaScript

Quite simple, really! Please keep in mind that ES7 might not be compatible with IE.

    const myArray = [];

        let addToArray = (newItem) => {
            
 if ( myArray.includes(newItem) ) {
@MirzaLeka
MirzaLeka / TriggerJSKeyPressEventWithoutInput.md
Last active July 16, 2023 19:05
Trigger Javascript event on keypress without input or button

Trigger Javascript event on keypress without input or button

Open HTML document and find a body tag. Give the body tag onkeypress attribute. It shoud look like this:

<body onkeypress="KeyPressCheck(event)"> 
...html code...
</body>

Once that's done head over to your Javascript file that you'll import inside the html file with <script> tag.

@MirzaLeka
MirzaLeka / ReplaceDoubleQuotesWithSingle.md
Last active July 16, 2023 19:06
Replace double quotes with single quotes | Javascript

Replace Double Quotes with Single ones in JavaScript

During my short use of MongoDB I encountered an issue with double quotes. Since MongoDB stores documents (objects) as JSON fields, key and value pairs, all string values are surrounded with double quotes. Example:

{"name": "Bruce Wayne"}

Although MongoDB will add an escape character if you use double quotes, using double quotes multiple times in the same string will throw an error. To avoid it, I found this handy code snippet that will replace all double quotes with single ones using regex.