magic-numbers

Would These Be Considered Magic Numbers?

血红的双手。 提交于 2019-12-14 03:48:35
问题 I've just completed writing a program for a programming class, and I want to avoid use of magic numbers, so here's my question: In the function below, would my array indexers be considered magic numbers? Code: string CalcGrade(int s1, int s2, int s3, double median) { const int SIZE = 23; const int LETTER_GRADE_BARRIERS[SIZE] = { 400, 381, 380, 361, 360, 341, 340, 321, 320, 301, 300, 281, 280, 261, 260, 241, 240, 221, 220, 201, 200, 181, 180 }; double finalGrade; string letterGrade; finalGrade

Magic number for plain text file

℡╲_俬逩灬. 提交于 2019-12-12 12:06:05
问题 After googling, I found that Magic numbers can be used to identify the content type of a file. In my program, I would like to validate the file content type on server side. My client side code : <form action="/Home/Index" method="post" enctype="multipart/form-data"> <input type="file" id="inputFile" value="" onchange="readFileContent(this)" /> <input type="submit" value="Submit" /> </form> function readFileContent(input) { if (input.files && input.files[0]) { reader = new FileReader(); reader

How do I choose a good magic number for my file format?

不想你离开。 提交于 2019-12-12 07:44:27
问题 I am designing a binary file format from scratch, and I would like to include some magic bytes at the beginning so that it can be identified easily. How do I go about choosing which bytes? I am not aware of any central registry of magic numbers, so is it just a matter of picking something fairly random that isn't already identified by, say, the file command on a nearby UNIX box? 回答1: Stay away from super-short magic numbers. Just because you're designing a binary format doesn't mean you can't

Can you have magic numbers in Access 2007?

不打扰是莪最后的温柔 提交于 2019-12-11 05:35:35
问题 How do I store numbers in an Access column and then associate some meaningful string to each value? Because I don't want to be seeing raw numbers when I can define the meaning of each value once at for all, and have those meanings displayed in the Datasheet View, like: ID Name Type 1 Jack 1 (Friend) 2 Jill 1 (Friend) 3 Diago 2 (Enemy) 4 Sally 3 (Colleague) 回答1: You probably want at least two different tables. One that has the ID and Name of the people, and another table with the Type and

What config file format to use for user-friendly strings of arbitrary bytes?

核能气质少年 提交于 2019-12-11 03:10:50
问题 So I made a short Python script to launch files in Windows with ambiguous extensions by examining their magic number/file signature first: https://superuser.com/a/317927/13889 https://gist.github.com/1119561 I'd like to compile it to a .exe to make association easier (either using bbfreeze or rewriting in C), but I need some kind of user-friendly config file to specify the matching byte strings and program paths. Basically I want to put this information into a plain text file somehow: magic

About the magic number of PE

邮差的信 提交于 2019-12-11 01:19:45
问题 0x10b : PE32 executable 0×107 : ROM image 0x20b : PE32+ (64 bit) executable What is the ROM image ? 回答1: Interesting question, I've dabbled with manipulating PE files but never noticed that. Here's what I believe they are used for: A ROM image can be executed 'in place' (XIP), if you search MSDN for "rom image", you'll find a number of references to it in the Windows Mobile and older Windows CE tools, e.g. Rom Image Creation. A ROM image can thus be executed directly from the ROM without

How to identify the file type even though the file-extension has been changed?

廉价感情. 提交于 2019-12-10 11:24:36
问题 This question was migrated from Information Security Stack Exchange because it can be answered on Stack Overflow. Migrated 6 years ago . Files are categorized by file-extension. So my question is, how to identify the file type even the file extension has been changed. For example, i have a video file with name myVideo.mp4 , i have changed it to myVideo.txt . So if i double-click it, the preferred text editor will open the file, and won't open the exact content. But, if i play myVideo.txt in a

Gradle dependency causing error “Invalid Magic Number”

99封情书 提交于 2019-12-08 17:38:23
问题 I have a project on GitHub that I work on both in the office at home. For about 2 months it was working fine on both machines. Then two weeks ago, it stopped running on my home PC, but still works fine on my work PC . This is the error I get: :app:shrinkDebugMultiDexComponents FAILED FAILURE: Build failed with an exception. What went wrong: Execution failed for task ':app:shrinkDebugMultiDexComponents'. java.io.IOException: Can't read [D:\dev\gitRepo\app\android\app\build\intermediates\multi

Why are people using magic values instead of null in their code?

↘锁芯ラ 提交于 2019-12-08 16:18:25
问题 I have seen this in legacy code and in some .NET open source projects. I can't imagine a reason to do this. Just using "null" seems so much easier to me. Example: public class Category { int parentID; bool HasParent { get { return parentID != -1; } } } versus public class Category { int parentID; bool HasParent { get { return parentID != null; } } } 回答1: Because to have a "null" value, the type must be nullable. This works fine for reference types (any class you define and the standard

non-NULL reserved pointer value

*爱你&永不变心* 提交于 2019-12-08 03:06:27
问题 How can I create a reserved pointer value? The context is this: I have been thinking of how to implement a data structure for a dynamic scripting language (I am not planning on implementing this - just wondering how it would be done). Strings may contain arbitrary bytes, including NUL. Thus, it is necessary to store the value separately. This requires a pointer (to point to the array) and a number. The first trick is that if the pointer is NULL, it cannot possibly be a valid string, so the