Skip to content

Instantly share code, notes, and snippets.

@grizmio
grizmio / monkey_patch.py
Created October 30, 2024 17:04
monkeypatch decorating django handle_simple tag (static tag)
from django.templatetags.static import StaticNode
def patch_static_tag(unique_per_deploy: str):
def handle_simple_wrapper(func):
def wrapper_func(cls, path):
resolved_static_path = func(path)
if resolved_static_path.endswith('.js') or resolved_static_path.endswith('.css'):
resolved_static_path += f'?u={unique_per_deploy}'
return resolved_static_path
@grizmio
grizmio / distance_sensor_helper.h
Last active September 8, 2024 22:54
DistanceSensorHelper
// https://registry.platformio.org/platforms/platformio/espressif8266/boards
// /homeassistant/esphome/distance_sensor_helper.h
#include "esphome.h"
// https://esphome.io/components/sensor/custom
class DistanceSensorHelper : public PollingComponent, public Sensor {
public:
int _trigPin;
int _echoPin;
DistanceSensorHelper(int polling_time) : PollingComponent(polling_time) {
# https://stackoverflow.com/questions/7499767/temporarily-disable-auto-now-auto-now-add
"""
Con modifcacion de Georgina S
n.b. (1.10) ModelClass._meta.get_field_by_name(field_name)[0] in do_to_model didn't seem to be working for me - changed to: ModelClass._meta.get_field(field_name) –
Georgina S
Commented Mar 8, 2017 at 1:15
"""
def turn_off_auto_now(ModelClass, field_name):
def auto_now_off(field):
@grizmio
grizmio / foo.py
Created July 24, 2023 03:33
Django ModelChoiceField label to "title"
from django.template.defaultfilters import title
class LabelToTitle:
def __init__(self):
self.label = title(self.label)
class FooBarModelChoiceField(forms.ModelChoiceField, LabelToTitle):
def label_from_instance(self, obj):
@grizmio
grizmio / django_reload.sh
Created July 7, 2023 19:40
django_reload develop
alias reload_gunicorn='pidof -x gunicorn|xargs sudo kill -s HUP'
$ inotifywait -m -e modify,create,delete -r . && reload_gunicorn
@grizmio
grizmio / foo.html
Created May 28, 2023 23:54
CSS, add checkmark to label when selected/checked bootstrap 5
<html>
<body>
<style>
.btn-check:checked + label:before {
content: "✓";
left: 3px;
position: absolute;
}
</style>
<div class="col-md-6">
@grizmio
grizmio / gist:ed58dfe8da1ceedc2583649af5165311
Last active May 19, 2023 19:20
JS class callable generate svgs with circles without index out :-D
class GetSVGDot extends Function{
dot_svgs = [];
constructor(size) {
super('return arguments.callee._call.apply(arguments.callee, arguments)');
const dot_colors = ['#FF0000', '#FF8000', '#80FF00', '#000000', '#0000FF', '#0000FF', '#FFFF00', '#FF6600', '#00FF00', '#00FFFF', '#FF00FF', '#8000FF', '#6600FF', '#FF7D00'];
let cont = 0;
for(const dot_color of dot_colors) {
this.dot_svgs.push(`<svg id='svg_circle_${cont}' width='${size}' height='${size}'>
<circle cx="12.5" cy="12.5" r="6.25" fill="${dot_color}">
</circle>
@grizmio
grizmio / gist:8e7965022fb47694fbc0a64365478229
Created January 20, 2023 03:58
zsh, oh my zsh and git plugin too slow
# https://github.com/ohmyzsh/ohmyzsh/issues/10175
DISABLE_UNTRACKED_FILES_DIRTY="true" in .zshrc
git config --global --add oh-my-zsh.hide-status 1
git config --global --add oh-my-zsh.hide-dirty 1
@grizmio
grizmio / SonarQube howto
Last active January 19, 2023 15:33
SonarQube 8.9.6
First, the server
docker run -d --name sonarqube -p 8000:8000 -p 9000:9000 sonarqube:8.9.6-community
Then login with admin:admin
http://127.0.0.1:9000
Create the project and its token
An example for running the scanner with docker
sudo cat /var/log/audit/audit.log | audit2why