instruction_seed
stringlengths
71
95.1k
_source
stringclasses
1 value
I have a SwingWorker which checks periodically for an internet connection and updates a jLabel accordingly. public class InternetCheckWorker extends SwingWorker<Void, String> { @Override protected Void doInBackground() throws InterruptedException { while (true) { try (Socket...
stackexchange/codereview
I'm a developer who has completed almost one year of full-stack development & learning. I published my very first package lately, and I don't know is my code good or bad. So I jumped down here. EditorJS is block based medium-like rich text editor, so here's a link to it. The package gets the JSON input, passes to offic...
stackexchange/codereview
Yesterday I posted my Generic List and received great feedback from it. I have taken the feedback to heart. Today I'm posting my take on the linked list in c#. LinkedList.cs using System; using System.Collections; using System.Linq; namespace GenericDataStructures { /// <summary> /// This is a singly Linked Li...
stackexchange/codereview
I'm trying to improve my C++ template metaprogramming skills. From my understanding, I can't partially specialize a function(either member function or not). So, I need to define another class that can be used as template class, which enables us partially specialize template argument. So, In order to check my understand...
stackexchange/codereview
say that: var stringToTest = "Hello i am walking" And var searchText = "Hello walking" I have the following javascript function for filtering. var searchSplit = searchText.split(" "); var num_split = searchSplit.length; var correctTested = 0; searchSplit.forEach(function (testString) { if (stringToTest.indexOf(te...
stackexchange/codereview
You have one form and you can register a user. It can be god or mortal, but it also requires all the information to let you save the user or the change. When you have all the registers that you want you can edit one or delete it. I'm new using Angular and I want tips to use it better. I also want to see other ways to d...
stackexchange/codereview
I have made a merge sort algorithm but am unsure of the 'Space Usage' of the algorithm. public class Sorting { public static void mergeSort(int[] arr) { if (arr.length == 1) { return; } int[] newArrLeft = new int[arr.length / 2]; int[] newArrRight = new int[arr.length - ...
stackexchange/codereview
I'm using JavaScript to handle breakpoints in a single page, non-scrollable application. I want to do various things when changing viewports, such as fire off animations with a JavaScript animation library. I've assigned the viewports like so: CodePen HTML: <div class='box'></div> CSS: .box { width: 300px; height:...
stackexchange/codereview
As a beginner Python programmer, I wrote a simple program that counts how many times each letter appears in a text file. It works fine, but I'd like to know if it's possible to improve it. def count_letters(filename, case_sensitive=False): alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" with ...
stackexchange/codereview
The following is my python code to find the number of iterations needed to generate random string iteratively to match the input string. Here I have repeated a similar kind of for loop in both the functions getRandomString() and getMatchString(). I tried to avoid it but couldn't. I want this to be combined together int...
stackexchange/codereview
I've designed a class ObjectPicker that can be given objects and weights. Objects can be picked randomly out of the ObjectPicker, with heavier weighted objects having a higher chance of being selected. The pick() method is designed to be recursive and provide \$O(\log n)\$ speed. What I'm not sure about is the defaulti...
stackexchange/codereview
A script which scans a local filesystem and writes to a file a list of world-writable files found on the filesystem. I ran it on a server with a couple terabytes of storage; not all of it used. In fact, only 195GB have been used. I'm not sure how many files there are, though. The script takes 23 minutes to run. Is ther...
stackexchange/codereview
I was writing a bit of code and I was just wondering if I was doing it the right way. I know all the syntax is right and It all works perfectly. I was just wondering if I'm doing it the right way. Should I have another infrastructure, am I following the MVC correctly (there is no V yet, it's mostly just a model). Is th...
stackexchange/codereview
It was written in Emacs Lisp and requires Common Lisp loop facility. Can this code be improved? Did I hit any anti-patterns along the way? (defun combos (list) (let* ((a (car list)) (d (cdr list)) (s (and d (combos d))) (v (loop for c in s collect (cons a c)))) (cons (list a) (append s ...
stackexchange/codereview
I have to show a select control of students with event information where Monday, Tuesday, Wednesday, Thursday and Friday are Events. (Independent buttons). The second columns are Events too, but you can add these Events using the "Add" button. Data flows in like this: I have to maintain the state the state of every st...
stackexchange/codereview
I'd like to optimize my code and get a better understanding of how I can perform the task I am doing better. I've only used Perl threads about 3 or 4 times now. The purpose of my code block is to scrape the Pastebin API for every new public paste that appears at regular intervals using a crontab. Then search inside tho...
stackexchange/codereview
I have a question regarding a program that is to run an alarm clock and display the time (HH:MM AM/PM) and also trigger the alarm and display "ringing" at 12:00 AM. I am a beginner in Java and I am a little lost. I believe I have most of the skeletal work done. This is much like another question asked on here but I cou...
stackexchange/codereview
I have created a rationalnumber class and used operator overloading function of C++. My questions are: Have I implemented the class and < operator correctly? Objects of class can now inserted in map and set. Is that part done correctly? #include <bits/stdc++.h> using namespace std; class RationalNumber { int nu...
stackexchange/codereview
Although I have been coding in PHP for a while now I am trying to go back to basics with some things to make sure by understanding and methods are the most efficient. I have the following snippet... if (!empty($_GET['location'])) { $location = $_GET['location']; } else { $location = ''; ...
stackexchange/codereview
I am at the moment trying to grasp multi-file programming instead of one big main.cpp. The class I wrote is about ISBN 13. Can you point out what could be done to improve my code? Also is there a good guide how to write include guards? My sources differate in this respect. Runnable code here on Wandbox ISBN.hpp #includ...
stackexchange/codereview
I'm beginning my programming adventure in C++. I want to write a small program, which has to create an array in function create (size has to be defined in create function) and transfer them to function display which will print entered values. #include <iostream> using namespace std; int *create(int & n); void display...
stackexchange/codereview
I have written a small class that works in extracting Snapchat usernames from common conventions of sentences, manipulating the positioning of certain characters to hopefully extract a valid username. The script does have some partial protection for validity with its call to SnapchatUtilities.IsUsernameWellFormatted(ex...
stackexchange/codereview
I've written this simple JavaScript application for a homework assignment and I've received feedback saying it could be written better. Can I get some feedback on how to write this differently? It works for me and returns the results I need, but I would like some more specific feedback. It was meant to be simple and n...
stackexchange/codereview
Module name: database.py Code: import sqlite3 class Database(object): """sqlite3 database class that holds testers jobs""" DB_LOCATION = "/root/Documents/testerJobSearch/tester_db.sqlite" def __init__(self): """Initialize db class variables""" self.connection = sqlite3.connect(Database....
stackexchange/codereview
Any ideas how I could improve this? I already know that there is no checking for anything other than a 1, so you can enter a 2 or an a or a b and it will be interpreted as a 0, not interfering with the program's functionality. What I would like to know is if anyone has any suggestions for improving the logic. def main(...
stackexchange/codereview
Suppose there is a circle. There are n petrol pumps on that circle. You are given two sets of data. The amount of petrol that petrol pump will give. Distance from that petrol pump to the next petrol pump. Calculate the first point from where a truck will be able to complete the circle (The truck will stop at each pe...
stackexchange/codereview
I'm a newbie in Python. I need to read a GZ file contains thousands of users. But I think my code is not optimized in this case. Could anyone can help me? What should I do to improve performance? Or is it standard? if os.path.isfile("file.gz"): with gzip.GzipFile("file.gz", 'r') as fin: for line in fin:...
stackexchange/codereview
I am looking to build a message encryption/decription method that would allow messages to be encrypted in a timely fashion on board an Arduino Portenta H7, using as much of the onboard hardware acceleration as possible, and decrypted using python. This will be used to encrypt and sign an MQTT payload. The Server public...
stackexchange/codereview
I'm an experienced programmer but relatively new to Python (a month or so) so it's quite likely that I've made some gauche errors. I very much appreciate your time spent taking a look at my code. My intention is to do some experimentation with 1D cellular automata. For now, just totalistic ones (rules only based upon...
stackexchange/codereview
Challenge Problem Statement - Implement a Queue using two Stacks I implemented dequeue() in \$O(1)\$ at the cost of enqueue() in \$O(n)\$ #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <stack> using namespace std; struct Queue{ stack<int> s1,s2; int dequ...
stackexchange/codereview
In this I have written the setAnalyticsInfo() method. The code inside this is common to almost all other (30) classes, so I have created GoogleAnalyticsCode and defined one common method and calling this method from all other classes. import com.google.analytics.tracking.android.EasyTracker; import com.google.analytic...
stackexchange/codereview
coming again from previous questions on this, I've expanded the virtual machine a little bit in terms of a direct API to read and write data to the VM. I've attempted to add a callback system so that host apps can add callable code that can be used by the scripts though I have no clue how to implement this. This may or...
stackexchange/codereview
I'm new to MVC and i'm having some difficulty on understanding the proper usage of ViewModels and Controllers. I have this example where i will list several different informations in my HomeController as CTAs, Banners, News, Courses... and i came up with this ViewModel structure after some research : public class Cours...
stackexchange/codereview
I've come up with some simple implementation for algorithms in C and more specifically for std::accumulate alternate since I need something like it recently. Can you provide some review on the approach? #include <stdio.h> #include <string.h> #define ARRSIZE(X) (sizeof(X) / sizeof(X[0])) #define ACCUMULATE(RET, FIRS...
stackexchange/codereview
Over the last months I have been writing a jQuery plugin called Better Autocomplete (Code on Github). It originated from another project, a Drupal module called Linkit, but I decided it should be a standalone plugin. I have spent a lot of time refactoring the code, mainly to make it more generic and flexible for multip...
stackexchange/codereview
I have written this code which finds duplicate numbers and the occurrence of a particular number in an array. I have used a HashMap, but I want to know if there is a more efficient way to do the same, or whether I should be using another method. import java.util.*; class test7 { public static void main(String ...a)...
stackexchange/codereview
This synchronizes the document’s vertical scrollbar and a DIV’s horizontal scrollbar so they can work in unison controlling the content simultaneously. The code is operable and behaves how I want. I want to know whether or not this code can be optimized any further. Heads-up: the jsScroll0 and jsScroll1 flags stop eith...
stackexchange/codereview
This is a script I have written to calculate the population standard deviation. I feel that this can be simplified and also be made more pythonic. from math import sqrt def mean(lst): """calculates mean""" sum = 0 for i in range(len(lst)): sum += lst[i] return (sum / len(lst)) def stddev(lst)...
stackexchange/codereview
My header file implementation: #ifndef CIRCULARSPSC_H #define CIRCULARSPSC_H #include <atomic> #include <cstddef> template<typename Data, size_t Size> class CircularSpsc { public: enum { queue_size = Size + 1 }; CircularSpsc() : back(0), front(0){} virtual ~CircularSpsc() {} bool push_back(const Da...
stackexchange/codereview
Whenever I learn a new (or an old :)) programming language, I implement Hangman in it. This time it's with COBOL. identification division. program-id. hangman. data division. working-storage section. 01 state. 05 word pic A(100). 05 word-length pic 9(3). 05 guess pic A. 05 guesses occurs 256 times pic ...
stackexchange/codereview
*** PS_HOURS.3_1 July |1 |2 |3 |4 |5 |6 |7 Name |Total|Total|Total|Total|Total|Total|Total Abram, John |1.00 | | | |3.00 |3.00 |3.00 Agara, Hara |2.00 | | | |2.00 |2.00 |3.00 Alsi, Idria |2.00 | | | |2.00 |2.00 |2.00 Amon,...
stackexchange/codereview
This query produces the results I want. Is there a less wordy or more effective way to write this query? Criteria: 1. Vendor in detail record must have a record in TRANSEFFECTIVE 2. Get the most recent (begin_frame) record from TRANSDETAIL 3. Tells me if the vendor has any other categories in the TRANSMODAL table. In...
stackexchange/codereview
I'm often applying to jobs just to test out my skills. I have recently applied to one, had to submit a Java problem, but got rejected. Could someone please review my application briefly and tell me what was the worst mistake in my code? I am interested in improving myself but it's hard for me to figure out what I need ...
stackexchange/codereview
In many cases, we want a variable-size array like std::vector, but we know an upper limit on the size. In such cases, the vector can be allocated on the stack. We have been doing this in C: char a[100]; fgets(a, 100, STDIN); The problem is that the array doesn't know how many elements are actually there. All it k...
stackexchange/codereview
I wrote simple TCP Client Server application, I was wonder could you please review my code. I would be grateful for any hints and tips regarding to logic of app, coding style or naming convention. Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics;...
stackexchange/codereview
My code communicates with a Raspberry Pi (with a static IP address) running on a network. The client sends a signal to the Pi, and the Pi sends back a double (encoded as a string) with the angle correction needed for another routine of the code (the Pi does some image processing, but that doesn't matter). The main exec...
stackexchange/codereview
this is my implementation of std::forward template<typename T, typename U> constexpr decltype(auto) forward(U && u) noexcept { return static_cast<T &&>(u); } compared to the standards template<typename T> constexpr T && forward(typename std::remove_reference<T>::type & __t) noexcept { return static_cast<T &&>(...
stackexchange/codereview
This is the problem: Airport Pretend we are operating a small airport with a single runway. We need to develop a data structure to help scheduling airplanes to take off and land from this runway. Each time a plane takes off or lands, it needs exclusive use of the runway starting 10 minutes before the schedul...
stackexchange/codereview
I am a novice coder and I am very new to algorithms. Something about my code leads me to believe that it is unnecessarily verbose and/or inefficient. I am building a command line Mastermind game, and part of the project is to provide feedback for a user's guess. In the game, the codemaker creates a secret code with fou...
stackexchange/codereview
private void moveViewToScreenCenter(final ImageView img, int x) { DisplayMetrics dm = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(dm); img.animate() .translationX(0) .withEndAction(new Runnable() { @Override public vo...
stackexchange/codereview
This function may compute the amount of unequal elements of two char-arrays of the length n: size_t difference(size_t n, const char a[n], const char b[n]) { size_t res = 0; for (size_t i = 0; i < n; i++) res += a[i] != b[i]; return res; } How can I make the iteration faster regarding the memory all...
stackexchange/codereview
I added Rock, Paper, Scissors to one of my programs. I'm new to python and PEP 8, so I want to see how to improve my work. def rock_paper_scissors(name): play_rps = True while play_rps: rps = ["rock", 'paper', 'scissors'] player_rps = input("Rock, Paper, or Scissors: ").lower() com_rps =...
stackexchange/codereview
This is the first question for this language, and I decided I would do a FizzBuzz. I used a template literal as a proof of concept, same goes for the pipe (|>). The code creates a function that recreates the traditional FizzBuzz in FreezeFlame: var fizzBuzz = (max) -> { for(var i = 0; i < max + 1; i++) { (i...
stackexchange/codereview
I have code for calculating the date for orthodox Easter and it makes me cry when I look at the if-else part. Please give your suggestions on how to make it shine (if possible). I guess I can format day/month to DateTime format but I'm afraid it'll bring just more mess. It works just fine though this. Source puts "- He...
stackexchange/codereview
I don't know exactly what to name this, but I was refactoring a code snippet and looking at this constant users I thought I'd do this destructuring: Before: async queryDBUsers({ commit }) { await getDocs(collection(db, "users")) .then((querySnapshot) => { const users = querySnapshot.docs.map((doc) => ({ ...
stackexchange/codereview
I'm writing an application where users can write custom expressions which are then converted to JavaScript functions and executed. The expressions are used for filtering and sorting data from a database and to improve performance I want to be able to run the expressions on my server without worrying about getting hijac...
stackexchange/codereview
I recently started using the Builder pattern in one of my projects. Below is my builder class - public final class DataKey { private final long userId; private final String uuid; private final String deviceId; private final int clientId; private final long timeout; private final FlowEnum flow; ...
stackexchange/codereview
I am wondering can I please get some feedback for my simple implementation of the Kosaraju algorithm. More specifically how I de-allocate the things I allocated using malloc and method names. /** * Kosaraju's algorithm implementation which is a linear time algorithm * to find the strongly connected components of a di...
stackexchange/codereview
I am collecting tweets using a Python script and I want to store them in a MongoDB database. I want to find out the lowest tweet id and for each tweet, I want to change the id field to an _id field. Is it possible not having to iterate over all the tweets with a for loop in order to do these 2 things. search_result = ...
stackexchange/codereview
This is a sparse matrix (dgCMatrix) class that extends Rcpp. WHAT: This class includes Rcpp::NumericVector and Rcpp::NumericMatrix classes which are simple references to R objects. This class fully supports reference-only no-copy conversion of the Matrix package dgCMatrix class from R to C++ and vice versa. WHY: I want...
stackexchange/codereview
I hate using unnecessary catch blocks and I like to see my code look beautiful. In most of the cases in my project, which is a web application, I can't declare many exceptions as checked exceptions as there is little that my client (browser) can do to recover from the exception. However, only if there is a way that the...
stackexchange/codereview
I am trying to solve this problem using Clojure: You are given a list of \$N\$ people who are attending ACM-ICPC World Finals. Each of them are either well versed in a topic or they are not. Find out the maximum number of topics a 2-person team can know. And also find out how many teams can know that maximum num...
stackexchange/codereview
map is a builtin function that takes one function func and one or more iterables, and maps the function to each element in the iterables. I wrote the following function that does the reverse, but it feels like this is such a basic operation that someone must have done this before, and hopefully given a better name to t...
stackexchange/codereview
I am uploading an array of photos to the server (using Alamofire): func uploadImages() { for card in cards! { let photo = card.media func onSuccess(jsonData: Any?) { photoCount += 1 SVProgressHUD.dismiss() if let jsonData = jsonData { // unwrapping l...
stackexchange/codereview
Disclaimer: This code is far from complete, I am aware of issues regarding my standards of naming, my lack of comments and readability, however I am encountering a large issue which is preventing me from editing, testing and completing the game. This is not a functional issue, but a performance issue. If you would like...
stackexchange/codereview
I'm trying to write a class that simplifies the most common operations with arrays and then I want to distribute... Maybe it can help someone... But I'm facing some problems in make the object simple to use and intuitive. Here a summary of the public methods: Array to range Array to string Array to text file Array Fi...
stackexchange/codereview
I've just begun programming Java and I'm working on the following code that deals with socket-based communications. Basically it connects to a client on port 8888: Gist of code package com.mobile.stoq.stoqpay; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import or...
stackexchange/codereview
The following code sorts the current users bid model items based on a param condition :bid_status. It starts to get messy when checking if the project space (:real_property_sale_project) :failed_date is .present? or .nil? to exclude certain items from the returned results. How can I improve this? def index @bids = cu...
stackexchange/codereview
So my code is done it outputs exactly what it needs to I'm just wondering if it is possible to make this code a lot more simple using objects. If so could someone tell me what I would need member-wise and I will try and implement it. When I tried it got way too complex and it ended up looking easier to just write funct...
stackexchange/codereview
I am working on an online ordering form and am looking for some advice about my jQuery. I am re-developing the code base for this ordering form and improving what was created by a web design group years ago. The existing form uses Javascript to dynamically generate a new line of item information when the starts typin...
stackexchange/codereview
I have written yet another n-puzzle solver. I used the A* algorithm to search with the Manhattan Distance heuristic. It worked very well for the 9-puzzle (3x3) but was unusable for most instances of the 15-puzzle (4x4.) In fact I would exhaust all RAM before I got anywhere near the result. So I switched to IDA* and ...
stackexchange/codereview
I have created a program to validate a Canadian S.I.N. using Luhn's Algorithm, and was wondering if there was any way to make it more efficient. From what i can tell, it is already extremely efficient, but any tips or advice will be greatly appreciated. import javax.swing.*; import java.awt.*; import java.awt.event.*; ...
stackexchange/codereview
Is there a more efficient/concise way to add the elements of these columns? Basically the D-# codes are error code for documents, and the Q# codes are classes of error. ##Summary columns## errorarray$Q1 <- errorarray$"D-03" + errorarray$"D-06" + errorarray$"D-07" + errorarray$"D-14" + errorarray$"D-15" + errorarray$"D-...
stackexchange/codereview
I'm currently developing an app that requires sending and receiving of data from android studio going to MySQL and then data coming from MySQL will be saved from the SQLite. I need advice on how to make the process faster. Right now I'm inserting 80,000 + rows of data coming from MySQL and then saving it to SQLite and ...
stackexchange/codereview
I am trying to solve a Hacker Rank problem about string suffixes: For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings "abc" and "abd" is 2, while the similarity of strings "aaa" and "aaab" is 3. Cal...
stackexchange/codereview
Because I use the task so often, I wrote a C header for reading a file. I never formally learned C, so I'd really appreciate a code review on the code. As a matter of personal taste, I do not put a space between the final parenthesis and an opening brace (){). readfile.h #ifndef _READ_FILE_INCL #define _READ_FILE_INCL ...
stackexchange/codereview
I've got a filter that I'd like to work out how to optimize. The most basic implementation, using loops is like the following: import numpy as np nrow = 500 ncol = 500 refArray = np.random.randint( 0,100, (nrow,ncol) ) boundsArray = np.random.randint( 90,95, (2,nrow,ncol) ) window = 31 halfwindow = window/2 result = np...
stackexchange/codereview
I am a beginner who just picked up Java (2 months ago) and I am solving some questions. For this question, the overall problem wants me to choose the cheapest price plan, so I listed out the possibilities of every plan and 'hardcoded' the logic by inputting the number of services, as the services is more important than...
stackexchange/codereview
I have made part of a quiz game and realize that if I continue down this route my code could get huge, is there a way to simplify my code or make it more efficient? The first couple of lines of MathsQuestions.txt are: 1.Work out the value of 3 × 8? a)12, b)14, c)16, d)18, 2.Work out the value of 4 × 2? a) 6, b) 8, c)1...
stackexchange/codereview
If I'm creating an immutable class from an existing class, should I override methods that mutate the property or have an instance of it and write my own methods to read from the property? I have an existing class Set which is basically a fancy array. There's a few more methods in the class but for the purposes of this ...
stackexchange/codereview
Task: per host concurrency limits for web crawler (map[string]Semaphore). I considered chan struct{} (chan bool) approach, but essentially it would not make code a lot easier because the main hurdle is to delete unused keys from map. And then semaphore takes constant memory - good property - as opposed to chan which gr...
stackexchange/codereview
This working macro converts Hindi Devanagari proprietary font to Unicode font. It reads the conversion table from a tab delimited file, and converts one by one by finding all matches and then does some ligature shifting. I don't know how efficient it is and how much time and resources it uses. Feel free to tell me if s...
stackexchange/codereview
I'm using a NodeJS script to do some geo calculations using the h3.js library by Uber. the concept of getting a nodejs script result back into php is new to me. I found the following example online, which I'm not following. $output = []; $arg = escapeshellcmd('some variable to pass on'); $command = 'node /var/www/hex/s...
stackexchange/codereview
I have a (control engineering) controller. These controllers usually need several parameters to do their thing, and in my application it is desirable that these parameters can be changed while the controller is running - in a thread safe and well defined manner. I came up with this design (extremely simplified): // Thi...
stackexchange/codereview
I am (still!) going through these CodingBat exercises for Java. Here is the one I have just done: Return an array that contains the exact same numbers as the given array, but rearranged so that all the zeros are grouped at the start of the array. The order of the non-zero numbers does not matter. So {1, 0, 0, 1} becom...
stackexchange/codereview
Here is my code: $sql = <<<END Select Sum(p)/Sum(w)*100 as present FROM attendance group by month END; $query = mysql_query($sql) or die($sql . ' - ' . mysql_error()); $names = array(); while ($row = mysql_fetch_array($query)) { $names[] = $row[0]; }
stackexchange/codereview
Here is my implementation of a linked list in Scala.It is a very basic implementation to understand generics and use of Option in Scala. Please let me how I can make it better and implement it more effectively. class LinkedList[A] { val element: A = element.asInstanceOf[A] var head: Node[A] = Node(this.element, No...
stackexchange/codereview
I am solving this question: It's not the rivers that you might be thinking about. The question revolves around the concept of digital rivers. A digital river is a sequence of numbers where the number following n is n plus the sum of its digits. FOR EXAMPLE 12345 is followed by 12360 since 1+2+3+4+5=15 and so 123...
stackexchange/codereview
I wrote a function in JavaScript that expects an array of integers (negative or positive) and determines if that array has an increasing sequence. For the sake of better time performance I made the function return out of the loop with false as soon as i+1 - i did not equal 1 or -1. I used continue to do this. Here is ...
stackexchange/codereview
I have reworked my code as suggested from my previous question: Determine if a word can be constructed from list of subsets. Please instruct me on the complexity along with a review feedback, as explained in the comments below. /** * Question is better explained by examples: * 1. given * i/p subsets - ["un", "xy...
stackexchange/codereview
So I'm currently using python to unscramble words that are retrieved from an OCR program, and checked in the 'dictionary'. The current code I am using to unscramble words is this: import numpy as nm import pytesseract import cv2 import ctypes from PIL import ImageGrab def imToString(): # Path of tesseract e...
stackexchange/codereview
I am currently learning how to use PDcurses in VC++ 2015 Community, and I noticed that menu.h is not implemented so I decided to extend the library for my own use (feel free to just copy the code if it's what you were looking for). The only question I have is: was my use of namespaces (both named and unnamed) correct? ...
stackexchange/codereview
I learnt everywhere that using if statement is a bad practice when it's possible to avoid them. I'm trying to learn how to make clean code, it seems also that some design patterns could be helpful so I'm wondering if it's possible to refactor this piece of code in order to remove if statement from, here is the code dem...
stackexchange/codereview
A while ago I got bored and being the beginner programmer I am I made a Russian Roulette game in Java using JFrame. The first few windows are JOptionPanes that are a welcoming screen, an update log and a how to play. The object of the game is you get 5 lives and when you lose all of your lives, you die. At the very end...
stackexchange/codereview
I read here that "Furthermore, for a zero of multiplicity 1, the convergence is at least quadratic (see rate of convergence) in a neighbourhood of the zero, which intuitively means that the number of correct digits roughly doubles in every step.". The code which I've written to find the square root using Newton-Raphson...
stackexchange/codereview
I currently have a worksheet with approximately 40K rows and 108 columns that I am working with. What I am doing is creating a list that when user selects a particular text in that list then certain columns and/or rows are hidden. The issue I am encountering is that when 'Unsecured Streamline' is selected, the code to ...
stackexchange/codereview
Just after a bit of feed back or peoples ideas on which practice is best. I currently have a method but am unsure of the best way to approach it from a readability point of view or even from best practices point of view. Or perhaps it doesn't really matter at all and they are all fine? My three options I explored we...
stackexchange/codereview
I have two classes that do that same thing with different types. I was thinking of using generics (but I am open to all options). QueryPermissions and the WebQueryObjects come from an external dll that I cannot edit. public class OnlineReportOutputService : AService, IOnlineReportOutputService { public IEnumerable...
stackexchange/codereview
I need to be able to cancel a long running query programmatically through our application. The code below will kick off a long running query and give control back to the main thread. At any arbitrary time, a user could choose to cancel the query. It both cancels the Task as well as cancels the query in SQL Server. I...
stackexchange/codereview
I came across this thread and I am working on the same problem. My best algorithm passes 6/11 cases while the algorithm in the other thread does indeed pass 8/11 cases. Running time trials with random input my algorithm is significantly quicker (8 to 12 times depending on input) then the one in the other thread. So I a...
stackexchange/codereview