Skip to content

Instantly share code, notes, and snippets.

View niccolomineo's full-sized avatar

Niccolò Mineo niccolomineo

View GitHub Profile
@niccolomineo
niccolomineo / bbcode-to-html.js
Last active August 23, 2023 14:32
BBCode-to-HTML JS tokenizer + parser
var input = '[section][lang]Web writing (EN / IT / FR)[y]A lot[/y][/lang][/g][g Tools][lang]Git, AngularJS, GruntJS, Bower, Bash[y]A lot[/y][/lang][lang]Photoshop, Illustrator, InDesign[y]A lot[/y][/lang][/g][/section][p][i]Head in the clouds and feet on the ground web technologies enthusiast, with 6+ years across the web product value chain, aiming at 0 pending emails a day.[/i][/p][p]Hands-on practice across all web dev layers and in all stages of the web product Agile lifecycle, in Euro/regional institutions and private media agencies. Specific strengths:[/p] [*]API-first thinker[/*] [*]mixed technical/design skills[/*] [*]coolheadedness[/*] [*]stakeholder convergence and allocation[/*] [*]brand oriented/redundancy allergic view.[/*][p]Check out my full [a docs/niccolo_mineo_cv.pdf|résumé].[/p][q]The personal qualities and technical skills of Niccolò, as well as his ability to adapt to a multinational and multilingual environment, have made it very easy to integrate him in a well established team. We are s
@niccolomineo
niccolomineo / join-filter-angularjs.js
Created August 9, 2016 15:10
AngularJS - Filter - Join
// 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;
};
});
@niccolomineo
niccolomineo / get-ns-rgb-components-at-coords.swift
Last active August 7, 2018 15:11
Get NS RGB components at specific coordinates based on main display id
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)!
@niccolomineo
niccolomineo / toggle-bluetooth.applescript
Last active January 21, 2023 09:59
Toggles Bluetooth on Mac Os. Requires blueutil utility.
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"
beep
delay 0.25
beep
else
do shell script "eval $(/usr/libexec/path_helper -s); blueutil -p 0"
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
niccolomineo / google-spreadsheet-select-rightmost-sheet.gs
Created March 2, 2020 13:20
Select rightmost sheet in a Google Spreadsheet
function selectRightmostSheet()
{
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet()
var sheets = spreadsheet.getSheets()
spreadsheet.setActiveSheet(sheets[sheets.length-1])
}
selectRightmostSheet()
@niccolomineo
niccolomineo / response_mock.py
Last active February 17, 2021 14:02
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
niccolomineo / admin.py
Last active September 10, 2021 16:29
(Django admin inline) PIL thumbnail generation w/ smart cropping
# Requirements:
# - a model with `file`and `thumbnail` fields.
# - the smartcrop module for Python https://github.com/smartcrop/smartcrop.py
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
"""Set MyModel Admin."""
formset = MyModelFormset
@niccolomineo
niccolomineo / mixins.py
Last active September 10, 2020 20:39
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.
!!!THIS IS JUST A STUB, AWAITING COMPLETION!!!
Read-only fields can be specified in a setting exemplified below.
For permission names, codenames without the model name are considered well-formed.
GROUPS = {
@niccolomineo
niccolomineo / settings.py
Last active February 17, 2021 16:24
Settings env init
"""
Initialise settings.
This implementation requires class-based definition of each environment
in an individual file (e.g. `production.py` / `class Production`).
This very init code should go in an `__init__.py` file in the same folder as the environment files.
"""