Skip to content

Instantly share code, notes, and snippets.

View martin056's full-sized avatar

Martin Angelov martin056

View GitHub Profile
@martin056
martin056 / handle_errors_article.md
Last active May 30, 2017 07:23
Handle errors from third-party apps in Django

Handle errors from third-party apps in Django

TL;DR - Here is a demo of what we are going to achieve. Once you have this basic implementation you can use it in many defferent ways - in a View, to send notifications, etc.

Before we start

Things you should be familiar with:

Introduction

In my previous article I promised you to show you how to properly unit test Celery tasks. Since I keep my promises every time, this is the target of the following article.

You had better be familiar with the mocking technique in the unit test practices before dive into the article. If you are not that sure in your knowledge - check this article.

Repetition is the key to success

I'm going to expand my previous article so you had better take a quick look at it. If you already read it you can take a look at its demo.

@martin056
martin056 / mock_everything.md
Last active July 17, 2017 11:32
Explaining the mock technique.

Introduction

Unit testing is essential part of our daily struggles as a programmer. Therefore, if we want to be better in our work we have to advance in this approach.

In the article we are going to look at the mock module of Python's unittest library. In the end you will end up with levelled up unit testing skills.

What is mocking?

This is actually a test technique that allows you to isolate parts of you code and unit test them. You can easily fake function calls in your tests wherever needed.

@martin056
martin056 / fake_it.md
Last active August 23, 2017 09:31
Improve your tests in Django with fakes and factories

TL;DR This article is targeted at programmers who have very little or no experience with fakers and factories. If you are already skilled in the topic this article may not be that interesting to you.

Introduction

In our Django apps we have the M(odel)T(emplate)V(iew) structure (mostly known as MVC). When we want to test its functionality we usually have to create some model instances and work with them and the database.

A nice and easy approach for doing so is to create fake data in our tests in the form of factories and fakers.

In the following article we are going to look over some practical examples and techniques. This will improve your tests readability and behavior.

@martin056
martin056 / first_webpack.md
Last active December 12, 2017 08:04
Recently we've started a new SPA project. In this gist I will explain the main struggles and knowledge I take during creating the webpack configuration.

Introduction

Recently we've started a new SPA (single-page application) project with Redux, React and React Router (v4).

Until now I've been working mainly on the backend part of apps so this was a new challenge. In this blog post I will share my knowledge with you.

TL;DR You can check this demo project that uses the Webpack configuration that we are going to achieve.

What is this article about?

@martin056
martin056 / split_webpack.md
Last active December 11, 2017 08:39
How to split your `webpack.config.js`

Introduction

In my previous article I promised you to write about how we split our webpack configurations for production and for development. This post is a continuation to the previous one and I will use the webpack.config.js file from there. You had better check it out if you haven't yet!

Why do we need to separate the webpack configuration?

Well, like the most things in programming you may want to use a different configuration for your production files and for development. If you think your webpack.config.js is good enough for both cases then this article is not for you.

If you are from the ones that want to have different configurations - like minifying your bundle file only for production and stuff like that - then let's dive in!

@martin056
martin056 / create_container.sh
Last active August 28, 2017 14:25
Bash script that generates containers for Redux apps. The directories it uses are not configurable at the moment - if you have user `create-react-app` it will work for you.
#!/bin/bash
# USAGE (cd utility/ first!): ./create_container.sh -n <CONTAINER_NAME> -a <ACTION_1> (-a <ACTION_2>...)
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
SRC_PATH=../src
CONTAINERS_PATH=${SRC_PATH}/containers
@martin056
martin056 / loginFlow.md
Last active February 1, 2018 16:00
Implementation of login flow using redux-saga.
function* authenticate(credentials) {
  try {
    const {data} = yield call(requestLogin, credentials);

    storeAuthToken(data.token);

    yield* [
      put(loginSuccess()),
      put(storeMe(data.me)),
@martin056
martin056 / deep_transform.py
Created May 28, 2018 18:12
Deep snake_case and camelCase transformations
import re
from typing import Dict, Callable, Optional
def to_camel_case(snake_case_str: str) -> str:
"""
Transforms snake_case to camelCase
"""
components = snake_case_str.split('_')
titled_components = ''.join(x.title() for x in components[1:])
@martin056
martin056 / drf_parsers_and_renderers.md
Last active November 28, 2019 09:27
How to deal with cases mismatch between Django and React

Introduction

As you may know from my other blog posts I am mainly working with Django and React at the moment. In this article we are going to take a look on how to solve one bothering problem - the cases mismatch.

The picture

  • We have working frontend that uses only React
  • We are migrating to full Single Page Application (SPA) now
  • We maintain the APIs of the app's mobile application