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 / html-triggers.md
Last active July 16, 2023 19:09
Trigger HTML child by interacting with it's parent using pseudo classes

Trigger HTML child by interacting with it's parent using Pseudo classes

<div class="myDiv">
  
  <h2 class="myTitle">Title</h2>
  <h2 class="newTitle">Title2</h2>
  
</div>
@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.

@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 / 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 / disable-sentry.md
Last active June 2, 2024 00:19
Disable Sentry in development environment (or any other env) using Next.js/Node.js

Disable Sentry in development environment (or any other)

Look for Sentry config file/s (sentry.client.js & sentry.config.js)

Either file should contain an object like this

Sentry.init({
  dsn: DSN_YOU_ACQUIRED_FROM_SENTRY
})
@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.