So I've written a function that returns how many Months and Days are between two dates. I want to respect calendar month boundaries, but I'm ignoring time as it's not relevant for my needs.
I've got the following, but I feel like I'm missing thing I can do to optimize it/refactor it. So I'm look...
Still learning Python, but thought this was kinda a cool project to work on.
Feel free to critique and let me know what to work on or change.
main.py
# -------- MODULE IMPORTS --------
import random
# -------- CLASS IMPORTS --------
from phrases import Phrases
# -------- GLOBAL VARIABLES ----...
If you have a working code and is looking for a review, you might want to check codereview.stackexchange.com. Just make sure you check and follow their guidelines. — Andreas16 secs ago
Belongs on codereview.com, but it is inefficient to flush after every write; on the other hand your application may demand flushing of every log message so as never to risk losing any. — user20742123 secs ago
AWS_CDK is provides abstractions to write programmable cloud formation templates. We are using TypeScript.
But, I see that AWS CDK did not provide abstractions to separate state from logic. In the sense, below example from cdk documentation:
import s3 = require('@aws-cdk/aws-s3');
// "this" is...
@pacmaninbw about the names I am complaining that you include the constraint type in the name, FK should not be part of a name. camel case is not a big deal.
@pacmaninbw The choice of PK ,even if you are forced to use a numeric value, should not include non-key attribute. For instance the PK (id, first name, last name) should just be PK (id). The combo first name and last name should not even require to be unique.
I came across a pretty simple question where the author explicitly states:
The function returns the correct output, and all known edge cases have been accounted for.
I took this at face value and started writing up a quick review. Examining the code further, it turned out to be broken. I we...
I am very new to java, but for some reason, trying to create an app
the app is building properly in android studio, but, when trying to open in an emulator, it is crashing.
This is my complete code
is the zip of the app, with I guess, the main error is
final View rootView = inflater.infl...
I have 2 data structures with me in JS. One is an array say of length N. Let's consider N = 4.
const arr = ['a', 'b', 'c', 'd'];
The second one is an object:
const obj = {
a: 0,
b: 2,
c: 3,
z: 5
};
I wrote a code in Javascript, to create a new object out of obj which should not cont...
There are exactly ten ways of selecting three from five, 12345:
123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
In combinatorics, we use the notation, 5C3=10.
In general, nCr = n! / r! (n−r)!, where r≤n, n! = n × (n−1) × ... × 3 × 2 × 1, and 0! = 1.
It is not until n = 23, that a value e...
To avoid nesting I use for comprehension instead of nested map and
flatMap, which of them is most recommended way while dealing with
Monadic data types in functional programming.
For comprehension version of the code:
val result: Future[T] =(for {
result1 <- Future[T1]
...
So My code seems to be working as data is being entered in database after my form is being submitted..
However, concurrently, another ERROR page is being generated with the above error message.
And an additional field without any data is being created in my database.
Here is my code for my html s...
Here is implementation for singly linkedlist. Any suggestions are most welcome
'''java'''
package linkedlist;
import java.util.Scanner;
public class linkedlist {
private int size=0;
private Node newNode,oldNode,firstNode,displayNode;
public void createNode(String value) {
if(size==0) {
...
May be my question is not up to the standard for Code Review, but of upmost importance for reassessing methods used in my VBA coding . While preparing/testing answer for a SO post (thought to simplest of simplest questions) VBA cell format that contain a specific percentage value, I came to a jol...
I was wondering what's the fastest method to compare similarity between two lists of strings (e.g. two dataframes, documents etc.) using levenshtein distance or other procedures.
I am currently using:
def wuzzyfuzzy(df1, df2):
myList = []
total = len(df1)
for idx1, df1_str in enumer...
Here is a function I just wrote and I'm wondering whether there would be better ways to implement it?
void severity_variable::process_value(message const & msg, std::string & value)
{
severity_t sev(msg.get_severity());
severity::pointer_t severity(get_severity(sev));
if(severity == ...
I'm having memory overflow issue with the code below when I read huge file, code is converting a sas file to parquet by hashing few columns.
import pandas as pd
import ast, sys
def sas2parquet(df,col_names):
lis = df.columns.tolist()
tgt_path = col_names[0].replace('.sas7bdat', '')
for i in c...
I've been fiddling around with some easy code challenges and there's one about determining if a triangle is equilateral, isosceles, or scalene.
I've come up with a working solution, but I feel this could be greatly improved and/or simplified.
The sides of a triangle come in a list e.g. [2, 2, 2...
I've got below implementation for my controller and show action which implements MiniMagick gem. I've just wondering is there any better way to write it down? If block in a separate, private method maybe?
def show
identification_document = IdentificationDocument.find(params[:id])
autho...
I knew you were interested in migrations towards CR, so I was hoping you'd keep an eye on the current process among SO mods. This isn't the first migration we reject and all migrations are from mods. Indicating at least some of the mods may benefit from extra instruction we're perfectly willing to provide.
@Bob This is absolutely unsuitable for Code Review by lack of context. Please refer to their help center before making further recommendations. — Mast54 secs ago
@Mast I've read it and it says also that, there are question on-topic on both sites, so that means in my oppinion , that's also suitable for Code Review. — Bob26 secs ago
@Duga The nth time I'm going to explain this to John Doe from SO.
@YvetteColomb It certainly won't hurt anything, but the average SO user won't be able to migrate it anyway. It's probably moderators responding to custom flags where things go wrong here. You're in a better position to raise awareness among the SO team than the average CR user. Martijn used to do a lot of good in regards to debunking migrtion myths among the SO populace, not sure what he's been up to lately.
@Bob please do not make recommendations for migration to sites you have limited experience. Code Review has strict migration guidelines. — Yvette Colomb ♦29 secs ago
@Mast yes he did. He has helped me a lot. He still does a lot, I've left the baton. I'll pick it up again. Thanks for the heads up. If we need to we can always post another meta post on SO. But I'll wait and see how we go. Currently SO is in a state of flux, but I'm hoping it's sorted out soon
I'm using flexbox to create a simple header, hero image with caption and footer.
As you can see from my snippet, the header is fixed and the hero image scrolls underneath.
Is there a way to achieve my layout without fixed or absolute positioning? I'm relatively new to flexbox and and haven't co...
@Bob With this particular question it's clear that the code in the question is not the OP's actual, real code, as you have the If vs. if issue and also ProgressBar vs. progressBar, so this question would get closed on Code Review directly, as it's currently written. — Simon Forsberg1 min ago
@Bob The topic itself, about simplifying if-statements, is absolutely a good fit for Code Review. But I would have guessed that the OP will just see "Oh, I should copy-paste this exact question to this site instead" and then it would be closed on Code Review, leading to unwanted experience for both OP and Code Review. The question itself is not the only requirement for a question to be on-topic on CR, the code also matters. — Simon Forsberg44 secs ago
I'm wondering why a perfectly valid answer with two upvotes for the Add and Search Word question has been deleted? There is no comment explaining this strage action. From a regular user's point of view a ♦ has removed it single-handedly witout prior community voting for deletion or without asking...
Oh don't worry, the community won't play much a role here. It's just the mods who can wreck havoc by featuring whatever post they like. :-) ... but yeah, jokes aside, I don't think it is practically possible nor feasible for users to come up with a process for featuring posts. My plan as of now is to just feature every post that crosses +3 or dips below -3. That should help some of those posts get the traction that they need to rise further up. — Bhargav Rao ♦6 hours ago
Can someone please tell me why this code is giving wrong answer ... I don't seem to find the mistake...
#!/bin/python3
import math
import os
import random
import re
import sys
if __name__ == '__main__':
arr = []
min_sum=-9*7-1 #all elements of an hourglass become min val ie -9 here
...
You added example dataset, now add expected output based on your example dataset and explain what your rules are. This is not a code review site. — Erfan28 secs ago
this method definition for you to implement:
CurrencyExchange.rate(date, from_currency, to_currency)
The method definition should not be changed.
This method must return the exchange rate between from_currency and to_currency on date as a float.
If the method is unable to calculate the exchan...
I encountered this bug a few minutes ago, and decided to bring it up here. It happens when both asking and answering a question.
Steps to reproduce
1. Create bulleted list with a couple/few items. I checked, the size of the list doesn't matter, whether it's one or seven items
.
2. Post a piece...
Would bot-support for highlighting zombies be a good idea (i.e. a bot that declares when a Zombie is some number of days old)? I can't see any references to this idea before, but I'm not much good at searching for things.
(I wrote some musings as an answer to a meta question, but then realised it shouldn't be an answer to that meta questions, so now it's a gist)
Regular visitors of the 2nd monitor chat room may be familiar with @RoboSanta, a friendly bot, pimping posts that are hopefully upvote-worthy.
Currently RoboSanta posts one Naruto answer per day (accepted non-selfie answer with zero score on a non-closed non-deleted question), randomly selected...
I've written this code in Scala that extracts bigram statistics from the Reuters dataset. It puts the statistics in a Map[String, SortedMap[String, Int]]. For example, the bigrams for "hi" could look like this:
Map("hello" -> SortedMap("there" -> 10, "friend" -> 6))
which means that "there" fo...
I have a simple program that looks like:
[<EntryPoint>]
let main argv =
let mutable timer = new Timer(float 5000)
let OnTimedEvent (frameId:uint32) : ElapsedEventHandler = new ElapsedEventHandler (fun obj args -> printfn "DATE: %A FRAME: %i" DateTime.Now frameId)
while(true) do
...
@VisualMelon About bots: if you write something useful, let it do a test-run on it's own chat room and point a couple of users from here towards it. If it's useful enough, we'll support it in The 2nd.
If you got the next RoboSanta and it helps with keeping the zombies down, we're probably all for it.
Or, if you want to make it interactive, keep it in it's own room, make a meta post about it's launch and see what happens.
@Ctx "If you reverse the logic, you could close everything as opinion based." What logic do you want to reverse? "If not X then not Y" does not imply "If X then Y" - that is a classical fallacy. I would like to point to the existence of codereview.stackoverflow.com which specializes in exactly these kinds of questions. — Max Langhof56 secs ago
@VisualMelon Duga is written in Java / Gradle, RoboSanta was python if memory serves and then there's repos like SmokeDetector (also python) or Zirak's Chatbot
If anyone is wondering why all my mistakes are still visible, that's because the browser on my current machine doesn't support this chat too well so editing is not possible.
I'm getting articles from db, and each article has it's own list of histories (as price changed etc) and there inside should be ModifiedBy - to check who modified it, and because of that I need to loop throught each row of history to set ModifyName.. I think it might be avoided?
Check code below...
Looking at Duga now; I've never seen Groozy or Grails or Gradle before, and I only pretend to know how to use Maven when other people ask me for help ;)
3
Thinking about reading this and exploiting this, so that I can stay in my comfortable world of bodged together C# with minimal dependencies.
Am I right in thinking that this will automatically close a file?
def get_file():
with open("file.csv", "rb") as f:
yield f
If not, how do i write a function that returns a file object, whilst making sure that it closes the file after the receiver is done using it?
I hope its the right place to ask. I have a calculator (in React) and I wonder if the way I did is is good or what I could improve. I wanted to do it like the iphone calculator (you dont only see results when you press =) and I feel like my code became a little messy. Any suggestions would be awe...
Below is a stored procedure which we use to port the data from a remote server to our Data ware house server. THE SP uses a generic style
where all the table's along with it's schema and data will be loaded into the data ware house.
The script is working fine, but now we have a requirement where...
@VisualMelon You don't need to know anything about Groovy or Grails. You can choose between using Maven or Gradle. It is possible to use neither, but I wouldn't recommend it.
@VisualMelon Well, if you are used to C# then I guess that's what you would go with
this is a simple wrapper for sqlite3 to make working with databases easier
it isn't a professional implementation but it is much better than the raw c interface
I saved much time and code using this wrapper instead of the raw interface
any improvements will be appreciated
HandleBase.hpp
#pragma...
There are four categories(Technical, Quality, Extracurricular and Economics) in a school and 5 free days. Each student has to invest in a course under each of the four categories AT LEAST ONCE during the 5 free days. (For example, Technical on 1st day, Extracurricular on 2nd day, Economics on 3rd...
If you have a working solution and have questions about efficiency, then the question is more suitable for CodeReview. If however you don't have code that works exactly as you really would want it, then share your code and describe the problem it has. — trincot45 secs ago
AskUser has been developed as a means by which to get a single keystroke in non-canonical mode without echo and return the ASCII value to calling procedure. Prompting should be intuitive enough that the user realizes input in the range of 0-9 or A-Z or any ASCII character from 32 to 127 for that...
There is code review, but that's impossible since nodes are not in SCM, so can't be seen as having been edited during code review. — CallMePickle29 secs ago
As d_kennetz stated, this is not code review. If you want help, you have to explain your logic in words, and not expect us to go through your code and reproduce a better answer for you. — Erfan28 secs ago
I'm new to stack overflow. Didn't even know that code review existed. — SCool57 secs ago
@PatrickHonorez no. this is clearly a very specific question involving hypothetical illustrative code, Code Review is for revieweing all aspects of real, working code. Illustrative example code like this is explicitly off-topic on CR. — Mathieu Guindon29 secs ago
OK, I'm reading the guide to Code Review for Stack Overflow users, and I have a question. How much context do you actually need? Must questions explain every line of code and what it does, or is "this is an ORM" sufficient?
@RobertHarvey No, you don't have to explain every line. But you should provide enough detail so that someone reviewing the code has some idea of what it's doing and why.
@RobertHarvey I'd answer that with: Don't modify your code just for the sake of putting it up on Code Review. If you don't do that, then we normally have all the context that we need. We want the code as-is.
@SimonForsberg Yes, the moment somebody starts talking about simplified code, alarm bells go ringing. We've seen in the past that reviews on such code are nigh useless to whoever posted the code.
Yep. That's like the "my professor told me to" case, where you are studying it to learn new principles that can be applied with or without various transformations to other problems.
I remember the trouble we had with a high-scoring migrated question here. Turns out all he wanted was verification, not a review. It's one of the highest-scoring off-topic questions we have.
I am using an API to check if customers have social media profiles.
Depending on whether they have phone or email or both there's a different search type.
There's a lot of conditions in this function, and the real dataframe has about 50 columns. So I'm just wondering if this is the most effici...
I am writing a small color space converter for a device, that records an image and displays it on a screen. The image is available as a planar 4:2:2 YUV image and needs to be converted into a 8 bit/channel RGB image. It is possible, that in the near future, the color space of the input image will...
void ColorConverter::convertImage<YUV422_LOGIISP, RGB888>(YUV422_LOGIISP const& src, RGB888& dst) {
// Do actual conversion
// Handle indices to access correct (y,u,v) values
// For every (y, u, v) set, call src.yuc2rgb to obtain a the rgb values
}
> Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site.
> If your question contains stub code, then there are significant pieces of the core functionality missing, and we need you to fill in the details. Excerpts of large projects are fine, but if you have omitted too much, then reviewers are left imagining how your program works.
Because more than once, I've seen a post that has N answers, and think it's not worth answering, but then find it was migrated and doesn't have any good ones.
Whereas if we nuked the answers when migrating, we'd see that it was still a zombie right on the home page.
So rejecting a migration leaves it deleted on the original site?
That seems wrong... It should remain open for normal closure, or get auto-closed with a generic reason (too broad, maybe, or a custom reason just for this).
I have been working on my game for quite a while. one of its key features is cross-platform local multiplayer for example 2 players on 1 keyboard and some people on the controller.
However after finishing my script which took me a whole day to get it running just the way I want it to work. it wo...
The SO mods actually contacted us to apologise for the migration before it was closed on our side.... but I did not get their ping until after it was closed here.
@Hosch250 The whole reason for migration is that it's off-topic on one site, but on-topic somewhere else. So if you encounter a situation where a post gets migrated, migration rejected, and re-opened on the original site, then it shouldn't have been migrated in the first place.
oh sorry i didnt know about code review i just found out from you thanks i will move it there — Boozie36 secs ago
iam tempted to say this is off-topic on stackoverflow as the code works and the question is about refactoring.. This seams more on-topic on code review which is a other stackexchange site — Raymond Nijland26 secs ago
@user207421 I believe you mean Code Review Stack Exchange. Make sure you really understand the scope of that site before recommending it though, but in this case I think you are right — Simon Forsberg43 secs ago
I've undertaken the project of creating my own programming language, Linny. It's a very, very simple language, with only variable creation, variable changing, and outputting to the console, but I've very proud of it. It's an interpreted language, with the interpreter being written in python3. The...
Questions involving improving otherwise working code are better suited on Code Review, but be sure to follow their posting/content guidelines. — jmoerdyk17 secs ago
here is a code of a simple contact form that I have created, I believe that the form is server-side protected against empty fields, header injections, CSRF, XSS, bots using 'Google reCAPTCHA v3' and so on..
The call is done through AJAX..
I just wanted to share this code and I am open to any sugg...
I new in vue.js and i need fast rewrite my js code.
There custom inputs validator.
Is this good way to use following methods:
methods: {
checkInput: function () {
let callerClasses = event.target.classList;
let inputTo = document.getElementsByClassName("inputTo");
le...
I'm trying to write a script that will allow me to load pictures contained in my workbook into my userform dynamically in an attempt to make the workbook completely portable. I've come up with the following that seems to work but there is one line which I don't understand why it doesn't work with...
This is a Knapsack problem, there are plenty of available algorithms for you to implement. If your code works but you need to speed it up/improve it in other ways, this might be more appropriate for code review. — user348320341 secs ago
Please try to ask a specific question. SO is not for code review or general debugging. — Calum Halpin9 secs ago
To clarify, yes - this could use some optimization (code review site - use the iterator it gives you), but it is the brute force knapsack solution and will fail horribly on a larger dataset. — Kenny Ostrom9 secs ago
Welcome to StackOverflow. Please follow the posting guidelines in the help documentation, as suggested when you created this account. On topic, how to ask, and ... the perfect question apply here. StackOverflow is not a testing or code review site. When you can demonstrate a reproducible problem, then you have an appropriate posting. — Prune59 secs ago
@dfhwze I plan on finishing it, but it's been on hold since April because I had to move. I could start a new project utilizing Entity Framework, now that I know EF supports stored procedures. Why are you asking? There have definitely been changes since both questions you answered. How does one normalize tables in a code first approach?
@dfhwze I still have one or two problems in add book that I haven't looked at in a while. I also need to set up unit tests for the c# code, currently only the database has unit tests.
@pacmaninbw The way we used to do it (current projects are in Oracle and NHibernate) is generating scripts (stackoverflow.com/questions/13939404/…) and then we could edit the scripts before we ran them.
@pacmaninbw It's imperative you make proper use of interfaces to allow for TDD (test driven development)
@dfhwze I haven't created unit tests in Visual Studio, I have done with shell scripts (C and C++ on Unix), PHPUNIT on Linux and SQL scripts using MySQL on windows.
A few months ago, I wrote a library that implements BRE(Business Rules Engine). But I can't find any programmer who can(and wants) to review the code.
What is this library for?
This library allows you to simplify the writing of rules for business processes,
such as complex discounts calculation...
I have a webserver that replies with {"data":true} if it receives the right number between 0-999. My script is guessing the number by sending numbers 0-999 to the server one by one using the requests library. However, this is a very slow process.
How could I make the requests asynchronous, let's ...
What is it?
The google sheet that the macros are on acts as a sort of "back-end" for the records of a behaviour system at a school. I build multiple google sheets that link to this one that pull the data. Each week the behaviour records are put in this main sheet and then formulas total up the r...
I am using 3 forms which are used very much inside my project. Cause my skin elements are some kind of heavy, i deside to re use this 3 forms instead of creating again and again each time. Here i will write a mini example of my code.
Form1
private void button1_Click(object sender, EventArgs e)
...
I am a part of group that is building ERP for some months. We are having a practice of Anemic domain model. After few researches I came to know about Rich Domain Model. As ERP is considered to be a long lasting product , which would be better? Along with that I am adding code snippet to know abou...
I am relatively new to scripting. My programming experience stems from a QBASIC course when I was 11, and teaching myself HTML when I was a teenager (a while ago).
This script resides on what is essentially a log of orders for a company. Occasionally, orders will be "shorted" if all the products...
#define loop(n) for(int i=0; i<n; i++) - If I saw this in a code review I would have a serious talk with my manager about getting rid of the idiot who did that. — Jesper Juhl48 secs ago
I wrote a bit of code to create an array out of another array where each batch will have maximum 100 records and then the last batch will have the last remaining records.
Here is the code but I am not happy with it, I would like to refactor it into a more smaller and cleaner code. Can anyone hel...
I am creating a simple python Tkinter calculator. My code works however when I was due to submit my code in my teacher said that my code is inefficient and recommended I change the following:
Create buttons using a for loop
have two classes - one of which is for the definitions of the functions...
At the moment I have this:
function getValue(str)
{
let result = 0;
var regex = /(\d+[a-z]+)/g;
match = regex.exec(str);
while (match != null)
{
var match_str = match[0];
var last_char = match_str[match_str.length-1];
if ( last_char == 'h' )
...
"This is {0} cool!", "freaking"
I've always wanted an easy and intuitive way to inject variables into a string. So after about 10 variations, I finally came up with this function.
How it works
The concept is that I can find every pattern such as {key} or {0} or whatever {taco} and get a uniq...
I am already coding in Java since some years as a Hobby but I always think that I make things wrong and have to improve my coding but I dont really know where to start or what to do so if someone would take his time and look at some of my code and tell me what are typical mistakes or wrong things...