Skip to content

Instantly share code, notes, and snippets.

@senko
senko / singleton.py
Created February 25, 2013 08:01
Singleton Django Model
# Written by Senko Rasic <senko.rasic@goodcode.io>
# Released into Public Domain. Use it as you like.
from django.db import models
class SingletonModel(models.Model):
"""Singleton Django Model
Ensures there's always only one entry in the database, and can fix the
@vitorfs
vitorfs / example.html
Last active August 23, 2023 05:44
Startswith Template Filter
{% load startswith %}
<li{% if request.path|startswith:'/settings/' %} class="active"{% endif %}>
@alejovicu
alejovicu / python3.7.2-selenium-alpine3.8-dockerfile
Last active August 23, 2023 04:16
Docker Selenium Webdriver with Python3 in alpine 3.8
# Objective: Running selenium python scripts in alpine without grid
FROM python:3.7.2-alpine3.8
RUN pip install selenium
RUN apk add chromium
RUN apk add chromium-chromedriver
ENV CHROME_BIN=/usr/bin/chromium-browser \
@lmn3x
lmn3x / code_meli_validator.py
Last active August 23, 2023 05:45
django validator for code meli
from django.core.exceptions import ValidationError
def validate_meli_code(value: str):
if not len(value) == 10:
raise ValidationError("کد ملی باید ۱۰ رقم باشد.")
res = 0
for i, num in enumerate(value[:-1]):
res = res + (int(num) * (10 - i))
@rutcreate
rutcreate / README.md
Last active July 22, 2024 12:23
Install Python 3.10.x on Ubuntu 20.04

Prerequisite

sudo apt update
sudo apt install software-properties-common -y

Add custom APT repository