« first day (2696 days earlier)      last day (35 days later) » 

12:00 AM
RELOAD! There are 6999 unanswered questions (89.7635% answered)
12:35 AM
Also, if your code works and you're simply asking for peer review to improve it, you should ask at Code Review instead. It was created specifically for that purpuse. — Ken White 14 secs ago
@Peilonrayz I looked at the edit history before I posted the comment. It got one more down vote after I made the comment.
@pacmaninbw Just wanted to ensure you have all the information I had :) Yeah I don't get it, but oh well.
12:58 AM
Q: Animal, Dog, and IDangerous - Using interfaces and inheritance with C#

tommy99I'm quit new to object-oriented C#. I wanted to test my knowledge by creating a Dog/Animal classes. I also tried to implement an IDangerous interface in my code. Is there anything I could've done better/differently? Again, this is my first time on this stack exchange so if I could've restructured...

1:10 AM
@Peilonrayz Hopefully the answer provided will slow down the down votes.
7 hours later…
8:05 AM
Thank you @gman, awesome suggestion. I converted the code to a snippet. I was thinking that maybe 1) in itself is more of a CodeReview question, but the spirit of 1) 2) 3) as a whole fits StackOverflow better I think. — damix911 31 secs ago
1 hour later…
9:14 AM
Q: Rust Beginner: flatten nested matches

Kerry PerretThis is how I implemented the guessing game - chapter 2 of the Rust book: https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html use std::io; use std::io::Error; use std::cmp::Ordering; use std::num::ParseIntError; use rand::Rng; enum MyReadLineError { FailReadLine(Error) } #[...

1 hour later…
10:24 AM
@Peilonrayz @pacmaninbw LQ question, no effort. It's on-topic so it won't be closed, but that doesn't make it a valuable question.
10:53 AM
Q: Product landing page using flexbox

Tushar AgrawalThis is my first time making any web page from scratch on my own. I have used a flexbox for making it responsive. I have done it but not sure if I have done it the correct way. I read somewhere that we should minimize the use of @media if we are using flexbox. How can I do it? In my code I have u...

As interesting as this problem is, code review questions are not on-topic on Stack Overflow. — halfer 6 secs ago
(Generally I recommend that code review questions are at least accompanied by an attempt, otherwise it looks like a request for someone else to do it - not ideal when the audience is volunteers). — halfer 27 secs ago
11:40 AM
possible answer invalidation by Parvathirajan Natarajan on question by Dejan Samardzija: codereview.stackexchange.com/posts/249545/revisions
11:59 AM
@Mast I'm not sure it's -5 worthy. But then again if it were it'd probably have gone hot.
@pacmaninbw It seems not :)
@Peilonrayz Well the code does not work if you look at the other answer and the last comment posted. @Mast LQ for sure.
@pacmaninbw Was this in response to the comment before the one you linked to?
@Mast @Peilonrayz I've removed my comment because there is a better comment now that explains the down vote.
@Peilonrayz Yes
Q: Get the prime factors of a number

Subhadeep BanerjeeMy solution runs properly and I have tested it against various test cases. Is this the best approach? #include<stdio.h> #include<math.h> int primefactors(int); int main() { int num; printf("Enter a no:-\n"); scanf("%d",&num); printf("%d",primefactors(num)); return 0; } int pri...

I'll leave the answer for now.
12:19 PM
@pacmaninbw If you want to close the question then check the first say 10000 numbers and see if any of the results are right. If none of them are then we can just say "My solution runs properly and I have tested it against various test cases." is a lie.
If you want to prove yourself with say a code block or more than the 12 characters comments allow, you can post a CW answer as 'an extended comment'.
12:55 PM
You might want to post this to codereview.stackexchange.com as well — Jasmijn 12 secs ago
1:08 PM
@Peilonrayz Tested on 2 through 100, it fails on any power of 2, returning an uninitialized value for the last 2. Example input = 16 output 2 2 2 UB.
@pacmaninbw So it has a 6/7% failure rate? That seems like an edge case to me
It's 7% if you're counting 1 as a power of 2.
Very predictable, and the compiler actually generates a warning for it, not all paths return a value.
Yes 7%.
Enough to crash an airplane.
But not enough to say that the OP lied.
1:26 PM
@Peilonrayz OP didn't lie, just didn't test any power of 2. ;)
Can you verify "return value looks undefined for many values of n. What is the required output for, say, 126?" Was 126 a typo for 128?
@Peilonrayz Updated my answer at the bottom. I think you're correct about 126.
Ah the comment made me think there was potentially way more then a 7% failure rate in the 1-100 space.
Interestingly, or not, the failure rate tends towards 0. So if one were to take a big enough sample they could say "I have a 0% failure rate" ;)
Yes but the code is limited to integers, doesn't use long or long long, since it is a finite space it would never reach zero, just come close.
Oh yeah I forget Python is IIRC the only language with unbounded ints. If max int is 2^15 - 1 then the failure rate is 0.046% say limit the dp to 1 and you've got the magic 0% :)
1:45 PM
@Peilonrayz it's not...
haskell is another one
@Peilonrayz Did you have anything to do with coding for the Boeing 737 Max?
@Vogel612 Oh, that's pretty cool. Thanks
@pacmaninbw lol
@Vogel612 I'm reading up on this and it seems Int is bounded in Haskell
I assume I'm misunderstanding something
Ah found it it has an Integer type which is unbounded.
2:36 PM
Q: Reading all data from socket with poll()

