dnd 5e – What is the source for defaulting to plain English readings of non-game terms?

Jeremy Crawford1 has affirmed that this is indeed the way the rules are supposed to be read in this tweet:

Unless the rules explicitly expand, narrow, or completely redefine a word, that word retains the meaning it has in idiomatic English. #DnD

Going back to the original articles detailing the design goals for the 5th edition (see this related answer for more details) one can also find that there was some concern over the kind of language used to detail the rules. Of particular interest is this article (found by illustro) which includes:

The choice between “fun to read” and “precise” needs to be handled on a case-by-case basis. Certain rules can be simple and straightforward, while other matters can be handled more conversationally or filled with inspirational descriptions of people, places, or events.

While certainly not as explicit as the tweet by Jeremy Crawford, one can read from that article that the designers wanted to use plain language to describe at least part of the rules where more specific technical jargon was not necessary.


1. Jeremy Crawford was the lead rules designer of Dungeons & Dragons 5e. Though at the time this answer was first written his twitter posts were considered official, as noted by V2Blast, that is no longer the case.

automata – How to describe the language of an automaton in plain English?

How do I describe the following automaton in plain english?

The only thing that I can think about when explaining in plain english would be the states, alphabet, start, accepting state, but I think there is more to when explaining about an automata. How do I answer that?

The states are as follows: Q = {q1, q2, q3, q4} 
The alphabet is as follows: Σ = {0,1} 
The start state is q1
The accepting state is q4

enter image description here

algorithm – Huffman compressor in plain C

I recently picked up C, because I am getting tired of the hell that is Java Enterprise development.
I decided that writing a Huffman compressor will be a great little exercise, and I have always wanted to write a compression algorithm.
I want some pointers(get it) on how to make the code more idiomatic, modular and less verbose.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_SZ 128
#define MAX_CODE_LEN 64

int counts(MAX_SZ);
char codes(MAX_SZ)(MAX_CODE_LEN);

typedef struct Node {
    char character;
    int count;
    struct Node *left;
    struct Node *right;
} Node;

void calculate_prob(char *str, int *counts) {
    int len = strlen(str);
    for (int i = 0; i < len; i++) {
        counts(*str++)++;
    }
}

int comparator(const void *a, const void *b) {
    Node *n1 = (Node *)a;
    Node *n2 = (Node *)b;
    return (n1->count - n2->count);
}

Node *find_and_remove_min(Node *nodes, int sz) {
    int idx = 0;
    Node *minNode = &nodes(0);
    for (int i = 0; i < sz; i++) {
        if (nodes(i).count < minNode->count) {
            minNode = &nodes(i);
            idx = i;
        }
    }
    Node *node = (Node *)malloc(sizeof(Node));
    memcpy(node, minNode, sizeof(Node));
    nodes(idx) = nodes(sz - 1);
    return node;
}

void dfs(Node *node, char *path, int sz) {
    if (node == NULL) {
        return;
    }
    if (node->left == NULL && node->right == NULL) {
        strncpy(codes(node->character), path, sz);
        return;
    }
    path(sz) = '0';
    dfs(node->left, path, sz + 1);
    path(sz) = '1';
    dfs(node->right, path, sz + 1);
}

char *fileToString(char *file_name) {
    FILE *file = fopen(file_name, "r");
    if (file == NULL) return NULL;

    fseek(file, 0, SEEK_END);
    long int size = ftell(file);
    fclose(file);

    file = fopen(file_name, "r");
    char *str = (char *)malloc(size);
    int bytes_read = fread(str, sizeof(char), size, file);
    fclose(file);
    return str;
}

void writeCodeBook(FILE* file){
    for (int i = 0; i < MAX_SZ; i++) {
        if (codes(i)(0) == '') {
            continue;
        }
        putc((char)i, file);
        putc(':', file);
        fwrite(codes(i), sizeof(char), strlen(codes(i)), file);
        putc('n', file);
    }
}

