How is JavaScript library bloat mitigated with Web Components?

This is an issue that’s been bothering me as well for a while, esp when faced with maintaining code that’s been touched by numerous developers. You often encounter multiple JS libraries (some of which essentially does the same thing) included in one solution, not to mention even different versions of the same framework used in … Read more

Stairway pattern implementation

Application entry points should be the composition root, as per Mark Seemann’s excellent book on Dependency Injection. Here, the issue is more about Dependency Inversion, whereby both client and implementation should both depend on abstractions. What that diagram doesn’t show, but hopefully other parts of the book make clear, is that the entry point will … Read more

How do you use python-decouple to load a .env file outside the expected paths?

I figured it out. Instead of importing decouple.config and doing the usual config(‘FOOBAR’), create a new decouple.Config object using RepositoryEnv(‘/path/to/env-file’). from decouple import Config, RepositoryEnv DOTENV_FILE = ‘/opt/envs/my-project/.env’ env_config = Config(RepositoryEnv(DOTENV_FILE)) # use the Config().get() method as you normally would since # decouple.config uses that internally. # i.e. config(‘SECRET_KEY’) = env_config.get(‘SECRET_KEY’) SECRET_KEY = env_config.get(‘SECRET_KEY’) Hopefully … Read more

Functional programming and decoupling

I struggled with this question for years before I realised that I was looking at it the wrong way. Coming from object-oriented development and Dependency Injection, I kept looking for a functional alternative to Dependency Injection. I finally realised that Dependency Injection makes everything impure, which means that you can’t use that approach (not even … Read more

Managing resources in a Python project

You may want to use pkg_resources library that comes with setuptools. For example, I’ve made up a quick little package “proj” to illustrate the resource organization scheme I’d use: proj/setup.py proj/proj/__init__.py proj/proj/code.py proj/proj/resources/__init__.py proj/proj/resources/images/__init__.py proj/proj/resources/images/pic1.png proj/proj/resources/images/pic2.png Notice how I keep all resources in a separate subpackage. “code.py” shows how pkg_resources is used to refer to … Read more

Difference between “Inversion of Control”, “Dependency inversion” and “Decoupling”

Decoupling is a very general principle applicable in many fields. Dependency inversion is a specific form of decoupling where you decouple the higher levels of your system from the lower levels by separating them into libraries and using interfaces. This allows you to replace lower level parts of your system without major rework. For example, … Read more

When should I use jQuery deferred’s “then” method and when should I use the “pipe” method?

Since jQuery 1.8 .then behaves the same as .pipe: Deprecation Notice: As of jQuery 1.8, the deferred.pipe() method is deprecated. The deferred.then() method, which replaces it, should be used instead. and As of jQuery 1.8, the deferred.then() method returns a new promise that can filter the status and values of a deferred through a function, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)