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 / sign-in-with-apple.md
Created October 8, 2019 14:58
Sign In with Apple using Django (Python) Backend

Implementing Sign In with Apple in your Django (Python) backend

Apple announced a new feature, "Sign In with Apple" enabling users to sign in to apps using their Apple ID. This new feature is meant to be a secure and privacy-friendly way for users to create an account in apps. Most iOS and Mac users already have an Apple ID, and this new feature lets them use that Apple ID to sign in to other apps and websites.

Apple is taking a firm stance to protect user's privacy, rather than letting applications see the user's real email address, they will provide the app with a fake or random email address unique to each app. Don't you worry! Developers will still be able to send emails to these proxy addresses, it just means developers won't be able to use the email addresses in any other way. This feature will also allow users to disable email forwarding per application.

How it works

Apple adopted the existing standards OAuth 2.0 and OpenID Connect to use as the foundation for their new API. If you're familiar

@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 / 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 / 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 / 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 / apple.py
Last active October 8, 2019 14:29
Apple Custom Backend for Python Social Auth
import jwt
import requests
from datetime import timedelta
from django.conf import settings
from django.utils import timezone
from social_core.backends.oauth import BaseOAuth2
from social_core.utils import handle_http_errors
class AppleOAuth2(BaseOAuth2):
import jwt
headers = {
'kid': settings.SOCIAL_AUTH_APPLE_KEY_ID
}
payload = {
'iss': settings.SOCIAL_AUTH_APPLE_TEAM_ID,
'iat': timezone.now(),
'exp': timezone.now() + timedelta(days=180),
@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 / nfs-vagrant-error.md
Created March 1, 2018 14:51 — forked from ikennaokpala/nfs-vagrant-error.md
Vagrant error :NFS is reporting that your exports file is invalid

Vagrant error :NFS is reporting that your exports file is invalid

==> default: Exporting NFS shared folders...
NFS is reporting that your exports file is invalid. Vagrant does
this check before making any changes to the file. Please correct
the issues below and execute "vagrant reload":

exports:2: path contains non-directory or non-existent components: /Users/<username>/path/to/vagrant
exports:2: no usable directories in export entry
exports:2: using fallback (marked offline): /
@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.