void writeBitToFile(unsigned char bit, FILE *file, int flush) {
    static int count = 0;
    static char buffer = 0;
    
    if(flush){
        buffer <<= (8 - count); 
        fwrite(&buffer, sizeof(buffer), 1, file);
        return;
    }

    buffer <<= 1;          // Make room for next bit.
    if (bit) buffer |= 1;  // Set if necessary.
    count++;

    if (count == 8) {
        fwrite(&buffer, sizeof(buffer), 1, file);  // Error handling elided.
        buffer = 0;
        count = 0;
    } 
}

int main(int argc, char **argv) {
    char *str = NULL;

    if (argc > 1) {
        str = fileToString(argv(1));
    } else {
        return 1;
    }

    calculate_prob(str, counts);
    int node_count = 0;

    for (int i = 0; i < MAX_SZ; i++) {
        if (counts(i) != 0) {
            node_count++;
        }
    }
    const int SZ = node_count;
    Node nodes(SZ);

    for (int i = 0, idx = 0; i < MAX_SZ; i++) {
        if (counts(i) != 0) {
            struct Node node = {(char)i, counts(i), NULL, NULL};
            nodes(idx++) = node;
        }
    }

    qsort(nodes, SZ, sizeof(Node), comparator);

    int sz = SZ;
    Node *root = NULL;

    while (sz != 1) {
        struct Node *min = find_and_remove_min(nodes, sz);
        struct Node *min_2 = NULL;
        sz--;
        min_2 = find_and_remove_min(nodes, sz);
        Node new_node = {'', min->count + min_2->count, min, min_2};
        nodes(sz - 1) = new_node;
        root = &new_node;
    }

    char path(MAX_CODE_LEN);
    memset(path, '', MAX_CODE_LEN);

    dfs(root, path, 0);

    FILE *file = NULL;

    if (argc > 2) {
        file = fopen(argv(2), "w+");
    } else {
        return 1;
    }

    writeCodeBook(file);

    for (char *s = str; *s; s++) {
        char *code = codes(*s);
        int len = strlen(code);
        
        for (int i = 0; i < len; i++) {
            unsigned char bit = code(i) - '0';
            // printf("%d", bit);
            writeBitToFile(bit, file, 0);
        }
    }
    writeBitToFile(0, file, 1);
}

macos – Binary plist is opened as plain text in Xcode

# file /private/var/root/Library/Preferences/com.apple.finder.plist
/private/var/root/Library/Preferences/com.apple.finder.plist: Apple binary property list

Opened in Xcode 10.1:
Xcode bug
If I use plutil -convert xml1 file.plist, Xcode can open it correctly. What might cause this behavior? How can I tell Xcode to treat it as a binary plist file?

applescript – Service to underline plain text with a line of dashes

applescript – Service to underline plain text with a line of dashes – Ask Different

Generic converter for plain java objects

As part of my recent transition from c# to java i decided to write a small converter implementation to translate DTO objects to entities. I’m fully aware of already existing solutions, especially in spring boot, but decieded to create this class as part of my learning process to write projects in java.

General note: I’ve used lombok to not write get and set methods by hand

The main goal for me was to create a simple to use class to convert DTOs or input objects into entities by mapping the fields between them. Ideally the implementation would allow me to extend the base class to implement special converters while still using the basic reflection mapping.

Main implementation

public class Converter<F, T> {
    private final static String SET_METHOD_PREFIX = "set";
    private final static String GET_METHOD_PREFIX = "get";
    
    private final List<Field> fieldsOfF;
    private final List<Field> fieldsOfT;

    private final List<Method> methodsOfF;
    private final List<Method> methodsOfT;

    private final Class<T> classToType;
    private final Class<F> classFromType;

    public Converter(Class<F> fromClass, Class<T> toClass) {
        this.classToType = toClass;
        this.classFromType = fromClass;

        this.fieldsOfF = getAllFields(fromClass);
        this.fieldsOfT = getAllFields(toClass);

        this.methodsOfF = getAllMethods(fromClass);
        this.methodsOfT = getAllMethods(toClass);
    }

