Skip to content

Instantly share code, notes, and snippets.

@GaretJax
GaretJax / monkeypatch.py
Last active January 22, 2020 10:07
Django-CMS fix-tree optimization
from cms.models import CMSPlugin
from cms.utils.plugins import reorder_plugins
from django.db import connection, transaction
from django.db.models import Count, F
from treebeard.mp_tree import sql_length
def new_fix_tree():
print("RUNNING PATCHED CMSPLUGIN FIX TREE")
vendor = CMSPlugin.get_database_vendor('write')
@GaretJax
GaretJax / super.py
Created February 22, 2019 12:01
Automatically cleanup super calls for python3
import pathlib
import ast
import sys
import asttokens
import black
def walk(parent):
for path in parent.iterdir():
@GaretJax
GaretJax / on_delete.py
Last active February 25, 2019 10:00
Automatically add on_delete=models.CASCADE to source code where needed (mandatory in django 2.0)
import pathlib
import ast
import inspect
import asttokens
import black
def ForeignKey(
to,
form django.shortcuts import redirect
def redirect_job_details(request):
full_path = request.get_full_path()
if full_path.startswith('/en'):
full_path = full_path[3:]
return redirect('/jobs' + full_path)
@GaretJax
GaretJax / build.log
Last active May 10, 2017 22:13
emerging ftgl fails
$ cat /var/tmp/portage/media-libs/ftgl-2.1.3_rc5/temp/build.log
* Package: media-libs/ftgl-2.1.3_rc5
* Repository: gentoo
* Maintainer: games@gentoo.org
* USE: abi_x86_64 amd64 elibc_glibc kernel_linux userland_GNU
* FEATURES: preserve-libs sandbox userpriv usersandbox
>>> Unpacking source...
>>> Unpacking ftgl-2.1.3-rc5.tar.bz2 to /var/tmp/portage/media-libs/ftgl-2.1.3_rc5/work
>>> Source unpacked in /var/tmp/portage/media-libs/ftgl-2.1.3_rc5/work
#!/usr/bin/env python
# copied from
# https://raw.githubusercontent.com/mitsuhiko/pipsi/ad72771136c885b9bdaa965df454f19a9415da26/get-pipsi.py
# Altered to use install from github instead of latest from pip.
# We can switch to using the stock get-pipsi.py when there is a new release:
# https://github.com/mitsuhiko/pipsi/issues/36
import os
import sys
@GaretJax
GaretJax / decrypt.py
Last active September 15, 2021 08:05
Genetic algorithm to decrypt substitution ciphers
from __future__ import print_function
import collections
import re
import random
##############################################################################
# Program parameters
# Path to the text file containing the ciphertext
@GaretJax
GaretJax / 5.0.1.txt
Last active April 4, 2016 13:03
PyPy crash
RPython traceback:
File "rpython_jit_metainterp_7.c", line 33594, in MIFrame_run_one_step
File "rpython_jit_metainterp_9.c", line 35383, in handler_residual_call_ir_i_1
File "rpython_jit_metainterp_11.c", line 29636, in MIFrame_do_residual_call
File "rpython_jit_metainterp_12.c", line 36220, in MetaInterp_vrefs_after_residual_call
File "rpython_jit_metainterp_14.c", line 3071, in MetaInterp_stop_tracking_virtualref
Fatal RPython error: AssertionError
from OpenSSL import SSL as ssl
from zope.interface import implementer
from twisted.protocols.tls import TLSMemoryBIOFactory, TLSMemoryBIOProtocol
from twisted.internet import defer
from twisted.internet.ssl import CertificateOptions
from twisted.internet.interfaces import IOpenSSLServerConnectionCreator
from twisted.logger import Logger
reactor.listenSSL(
port=443,
factory=server_factory,
contextFactory=SNICallbackSSLFactory(RedisCertsStore()),
)