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 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 / 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 / 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$"
@marteinn
marteinn / test.js
Created January 30, 2023 13:59
Read local file from jpg, pass to gotenberg libreoffice and then download result as pdf
const fs = require('fs/promises');
const { createWriteStream } = require("fs");
const util = require('util');
const stream = require('stream');
const got = require('got'); // third party
const FormData = require('form-data'); // third party
const pipeline = util.promisify(stream.pipeline);
const main = async () => {
@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

How to use AnyConnect with the keychain on MacOS

1. Store VPN details in keychain

  • Open Keychain Access
  • Navigate to "Login" in the left menu
  • Cmd+N (New Password item)
  • Fill in these details:
    • Keychain Item Name: anyconnect
    • Account name: Your username (firstname.lastname)
    • Password
@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 / _app.js
Created March 5, 2021 06:18
How to add IE11 css variables polyfill in Next.js
// Polyfills
if (typeof window !== 'undefined') {
require("ie11-custom-properties");
}
function MyApp({ Component, pageProps, err }) {
return <Component {...pageProps} err={err} />;
}
export default MyApp;
@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) => {