    public T convert(F object) throws ConverterException {
        T instance = getInstance(classToType);

        for (Field item : fieldsOfF) {
            setValue(instance, getValue(object, item, methodsOfF), item, fieldsOfT, methodsOfT);
        }

        return instance;
    }

    public F convertBack(T object) throws ConverterException {
        F instance = getInstance(classFromType);

        for (Field item : fieldsOfT) {
            setValue(instance, getValue(object, item, methodsOfT), item, fieldsOfF, methodsOfF);
        }

        return instance;
    }

    private Object getValue(Object object, Field field, List<Method> methods) throws ConverterException {
        Optional<Method> optionalMethod;
        Object value = null;
        if (field.canAccess(object)) {
            try {
                value = field.get(object);
            } catch (IllegalArgumentException | IllegalAccessException e) {
                e.printStackTrace();

                throw new ConverterException(e.getMessage(), e);
            }
        } else {
            optionalMethod = methods.stream().filter(
                    x -> x.getName().equals((GET_METHOD_PREFIX + capitalizeFirstChar(field.getName()))) && x.canAccess(object))
                    .findFirst();
            if (optionalMethod.isPresent()) {
                try {
                    value = optionalMethod.get().invoke(object);
                } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    e.printStackTrace();

                    throw new ConverterException(e.getMessage(), e);
                }
            }
        }
        return value;
    }

    private void setValue(Object instance, Object value, Field item, List<Field> fields, List<Method> methods)
            throws ConverterException {
        Optional<Field> optionalField = fields.stream().filter(
                x -> x.getName().equals(item.getName()) && x.getType().equals(item.getType()) && x.canAccess(instance))
                .findFirst();
        if (optionalField.isPresent()) {
            try {
                optionalField.get().set(instance, value);
            } catch (IllegalArgumentException | IllegalAccessException e) {
                e.printStackTrace();
            }
        } else {
            Optional<Method> optionalMethod = methods.stream().filter(
                    x -> x.getName().equals((SET_METHOD_PREFIX + capitalizeFirstChar(item.getName()))) && x.canAccess(instance))
                    .findFirst();
            if (value != null) {
                if (optionalMethod.isPresent() && optionalMethod.get().getParameterCount() == 1
                        && optionalMethod.get().getParameters()(0).getType().isAssignableFrom(value.getClass())) {
                    try {
                        optionalMethod.get().invoke(instance, value);
                    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                        e.printStackTrace();

                        throw new ConverterException(e.getMessage(), e);
                    }
                }
            }
        }
    }

    private <E> E getInstance(Class<E> instanceClass) throws ConverterException {
        E instance = null;
        try {
            instance = instanceClass.getDeclaredConstructor().newInstance();
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
                | NoSuchMethodException | SecurityException e) {
            e.printStackTrace();

            throw new ConverterException(e.getMessage(), e);
        }
        return instance;
    }

    private <E> List<Field> getAllFields(Class<E> clazz) {
        if (clazz == null) {
            return Collections.emptyList();
        }

        List<Field> result = new ArrayList<>(getAllFields(clazz.getSuperclass()));
        List<Field> filteredFields = Arrays.stream(clazz.getDeclaredFields()).collect(Collectors.toList());
        result.addAll(filteredFields);
        return result;
    }

    private <E> List<Method> getAllMethods(Class<E> clazz) {
        if (clazz == null) {
            return Collections.emptyList();
        }

        List<Method> result = new ArrayList<>(getAllMethods(clazz.getSuperclass()));
        List<Method> filteredFields = Arrays.stream(clazz.getDeclaredMethods()).collect(Collectors.toList());
        result.addAll(filteredFields);
        return result;
    }

    private String capitalizeFirstChar(String value) {
        return value.substring(0, 1).toUpperCase() + value.substring(1);
    }
}

