Ask Better Questions to Build Better Connections | Amber L. Wright | TEDxCSULB

April 14, 2024 Leave a comment

Asking better questions isn’t simply another way to make small talk. Instead, it’s a path to creating real connection with the people around you, in a thoughtful and genuine way. This talk by communication expert and certified life coach, Amber L. Wright, explores how to ask better questions and invest in one of life’s greatest currencies: relationships. Amber L. Wright, CSULB Alumna, is a communication expert, certified life coach, and speaker who helps people find their voice during moments that matter. An award-winning educator, she holds a master’s degree in Interpersonal Communication. Well versed in the power of storytelling, she is known for giving dynamics presentations on how to communicate effectively and live authentically.

Amber has shared her expertise on what it means to speak, live, and lead with confidence in notable media outlets such as Forbes, Mashable, Fast Company, and Black Enterprise. She is the host of the Talk to Amber Podcast and author of, “Can We Talk? 10 Life Lessons on Finding Your Voice and Finding Yourself,” a wildly popular personal development book. She is a married mom of two, proud lefty, and a card-carrying member of Beyonce’s BeyHive. This talk was given at a TEDx event using the TED conference format but independently organized by a local community. Learn more at https://www.ted.com/tedx

Categories: Interesting

Using the git stash command

March 29, 2024 Leave a comment

Notes:

$ git stash # to create/save changes
$ git stash save <description> # to specify the name of the stash
$ git stash list # to view a list of the current stashes that exist
$ git stash pop <stash_id> # apply the saved changes and remove changes
                           # from stash
$ git stash apply <stash_id> # apply the saved changes but keep changes on
                             # the stash
$ git stash clear # empty the stash list by removing all the stashes
$ git stash drop <stash_id> # deletes a particular stash from the stash list
$ git stash show <stash_id> # view the diff of a stash
$ git stash branch <new_branch_name> <stash_id> # create a new branch
                              # based on the commit the stash was created
                              # from and pop the stashed changes to it

Source:
https://opensource.com/article/21/4/git-stash

Categories: git Tags:

Best practices to protect your Flask applications

January 11, 2024 Leave a comment

How to secure your Flask applications

Want to know how to protect your Flask applications? Dive into our latest blog post, where we guide you through the best practices for Flask security. Explore how these techniques can not only enhance the security of your web applications but also bring tangible benefits to your development journey.

In this guide, Escape’s security research team has gathered the most crucial tips to protect your Flask applications from potential breaches, including how to implement CSRF protection for Flask. Our goal is to empower you to create more resilient and efficient Flask projects. Let’s get started!

https://escape.tech/blog/best-practices-protect-flask-applications/

Categories: flask Tags:

ImportError: attempted relative import with no known parent package

November 26, 2023 Leave a comment

Problem:
I was getting the following errors
ImportError: attempted relative import with no known parent package and ModuleNotFoundError: No module named 'mymodule'

Solution:
This stackoverflow answer helped clear up my confusion.

As answered by sfy on here

TL;DR

You can only relatively import modules inside another module in the same package.

Concept Clarify

We see a lot of example code in books/docs/articles, they show us how to relatively import a module, but when we do so, it fails.

The reason is, put it in a simple sentence, we did not run the code as the python module mechanism expects, even though the code is written totally right. It’s like some kind of runtime thing.

Module loading is depended on how you run the code. That is the source of confusion.

What is a module?
A module is a python file when and only when it is being imported by another file. Given a file mod.py, is it a module? Yes and No, if you run python mod.py, it is not a module, because it is not imported.

What is a package?

A package is a folder that includes Python module(s).

BTW, __init__.py is not necessary from python 3.3, if you don’t need any package initialization or auto-load submodules. You don’t need to place a blank __init__.py in a directory.

That proves a package is just a folder as long as there are files being imported.

Real Answer

Now, this description becomes clearer.

You can only relatively import modules inside another module in the same package.

Given a directory:

. CWD
|-- happy_maker.py # content: print('Sends Happy')
`-- me.py # content: from . import happy_maker

Run python me.py, we got attempted relative import with no known parent package

me.py is run directly, it is not a module, and we can’t use relative import in it.

Solution 1

Use import happy_maker instead of from . import happy_maker

Solution 2

Switch our working directory to the parent folder.

. CWD
|-- happy
| |-- happy_maker.py
`-- me.py

Run python -m happy.me.

When we are in the directory that includes happy, happy is a package, me.py, happy_maker.py are modules, we can use relative import now, and we still want to run me.py, so we use -m which means run the module as a script.

Python Idiom

. CWD
|-- happy
| |-- happy_maker.py # content: print('Sends Happy')
| `-- me.py # content: from . import happy_maker
`-- main.py # content: import happy.me

This structure is the python idiom. main is our script, best practice in Python. Finally, we got there.

Siblings or Grandparents

Another common need:

