Skip to content

Instantly share code, notes, and snippets.

Avatar
👽
Writing code from another galaxy.

Douglas Miranda douglasmiranda

👽
Writing code from another galaxy.
View GitHub Profile
@douglasmiranda
douglasmiranda / admin.py
Created Jan 12, 2021
Django Admin Inline / Access parent object/instance of an Inline
View admin.py
# Let's say you want to access the Collection instance for a Image in a Django Admin Inline
from django.contrib import admin
from app.models import Image, Collection
class ImageInline(admin.StackedInline):
model = models.Image
extra = 1
@douglasmiranda
douglasmiranda / toasts.css
Last active Jan 19, 2021
Bootstrap Toasts - Top Right Fixed (+ Fix toast-container overlaping content)
View toasts.css
/* https://getbootstrap.com/docs/5.0/components/toasts/ */
.toast-container {
position: fixed;
right: 20px;
top: 20px;
}
.toast:not(.showing):not(.show) {
display: none !important;
@douglasmiranda
douglasmiranda / tagify.js
Created Jan 7, 2021
Tagify: Format for server side comma separated / on form changes event / jQuery example
View tagify.js
jQuery(document).ready(function ($) {
$input = $('#my-form')
.tagify()
.on('change', function (e, tagData) {
if (tagData === undefined) {
return;
}
// string [{"value":"test"}', '{"value":"test2"}] to JSON Object
var tags = JSON.parse(tagData);
// Converts into a simple array ["test", "test2"], then convert to string "test,test2"
@douglasmiranda
douglasmiranda / wkhtmltopdf.md
Created Nov 23, 2020
wkhtmltopdf headless fix
View wkhtmltopdf.md
@douglasmiranda
douglasmiranda / choices.md
Created Jan 4, 2020
Django Field.choices alternative
View choices.md

Django Field.choices

I was never very fond of using that tuple of tuples and acessing those choices with something like choices[0].

In my latest projects I was using a solution of my own.

This:

@douglasmiranda
douglasmiranda / docker-client-go.md
Created May 8, 2019
Docker client API version mismatch: Error response from daemon: client version 1.40 is too new. Maximum supported API version is 1.39
View docker-client-go.md

When building things that will interact with the client/server you can have a mismatch of API versions.

This is a common way to get started with the Docker client in Go: (this will create a new client based on your environment settings for Docker)

cli, err := client.NewClientWithOpts(client.FromEnv)

You may face an error similar to:

View pull.go
package main
import (
"context"
"fmt"
"io/ioutil"
"os"
"github.com/containerd/containerd/content/local"
"github.com/containerd/containerd/images"
@douglasmiranda
douglasmiranda / ubuntu-dell-g3.md
Last active Jun 14, 2021
Ubuntu 16.04 Dell G3 series setup
View ubuntu-dell-g3.md