« first day (2473 days earlier)      last day (1530 days later) » 

12:00 AM
RELOAD! There are 6392 unanswered questions (90.0887% answered)
 
12:18 AM
Also if you see bad code make sure to tell me .. Assume no one wants to do code review here. State your problem. Pinpoint where you having issues. — GetSet 31 secs ago
 
 
1 hour later…
1:23 AM
0
Q: Prime number finder in bash

CarcigenicateI need to learn bash at some point in the near future, so I decided to start playing around with it. This is really the first actual script that I've written and would like feedback. This finds and prints all the prime numbers up to the argument provided to the script: ./primes.sh 100 2 3 5 7 1...

 
1:43 AM
1
Q: Graceful way to find combinations in JavaScript

tamarintechI'm looking for combinations, not permutations, and have found some really great examples ranging from using flatMap such as https://stackoverflow.com/a/54329187/669843 The result of ['a', 'b', 'c'] would be an array of arrays of 3 (a, b, and c). The result I'm looking for would also contain arr...

 
 
2 hours later…
3:24 AM
0
Q: Rotating an array by mentioned digit to rotate

dghtrI have developed the program to rotate the array in java request you to please check it and let me know if there are any flaws in it or where further it can be improved package com.dataStructures.Arrays; // Java program for reversal algorithm of array rotation //Let the array be arr[] = [1,...

0
Q: Should Golang interface be shared among different packages of an application?

someoneI'm developing a Go application that has lots of packages. Many of the packages use the same type from a 3rd party library. Should an interface be defined for the type in each package, and let the interfaces only contain the methods that are used by the package? Or, we should define a single inte...

 
 
1 hour later…
4:47 AM
Monking
 
5:27 AM
0
Q: How to do these extraction/computations efficiently?

Hilbert HotelI have a set of products(e.g. P0006, P0009, etc.) and a set of production lines (eg. L1H175, L2H175). A product can be produced on a subset of the lines set (and not necessarily all of them). If we decide to produce a product on a production line(assuming that the line can actually produce it), ...

 
5:47 AM
0
Q: ExpressJS user creation in pg-database