The main methods are convert(T object) and convertBack(F object). I’ve tried to keep the usage as simple as possible without any additional methods or setup steps.

Specific implementation

public class SampleEntityConverter extends Converter<SampleDTO, SampleEntity> {

    private Converter<SampleNestedDTO, SampleNestedEntity> nestedConverter = new Converter<>(SampleNestedDTO.class,
            SampleNestedEntity.class);

    public SampleEntityConverter() {
        super(SampleDTO.class, SampleEntity.class);
    }

    @Override
    public SampleEntity convert(SampleDTO object) throws ConverterException {
        SampleEntity instance = super.convert(object);
        if (object.nested != null) {
            instance.setNested(nestedConverter.convert(object.nested));
        }

        return instance;
    }

    @Override
    public SampleDTO convertBack(SampleEntity object) throws ConverterException {
        SampleDTO instance = super.convertBack(object);
        if (object.getNested() != null) {
            instance.nested = nestedConverter.convertBack(object.getNested());
        }
        return instance;
    }
}

Sample DTO and entity classes

The SampleDTO is a very simple DTO object with a abstract class as base to check if my implementation will handle inherited classes correctly

@ToString
public class SampleDTO extends AuditedDTO {
    public String field1;
    public Integer field2;
    public Boolean field3;
    public Instant field4;
    
    public SampleNestedDTO nested;
    
    public List<String> list1 = new ArrayList<>();
    
    public Map<String, Instant> map1 = new HashMap<>();
    
    public SampleDTO() {
        this.created = Instant.now();
        this.createdBy = "Test";
    }
}
@ToString
public class SampleNestedDTO {
    public String nestedField1;
    public Integer nestedField2;
    public Boolean nestedField3;
    public Instant nestedField4;
}
public abstract class AuditedDTO {
    public Instant created;
    public String createdBy;
    public Instant lastUpdate;
    public String lastUpdatedBy;
}

The SampleEntity object uses only get and set methods instead of public member variables to match our implementation of hiberante entities.

@ToString
public class SampleEntity extends AuditedEntity {
    @Getter
    @Setter
    private String field1;
    
    @Getter
    @Setter
    private Integer field2;
    
    @Getter
    @Setter
    private Boolean field3;
    
    @Getter
    @Setter
    private Instant field4;
    
    @Getter
    @Setter
    private SampleNestedEntity nested;
    
    @Getter
    @Setter
    private List<String> list1 = new ArrayList<>();
    
    @Getter
    @Setter
    private Map<String, Instant> map1 = new HashMap<>();
}
@ToString
public class SampleNestedEntity {
    @Getter
    @Setter
    private String nestedField1;
    
    @Getter
    @Setter
    private Integer nestedField2;
    
    @Getter
    @Setter
    private Boolean nestedField3;
    
    @Getter
    @Setter
    private Instant nestedField4;
}
@ToString
public abstract class AuditedEntity {
    @Getter
    @Setter
    private Instant created;

    @Getter
    @Setter
    private String createdBy;

    @Getter
    @Setter
    private Instant lastUpdate;

    @Getter
    @Setter
    private String lastUpdatedBy;
}

Usage

Now with my implementation of the converter simply using it as

Converter<SampleDTO, SampleEntity> converter = new Converter<>(SampleDTO.class, SampleEntity.class);

SampleDTO sampleDto = new SampleDTO();
sampleDto.field1 = "Sample String";
sampleDto.field2 = 1;
sampleDto.field3 = true;
sampleDto.field4 = Instant.now();
sampleDto.list1.add("String 1");
sampleDto.list1.add("String 2");
sampleDto.list1.add("String 3");
sampleDto.map1.put("Now", Instant.now());
sampleDto.map1.put("Tomorrow", Instant.now().plus(1, ChronoUnit.DAYS));
        
sampleDto.nested = new SampleNestedDTO();
sampleDto.nested.nestedField1 = "Sample nested String";
sampleDto.nested.nestedField2 = 2;
sampleDto.nested.nestedField3 = false;
sampleDto.nested.nestedField4 = Instant.now();

