Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read
Q&A

General Q&A about programming, scripting, software design & architecture, process, tools, testing, and more.

92%
+21 −0
What is HEAD in Git?

In Git documentation, there are lots of references to the term "HEAD". But what exactly is it? Some places refer to it as "a pointer to the current branch". So it's a branch? What is it used for?

1 answer  ·  posted 1y ago by hkotsubo‭  ·  last activity 3mo ago by hkotsubo‭

90%
+18 −0
What must a C compiler do when it finds an error?

What exactly must a C compiler do when it finds a compile-time error? The most obvious kind of errors are language syntax errors, but the C standard also speaks of constraints, which are rules tha...

1 answer  ·  posted 2y ago by Lundin‭  ·  edited 1y ago by ghost-in-the-zsh‭

90%
+17 −0
Should a salt be stored in the same database as the hash?

To protect against dictionary and rainbow table attacks it is well known that passwords should be salted before hashing. The salt (unique to each password) gets stored with the hash, often in the s...

3 answers  ·  posted 2y ago by jla‭  ·  last activity 2y ago by Canina‭

90%
+17 −0
Does the location of an import statement affect performance in Python?

When writing Python-based apps (e.g. Django, Flask, etc.), it's often the case that import statements can be found all over the place, often more than once for the same module. For example, you can...

1 answer  ·  posted 2y ago by ghost-in-the-zsh‭  ·  last activity 2y ago by ghost-in-the-zsh‭

88%
+14 −0
How should we share some content between two otherwise-independent git repositories?

We have two teams, dev and doc, and I'd like them to have shared access (via git) to a common subset of content. Specifically, I would like the examples that are used in the doc and that are scrip...

4 answers  ·  posted 2y ago by Monica Cellio‭  ·  last activity 2y ago by Monica Cellio‭

88%
+14 −0
What is the purpose of `if __name__ == '__main__'`?

I often see the construct if __name__ == '__main__' in Python code. For example, the queens.py demo in the Python repository ends with these two lines: if __name__ == "__main__": main() Ho...

1 answer  ·  posted 1y ago by J-hen‭  ·  last activity 1y ago by hkotsubo‭

87%
+12 −0
Why are list comprehensions written differently if you use `else`?

The following list comprehension worked when I tried it: [num for num in hand if num != 11] But this doesn't work: [num for num in hand if num != 11 else 22] which led me to believe that you ca...

1 answer  ·  posted 1y ago by true_blue‭  ·  last activity 1y ago by Moshi‭

87%
+12 −0
Is strcpy dangerous and what should be used instead?

I heard rumours that the strcpy function is dangerous and shouldn't be used. Supposedly it can be exploited to create buffer overflows somehow. And indeed when I compile my C code in the admittedl...

1 answer  ·  posted 1y ago by Lundin‭  ·  last activity 1y ago by J-hen‭

87%
+12 −0
What compiler options are recommended for beginners learning C?

When reading questions about C programming from beginners, I very often see them describing peculiar run-time errors and crashes, segmentation faults and similar. They have spent a lot of time chas...

1 answer  ·  posted 1y ago by Lundin‭  ·  edited 1y ago by Lundin‭

87%
+12 −0
Why is it considered bad practice to use float for representing currency?

This is intended to be a canonical post for this problem which is pretty common. Especially among beginners. I've heard that I should avoid using floating point variables for representing curren...

2 answers  ·  posted 1y ago by klutt‭  ·  last activity 1y ago by klutt‭

86%
+11 −0
Different behavior with relative imports when using flask vs py

I have a small new Python 3.8 Flask project with some relative import quirks. For the DB I use SQLAlchemy with Flask-Migrate. My project has the following general structure: controllers/ static/ te...

1 answer  ·  posted 2y ago by luap42‭  ·  last activity 2y ago by ajv‭

86%
+11 −0
Are there best practices for sticking conditions in WHERE clauses vs the JOIN statement?

Lets say I have two tables, A and B and I need to join a subset of them. Is there best practices of sticking the conditions in the WHERE clause like this, SELECT * FROM A JOIN B on a.fk_b = b....

2 answers  ·  posted 2y ago by Charlie Brumbaugh‭  ·  last activity 2y ago by klutt‭

86%
+11 −0
Can regex be used to check if input conforms to a very strict subset of HTML?

Tldr; I don't need to parse HTML, but I need to check if user submitted input conforms to a very strict subset of HTML. Can regex be a suitable tool for this? Details I have a frontend sanitiser th...