iuhgfdtyuihjkjhgI have made a program to read all data from a socket in C++ but i feel like the code is inefficient and ugly. Anyway of improving it would be appreciated. Here is the code: std::string recvAll (void) { bool rd = false; // For the purpose of replicating...

3:24 PM
@Peilonrayz Where do you think they got the name stack overflow?
Q: Filter a database table in Ruby, migrating code to Postgres

Eyeslandic# Users | id | name | age | | ----- | -------- | ---- | | 1 | Rand | 25 | | 2 | Mat | 24 | | 3 | Perrin | 23 | Given the above table I've been building queries against it in Rails with the basic stuff which works quite well. The real application has about 10...

@pacmaninbw I would presumed that is not an artificial limitation, but a limitation due to running out of actual space.
@Peilonrayz Yes. Early Unix systems had a hardware limit that wasn't enforced in the software.
I wrote a N Queens program in Pascal at the university using recursion, resulted in stack overflow.
64K deep
CDC Cyber 170-750, super computer of the time.
So C now has a software limitation on stack sizes? I can imagine that was 'fun', one of my projects died cause I misused recursion.
I would bet that any check is implemented in the Kernal.
Or at least the Kernal provides the limit.
@Peilonrayz Very easy to do.
3:34 PM
I would presume that's reasonably close to a hardware limit and so isn't anything like Python's 1k depth limit. You use recursion for control flow once and your program might as well be a dead Python walking.
Perhaps it is limited because they are already using recursion to implement other things.'
Possibly, but I have a small feeling that's not the case. Python and FP don't really play ball. As such I think my cynical view that an artificial limitation to the stack and the lack of TCO are merely ways to kill FP.
Sorry, FP? Frame Pointer?
sorry, FP = Functional Programming, TCO = Tail Call Optimization
FYI, the CDC Cybers were designed by Cray before he started his own company.
4:03 PM
@CaptainObvious MRC, really not enough code to help optimize.
Why in the world is the poster using malloc in C++?
@pacmaninbw Ah I thought you only replied here. Thank you for the reply on Main too :)
@Peilonrayz Couldn't say everything I wanted to say on main.
Like where SO came from.
@CaptainObvious Also not sure the poster is the original author of some of the code since so much of it is C rather than C++.
@pacmaninbw Thank you for the comment, helped me see it through your eyes. Yes with so much missing I have voted MRC too.
@Peilonrayz Hoping the author will update with more code, could be an interesting question.
I’m voting to close this question because SO is not a code review service. — wwii 12 secs ago
4:14 PM
@pacmaninbw Ah, that'd be nice :D
@Duga Eh, wwii isn't really talking about us. I'll leave it.
@Peilonrayz This function is clearly a member of a class, so your edit is off. The use of the this pointer will only work within a class.
Code Review is a better site for this type of question. But it's expected that you post actual code there and ask specific questions about areas you are not sure about. — bfris 17 secs ago
@pacmaninbw The 4 levels of extraneous indentation cause the code to be impossible to read without vertical scrolling. I will accept that it is not 100% accurate, however I believe the negative experience reading the question out weighs purity.
What am I saying vertical for, that's meant to be horizontal. Silly me
They really need to post the entire class to make the question good. FYI, while bzero() isn't defined within the scope it is defined by a standard C header file. It stands for zeroing out memory, however, memset() should be used instead.
The reason I would like to answer it is because so much of the code is C rather than C++, it should be using new rather than malloc() and realloc().
@bfris Code Review does not expect "specific questions about areas you are not sure about." You are certainly correct about the former - "it's expected that you post actual code there". — Peilonrayz 22 secs ago
4:23 PM
@Peilonrayz At least Duga catches you sometimes.
@pacmaninbw lol yeah XD
@pacmaninbw I do not disagree. I don't believe my edit inhibits that.
@Peilonrayz OK, I have also removed my comment from this and retracted my VTC Up to you if you delete your comment or not.
@pacmaninbw What comment :)
Don't know what I was talking about.
1 hour later…
5:38 PM
@Peilonrayz Do you have any experience with difflib or similar?
@Mast Yes, a very small amount. I don't like the output nor is it an executable module so I don't really use it.
Is there anything I could help you with in particular?
I'm looking for Intersections between texts, SE posts.
No Lehvenstein distances or anything to note they're similar, but actual text intersections.
And I think the SequenceMatcher of that library would help, but I have a tendency of using the wrong tool for the job.
Are you looking for a line by line or char by char diff?
Eh, char by char. Matches can be entire lines, but if it's only 3 words I want that too. Let me whip up a quick example.
Yeah I think SequenceMatcher would be adequate
5:48 PM
Say we got the following texts.
> <p>Technology has improved a lot in the last two decades and when we talk about technology vs technology than we are talking about the improvement in the process because there is no competitors of technology till date <a href="https://exampledomain.com/category/technology/" rel="nofollow noreferrer">Read More</a></p>
> <p>So if you're the one who is looking to build an online business or looking to do something online form home so you gonna need versatile ideology and definitely some gas to start a business to stay updated for new business ideas <a href="https://exampledomain.com/category/business/" rel="nofollow noreferrer">Click here</a></p>
Expected output:
Something like that.
Possibly with multiple posts at once.
And highlighted differently, I'm only interested in what's matched.
But that's details.
Are you interested in the red and green highlights, not the plain unchanged stuff?
Yeah I think you can do it fine with SM I'll whip something up quick
@Peilonrayz I'm interested in the unchanged stuff.
The tool I used works the other way around, but effectively it gets the same thing done...
@Mast fighting some spam?
@Vogel612 Yup. The idea is to smack some similar posts together and hopefully get a decent 'base' out of it that's in all of them.
Yeah seems perfect for that
5:55 PM
Or most of them.
import difflib

