# Tag Info

15

That looks crazy. But some constructive comments: Did you check for ssh-copy-id script, that is usually shipped with openssh? It solves for you the first part of your problem in standard way. The second problem is in my eyes non-existent. Do you really need your authorized_keys in all accounts? Isn't it enough for one user that can do sudo? The third is ...

11

I see some things that may help you improve your program. Use all of the required #includes The function strncpy is used but its declaration is in #include <cstring> which is not actually in the list of includes. Don't expose class internals The sections member data is a private data member, which is fine and appropriate, but then the get_sections()...

10

Interface I'm not overly fond of the interface you've defined to the function. I think trying to combine reading integers and reading strings into a single function makes it more difficult to use. For most C code, I think the old guiding principle of UNIX ("do one thing, and do it well") provides excellent guidance. As such, I'd probably have two ...

8

I would use something like perl -lane '@h{@F[1..$#F]}=()if/^Host\b/;END{$,=" ";print keys %h}' -- file or perl -lane '@h{ @F[ 1 .. $#F ] } = () if /^Host\b/; END {$, = " "; print keys %h; }' -- file -l removes newlines from input and adds them to prints -n runs the code for each line of the input -...

7

Here are some things that may help you improve your program. Use a state machine The approach you currently have uses bool variables keeping track things such as whether a section has been found, whether a character is the last one and weaves the interpretation int a long series of nested if statements. That approach may work for small, simple grammars ...

7

This version seems much improved. Good job! There are still a few things that might be further improved, which I list below. Avoid defining types that aren't used The config.hpp code currently contains this line: typedef std::pair<std::string, std::string> keyvalue; However, that type isn't actually used anywhere within the header. It's only ...

7

