Skip to content

Instantly share code, notes, and snippets.

@juandm
juandm / Find and remove dead code.md
Last active February 27, 2023 22:16
A guide to find and remove dead code in JavaScript and TypeScript projects

Finding, removing, and monitoring dead code

This guide considers only Javacript/Typescript projects, since the main library used on it detects dead code in this language.

How this works?

There is a lib that provide this functionality and some recommended configs for it. The lib searches for code that is exported and not imported in other files and list them. It is also easy to ignore some directories and/or files that are ok to contain dead code.

Detecting dead code

@juandm
juandm / REST API design guide lines.md
Last active February 27, 2023 21:44
Simple guide lines to follow when creating REST APIs

REST API Design Guidelines

This document aims to define some structural guidelines to be used when designing REST API design.

  1. Use hyphens instead underscores to improve URI readability
  2. Prefer lowercase letters, following the rule above, avoid to use camelCase in URI sections
  3. Avoid to include file extension in URIs, this should be communicated to the client via HTTP headers. i.e. content-type header.
  4. Use always plurals for resource collections, example http://api.company-xyz.com/clients instead http://api.company-xyz.com/client
  5. Avoid to use verbs in our endpoints (RPC style), the verb is implicit by the HTTP method we are using (GET - POST - PUT - PATCH - DELETE). For example, avoid HTTP GET - http://api.company-xyz.com/getAgent/:agentId instead use something like HTTP GET - http://api.company-xyz.com/agents/:agentId.
  6. Prefer query string for search, filters and pagination:/houses?city=San%20Francisco&page=2&size=30&order=desc
@juandm
juandm / see_github_workflow_secret.md
Last active August 3, 2022 17:57
See Github workflow secret value if you forgot it

Check secret value in Github workflow

  1. Create a new branch called test-branch.

  2. Create a workflow YAML file in .github folder in the root of your project, with the content below:

    • test.yml

name: Test workflow

Keybase proof

I hereby claim:

  • I am juandm on github.
  • I am juandm (https://keybase.io/juandm) on keybase.
  • I have a public key ASBF-EGu2vcDArxfbyC2dEj2dw7r1aoklDYG9AimmJCAOwo

To claim this, I am signing this object:

@juandm
juandm / example.sh
Created August 17, 2021 15:39
BashScriptWithOptions.sh
#!/bin/bash
############################################################
# Help #
############################################################
Help()
{
# Display Help
echo "Add description of the script functions here."
echo
echo "Syntax: scriptTemplate [-g|h|v|V]"
@juandm
juandm / StrapiAdminPasswordRecoveryInDev.md
Last active April 4, 2021 17:51
Recover strapi admin password in development mode

Strapi recover admin password in development mode

  1. Open a console inside the project folder.
  2. execute npx strapi console command
  3. Copy & paste this code snippet in the console
     function changePassword(useremail, password) {
       strapi.admin.services.user.findOne({ email: useremail })
       .then((u) => {
         if (u) {
@juandm
juandm / HerokuCommands.md
Last active October 30, 2020 12:56
Heroku commonly used commands

Heroku commands


Heroku accounts commands

  • List accounts

    $ heroku accounts

Dump MySQL database from Production and Restore into a local Database in docker container

Reference

https://hub.docker.com/_/mysql/

  1. Dump using mysqlpump.
$ mysqlpump -h your.host.db.com -u user_name -p --skip-definer --set-gtid-purged=OFF  database_name > my_dump_file.sql

Dump and Restore postgres Database

1. Dump

In this gist we are going to use the pg_dump tool to back up a remote postgres database and pg_restore to restore the dump in a local database.

  1. If postgres is not installed directly in your machine because you are usign it via docker containers, first you should install the postgresql client utility in your host machine, this client includes psql and pg_dump tools.

  1. Delete all local branchs except master and develop
git branch | grep -v "master\|develop" | xargs git branch -D
  1. Delete local refs to deleted remote branchs.

    • Verify branchs