## coding theory – Understanding a CRC32 Implementation

I’m currently trying to understand an implementation of CRC32 about which I have a question.

``````public uint Compute_CRC32_Simple(byte() bytes)
{
const uint polynomial = 0x04C11DB7; /* divisor is 32bit */
uint crc = 0; /* CRC value is 32bit */

foreach (byte b in bytes)
{
crc ^= (uint)(b << 24); /* move byte into MSB of 32bit CRC */

for (int i = 0; i < 8; i++)
{
if ((crc & 0x80000000) != 0) /* test for MSB = bit 31 */
{
crc = (uint)((crc << 1) ^ polynomial);
}
else
{
crc <<= 1;
}
}
}

return crc;
}
``````

I’m particularly interested in understanding this line: `crc ^= (uint)(b << 24); /* move byte into MSB of 32bit CRC */`

What are the mathematics that make this line possible, both the shifting of the current byte (turned into an int) by 24 and the following XOR with the current crc? Unfortunately, the author doesn’t go into detail regarding this.

## coding style – Is this enum/trait a good way to implement polymorphic design in Rust?

this is my first post on here, and I’m wondering about a good rust implementation with traits on enum types. I want to know if using an enum w/ a trait as a generator of different code is viable like the one below? Also a couple of things I’m curious about is if there is an overhead with the match statement? Would implementing separate structs be faster?

``````struct GeneralCell {
repr: char,
position: Position,
cell_type: Cell,
}

trait InitializeCells {
fn new(&self, position: Position) -> GeneralCell;
}

pub enum Cell {
Hall,
Filled,
Empty,
}

impl InitializeCells for Cell {
fn new(&self, position: Position) -> GeneralCell {
match self {
Cell::Hall => GeneralCell {
repr: 'H',
position,
cell_type: Cell::Hall,
},
Cell::Empty => GeneralCell {
repr: 'E',
position,
cell_type: Cell::Empty,
},
Cell::Filled => GeneralCell {
repr: 'F',
position,
cell_type: Cell::Filled,
},
}
}
}
``````

## coding theory – Variance Gamma parameter estimation in R studio

I am using the vgFit function in R Studio to estimate parameters for stock prices. I converted the stock prices to a vector and I get this error. My code was:

``````param<-c(0,1,0,1)
fit<-vgFit(c(x), param=param)
``````

The error is:

``````Error in optim(paramStart, llsklp, NULL, method = startMethodSL, hessian = FALSE,  :
function cannot be evaluated at initial parameters
``````

## programming practices – How do you delegate coding task efficiently as a project manager?

I would like to know your opinion in delegating task efficiently, it can be how detailed are you, or how demanding are you.

Please read `tl:dr` to understand the purpose of this question.

`tl:dr`

I am new to software engineering and currently competing in getting a bootcamp scholarship. The instructor gave a task in written paragraph. The paragraph explains how the apps works in detail with logic flow specified.

The task is simple but because of the logic flow is specified, the task becomes tedious and in the end the code becomes a very long `if else` statement.

Then, this question struck me and I put it on practice. I refactored the code with different logic flow and the code becomes shorter.

`In my opinion after refactored the code`

The written task should only explains the purpose of the app, the input, the output, the checks, and the deadline. The process / logic flow should be left to the software engineer.

``````Task: Create a function character(name,role,gender)
Purpose: Function to be called to register new character.
Input:
name: strings;
role: array; available roles are Knight, Rogue, Magician.
gender: integer; 0 for Female, 1 for Male.
Output:
variables name, role and gender to be used in mysql.createconnection.query()
Checks:
// check the variable value, example
console.log(name);
console.log(role);
console.log(gender);
// try it with the db
mysql.createconnection.query( INSERT INTO tables ( name,role,gender ) VALUES ( \${name}, \${role}, \${gender} ) );
``````

Sincerely,

kidfrom

## coding style – Dealing with unwanted usages of a function

I am writing a function that I would not like to get called given a certain context and am wondering how best to convey that to possible users of the function. Assume, for exemplification, I am writing a function `process_payment` that must not get called in an environment that demands certain security standards on the payments being done.
Some possible options of dealing with this I have thought of:

1. Having a `...warning` docstring comment ( or just a verbose comment in another programming language)
``````def process_payment(Payment payment):
"""
.. warning: DO NOT USE if we are in SECURE PAYMENT environment. Use a pipeline that leads to
"""
(...)
``````
1. Specifically checking if the conditions are met inside the `process_payment` function by calling in some global state to check the conditions.
``````def process_payment(Payment payment):
if get_payment_state() == SECURE_PAYMENT:
raise Exception(...)
``````
1. Having the execution conditions be some values inside of a Payment class/struct, such that one can easily check them at the call site.
``````def process_payment(Payment payment):
if payment.is_secure:
raise Exception(...)
``````

Obvious drawbacks to 1) are that it allows a not-careful user to process payments insecurely. Obvious drawbacks to 2) are that if the state which we are deciding with is quite far away in the call hierarchy, one needs to either call in some global state or propagate (potentially) a lot of information and pass it as an argument. Option 3) looks good, but one could imagine it being quite cumbersome and (depending on the programming language) suboptimal to include such redundant information into every Payment class.

Are there any other approaches I am missing? What are some common ways to deal with this?

## algorithms – Adaptive arithmetic coding confusion

I understand that static arithmetic coding involves using preset probabilities of symbols that remain static during the whole process. I also understand that adaptive arithmetic coding involves change all probabilities after each symbol encountered.

However, what is the point of changing the probability after each symbol? Why wouldn’t you just go through an entire file first and determine the probabilities and then do the arithmetic coding as a second pass?

Additionally, I don’t understand how changing the probability of symbols impacts the compression? If we know the true probabilities of the symbols in the file we are compressing, then will it make the file smaller?

## coding theory – How to find sent codeword using generator matrix?

Over $$GF(4)$$, received codeword is $$z = 2?3$$. Generator matrix is:
$$left(begin{array}{ccc}1&0&1\0&1&3end{array} right)$$

From options 203, 213 and 223, what was the sent codeword?

I tried multiplying vector $$u = (a;b)$$ by the generator matrix which would result in $$c$$ = (x y z) codeword (either 203, 213 or 223), but I got a failure on each try.

I know how to define actual sent codeword using parity check matrix, but I have no idea how to do it with generator matrix only.

Note: key says the correct answer is 223.

## css – A little help with coding problems

guys.

I’m doing a roleplay-based Tumblr page that will take as base this design: https://www.lecantiche.com/ (I already asked the creator, Emanuele Mila, for permission and got it; unfortunately, he’s very busy and can’t help me with this problem).

When I paste the code in my page, however, it looks like this:

https://thekabbalist.tumblr.com/teste

So what I’m doing wrong?

## workflows – Tool for live coding with collaborators

With `tmux` multiple users can connect to a window and see what people type even before execution of the command.

``````apt install tmux
tmux new -s mywindow
tmux attach -t mywindow
``````

I’ve started using Visual Studio Code with Remote SSH: https://code.visualstudio.com/docs/remote/ssh
With that you have the benefit of developing on your local machine but executing your program on a remote. That is especially useful if you are e.g. utilizing the GPIO of a Raspberry Pi.

I was wondering if there is an IDE/plugin that allows you to code on a remote server + immediately showing what you are writing live when someone connects to the remote.
I do not wish to screenshare because it consumes a lot of bandwidth and the quality can be bad. Furthermore the user cannot edit. I also do not want to share my PC because then I cannot do different things off-screen and there is the security aspect.