a = 'foo baz'
b = 'bar baz'
for ai, bi, size in difflib.SequenceMatcher(a=a, b=b).get_matching_blocks():
    print(f"{a[ai:ai + size]!r} = {b[bi: bi + size]!r}")
Sometimes it's easy to see the similarities, other times not so much.
' baz' = ' baz'
'' = ''
might also be interesting to compare how spam for a certain domain evolved over time, if at all
@Vogel612 If I get something going, I totally expect more-experienced users to run with it and do all kind of fancy things with it.
Like that.
5:57 PM
yea, the stuff that Undo, Makyen, Art and the other Smokey Veterans can do is a sight to behold
Glorfindel is also a candidate for building magic out of scraps and duct tape :D
@Peilonrayz Awesome, thanks!
I like how SM has ratio, quick_ratio and real_quick_ratio as methods XD
@Vogel612 Indeed.
import difflib

def main():
  a = 'foo baz'
  b = 'bar baz'
  c = "<p>Technology has improved a lot in the last two decades ahead"
  d = "<p>So if you're the one who is looking to build an two decades ago"
  for ai, bi, size in difflib.SequenceMatcher(a=c, b=d).get_matching_blocks():
      print(f"{c[ai:ai + size]!r} = {d[bi: bi + size]!r}")

'<p>' = '<p>'
'o' = 'o'
' i' = ' i'
'r' = 'r'
'e' = 'e'
' the ' = ' the '
'l' = 'l'
'a' = 'a'
' two decades a' = ' two decades a'
'' = ''
Cut-off everything under a usability threshold and it looks like a winner.
I like how easy it is to get the non-matching stuff too. Actually I like the library a bit more now.
import difflib

def all_blocks(a, b):
    ap, bp = 0, 0
    for ai, bi, size in difflib.SequenceMatcher(a=a, b=b).get_matching_blocks():
        yield a[ap:ai], b[bp:bi]
        yield a[ai:ai + size], b[bi: bi + size]

for a_delta, b_delta in all_blocks('foo baz', 'bar baz'):
    print(f'{a_delta!r}, {b_delta!r}')
