General purpose replacement for enum with FlagsAttribute

Enums with the FlagsAttribute have the disadvantage that you need to be careful when assigning their values. They are also inconvenient when you would like to allow the user of the library to add their own options. The enum is closed/final.

My alternative Option class should solve these two issues. It can be used either on its own or be inherited from. The two static Create factories take care of the Flag value for the specified Category. The Category groups options together. HasFlag is called here Contains. Other than this it also implements the usual set of operators and parsing.

[PublicAPI] [DebuggerDisplay(DebuggerDisplayString.DefaultNoQuotes)] public class Option : IEquatable<Option>, IComparable<Option>, IComparable {     private static readonly OptionComparer Comparer = new OptionComparer();      private static readonly ConcurrentDictionary<SoftString, int> Flags = new ConcurrentDictionary<SoftString, int>();      public Option(SoftString category, SoftString name, int flag)     {         Category = category;         Name = name;         Flag = flag;     }      private string DebuggerDisplay => ToString();      [AutoEqualityProperty]     public SoftString Category { [DebuggerStepThrough] get; }      public SoftString Name { [DebuggerStepThrough] get; }      [AutoEqualityProperty]     public int Flag { [DebuggerStepThrough] get; }      public static Option Create(string category, string name)     {         return new Option(category, name, NextFlag(category));     }      [NotNull]     public static T Create<T>(string name) where T : Option     {         return (T)Activator.CreateInstance(typeof(T), name, NextFlag(typeof(T).Name));     }      private static int NextFlag(string category)     {         return Flags.AddOrUpdate(category, t => 0, (k, flag) => flag == 0 ? 1 : flag << 1);     }     public static Option Parse([NotNull] string value, params Option[] options)     {         if (value == null) throw new ArgumentNullException(nameof(value));         if (options.Select(o => o.Category).Distinct().Count() > 1) throw new ArgumentException("All options must have the same category.");          return options.FirstOrDefault(o => o.Name == value) ?? throw DynamicException.Create("OptionOutOfRange", $  "There is no such option as '{value}'.");     }      public static Option FromValue(int value, params Option[] options)     {         if (options.Select(o => o.Category).Distinct().Count() > 1) throw new ArgumentException("All options must have the same category.");          return             options                 .Where(o => (o.Flag & value) == o.Flag)                 .Aggregate((current, next) => new Option(options.First().Category, "Custom", current.Flag | next.Flag));     }      public bool Contains(params Option[] options) => Contains(options.Aggregate((current, next) => current.Flag | next.Flag).Flag);      public bool Contains(int flags) => (Flag & flags) == flags;      [DebuggerStepThrough]     public override string ToString() => $  "{Category.ToString()}.{Name.ToString()}";      #region IEquatable      public bool Equals(Option other) => AutoEquality<Option>.Comparer.Equals(this, other);      public override bool Equals(object obj) => Equals(obj as Option);      public override int GetHashCode() => AutoEquality<Option>.Comparer.GetHashCode(this);      #endregion      public int CompareTo(Option other) => Comparer.Compare(this, other);      public int CompareTo(object other) => Comparer.Compare(this, other);      public static implicit operator string(Option option) => option?.ToString() ?? throw new ArgumentNullException(nameof(option));      public static implicit operator int(Option option) => option?.Flag ?? throw new ArgumentNullException(nameof(option));      public static implicit operator Option(string value) => Parse(value);      public static implicit operator Option(int value) => FromValue(value);      #region Operators      public static bool operator ==(Option left, Option right) => Comparer.Compare(left, right) == 0;     public static bool operator !=(Option left, Option right) => !(left == right);      public static bool operator <(Option left, Option right) => Comparer.Compare(left, right) < 0;     public static bool operator <=(Option left, Option right) => Comparer.Compare(left, right) <= 0;      public static bool operator >(Option left, Option right) => Comparer.Compare(left, right) > 0;     public static bool operator >=(Option left, Option right) => Comparer.Compare(left, right) >= 0;      public static Option operator |(Option left, Option right) => new Option(left.Category, "Custom", left.Flag | right.Flag);      #endregion      private class OptionComparer : IComparer<Option>, IComparer     {         public int Compare(Option left, Option right)         {             if (ReferenceEquals(left, right)) return 0;             if (ReferenceEquals(left, null)) return 1;             if (ReferenceEquals(right, null)) return -1;             return left.Flag - right.Flag;         }          public int Compare(object left, object right) => Compare(left as Option, right as Option);     } } 

This should replace the previous enum

[Flags] public enum FeatureOptions {     None = 0,      /// <summary>     /// When set a feature is enabled.     /// </summary>     Enabled = 1 << 0,      /// <summary>     /// When set a warning is logged when a feature is toggled.     /// </summary>     Warn = 1 << 1,      /// <summary>     /// When set feature usage statistics are logged.     /// </summary>     Telemetry = 1 << 2, // For future use } 

with

[PublicAPI] public static class FeatureOptionsNew {     public static readonly FeatureOption None = Option.Create<FeatureOption>(nameof(None));      /// <summary>     /// When set a feature is enabled.     /// </summary>     public static readonly FeatureOption Enable = Option.Create<FeatureOption>(nameof(Enable));      /// <summary>     /// When set a warning is logged when a feature is toggled.     /// </summary>     public static readonly FeatureOption Warn = Option.Create<FeatureOption>(nameof(Warn));      /// <summary>     /// When set feature usage statistics are logged.     /// </summary>     public static readonly FeatureOption Telemetry = Option.Create<FeatureOption>(nameof(Warn)); } 

that is based on a new FeatureOption type

public class FeatureOption : Option {     public FeatureOption(string name, int value) : base(nameof(FeatureOption), name, value) { } } 

They can be used exactly like classic enums:

public class OptionTest {     [Fact]     public void Examples()     {         Assert.Equal(new[] { 0, 1, 2, 4 }, new[]         {             FeatureOptionsNew.None,             FeatureOptionsNew.Enable,             FeatureOptionsNew.Warn,             FeatureOptionsNew.Telemetry         }.Select(o => o.Flag));          Assert.Equal(FeatureOptionsNew.Enable, FeatureOptionsNew.Enable);         Assert.NotEqual(FeatureOptionsNew.Enable, FeatureOptionsNew.Telemetry);          var oParsed = Option.Parse("Warn", FeatureOptionsNew.Enable, FeatureOptionsNew.Warn, FeatureOptionsNew.Telemetry);         Assert.Equal(FeatureOptionsNew.Warn, oParsed);          var oFromValue = Option.FromValue(3, FeatureOptionsNew.Enable, FeatureOptionsNew.Warn, FeatureOptionsNew.Telemetry);         Assert.Equal(FeatureOptionsNew.Enable | FeatureOptionsNew.Warn, oFromValue);          Assert.True(FeatureOptionsNew.None < FeatureOptionsNew.Enable);         Assert.True(FeatureOptionsNew.Enable < FeatureOptionsNew.Telemetry);     } } 

Questions

  • Is this as extendable as I think it is?
  • Are there any APIs missing that I didn’t think of or would be convinient?
  • What do you think about the automatic Flag maintenance and options creation?

General question on choosing an Assembly language based on my goal

So I know assembly is so big and it seems learning assembly is like learning high level programming, you don’t need to learn them all, you can learn couple and this will be enough.

The thing is with high-level language it is easier to grasp and implement in your life. But I am having hard time with assembly, I learned ARM at university, but I am not sure which version it was. And, it wasn’t practical in real life. Also, it was too primitive. It doesn’t even help me read other assemblies. Because when i read other assembly, I am lost seeing too many new commands that I have never seen before.

But I want to learn a language where I can add it to my code or make stand-alone version out of it easily like C++ or C# for Windows, so basically a practical language, also a language with live community and not an abandoned one. i learned some programming languages and they are useless for me like CLIPS, ADA and Prolog.

So what are the useful and practical assembly languages out there to learn for windows. Is FAsm a good start? Also note that I do not know what I want to do with it, I will learn it them when I get good command of it I will decide, I may use it for images, or AI project or anyother use where my path will lead. I already know C++ (i use it for UE4 and AI code implementations), C# (desktop/web) app and java (desktop).

Ordered module file naming in Python or in general

I do data science projects, and usually they require a general workflow. I tend to name my python scripts and local modules in an ordered fashion.

sec1_data_preparation.py sec2_prepped_data_import.py sec3_subject_selection.py sec4_analysis.py sec4a_analysis_demographic.py ...etc... 

When I need to import the module, I simply do

import sec1_data_preparation as data_prep import sec2_prepped_data_import as prepped_data_import 

I find it very easy to use where I can sort my files easily in the folder, and I know which stages of analysis I am needing when doing the import.

However, none of the python libraries I found in github named their files this way. I understand there maybe some cons about it (i.e., if I need a intermediate process, I will have to rename/reorder them all, but for the most part it’s very minor compared to the ease it brings). Does anyone know why this kind of file naming is not used more often?

iPhone 6s ios 12.3 general settings restrictions [duplicate]

This question already has an answer here:

  • How to remove restrictions in latest IOS? 1 answer

Good day, My “restrictions” folder in “general “ unable to access) It’s disappeared in “general “ settings. In search I can see search result as “restrictions” but unable to access this search result. Is it connected with update 12.3??? Symbol E appeared in music. I’m not sure regarding this symbol during usage 12.2. And my friend with 12.2 now has normal access to “restrictions” folder in “general” settings.

How can I compute the most general unifier for these two expressions?

I have the following first order logic expressions:

$ f(g(a, h(b)), g(x, y)),~f(g(z,y), g(y, y))$

and I want to compute the most general unifier for them. If I follow the algorithm found on these slides then I get the following.

\begin{align*} S_0 &= \{f(g(a, h(b)), g(x, y)), f(g(z,y), g(y, y))\}\ D_0 &= \{g(a, h(b)),g(z,y)\} &[\text{first disagreement set}]\ &\text{(need to unify these two functions)}\ D_0’&= \{a,z\} &[\text{first sub-disagreement set}]\ \sigma &= \{z=a\}\ D_0”&=\{h(b),y\} &[\text{second sub-disagreement set}]\ \sigma &= \{z=a, y=h(b)\}\ S_1 &= \{f(g(a, h(b)), g(x, h(b))), f(g(a,h(b)), g(h(b), h(b)))\}\ D_0 &= \{x,h(b)\} &[\text{second disagreement set}]\ \sigma &= \{z=a,y=h(b),x=h(b)\}\ S_2 &= \{f(g(a, h(b)), g(h(b), h(b))), f(g(a,h(b)), g(h(b), h(b)))\} \end{align*} No disagreement, unifier found! $ \sigma = \{z=a,y=h(b),x=h(b)\}$ .

However, this is not the most general unifier as we have $ \{y=h(b),x=h(b)\}\in \sigma$ , so i think the MGU should actually be $ \sigma’ = \{z=a,y=h(b),x=y\}$ .

Is this correct? When I use Prolog to unify them, it gives $ \sigma’$ . What did I do wrong in my following of the algorithm, so that it gave me a unifier that wasn’t the most general?

Find the general solution for this equation sin5θcos3θ = sin6θcos2θ.

I have tried to solve it but my is wrong. I did the following- $ $ using 2cosBsinA = Sin(a+b) + Sin (a-b)// 2sin5\thetacos3theta = 2sin6\thetacos2\theta// Sin 8\theta+ Sin 2\theta = sin8\theta+sin4\theta// Sin2\theta – sin4\theta = 0// Sin2\theta – 2sin2\thetacos2\theta=0// Case 1-// Sin2\theta=0// Sin2\theta=sin0//

\therefore \theta = nπ // Case 2-// 2cos2\theta =1 // Cos2\theta=\frac{1}{2}// \therefore \ theta = nπ \pm \FRAC{π}{6}// $ $

ASM source code explaination of a general payload such as shell_reverse_tcp.asm

these days i’m interested in learning how metasploitable payloads works deep down.

I’m not new to programming and luckly metasploitable comprehend a lot of interesting payloads with all the relevant source code.

However i’ve come across asm program (for example this one which i would like to understand and study) and i’ve had really little experience with assembly.

I was wondering if any of you could suggest me any lesson/tutorial which explain this and/or other programs.

I’ve already searched on the internet and i didn’t find any good resource and i really wanted to avoid trying to understand it with an asm book just by myself. Thank you.

Computing Deligne-Lusztig Characters in General

The goal for this question is to try to find a relatively explicit way of computing the Deligne-Lusztig characters. I understand that the $ R_{T,\theta}$ can be computed if we know the values of the Green functions. I also have a very basic understanding of perverse sheaves, but not tons of experience with geometric representation theory. I am struggling to read Lusztig’s Orange book and I was wondering if there was a more accessible/modern introduction to the theory?

For those interested, here are my main goals in understanding this: I am working in theoretical computer science, and am trying to find combinatorial methods to express these characters. For example, J.A. Green’s paper on the charcters of $ GL_n(\mathbb{F}_q)$ gives such a formula. The end goal is to be able to do this for all finite groups of lie type. From what I understand, Shoji-Lusztig give an algorithm based on the Springer correspondence, but I am still struggling on how to compute the so-called “Y” functions. In the case we can find a split unipotent element, from what I have read there is a method of computing these functions, but I am unsure of what to do in the non-split case. Honestly an overview article that summarizes most of this work would be quite helpful.