BenjI created a table within a postgres database ( https://www.postgresql.org/ ) by executing the following SQL CREATE TABLE users ( id BIGSERIAL PRIMARY KEY, username VARCHAR (100) UNIQUE NOT NULL, passhash VARCHAR (256) NOT NULL, pub_gpg VARCHAR (2048) UNIQUE, pub_rsa VARCHAR (2048)...

 
5:58 AM
You're more likely to get help if you can edit your question to share a minimal reproducible example showing the code that performs badly. Also, codereview.stackexchange.com might be a more appropriate forum for your question, they accept questions about improving the performance of code that already works correctly, see codereview.stackexchange.com/help/on-topicdbc 50 secs ago
 
0
Q: Minimalist Golomb-Rice coding

DaBlerI have implemented a very simple but robust implementation of the Golomb-Rice coding. To understand my motivation, see the minimalist data compressor that is based on this. At the moment, the implementation works well. However, I intend to make it more elegant, concise, and possibly faster. Any s...

 
 
1 hour later…
7:07 AM
0
Q: minimum num of swaps to maximise the sum in first row

ERJANgiven a 2 d square matrix find minimum number of swaps required to maximise the sum of the first row. My logic - store the sorted first row. Create variable num-swaps = 0. Traverse starting from 2nd row check if the current number > than max of first row, then the 2nd max, i.e. find the place ...

 
 
1 hour later…
8:28 AM
Monking
 
8:51 AM
Monking
 
This does not answer the question as stated, nor does it explain why you've chosen that particular set of characters. From a code review perspective, I'd also note that negatives in identifiers are a Bad Thing. — ClickRick 18 secs ago
 
9:08 AM
0
Q: implementation of atoi in scala

Bunny RabbitI've implemented atoi function as described in leetcode problem string-to-integer-atoi. I am looking for some feedback on writing this in a more scala native way and being able to include the requirement that: If the numerical value is out of the range of representable values, INT_MAX (231...

 
9:28 AM
0
Q: To display a value in silverlight website based on its database table column values

user218098I have a database table which has a column named "Status" and the value in the "Status" column will be 1 or 0 or Null. What I am trying to achieve is if the value is 1 it should display "On", If the value is 0 it should display "Off", if the value is null, it should display "null". Here is some o...

0
Q: C++ determinant calculator

chrysaetos99I've wrote a C++ program to calculate the determinant of a matrix: #include <iostream> #include <string> double getDeterminant(double arr[], int dimension); int main() { //First, the user has to enter the dimension of the matrix int dimension; std::cout << "Please enter dimensi...

 
9:48 AM
0
Q: identify what has changed and what is new in 2 lists

cs0815I use the code below, to identify what is new and has changed in UsDtos in comparison to ThemDtos. I am pretty sure it works. Any feedback to improve (fix?) this appreciated? Thanks. public class UsDto { public int Id { get; set; } public DateTime LastUpdate { get; set; } } public class...

 
10:10 AM
If your solution works, consider posting this on CodeReview instead — M.kazem Akhgary 46 secs ago
 
@pacmaninbw Bots has taken over.
2
I'm alive, at least. I've had a very busy week, but also a very good week. This coming week will be less busy, I think.
 
10:29 AM
0
Q: I have working a Dijkstra algorithm code for solving mazes but I am looking for more performance

PrithvidiamondThis my dijkstra's algorithm code... it solves any order square mazes... from copy import deepcopy from math import inf import maze_builderV2 as mb def dijkstra(maze, order, pos, finalpos): mazemap = {} def scan(): # Converts raw map/maze into a suitable datastructure. for x in range(1, o...

 
11:06 AM
@SimonForsberg this reminds me ... I was supposed to poke you about the comment watching task IIRC?
 
@Vogel612 Yes I am aware. While @Duga is partly AWS now, I still haven't migrated the comment scanning task or the answer invalidation check.
 
I just remembered again now, that's why I poked you. Not really prompted by anything...
unrelatedly: the weather around here is weird...
like ... we had a warning for a storm tonight, but I'm sitting in the kitchen, sweating under the sun mere minutes after it was raining with strong winds...
 
@Vogel612 Sounds like Sweden. Besides the part about the sun of course...
Windy as hell yesterday, and lots of rain. My umbrella got hurt
 
0
Q: Is a memory leak and a lack of concurrent safety enough to make code unreviewable?

mdfst13There is this question which has one close vote and three down-votes. The only comments are The code is broken because it doesn't deallocate memory (and because it uses a global variable although that observation is incorrect). The code won't work in a concurrent context. Looking at the...

 
11:29 AM
0
Q: Refactor two functions with createElement and DOM operations

BernardaoI'm trying to refactor this two functions, also thinking in creating functional tests, but my approaches, have not worked. I would really appreciate new ways of reuse my code. Thank you createMenuItems(providers, selected) { for (let i = 0; i < providers.length; i++) { const item = documen...

 
possible answer invalidation by madprops on question by madprops: codereview.stackexchange.com/posts/236755/revisions
Is this a code review? — Nkosi 43 secs ago
 
12:17 PM
@Vogel612 We had your storm. Not entirely over yet.
 
Yea, it used a lot of momentum up north closer to the coast
 
@Duga Possibly, can someone who actually understands regex double-check that?
 
@Duga doesn't seem to be mentioned in any of the answers.
 
Thanks.
 
@SimonForsberg Generally bots don't say anything starable.
2
 
12:30 PM
0
Q: C++ determinant calculator - follow-up

chrysaetos99After following some suggestions you can find here, I'd like to show you the result: #include <iostream> #include <string> #include <vector> double getDeterminant(std::vector<std::vector<double>> vect, int dimension); int main() { //First, the user has to enter the dimension of the mat...

 
12:42 PM
@pacmaninbw Yet the XKCD feed and Duga get starred often enough.
 
@Mast I guess cartoons are easy to star. I don't think I've ever commented on one of Duga's posts.
Or starred.
 
That sounds like a fairly self-absorbed stance you have there
 
12:57 PM
Hey everybody. I have a question for the the regular users of this site. I'm afraid it is a bit broad so I'm rather hesitant to post it on the META. However, this is chat so here goes:
Have you regular reviewers learned anything that surprised you from other reviews? Anything out of the box that proved useful in your normal workspace?
 
@pacmaninbw Generally, I'm not so sure other people do that either.
3
@MaartenBodewes For me I would say "A lot". There's a lot of knowledge I have today that I learned from CR.
As for a possible meta, it could maybe be phrased as "How applicable is knowledge learned from CR to your normal workspace?"
 
@MaartenBodewes I have learned a lot on CR.
 
Yeah, I guess people would come up with examples anyway :)
 
