This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button data-areyousure>Default</button> | |
<button data-areyousure="¿Está seguro?" | |
data-confirm="Sí" | |
data-cancel="No">Custom Text</button> | |
<button id="callbacks">Callbacks</button> | |
<script> | |
$("#callbacks").areyousure({ yes: function() {alert('Sure.');}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: test csf | Port scans are denied | |
connection: local | |
sudo: no | |
# doalarm runs a command and returns an error if no output was captured in | |
# 3 seconds | |
# Here, a portscan is attempted; CSF should hang the connection, so doalarm() should | |
# return an error | |
command: doalarm () { perl -e 'alarm shift; exec @ARGV' "$@"; } && doalarm 3 nc -z 192.168.111.111 1-1023 | |
register: portscan_result | |
failed_when: portscan_result.stdout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from marshmallow import Schema, fields | |
class FooSchema(Schema): | |
author_name = fields.Nested('UserSerializer') | |
class Meta: | |
fields = ('id', 'author_name') | |
foos = Foo.query.all() | |
schema = FooSchema(many=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Proof of concept for converting 3rd-party validators to marshmallow validators, | |
demonstating multiple possible implementations. | |
""" | |
from marshmallow import fields | |
from marshmallow.exceptions import UnmarshallingError, ValidationError | |
import pytest | |
class Converter(object): | |
__name__ = 'Converter' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The slow way | |
class Person: | |
def __init__(self, name, occupation): | |
self.name = name | |
self.occupation = occupation | |
self.relatives = self._get_all_relatives() | |
def _get_all_relatives(): | |
... | |
# This is an expensive operation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Boiler: | |
def safety_check(self): | |
# Convert fixed-point floating point | |
temperature = self.modbus.read_holding() | |
pressure_psi = self.abb_f100.register / F100_FACTOR | |
if (psi_to_pascal(pressure_psi) > MAX_PRESSURE or | |
temperature > MAX_TEMPERATURE): | |
# Shutdown! | |
self.pnoz.relay[15] &= MASK_POWER_COIL | |
self.pnoz.port.write('$PL,15\0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_task(self, task, job, obligation): | |
... | |
processed = ... | |
... | |
copied = ... | |
... | |
executed = ... | |
100 more lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# At initiation `point` is not well-formed | |
point = Point() | |
point.x = 12 | |
point.y = 5 | |
# Better | |
point = Point(x=12, y=5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TaskSender: | |
def __init__(self, task, job obligation): | |
self.task = task | |
self.job = job | |
self.obligation = obligation | |
self.processed = [] | |
self.copied = [] | |
self.executed = [] | |
def __call__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if self.flags & 0b1000: # Am I visible? | |
... | |
# Better | |
... | |
@property | |
def is_visible(self): | |
return self.flags & 0b1000 | |
if self.is_visible: |
OlderNewer