Skip to content

Instantly share code, notes, and snippets.

View aamishbaloch's full-sized avatar
🎯
Focusing

Aamish Baloch aamishbaloch

🎯
Focusing
  • HelloFresh
  • Berlin, Germany.
View GitHub Profile
@aamishbaloch
aamishbaloch / remove_server_details.md
Last active February 13, 2024 14:18
Remove Server Details from Response Header - Nginx

Remove Server Details from Response Header - Nginx

Below mentioned method is used to hide or remove the NGIX details from the header of your http requests.

Install Nginx Extras

sudo apt-get update
sudo apt-get install nginx-extras

Remove Server Details

@aamishbaloch
aamishbaloch / squash_commits_to_one.md
Last active September 18, 2017 15:19
Squash & Merge your Commits for Pull Requests

Squash & Merge your Commits for Pull Requests

The method mentioned below only allows you to squash the last X consecutive commits into a single commit. Also, if you have merged master into your branch along the way, you will have to manually merge your new (squashed) commit into master and resolve the merge conflicts.

Combining the commits (Method 1)

To squash the last 3 commits into one:

git reset --soft HEAD~3
git commit -m "New message for the combined commit"
@aamishbaloch
aamishbaloch / getting_code_from_remote.md
Created July 24, 2017 07:05
Getting the code as it is from the remote

Getting the code as it is from the remote

Ideal way to do this is to not use pull at all, but instead fetch and reset. You can see in the example below:

git fetch origin master
git reset --hard FETCH_HEAD
git clean -df
@aamishbaloch
aamishbaloch / accepting_boolean_value.md
Last active August 2, 2017 18:00
Accepting Boolean Value in Params in Django (Python)

Accepting Boolean Value in Params in Django (Python)

There are cases in which we have to receive a boolean value in params to fill up an object. I have came through an idea of doing this, following utility method will help you doing this:

def str2bool(value):
    """
    convert string to bool
    """
    if value:
        return value.lower() in ("true",)
 else:
@aamishbaloch
aamishbaloch / manual_deployment.md
Last active November 4, 2019 20:17
Manual Deployment of Django Application

Manual Deployment of Django Application

Deployment of Django application to ubuntu based server. We'll be using Nginx & WSGI to run the application. PostgresSQL will be used as the database in this example.

Pem File

You have to download pem file from the console to ssh into the server.

ssh -i key.pem ubuntu@(ip-address)

Clone the Repository

@aamishbaloch
aamishbaloch / run_management_task_programmatically.md
Created August 17, 2017 20:46
Execute Management Command Programmatically

Execute Management Command Programmatically

Sometimes you have to run the management commands in some tasks or other sort of programmatical features. So you can do this very easily.

How to run?

You can run this programmatically as follows:

from django.core.management import call_command
call_command('{command name}', interactive=True/False)
@aamishbaloch
aamishbaloch / load_testing.md
Created September 22, 2017 14:05
Load Testing a Django Application using LocustIO

Load Testing a Django Application using LocustIO

Django framework, used for buliding web applications quickly in a clean and efficient manner. As the size of application increases, a common issue faced by all teams is performance of the application. Measuring performance and analysis the areas of improvement is key to deliver a quality product.

LocustIO, an open source tool written in python, is used for load testing of web applications. It is simple and easy to use with web UI to view the test results. It is scalable and can be distributed over multiple machines.

This article demonstrates an example to use locust for load testing of our django web application.

Before starting load testing, we have to decide the pages which we want to test. In our case, we expect users to follow the scenario where they log in, visit different pages and submit CSRF protected forms.

@aamishbaloch
aamishbaloch / create_request_object.md
Created September 26, 2017 12:11
Creating http request object a setting Params in Django

Creating http request object a setting Params in Django

Whenever we have to call an external link(URL) and get any sort of data from that, we might came across the need to create a http request object and setting up some params for that. So following is the example for doing that in Django.

from django.http import HttpRequest

request = HttpRequest()

request.method = 'GET'
@aamishbaloch
aamishbaloch / redirect_url_in_template_view.md
Created October 31, 2017 13:06
Redirect to another URL in Django Template View

Redirect to another URL in Django Template View

Sometime we might came across the need to redirect to another url from django template. Like if you want to check if user is authenticated or not. So following is the example for doing that in Django.

def dispatch(self, request, *args, **kwargs):
    if not request.user.is_authenticated():
        return redirect('login')

 return super(MyTemplateView, self).dispatch(request, *args, **kwargs)
@aamishbaloch
aamishbaloch / undo-last-commit.md
Created January 1, 2018 15:12
Undo Last Commit

Undo Last Commit

Sometime we might came across the situation where we have to undo the last commit.

So for the soft undo:

git reset --soft HEAD~1

If you don't want to keep these changes, simply use the --hard flag. Be sure to only do this when you're sure you don't need these changes anymore.