@MaartenBodewes I've learnt lots from other reviewers. I can't comment on whether I use it in my normal workspace as I can't distinguish where I learnt most things now. I know Gareth, Mathias and Graipher have taught me a lot of things.
 
Can you guys just name something concrete? I know it is hard to maybe reach back and get to a particular example, but I'm just curious..
 
1:06 PM
@MaartenBodewes Umm... now it's getting difficult.
 
@MaartenBodewes C programming using malloc, use the size of what the receiving pointer points to.
 
Well actually... the importance of curly braces. I didn't use them fully in my Java code until after I started using CR.
I have probably learnt more from chat than from answers on the site.
 
@SimonForsberg That's a very important one.
 
Cool, those are very concrete.
@pacmaninbw That one scares me a bit :)
 
I also learnt that Brainfuck programs can be readable. Sadly, that's not applicable in my everyday work though.
 
1:09 PM
Fortunately I presume you assumed bytes.
...
 
@MaartenBodewes Yes
 
I have definitely improved my skill on reading and understanding other people's code thanks to CR. That has definitely been useful.
 
struct some_struct *p = malloc(sizeof(*p));
 
@pacmaninbw I did a course Software Security on Coursera from Maryland. That scared me enough not to use it anymore. But yeah, sometimes you have to.
 
@MaartenBodewes ^^
 
1:12 PM
@SimonForsberg This I can definitely vouch to. It's also taught me why style guides are a good idea
 
(with it I mean C lang)
 
@Peilonrayz Yup, agreed.
 
@Peilonrayz Style guides are very good, unfortunately they can be localized to some extent for some languages.
 
Oh, interesting about the style guide. I tried to softly impose one on the other devs, but they wouldn't have much of it. The C++ guides used one for the JSF.
Getting better at reading code is always good of course.
 
@pacmaninbw Not sure I follow. Like JS's style guide being vastly different to Python's and both being different to C/C++'s?
 
1:16 PM
@pacmaninbw Did you mean too localized maybe?
 
@Peilonrayz Style guides for a language can include how many spaces to indent, if the opening brace should be on the same line or the next line. Should snake case or camelCase be used.
 
With style guides I find that it is vitally important to use rules defined externally. If you make one up your own, it's likely that the other devs get defensive.
 
@MaartenBodewes They can, but it can be done through a series of meetings and consensus.
Management should say we need a style guide, and the Devs work it out between themselves.
 
Yeah, probably best even though that can take a lot of time. It is easy to recuperate that time of course during maintenance, but it can be tricky to tell that to a project manager.
Well, at least in the company I worked for where PM's had too much power.
 
Someone always has too much power.
2
 
1:21 PM
@pacmaninbw I never worked for a SW only company, so the management would never even interfere.
 
@pacmaninbw Usually the wrong person.
 
@SimonForsberg Didn't want to say that, but yes.
 
#POTUS
 
#Not my president
 
Of course, we had a whole bunch of such people. One time I went to HR and asked them if they could even distinguish psychopaths.
 
1:24 PM
@MaartenBodewes Lots
 
Probably a bit much to ask for. I had a very nice colleague who had a reading/writing disability. They only started to notice that the code he wrote was very ... bad.
He asked me if there was maybe an audio book to learn Java.
 
@pacmaninbw Yeah there are quite a few differences between languages. However, they make historical sense. And now it's a matter of changing the norm - which is hard
 
@MaartenBodewes Did it work?
 
@pacmaninbw Did what work?
 
The very bad code he wrote.
 
1:26 PM
@pacmaninbw Sometimes the general style guides go a bit far though. Eventually it boils down to "When in Rome, do as the Romans do"
 
@pacmaninbw To a certain extent only.
 
