menu

Search By Label

CommonJS (Node.js):
  • Syntax: Utilizes require to import modules and module.exports or exports to define exports.
  • Loading: Synchronous, modules are loaded and executed sequentially.
  • Use Cases: Well-suited for server-side applications, especially in Node.js environments where synchronous loading is acceptable.

ES6 Modules:
  • Syntax: Uses import and export statements for importing and exporting modules.
  • Loading: Supports asynchronous loading, enabling more efficient loading of modules in browsers.
  • Use Cases: Widely used in front-end development due to support in modern browsers. Offers a more standardized syntax and supports advanced features like dynamic
  • imports.
types are indexed by the default whereas interfaces are not. It makes interfaces more safe. 

Consider this example:
type Admin = {
    name: string,
    privileges: string[]
}

type Employee = {
    name: string,
    startDate: Date
}

type CombinedType = Admin & Employee;

interface CombinedInterface extends Admin, Employee { }

const interfaceData: CombinedInterface = { name: '', privileges: [], startDate: new Date() }
const typeData: CombinedType = { name: '', privileges: [], startDate: new Date() }


const handleType = (obj: Record<string, unknown>) => {
    obj['name'] = 42 // unsafe
}


handleType(interfaceData) // error
handleType(typeData) // ok

Source: https://stackoverflow.com/questions/72598769/intersection-types-vs-interfaces-in-typescript
process.nextTick is a Node.js feature that defers the execution of a callback function to the next iteration of the event loop. It's often used when immediate execution is necessary, but the function should be deferred to avoid blocking the event loop. For example, in scenarios where you want to ensure that certain asynchronous operations are complete before continuing, process.nextTick can be employed.
Remove the file and rewrite the history from the commit you did with the removed file(this will create a new commit hash from the file you committed):

there are two ways:

  1. Using git-filter-branch:
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch <path to the file or directory>' --prune-empty --tag-name-filter cat -- --all

  1. Using git-filter-repo:
pip3 install git-filter-repo
git filter-repo --path <path to the file or directory> --invert-paths
Use this following command from your terminal to amend email/name from all commits in a branch:

git filter-branch --env-filter '
OLD_EMAIL="old-test@test.com"
CORRECT_NAME="Oswaldo Pineda"
CORRECT_EMAIL="new-test@test.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
Optimistic Concurrency Control (OCC) is a technique used in computer systems, particularly in databases, to manage concurrent access to shared resources without resorting to locking mechanisms that can potentially introduce performance bottlenecks and contention.

Imagine you have a group of friends trying to update a shared document online at the same time. Optimistic Concurrency Control is like letting everyone make changes freely and then checking for conflicts later.

Here's how it works:
  1. Checking Out the Document: Each friend checks out the document and sees a version number (like "1.0"). This tells them the state of the document when they started.
  2. Making Changes: Friends start making changes to the document without telling each other. They trust that conflicts are rare.
  3. Checking Back In: Before saving their changes, each friend checks the version number again to make sure nobody else has made changes in the meantime.
  4. Conflict Check: If someone else made changes (maybe the version is now "1.1"), it means there's a conflict. Friends are notified, and they need to figure out how to resolve the conflicting changes.
  5. Saving Changes: If no conflicts are found, the changes are saved, and everyone's updates are combined.
memo lets you skip re-rendering a component when its props are unchanged.

Wrap a component in memo to get a memoized version of that component. This memoized version of your component will usually not be re-rendered when its parent component is re-rendered as long as its props have not changed. But React may still re-render it: memoization is a performance optimization, not a guarantee.

import { memo } from 'react';
const SomeComponent = memo(function SomeComponent(props) { // ...});
Through the Heroku PostgreSQL add-on create a new backup capture you can do that by the UI or the CLI running:

heroku pg:backups:capture -a your-production-name-app

and after that run:

heroku pg:backups:restore <production-database-name>::<you-backups-id> DATABASE_URL --app <production-staging-enviroment> --confirm <production-staging-enviroment>

example:

heroku pg:backups:restore juanequex-prod::b194 DATABASE_URL --app juanequex-staging --confirm juanequex-staging

Enjoy! c:
Through the Heroku PostgreSQL add-on create a new backup capture you can do that by the UI or the CLI running:

heroku pg:backups:capture -a your-production-name-app

After that download the backup on your local machine, and set it in your local environment running on the terminal:

pg_restore --verbose --clean --no-acl --no-owner -h localhost -d <data-base-name> /Users/juanequex/backups/<your-local-backup>

and it is what it is, enjoy your local debugging.
The npm show command is used to display detailed information about a package available on the npm registry. 
This command provides information such as the package's metadata, versions, maintainers, dependencies, and more. It's a useful tool when you want to inspect details about a package without necessarily installing it.

Here is the basic syntax of the npm show command:
npm show <package-name>

Keep in mind that npm show retrieves information directly from the npm registry, so it doesn't require the package to be installed locally. It's a convenient way to inspect package details before deciding to install or use a particular version.
npm-check-updates upgrades your package.json dependencies to the latest versions, ignoring specified versions.

Source: npm-check-updates - npm (npmjs.com)
To check if any module in a project is 'old':
npm outdated
'outdated' will check every module defined in package.json and see if there is a newer version in the NPM registry.

CDN
Use CDN if you are developing a website that will be accessible by public internet users.

CDN Benefits:
  • Will be cached on most browsers because it's used by a lot of other websites
  • Reduce the bandwidth

NPM
npm is a great tool for managing your app's dependencies using a module bundler.

Example:

assume using a webpack module bundler and jQuery is installed
import $ from 'jQuery'
...
var content = $('#id').html();

but the browser does not understand the import statement so you have to transpile the code with Webpack commands, the bundler will check all the used dependencies and bind them in a single file without any dependency problems.

Source: javascript - Using CDN vs Installing library by NPM - Stack Overflow

ACID properties are principles of transaction-oriented database recovery.
ACID is an acronym for a set of properties for database transactions used to make sure data is valid.

The ACID principles are:
  • Atomicity: A transaction is made up of multiple statements. Atomicity ensures that either all statements are executed or none are executed.
  • Consistency: Consistency ensures that integrity restraints are followed.
  • Isolation: Transaction often occurs concurrently, at the same time, and isolation ensures that this does not lead to inconsistent data.
  • Durability: Durability ensures that once a transaction is committed, it will remain committed even in the case of a system failure.

See more examples on: https://www.freecodecamp.org/news/acid-databases-explained/?ref=dailydev
List the stashes:
git stash list

Show the files in the most recent stash:
git stash show

Show the changes in the most recent stash:
git stash show -p

Show the changes in the named stash:
git stash show -p stash@{1}

Or in short:
git stash show -p 1