Skip to content

Instantly share code, notes, and snippets.

View marteinn's full-sized avatar
✖️
🥕

Martin Sandström marteinn

✖️
🥕
View GitHub Profile
@marteinn
marteinn / info.md
Created May 6, 2024 04:13
How to solve cache busting issue in django-tinymce 4.0

Having issues with the latest 4.0 version of django-tinymce where assets are not refreshed in the browser?

  1. Make sure you add a cache busting query param to tinymce.min.js
APP_VERSION = "1.0.0"
...
TINYMCE_JS_URL = f"/static/tinymce/tinymce.min.js?app_version={APP_VERSION}"
  1. Add cache suffix so any asset loaded by tinymce gets the same cache busting query.
@marteinn
marteinn / list-90.md
Last active April 18, 2024 13:43
Best albums of the 90:s (very opinionated)
  1. Mercury Rev - Deserter Songs
  2. Nick Cave - Let Love In
  3. Cocteau Twins - Heaven Or Las Vegas
  4. Pulp - This Is Hardcore
  5. This Mortal Coil - Blood
  6. Spiritualized - Ladies And Gentlemen We Are Floating In Space
  7. Tom Waits - The Black Rider
  8. Coil - Loves Secret Domain
  9. Smashing Pumpkins - Mellon Coolie & The Infinite Sadness
  10. Wilco - Summerteeth
@marteinn
marteinn / list-80.md
Last active April 18, 2024 13:38
Best albums of the 80:s (very opinionated)
  1. Tom Waits - Rain Dogs
  2. Tom Waits - Swordfishtrombones
  3. The The - Soul Mining
  4. Cocteau Twins - Treasure
  5. Talk Talk - Spirit Of Eden
  6. Ryuichi Sakamoto - Merry Christmas Mr.Lawrence
  7. This Heat - Deceit
  8. Waterboys - This Is The Sea
  9. Sonic Youth - Daydream Nation
  10. XTC - Skylarking
@marteinn
marteinn / solution-asdf-unrecognized-format.md
Created May 28, 2021 07:29
Solution for Unrecognized archive format in asdf

Are you getting the error "Unrecognized archive format" while trying to install php on asdf?

asdf install php 7.4                                                                                                                      develop ⬆ ✖ ✱ ◼
Determining configuration options...
Downloading source code...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   120  100   120    0     0    272      0 --:--:-- --:--:-- --:--:--   272
100    14  100    14    0     0     18      0 --:--:-- --:--:-- --:--:--    18
@marteinn
marteinn / info.md
Created February 13, 2024 13:31
How to add json field to django-constance

How to add a json field to django-constance

  1. Install django-jsonform

    pip install django-jsonform
  2. Add django-jsonform to installed apps

@marteinn
marteinn / info.md
Last active January 21, 2024 06:57
Using the Fetch Api with Django Rest Framework

Using the Fetch Api with Django Rest Framework

Server

First, make sure you use the SessionAuthentication in Django. Put this in your settings.py

# Django rest framework
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
 'rest_framework.authentication.SessionAuthentication'
@marteinn
marteinn / example.md
Last active December 5, 2023 21:16
Mocking gettext in unittest (django)

Mocking unittest translations in Django

This is a simple example on how you can mock gettext/translation in django.

from django.utils import translation

class MyTestCase(TestCase):
    def setUp(self):
 swe_trans = translation.trans_real.translation("sv-se")
@marteinn
marteinn / _document.js
Created September 26, 2020 06:27
Next.js: How to capture and use page props in next/document
import Document, { Html, Head, Main, NextScript } from 'next/document';
class CustomDocument extends Document {
static async getInitialProps(ctx) {
let pageProps = null;
const originalRenderPage = ctx.renderPage;
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) => {
@marteinn
marteinn / cookietractor-match.js
Created October 11, 2023 12:37
Match category in cookietractor cookie
var data = "%7B%22user%22:%22bfce3822-d2ce-4327-a813-00e616f4773b%22,%22consents" +
"%22:%5B%22undefined%22,%22necessary%22,%22statistical%22%5D,%22avail" +
"ableConsents%22:%5B%22undefined%22,%22necessary%22,%22marketing%22,%" +
"22statistical%22%5D,%22utc%22:1697017078669%7D"
////////////////////
// Match using regex
////////////////////
var altStatistical1 = /%22consents%22:.*statistical.*%22availableConsents%22/
var altStatistical2 = /\%22consents\%22:.*statistical.*\%22availableConsents\%22/
@marteinn
marteinn / middleware.py
Created July 5, 2023 03:29
Generate a LogEntry every time a user is inspecting a object in the django admin.
import json
import re
from datetime import timedelta
from django.contrib.admin.models import ADDITION, LogEntry
from django.contrib.contenttypes.models import ContentType
from django.utils import timezone
admin_change_path_match = r"^admin:([a-z_]*)_([a-z]*)_change$"