On Code Review I learned why you should write proper tests. And I still don't test enough, since it's too bloody time consuming...
3
But the rule that "if you can't write a test for it, the spec is insufficient" helped me a lot over the years.
It's really, really important to know what you're going to write before you write it.
 
When reading the code you had so many face-palms that you might as well leave your hand on your face.
 
Of-course, this has resulted in me writing less and less code.
So...
When writing Python I still go fast-and-loose, but that fast-and-loose has become a lot neater than it used to be.
Progress.
 
@Mast Yeah, important one, testing. I have a few interesting things on that. I had code that had 10ns of thousands of tests on it.
 
1:29 PM
PEP8?
 
@pacmaninbw I put it through a linter every once in a while, but I don't follow the PEPs blindly. If different indentation makes my code/comments look better, I do that instead.
@MaartenBodewes I also learned you can test the crap out of something and still miss the obvious.
 
Oh, that's always good when the language designers have a style guide. Unfortunately the one of Java has mostly gone the way of the dodo.
 
It's a good thing the PEPs exist though. Some of them, including the PEP8, are very useful.
Especially when sharing code with others.
 
@Mast Sure, that's why somebody else needs to test code and that tester must at least have half a brain. Or at least be able to think sideways.
The problem with testing from specs is that it misses the side cases that are created by the code base itself.
 
@Mast This is true, I've found something I like more than what is PEP 8 compliant. But the first part of PEP 8 states that it's not perfect, and you should violate it if you know what you're doing
 
1:33 PM
@Peilonrayz Exactly, so violating the PEP8 in good conscience is still following the PEP8.
3
 
@Mast LOL
 
Also, TDD is crap if followed blindly.
Another thing I've learned over time (on CR) is that performance is usually less relevant than readability.
 
Yeah, don't like it either. It will restrict your abilities to redesign. And most complex situations do require at least one redesign.
 
So what if it takes 20% longer? If it's still finished in half a second and it only runs once a month, who cares?
 
Yeah, people in Java still wondering if creating an additional object is maybe too time consuming.
 
1:36 PM
@Mast Can you explain the TDD comment better?
 
@pacmaninbw You can write 24 tests for a very simple function and still have obvious bugs in your code.
 
@Mast For the last 25 to 30 years that I know of, the first rule of optimization is "Don't Optimize"
 
@pacmaninbw Pretty much.
 
@pacmaninbw Well, I do think that knowing about the big-O thingy is much more important than low level optimization. As long as you at least get the O right, the rest can come later.
 
But, coming from an embedded background, there were always restricted resources. So it was really hard not to optimize.
 
1:41 PM
@Mast It depends on what you are optimizing.
Size or speed.
 
@Mast Yeah, I had to fight some guys not to over-optimize in the embedded space as well.
 
@Mast I wrote a HRM interpreter a couple years ago, where I cared about performance. And then rewrote it a month ago. It was an eye opener on KISS and maintainability and how little performance matters.
 