.
|-- happy
| |-- happy_maker.py
| `-- me.py
`-- sad
`-- sad_maker.py

We want to import sad_maker in me.py, How to do that?

First, we need to make happy and sad in the same package, so we have to go up a directory level. And then from ..sad import sad_maker in the me.py.

That is all.

Source:
https://stackoverflow.com/questions/16981921/relative-imports-in-python-3

Categories: python Tags: ,

React Error Handling And Reporting With Error Boundary And Sentry

November 18, 2023 Leave a comment

In this article, we’ll look at error boundaries in React. We’ll learn what they are and how to use them to deliver a better user experience, even when something breaks in our app. We’ll also learn how to integrate with Sentry for realtime error monitoring.

Source:
https://www.smashingmagazine.com/2020/06/react-error-handling-reporting-error-boundary-sentry

Set up semantic-release to work with bitbucket git

October 23, 2023 Leave a comment

Problem:
Setting up semantic-release to work with bitbucket.

Solution:
Followed the steps in https://medium.com/coding-spaghetti/npm-version-control-using-semantic-release-and-bitbucket-cloud-5294ac6b324b to set up semantic-release.

Install the relevant packages

$ npm install --save-dev semantic-release
$ npm install --save-dev @semantic-release/git @semantic-release/npm
$ less package.json
...
"devDependencies": {
    "@babel/plugin-proposal-private-property-in-object": "^7.21.0",
    "@commitlint/cli": "^17.8.0",
    "@commitlint/config-conventional": "^17.8.0",
    "@semantic-release/git": "^10.0.1",
    "@semantic-release/npm": "^11.0.0",
    "commitlint": "^17.8.0",
    "husky": "^8.0.0",
    "semantic-release": "^22.0.5"
  },
  "release": {
    "repositoryUrl": "https://auth@bitbucket.org/<BITBUCKET_REPO_OWNER>/<BITBUCKET_REPO_SLUG>.git",
    "branches": [
      "main"
    ],
    "plugins": [
      "@semantic-release/commit-analyzer",
      "@semantic-release/npm",
      [
        "@semantic-release/git",
        {
          "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
        }
      ]
    ]
  }
...

note: you need to change and to match your project repo. (If you try and clone your repository, the last two sections of your path make up the repo owner and the repo slug.)

Ex: git clone https://username@bitbucket.org/blahblah/sampleproject.git

the BITBUCKET_REPO_OWNER is blahblah and BITBUCKET_REPO_SLUG is sampleproject

Note:
Bitbucket Personal Access Tokens. Documentation below is for Atlassian’s self-hosted source control tool Bitbucket Server instead of Bitbucket Cloud.
https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html
See https://stackoverflow.com/a/70415364

For Bitbucket Cloud I created an “App Password”
Settings > Personal Bitbucket settings > Access Management > App passwords > Create app password
Under Permissions, Repositories select Write permission

Save the created token. Replace with created token.

export BITBUCKET_TOKEN_BASIC_AUTH=<bitbucket-username>:<token>

Test the settings

$ npx semantic-release --no-ci --dry-run

To start at version v0.1.0
git tag the initial commit. git log to get the commit checksum.

$ git tag -a v0.1.0 -m "v0.1.0" <commit checksum (or part of it)>

Added a post-merge git hook

$ less .git/hooks/post-merge

#!/bin/bash

CURRENT_DIR=$(pwd)
PROJECT_NAME="proj-name"
PROJECT_DIR="lib/proj"

if [[ "${HOME}/${PROJECT_NAME}/${PROJECT_DIR}" == ${CURRENT_DIR}  ]]
then 
    npx semantic-release --no-ci
elif [[ "${HOME}/${PROJECT_NAME}" == ${CURRENT_DIR} ]]
then
    cd ${PROJECT_DIR}
    npx semantic-release --no-ci
    cd -
fi

Source:
Configuration settings for semantic-release
* https://semantic-release.gitbook.io/semantic-release/usage/ci-configuration
* https://medium.com/coding-spaghetti/npm-version-control-using-semantic-release-and-bitbucket-cloud-5294ac6b324b
* https://github.com/semantic-release/git/issues/323

lintian error: source-is-missing

October 13, 2023 Leave a comment

Problem:

I was getting this lintian error for a debian package I was building for a reactjs application.
E: source: source-is-missing build/static/js/787.848931c7.chunk.js
E: source: source-is-missing build/static/js/main.dc45282d.js

Solution

Things I tried to “handle” the lintian error.

  • I added the missing files to /missing-sources folder.
  • Now the error reads

    E: source: source-is-missing debian/missing-sources/787.848931c7.chunk.js
    E: source: source-is-missing debian/missing-sources/main.dc45282d.js

    I was lost as to why lintian was now reporting this. As per this https://sources.debian.org/src/lintian/2.104.0/mail-templates/source-is-missing/

    In order to solve this problem, you could:
    1. add the source files to “debian/missing-sources” directory.
    2. repack the origin tarball and add the missing source files to it.

    Both ways satisfy the requirement to ship all source code. The second option
    might be preferable due to the following reasons [2]:
    – Upstream can do it too and you could even supply a patch to them, thus
    fulfilling our social contract [3], see particularly §2.
    – If source and non-source are in different locations, ftpmasters may
    miss the source and (needlessly) reject the package.
    – The source isn’t duplicated in every .diff.gz/.debian.tar.* (though
    this only really matters for larger sources).

    the relevant file were in debian/missing-sources as well as my package.tar file. So I was left with no option but to ignore the error.

  • I then opted to keep the files in missing-sources folder but ignore the debian/missing-sources error above by adding it to debian/.lintian-overrides, but the lintian error persisted.
  • $ less <package-name>.lintian-overrides
    
    <package-name>: initial-upload-closes-no-bugs
    <package-name>: source-is-missing debian/missing-sources/787.848931c7.chunk.js
    <package-name>: source-is-missing debian/missing-sources/main.dc45282d.js
    

    There was no change in the error. The override provided was not matching the error.

  • I then tried to override the source-is-missing errors by adding them to debian/source/lintian-overrides. This worked.
  • $ less debian/source/lintian-overrides
    
    <package-name> source: source-is-missing debian/missing-sources/787.848931c7.chunk.js
    <package-name> source: source-is-missing debian/missing-sources/main.dc45282d.js
    

    In Summary

    1. Add the files to debian/missing-sources
    2. Keep .lintian-overrides
    3. Use debian/sources/lintias-overrides to ignore/match source errors.

    Extra

    Trying to add the js files in debian/source folder just resulted in more lintian errors

    E: <package-name> source: unknown-file-in-debian-source 787.848931c7.chunk.js
    E: <package-name> source: unknown-file-in-debian-source main.dc45282d.js
    
    Categories: debian Tags: , ,

    The 11 Types Of Toxic Pull Requests (According To 4.5 Million Code Branches)

    September 7, 2023 Leave a comment

    In the world of software delivery, pull requests are at the heart of collaboration between many engineering teams. Yet, while PRs are pivotal for ensuring code quality and fostering collective input, they’ve also become the leading bottleneck in developer workflows.

    Poorly crafted or mismanaged pull requests can spell disaster for productivity. LinearB’s Engineering Metrics Benchmarks study analyzed the work of 2,000 dev teams and 4.5 million code branches, and found:

    • The average cycle time for a piece of work (first commit to deployment) is 7 days.
    • Half of all PRs are idle (e.g., no one is actively working on them) for at least 50% of their lifespan.
    • Cycle time and idle time doubled for pull requests of 200 lines of code compared to pull requests with 100 lines of code.

    Having pinpointed this significant dip in developer productivity, researchers have uncovered the root of these subpar performance indicators.

    Based on qualitative and quantitative analyses, developers and data scientists have identified four primary issues in PR management and 11 common types of pull requests that are particularly detrimental to workflow efficiency.

    The 4 Root Problems in Engineering Workflows

    1. Many organizations have no formal process for getting pull requests (PR) assigned.
    2. No standardization or best-practice guidance for PR size.
    3. Teams treat all PRs with equal importance despite their different risk levels.
    4. Lack of visibility into PR context or how long it will take to review (until it’s opened).

    With the root problems of poor PRs identified, engineers could now work on solutions to this massive hurdle in developer workflows. One of the most promising of these fixes has come in the form of Continuous Merge – the practice of automating the classification of pull requests in order to optimize the path to merge.

    https://devinterrupted.substack.com/p/the-11-types-of-toxic-pull-requests

    Categories: Interesting Tags:

    Restrict IP pool of docker0 virtual bridge interface

    June 28, 2023 Leave a comment

    Docker runs a daemon that manages the containers. This daemon creates an interface docker0 which is by default configured to use the 172.17.0.1/16 subnet for its operations. So, we need to configure the daemon to use the desired subnet.

    dockerd is used to run the docker daemon. It has –bip bridge IP option (see dockerd[1]).

    dockerd –bid=172.20.0.1/20
    But most systems run docker using respective service managers to accomplish this. In such cases docker has a docker daemon configuration file at /etc/docker/daemon.json. Docker linux daemon configuration[2] So create daemon.json if it doesn’t already exist and add bip.

    {
    “bip”:”172.30.0.1/20″
    }

    Source:
    https://stackoverflow.com/questions/42281996/change-ip-address-pool-of-docker-bridge

    [1] https://docs.docker.com/network/drivers/bridge/
    [2] https://docs.docker.com/engine/reference/commandline/dockerd/#/linux-configuration-file

    Categories: Interesting Tags:

    How to make flask-sqlalchemy automatically rollback the session if an exception is raised in Python?

    June 23, 2023 Leave a comment

    When working with a database in a Flask application using Flask-SQLAlchemy, it is important to ensure that any changes made to the database are properly managed, even in the event of an exception. One way to handle exceptions is to roll back the current session, effectively undoing any changes made to the database. This can be accomplished in a number of ways, depending on the specific requirements of your application. Here are some methods for making Flask-SQLAlchemy automatically roll back the session in the event of an exception:

    https://stacktuts.com/how-to-make-flask-sqlalchemy-automatically-rollback-the-session-if-an-exception-is-raised-in-python