Oops forgot to update ap and bp...
That's some wizardry.
6:08 PM
I was wondering why it always ends with a match even if it's empty, and realized it's to allow this algorithm to work without some jank at the end.
I'll experiment a bit with it, there'll probably be a CR question eventually.
That could be a pretty interesting question you have there Mast :)
To make it really elegant, you should stop execution as soon as possible after the first exception occurs. Why should you catch many exceptions, if the first one is always the most relevant? You also should post this question on code review stack exchange, because there it would fit first, because this does not really is a coding 'problem'. — Markus Zeller 11 secs ago
6:24 PM
@Peilonrayz Could be, we'll see :)
Basically it's applied set theory.
In mathematics, the intersection of two sets A and B, denoted by A ∩ B, is the set containing all elements of A that also belong to B (or equivalently, all elements of B that also belong to A). == Notation and terminology == Intersection is written using the sign "∩" between the terms; that is, in infix notation. For example, { 1 , 2 , 3 } ∩ { 2 , 3 , 4 } = { 2 , 3 } {\displaystyle \{1,2,3\}\cap \...
Venn diagrams on posts.
Possibly it could be improved using Gestalt Pattern Matching, but I'll save that for a (much) later date.
I don't think SM does that yet.
@Mast SM? Smoke monitor?
@Peilonrayz SequenceMatcher
Our smoke monitor is called SmokeDetector, SD.
Or Smokey.
Ah, smoke monitor did sound kinda wrong XD
Well, SM is kind-of an awful abbreviation.
I know I know D:
@Mast FWIW if Wikipedia's algorithm & text is anything to believe SM does Gestalt Pattern Matching
I've verified with the source of difflib in 3.10.0_a0
6:32 PM
Oh, that means I either missed something or misinterpreted something.
Saves me a worry.
Looks like it's the perfect tool for the job :D
Looks like it.
Maybe I'm not as bad at this as I thought.
Yeah that makes sense I think I can understand why you'd use Gestalt Pattern Matching, because I don't think they'll all converge to one point. But may converge to different similar styles. Figuring that out seems fairly complicated so I'll leave it to you :)
That's why I want to automate it, it's not at all easy sometimes to do it by hand.
I mean, when there are hyperlinks involved to domains that happen to be the same, it's easy. But sometimes it's more complicated than that.
@Mast Imposter syndrome?
6:37 PM
@Peilonrayz Possibly. But if you knew my full career history, I'm sure you'd understand.
I've been a developer for a full 2 months. I write a lot of crap for a lot of crappy situations, at a crappy speed.
@Mast Makes sense. If you need a hand at all, just give me a shout :D
I learned Python a few years ago simply because that's what they used at that gig, otherwise I'd still be stuck with C++ and VBA.
Or Basic.
shudders in 010 BASIC
@Peilonrayz Now I know how easy it is, I'm going to write a spec to test against. You've been a tremendous help already.
Q: PHP API REST with Value Objects - How to log ALL exceptions to a Error array and render it to user?

Lautaro AguirreI am developing an PHP API REST using Value Objects. I have some value objects as like: ID, Date, Name, etc. When they fail in their construction due to a invalid format or something it throws a InvalidArgumentException. How can I "collect" all the Exceptions and when the script stops send them i...

@CaptainObvious Left a comment.
@Mast If only you could see the code I've written for the last 2 weeks. It's on rev 4 and I've noticed again that it's woefully inadequate. I really don't want to write rev 5 from scratch again. I've just gone "f*** it, I'm working with this s***show".
And all it is is a tree, a tree.
@Mast Happy I could help :)
7:02 PM
What's your specific programming question? SO is not a site for general code review or professional hookups — Mad Physicist 38 secs ago
Q: Modding API for a game

PlutoThis will be in a dll injected into a game's process. The goal is to have a nice api to make it easier to develop mods. The api provides access to game variables, functions and events such as onDraw, onGameExit. Below is a console app minimal working example that hopefully captures what I am tryi...

1 hour later…
8:52 PM
The most important thing you need for Code Review is code. — Klaus D. 29 secs ago
@Duga Nice
@Mast Looks pretty in depth there. One of my favourite answers is about DNA
Managed to optimize to O(1) way back :D
3 hours later…
11:37 PM
Your immediate problem is a typo/bad variable name choice, as @selcuk indicated. However, your solution has quite a few more problems and could probably do with a friendly code review. SO isn't really the place for it, but folks at codereview.stackexchange.com might be helpful — Grismar 56 secs ago

« first day (2696 days earlier)      last day (35 days later) »