Skip to content

Instantly share code, notes, and snippets.

View outime's full-sized avatar
🇫🇮

outime

🇫🇮
View GitHub Profile
@outime
outime / model_to_dict_verbose.py
Last active October 7, 2015 15:12
Modification to model_to_dict() Django function to return a dict of verbose field names instead
from itertools import chain
from django.db.models.fields.related import ManyToManyField
def model_to_dict_verbose(instance, fields=None, exclude=None):
"""
Returns a dict containing the data in ``instance`` suitable for passing as
a Form's ``initial`` keyword argument. Keys in dict are exchanged for
verbose names contained in the model.
``fields`` is an optional list of field names. If provided, only the named
fields will be included in the returned dict.
@outime
outime / FutureToEither.scala
Created January 30, 2017 08:14
How to handle timeout with WS api in Play2.1/Scala 2.10
def asFutureEither[T](f: Future[T]): Future[Either[Throwable, T]] =
f map { Right(_) } recover { case x => Left(x) }
@outime
outime / main.py
Last active August 27, 2017 15:30
Overly complicated Python script with multiple LED programs which can be changed by pressing an attached button
from enum import Enum
from multiprocessing import Process
from time import sleep
import RPi.GPIO as GPIO
PINS = {'in': 19, 'out': 21}
class Program(Enum):