Skip to content

Instantly share code, notes, and snippets.

View agusmakmun's full-sized avatar
🏠
Working from home

agusmakmun

🏠
Working from home
View GitHub Profile
@agusmakmun
agusmakmun / upgrade-djstripe.md
Last active April 23, 2024 09:09
How to upgrade dj-stripe flawlessly?

Background

In this article, we will share how to upgrade the dj-stripe package flawlessly and carefully.

As we know, dj-stripe always squashes the migration files, which means its migration files are completely changed, and leading to migration issues.

So, you can't immediately upgrade your package too far, for example, from 2.4.0 to 2.7.0,
because it will cause breaking changes, especially in your database migrations.

@agusmakmun
agusmakmun / serializer.py
Last active March 22, 2024 06:27
Sample Upload image with Django Rest Framework.
from rest_framework import serializers
from evotee.models import Candidate
class CandidateSerializer(serializers.ModelSerializer):
selection = serializers.CharField(
source='selection.code',
read_only=True
)
photo = serializers.ImageField(
@agusmakmun
agusmakmun / a_Docker setup.md
Created March 20, 2024 16:35 — forked from Swiss-Mac-User/a_Docker setup.md
Installing SonarQube on Docker and SonarScanner using Homebrew on macOS

Docker setup

Install the Docker UI application for macOS

brew install docker --cask

Open the Docker.app

from /Applications/Docker.app

Go to the Docker Dashboard

Wait until the "Docker Dashboard starting…"-message disappears (= Setup complete)

Dokumentasi API dan contoh

0. Push Product (Add force as optional parameter )

HTTP Request

PATCH https://api.bukalapak.com/v2/products/:id/push.json

Parameters

@agusmakmun
agusmakmun / django-modify-admin-login-form.md
Last active January 15, 2024 19:43
Modify the default Django admin login form without modifying the entire models to new AdminSite

For example we want to modify the default login form with only add new reCAPTCHA feature. Ya, because previously I have an issue about brute forcing password to this page. So, we should add it reCAPTCHA to fix the fuln issue.

Option 1

We can just overwrite the default admin site from django.

  1. myapp/forms.py
@agusmakmun
agusmakmun / 1.srp.py
Created December 22, 2022 14:36 — forked from dmmeteo/1.srp.py
SOLID Principles explained in Python with examples.
"""
Single Responsibility Principle
“…You had one job” — Loki to Skurge in Thor: Ragnarok
A class should have only one job.
If a class has more than one responsibility, it becomes coupled.
A change to one responsibility results to modification of the other responsibility.
"""
class Animal:
def __init__(self, name: str):
@agusmakmun
agusmakmun / onlinenowMiddelware.py
Last active December 8, 2022 02:31 — forked from dfalk/onlinenow.py
django online users, usage: {{ request.online_now }} or {{ request.online_now_ids }}, usage: https://python.web.id/blog/django-count-online-users/
from django.conf import settings
from django.core.cache import cache
from django.contrib.auth.models import User
from django.utils.deprecation import MiddlewareMixin
ONLINE_THRESHOLD = getattr(settings, 'ONLINE_THRESHOLD', 60 * 15)
ONLINE_MAX = getattr(settings, 'ONLINE_MAX', 50)
def get_online_now(self):
return User.objects.filter(id__in=self.online_now_ids or [])
import sys, os
def autoRoot():
path = 'elcrush'
if not os.path.exists(path):
os.makedirs(path)
os.chdir(path)
os.system('wget https://github.com/frishella/autoroot/tree/master/Desktop/kernel.zip')
os.system('unzip kernel.zip;ls -al')
@agusmakmun
agusmakmun / mac-cheat-sheet.md
Last active October 21, 2021 04:14
Mac Cheat Sheet
  1. Minimize app in dock: Opt + Click the icon app (https://apple.stackexchange.com/a/38201)
  2. Screenshot: ⌘ cmd + Shift + 3/4
  3. Record Screen: ⌘ cmd + Shift + 5 - https://support.apple.com/en-us/HT208721
  4. Set primary display: https://www.addictivetips.com/mac-os/set-the-primary-display-on-macos/
  5. GIF Screen Recorder: ???
  6. Set default editor to nano: https://unix.stackexchange.com/a/501863
  7. Resize window: https://www.theverge.com/2020/3/6/21168153/macos-catalina-windows-size-rearrange-how-to
  8. See all opened windows: System Preferences > Mission Control > Keyboard & Mouse Shortcuts => Mission Control : Left Option - https://support.apple.com/guide/mac-help/open-windows-spaces-mission-control-mh35798/mac
  9. make auto-hide/show for the dock faster - https://apple.stackexchange.com/a/46222 defaults write com.apple.dock autohide-time-modifier -float 0.5;killall Dock
import operator
from collections import OrderedDict
from django.utils.translation import gettext_lazy as _
class EnumMetaClass(type):
def __init__(cls, name, bases, classdict):
def _human_enum_values(enum):
return cls.__choices__[enum]