instruction_seed
stringlengths
71
95.1k
_source
stringclasses
1 value
I wrote a simple console game, with the idea taken from a Reddit post. The basic Idea is: Player, controlled via arrow keys, has to escape the maze (reach the exit marked X). If a 2nd player is enabled, he controls a troll via WASD and has to catch the player before he reaches the exit. The 1st player can push walls ...
stackexchange/codereview
I have coded the following quick sort implementation. There are few things that still makes this code ugly and redundant. 1. Handling Arrays of Primitives I have to write a separate implementation of QuickSort to handle each of the 7 primitive types. Is there a way, this could be done in a much better way? 2. Usage of ...
stackexchange/codereview
I have been solving this problem of Hackerrank recently .. https://www.hackerrank.com/challenges/maximum-element A little bit about the problem You have an empty sequence, and you will be given N queries. Each query is one of these three types: 1 x -Push the element x into the stack. 2 -Delete the element present...
stackexchange/codereview
I've made a short simple strip poker game. It follows the traditional rules of poker (4 of a kind>flush>straight,etc.), one round of betting followed by an option to change cards, then another round of betting (if cards were exchanged). It is played in the terminal, and uses Tkinter to display/change the photos dependi...
stackexchange/codereview
Seeing as it's October, I thought I'd do the community challenge. Due to my inexperience coding in Groovy, I decided to give Groovy a go. I'm not sure how well I followed Groovy conventions, and the rendering is quite slow. It seem that the slow rendering might have to do with locking when writing to the BufferredImage...
stackexchange/codereview
My team has developed an API and I've been tasked with creating an authentication layer that allows partners' applications to consume it. To that end, I've created a data store which houses an Application ID, Login and salted/hashed Password for that application to authenticate against. I want to hand back a Token for ...
stackexchange/codereview
I completed an exercise from the Cracking the Coding Interview: Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. NOTE: One or two additional variables are fine. An extra copy of the array is not. Follow-up: Write the test cases for this method. I w...
stackexchange/codereview
I googled around for secure random number generation and random string generation, combining them with some user data. Is this good or am I totally off-base? I don't know much about cryptography but I do not see many alternatives, other than some bad code that gets copied around a lot with mt_rand and uniqid. //csrf t...
stackexchange/codereview
I am learning Java, so I am beginner. I know I can do this with split function but I want to improve my algorithm knowledge. I will be glad if you help me. Thanks. inputStr variable is contains the string entered by the user. stopPos variable is contains the order of wanted the word. parseWith variable is contains whi...
stackexchange/codereview
Continuing the spirit of the recent Weekend Challenge, here is a revised version of the RPSLS game. This is a follow up to my previous submission: Rock Paper Scissors Lizard Spock as a code-style and challenge This version is revised to accommodate the following suggestions: Model revised to abstract the display mecha...
stackexchange/codereview
I have written a code to replace all spaces in a String with %20. Input: "Mr John Smith " Output: "Mr%20John%20Smith" My logic: public class URLify { public static void main(String[] args) { String str = "Mr John Smith "; str = str.stripTrailing(); char[] ch = str.toCharArray(); St...
stackexchange/codereview
This function str_join() is an updated version of my earlier function strcat_new() — found here: strcat_new() function, not present in the Standard C library. The older version strcat_new() had a bug that is fixed in this version of str_join(). Syntax: char *str_join(const char *delim, long num_args, ...); str_join.c ...
stackexchange/codereview
So I'm working on a project that sometimes requires me to switch my server configuration. This is due to some circumstances with database drivers and names that are "too expensive to fix" ... That made me think though: "Why do I always copy these files around manually?" I decided I won't and wrote this small script to ...
stackexchange/codereview
I needed to implement a stop watch like class that will be used to measure running time of different functions by others. The final running time needs to be printed in 9h 3min 2s 23s 32ms 87us 78ns format. If the larger units are zero then they must be omitted. Time duration in a particular time-unit like seconds or mi...
stackexchange/codereview
I have a jQuery code that helps me to scroll to specific sections on mouse scroll. To handle mouse scroll events I am using the jQuery mousewheel plugin. function goTo(location) { $('html,body').animate({ scrollTop: $(location).offset().top }, 'slow'); }; //Mous...
stackexchange/codereview
I ask if the following code need some refactoring : public static int InsertBonus(DataTable dt, int month, int year) { int affectedRow = -1; using (IfxConnection con = new IfxConnection(ConfigurationManager.ConnectionStrings["xxx"].ToString())) { using (IfxTransaction tran = con.BeginTransaction())...
stackexchange/codereview
Description Match a Simple Sentence or a partial sentence Suitable for matching People Names (to some extent) Product Titles (to some extent) Correct use of apostrophe (to some extent) Input/Result match("Because I'm Batman") true match("John Cena's fans") ...
stackexchange/codereview
I am beginning to learn Scala and functional programming, and I came across this puzzle. This looked like good practice and I have a solution but just want some hints in terms of functional approach to this. I did rip off the evaluate function from Stack Overflow. I particularly am interested in if the approach of crea...
stackexchange/codereview
I'd like this code to be improved. package com.array.demo; import java.util.Arrays; public class ArraysDemo { public static void main(String[] args) { // TODO Auto-generated method stub // array initialization int[] arr = { 5, 10, 12, 22, 4 }; int size = arr.length; int i,pos; // loop counter ...
stackexchange/codereview
I posted not too long ago, asking for tips/improvements I could use on my models. I have changed quite a lot, so I thought I'll give it another go. My model is supposed to handle all the data I get from the Foursquare API: venueService.h typedef void (^TNVenueServiceCompletionBlock)(UIImage *image, NSError *error); @...
stackexchange/codereview
I have the following code to solve dinning philosophers problem using Go channels and am looking for review comments: package main import ( "fmt" "time" "sync" "os" "bufio" ) type diner struct { thinkTime time.Duration eatTime time.Duration free []chan bool done []chan bool n ...
stackexchange/codereview
This is a slightly specialised A* algorithm, basically it allows you to search to and from disabled nodes. It's for a game and we the entities spawn in houses and go into them. The rest of the search behaves normally, it doesn't traverse any disabled nodes in between the start and end points. NavData is a class which h...
stackexchange/codereview
I'm making a personal logger and so far I have come up with 3 solutions. I have them simplified in this example to highlight my dilemma. I want to know the pros and cons of my approaches and ways to make them better. Also should I be flushing the stream as often as possible and why? TempLog This version will be created...
stackexchange/codereview
I am making some functions within a function for learning which when passed information about a named tuple: it returns a reference to a class object from which we can construct instances of the specified named tuple. Is there any way to make the code a bit cleaner? Any help would be great. The function pnamedtuple ha...
stackexchange/codereview
I needed to create a mortgage calculator for an intro to CS class. As part of the assignment, with an interest rate of 6% needs to change to 7% after 3 years hence that if statement. The char dummy line at the end is a requirement from my professor. I'm mainly looking for ways to clean it up or if I missed anything. I'...
stackexchange/codereview
This is my first actual python tool I've written and I'm certainly happy with the way it works, but I'm sure there's better ways to do things in the code. Any ideas on how to speed it up would also be nice too! Code: #!/usr/bin/python import StringIO import getopt import hashlib import sys import os print " " print "P...
stackexchange/codereview
I'm writing a small custom DSL and interpreter as an exercise in understanding how the language stack (lexer/parser/(interpreter/compiler)) works. Because I want to be able to report the location of semantic errors, the AST needs to retain information about where the elements were in the source. For this purpose I wrot...
stackexchange/codereview
I needed a better string formatting options like ToUpper and ToLower but I also wanted to be able to use the default formattings so I created a custom formatter. It's main purpose is to support a template engine where the user should be able to use different formattings like upper or lower case. I still however couldn'...
stackexchange/codereview
Problem here. It's not exactly the brute force approach but I'm not using any sort of pre-calculated primes table, and I'm definitely not using the coprimality trick shown in the PE pdf. I'm finding the divisor count for each triangle number via its representation as a product of primes. More on it here. I've written a...
stackexchange/codereview
I finished the first part of my code that is run from PowerPoint. The steps it takes are: Open Excel file specified Choose correct tab that has an existing PivotTable Identify size of dataset and store into colNumb and rowNumb Copy each cell into an array IQRngRef and each cell in the top row into IQRef On column A, i...
stackexchange/codereview
The Standard C Library consists of various headers files. Often only a few select ones are needed for given code. Other times it is simply convenient coding to include them all in a .c file, even if that make the compilation time a bit slower. Including all standard <*.h> is useful to help detect naming collisions of ...
stackexchange/codereview
I'm learning Rust coming from an intermediate background in Python. I've completed the first 8 chapters of the book and I wanted a project that would solidify the concepts I learned, so I made a Brainf*** interpreter designed around the things I wanted to make sure I knew. This meant that I wanted it to use structs, en...
stackexchange/codereview
I want to direct all requests that haven't got a valid controller action to my custom page controller. I.e. I want /pages/new & /users/login etc to work correctly, but a request for /foo or /foo/bar should be directed to /pages/display/$path. The following code works, but I'm pretty certain I'm not doing something th...
stackexchange/codereview
I'm trying to define a function which takes an array and prints it to a predefined total width in as many columns as needed. Think of the way ls prints files for example. Here is the kind of output I am looking for: $ ./print-columns.py Files /home/stephen/dev/src/cmake-browser/cmakeclient.cpp /home/stephen/...
stackexchange/codereview
I'm making event system for my RPG game, and I want to know what I can do better, because I think that there are a lot things that can be better. Note that this code is still not completed but it works good, so could you tell me what of bad practises can you find there? Event: using UnityEngine; [System.Serializable] ...
stackexchange/codereview
I have written command line chess in Python 3.4.3 and the code is included here. The chessboard is printed to standard output as a 2-D array; for now I only have CLI and the output in the command line is as below: ['Rb' '0 ' 'Bb' 'Qb' 'Kb' 'Bb' 'Nb' 'Rb'] ['Pb' 'Pb' 'Pb' 'Pb' '0 ' 'Pb' 'Pb' 'Pb'] ['0 ' '0 ' 'Nb' '0 ' ...
stackexchange/codereview
I'm trying to replicate Android's GenerateViewId() to assign a unique Tag to dynamically created UIViews in Xamarin.iOS. internal static class LayoutExtensions { // A tentative to mimmic Java's AtomicInteger used by GenerateViewId() // https://android.googlesource.com/platform/frameworks/base/+/master/core/java...
stackexchange/codereview
I've been trying to mess around with boolean arrays in VBA since I started to try to write an algorithm to solve sudoku puzzles. I thought I'd first try to solve codeabbey tic-tac-toe. I might be reinventing the wheel here, but humor me please. Goal is to output the winning move number, or 0 if it's a tie. Here is samp...
stackexchange/codereview
In my project, I have 3 payment mode. Via Manually Entered , Card Swipe, and cash. I have 2 fragments named RecordCardManuallyFragment and SwipeCadFragment and they both are almost identical according to functionality except in RecordCardManually you have to type info manually and in swipe card fragment you informaion ...
stackexchange/codereview
The problem statement was pretty easy and I was able to run half of the test cases, but some of the test cases in the end gave me the error of memory limit reached. What can I do here to improve the memory efficiency of my code? Question: Find the min number of "usable" integers required to reach the N. The "usable int...
stackexchange/codereview
I have written a class in VB.NET that has the task of applying various arithmetic operations to two complex numbers. The class can also determine the magnitude and phase of a complex number. The project is just an exercise, but I want to make it as good as possible. For each calculation, 3 strings are created for outpu...
stackexchange/codereview
So I just experimented with some code to make a huge if-else construct more human readable, extendable and configurable (switch positions of conditions). The idea was to have a vector that contains all conditions and their actions and then just iterate over the vector, executing their ConditionalAction. I solved it wit...
stackexchange/codereview
I really like Ruby and want to get better at it. Any input is appreciated. Description This program prompts the user for a string which is ciphertext resulting from a Caesar cipher given (English) plaintext and a key on the range [0, 25]. The program then uses a table of character frequencies of the English language to...
stackexchange/codereview
Please help me in reducing the time complexity of this code as it is taking a long time to read its Excel input. # -*- coding: utf-8 -*- """ Created on Wed Mar 9 14:26:22 2016 @author: DalalNS """ from openpyxl import load_workbook import os import shutil filename = 'test.xlsx' wb = load_workbook(filename, use_iterat...
stackexchange/codereview
As per suggestion on SO, I am posting my code here to be reviewed. It was said I should not be saving and reading from disk so many times when a user selects and deselects a cell in my tableView. @property (nonatomic, strong) IBOutlet UITableView *tableView; @property (nonatomic, strong) NSArray *list; - (void)viewDi...
stackexchange/codereview
I have built a simple wild card pattern matcher algorithm. I am concerned where it can be improved. Main concern is algorithm. Any other improvements are welcome too. What it should does: Match * -> one or more of any character Match ? -> any single character similar to the file search wild card pattern (ex: Windo...
stackexchange/codereview
In MATLAB I have a set of 5393280 points in the form of a decimal-valued vector (x,y,z). How do I represent them in a way that I can quickly collect all the points within some rectangular x-y domain? Right now I'm representing them as a 3-column matrix, sorted by x-values, and using the following code to extract a rect...
stackexchange/codereview
I've created a program that will list all hung print jobs on a specified server, from there it will load them and strip the jobs down to their Job ID then cancel the jobs on that server only. I would like a critique of my work please. How does this look as an OOP script? Is there anything I can do differently? Is call...
stackexchange/codereview
After looking at a few tutorials on making minecraft mods i got as far as making my own blocks and the ModBlocks class to me looks awful and unruly especially when more blocks are added: public class ModBlocks { public static BlockPlatinum blockPlatinum; public static BlockNickel blockNickel; public static void init(...
stackexchange/codereview
I am trying to efficiently use the SEDE tool to get a list of tags a user has answered questions on, and their stats on each Tag. My code works for my account in 3185 ms, but if I try to run it on @jon-skeet's, user ID (22656) then it times out. Are there ways to make this more efficient / better code, and allow it to ...
stackexchange/codereview
I'm currently designing my book collection software, because I couldn't find any that suits my particular needs, especially when it comes to translations. Here are my particular needs: Books, authors and publishers must be sortable. This can be derived by the name, but shouldn't. A book can have several authors and an...
stackexchange/codereview
This is a simple Python multi-connection downloader primarily using requests, mmap and threads, it downloads a single file using 32 concurrent connections, slices the download using range parameter, and write the slices to a mmap object. The code: import re import requests import sys import time from collections import...
stackexchange/codereview
I wrote the following code for the question I asked here. Are there any catastrophic mistakes? (actually it did not really work with perltex and I am in doubt about having syntax mistake(s)) Also, I read it about lists, hashs (still list vs hash is a huge question mark in my mind) and forearch to improve my script. I a...
stackexchange/codereview
Specifically, how can I improve the time complexity of my algorithm (currently it is O(listLength * numberOfLists))? It only beats 5% of accepted LeetCode solutions, which surprised me. /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { va...
stackexchange/codereview
I'm writing a driver in C for a WiFi module attached to a PIC18 microcontroller. I want to implement some functions that I'm familiar with in computer application level programming like Window's API recv function for WinSock. The module itself already implements the WiFi communication protocol and the TCP/IP stack, and...
stackexchange/codereview
Is there a better way to ask for input and give answers, but without so many lines? Each input will give a specific output according to a key that I use, but this many lines seems excessive. I'm a beginner to java and could use some ideas on how to optimize this coding. import java.util.Scanner; class Test { ...
stackexchange/codereview
I'm kinda new to Java (<1 year) but have some background in C and Python. I've come up with a working solution to Project Euler Problem 4 - Largest Palindrome Product. However, I'm not confident this is "Effective Java"... All suggestions for improvement are welcome. I'd especially like feedback on the following: Java...
stackexchange/codereview
I'm a beginner and self taught and just want to see if there are neater ways of doing what I am doing, or whether there are bits of code that are poorly written. I think Lines 100-204 are the most crudely written. Below I've also determined who is bowling first and therefore assigning a dictionary to that team for ther...
stackexchange/codereview
In order to learn rust and concurrency , im trying to share a common hashmap between actix web server and a parallel thread Theres one thread which updates a hashmap with the current timestamp every 10 seconds theres a GET API which returns the latest timestamp provided in the hashmap heres my code use actix_web::{we...
stackexchange/codereview
I am writing a serial port communication app. And I thought I could get some feedback about the general structure of the program. If I am doing MVC correct, etc. Since this is a "large" program I came up with a something like a minimum working example, that shows the essence of my app (code is below): But I guess nobo...
stackexchange/codereview
This implements binary search on an array of cstrings. One thing I'm wondering about is it faster or slower to pass a variable as const i.e. len. Also strcmp() gets called a lot and since I can't find any specific details on how it works, is it worthwhile to make my own function? For example does it immediately return ...
stackexchange/codereview
I reviewed this question to a snake game console implementation: My first C++ game (snake console game) I enjoyed refactoring this code and presenting a solution using more C++ features/classes. I ended up rewriting this project from scratch. My aim was to make the code easy and maintainable to read. Also, I tried to s...
stackexchange/codereview
I have made three classes and I have put all the UI code in a different class and used method for labels, text fields etc so it does not mix up. Please look into this code and tell me is it good approach?. The UI is complete but the i just started working on functionality and was getting nowhere. The thing I want to do...
stackexchange/codereview
Here is my code for printf() implementation in C. Please share your thoughts for improvements. #define PRINTCHAR(c) putchar(c) #define MAXLEN 256 // Write a printf function which simulates printf() in C. int formatAndPrintString(char *pcFmt, va_list lList) { //Holds the number of characters printed, 0 on error ...
stackexchange/codereview
Is there any way to improve it? #include <iostream> #include <windows.h> #include"MMSystem.h" #include <conio.h> #include <fstream> #include <ctime> #include <string> #include <string.h> using namespace std; /****************************************************/ /**<Stores Player's Name and Score>*/ struct player { ...
stackexchange/codereview
I'm quite new to JavaScript and wrote this clone method to be able to clone any kind of object. It works quite well for the cases I've tested until now, but for JSON objects it seemed kind of slow to me. I'm sure there is some additional speed to to squeeze out and a lot of overall improvement to make. But I don't know...
stackexchange/codereview
The following code makes jQuery trigger a new target event on elements when they become the target of the fragment identifier. For a very basic example, the following target event handler: $('.question-page .answer').on('target', function highlight(){ $(this).stop().css({'background':'orange'}).animate({'background...
stackexchange/codereview
I would like a review of: Correctness, especially around edge/corner cases Efficiency Readability and/or style Appropriate use of Java idioms and data structures In particular: Have I missed typical idioms/patterns useful to solving the problem? Could I have reused existing/popular framework/library code? Less inte...
stackexchange/codereview
Given a list of Employees ( name and grade). Output the names of the top 2 employees selected for a task(sorted based on grade and then alphabetically). I am using a maxHeap and override the compareTo method of the Employee class to define the sorting order while initializing the heap .I would like to know if there is ...
stackexchange/codereview
This code checks user permissions for uploading file, and if user can upload, then the file undergoes a check to see if it exists in SharePoint. If so then the file is pulled and uploaded to S3 bucket. This all works fine, but I have been told all these catches create callback hell. I've been trying to implement promis...
stackexchange/codereview
I wanted to implement a bubble sort in Scala following the steps described in: http://www.bbc.co.uk/education/guides/z22wwmn/revision/3 import scala.collection.mutable.MutableList val result = bubbleSort(List(3,2,4,1,5)) def bubbleSort(list: List[Int]): (List[Int]) = { def doIteration(list: List[Int]): (List[Int], ...
stackexchange/codereview
I have the following solution to this problem. The idea is to compute the maximum width of a binary search tree. The width of a BST on a particular depth is defined as the distance from the leftmost non-null node to the rightmost non-null node at that depth. This implementation proceeds downwards from the root node in ...
stackexchange/codereview
I solve projecteuler.net Problem 2 deferent way Generate number from 1 to range ex 100 and get the even number Get Fibonacci numbers from list Reduce array I have one problem with a large set of numbers like 1000000 or 4000000. can I ask how can I optimize the code? I am trying to solve the problem as a collection ...
stackexchange/codereview
I have the following code, which is working (?), but I guess I can do it simpler and more elegantly. I need to invoke a method when everything is completed (channelsVideos array is filled). The console.log function at the end runs and display the array. The objects are in it, but it is displayed as Array[0] in the cons...
stackexchange/codereview
Program finds the number of pairs of co-primes in an array using functional concepts in Node.js const assert = require('assert') const gcd = (a, b) => (b != 0) ? gcd(b, a % b) : a const co_prime = (a, b) => gcd(a, b) == 1 const co_prime_pairs = (_list) => { co_primes = [] _list.map( (x, i) => _list....
stackexchange/codereview
Splitting a string in tokens is a more complex topic than String.Split() wants to make us believe. There are at least three common policies according to which a string might be interpreted and split in tokens. Policy 1: Equivalent to String.Split() There is not much to mention about this policy. Given a string s and a ...
stackexchange/codereview
I have the following code to generate an URL based on alias and args provided /** * Get the url by alias. * * @param string $alias * @param array $args * * @return mixed */ public function url($alias, array $args = []) { if (empty($this->map[$alias])) { return null; } $segments = explode('/'...
stackexchange/codereview
I am learning dynamic programming. I read articles for the rod cutting problem and I applied it in cpp, and I got a doubt, does the below code solves the problem through memoization (say, previously rod(3) was solved, then if same function was called with same parameters) has the answer, or will it use tabulation (rodM...
stackexchange/codereview
I don't mess around a lot with templates (or with GTK), but today I wrote something and would like to know how it can be improved, and hopefully clarify a few things in the process. So, Randolfi() is a function template which returns a random number. A range can be specified as arguments. It uses features new to C++11,...
stackexchange/codereview
I wrote a Logger which uses the destruction of temporary objects to Log their values including a scope time logger. Lets see what i can improve here to increase the performance and everything else. class Logger { public: static inline LogMessage Log(LoggerTypes type, const std::string& file, ...
stackexchange/codereview
How to optimize below code to reduce code with better performance? import java.util.Scanner; public class ConsoleCalculatorImproved { static boolean ERROR = true; public static void main(String[] m) { String arg ; ConsoleCalculatorImproved cC = new ConsoleCalculatorImproved(); Cal...
stackexchange/codereview
This program should generate NxN boards where there are words going from left to right and words going from top to bottom. Words are valid if they appear in the scrabble dictionary. For example, a valid 3x3 board would be: ACT TOO EGO as it contains ACT, TOO and EGO going across, and ATE, COG and TOO going down. impor...
stackexchange/codereview
I have JSON files of size data_large(150.1mb). The content inside the file is of type [{"score": 68},{"score": 78}]. I need to find the list of unique scores from each file. This is what I'm doing: import ijson # since JSON file is large, hence making use of ijson f = open ('data_large') content = ijson.items(f, 'it...
stackexchange/codereview
I'm learning bash and my goal here is from any repository on my computer to be able to type github and it will open the remote in a browser for me. This works but I feel like I over complicated the remote=$(..) logic and arguably the get_ext() method. get_ext() allows you to type github issues and it will open the issu...
stackexchange/codereview
I am trying to design some classes which I intent to use as a framework. I would like them to be compliant to SOLID design principles. I had a basic structure and then I implemented Strategy design pattern and tried adding dependency injection as well. Would like this to be reviewed so that I know if my understanding i...
stackexchange/codereview
I recently wrote this OpenGL buffer wrapper which covers the 4.5 Core specification. I feel like the typed interface could be done better. Any feedback is greatly appreciated. #ifndef MAKINA_CORE_RENDERING_BACKENDS_OPENGL_BUFFER_HPP_ #define MAKINA_CORE_RENDERING_BACKENDS_OPENGL_BUFFER_HPP_ #include <cstddef> #include...
stackexchange/codereview
I have taught myself some bash and already knew some AppleScript, so I have come up with this SSH chatting tool for OS X users. It allows you to chat from a terminal to another OS X computer. One problem is that this code has to be located in an executable shell file on the computer of the person receiving the messages...
stackexchange/codereview
The purpose of this code is to allow to add functions to a queue, that will execute them sequentially. With this in mind, it also allows to execute them with a defined delay, to prevent them from blocking the browser. (function(window, undefined){ 'use strict'; var queue = []; var running = false; var s...
stackexchange/codereview
I am having a bit of difficulty in designing my Go code. I'll try to demonstrate things with a very simple example of adding a new user to the database. My Handler is only doing one thing: Calling a service. The service is managing all the business logic and then calling the DAO to interact with the database. The DAO a...
stackexchange/codereview
The goal of this calculator is to evaluate an expression with PEMDAS in mind (no parenthesis yet, adding soon). Although the program works, I want to make it as efficient as possible with the approach I used to attack the mathematical expression. So the way I decided to approach the problem is to initially organize the...
stackexchange/codereview
I have written a simple system to load plugins from files in Python 2.7, and I'd like to see if any of it can be improved upon. vedo.py from __future__ import absolute_import import os.path import inspect from vedo.event_emitter import EventEmitter from vedo import VedoPlugin def _get_module_name(directory, filenam...
stackexchange/codereview
The string I'd like to check is something like "abcSun24def". If any valid "xxxyy" (xxx = weekday and yy = day) is found, return the position inside the string. If "xxxyy" is not found, return -1. The code works as desired, but I think it can be optimized. /* ------------------------------------------------------------...
stackexchange/codereview
Of the languages that I use, I have the most experience with C++. I am looking to sharpen my skills with C, so I wrote this small calculator program. What I have here is a sample of how I would probably write larger programs. #include <stdio.h> #include <string.h> int getSumInteriorAngles(const unsigned int numSides...
stackexchange/codereview
One thing lead to another and eventually I wanted to know the "proper" way of writing the permutation generating function in C#. Below is my code for generating permutations. This will go into an internal library, so the calling context is really generic. Expected calling is in a single-threaded context /// <summary> /...
stackexchange/codereview
I wrote a piece of code that included multiple AJAX requests and multiple SetTimeout animations. I want the code to perform better, especially the SetTimeout sections. which part of the code should be improved? window.timer = []; window.timerNum = 1; function amLoading(timer) { var node = document.createEleme...
stackexchange/codereview
I have the following log4j2.properties file: status = info name = my-app # properties property.name = my-app property.basePath = log property.filename = ${basePath}/${name}.log # console layout appender.console.type = Console appender.console.name = console-logger appender.console.layout.type = PatternLayout appender...
stackexchange/codereview
Problem Statement A group of farmers has some elevation data, and we’re going to help them understand how rainfall flows over their farmland. We’ll represent the land as a two-dimensional array of altitudes and use the following model, based on the idea that water flows downhill: If a cell’s eight neighboring ce...
stackexchange/codereview
I inherited some code and have discovered that it seems incredibly inefficient. The code works by applying text formatting to the cells in an Excel file cell by cell, via this loop: Public Sub RemoveNumberFormat(ByVal columnName As String, ByVal lastColumn As Integer) For i = 2 To lastColumn textval = Range...
stackexchange/codereview
Please help me review this code. I want to make it both accurate and more Go-styled. Go Playground code package main import( "fmt" ) type TreeNode struct { val int left *TreeNode right *TreeNode } func isSameTree(p *TreeNode , q *TreeNode ) (bool){ if p == nil && q == nil { return true ...
stackexchange/codereview
I'm a beginner in Django3 and just wrote an overview function to pass on some data to the template in a context variable. I am definitely passing a lot more than I should as I only need only a few fields from each of these variables. Also, it might not be the most Django-esque way of doing things as it isn't using Gene...
stackexchange/codereview