instruction_seed
stringlengths
71
95.1k
_source
stringclasses
1 value
Background Trevor wishes to duplicate an array, transforming it by multiplying its elements four times. Existing Solution // var atest = ['a','b','c']; var btest = []; btest = atest.concat(atest).concat(atest).concat(atest); // console.log(btest.length); // btest.length == 12 console.log(btest); // [...
stackexchange/codereview
Recently I asked a question on Programming SE about public vs private methods fo unit testing, which generated a lot of interesting responses. I only posted a skeleton of the code there, as it was a question about structure and not about the code itself. However, several respondants queried whether my code might be ove...
stackexchange/codereview
I am using ExcelDataReader to import an Excel file to a dataset. Example Excel table: //ID Name Display Order Active //1 John 1 1 ID, DisplayOrder and Active columns are read as double, so I have to convert them to long, int and bool types respectively. I need to create a list of...
stackexchange/codereview
I was asked the following question while trying to get a Hackerrank certificate. I couldn't solve on time but I now completed the solution. Can you please check if my solution seems good? Suggestions on improvement are appreciated. Q: You have a rectangle of width w and height h. You will start to draw boundaries. The ...
stackexchange/codereview
I made a simple authentication system with php for an elm webapp that will have a small number (1 - 5) of users able to log in. I am planning to send the users their php session-id at login, and keep this in memory while the app is running in order to anthenticate all the requests sent by the app to the server. Elm a...
stackexchange/codereview
I have a program that will get all possible permutations of a certain equation: A + 13 * B / C + D + 12 * E - F - 11 + G * H / I - 10 == 66 Where A, B....I is a value 1-9, and where each digit is used only once in the equation (So if A is 1, no other variable can be 1). There are 136 different solutions for this. usi...
stackexchange/codereview
I have written the code below for inserting an element at the position specified by the user. I have seen the code in multiple books, and they have always used two pointers in the function that inserts the node at specified position. However, in my code I have used only single pointer. My code works fine, but I want to...
stackexchange/codereview
I need to call an upsert to my Category table in PostgreSQL. My current solution uses the exec_query API in ActiveRecord, using binding. What I got so far looks like this: VERIFY_CATEGORY_SQL = <<SQL WITH sel AS (SELECT id FROM categories WHERE name=$1 AND source=$2), ins AS (INSERT INTO categories (name, source,...
stackexchange/codereview
I have a pair of General Ledger accounts to scan for data. I need to find a keyword or phrase from the descriptions and then collect certain bits of data from those lines. The source tables (there are two) are on separate tabs and the data from that needs to populate 5 other tables of data for analysis. This is the cod...
stackexchange/codereview
This is a Python script I wrote to generate a SVG animation of falling leaves. How can I simplify my script and also make the animation look more realistic? import xml.etree.cElementTree as ET from math import sin import random # author Kyle Kersey # configuation leaf_count = 30 min_fall_duration = 10.0 max_fall_dur...
stackexchange/codereview
I'm not sure if this is the correct place for an optimization question like this, but I'm not even sure where to start looking. So here it goes. There's this game I play that has very simple rules. You start with some of a resource and a single worker. This worker collects said resource and you can buy one of two upgra...
stackexchange/codereview
The discussion in the comments of this answer made me wonder how hard it would be to write a built-in only version of dirname. This is what I ended up with but I'm reasonably confident it should be able to be improved (I haven't spent much time thinking about it yet). Any improvements/suggestions are welcome. #!/bin/sh...
stackexchange/codereview
I have this script that I need to run a tab (jquery). Mainly I need to hide some div and add class (you sure have understood). How should it be written in a more elegant and readable? function fun1(){ $('#tab1 a').addClass('selected'); $('#tab2 a').removeClass('selected'); $('#tab3 a').removeClass('selected'); documen...
stackexchange/codereview
I developed this code for a vertical debounce counter for the PIC micro (PIC16F57). The code is called every 512 microseconds. It takes 5 bits from PORTB and compares it to a last known debounced state. If an active input has been stable for 64 calls it is accepted as changed. Though it is sufficiently good for the cur...
stackexchange/codereview
I wrote this blog post, but received some feedback that there are better ways to handle the situation. I'd like to get some more opinions. Here is the topic: Given a list of letters, I want to find the most commonly seen one. # create the list of letters my_list = ['b', 'b', 'b', 'c', 'a', 'b'] # simple sentence to ...
stackexchange/codereview
I was learning some DOM manipulation and interaction with third-party APIs by building a simple interface to get the people who commented on a PR on GitHub. I got great feedback for my initial prototype: Interface for getting Github PRs commenters using Github API. Now I am trying to get into OOP using ES6 Classes, so ...
stackexchange/codereview
I have created an interactive rendering of the Mandelbrot set in Processing. The image allows zooming (left and right mouse buttons) and translating (arrow keys) and prevents loss of quality by redrawing the set every time a change is made. It uses the standard color scheme from Ultra Fractal. I am not incredibly exper...
stackexchange/codereview
I am trying to make a scrolling game in Tkinter. However, with all my for loops and functions it is extremely slow. I am reading the tutorial from Khan Academy's advanced JS. In their JS game everything is fine, so is it just a problem of python is slow or am I doing things inefficiently. import tkinter as tk import r...
stackexchange/codereview
I am looking for some comments on my code and whether or not this is the best way to create an abstract class. In addition, some of the abstract methods are rarely called so I use the base variables within the subclass to make sure onCreateDialog selects the correct stuff. Hence, the getTitle() > 0 conditional. public ...
stackexchange/codereview
I currently have a container that has two features it allows adding objects to it and at the same time an independent thread continuously consumes items from it. It is a FIFO type deque. Which receives object at an extremely high rate. Following is the code for the container std::deque<Some_object*> my_container; void...
stackexchange/codereview
I'm inspecting VBA code to find obsolete code constructs - namely explicit Call statements, like this: Call DoSomething(42) The "correct" code construct would be to omit the Call token and drop the parentheses - my code locates the obsolete Call statements and rewrites them like this: DoSomething 42 I have an Id...
stackexchange/codereview
Is this code safe from injection, xss and whole other attacks or no ? The below code is for search box : if(isset($_POST["query"])) { $output = ''; $string = $_POST['query']; $search = htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); $stmt = $con->prepare(" SELECT * FROM topics_categories WHERE cat_name LIKE ? LIMIT 3"...
stackexchange/codereview
I'm using this JS to sticky website footers at the bottom and I would like to know if is there anything to be optimised? (function($, window, document){ //Screen_height = Header_height + Main_Content_height + Footer_height + alltoplvlContainersMarginTop_Bottom + alltoplvlContainersPaddingTop_Bottom $.fn.sticky_...
stackexchange/codereview
This is C++ code that consists of 9 different functions that generate Fibonacci numbers. Although all functions display same result, the emphasis is on practice to use different methods or ways. I would like to know better ways / technique to improve the existing code (especially, the fibo_9 function which uses Fibonac...
stackexchange/codereview
The scenario is we're working with a REST endpoint that gives us nice JSON objects. We're using requests, and everything works wonderfully. But one day you notice that data you though was always being pulled back isn't there for some models! You're getting index, key and attribute errors left, right and centre. What us...
stackexchange/codereview
We have two physical AWS S3s called in the code s3Legacy and s3Cache. They store the same data but with different S3 key structures. The fists solution shared below uses objects, the second does not. Is the solution using objects an excessive abstraction or there are benefits to it? (There is no need to comment on the ...
stackexchange/codereview
I would like the following code reviewed: I am trying to create a local server which listens indefinitely and provides the latest information. The server runs another while loop which fetches the latest info every one hour. I have tried multi-threading approach, in which one thread is a socket server (runs ind...
stackexchange/codereview
I've developed a simple CSS transition solution for a slide out menu with a single toggle, and would love some feedback on if anything could be simplified or improved. Markup <!DOCTYPE html> <html> <head> <title>Slide out menu</title> <link rel="stylesheet" href="css/main.css"> <meta name="v...
stackexchange/codereview
I am just starting to get my feet wet with C; and am rather enjoying myself in doing so. This is sort of a follow up to my last question here. I am posting this ordinate to hopefully getting some feedback on the logic itself, and possibly also some feedback on coding style. I do, however insist on making everything exp...
stackexchange/codereview
A recent Mandelbrot question (Hi @EBrown) in C# inspired me to build my own using the Java 8 parallel streams to implement the parallelism that's useful for computing each pixel value. The intention is to incorporate this in to a graphical interface that allows you to navigate and zoom in on the Mandelbrot set. To do t...
stackexchange/codereview
How can I reduce the cyclomatic complexity of this CloseButtonDimensions function? export function isMobile():boolean { return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|iemobile|Windows Phone/i.test(navigator.userAgent) ); } get CloseButtonDimensions(): Size { const IS_MOBILE: Boolean = isMobile(); let ...
stackexchange/codereview
Intro I want to visit the value held by a class, which could be of multiple types. This class is very similar to a std::any, so I will be using this in this question. I wanted to create a reusable solution that accesses the value efficiently (without recursion, or unnecessary calls), that worked similarly to how std::v...
stackexchange/codereview
I have a requirement to download multiple files using POST request. So I am using form submit to get this done. I have followed two approaches to accomplish this. Create a Form. Fill input details with payload data. Then set the target of the Form to _self then manually submit the Form. But I see few problems with thi...
stackexchange/codereview
In C++, to simplify string conversion between std::string and std::wstring, I created the following utility template functions: #pragma once #include <vector> #include <string> #include <cstring> #include <cwchar> #include <cassert> template<typename Td> Td string_cast( const char* pSource, unsigned int codePage = C...
stackexchange/codereview
I created this type for use in a "Wizard"-style user interaction. In each step, the user chooses an option called a Modifier and each of those options contains subselections that must be made. These Modifiers are stored with two parallel structures, one of the fixed values and a second of the selectable ones using this...
stackexchange/codereview
I wrote the following (static) class to read files easily in C#. However, it is a static class, so I wonder if there would be a gain to make it a non static method (and therefore, passing arguments as the separator and the path as attributes of the class). Besides, the OrderedDictionary class may not be a good choice (...
stackexchange/codereview
For my package dealing with pptx-files I need to create a temporary *.pptx file, to open in PowerPoint (e.g. to export as PDF). After some research I found that tempfile.NamedTemporaryFile is broken on Windows (you could have a temporary file, or you could get a filename - but you cannot have both). So I tried to build...
stackexchange/codereview
I have written an algorithm to do consecutive word match in a dataset The input is a dataset (list of textlines) and I want to scan that and return repeated word(s) in the dataset along with some metadata like the strings (lines) they matched at. I am having hard time to wrap my mind around a better approach to hand t...
stackexchange/codereview
I wrote a script which is supposed to be making requests to an API to gather a lot of data. There is a limit on requests that I can make: about 30 000 in 8 hours otherwise, I will get banned for a significant time. Each object I get from the API can be identified uniquely with a hash. Each API call returns me some data...
stackexchange/codereview
I need to allow incoming HTML in string parameters in my projects action methods, so we have disabled Input Validation. I have a good HTML sanitizer; the review I am interested in is the way I bound it into my project. I have the following Model Binder: public class EIMBaseModelBinder : DefaultModelBinder { ...
stackexchange/codereview
I find that I often want to calculate summary statistics from collections of data and decided to create a template to do that. I'm interested in a general review, but I also have some specific questions. Is the use of the lambda "too clever?" Is std::accumulate OK? Specifically, I'm thinking of the potential for ove...
stackexchange/codereview
Below is a simple random walk predator prey simulation that is optimized to the best of my abilities. I would love to hear about any improvements that can made. import numpy as np import time from matplotlib import pylab as plt import random def run(): # Initialize grid size = 100 dims = 2 # Each point...
stackexchange/codereview
I have written the following algorithm (for Android/NDK) to apply levels to a bitmap. The problem is that it is really very slow. On a fast device such as the SGSIII, it can take up to 4 seconds for an 8MP image. And on devices with ARMv6 takes ages (over 10 seconds). I know that can be speed up with NEON instructions...
stackexchange/codereview
I have created a C++ program that changes the color of a pixel to another color. But the main feature is that it not only changes 100% accurate colors; instead it matches two colors by using a method in which it takes the difference between the two colors' BGR values and then, the differences are squared to compare it ...
stackexchange/codereview
Given the following instructions I have created a function that achieves the requirements. I feel my function is a bit too complex, though it does what it's supposed to. The difficult part for myself was avoiding the equality operators. The only way I could think to solve this is with a bit of math and a comparison ope...
stackexchange/codereview
Recently I was going through this codechef problem while practicing for the upcoming zoc. The problem asks to calculate number of combinations of the given numbers where the sum is less than another given number. Previously I had a bruteforce algorithm which gave the correct answer but took a lot of time, in some cases...
stackexchange/codereview
I created a quick "demonstration of proposal behavior" tool for my post on MSO: A proposal to put ALL answerers on a path to curating better content. Because I have never asked for a review before and I am not a JavaScript or CSS SME, I'd like to see if I've used any antipatterns and how my code can be made more direct...
stackexchange/codereview
I'm working on a markdown-to-html parser for my C++ proposals. Example usage is turning markdown like this into an html page like this. The part that caused me the most frustration was having (a) tables that (b) themselves can internally use markdown. I ended up with a hacky solution that happens to work right now (bas...
stackexchange/codereview
I wanted to write a code that each time I will press some button in my menu, a numpy image array will somehow be created, and this image will show up in a new window. So the following code is the same purpose, but with the same numpy image array for all new windows (for simplifying). Which means, for a given numpy imag...
stackexchange/codereview
I am a Python beginner, and I wrote a simple Python program, which does the following: search the pattern in the lines of a file (contains messages) pick the information from the lines and save it to disk remove the messages which matches with the regex (regular expression) saves remaining messages to another file, ...
stackexchange/codereview
I made a little copy tool, but my progress bar seems to be too slow. I would also be very interested in any tips and improvements or code smells. MainForm (code behind): public partial class MainForm : Form { private FileCopy _fileCopy; private delegate void UpdateProgressEventHandler(object o, CopyProgressChan...
stackexchange/codereview
This code works, but I don't know if there are better and especially safer ways to do this. For context: this is a Django view (Python) and I wanted to unify the deletion methods because there were many of them. def delete(request, class_name, object_ID): obj = get_object_or_404(eval(class_name), id=object_ID) ...
stackexchange/codereview
I've created a short piece of code to determine whether or not various 2D shapes (circles/lines/rectangles) intersect. It was a job interview question, but now it's just about self-improvement. I'd like any suggestions for how best (in terms of code cleanliness and scalability) to handle the fact that in implementation...
stackexchange/codereview
I previously asked this question but have since improved my code: Substituting bookmarks in a Word document with data combined from an Excel sheet What happens in the code: Information about a list of suppliers needs to be consolidated into a Word document that maintains the same layout on all pages. To do this, a doc...
stackexchange/codereview
I'm trying to understand and learn about the SOLID principle and especially Dependency Injection (DI) and Factory pattern. Some background: I have a production application that uses some "helpers" classes but those are all-in-one classes that I just copy into each new project. One of the (most used) functions is serial...
stackexchange/codereview
The code below represents a lock-free ordered single-linked list, and is a modification of the algorithm proposed in this doc. How can I improve speed of searching (lookingup) in the list maintaining lock-free capability? Any suggestions, code modifications, examples, maybe other lock-free data structures? typedef uint...
stackexchange/codereview
I came across this issue in the problem titled: Another Prime Problem. Here's my solution with JavaScript which passed test case-1, but for other test cases it led to timeout. function processData(input) { input=input.split('\n'); input.shift(); for(var i=0;i<input.length;i++){ values(inp...
stackexchange/codereview
I have the following function that takes JSON and turns it into table rows: function addDataFromJson(json) { var data = json.data; var rows = ''; $('.uiGridContent tbody').html(''); for (var i = 0; i < data.length; i++) // for each row { var columns = ''; for (var b = 0; b < Object...
stackexchange/codereview
A very simple Thread pool: Any work added to the pool will be executed. The destructor will wait for all work to be finished before letting the threads stop. We then join all threads before letting the destructor exit. #include <thread> #include <mutex> #include <condition_variable> #include <functional> #include <vect...
stackexchange/codereview
I would appreciate review of this implementation of the concurrent list that is, to my knowledge, currently missing in .NET Core. Requirements Thread safe Lock free Ordered Supports get and set by index Implements generic IList Acceptable performance and time complexity compared to regular IList The main idea To kee...
stackexchange/codereview
https://plnkr.co/edit/bOZW1a9u62W1QA6cYjYj?p=preview My goal has been to separate the Dashboard states from the Feed state. Inside the Dashboard state these are the following views: Tickers, Tags, Social. Changes in those 3 should not effect the Feed module. (However changes from the Feed will eventually need to update...
stackexchange/codereview
I'm currently building a small web stack in swift for use in my iOS apps. It consists of multiple components and I want to make it resource specific; To that end, I have a WebService class composed of two parts; a part that handles the request logic, and a part that handles the parsing. The catch here is that the parsi...
stackexchange/codereview
I've been writing Python for years, but I've only just started using it in bigger programs than just simple server scripts. This means I now also want to use a more advanced logging system. To make things simple I created the following logger: import logging from inspect import getframeinfo, stack logger = logging.ge...
stackexchange/codereview
I have this specific scenario where I'm going to get a JSON that could have multiple Objects. From the Multiple Objects I will create a new Json that can have nested arrays growing by n amount depending on some json object values. I hoping there is a better way to do this. Maybe my example below is the best way? I took...
stackexchange/codereview
I wrote a simple script to translate (a subset of) StackExchange markdown to HTML. I used Regex for this task, but luckily I only had to use simple patterns. Modularization I also wrote a Regexp-generating function as I noticed that in Markdown you are always looking for things inside such and such symbols, I feel like...
stackexchange/codereview
Given an array of integer (all different from each other), this program creates a BST with the array elements in order to sort them and put them back into the array, using the BST properties. #include<iostream> using namespace std; struct Node { int label; Node* left; Node* right; ~Node() { dele...
stackexchange/codereview
Assume I have the following list (List<string>) G G M T I'd like this to be in an order where the same letter will not occur twice, such as G M G T (I appreciate other variations would also suffice) Please note, if I had the following G G G G G M T Then of course some values will have to occur concurrently. The posit...
stackexchange/codereview
I wrote a program to solve a magic numbers puzzle. The puzzle works like this: You have an NxN square where each row, column, and diagonals add up to x except some of the numbers in the square are switched. Find the numbers that are out of place and switch them. Here's an example: 16 16 11 09 14 17 09 29 13 ...
stackexchange/codereview
I have 2 <label>s being used for displaying the votes, which is up votes and down votes. There is no problem for the adding or removing votes, but the switching of votes is the issue (not really an issue). The structure of the votes in the HTML is: <label id="up_vote"></label> <label id="down_vote"></label> The va...
stackexchange/codereview
I have a view which displays a list of items, in each row I'm going to have a link, a link in each row points to different location So base upon a property called CertificationType I have to generate an address, for example if the type equals to 'BirthCertificate' I need to fetch the address from a table called BirthCe...
stackexchange/codereview
This is a game that is supposed to be based on strategy and guessing. The letters need to match in a ABCD fashion on each button on buttons[0] - buttons[3] ... and buttons[n] - buttons[n] in each square, kind of like a matrix, although there is no matrix math involved. This is how the game starts: Each time a user cli...
stackexchange/codereview
I have a piece of code that tries to get some data from a different services, falling back to the next one if previous fails. The code look a little bit ugly, though. Any suggestions on how to rewrite it in a more concise way? (defn get-data [query] (let [data-cached (get-data-from-cache query) data-service-1...
stackexchange/codereview
I need to calculate the sum of all k-sized sub-arrays in an array using sliding window algorithm. Is that a valid sliding window algorithm? If not, why? var sumOfSubArrays = function(arr, k) { let currentSubArray = 0; for(let i=0; i<k; i++) { currentSubArray += arr[i]; } let sum = currentSubArr...
stackexchange/codereview
I have the following tables structures: CREATE TABLE IF NOT EXISTS `options` ( `option_id` tinyint(4) unsigned NOT NULL, `poll_id` mediumint(8) unsigned NOT NULL, `option` tinytext NOT NULL, UNIQUE KEY `option_id_poll_id` (`option_id`,`poll_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Storing poll options...
stackexchange/codereview
By analogy with std::thread, I've written an RAII POSIX process: class posix_process { public: explicit posix_process(std::function<void()> proc_main) : _pid(fork()) { if (_pid == -1) throw std::system_error(errno, std::generic_category(), "fork"); if (_pid == 0) proc...
stackexchange/codereview
I tried to make the code for implementation of first-come first-serve job scheduling algorithm as used by operating systems. How can I make it better? I am using turbo C++ compiler #include<conio.h> #include<iostream.h> #include<dos.h> struct process//contains information about processes in waiting queue { int wait...
stackexchange/codereview
I am using this code to display all the permutations of a given input string. Any advice/solution will be very helpful. #include<iostream> using namespace std; /* Function to swap two characters */ void swap(char& a, char& b) { char temp; temp = a; a = b; b = temp; } /* Function to obtain permutations of string c...
stackexchange/codereview
I put together a Haskell function for Knuth's word wrap algorithm. A simplified version of the algorithm is described here. I've already been told that there are certain aspects of my style that are not very agreeable (e.g. lack of comments and type declarations). However, I'd like to get some opinions on where I migh...
stackexchange/codereview
I have written this class which sorts the array using bubble sort. Please let me know how can I improve it. (I don't like recurrent code in if/else statement) public class BubbleSort { public static void numbers(int[] array){ numbers(array, '<'); } public static void numbers(int[] array, char direction){ if(d...
stackexchange/codereview
I want to generate a random date of birth [mm/dd/yyyy]which will represent an age equal to less than 18years old My requirement is to dynamically generate test data [date of birth] to negatively test a system which needs a date of birth (age) to be always greater than 18 years old The system which I am trying to test ...
stackexchange/codereview
This is a simple flashcard app. With flags to control the sides of the flashcards and the number of flashcards in the session. All the flashcards without any input at the prompt, are deleted from the map. And ones with an input, remain. The idea is that, the user marks the flashcard that they want to revise in case the...
stackexchange/codereview
An implementation of BlockingQueue import java.util.LinkedList; import java.util.List; public class MyBlockingQueue<T> { List<T> queue = new LinkedList<T>(); private int limit = 0; public MyBlockingQueue(int limit) { this.limit = limit; } public synchronized void enqueue(T item) throws In...
stackexchange/codereview
I have created an Insertion Sort code that sorts numbers (obviously). #include <iostream> #include <cstdlib> void insertion_sort(int arr[], int length); void print_array(int array[],int size); int main() { int array[] = {4,6,3,7,5,9,2,8,1,10}; insertion_sort(array,10); print_array(array,10); return 0;...
stackexchange/codereview
I am reviewing some C code (see extract below) that uses inline asm. I believe there are 4 spec violations, 1 inefficiency and 1 honking big design flaw in this code. While some of the problems I'm seeing apply to both the x86 and x64 sections in that code, this post is focused on x64. Before I'll be allowed to check...
stackexchange/codereview
I have created a working VBA script that allows the user to select a workbook and make a values only copy of it without opening it. This is useful for getting data from a workbook that is very slow to open. From here: https://stackoverflow.com/questions/63398348/how-can-i-copy-the-values-only-from-an-entire-excel-workb...
stackexchange/codereview
I'm looking for a code review on the following C++/STL graph implementation: #include <list> #include <algorithm> #include <vector> #include <utility> #include <iostream> #include <stdexcept> #include <assert.h> namespace Graph { template <class T> class graph { public : explicit graph(const std::vector<st...
stackexchange/codereview
I am having a simple foreach where I add objects to a list: List<SoonestDrawDateModel> soonestDrawDateModel = new List<SoonestDrawDateModel>(); foreach (var item in drawDates) { SoonestDrawDateModel sdModel = new SoonestDrawDateModel(); sdModel.DrawDay = item; sdModel.DrawDayId = it...
stackexchange/codereview
I always wanted to know how to pass member functions as arguments, and then I stumbled across templates that could automatically deduce types, and so I rejoiced! This is used in a Publisher-Subscriber system for a game server. I wanted the subscribing to individual packet 'types' (i.e. by enum) to be simple at the call...
stackexchange/codereview
I am trying to write a script that will traverse through my directory and sub directory and list the number of files in a specific size. For example, 0kb-1kb: 3, 1kb-4kb:4, 4-16KB: 4, 16kb-64-kb:11. This goes on in multiples of 4. I am able to get the list of file numbers, the size in human readable format and find the...
stackexchange/codereview
I'm a newbie in programming. Could you please check my code and give any refactoring ideas, tips, etc... how it can be improved. I wrote a code to perform the following task: Find in randomly filled square matrix M x M max element which located in given sector, where M - is matrix size. Here is the image of how sectors...
stackexchange/codereview
To determine whether the specified array contains specific element or not, Array.Exists can be used if the given array is one dimensional. I am attempting to implement Exists method for multidimensional array cases. The experimental implementation static class MDArrayHelpers { public static bool Exists<T>(Array arr...
stackexchange/codereview
Basically I have an array of strings. In this array, a range separator word might exist. For this example, I'm going to use the word to as range separator. We can assume that the range separator is not the first or last entry in the array. If we find the range separator we need to get the entry before and the entry aft...
stackexchange/codereview
Is the code properly documented/commented? does the code handle errors properly? any suggestions to improve the code Help outline the object-oriented principles shown in the code. using System; public class testScore { public static void Main() { string str1; double dbl1; Con...
stackexchange/codereview
public class URLBuilder { StringBuffer api_url; final String AND = "&"; private String API_KEY; String parameter; public void setAPI_KEY(String API_KEY) { this.API_KEY = API_KEY; } public void setCity_name(String cityname) { parameter = "q="+ cityname; } pu...
stackexchange/codereview
Sometime back I came across a bug where a particular object was leaking but it was very hard to identify the root cause. I knew that it was due to a cyclic dependency (which usually indicates a bug in the design), but couldn't get a clue where the design went wrong. I wrote a small utility class view on github to help...
stackexchange/codereview
How to write and design a simple (but still proper and secure) login class for PHP? Currently I'm checking whether there is a login request (user entered data into login form) or the session is already existent and contains $_SESSION['authenticated'] == TRUE;. If both checks failed the user is not (properly) logged in....
stackexchange/codereview
there is a other way to write in JS the switch statement , This code is working :) _update: function(oHtml, oConfig) { var _this = this; var oParent; if (oConfig.attributes != null) { oConfig.attributes.forEach(function(oAttr) { //debugger; oParent = o...
stackexchange/codereview
I am trying to create this API endpoint that will accept JSON payload and will calculate quote based on provided factors and their ratings. I have Entities that contain information about: age postcode ABI code ratings. These AgeRating, PostcodeRating and AbiRating entities implement RatingFactorInterface to force imp...
stackexchange/codereview
I've decided to write a C++ FizzBuzz with the focus on some new C++11 features, ridiculous optimizations and unit-testability. Are there improvement possibilities in those regards? template <typename T> static void fizzbuzz(std::ostream& out, const T& number, const std::vector<std::pair<std::string, T>>& values) { ...
stackexchange/codereview
This program converts legacy markup in the form seen in the tests to the resulting markdown seen in the test's respective comment. The full program is as uploaded as a snippet, or you may see below let tests = [ "OneMatch$$$TwoMatch" // [One Match](OneMatch)[Two Match](TwoMatch) , "OneMatch$$$TwoMatc...
stackexchange/codereview