Skip to content

Instantly share code, notes, and snippets.

Avatar
Remote Working

Paolo Melchiorre pauloxnet

Remote Working
View GitHub Profile
@rajeshr188
rajeshr188 / models.py
Last active Jan 26, 2021
Creating ArrayField of custom basefield in Django
View models.py
from moneyed import Money
from psycopg2.extras import register_composite
from psycopg2.extensions import register_adapter, adapt, AsIs
MoneyValue = register_composite(
'money_value',
connection.cursor().cursor,
globally=True
).type
View 2a-Leaflet-marker-emoji.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Leaflet - Emoji marker</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" rel="stylesheet" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
<style>
.mymarker { font-size: 50px; }
View models.py
from django.db import models
from django.db.models import Avg
class Blog(models.Model):
name = models.CharField(max_length=100)
rating = models.DecimalField(max_digits=5, decimal_places=2, null=True)
def __str__(self):
return self.name
@bzamecnik
bzamecnik / process_memory_usage_osx.sh
Last active Jan 24, 2021
Process memory usage on OSX using GNU time
View process_memory_usage_osx.sh
# On Linux we can use native GNU time, on OSX we have to install gnu-time
# manually, since native time doesn't measure memory.
# http://man7.org/linux/man-pages/man1/time.1.html
# http://braumeister.org/formula/gnu-time
$ brew install gnu-time
# can be called via gtime, since time is a bash command
# %M - Maximum resident set size of the process during its lifetime, in Kbytes.
@apollo13
apollo13 / chromelogger.py
Last active Jun 25, 2017
Django logging to Firefox/Chrome devtools
View chromelogger.py
"""
License: MIT - https://opensource.org/licenses/MIT
ChromeLogger is a protocol which allows sending logging messages to the Browser.
This module implements simple support for Django. It consists of two components:
* `LoggingMiddleware` which is responsible for sending all log messages
associated with the request to the browser.
* `ChromeLoggerHandler` a python logging handler which collects all messages.
@lockie
lockie / trigram_migration.py
Last active Jan 14, 2018
A Django migration to add PostgreSQL trigram search, aka pg_trgm
View trigram_migration.py
# -*- coding: utf-8 -*-
# XXX this is actually useful for very special use cases, e.g. misspel suggestions:
# https://www.postgresql.org/docs/9.6/static/pgtrgm.html#AEN180626
from __future__ import unicode_literals
from django.db import migrations
from django.contrib.postgres.operations import TrigramExtension
class Migration(migrations.Migration):
operations = [
@pylover
pylover / a2dp.py
Last active Feb 9, 2021
Fixing bluetooth stereo headphone/headset problem in ubuntu 16.04, 16.10 and also debian jessie, with bluez5.
View a2dp.py
#! /usr/bin/env python3.5
"""
Fixing bluetooth stereo headphone/headset problem in ubuntu 16.04 and also debian jessie, with bluez5.
Workaround for bug: https://bugs.launchpad.net/ubuntu/+source/indicator-sound/+bug/1577197
Run it with python3.5 or higher after pairing/connecting the bluetooth stereo headphone.
This will be only fixes the bluez5 problem mentioned above .
@raprasad
raprasad / test_unmanaged_models.md
Last active Feb 25, 2021
Ignoring migrations during Django testing (unmanaged databases, legacy databases, etc)
View test_unmanaged_models.md

Scenario

  • Django 1.9 application with two databases:
    • Legacy database with readonly access via unmanaged models. Both Django models (models.py) and related migrations have "managed" set to False
      • 'managed': False
    • Default database holding django specific tables (e.g. auth_user, django_content_type, etc)

Testing Woes

@pauloxnet
pauloxnet / signals.py
Last active Apr 1, 2016 — forked from jefftriplett/signals.py
Django management command to trace / list all signals. My fork is just a few cleanups where CommandError wasn't referenced, etc.
View signals.py
# coding:utf-8
import gc
import inspect
import weakref
from django.core.management.base import BaseCommand, CommandError
from django.dispatch import Signal
from django.dispatch.weakref_backports import WeakMethod
from optparse import make_option