Skip to content

Instantly share code, notes, and snippets.


Niccolò Mineo niccolomineo

View GitHub Profile
niccolomineo /
Last active Sep 10, 2021
Django ArrayField inheritable list filter
"""Define Django filters."""
from django.contrib.admin import SimpleListFilter
class ArrayFieldListFilter(SimpleListFilter):
"""An admin list filter for ArrayFields."""
def lookups(self, request, model_admin):
"""Return the filtered queryset."""
niccolomineo /
Last active Feb 17, 2021
Settings env init
Initialise settings.
This implementation requires class-based definition of each environment
in an individual file (e.g. `` / `class Production`).
This very init code should go in an `` file in the same folder as the environment files.
niccolomineo /
Last active Sep 10, 2020
A mixin handling read-only fields per group, admin model and form type in Django
class FieldPermissionsMixin:
Define a mixin handling read-only fields per group, admin model and form type.
Read-only fields can be specified in a setting exemplified below.
For permission names, codenames without the model name are considered well-formed.
niccolomineo /
Last active Sep 10, 2021
(Django admin inline) PIL thumbnail generation w/ smart cropping
# Requirements:
# - a model with `file`and `thumbnail` fields.
# - the smartcrop module for Python
class MyModelAdmin(admin.ModelAdmin):
"""Set MyModel Admin."""
formset = MyModelFormset
niccolomineo /
Last active Feb 17, 2021
Django response mock object
"""Define Django Response Mock."""
import json
from django.conf import settings
from django.utils.translation import gettext_lazy as _
class ResponseMock:
"""Define response mock."""
niccolomineo /
Created Mar 2, 2020
Select rightmost sheet in a Google Spreadsheet
function selectRightmostSheet()
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet()
var sheets = spreadsheet.getSheets()
View google-drive-api-jwt-service-account
import os
import time
import mimetypes
import jwt
import google.auth.crypt
import google.auth.jwt
import requests
credentials_file = json.load(open(
os.path.dirname(os.path.realpath(__file__)) +
niccolomineo / toggle-bluetooth.applescript
Last active Jan 19, 2019
Toggles Bluetooth on Mac Os. Requires blueutil utility.
View toggle-bluetooth.applescript
on run {input, parameters}
tell application "System Events"
set current_status to (do shell script "eval $(/usr/libexec/path_helper -s); blueutil | grep 'Power:' | cut -c8-")
if current_status = "0" then
do shell script "eval $(/usr/libexec/path_helper -s); blueutil -p 1"
delay 0.25
niccolomineo / get-ns-rgb-components-at-coords.swift
Last active Aug 7, 2018
Get NS RGB components at specific coordinates based on main display id
View get-ns-rgb-components-at-coords.swift
func getNSComponentsAt(x: Int, y: Int) -> NSColor {
let screenID = NSScreen.main!.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as! UInt32
let image: CGImage = CGDisplayCreateImage(CGDirectDisplayID(screenID), rect: CGRect(x: CGFloat(x), y: CGFloat(y), width: 1, height: 1))!
let bitmap = NSBitmapImageRep(cgImage: image)
let color = bitmap.colorAt(x: 0, y: 0)
self.redComponent = (color?.redComponent)!
self.greenComponent = (color?.greenComponent)!
self.blueComponent = (color?.blueComponent)!
View join-filter-angularjs.js
// Filter: removes all non alphanumerical characters from input
myApp.filter('join', function() {
return function(input) {
input = input || '';
var output = input.replace(/\W/g, '');
return output;