Questions tagged [flags]

Flags are atomic data structures used to identify state in a program.

A flag field is an integer interpreted as a sequence of boolean bits, each called a flag. A single flag has two possible states: 0, representing false or off, and 1, representing true or on.

This tag can be used for problems related to .

Source

Wikipedia

1473 questions
77
votes
11 answers

SameSite cookie in Java application

Do you know any Java cookie implementation which allows to set a custom flag for cookie, like SameSite=strict? It seems that javax.servlet.http.Cookie has a strictly limited set of flags which can be added.
Michal_Szulc
  • 4,097
  • 6
  • 32
  • 59
75
votes
6 answers

Enum flags in JavaScript

I need to emulate enum type in Javascript and approach seems pretty straight forward: var MyEnum = {Left = 1; Right = 2; Top = 4; Bottom = 8} Now, in C# I could combine those values like this: MyEnum left_right = MyEnum.Left | MyEnum.Right and…
Andrey
  • 20,487
  • 26
  • 108
  • 176
69
votes
11 answers

Correct way to check for a command line flag in bash

In the middle of a script, I want to check if a given flag was passed on the command line. The following does what I want but seems ugly: if echo $* | grep -e "--flag" -q then echo ">>>> Running with flag" else echo ">>>> Running without…
BCS
  • 75,627
  • 68
  • 187
  • 294
67
votes
3 answers

Enum flags over 2^32

I am using Enum flags in my application. The Enum can have around 50+ values, so values go up to 2^50. I was just wondering, can I use Math.Pow(2, variable) to calculate these? When I try to do that I get a constant value compile-time error. Is…
Charu
  • 2,679
  • 6
  • 35
  • 52
63
votes
1 answer

Material design layout_scrollFlags meanings

I find out that we can use cool flags that scroll both toolbar and even content by using layout_scrollFlags. In my case, I have a layout like this:
Mahdi
  • 6,139
  • 9
  • 57
  • 109
59
votes
11 answers

Switch on Enum (with Flags attribute) without declaring every possible combination?

how do i switch on an enum which have the flags attribute set (or more precisely is used for bit operations) ? I want to be able to hit all cases in a switch that matches the values declared. The problem is that if i have the following…
MartinF
  • 5,929
  • 5
  • 40
  • 29
55
votes
6 answers

How to disable a log.Logger

I have some heavily instrumented code that makes use of the log package. Now it's come time to turn off the logging, and I can't determine how to turn off the standard logger. Have I missed something? Should I be checking a flag before making log…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
52
votes
3 answers

Activity stack ordering problem when launching application from Android app installer and from Home screen

For testing purposes only, I am allowing my app APK to be downloaded and installed via a URL. Once downloaded on the phone, it can be launched with the Android app installer which gives the user an option to install it to their device and then run…
antonyt
  • 21,863
  • 9
  • 71
  • 70
52
votes
5 answers

Checking flag bits java

I have a problem with flag bits. I have an int variable to hold flags. First I set some flags to that variable. Later I need check how many flags were set in that variable. But I don't know to do it.
Nagaraju
  • 1,205
  • 2
  • 11
  • 12
49
votes
1 answer

What does regex' flag 'y' do?

MDN says: To perform a "sticky" search, that matches starting at the current position in the target string, use the y flag. I don't quite understand it.
DarkLightA
  • 14,980
  • 18
  • 49
  • 57
48
votes
3 answers

Should command line options in POSIX-style operating systems be underscore style?

Should the name of command line options for a program in a POSIX-style operating system be underscore-style, like --cure_world_hunger or maybe some other style? --cureworldhunger --cure-world-hunger --cureWorldHunger What's most common? What's…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
47
votes
10 answers

Enum.HasFlag, why no Enum.SetFlag?

I have to build an extension method for each flag type I declare, like so: public static EventMessageScope SetFlag(this EventMessageScope flags, EventMessageScope flag, bool value) { if (value) flags |= flag; else flags…
bevacqua
  • 47,502
  • 56
  • 171
  • 285
45
votes
2 answers

Python RegExp global flag

Is there a flag or some special key in python to use pattern multiple times. I used to test http://gskinner.com/RegExr/ my RegExp, it worked correctly in it. But when testing in correct enviorment match only returns None. import re pattern =…
Metsavaht
  • 618
  • 1
  • 7
  • 10
44
votes
4 answers

Removing Strikethrough from TextView

I'm using this line below in order to set a strikethrough on my TextView: tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); However later on in the Fragment, if they click the TextView again, I would like the strikethrough to be…
edwoollard
  • 12,245
  • 6
  • 43
  • 74
38
votes
8 answers

Flags in a database rows, best practices

I am asking this out of a curiosity. Basically my question is when you have a database which needs a row entry to have things which act like flags, what is the best practice? A good example of this would be the badges on stack overflow, or the…
Evan Teran
  • 87,561
  • 32
  • 179
  • 238
1
2
3
98 99