Just declare a (static readonly) dictionary: var values = new Dictionary<(DatabaseType, DomainType), DatabaseConfigType>() { { (DatabaseType.Type1, DomainType.Domain1), DatabaseConfigType.Type1Domain1 } }; Filled with all possible combinations. Then your function will be reduced to: DatabaseConfigType GetDatabaseConfiguration(DatabaseType ...

7

That's nutty, trying to address a server by a changing IP address. Reconfiguring the wiki to adjust to it is even crazier. The standard practice for adapting to dynamic IP addresses is to use a dynamic DNS service. Then, everything else works normally. Pick a hostname, like afuna.noip.com. Run a DDNS client to register your hostname whenever you acquire a ...

7

You are trying to recreate functionality that is already provided out of the box. Reference Configure an ASP.NET Core App From documentation it supports providers for INI, JSON, and XML. Each configuration value maps to a string key. There's built-in binding support to deserialize settings into a custom POCO object (a simple .NET class with properties)...

7

__func__ Unlike __FUNCTION__, __func__ is standard C since C99. Some compilers might not support C99 and therefore in those compilers you have to use whatever they provide, but if your compiler supports C99, you should use __func__. If you have a crappy compiler, think about using a better one. magic numbers What is a magic number, and why is it bad? ...

6

Looks good to me. A couple remarks: section* get_section(const std::string& sectionname); std::list<section>& get_sections(); Not so sure it is a good idea returning mutable pointers/references to the data, since changing a section in memory has no effect to the underlaying file representation. It could lead to misunderstandings. It is ...

6

Assuming you already have a class called Enchant (should be a superclass of your enchantments), you could use an enum to organize all of your enchantments: public enum Enchantments { MULTI_FIRE(1, "multifirearrow") { Enchant getEnchant() { return new MultiFireArrow(); } }, BOLT(2, "bolt") { Enchant getEnchant() { return new Bolt(); } ...

6

Use $(...) always There's really no good reason today to use ..., always use the modern$(...) instead. Avoid flags of echo The flags of echo, such as -n don't work consistently in all systems, so it's better to avoid them when possible. If you really don't want to print a newline, you could use printf, though it's not POSIX compliant. Checking that a ...

6

Definitely go with Method 1: There is no custom code to support. ConfigParser is part of the standard Python library; any programmer can easily look up its documentation to see how it works, if they weren't already familiar with it. URL normalization has no business being part of the configuration file parser. Including such normalization would violate ...

6

Notes: Quote your variables. Ref Security implications of forgetting to quote a variable in bash/POSIX shells Don't use ALLCAPS varnames. It's too easy to overwrite important shell variables like PATH. A2ENSITE=$A2A2ENSITE$HOST".conf" -- I don't see the A2A2ENSITE variable anywhere this is a perhaps a corollary of the ALLCAPS vars problem: they can be hard ...

6

Your program crashes when it reads a line from the parameters file that doesn't contain an = sign. The name of the macro TEXT is misleading. It doesn't contain a text but a filename. Whenever you output an error message, it belongs on stderr instead of stdout. To do this, replace printf( with fprintf(stderr,.

5

I'll start by agreeing with Mug that a ISettingsProvider should have a CurrentSetting property and simply also implement INotifyPropertyChanged. ApplicationData.Current.DataChanged += (a, o) => ... I like delegate expressions as much as the next guy, but it's not always appropriate to use one letter identifiers in them. I mean, we complain when people ...

5

public readonly int NewSetting; public SettingChangedEventArgs(int newSetting) { NewSetting = newSetting; } Notice how the code formatting is getting confused with NewSetting? It might be readonly, but it's still a public field you have here. An EventArgs class is a class like any other - there's no reason to not properly encapsulate its data. I like ...

5

The conditions to create keys The condition on the directory seems a bit excessive here: if [ ! -d "$HOME/.ssh" ] && [ ! -f "$HOME/.ssh/id_rsa" ] && [ ! -f "\$HOME/.ssh/id_rsa.pub" ]; then echo -e "Private / Public keys not generated" echo -e "Generating..." ssh-keygen -b 4096 fi My concern is that if the key files are missing ...

5

Since you’re willing to install third-party packages (I see a pip install -r requirements.txt step in your README), there are a couple of packages you can install that will probably be quite useful for your code. For secure config: consider keyring keyring provides an interface to the system keychain, so configuration is stored more securely than by mere ...

5

Style is always in the eyes of the beholder For a lot of cases you will get differing answers, for the problem at hand, parsing a file to produce an instance of a class representing the information there are a lot of different ways some coming down to -taste-. To help deciding between some of them it's always good to look at how it will be used. This review ...

5

configuration is usually accessed statically I have a different impression. Configuration is accessed in a way that is convenient in terms of maintainability and testing. And static references do not help in those areas. It is common to register settings in DI containers and either inject them directly or using some sort of wrapper (probably what you have ...

5

OpenChakraLinkPlusSaveNext() is a very long function, with its logic for incrementing, loading, and saving state scattered and duplicated all over the place. Functions should adhere to the Single Responsibility Principle, and do one thing only. Another problem is that the implementation is strongly tied to configparser. As a result, you need to put int() ...

5

Do you think this service is useful? I don't think it's possible to answer that question with the toy example given. IMO it doesn't shed any light on how you intend to use it for things like committing things to the database, saving files, sending emails, reading files, executing queries and and and... public FeatureService(ILogger<FeatureService&...

4

I don't have a whole lot to add, as this is pretty straightforward and seems like a completely reasonable way to do what you're trying to do. In regards to your questions: There's a tradeoff for using accessor methods for properties. Every time you add a new one, you need to add a constant to the Key struct, and add an accessor method to the Configuration ...

4

What kind of things are you looking to improve? Your solution looks pretty straightforward. The only problem with an ini file is that ColdFusion can't instantly/natively parse it. Whereas XML/JSON can be parsed directly into a Coldfusion Struct. <cfscript> public struct function loadini( required string configFile) { var stResult = {}; var ...

4

I generally don't like to add a second answer but the magnitude of what I'm gong to suggest is a lot greater than what I proposed previously, which doesn't appear to be enough. I pulled the entire source off of GitHub and what's really missing from your question is how you are "injecting" these dependencies. Specifically, you are newing a lot of stuff up in ...

4

I think a couple of Role interfaces would really help here. You need to do two things with your configuration load it save it so: public interface IConfigurationReader { Configuration ReadConfiguration(); } public interface IConfigurationWriter { void WriteConfiguration<T>(T configuration); } Obviously those names could be improved. You ...

4

Pardon my lack of Python knowledge, but I think a function something like this might work: def fatal_error(message): log.error(message) app_exit(1) And now your catch cases look more like this: try: root = get_root(xmlfile) except ET.ParseError as e: fatal_error("Error while parsing {0}: {1}".format(xmlfile, e)) except IOError as e: ...

4

Generally a parser can be modeled as a state machine. Think about what different expressions your grammar consists of. I don't know the INI spec but here is a suggestion for a section header: maybe_whitespace - zero or more tabs and/or spaces identifier - one or more (is there a maximum?) alphanumeric ASCII characters open_section_header - a "[" ...

Only top voted, non community-wiki answers of a minimum length are eligible