instruction_seed
stringlengths
71
95.1k
_source
stringclasses
1 value
Following-up on Creating ADODB Parameters on the fly and pushing the "wrapping" of ADODB a step further, I have written two more classes that allows me to expose methods that don't require a Connection object, without returning an ADODB.Recordset. Taking this method as a reference: Public Function Execute(connection ...
stackexchange/codereview
I got this requirement recently: Write some code that prints out the following for a contiguous range of numbers: the number 'fizz' for numbers that are multiples of 3 'buzz' for numbers that are multiples of 5 'fizzbuzz' for numbers that are multiples of 15 e.g. if I run the program over a range from 1-20 I should ...
stackexchange/codereview
I tend to feel the need in my Knockout applications to pass along a reference of the root view model down to the sub view models. However, I don't like the fact that I then have a dependency that lies both ways: root has a list of children, and each child a reference to the root. The Scenario Here's a typical example, ...
stackexchange/codereview
I've been always updating my log methods, because I started SDL and I needed some new methods. First, I made difference between debug and release, and so console and file. But now I want a more powerful method, which handles the console with implicating the file, and works like C++ streams. I would like to know if it's...
stackexchange/codereview
I want to know if my SCSS code looks correct. Note: Everything works as I expected. The Main Idea of this code is to generate Word Break Utilities for controlling word breaks in an element. using SCSS mean I can declare only css classes in html element. here is the result of my code : .break-normal { overflow-wrap: n...
stackexchange/codereview
I have some triggers placing and sizing elements for video controls. It works well enough but mostly through trial and error and I am not sure if there is a better pattern: The full source can be found here and webpage here. My biggest issue I think is when is it appropriate to have an element listen (e.g. on the speci...
stackexchange/codereview
This is a follow-up from: Reversing a domain name string in Java There are a number of ways of splitting a String using a delimiter in Java, especially now with Java 8: StringTokenizer (not recommended) String.split (recommended replacement) Scanner with delimiter Scanner with Pattern Pattern.splitAsStream With the m...
stackexchange/codereview
I've been wanting to try out F# for some real world programming so I decided to try rewriting a program that is being used at work. It can be reduced to a few steps: Get report templates. In this step I query a DB and get some templates for reports Update data that the reports are working on. In this step I query some...
stackexchange/codereview
I'm working on a solution to the Following problem on Hackerrank, and I seem to have found a function that works for the purpose. However, I feel as though this is a very overdesigned solution to a problem that appears, at first glance, to be simple. This is what I've come up with so far: This code takes in two arrays,...
stackexchange/codereview
I am a beginner, and it is my first program in C. It works well, but I was wondering if there is a shorter way to do it, and how I could have done it better. It is supposed to make a quadratic expression and ask the user to factor it. If the user factors it correctly (s)he proceeds to the next level, which is a slightl...
stackexchange/codereview
The process: I read the lookup and create a list aa. I traverse through the glob.glob("C:\\project resource\\dump\\*.html") and find matching. If a match is found, I create a file if not available, but if available, I just append it to the file. import glob,re from bs4 import BeautifulSoup import unidecode lis=[] aa...
stackexchange/codereview
I want to have a continuous date sequence like ['2014-01-01','2014-01-02', ...] Then I define a stream to do that. def daySeq(start: Date): Stream[Date] = Stream.cons(start, daySeq(plusDays(start, 1))) I get the sequence within range [start, end) by calling daySeq(from).takeWhile(_.getTime < to.getTime) Any better/...
stackexchange/codereview
My adjacency matrix looks like this, where non-zero weights denote edges. [0, 2, 0, 0, 3] [2, 0, 2, 4, 0] [0, 2, 0, 3, 0] [0, 4, 3, 0, 1] [3, 0, 0, 1, 0] Here's my attempt, would appreciate a code review. private static class Edge implements Comparable<Edge> { private int source; private int destination; p...
stackexchange/codereview
I have an application which uses SQLite. In that database I have several tables that I need to be able to read and update in my application. Often I need to 'cross-reference' these tables to get the correct values. For instance, I load an interview with answers someone has previously selected. To do so, I have a Result...
stackexchange/codereview
I have written a function to selectively extract data from a file. I want to be able to extract only from a certain line and only given rows. Would convert this function into a generator improve the overhead when I need to process large files? import itertools import csv def data_extraction(filename,start_line,lenght,...
stackexchange/codereview
I wrote my first project in java which is just a simple game where you need to guess title of movie. I'm curious what do you think about it? Could you tell me what i did incorrectly, what would you change, etc. I would appreciate any feedback from you. public class Main { public static void main(String[] args) { ...
stackexchange/codereview
This is my attempt at implementing a Binary heap. I made an abstract base class Heap with an abstract property controlling whether it is a min-heap or a max-heap. One thing I've been struggling with was which collections.generic interfaces to apply to the class. Enumerating the heap only makes a bit of sense. At the s...
stackexchange/codereview
I have this code to translate text using the Google Translate mobile site. Currently, text size is limited by the request method. Everything else seems to works just fine. I am also about to post this on PyPi but I don't know how I should name the package, the file and the function. Basically today you must do: import ...
stackexchange/codereview
So we have a RESTful webservice that implements CRUD operations for a model, like this one: class MyModel { private long id; private String name; // other fields private boolean completed; private boolean active; // getter and setters } In this webservice there is also a path like /service/{id}...
stackexchange/codereview
I have a couple of VBA loops that work in the blink of eye when I execute them through Excel, but doing this as part of an Access VBA application takes like 15 minutes. The loops run through each row and check to see if multiple conditions are met, and if they are they change the value of one cell in the row in questio...
stackexchange/codereview
I am pretty new to JavaScript, and put together a weather application. I'd like to get some feedback on improvements I could make to the code itself and also possible ways to speed up weather data display. This is a screenshot of the working site: The basics for how the application works: It checks if local storage h...
stackexchange/codereview
The problem: Start with two arrays of strings, a and b, each in alphabetical order, possibly with duplicates. Return the count of the number of strings which appear in both arrays. commonTwo({"a", "c", "x"}, {"b", "c", "d", "x"}) → 2 commonTwo({"a", "c", "x"}, {"a", "b", "c", "x", "z"}) → 3 commonTwo({"a", "b", "...
stackexchange/codereview
I need to make a matrix (in the form of a numpy array) by taking a list of parameters of length N and returning an array of dimensions N+1 x N+1 where the off-diagonals are symmetric and each triangle is made up of the values given. The diagonals are equal to 0 - the row sum of the off-diagonals. I don't really like ha...
stackexchange/codereview
In working on a review for Solve a set of "restricted" linear equations efficiently, I decided to reimplement from scratch using the method I proposed in my answer. The application I won't repeat the entire specification here, but in a nutshell, this program is intended to solve a very restricted system of linear equat...
stackexchange/codereview
I've created a Node class and a Graph class class Node: def __init__(self, val): self.val = val self.edges = [] class Graph: def __init__(self, nodes=[]): self.nodes = nodes def add_node(self, val): newNode = Node(val) self.nodes.append(newNode) def add_edge(se...
stackexchange/codereview
I'm working on a framework that will be used to create simple 2D grid based games. It is using an Entity-Component-System pattern with corresponding manager classes used to control the lifespan of objects and construct them polymorphically based on an ID. In addition to general improvements to my code, I'm asking for f...
stackexchange/codereview
I was searching for a way to exercise the Java 8 concepts I've been learning, especially pertaining to Lambdas. Incidentally, I hadn't used any swing in a while and wanted a refresher. This is the result of these two pursuits. import java.awt.GridLayout; import javax.swing.JComboBox; import javax.swing.JFrame; import ...
stackexchange/codereview
I am currently working on an API and came across the following design. // not mandatory @ManyToOne @JoinColumn(name = "person_id") private Person person; Actually, a telephone number should belong to a company, person or a contact form. However, this is logically not possible with the current design. ...
stackexchange/codereview
References Using those references: rolling median implementations benchmark FAST RUNNING MEDIAN USING AN INDEXABLE SKIPLIST Calculate the median of a billion numbers Find running median from a stream of integers Code A code was written to calculate the Median with the SortedContainers library: from itertools import i...
stackexchange/codereview
The original purpose of this script was saving data to a local file, which is still the primary purpose. Since I may only obtain one copy of a data stream (not this particular Coinbase one; it's just a free example), I'd like to add a secondary purpose using websockets to mirror the data for a Python web-server, but ab...
stackexchange/codereview
The following makefile builds my classwork for my various college classes and builds pdfs to hold the notes I took during class. I would like feedback on my directory structure and any optimizations that can be thought of to help improve it. I've been using and updating it for the past 18 months. I know that I should p...
stackexchange/codereview
I just wrote this simple function in order to implement something like console.table: function toTable(obj) { let arr = ''; arr += '--------------------------\r\n'; for (let [key, value] of Object.entries(obj[0])) { arr += ' ' + key + '\t'; } for (let i = 0; i < obj.length; i++) { ar...
stackexchange/codereview
I'm trying to follow the path of Sandi Metz and others who state that aiming for small and simple is good for writing understandable code. I've written a method that takes care of writing content to a file without overwriting any existing file of the same name. I wrote it TDD style and, once the tests passed, I refacto...
stackexchange/codereview
tl;dr I tried to write some as general and as feasible as possible code where entities are able to communicate with other entities of the same type or of different types, allowing for the recipient to reply to the sender. Details : Trying to work with some of the new contextual abstractions e.g. given and extension m...
stackexchange/codereview
What follows is a simplified version of a tentative implementation for a template-based set, named TemplateArgs. For the sake of clarity and focus on the question at hand, TemplateArgs was converted into a non-parameterized class, and its size and elements are hard-coded. It should be C++11-compliant and portable (any ...
stackexchange/codereview
I'm writing a basic tutorial for a simple console menu for Python. I think it is secure, since the input() is controlled by a dispatch. Any suggestions would be appreciated. """ Nice Menu for Python """ import time # used only for testing purposes def m_help(): """ - - - - - - - - - Micro Menu Help - help line 1...
stackexchange/codereview
I created my brainfuck interpreter and I would like to know what can be done better and is the code clear and readable. I will be very thankful for opinions and suggestions. Here is the code: #include <stdio.h> #include <stdlib.h> #define ALLOCATION_ERROR 1 #define FILE_ERROR 2 #define OTHER_ERROR 3 #define TAPE_SIZE ...
stackexchange/codereview
I have designed a compile time Finite State Machine generator. I have chosen to use some of the features of C++17 such as parameter pack expansion, fold expressions and lambdas to keep the complexity of this class structure and its hierarchy as simple and readable as possible. It is currently in its infancy as I have ...
stackexchange/codereview
As a hobby I am working on a game engine in order to learn C++ and graphics programming, now I have completed my first iteration of my camera system using OpengGL and GLM. Because I am mostly self taught I am searching for some feedback. I am mostly searching for feedback regarding the following points: Is the API eas...
stackexchange/codereview
I've got a piece of code that takes an element, checks where it is, and if it's beyond a set place in the viewport, make the opacity increase to 1. I've made the code so that it only runs the checks if they're needed, the problem is that the code looks atrocious, and I suspect there's a better way for me to be doing it...
stackexchange/codereview
I think I have fixed the issues which caused this program to not be functional. Now I believe the design of my code is somewhat bad and may be causing problems with the number of processes that are created (I would think 10 processes would be created when 20 are?). I am unsure what may be causing this, but I probably ...
stackexchange/codereview
To check a win in my TicTacToe game, I have created a 2D array that contains all the combination that a game can be won in, like so: private int[][] winningCombinations = new int[][] { {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, //horizontal wins {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, //virticle wins ...
stackexchange/codereview
#include <iterator> #include <memory> #include <algorithm> template<typename RandomIt> void sub_merge(RandomIt begin, RandomIt mid, RandomIt end) { // create copy of input array; const auto left_size = std::distance(begin, mid); const auto right_size = std::distance(mid, end); auto left = std::make_unique<typ...
stackexchange/codereview
I am looking for a review on the following code which is for this question. I am looking for a general review of the code. I am specifically also looking for advice on how to make this code run more efficiently. import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; import java.io.InputS...
stackexchange/codereview
I have created a Data Verification page in a Django SessionWizardView where a user has to confirm an earlier submitted rating of an image using a jQuery UI Slider (-100 - +100) The below slider starts off at the same point the user has previously rated the image at by adding a Django template variable. value: {{first_s...
stackexchange/codereview
I currently need some advice regarding the best practices and whether this is code is valid from a review perspective. Needs some tips of what i should be writing like and whether there are any clear pointers on how i can improve. var Structure = function () { var _this = this; this.Version = "1.0"; this.G...
stackexchange/codereview
I know this task could be done in more practical ways, but the professor only want us to solve it with the "if" statement. I tested and it meets the condition for each task, but I still feel this code looks a bit awkward, I think there is an easier way to get it done. Can someone give me any advice? import javax.swing....
stackexchange/codereview
Here is a working pari/gp implementation of prime number sieve. Is there something that I could change in code to achieve a better running time? Sieve(g)= { A=vector(floor((g-1)/2)); for(n=1,floor((g-1)/2), A[n]=2*n+1); for(x=3,floor(sqrt(g)), if(Mod(x,2)==1,i=0,i=1); forstep(y=i,x-3,[2], A[(x^2-y^2-1)/2...
stackexchange/codereview
I have a LoginController in Laravel, but I think it could use some improving, can anyone tell me where I am going wrong? It just seems overall a bit messy, but I can't think of a logical way to improve it. <?php namespace App\Http\Controllers\Ec9\Frontend\Guest; use App\Http\Controllers\Controller; use App\Database\Ec...
stackexchange/codereview
I have a Swing vector-program similar to Dia targeting RAD. There are some plug-ins that let you create structures like Rectangle, Text and Circle but also complex types like Table-Columns. generate files like Spring-Roo-Script, grails-script, SQL-Files and svg-Files. In the Center you have the Drawing-Panel (DrawPa...
stackexchange/codereview
I had implemented a simple Linked list Insert, print and insert at the nth position. It works fine. Could someone review code and let me know where I could have done better (or) where I had gone wrong? class Linkedlist { public Nodes current; public static Nodes headnode; public static int ...
stackexchange/codereview
I'm following this let StringOfLengthConstructor<'c> (input:string, length:int, defaultConstructor:string->'c) = match input with | null -> None | x when x.Length = length -> Some(defaultConstructor(input)) | _ -> None type String3 = | String3 of string let String3 input = StringOfLengthConstructor<Stri...
stackexchange/codereview
I decided to create a double pendulum simulation to trace out its path and explore chaos theory a bit. I'm looking for any feedback regarding my code. Are there any atrocious portions of my code or bad practices I did? import tkinter as tk import random from math import pi, sin, cos G = 9.81 class SimplePendulum(): ...
stackexchange/codereview
I would like to know how to improve the performance of the following query: SELECT Kunde.Nachname, Kunde.Vorname, Kunde.Debitorennummer, sum(Abmeldestatus) AS Abmeldestatus, Ab1.Fruehstuck, Best1.Menu1, Best2.M...
stackexchange/codereview
I created this class to handle some dropdowns that I'd been creating using a squirrelly combination of HTML, jQuery, and AJAX. This works much better in the one script that I've deployed it in: namespace appwpclass; class PopulateDropdown { public $skillArray; public $grpArray; public $facArray; /** ...
stackexchange/codereview
pathmunge is an often-seen function in shell initialization files, used to add entries to the PATH environment variable without duplication. Examples: Fedora /etc/profile's pathmunge. How can I cleanly add to $PATH? - Unix & Linux Unix shell function for adding directories to PATH I wrote this pathmunge variation in ...
stackexchange/codereview
There is a draft of my models.py. What can I do for code quality and readability increase? from datetime import timedelta from django.contrib.auth.models import User from django.db import models from django.utils import timezone class Rule(models.Model): start_date = models.DateField() end_date = models.Date...
stackexchange/codereview
If you don't play poker this will be hard to follow. In Hold'em and other Poker games you take the best 5 of 7. The class Hand selects the best 5 and scores the hand. Hand implements IComparable so hands may be compared. In simulations will create millions of boards to compare hands so speed is a priority. There are 13...
stackexchange/codereview
I created a simple Pomodoro timer using React JS. In my example: Timer should count down seconds until it reaches 00:00 Timers should switch between 25 and 5 minutes Timer should be able to start, stop, and reset My questions: how can I improve the switching between the "work" and "relax" modes? Now I use 2 functi...
stackexchange/codereview
I have a piece of javascript I wrote for a recent work project that is essentially taking a deviceorientation event object, taking either the beta value or gamma value of that object and makes a calculation. While I can't necessarily put my exact code here just in case that breaks any of the agreements I signed, the ge...
stackexchange/codereview
My day job is supporting a piece of software that just started using the DevArt Oracle drivers, which utilize the Oracle.DataAccess .NET drivers. However, the assemblies in the .NET GAC may not uninstall correctly, and I have encountered later assemblies that do not match the installed Oracle client, and which therefor...
stackexchange/codereview
I wanted to write a generic abs function that would correctly work for every type. Basically, I wanted to use the following algorithm: If the type is a built-in integer, use std::abs from <cstdlib>. If the type is a built-in floating-point, use std::abs from <cmath>. If the type is a user-defined type with a namespace...
stackexchange/codereview
I recently came across this problem: It is Lavanya's birthday and several families have been invited for the birthday party. As is customary, all of them have brought gifts for Lavanya as well as her brother Nikhil. Since their friends are all of the erudite kind, everyone has brought a pair of books. Unfortun...
stackexchange/codereview
I have been playing around with some improvements to some sort algorithms like Selection Sort and Merge Sort and I ended up needing some sort of measurement to check if my versions were any faster than the original algorithm form. I also had a need to implement some sort of time measurement before but never did it, so ...
stackexchange/codereview
I'm looking for OOP tips or advice. ;(function ( $, window, document, undefined ) { if ( typeof Object.create !== 'function' ) { Object.create = function (o) { function F() {} F.prototype = o; return new F(); }; } if (!Function.prototype.bind) { // check if native implementat...
stackexchange/codereview
I'm learning Java and was making a program to go along with the board game Clue. I type the name of who didn't do it and it takes them off the list. I want to evolve this program to be able to do other things and include the weapons and locations and maybe even probabilities based on other peoples guesses' during the g...
stackexchange/codereview
I'm here again; I'm learning a bit about github and posting things to packagist, this is my first try. I have created a library that validates or verifies in what type of environment php is being executed, whether from a web environment or from a command terminal. I appreciate if you can support me by giving it a look,...
stackexchange/codereview
One of the questions that is presented in Chapter 3 for Cracking the Coding Interview is this: Describe how you could use a single array to implement 3 stacks I've implemented a solution to this problem in C++. My assumption is that the array is a static array that is not growable (unlike a dynamic array). I would lik...
stackexchange/codereview
I've implemented merge sort in Scala: object Lunch { def doMergeSortExample() = { val values:Array[Int] = List(5,11,8,4,2).toArray sort(values) printArray(values) } def sort(array:Array[Int]) { if (array.length > 1 ){ var firstArrayLength = (array.length/2) var first:Array[Int] = ar...
stackexchange/codereview
My program is a fraction calculator that is supposed to calculate the basic operations (+, -, *, /) and is supposed to exit when I enter % as my sentinel value. This is what I have so far; any feedback is highly appreciated. #include <iostream> #include <cstdlib> using namespace std; enum MenuSelection{ NONE ...
stackexchange/codereview
basically i am new to python lookin for any bad practices done down there in my script, any ways to shrink the code and increase efficiency import json, os, win32crypt, shutil, sqlite3 from Crypto.Cipher import AES tmp = os.getenv('TEMP') usa = os.environ['USERPROFILE'] triple = False both = False edb = usa + os.sep ...
stackexchange/codereview
I want to print a tree in a zigzag manner level-by-level. I'm wondering if there are any logic issues in my code and any further performance improvement ideas by using a smarter algorithm implementation. class Node: def __init__(self, value): self.value = value self.left = None ...
stackexchange/codereview
I'm trying to get my code to conform to java formatting convention, I think I've spaced and indented the right way, however, your peer review would be much appreciated. /** * @author Nad Deb * Date: 10/10/2020 * This program is used to play two words games * It will work on input from the keyboard to workout suffix/inf...
stackexchange/codereview
I have this code block, where I search for the value of Ordnungsbegriff. I have to search through a tree of my CurrentDocument. How can I rewrite it to be more dynamic? I don't know at which level I will find my value. string xy = ""; try { if (string.IsNullOrEmpty(CurrentDocument.Ordnungsbegriff)) { ...
stackexchange/codereview
I am attempting to make three-dimensional discrete cosine transformation spatial frequency components illustration. The 3D cubes is used to present the level of each coefficient. The more bright the cube, the higher value of its coefficient, and vice versa. The 3D inverse discrete cosine transformation is used here and...
stackexchange/codereview
I made a code that can find the prime sets: The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 and 109, both 7109 and 1097 are prime. The sum of these four primes, 792, represents the lowest sum for a ...
stackexchange/codereview
I'm trying to separate the fetch logic from the component, but, due to the nature of async/await functions I have to write an async function to call other async function and I wanted to know if that's ok, if it decreases performance and what are the good practices on this. Here's an example of a fetch function in the p...
stackexchange/codereview
I made a fairly simple template engine (if I could call it that). Basically my server returns something like string "This text should be [color:red;font-weight:bold; red and bold]" Then on the client side I have my parser, for HTML in this case function parse(str){ return str.replace(/\[(.+?) (.+?)\]/g,'<span styl...
stackexchange/codereview
I have a list of 32-bit signed numbers in range [-10e5, 10e5] in string form read from stdin, and I would like to compute and print their sum in the fastest way possible. The bottleneck is in the fast_atoi function (checked using callgrind) I thinking of two ways for improvement : cache misses seems to be an issue, and...
stackexchange/codereview
I am fairly new into asp.net MVC c# I am working on request holiday app where an employee can request holidays. The problem is the app works fine, however, I am trying to set 8 hours a day when an employee requests a holiday I have scratching my head from 2 days already seen every topic in StackOverflow and here and s...
stackexchange/codereview
I was assigned a task to fix the SQL injection flaw reported by a code analysis tool. I am not the original author of the code. I am fairly knowledgeable with SQL. public int ExecuteNonQuery(string query, SqlParameter[] parameters) { using (SqlCommand command = CreateCommand(query, parameters)) { i...
stackexchange/codereview
I have written a wrapper for Java's Iterator class using Java 7, which is designed to only iterate items that match a certain filter. When the filter is null, all items should be iterated. Filter.java public interface Filter<T> { boolean apply(T type); } FilteredIterator.java import java.util.Iterator; public cla...
stackexchange/codereview
I was sort of bored and wondered how that Youtuber (Max Wihlborg) implemented his snake-game, so I went on and took a look at his code, and then I and edited his code. I made some minor changes, but the biggest change was that I felt some sort of redundancy where he had to update 2 objects for basically the same purpos...
stackexchange/codereview
I have an Android app that shows some fragments, but I'm repeating lots of code. MainActivity.java public class MainActivity extends FragmentActivity { MyPagerAdapter pageAdapter; ViewPager pager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);...
stackexchange/codereview
I'd like some feedback/suggestions on how to improve the following. Specifically I want to know if what I'm doing is reliable and fast, or if there is a better way to accomplish this. The problem: I have some dataset containing counts of sales made at different times throughout the day, across different locations/shops...
stackexchange/codereview
How does my HTML and CSS look? I'm a beginner so I have no idea if this is good design or not. Is there an easier way to copy and paste code here? Everytime I paste my code in here and use CTRL+K, only a few lines at the top of my code are formatted, and for the rest I have to go down with a spacebar constantly which i...
stackexchange/codereview
I'm new to programming and I sort of understand the concept of methods but, I am little overwhelmed by this program and want to shorten it using methods to make it easier to read and understand. import java.util.Scanner; public class NewCalculator { public static void main(String[] args) { String usrInput...
stackexchange/codereview
I wrote 2 versions of problem 22 on Project Euler: Using a text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score. For example, when the...
stackexchange/codereview
I'm developing a plugin for Revit (a software to make 3D buildings). The goal is simple to understand. When there is an intersection between a Wall and a Duct I create an object called Reservation at this location. I need to extract the Curve of the Ducts and the Faces of the Walls in order to calculate this intersecti...
stackexchange/codereview
My concern is speed, since this may be used in an e-commerce website I want it to be as quick as possible. Where can I improve? def get_queryset(self): search_terms = self.request.GET.getlist('search', None) if not search_terms: return [] # removing trailing slash on restangular calls sea...
stackexchange/codereview
I tried to implement the shell-sort algorithm using this Java code: // Using Pratt sequence public static void hSort(int tab[]) { int N = tab.length; int k = 0; int sequence = 1; // Getting the final term of the pratt sequence while(((int)(Math.pow(3, k) - 1) / 2) < N/3) { sequenc...
stackexchange/codereview
This feels like a simple question, but I'm wondering what the best way would be to manage the elements of a private, fixed-size array. Context: I'm making a simple particle engine, and my Emitter class will smoothly interpolate between up to 8 colors per Particle, depending on the Particle's Life value. I have that par...
stackexchange/codereview
Original question can be found here I took the advice I got to heart, and re-wrote it. Once again I'd appreciate any advice as to how I can improve this using best practices. Jar.java package com.tn.jar; public class Jar { private String itemName; private int numberOfItems; private int numberToGuess; ...
stackexchange/codereview
I'm more like playing and the problem I'm going to demonstrate is a learning task, so to speak, not something I really need to solve. Imagine having a matrix of data. You chose square in it and would like to access each point on square perimeter by 1D index, like this: This image represents instance of some Matrix cl...
stackexchange/codereview
In a project I have a few long switch statements which seem ugly to me. Please suggest how to refactor the following code. protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); ...
stackexchange/codereview
This is an algorithm for finding the closest pair of points on a 2d plane by dividing the problem by half recursively, as illustrated here: use point::Point; type PairDistance = (Point, Point, f64); // Divide and conquer approach for finding the closest pair of points // See https://i.stack.imgur.com/O3Drf.png pub...
stackexchange/codereview
A follow-up to this question, this post improves on test case issues. To restate problem parameters, a given string S is considered closed if it: Has a matching opening and closing bracket or no brackets at all Respects bracket nesting levels Has no more than at least one of each bracket type in it Note that the stri...
stackexchange/codereview
I made tic-tac-toe (a common practice). board_and_player.py class Board: def __init__(self): self.cells = {"top_l": ' ', "top_m": ' ', "top_r": ' ', "mid_l": ' ', "mid_m": ' ', "mid_r": ' ', "down_l": ' ', "down_m": ' ', "down_r": ' '} def generate(self): ...
stackexchange/codereview
So I'm very much a beginner to Java and Android programming. I've worked a lot more with Python so I might have some quirks from there bleeding into my code here. I'd like a particular focus on pointing out ways I'm approaching the language and any confusing style I might be employing. What the app does is pretty simp...
stackexchange/codereview
As part of my stupidly large project Concaten, I'm writing a string escaper. It's the majority of the part that turns string tokens (like "hello world" or "buncha\n\n\n\n\n\nnewlines") into the string data that they represent. It's part of the token-to-object module, hence the prefix. The code that calls the function b...
stackexchange/codereview