4 answers  ·  posted 2y ago by jla‭  ·  last activity 2y ago by Stephen C‭

86%
+11 −0
What is undefined behavior and how does it work?

I have created this sensational program: #include &lt;stdio.h&gt; int* func (void) { int local=5; return &amp;local; } int main (void) { printf("%d\n", *func()); } This prints 5 even thoug...

1 answer  ·  posted 2y ago by Lundin‭  ·  last activity 2y ago by Lundin‭

86%
+11 −0
Does using an Integer have any speed/performance benefits over a string in JSON

I'm working on an API to respond some data about a bunch of orders and items. The order and item numbers are always an integer (it's the order.id and item.id value, respectively). Originally the re...

3 answers  ·  posted 2y ago by Welz‭  ·  last activity 2y ago by .                                                .‭

86%
+11 −0
Should I check if pointer parameters are null pointers?

When writing any form of custom function such as this: void func (int* a, int* b) Should I add code to check if a and b are null pointers or not? if(a == NULL) /* error handling */ When po...

4 answers  ·  posted 8mo ago by Lundin‭  ·  last activity 8mo ago by Dirk Herrmann‭

86%
+11 −0
How do I support tab completion in a python CLI program?

I spend a lot of time writing CLI tools in Python, and I would like to support tab-completion in a style similar to Git. For example, subcommands should be tab-completable, options should expand ba...

1 answer  ·  posted 1y ago by ajv‭  ·  last activity 1y ago by hkotsubo‭

86%
+11 −0
What is malloc's standard-defined behavior with respect to the amount of memory it allocates?

I recently told a friend that malloc(n) allocates and returns a pointer to a block of at least N bytes of memory, as opposed to exactly N; that it is allowed to allocate 'extra' memory to meet e.g....

2 answers  ·  posted 12mo ago by ajv‭  ·  last activity 11mo ago by bta‭

85%
+10 −0
What does the static keyword do in C?

What exactly does the static keyword do in C? I have seen it used in several diverse contexts: 1) As a variable outside a function: #include &lt;stdio.h&gt; static int x = 5; int main (void) ...

1 answer  ·  posted 1y ago by Lundin‭  ·  last activity 1y ago by Lundin‭

85%
+10 −0
How to manage user-specific application data on Linux?

I am developing an application that targets Linux-based OS, and I need to store the user's configuration, metadata and other things in a persistent way (i.e. on the file system). I know that one c...

3 answers  ·  posted 4mo ago by Björn‭  ·  last activity 4mo ago by celtschk‭

85%
+10 −0
What does the "\s" shorthand match?

I've seen some regular expressions (regex) using \s when they want to match a space, but I noticed that it also matches line breaks. Example: the regex [a-z]\s[0-9] (lowercase ASCII letter, follow...

1 answer  ·  posted 1y ago by hkotsubo‭  ·  last activity 11mo ago by hkotsubo‭

85%
+10 −0
Scheme for cross-platform warning control?

tl;dr I'd like to learn a compact, cross-compiler way of selectively suppressing compiler warnings. Consider the case where you really mean to make an exact floating-point comparison using ==, o...

1 answer  ·  posted 2y ago by dmckee‭  ·  last activity 2y ago by Someone‭

85%
+10 −0
Destroy std::mutex referenced but not owned by std::unique_lock?

