Skip to content

Instantly share code, notes, and snippets.

@pmuller
pmuller / dfplayer.md
Last active January 12, 2024 08:47
dfplayer.md

DFPlayer ICs

Manufacturer

  • Name: Guangzhou Xinyue Electronics Co., Ltd.
  • Website: yx080.com
  • Tel: 020-36776060
  • Mobile: 13751729917
  • Email: lur@yxin18.com
  • QQ:1553069551
>>> class Descriptor:
... def __get__(self, instance, owner):
... print('__get__', instance, owner)
... print('called on a', 'class' if instance is None else 'instance')
...
>>> class Class:
... foo = Descriptor()
...
>>> Class.foo
__get__ None <class '__main__.Class'>
from time import sleep
import RPi.GPIO
class PushButton:
def __init__(self, pin, rpi_gpio=RPi.GPIO):
self.pin = pin
self.rpi_gpio = rpi_gpio
from io import BytesIO
from PIL import Image
def scale_image_max_width(image_bytes, max_width):
"""Scale ``image`` to honor the ``max_width`` constraint.
"""
image = Image.open(BytesIO(image_bytes))
def find_fabfile(names=None): # pylint: disable=unused-argument
"""The absolute path of the cloudfab fabfile.
"""
return abspath(dirname(__file__))
@pmuller
pmuller / Makefile
Created May 23, 2016 18:24
PKI simple Makefile
help:
@cat README
server:
openssl req -new -config etc/server.conf -out certs/$(FQDN).csr -keyout certs/$(FQDN).key
openssl ca -config etc/signing-ca.conf -in certs/$(FQDN).csr -out certs/$(FQDN).crt -extensions server_ext
user:
openssl req -new -config etc/user.conf -out certs/$(NAME).csr -keyout certs/$(NAME).key
openssl ca -config etc/signing-ca.conf -in certs/$(NAME).csr -out certs/$(NAME).crt -extensions user_ext
@pmuller
pmuller / decorators.py
Created July 22, 2015 09:25
decorators examples
def add(x, y):
return x + y
def dummy_decorator(func):
"""This decorator does NOT modify ``func`` behavior.
It only prints stuff.
"""
print 'creating wrapper'
@pmuller
pmuller / duration_logger.py
Created April 2, 2015 16:33
Log timing information (context manager + decorator)
import time
import logging
LOGGER = logging.getLogger(__name__)
class DurationLogger(object):
"""Log run time duration of an operation.
@pmuller
pmuller / gist:a6bb6f9f662271837149
Created April 1, 2015 15:45
WTF Puppet parameterized class include scope
$ puppet -V
2.7.17
$ cat /tmp/wtf.pp
class foo {
warning('foo')
}
class bar::foo {
@pmuller
pmuller / facter-facts-timing.sh
Last active August 29, 2015 14:16
Generate a list of facts names, ordered by their generation time
#!/bin/sh
facter --timing 2>&1 | perl -ne '/^(.*): (\d+\.\d+)ms/ && print $2 . " " . $1 . "\n"' | sort -nu