instruction_seed stringlengths 71 95.1k | _source stringclasses 1
value |
|---|---|
I have finished Project Euler #9 on HackerRank:
Given \$N\$, Check if there exists any Pythagorean triplet for which \$a+b+c=N\$, \$a^2+b^2=c^2\$.
Find maximum possible value of \$abc\$ among all such Pythagorean triplets, and if there is no such Pythagorean triplet print −1.
However, I feel uncomfortable about my... | stackexchange/codereview |
I'm making a game. There is a turtle and lots of platforms it can walk on. It walks on its own and you can change the direction it is walking. I implemented a working logic, but I think it can be improved.
I made 2 classes (one for the turtle and one for the platforms).
class Turtle
{
public Rect HitBox;
public... | stackexchange/codereview |
In the SplashActivity of my Android Application, the following sequence of events occur:
Check if Google Play Services is installed
If Google Play Services are available, start the InstanceIDListener service
Check if app needs to be updated
Load country info using network IP
Previously, I'd implemented this logic usi... | stackexchange/codereview |
My team and I are trying to implement a secure API and would appreciate some feedback on the following:
If there are areas of improvement in the current code to improve security
Recommendations on other secure API implementations, if any, that would fit our requirements better (see below)
If there are any major loopho... | stackexchange/codereview |
I am dealing with the following problem:
Write a method for the Queue class in the queue.java program (Listing 4.4) that displays the contents of the queue. Note that this does not mean simply displaying the contents of the underlying array. You should show the queue contents from the first item inserted to the last... | stackexchange/codereview |
I'm working on an experiment to parse speech out of an emote in a text roleplaying game (MUD) so that if you can't hear it correctly, or if it's in a different language, you won't understand it. This works correctly, but I was just wanting to make sure it was as clear and efficient as possible.
import java.util.Scanner... | stackexchange/codereview |
I have a component that displays a bunch of selectable options in a single row. It takes a pageSize prop from the parent component due to responsiveness requirements.
If the pageSize prop ever changes, I need to reset the currentPage (currently active page), which is held in state, to 0.
class OptionsRow extends React.... | stackexchange/codereview |
This is the third iteration of the Natural language text fast tokenizer code review. Special thanks goes to G. Sliepen, Toby Speight and uli who conducted previous reviews and to Matthieu M. and Adrian McCarthy who participated with important findings.
Functional specification
Implement a function for fast text tokeniz... | stackexchange/codereview |
I created this class to keep track of a user's role:
class UserRoleHelper extends AppHelper
{
public $helpers = array('Session');
private $role = NULL;
const CUSTOMER = 'customer';
const ASSOCIATE = 'associate';
const MANAGER = 'manager';
const ADMIN = 'admin';
const DEVELOPER = 'de... | stackexchange/codereview |
I want to improve quality of this symfony rest endpoint (solid principle, Kiss, best practice...) Can you review my code please?
Symfony controllController function that return json list of product
/**
* @Route("/api/products/my_list/{number}", methods={"GET"})
* @param Security $security
* @param BeamyAPI $beamyAPI... | stackexchange/codereview |
I am running through an app idea to help improve my knowledge of Javascript. The code attached performs the following:
Performs a regex on the input field to check it is value 0-9 If not,
it clears the field and shows a warning (Although this only seems to work on FF)
If it passes, updates the styles of the preview bo... | stackexchange/codereview |
Project Euler Problem 27
Euler discovered the remarkable quadratic formula:
\$n^2 + n + 41\$
It turns out that the formula will produce \$40\$ primes for the
consecutive values \$n = 0\$ to \$39\$. However, when \$n = 40, 40^2 + 40 + 41 =
> 40(40 + 1) + 41\$ is divisible by \$41\$, and certainly when \$n = 41, 41^2 ... | stackexchange/codereview |
I wrote a simple shared pointer, which I think works pretty well. I would like to see your review of it.
This is the header file:
#pragma once
#include <algorithm>
template <class T>
class SharedPointer
{
private:
T* ptr;
int* counter;
void swapp(SharedPointer& first, SharedPointer& second);
public:
... | stackexchange/codereview |
I have this CLion project on GitHub. It constructs a directed, weighted graph consisting of 100 thousand nodes and 500 thousand directed arcs, picks two random nodes, and computes the shortest paths between the two using both versions of the Dijkstra's algorithm.
Code
algorithm.c:
#include "algorithm.h"
#include "dary_... | stackexchange/codereview |
I have made this little program for fun, to add on my personal webpage. I remember seeing something like it some time ago, don't remember exactly where, and I tried to reproduce it myself.
As it turns out, I figured out that it isn't quite fun to have your CPU stressed out by 25% because of a funny single homepage, so... | stackexchange/codereview |
Had to create this for my class, figured I'd get some advice/insight on how I can advance my program while making it more efficient. Also want to help anyone who may come across the same assignment and is in need of direction; with this said, I would have regretted copying anyone work because I learned a lot about C sy... | stackexchange/codereview |
I am using Callable in my code which will be called by multiple threads as shown below. Given a user id in DataKey object, I will find out what are the hostnames I can use to get the data and then I will iterate that hostnames list one by one to get the data.
As of now, whenever any RestClientException is thrown on a ... | stackexchange/codereview |
Someone asked if their singleton is good for OOP:
Using a singleton class to get and set program wide settings.
However, the answer just provides tweaks to his existing code - but the question wasn't entirely answered. What is the best practice to use for configuration files so that it doesn't become spaghetti code?
Al... | stackexchange/codereview |
I'm currently learning C# as first programming language and I've made a simple program to exercise the basic concepts. It's nothing fancy especially compared to advanced stuff you normally talk about, but I would like to know if I've made some common mistakes or I missed some good practices.
Basically I created a log-i... | stackexchange/codereview |
We have a working implementation that is doing I/O operations, returning data from blobs in an async/await manner from Azure Blob Storage.
//Method1 is not async, this is what is called from the controller
public IEnumerable<Data> Method1()
{
//Running the async method and returning the result from task
return... | stackexchange/codereview |
I wanted to use the Try helper from @DmitryNogin's General Retry Strategy #2 but each attempt to implement it revealed another thing that is missing.
In my review I mentioned that it would be useful to be able to log the exceptions but later I came to the conclusion that perhaps it would be better to implement somethin... | stackexchange/codereview |
I made the following code to take two reports and compares them to show the end user elements which are missing from one of the reports so they can make the adjustments needed.
This is the main part of the process where the data within the two reports are processed and it's working with around 85K lines in one report... | stackexchange/codereview |
I developing an algorithm to read a row from a table (specifically, I'm reading from an Excel file).
I have three conditions about when to terminate the Read operation:
When an empty cell is found (recognized by an ElementNotFoundException
When a cell with errors is found (which corresponds to a null value)
Both the t... | stackexchange/codereview |
Even though singletons are bad practice and often unnecessary, I still see many developers using this pattern over and over. Since implementation of this pattern usually requires some common code, I thought we could just make a base class to be extended.
I came up with this so far.
<?php
namespace wl;
/**
* @dosc al... | stackexchange/codereview |
This is my array implementation on stack in Java. It involves push, pop, get and growth when limit of array size is reached.
I am a self-taught programmer starting to learn data structures and algorithms.
I am looking for
any recommendation on conventions
an honest opinion on how bad this piece of code if this is an i... | stackexchange/codereview |
Is there any way to make that code shorter? I still want to use jQuery. I don't want to use any validation script.
$("#form").submit(function (e) {
var tmp = $('#select-1').val();
var tmp1 = $('#select-2').val();
var tmp2 = $('#select-3').val();
var error = $('#error-1');
var error2 = $('#error-2');
... | stackexchange/codereview |
I have a block of code that pulls the current menu position and compares it to what users selected, if the selection is different the database is updated with the new selection. As I am still new with EF I was hoping for a general code review for suggestions on a possible better, more efficient, and/or easier way to co... | stackexchange/codereview |
I'm using multiple jQuery filter functions to affect the background color of select objects based on the selected option and it works, but it seems bulky/redundant. Does anyone know how these filter statements could be simplified/combined? I have a JSFiddle here.
<head>
<!-- Load minimum jQuery -->
<script src="http... | stackexchange/codereview |
I made a function that converts Roman letters to integers. But I'm not happy with it, as I feel like I used too much code for a such a simple task. Any suggestion on how I can minimize it?
values = (('M', 1000),
('CM', 900),
('D', 500),
('CD', 400),
('C', 100),
('XC', 90)... | stackexchange/codereview |
I wrote a function in Java that edit file name, and replace each space char into dash char.
Currently I iterate all the files in a specific directory, iterate in each file name, creating a new file name, and replace the file in the directory.
I guess that the current complexity is \$O(N*M)\$ with
\$N\$ being the nu... | stackexchange/codereview |
The code returns the mean of a list of integers, except ignoring the largest and smallest values in the list. If there are multiple copies of the smallest value, ignore just one copy, and likewise for the largest value. Assume that the list is length 3 or more.
For this problem, as part of my learning, I’ve defined my... | stackexchange/codereview |
This file enhances PostScript with a few new syntactic niceties for defining functions with named arguments and even type-checking.
block
The first part of the enhancement consists of a new control structure called a "block". A block is a list of pairs which will be collected as key/value pairs into a dictionary and th... | stackexchange/codereview |
Before I used reflection to invoke a state based on the string, it looked like this:
public void setState (String state) {
try {
this.state = (State) Class.forName("state"+state).getConstructor().newInstance();
} catch (Exception e) {
System.out.println ("Tried to set state to " + state.toString... | stackexchange/codereview |
I created a console program that tests report results from JasperReport. It retrieves the list of reports, splits it, and passes each sublist to a new thread. Each thread executes its own reports and compares the results with reference files.
My colleague says multithreading is wrong, but as usual he doesn't explain wh... | stackexchange/codereview |
I have only recently started learning python and the below is my attempt to create an 'interest rate' object which, given one of several types of interest/discount rate, gives the user access to all of the other corresponding rates that are equivalent to this. This looks as follows:
import math
class InterestRate:
... | stackexchange/codereview |
I have a small console application that runs a very long task and I would like to hide the console window when I click on the minimize button but keep a notify icon in the system tray so that I would know when the task is completed or something went wrong.
Well, I did a lot of research mostly here on SE and I came up w... | stackexchange/codereview |
I have started working on the projects listed here. I want to practice my C++ coding skills. I would love any constructive criticism I can get!
This is for the very first problem, #1 "Grading Program"
#include <iostream>
using std::cout;
using std::cin;
int main()
{
int UserNumber;
char Grade;
cout << "... | stackexchange/codereview |
Teachers can raise 'dramas' which are when students forget equipment, don't do homework or are flagged for concern. Each drama for each student is stored as a separate record.
I seek a list of all unresolved dramas, grouped by student & date. So if on one day a student forgets their homework and doesn't have equipment,... | stackexchange/codereview |
I have designed a C++/CLI wrapper library that allows C++ applications on windows, and other platforms that can load C dlls (e.g. Java via JNA or Python) to make calls to my .Net library.
I was wondering if my dll import/export header, which will be used by external developers, complies with the current "best practice... | stackexchange/codereview |
In part one (Tkinter program to teach Arabic) I was asking for help to review the part of the program responsible for managing the main screens and links to all of the different lessons. From the responses I got, I was able to reduce a lot of redundancies in my code thru the use of classes (a new skill for me) and was ... | stackexchange/codereview |
For the past few days I've been working on a AES-128 encrypt/decipher class. I needed something very scaled down from Cryptolib so that I didn't have to constantly import the .lib file on all my programming computers (work, home, laptop1, laptop2). I've decided that since I will only every use AES-128 for one my progr... | stackexchange/codereview |
This is my Clojure code for finding prime numbers.
Note: this is an advanced version which starts eliminating from i*i with step i, instead of filtering all list against mod i == 0 (Sieve of Eratosthenes).
It has better asymptotic runtime: O(n log log n) instead of O(n log n) in typical examples of finding primes in Cl... | stackexchange/codereview |
I wrote a mouse and keyboard event system in C++, using the GLFW library to get mouse and keyboard states.
I've been working on a 3D game engine of my own for a long time (about 9 months) and wanted to have a way to handle input independent of having to intertwine GLFW calls randomly in my code (thought this would be g... | stackexchange/codereview |
Question:
Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string "".
Example :
Input: strs = ["flower","flow","flight"]
Output: "fl"
Source: https://leetcode.com/problems/longest-common-prefix/
My Code:
public String longestCommonPref... | stackexchange/codereview |
My background is primarily in C#. Though, I've gotten comfortable with JavaScript, I feel that stylewise my JS code looks more like C# code.
Does the following code's style conform to "standard JS style"?
processArray = (myArray) => {
if(typeof myArray === "undefined" || myArray == null || myArray.length == 0)
... | stackexchange/codereview |
I have a class that loads locales from a database. I'm not sure if locale is the right word. It's basically loading texts for a game, generic sayings like alerts and error messages.
I'm also not sure if it should be called WhateverHandler or WhateverController, maybe even WhateverManager. I tend to get really OCD about... | stackexchange/codereview |
I am writing a WPF application that needs to access information from a database (I am currently using Entity Framework code first, so data access is via DbContext).
My ViewModels directly instantiate my DbContext derived class and query this to obtain the information they require. I understand that this is bad for the... | stackexchange/codereview |
I am trying to generate Pascal's triangle table in Python 3. I started to like using this following pattern when dealing with 2D arrays.
Generate a list of valid indices
Use a function that works with those indices in a list comprehension. (may produce side effects)
I wonder, is this pattern pythonic and how common i... | stackexchange/codereview |
I am building a UI which fetches a list of features based on an ID and then the user can edit the list of features and save it. The script also build the UI based on the data structure currently hard coded in.
Was hoping you guys review it and let me know how I can improve it
"use strict";
var activeFeatures = [
... | stackexchange/codereview |
This is my DAO object that takes the Cypher query as a string, and returns a JSON representation of the graph it returns.
Because it's using a Spring JdbcTemplate to access the database, the jdbc query will return any errors wrapped in a DataAccessException.
What I'm wanting to do here, is detect whether the error be... | stackexchange/codereview |
Is pattern matching within a unit test a code smell?
Do I really need to throw an exception just for my test to fail if the function under test receives invalid arguments (i.e. not Succeeded case value)?
Here's my test:
[<Test>]
let ``get available positions for black soldier`` () =
// Setup
let piece = Blac... | stackexchange/codereview |
I run a small server, and to check whether clients are being hosted on my server, I wrote this. I'm new to object oriented programming. How stratified should my programs really be? Do I want to have every possible variable and piece in their own function? Also, how am I doing in general? Any recommendations?
class D... | stackexchange/codereview |
I would like a review regarding the following code in which I index and search the City model. Currently both solr (with sunspot gem) and elaticsearch (with the tire gem) are show. I am migrating from solr to ES and want to make sure I am not making any major mistakes.
I am new to ES.
class City < ActiveRecord::Base
... | stackexchange/codereview |
I already solved this one from CodingBat, but I'm unsatisfied with my solution and I feel I could have made it much shorter. Most of the other recursion tasks could be solved by a one line conditional for the base case and a one line return statement usually using ternary operator. So, could I have made this any shorte... | stackexchange/codereview |
I have been Googling for a few days and am trying to find the best practices when it comes to using the Repository pattern. But what I found that there are no standards and everyone claims that their approach is the best approach. However, I have come up with this design based on what I have read online.
It it good p... | stackexchange/codereview |
I need to compute the number of target values \$t\$ in the range: \$-10000 \le t \le 10000\$ (inclusive) such that there are distinct numbers \$x, y\$ in the input file that satisfy \$t= x+y\$. I have the code which does work and would like to optimize it to run it faster.
Also, we'll count the sum \$t\$ only once. If ... | stackexchange/codereview |
#!/usr/bin/bash
# debug
#export PS4='$LINENO + '
#set -x
# description : #TODO
#
#
# PERSONAL FUNCTION HERE
########################
##
#
#TODO
#
##
########################
# help information
myhelp() {
#TODO
echo "usage : mksh [options] {files} "
echo ''
echo " -h,--help check for help"
e... | stackexchange/codereview |
After learning the basics (isolated state, communication and computation) of the the Actor-Model, I wrote my own implementation and I'm ready for a thorough code review.
You will be able to see that in the test code I've created 2 tasks which are simultaneously sends multiple messages to an instance of the Actor class.... | stackexchange/codereview |
This is quite final code of a script. It looks to me a little messy ad repetitive.
What can I do to improve it?
jQuery(function($) {
'use strict';
/*
* This Object calls a editor based
* on the choice of a radio input
*/
var wiz_ajax = {
callUrl : setup.ajax_url,
... | stackexchange/codereview |
I am attempting to learn Python. It was suggested to me to try a web scraper, so I thought to get myself to look at multiple Nagios instances. I have not programmed in Python before, but learned from other code reviews to adapt my standards to PEP8. The online checker says the code passes.
from bs4 import BeautifulSoup... | stackexchange/codereview |
I have done a lot of research on OOP and I keep seeming to read different opinions on several items, especially the scope resolution operator (::) and handling class containing private functions.
When calling a private function from within the class it seems that a majority of programmers recommend self::method(), is t... | stackexchange/codereview |
How can I improve this code?
public class Address {
public string house_no { get; set; }
public string street { get; set; }
public string zip { get; set; }
}
public class Contact {
public string email { get; set; }
public string ph_no { get; set; }
public Address address ... | stackexchange/codereview |
Can I somehow make this a bit cleaner using Math.[Something], without making a method for it?
int MaxSpeed = 50;
if (Speed.X > MaxSpeed)
Speed.X = MaxSpeed;
if (Speed.X < MaxSpeed * -1)
Speed.X = MaxSpeed * -1;
if (Speed.Y > MaxSpeed)
Speed.Y = MaxSpeed;
if (Speed.Y < MaxSpeed * -1)
Speed.Y = MaxSpe... | stackexchange/codereview |
I finished the Python Koans because I wanted to practise Python and I completed the extra assignment which is the Greed Game (see the rules here).
I think there are no flaws but you never know.
import random
class DiceSet(object):
def __init__(self):
self._values = None
@property
def values(self):... | stackexchange/codereview |
I code a lot of web crawlers and web scrapers and I find myself writing the same functions over and over again. I also find myself having to come to Stack Overflow and find the answer to a question I have had to ask myself a dozen times. Things like "how to supply proxies to requests" or "how to use custom headers with... | stackexchange/codereview |
This code is part of a larger mapping library I'm working on to address some business concerns of transforming data. I was inspired by mapstruct in Java, but opted for users to annotate / add attributes to a poco to control the mapping operation.
Because reflection can be an expensive operation, I opted for scanning al... | stackexchange/codereview |
I feel like the main point of inefficiency is how I create "notches" and must loop through all of the created notches every time the value for the slider is changed.
function sliderLoop() {
for (var i = slideNotchArray.length - 1; i >= 0; i--) {
if ($(".slider").val() >= slideNotchArray[i].value) {
c... | stackexchange/codereview |
I had to create this makefile to build and debug a C++ console app. I just need some hints and tips on how I can organize my makefile.
CC=g++
CFLAGS=-c -Wall
LDFLAGS=
SOURCES=helloWorld.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=helloWorld
all: $(SOURCES) $(EXECUTABLE)
debug: CXXFLAGS += -DDEBUG -g
debug: CCFLAGS += -... | stackexchange/codereview |
My first piece of code encrypts text by moving each letter in the string 5 letters across in the alphabet.
encrypt = input('Enter text to encrypt : ')
encrypt = encrypt.lower().replace(" ", "")
for i in encrypt:
print(chr(ord(i) + 5))
decrypt = input('Enter text to decrypt : ')
decrypt = decrypt.lower().replace(" "... | stackexchange/codereview |
I have the following code that takes input of Line arrays and attempts to find the intersections on the end points between them. The value _nConrerTolerance is an int of a value of around 10% of the average Line length to allow the lines to not need to be exactly on each other. Now obvisouly this code will be quite slo... | stackexchange/codereview |
The CSyncObject object in CSingleLock constructor can't be NULL but I want it to work with NULL because I need to use this nest.
BOOL CADODatabase::Open(LPCTSTR lpstrConnection, LPCTSTR lpstrUserID, LPCTSTR lpstrPassword)
{
CString database = GetSourceDatabase( lpstrConnection, NULL );
// get the appropriate ... | stackexchange/codereview |
Link here
I'll include a solution in Python and C++ and you can review one. I'm mostly interested in reviewing the C++ code which is a thing I recently started learning; those who don't know C++ can review the Python code. Both solutions share similar logic, so the review will apply to any.
Problem statement
Determin... | stackexchange/codereview |
I have code to find images in my selections. But when nothing in selection (loop FOR) and selection is kinda big, it's kinda laggy. How can I improve my code?
var toStageCoord = map.stageXYToCoordinates(toStage.x + selection.x1, toStage.y + selection.y1);
var element1 = document.elementFromPoint(toStage.x + select... | stackexchange/codereview |
Here is the link of the problem for which I need your help.
I came up with solution and it is working fine for all cases, but it takes more time. I need your help in reducing the runtime of code. I unable to optimised it more.
#include <iostream>
#include <string>
using namespace std;
long nChoosek( unsigned n, unsig... | stackexchange/codereview |
I am trying to learn how to tell if my code will be better off creating a class as opposed to using many functions. I am a new Python programmer trying to get the hang of when classes should be implemented.
Determines whether the username is valid or invalid:
def is_good_user(user):
is_user_good = True
if user ... | stackexchange/codereview |
I've created a menu that allows you to display the list when clicking on the menu icon. I wonder whether this can be improved somehow - can anyone help improve this?
Also, initially I created it with the event passed into the script to prevent it from scrolling to the top when clicking on the link. I then changed it to... | stackexchange/codereview |
(See the next iteration.)
I have this tiny library for building HTML pages in Java code:
HtmlViewComponent.java
package net.coderodde.html.view;
/**
* This abstract class defines the API for logical HTML view components, that
* may consist of other view components;
*
* @author Rodion "rodde" Efremov
* @version ... | stackexchange/codereview |
I have an if-else statement in a php class, which works perfectly. I want to know if there could be an any better or faster way to accomplish this?
<form method="post" action="">
<input type="text" name="value_1" value="" ><br>
<br>
<input type="text" name="value_2" value="" ><br>
<br>
<input type="submit" value="su... | stackexchange/codereview |
I'm studying nodejs w/ graphql and I would like to make sure I'm going in the right direction here.
My study project is based on a simple ERP with entries, products, orders and users.
I have one mutation that creates products indiviadually but I thought that allowing add products while creating a new entry (same mutati... | stackexchange/codereview |
I've been grappling with Unity's architecture for the last few days, trying to work around the fact that you can't use constructors for your MonoBehaviours (and by extension, you can't easily configure components before Awake if you create them programmatically). I've got a pattern now that I'm fairly happy with, but b... | stackexchange/codereview |
I implemented a basic dynamic array using C++.
When deleting an element and shifting the others, the last element will be twice repeated (the original still exists after copying). I want to avoid memory leaking by deallocating the last element of the array. Currently, I do this by shrinking once after a number of dele... | stackexchange/codereview |
Task:
Class for connecting to a mqtt broker using QMqttClient and getting notified on connect and disconnect.
Context:
I'm trying to write modern C++ (standard 2011 and up) code - using smart pointers. I have only created small projects for learning C++. I'm not very confident if I'm using those pointers correctly.
Th... | stackexchange/codereview |
Given a list of Players with score, I want to find the ones with the highest score. There can be multiple players with the same score. I'm doing it like this now:
class Player {
final String name;
final int score;
Player(String name, int score) {
this.name = name;
this.score = score;
}
... | stackexchange/codereview |
When a user clicks on "Case", it pops up a box where they have to input a number, which is later used to calculate the value to Euro and around to other values. After this, it checks which value is larger than 0 and writes it to the display box with a white line between each value.
I want to optimize this code. What's ... | stackexchange/codereview |
I wrote the following to output, at the type level, the sum, Nat, of an input HList:
trait HListSum[L] {
type Out
}
object HListSum {
type Aux[L, O] = HListSum[L] { type Out = O }
def apply[L <: HList](implicit ev: HListSum[L]): ev.type = ev
implicit def hListSumInductive[H <: Nat, L <: HList, S <: Nat, T <:... | stackexchange/codereview |
Inspired by recent questions about counting the rooms in a floor plan
(1,
2,
3),
here is my attempt to solve the problem with a Swift program.
The problem (from “Counting Rooms” on CSES) is:
You are given a map of a building, and your task is to count the number of rooms.
The size of the map is \$ n \times m \$ sq... | stackexchange/codereview |
I am tracking trains and trying to identify individual trains seen multiple times at different points through the IDs of the wagons on them when spotted.
// create a lookup of all tracked trains for each wagon
IEnumerable<Train> trains = GetTrains();
var wagonTrains = new Dictionary<int, List<Train>>();
foreach (Train... | stackexchange/codereview |
I'm creating a class which uses a custom buffer. I want to offer the possibility to pass an external memory address (for higher interoperability between languages) or (for convenience) to specify a custom allocator type. The following code outlines what I mean:
template<typename int_type, class alloc = void>
class uses... | stackexchange/codereview |
I have a text file containing integers in different lines which I want to read into a list of lists.
So
01
11 14
45 50 09
should become
((1)
(11 14)
(45 50 9))
The real file is longer so I want to read it in using CL instead of transforming it using Emacs' macros etc. It is important that every line becomes exactly... | stackexchange/codereview |
I've created a variable order Markov chain built on top of a tree, but I can't train on datasets >1MB worth of text without running out of memory. I'm sure the tree can be replaced by something else more efficient, but I'm struggling with figuring that out. I've heard a linked list might work, but I'm not sure how.
Bel... | stackexchange/codereview |
I will try to be as concise as I can:
The goal: trying to universalize a specific section of a project, that is dealing with the SQL database transactions.
To assist you with your answer, I've pasted the following (just for reference):
a usage code: GetTestOfTablTime() returns a DataTable
class: SQLDBInteraction is a... | stackexchange/codereview |
I've been learning C++ on my own and working solo on trying to implement some of the concepts I've been reading.
I'm wondering if this is the correct group to get someone to point me to other info regarding the code I've wrote or if I'm getting the concepts right.
I've tried to build Tic Tac Toe using a class system. I... | stackexchange/codereview |
Do two circles in a 2D plane disjoint?
$$(r_1 + r_2) \cdot (r_1 + r_2) \gt \Delta{X} \cdot \Delta{X} + \Delta{Y} \cdot \Delta{Y}$$
Any comments / corrections on this code?
internal struct HoleInfo
{
public float Diameter { get; internal set; }
public float X { get; internal set; }
public float Y { get; inte... | stackexchange/codereview |
You are given information about users of your website. The information
includes username, a phone number and/or an email. Write a program
that takes in a list of tuples where each tuple represents information
for a particular user and returns a list of lists where each sublist
contains the indices of tuples co... | stackexchange/codereview |
This code outputs each tag followed by its attributes in the given HTML, both in lexicographic order. It must be possible to keep the spirit of the code without these many nested cycles and conditionals.
from bs4 import BeautifulSoup
htmlist = ['<div class="portal" role="navigation" id=\'p-coll-print_export\'>',
... | stackexchange/codereview |
add9 = []
add9.append(int(input("Enter 1st 4-digit no.: ")))
print(f"The answer will be 2 and {str(add9[0])[0 :-1]} and {str(add9[0]-2)[-1]} = 2{add9[0]-2}")
add9.append(int(input("Enter 2nd 4-digit no.: ")))
add9.append(9999-add9[1])
print(f"The 3rd 4-digit is 9999 - {add9[1]}= {add9[2]}")
add9.append(int(input... | stackexchange/codereview |
Here is a program that will parse and print XML feed URLs. I want to reuse most of it to add post date to each link. This adds a new concern of CLI and output formatting on top of parsing and (poor) error handling. I wonder how much of this code has enough value to put is in a wrapper utility and how much should be sim... | stackexchange/codereview |
I have written an answer to this question on Stack Overflow. To make it easier for you, I have copy-pasted the question below.
Your friend wants to try to make a word ladder! This is a list of
words where each word has a one-letter difference from the word before
it.
Here’s an example:
cat
cot
cog
log
Write a pr... | stackexchange/codereview |
I have small Class which handles user's information. (name, surname, login, hash of password). Also this class can activate, register and login the user. This means I should connect to DB. Is it normal? I'm using Pear MDB2 to connect to DB.
Does it mean that every instance of User will have MDB2 object initialised?
cl... | stackexchange/codereview |
I am trying to return a value (a.tnAddress) from a custom class based on a lookup (foreach loop). Depending on the type of transaction, I will need to do the foreach loop based on different properties (sExecID, iMsgSeqNum, orsClOrderID). I prefer to not have 3 differentforeach` loops just but I am not sure how else t... | stackexchange/codereview |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.