Is it correct to destroy a mutex which is referenced but not owned by an unique_lock as in this code? { std::unique_ptr&lt;std::mutex&gt; mutex = std::make_unique&lt;std::mutex&gt;(); std::u...

1 answer  ·  posted 2y ago by Estela‭  ·  last activity 2y ago by Angew‭

c++
85%
+10 −0
How to do private encapsulation in C?

I'm using an object-oriented design for my C project and trying to implement classes with private encapsulation. How do I do this? Some things I've tried that are problematic: Using a struct f...

1 answer  ·  posted 1y ago by Lundin‭  ·  last activity 4mo ago by Lundin‭

84%
+9 −0
Behavior of Pointer Arithmetic on the Stack

Consider the following code: #include &lt;stdio.h&gt; int main() { int a = 5; int b; ++*(&amp;b + 1); printf("%d\n", a); return 0; } The output is as expected: 6 ...

4 answers  ·  posted 12mo ago by Josh Hyatt‭  ·  last activity 11mo ago by Alexei‭

84%
+9 −0
Vim: how to search for all instances of a string, except for those that are between two specific strings

Using Vim, I am trying to search for all instances of a specific string, except for those that fall somewhere in between two other specific strings. For example, I want to determine all instances ...

2 answers  ·  posted 6mo ago by Trevor‭  ·  last activity 6mo ago by Dirk Herrmann‭

83%
+8 −0
How to delete contents of a specific field, if it matches a pattern and there is nothing else in the field

How do I delete contents of a specific field, if it matches a pattern, and there is nothing else in the field? I have a several GB tsv file, and I am interested in a specific field (72). If it cont...

3 answers  ·  posted 8mo ago by LVx0‭  ·  last activity 8mo ago by Dirk Herrmann‭

83%
+8 −0
Are there references in C?

When reading posts at programming sites such as this one, I frequently encounter people saying things like: "There is no pass-by-reference in C, everything is passed by value." People claiming su...

4 answers  ·  posted 10mo ago by Lundin‭  ·  last activity 10mo ago by klutt‭

83%
+8 −0
Is it dangerous to use json.loads on untrusted data?

I manage a wsgi application that accepts JSON data via POST from potentially untrusted sources. Normally it is treated as a text blob and never parsed, but there is a value in the expected input th...

1 answer  ·  posted 1y ago by ajv‭  ·  last activity 1y ago by hkotsubo‭

83%
+8 −0
Is it possible to undo a git reset?

For some reason, I just wanted to undo a commit on my git repository, which I've done with the following command: git reset --soft HEAD~1 So far, so good. However, by mistake I issued the comma...

2 answers  ·  posted 6mo ago by celtschk‭  ·  edited 6mo ago by Alexei‭

83%
+8 −0
Why does Firefox block based on a restrictive default-src directive, when more specific, more permissive *-src exist?

I am working on a website which unfortunately uses a mix of linked and inline CSS and Javascript (and, even more unfortunately, I can't do a lot about the use of inline CSS and Javascript), and am ...

1 answer  ·  posted 1y ago by Canina‭  ·  last activity 1y ago by Moshi‭

83%
+8 −0
Path separator for Atom / JavaScript on Windows

I have developed an Atom package which calls SyncTeX (a utility for reverse lookup for LaTeX), and then opens in Atom the file specified in the SyncTeX response. I'm developing on Linux, but now a ...

0 answers  ·  posted 2y ago by A. Donda‭  ·  last activity 1y ago by Kevin M. Mansour‭

83%
+8 −0
How to set text-align for whole column of HTML table?

To start off, here is the complete HTML of a simple example table: &lt;html lang="en-US"&gt; &lt;head&gt; &lt;title&gt;Title&lt;/title&gt; &lt;style&gt; table { width: 20em; ...

2 answers  ·  posted 1y ago by Olin Lathrop‭  ·  edited 1y ago by Alexei‭

83%
+8 −0
For scripting what are the pros and cons of command line arguments versus capturing input at the start?

Let's say I have a script that needs the user to set X number of variables at the start. One can either Pass the arguments in on the command line. Start the program and then have the user input th...

3 answers  ·  posted 2y ago by Charlie Brumbaugh‭  ·  last activity 2y ago by klutt‭

83%
+8 −0
Is there a way to estimate the execution time of a statement in MySQL?

From time to time I will have large structural changes to make on my MySQL DB, things like adding columns, changing datatypes, adding indexes etc. These types of changes result in downtime and what...

1 answer  ·  posted 2y ago by Charlie Brumbaugh‭  ·  last activity 2y ago by meriton‭

83%
+13 −1
What's the correct way to merge a branch and its dependent branch back to master?

In git I branched feature-A from master. To reduce eventual merge conflicts later, I branched feature-B, which heavily overlaps and depends on A, from feature-A. A build of the feature-B branch s...

2 answers  ·  posted 1y ago by Monica Cellio‭  ·  edited 11mo ago by hkotsubo‭

83%
+8 −0
Is MISRA-C useful outside safety-critical and embedded programming?

When discussing best or safest C programming practices with various C gurus on the Internet, the "MISRA-C guidelines for the use of C language in critical systems" often pops up as a source. This ...

1 answer  ·  posted 2y ago by Lundin‭  ·  last activity 2y ago by ghost-in-the-zsh‭

83%
+8 −0
How can I emulate regular expression's branch reset in Java?

I've got this sample regex: Pattern p = Pattern.compile("(?:([aeiou]+)[0-9]+|([123]+)[a-z]+)\\W+"); It basically has the following parts: one or more lowercase vowels ([aeiou]+), followed by one ...

2 answers  ·  posted 2y ago by hkotsubo‭  ·  last activity 1y ago by hkotsubo‭

83%
+8 −0
Should I cast to (void) when I do not use the return value

I saw at least one compiler (Codewarrior for HC12) warn me if I use a function without using it's return value. Other compilers (clang/gcc) do not issue a warning though, even when using the std=90...

3 answers  ·  posted 2y ago by Kami‭  ·  edited 2y ago by Monica Cellio‭

83%
+8 −0
Is `uint8_t` always an alias for a character type if it exists?

Is uint8_t guaranteed to be a character type if it exists? Will using a uint8_t* to examine bytes of an object cause violation of the strict aliasing rule? Is the following legal code: #include &l...

1 answer  ·  posted 1y ago by Ayxan Haqverdili‭  ·  edited 1y ago by Lundin‭

83%
+8 −0
What is CPU endianness?

I was fooling around with the following C code on my trusty old x86 PC: #include &lt;stdint.h&gt; #include &lt;stdio.h&gt; int main (void) { uint32_t u32 = 0xAABBCCDD; uint8_t* ptr = (u...

1 answer  ·  posted 2y ago by Lundin‭  ·  last activity 2y ago by Lundin‭

83%
+8 −0
How to override default string formatter?

It is possible to create a new formatter class by subclassing string.Formatter class and then to use it like myformatter.format("{foo:customformat}", foo=foo). It's not super-convenient though, and...

1 answer  ·  posted 2y ago by luser‭  ·  edited 2y ago by Alexei‭

83%
+8 −0
Why don't format specifiers work with lists, dictionaries and other objects?

When I want to print a number or a string, I can use f-strings (Python &gt;= 3.6) or str.format, and I can use just the variable between braces, or use format specifiers. Ex: num, text = 10, 'abc' ...

1 answer  ·  posted 2y ago by hkotsubo‭  ·  edited 2y ago by sth‭

83%
+8 −0
How can I define a method on [&mut T] where T: MyTrait?

I'm trying to make a trait method callable on mutable slices of a type implementing that trait (see main). Rust doesn't like me for it. use core::convert::AsMut; trait A { type B; fn f(m: ...

1 answer  ·  posted 2y ago by wizzwizz4‭  ·  last activity 2y ago by r~~‭

83%
+8 −0
How do I find the order that yields the shortest path?

The Problem I have a path optimization problem that in some ways reminds me of the Traveling Salesman Problem, but differs in some key respects. I have a group of items that need to be used by a m...

1 answer  ·  posted 2y ago by matthewb‭  ·  edited 2y ago by matthewb‭

82%
+12 −1
What is the difference between operator precedence and order of evaluation?

When doing something simple such as this int a=1; int b=2; int c=3; printf("%d\n", a + b * c); then I was told that operator precedence guarantees that the code is equivalent to a + (b * c)...

1 answer  ·  posted 2y ago by Lundin‭  ·  edited 2y ago by Lundin‭

81%
+7 −0
Function call; `this` gets bound to unexpected value

I recently encountered a strange situation in javascript; if I have: let obj = { a: function() { return (this === obj) ? this.b : 'bye'; }, b: 'hello' }; I can call obj.a with this bound...

2 answers  ·  posted 2y ago by Gershy‭  ·  last activity 2y ago by Alexei‭

81%
+7 −0
SQL timestamp for daylight saving day when clock goes 1 hour back.

On 25th October 2020 in Europe/Berlin clocks where set back from 03:00 AM to 02:00 AM to change from summer time (CEDT) to winter time (CET). Which means there is a 1 hour separation between 02:30...

1 answer  ·  posted 1y ago by Estela‭  ·  last activity 1y ago by hkotsubo‭

81%
+7 −0
What's the difference between placing <script> in the <head> and placing in the <body>?

While learning JavaScript, I started to see sometimes the &lt;script&gt; is placed in the &lt;head&gt; and sometimes it is placed in the &lt;body&gt;, What's difference between placing the &lt;scri...

1 answer  ·  posted 1y ago by Kevin M. Mansour‭  ·  last activity 1y ago by Kevin M. Mansour‭

81%
+7 −0
Pros and cons of various type_traits idioms

My work tasks have recently started requiring me to use the type_traits header to restrict the classes that may be used in template functions, methods, and classes. And while I used it for a long t...

1 answer  ·  posted 2y ago by dmckee‭  ·  edited 2y ago by Marc.2377‭