@Mat'sMug: I get your point. I've added a sentence to make clear that performance, too, is an important aspect in this problem. Yet I don't quite see how the provision of three basic options would make a review of the problem impossible? — simon4 mins ago
This meta-answer from @amon has the quote I'm looking for, but I'm not sure pointing the OP to that post would be helpful, given the meta-post's title:
I put a close-vote on your question, because it's not a good fit here. You are asking a whiteboard-style programming question about how you should design your classes. That's something that probably belongs on Programmers (but read through their help center first).
A good indication that you're...
> A good indication that you're not actually seeking a code review is that you phrased your question in a “Solution A versus Solution B – which is better” format. This is generally bad on Stack Exchange because such questions have a tendency to be more opinion-based than objective.
This is my solution for CodeEval challenge 44.
The function followingInteger takes a number in its decimal representation and returns the next higher permutation of the digits of the number. If there isn't a larger permutation of the digits, a '0' may be added to the digits:
ghci> followingInte...
I've been working on a 3D-vector class which should be as streamlined as possible for use in numerical simulations. It will be used to model 3D-physical vectors.
I hoped to design it in a modern and fast way - but one is never perfect. So, I would be interested in some input from your side.
Thank...
I'm new to Python and I'm wondering is there a way to streamline this clunky code I've written. Maybe a built-in function I've never come across before?
I run through two lists of binary numbers and if the same number appears at the same index in list one and two, do x.
So in the example below ...
Why do you separate questions and answers into two separate arrays? It seems to me that working with one array of question-answer pairs is much easier. But we'd have to see the code where you use those arrays to be sure.
Attached is a generic code I wrote to create an excel file with x amount of worksheets. The problem I am having is that it's pretty slow, like 5 seconds a sheet. It was my understanding that using a for loop when creating the tables was ideal, but the issue seems to be with tables containing over...
I'm working with AutoFac to do some DI. I think I've got a decent grip on things, but just ran into a question I had with my code and thought I'd check:
public class AutofacRegistrations
{
public static void RegisterAndSetResolver()
{
// Create the container builder.
var ...
I have a program that gets 5 random dice throws from random.org over and over. In order to avoid doing getaddrinfo() over and over with the exact same data, I moved some of the code to an initialization function (and an unused finalization function).
My issues are:
is this a bad idea?
can bad ...
I've occasionally seen "radar enforced" on speed limit signs, and I can't help but ask: How intense would radio waves have to be to stop a car from going over the speed limit, and what would happen if this were attempted? —joausc
> I've occasionally seen "radar enforced" on speed limit signs, and I can't help but ask: How intense would radio waves have to be to stop a car from going over the speed limit, and what would happen if this were attempted? —joausc
A tag was recently created for autofac, which is an IoC container. The question that created this tag is also correctly tagged with dependency-injection.
A long, long time ago I wanted to create a tag for ninject (another IoC container) but I didn't have enough rep back then, and dependency-inje...
In software engineering, inversion of control (IoC) is a programming technique in which a dependent object is coupled to the object it needs at run time. Which particular object will satisfy the dependency during program execution typically cannot be known at compile time using static analysis. While described in terms of object interaction here, the principle can apply to other programming methodologies besides object-oriented programming.
In traditional programming, the flow of the business logic is determined by objects that are statically bound to one another. With inversion of contro...
A tag was recently created for autofac, which is an IoC container. The question that created this tag is also correctly tagged with dependency-injection.
A long, long time ago I wanted to create a tag for ninject (another IoC container) but I didn't have enough rep back then, and dependency-inje...
@SimonAndréForsberg if DI is done properly, the IoC container has no importance, no one can even tell you're using an IoC container - dependency-injection applies. However the IoC configuration code is extremely container-specific. That was my point... should I edit?
I wrote a service object that emails a list of files to a list of email addresses.
I am unsure about my emails method. It splits a string into an array of emails. It then loops over the array and rejects any elements that do not match the email regex. The return value is an array of valid emails...
I have a bat. file that has been passed down a few times. If I run it on my PC it will reboot the remote server 'server04'. It is known to work on windows 2003 servers.
Complete code is below double click to run, left click and edit to reboot a different server on the next run.
shutdown -r -...
I have a bat. file that has been passed down a few times. If I run it on my PC it will reboot the remote server 'server04'. It is known to work on windows 2003 servers.
Complete code is below double click to run, left click and edit to reboot a different server on the next run.
shutdown -r -...
I personally think that my recent android answer is better than my recent custom indexOf() answer, but I suppose the indexOf question has gotten a whole lot more attention.
I wrote a couple reviews for this CR post. In my most recent review, I refactored @Malachi 's code to fit OO design. I'm looking for any advice/hints/criticisms on it.
Here is the entire dump:
using System;
using System.Collections.Generic;
using System.Linq;
namespace RPSLS
{
class Progra...
@BenVlodgi the playAgain variable and the loop it belongs to is a little weird. can't you make this ` playAgain = result == 0;` into this inside the while statement result == 0
@Malachi Yes you could if you declared result outside the loop... and that is probably what I should do, but I kept it this way to keep it more obvious why it should loop again
I spent a little time on this myself. In particular, I wanted to implement the Boyer Moore algorithm, which can be much, much faster than a brute-force approach.
However, in the end I concluded that IndexOf() likely uses optimized assembly language, which I simply couldn't been with any algorith...
@SimonAndréForsberg yes, that is a very good point. I originally implemented it that way when dealing with @Malachi 's list of strings which were int based. but then never realized to change it to using Gestures
@BenVlodgi I would write an answer if I didn't were rep-maxxed already, I can give that answer to @Mat'sMug (who probably would have other things to say as well)
@Malachi it is what I'm used to from my C days.. it doesn't really matter. butI like to mentally visualize a loss as bad so -1, a win is +1, and a tie is inbetween
The comments in the clearmem procedure for the Linux block look a bit confusing. You could just have a summary of the procedure commented above, and have the individual comments for each line specify the meaning of the assembly instructions.
Specifically, the lines that describe the C++ code d...
you have a lot of if statements in your SQL, this screams at me that you are doing something in your SQL that should be done in the application, and that this SQL should be separated into two distinct stored procedures.
the benefits
faster stored procedures
use an actual coding language to d...
one thing to start with.
I would get rid of your playAgain variable and replace the while statement like this
Original Code:
do
{
Game.Play(me, computer);
Console.WriteLine("Your scorecard: " + me.GetScoreCard());
int result;
do
...
▲sure I missed something that will break this, that always happens to me ▲
I was using setTimeouts for a project where a callback will be called after a duration, but the user has the options of extending, pausing or stopping the timeout. I felt using the default setTimeout was a bit clunky, especially since I needed to remember the timeout ids, and I decided to create ...
@SimonAndréForsberg And it's not even what Stack Overflow is about (referring to the comment of Jonathan Wood). Even at Stack Overflow people would ask about the same things that we do ...
I feel like this is auto-promotion of his article and I don't like it
@Jamal You should be able to use the vector instructions to write to the memory, regardless of the source syntax used to allocate it. That said, a pointer-based interface is simpler/more obvious from the assembly side of things. Honestly, the whole thing's generally pointless--std::fill_n will typically produce code that's plenty fast (and may even already use SSE/AVX instructions).
If you're zeroing memory often enough that even slow code to do it causes a significant bottleneck, chances are really high that you're doing something else wrong to need to zero memory that much/often.
@BenVlodgi you should have a would you like to continue inside of the if statement that will set the Result to one of the other choices.
@BenVlodgi I will check out the rest of the code again later. I just skimmed it all from the answer to my question, I will read the entire code tonight though.
I guess I am just thinking about it now, why would you reset your score if you are just going to quit anyway?
@JerryCoffin I've only once been exposed to assembly and C, so I was unsure about this one. I agree about the pointers, but I'm still in the C++ mindset regarding C-style arrays. :-) Your answer does have much good stuff, and I can learn from the assembly side of things.
I've been working on a 3D-vector class which should be as streamlined as possible for use in numerical simulations. It will be used to model 3D-physical vectors.
I hoped to design it in a modern and fast way - but one is never perfect. So, I would be interested in some input from your side.
//t...
@Jamal I looked at that earlier. My only guesses are that 1) he just doesn't know what he's talking about, 2) made a silly mistake, or 3) the "3D" reference is really to something like a single point in 3D space. But ultimately you're right: it's not a 3D vector (or really even similar to one either).
It is interesting how beginners often get very wrapped up in performance. I've lost count of the number of SO questions about "why is A so much faster than B", where the answer was: "because you compiled with optimization turned off." (and actually, optimization in general, with the compiler's optimization turned off).
There's one huge problem here: this is a 1D vector of size 3, not a 3D vector. This looks more like a single point in 3D space, while a 3D vector would have nested vectors (and that syntax would look rather nasty). Do you still want this reviewed as is? It could still help you in general. — Jamal23 secs ago
@Malachi do you think I shouldn't update the OP? I did because I didn't want people reviewing the previous crap... I know I could post a whole nother question, but I didn't think it was worth for such a small part of the code
you have a lot of if statements in your SQL, this screams at me that you are doing something in your SQL that should be done in the application, and that this SQL should be separated into two distinct stored procedures.
the benefits
faster stored procedures
use an actual coding language to d...
You guys will probably laugh at the way that I implemented this simple task. I know there is a simpler way of doing this but I just really cant think of it right now. Can you guys please help me out? A fellow member of stack exchange recommended me to the Code Review
Thanks in advance,
-Jia
...
I'm writing a simple remote PC app (mouse-keyboard).Android is client and it's connect with wifi to Java PC Server. I'm using TCP but I see a bit of latency compared to other remote apps. Then I used UDP and didn't see any latency or wrong data. UDP look like it's working well. I'm sending a Stri...
I was going to give both solutions in my answer but then before I could even finish one they were both up. And wow I forgot how annoying Maps in java are.
@Jamal Yup. I'm hoping that whoever answers that will not primarily focus about the TCP/UDP issue.
@BenVlodgi Yeah, I guess C# would just use a bit of LINQ here and it would be done. Perhaps @skiwi knows if there's a good new Java 8 technique that can simplify it...
@SimonAndréForsberg even just the sugar all over C# has spoiled me... like... with a Dictionary, counters['a'] instead of .get() which is also for some reason lowercase
You can iterate over the enum and insert each one individually.
for ( int i = FIXED_VOLTAGE1; i != FIXED_VOLTAGE4; i++ )
{
m_modules.insert(CreateAndUseIniFile::static_cast<iniFileValues>(i));
}
Note: This will work with your specific case... don't do this if you have enums with set values...
It is messy I know it. But what can I do for improve it? Why I'm getting latency , I think It's not about messy. Is it possible sending a string , server side or key press? — sallamaniaa4 mins ago
I've got the following code which was written for an exercise, and I'm looking for things to improve my general Scala style. What I currently have:
object Graphs {
case class Node[T](value : T)
case class Edge[T](from : Node[T], to : Node[T], dist : Int)
def shortest[T](edges : Se...
Here is my implementation of a simple 3 rotor Enigma machine in C++:
#include <iostream>
#include <cstring>
using namespace std;
char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char rotors[3][27] =
{
"EKMFLGDQVZNTOWYHXUSPAIBRCJ",
"AJDKSIRUXBLHWTMCQGZNPYFVOE",
"BDFHJLCPRTXVZNYEIWGAKMUSQO"
};...