Size is much more important. If the size is not correct, you'll have all kinds of problems
(I'm a Java Card developer and former member of the Java Card Forum)
When 8 KB is all you have... I never imagined after my University that I would have less memory to spend than on my MSX.
Oh, dear, if that doesn't show my age...
 
the most important thing I learned on CR (and through things like codelesscode) is that following existing code conventions is more useful than enforcing your own subjectively better ones
 
I once had a HDL solution that wouldn't fit in the target platform. The chip simply wasn't big enough. You don't run into those problems as fast anymore.
 
1:46 PM
@MaartenBodewes Never been limited to 8K, 64K was the smallest I had.
 
With SO I've really learned to very quickly spot problems, even when I'm writing code myself.
8K is for high end smart card chips. Most have less.
1
Q: Find all substrings that contain k specific characters in a string

user9355495Given a string, return the count of the number of substrings that contains characters A, B and C. Two substrings are considered different if the starting, ending or both positions differ. Example - s = "ABBCZBAC", there are 13 substrings which are "ABBC", "ABBCZ", "ABBCZB", "ABBCZBA", "ABBCZBAC"...

Classic example of bad - well anything really. But especially getting big-O wrong.
You can optimize the heck out of that routine, but as long as you're going to actually construct each substring and search. No way that's going to be fast.
Dang, I'm having a POOC error.
 
@MaartenBodewes True. Sometimes you just need a better algorithm entirely.
Counting the amount of nested loops usually gives a good indication already.
I've seen a for in a for in a for in a while in a while. That was 3 layers too much.
 
Ugh, nested loops. Yep, that's when you have to think of another way to split up your routines. If you cannot make methods out of it.
PooC, programmer out of coffee.
Hey, we've been sidetracked just ever so slightly. Nice to talk to so many of you, I'll create my Meta when I have some time to reply/manage it. Could be tomorrow though.
 
0
Q: Should I change the question's title or body, and/or create another question?

Dorian TurbaIn this question (What is the best practice between second assignment or dict's value call?), I first ask for the best solution between second assignment or dict's value call. But, after few days I realize that the real issue in my problem wasn't really what I asked in the title but instead "Ho...

 
Oh, and a bit of CodeSOD to quit. Key setup routine from SO. That question got deleted, don't know why...
public instantiate(byte[] key) {

for (int off=0, i=0; i<4; i++) {
k[i] = ((key[off++] & 0xffffffff)) |
((key[off++] & 0xffffffff) << 8) |
((key[off++] & 0xffffffff) << 16) |
((key[off++] & 0xffffffff) << 24);
}
}
Java code of course. Later!
(I anonimized it somewhat of course)
 
2:25 PM
@MaartenBodewes That's Java? We used constructs like that in C as well.
 
@MaartenBodewes Well, in some cases it can matter a lot if you're creating an additional object...
11
A: Advanced and Detailed Minesweeper Probabilities

Simon Forsberg@Pimgd were definitely on to something big in the last part of the answer, but not on to it enough. Simply changing Solution<T> to GroupValues<T> did not help much. However, what certainly did help, is to use a List<Entry<FieldGroup<T>, Integer>> (as ugly as that type declaration looks). And to ...

 
2:39 PM
Hello! Your question is well presented. You might get more feedback on codereview.stackexchange.com/, because your code seems to be already working. — Eric Duminil just now
 
@Mast Well, the advantage of C is that you can do the same with unsigned integers.
(b & number) in Java converts to integer, and uses sign extension.
 
IIUC you're just converting the byte[] to an int[]?
 
Yep, little endian to be precise.
Or at least it should do that.
 
should be easier using ByteBuffer.wrap(key).asIntBuffer()
 
No, that doesn't work, but just setting the order to little endian and then getInt would work fine.
 
2:43 PM
right... so ByteBuffer.wrap(key).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer()
 
Yeah, but you cannot get to the underlaying int[] if you do that.
But the problem in above code is not in the method. It's the masking.
 
sure, just get it into a destination buffer
 
Uh, underlying?
 
you're not accessing the underlying byte buffer through k[i] either?
 
No, that's fine. It's the part of 0xFFFFFFFF. I mean, an & with all the 32 bits set is not going to do much, right?
 
2:48 PM
ya. that should be optimized away by the compiler
hopefully ....
 
So what you do in Java to just get the bits of a byte into an integer is that you mask them after conversion. That way you undo sign extension.
Of course, you have to mask with 0xFF to do that...
It seems that this developer heard of the trick but - uh - extended it to the full integer.
 
welp
 
So there are a few too many bits set to 1 in the resulting key...
As they nicely do an OR with the result...
 
huh? I seem to be missing a crucial step there ..
 
0x80 is converted using sign extension into 0xFFFFFF80 to get to the same negative value. Then you & with 0xFF and you get 0x00000080 again.
Anything in Java is converted to integer before doing the calculation (well, except for long & long which results in a long.
 
2:55 PM
ahh... so you mask down to the original size of the byte ...
now I understand the issue
 
Ryan Donovan on February 10, 2020
One thing we continuously speak about in the programming community is impostor syndrome and how to cope with it, but no one talks about tangible steps on how to solve it within yourself. What if instead of learning how to endure, we learned how to cure it? While It’s something that happens to everyone at […]
 
Of course, if you're writing optimized code, then ((key[off++] & 0xffffffff) << 24); doubly doesn't make any sense.
OTOH, it's the only one that is semantically correct.
I mean, you get rid of all the bad values by performing the shift...
32 out of 128 bits key space left if you're unlucky. Yipes.
Once in every 16 to be precise.
 
one byte every four, right?
 
Yep, if the least significant byte is negative, then all the bits will get OR'ed to 1
 
ouch
 
3:03 PM
Actually, I cannot count either, there is 28 bits of key space left :)
In that case.
 
you're discounting the signbit of the least significant byte, right?
 
yeah
JavaCard doesn't have integer, but it still performs java calculations as if it has integer. You can imagine the fun I had with writing b & 0xFF all the frickin' time. I must have typed it a few thousand times.
For byte to short conversion...
 
oh wow, that sounds horrible ...
 
Note to language designers: bytes should be unsigned. UNSIGNED.
 
co-signed
 
3:08 PM
Yeah, probably better.
If you want to do multiplication, then convert to a bignum, Python style.
I was thinking of creating a langauge that had python style numbers by default, and then int16, int32 etc.. with %+ and %- calculations on it.
 
ohhh I kinda like that
 
Then convert using number = Number.asSigned(int16) or something similar.
(or some shorthand notation)
Then the int32 is really just a representation of a CPU register.
But you still have normal numbers.
 
this raises some optimization questions, though...
if you expose sized numerical types, you will want to take advantage of these types when emitting low-level code
 
@MaartenBodewes If there's one thing error-prone it's a Duff's device.
Write once, copy forever.
 
It doesn't feel right to me to default to the costly integer arithmetic
 
3:19 PM
@Feeds For some values of tangible steps.
 
@Vogel612 Sure but you can do that with int16 etc. all the way. It's what we currently do basically. And optimizing compilers can be smart, right? If you do for i = 0 to 16 internally the i is perfectly suitable to a 32 bit word.
 
true
 
possible answer invalidation by someone on question by someone: codereview.stackexchange.com/posts/236960/revisions
4
 
Oh, dear, someone is going to get into trouble :)
2
 
0
Q: Change architecture of Ruby app to be more object oriented, readable

mr_muscleI'm working on a Slack bot for service desk which sends direct message to user on a Slack when their ticket will be on user_action_needed status. I'm using AWS Lambda to handle Jira incoming webhooks. Everything works well but I think I've got an issue with whole architecture of the app - I quess...

 
4:10 PM
hi and welcome. this question seems a better fit for codereview@ or so... stackoverflow is more about technical Q&A style questions — Daij-Djan 37 secs ago
But I don't have any code yet and I can't post in @codereview without lines of code — Ludwig von Drake 8 secs ago
 
@Daij-Djan OP is 100% correct, this question would be off-topic on Code Review. Please don't suggest other sites when it's clear you know nothing of their rules. — Peilonrayz 14 secs ago
 
4:52 PM
0
Q: C# MySQL Database insert list of components

TravisI am writing a function to have insert a list of strings into a MySQL database and C#. The process of creating the list of Components: User has to scan multiple barcodes and have them stored in a list. The goal is to take that list and insert it into a MySQL database on the click of a submit bu...

 
5:09 PM
Monking
 
-1
Q: C# logging strategy for third party DLL

Timothy VogelI'm working on a C# project (.NET framework) that will result in a DLL / assembly that may be called from multiple applications. The logging framework used by these applications is unknown. My preference is to use Serilog's static Log method for my own code and not setup any configuration. u...

 
5:53 PM
0
Q: Asset management in C++ for games

ekardnam_I've been making a simple "game engine" for fun and I had a lot of trouble designing a decent asset management system. Currently I got it working but it uses a lot of downcasting which is usually bad practise. The whole code wouldn't really fit here so I'm putting here the relevant parts and link...

-1
Q: Can I clean up this Linq query?

Avrohom YisroelI'm creating mazes, and want to pick a cell that is a neighbour of the current one. If one of these neighbours is a dead end, I want to pick the first of those, if not, I want the first non-linked cell in the list. My current code looks like this... Cell neighbour = current.Neighbours.Any(n =>...

 
6:13 PM
0
Q: A Brushfire algorithm to generate a distance map in a grid

user1747281I'm working on implementing a goal-based pathfinding. first step is to set a goal and calculate the shortest walkable distance between the goal and all points in the grid, using a brushfire algorithm. I'm worried about two things here, readability and efficiency, since this is for an RTS game. ...

 
6:33 PM
-1
Q: How can I make my library more losely coupled and implement better and more modern practices?

Ash KetchumBefore I begin showing code, I have two main questions which I feel could help me. What is a service or factory, I've heard of them but why use them? When should I use one logger per class? I only plan on persisting errors and don't care about the reporter, would a shared instance for the whole...

 
7:14 PM
-1
Q: Binary Partitioning an array in Java

EesaI am a beginner(first year uni student) programmer trying to solve this problem which i'm finding really difficult. If you are to answer this question, don't provide me with a complex daunting algorithm that will leave me scratching my head. I'll really appreciate it if you explain it step my ste...

 
7:35 PM
0
Q: Creating a bijection between integers and a set of strings

AmiraI have a set of unique strings, I want to create a unique integer identifier for each string. Usage I want a function to move back and forth, if I give it an integer it returns the corresponding string and vice versa. Here is how I am doing it def str_to_int(S): integers = list(range(len(...

 
8:12 PM
You might want to try asking the question at Code Reviewblurfus 27 secs ago
 
8:56 PM
-1
Q: Parsing Binary Tree Array in Python

getgladI got this from a practice problem set, and looking for feedback on my approach. Suppose you're given a binary tree represented as an array. Write a function that determines whether the left or right branch of the tree is larger. The size of each branch is the sum of the node values. The func...

-1
Q: Java Palindrome - Time & Space Complexity

PacificNW_LoverWhich of these three methods is the most efficient? Also, what is the time & space complexity of each? public class Palindrome { public static boolean isStringBased(String word) { if (word == null || "".equals(word)) { return false; } String lowerCasedWo...

 
9:08 PM
Some people suspect that it started as a "No, I didn't forget Valentine's Day" excuse that got out of hand.
2
 
@CalvinNunes It's not another answer, this is your answer expanded and updated with idiomatic ES6 based on the limitations yours had. If your answer isn't going to work, mine is going to fall flat right behind it. TL;DR this is the change I'd recommend in a code review, but isn't beginner friendly so I didn't edit it in. — gelliott181 9 secs ago
 
9:36 PM
0
Q: Transpose 2D Matrix in Java - Time & Space Complexity?

PacificNW_LoverHere's my algorithm / approach for transposing a 2D Matrix on the main diagonal. Before: a L M d b G c N H K e F I J O P After: a b H I L G K J M c e O d N F P My code: public class Matrix { static String[][] matrix = { {"a", "L", "M", "d"}, {"b",...

0
Q: Speed up Django migration that adds two fields into one

Helana BrockCurrently trying to migrate two fields of information into one field. We have many, many objects to go through and it takes roughly 12 minutes to loop through all the objects. That would mean the website would be down for 12 minutes and we do not want that. Is there any way to speed up this migra...

 
9:54 PM
Since this code is working and you are looking for opinions on how to improve it, this belongs on Code ReviewZack E 33 secs ago
 
0
Q: Convoluting 3D image with 2D

MatthewI have a single image of shape img.shape = (500, 439, 3) The convolution function is def convolution(image, kernel, stride=1, pad=0): n_h, n_w, _ = image.shape f = kernel.shape[0] kernel = np.repeat(kernel[None,:], 3, axis=0) kernel = kernel.transpose() n_H = int(((n_h + ...

0
Q: Clean up HashMap

VemuDo you guys have any ideas how to clean up this code? Imo that new LinkedHasMap<>() look awful. Document document = response.parse(); List<Elements> elements = Arrays.asList(document.selectFirst("#oddzialy").children(), document.selectFirst("#nauczyciele").children(), ...

 
10:24 PM
This is a question better asked at Code Review. — Kenneth K. 23 secs ago
 
10:36 PM
Oh, darnit, that's the second question that gets deleted while I'm at 90% on an answer.
I thought "Clean up HashMap" was terrible in a nice way.
Really, I do think that CodeReview should be a bit nicer to newcomers.
That immediate downvote was a bit much IMHO.
 
@MaartenBodewes The OP deleted it -perhaps it will be undeleted after revision...
 
I hope so, it is easy to refactor and I already wrote most of hte text. Now in my fave text editor buffer.
(we live in a great time where these drafts are automatically saved even without putting it in a folder somewhere)
 
10:52 PM
@Nkosi I've edited the question to be better suited for a code review. — Michael Brandon Morris 8 secs ago
 
@Duga ugh... could potentially be migrated to CR , though it has an open bounty...
 
0
Q: Better ways to edit Excel through MS Access?

Bread DoughlasI have an Access macro that runs AfterUpdate of a form. It opens an excel workbook and edits a few cells. I have It working the way I want, but the problem is that the code takes about 25 seconds to run. This is way too long for the users of this database to have to wait. After adding some timing...

 
It is strange that devs can not even spot simple repetition. I wonder what problems you can solve if that's the case.
 
11:17 PM
0
Q: Is this the fastest and easiest way to remove nodes from a list?

awwwwwIs this a good way of removing all the nodes that contains a value x? This functions takes in input the head of a list and has to delete all the nodes that contains a value taken in input and saved in x variable. If there is any better way to do this can you please show them to me? node_t *funz...

 
this might call for some weapons-grade facepalm...
@SᴀᴍOnᴇᴌᴀ my question is indeed how to reduce repetition and/or avoid the ?: operator. Describing what the code accomplishes would be very hard in a few words, and miss the point. Don't know how else to phrase it — Avrohom Yisroel 1 min ago
 
Sorry to contact you here. I was already writing an answer for your question on codereview. I think the -1 was a bit early, although the missing imports were a bit of a problem. Anyway: this message will self destruct: private static LinkedHashMap<String, String> createMapOfLinksForID(Document document, String id) { var elements = document.selectFirst(id).children(); var mapOfLinks = new LinkedHashMap<String, String>(); for (var element : elements) { mapOfLinks.put(element.text(), element.child(0).attr("href")); } return mapOfLinks; } — Maarten Bodewes 14 secs ago
 
11:33 PM
@MaartenBodewes We often tell users that answer off-topic questions to check out the on-topic questions - e.g. for java
while older questions won't be candidates for Hot Network Questions, you could still earn certain badges like the necromancer, revivalist, etc.
 
Just to be completely clear; why was this mostly off topic? Because it was impossible to compile?
There was one close vote reason I think.
But I could hardly read it before it got deleted.
 
I see one up-voted comment from greybeard... I can try linking it, or else paste it
Please heed How do I ask a Good Question?: provide more context. At the very least, the imports giving document, Element, Elements(?!). The tag is not useful.
 
0
Q: Lexer written in Rust

Ian RehwinkelSo I ported a lexer I wrote in C++ over to rust, as I'm starting to learn rust. Since I'm very new though, I don't know any Idioms and good practices in rust. So if anyone could point out some (probably obvious) issues I'd be very thankful. This is my code: use std::cmp::PartialEq; use std::fmt...

 
yeah, they parsed it from a HTML or XML document I think, probably using a specific parser that's not included in the standard JVM.
 
as a reviewer of that code I would want to know where variables like response came from, and how the ending variables were used (i.e. classes, teachers, rooms)
I could guess, but that only goes so far...
 
11:41 PM
Well, enough for me to create:
private static LinkedHashMap<String, String> createMapOfLinksForID(Document document, String id) {
var elements = document.selectFirst(id).children();
var mapOfLinks = new LinkedHashMap<String, String>();
for (var element : elements) {
mapOfLinks.put(element.text(), element.child(0).attr("href"));
}
return mapOfLinks;
}
var document = response.parse();
var classes = createMapOfLinksForID(document, "#oddzialy");
var teachers = createMapOfLinksForID(document, "#nauczyciele");
var rooms = createMapOfLinksForID(document, "#sale");
And that's all me wrote.
 
> Details matter! In order to give good advice, we need to see real, concrete code, and understand the context in which the code is used. Generic code (such as code containing placeholders like foo, MyClass, or doSomething()) leaves too much to the imagination.
 
Heh, one of the problems of this author was creation of placeholders in the first place.
List of maps. Right :)
 

« first day (2473 days earlier)      last day (1530 days later) »