Skip to content

Instantly share code, notes, and snippets.

@softzer0
softzer0 / rename_app.sql
Created November 7, 2024 05:40
Rename Django app in PostgreSQL DB
DO $$
DECLARE
source_app text := 'old_app_name';
target_app text := 'new_app_name';
BEGIN
EXECUTE format('UPDATE django_migrations SET app = %L WHERE app = %L', target_app, source_app);
EXECUTE (
SELECT string_agg(
'ALTER TABLE ' || tablename || ' RENAME TO ' || replace(tablename, source_app, target_app),
@softzer0
softzer0 / import_trello_data.py
Created September 10, 2024 00:38
Import from Trello JSON export to self-hosted Plane
# To path: plane/db/management/commands
# Example: python manage.py import_trello_data path/to/data.json 111ae9b3-cefc-4c25-adf2-48c0932d40e0
import random
import json
import requests
from django.core.management.base import BaseCommand
from django.core.files.base import ContentFile
from django.db import transaction
from plane.db.models import (
@softzer0
softzer0 / git_replace_author.sh
Created February 5, 2024 15:30
Replace committer/author name and email with one in the whole Git branch
#!/bin/sh
git filter-branch -f --env-filter '
CORRECT_NAME="YourUsername"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_NAME" != "$CORRECT_NAME" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
@softzer0
softzer0 / redact_secrets_from_repo.py
Last active February 5, 2024 15:32
Redact all secrets from the repository using GItleaks and BFG Repo-Cleaner. Just pass a path of the repository directory to the script. USE WITH CAUTION!
import json
import subprocess
import sys
def parse_gitleaks_report(report_path, secrets_path):
with open(report_path, 'r') as file:
data = json.load(file)
with open(secrets_path, 'w') as file:
for item in data:
from functools import partial
import os
import time
import multiprocessing
def _func_with_args(func, args):
return func(*args)
@softzer0
softzer0 / flask_crud_extension.py
Last active May 15, 2023 23:33
Flask CRUD extension (with SQLAlchemy, marshmallow, Flask-JWT-Extended)
import datetime
from inspect import signature
from flask import request, jsonify, make_response, Blueprint, current_app
from flask.views import MethodView
from flask_jwt_extended import current_user, jwt_required
from marshmallow import Schema, fields
from sqlalchemy import inspect as sqla_inspect, or_, String, Integer, Float, Boolean, DateTime, Date
from sqlalchemy.orm.exc import StaleDataError
@softzer0
softzer0 / gen_po_angular.py
Last active February 21, 2020 13:40
.PO synchronizer (with serializer/deserializer) + Bulk AngularJS template .PO generator (with filter and directive based on Django JS translator)
#!/usr/bin/python3
# Note: This script has to be in the same directory with sync_po.py (.PO synchronizer).
"""
Made for combining Django's JavaScript Catalog (translation) implementation with AngularJS templates.
Code (AngularJS):
-----------------
.filter('translate', function() {