SampleEntity sampleEntity = converter.convert(sampleDto);
// sampleEntity.getNested() will be null and not converted with the baisc converter

will convert the sampleDto but this will not convert nested objects as it can only handle simple datatypes and collections. The special implementation as SampleEntityConverter will handle nested entites.

SampleEntityConverter converter = new SampleEntityConverter();

SampleDTO sampleDto = new SampleDTO();
sampleDto.field1 = "Sample String";
sampleDto.field2 = 1;
sampleDto.field3 = true;
sampleDto.field4 = Instant.now();
sampleDto.list1.add("String 1");
sampleDto.list1.add("String 2");
sampleDto.list1.add("String 3");
sampleDto.map1.put("Now", Instant.now());
sampleDto.map1.put("Tomorrow", Instant.now().plus(1, ChronoUnit.DAYS));
        
sampleDto.nested = new SampleNestedDTO();
sampleDto.nested.nestedField1 = "Sample nested String";
sampleDto.nested.nestedField2 = 2;
sampleDto.nested.nestedField3 = false;
sampleDto.nested.nestedField4 = Instant.now();

SampleEntity sampleEntity = converter.convert(sampleDto);
// sampleEntity.getNested() will be converted using the SampleEntityConverter

I’ve added a simple exception class ConverterException as

public class ConverterException extends Exception {

    private static final long serialVersionUID = -2846211687408157933L;
    
    public ConverterException(String message, Throwable cause) {
        super(message, cause);
    }

}

because exceptions should only occur during the design and writing of classes and not at production use runtime. This will make the handling of the different exceptions a bit simpler and keep the resulting code cleaner as there is only one type of exception to catch.

SampleEntity sampleEntity = null;
try {
    sampleEntity = converter.convert(sampleDto);
} catch (ConverterException e) {
    // handle exception
    e.printStackTrace();
}

Questions

Now to my questions:

  1. Are there any general improvements to my code in regards to naming conventions, type usage or any general errors I’ve made when using my knowledge of c# on java.
  2. Regarding the constructor methods of the Converter<F, T>, could this be a potential cause for performance problems when reading larger classes or deep inhiterances?
  3. Am I using the Field and Method methods correctly to check if a field can be set or a method can be called?
  4. Are there any caveats to use super.convert() in the specific implentations?

Thanks

web browser – Is every plain flow into a dangerous sink exploitable?

Given a flow of information (for example from the URL) into a sink on a certain site, and given that this information is plain, i.e. is not sanitized, does this mean that if an attacker could control the information flow, this will ALWAYS give the attacker an exploit? Or does the exploitability rather depend on the situation?

If the latter is true, could you give me an example of a sink, where the provided modified information would not lead to an exploit?

encryption – Decrypting plain text. PEM certificate

I have a text that is supposedly base64 encoded. But when I try to decipher it, an incomprehensible text comes out. But in principle, Latin letters are read. Perhaps this is a public certificate.

How to decipher it. And is it possible to encrypt your certificate the same way?

MIID+DCCAuCgAwIBAgIII2l0BK3LgxQwDQYJKoZIhvcNAQELBQAwYjELMAkGA1UEBhMCVVMxEzARBgNVBAoTCkFwcGxlIEluYy4xJjAkBgNVBAsTHUFwcGxlIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MRYwFAYDVQQDEw1BcHBsZSBSb290IENBMB4XDTE0MDMwODAxNTMwNFoXDTI5MDMwODAxNTMwNFowbTEnMCUGA1UEAwweQXBwbGUgU2VydmVyIEF1dGhlbnRpY2F0aW9uIENBMSAwHgYDVQQLDBdDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTETMBEGA1UECgwKQXBwbGUgSW5jLjELMAkGA1UEBhMCVVMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC5Jhawy4ercRWSjt+qPuGA11O6pGDMfIVy9zB8CU9XDUr/4V7JS1ATAmSxvTk10dcEUcEY+iL6rt+YGNa/Tk1DEPoliJ/TQIV25SKBtlRFc5qL45xIGoZ6w1Hi2pX4pH3bMN5sDsTF9WyY56b6VyAdGXN6Ds1jD7cniC7hmmiCuEBsYxYkZivnsuJUfeeIOaIbgT4C0znYl3dKMgzWCgqzBJvxcm9jqBUebDfoD9tTkNYpXLxqV5tGeAo+JOqaP6HYP/XbbqhsgrXdmTjsklaUpsVzJtGuCLLGUueOdkuJuFQPbuDZQtsqZYdGFLuWuFe7UeaEE/cNobaJrHzRIXSrAgMBAAGjgaYwgaMwHQYDVR0OBBYEFCzFbVLdMe+M7AiB7d/cykMARQHQMA8GA1UdEwEB/wQFMAMBAf8wHwYDVR0jBBgwFoAUK9BpR5R2Cf70a40uQKb3R01/CF4wLgYDVR0fBCcwJTAjoCGgH4YdaHR0cDovL2NybC5hcHBsZS5jb20vcm9vdC5jcmwwDgYDVR0PAQH/BAQDAgEGMBAGCiqGSIb3Y2QGAgwEAgUAMA0GCSqGSIb3DQEBCwUAA4IBAQAj8QZ+UEGBol7TcKRJka/YzGeMoSV9xJqTOS/YafsbQVtE19lryzslCRry9OPHnOiwW/Df3SIlERWTuUle2gxmel7Xb/Bj1GWMxHpUfVZPZZr92sSyyLC4oct94EeoQBW4FhntW2GO36rQzdI6wH46nyJO39/0ThrNk//Q8EVVZDM+1OXaaKATinYwJ9S/+B529vnDAO+xg+pTbVw1xw0HAbr4Ybn+xZprQ2GBA+u6X3Cd6G+UJEvczpKoLqI1PONJ4BZ3otxruY0YQrk2lkMyxst2mTU22FbGmF3Db6V+lcLVegoCIGZ4kvJnpCMN6Am9zCExEKC9vrXdTN1GA5mZ

I cannot publish the base64 decrypted format. StackExchange gives an error due to encoding

theme customizer – How to remove html tags from output with json_encode in WordPress? I want to show only plain text

I’ve been on trial and error for a few days, researching a lot, but I can’t solve this problem.

objective: this function generates schema output for data structured in JSON.

the problem: the texts are being delivered with html <p> tags, n etc, and I think that Google is not integrating my structured FAQ data because of this.

Output example:

"@type": "Question",
                    "name": "<p>What are the best destinations for my trip?</p>n",

the solution: I need to remove the <p> and </p> tags and show only plain text.

I tried using strip_tags and it worked partially:
"name": "'.strip_tags(apply_filters('the_content', $faq('question'))).'",

partially because I was able to remove the tags with this “solution”, but in contrast the JSON became invalid because added blank space and line breaks. Validation error message from JSONLint:
Expecting ‘STRING’, ‘NUMBER’, ‘NULL’, ‘TRUE’, ‘FALSE’, ‘{‘, ‘(‘, got ‘undefined’

this is the complete function code:

     public function render_schema()
{
  $faqs = $this->render_faqs();
  
    if (!$faqs)
    {
        return;
    }
    $schema = '
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "FAQPage",
        "mainEntity": (';

    $comma = '';

    foreach ($faqs as $faq)
      
    {
        $schema .= ' 
                ' . $comma . ' {
                    "@type": "Question",
                    "name": '.json_encode(apply_filters('the_content', $faq('question'))).',
                    
                    "acceptedAnswer": {
                        "@type": "Answer",
                        "text": ' . json_encode(apply_filters('the_content', $faq('reply'))) . '
                    }
                }
                ';

        $comma = ',';

    }
    $schema .= '
        )
    }
    </script>';

    return $schema;
}

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123