instruction_seed
stringlengths
71
95.1k
_source
stringclasses
1 value
I have a set of views and view models in my project. There is a one-to-one mapping of views and view models, so each view requires a particular view model. I'd like to instantiate a series of views given a collection of view models. Here's what I've come up with: public class OverlayBundle : DrawingVisual { private...
stackexchange/codereview
The official Rust book chapter 13.1 includes an exercise to expand on the example provided in the chapter: Try modifying Cacher to hold a hash map rather than a single value. The keys of the hash map will be the arg values that are passed in, and the values of the hash map will be the result of calling the closure on ...
stackexchange/codereview
I wrote a C++ plugin that retrieves screen pixel. It works on Windows and Android. I noticed that dllexport is only required on Windows but not on Android and causes error on other platform other than Windows. I fixed that by using #if macro to make it use dllexport only on Windows. Here is the fixed header code: #ifnd...
stackexchange/codereview
The idea is to lock resources in C# or Java using Qt: lock(obj){/*process with locked obj*/}` Now I see the problem with deleting obj under lock(). resourcelocker.h #ifndef RESOURCELOCKER_H #define RESOURCELOCKER_H #include <QObject> #include <QHash> #include <QSemaphore> class ResourceLocker : public QObject { ...
stackexchange/codereview
I have this Python project to draw tessellated triangles on the screen. It takes the height to form the size of the triangle, cols to specify how many triangles on a line, and rows which is how many lines it outputs. This program has taken me some time to put together and I'm not sure if this is the best way to do this...
stackexchange/codereview
I have a model that consists of a 100 'agents' that change their x and y coordinates randomly. I use JFreeChart scatter chart to represent agents' locations. package jfreecharttest; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; import java.u...
stackexchange/codereview
In this code I calculate the statistical functions of values from different files and save them into CSV files (one filer for each statistical function). def mean(data): pass def standard_deviation(data): pass def afd(data): pass def norma_afd(data): pass def asd(data): pass def norma_asd(data)...
stackexchange/codereview
This script provides function T9r, which has some methods to detect, parse and replace tokens "{{ some_token }}" in a string with properties on an object. My use case, to have "composable" json objects or strings, (used for configs), that can be populated with real values at runtime. It's been a while since i worked in...
stackexchange/codereview
I want to create a network in which the links are formed based on a similarity metric defined as the Euclidean distance between the nodes. The distance is calculated using socio-demographic features of customers such as gender and age. The problem is the code takes 200 seconds to just create the network and as I am tun...
stackexchange/codereview
I coded a registration form and was wondering if anyone could give me feedback on whether I'm lacking any major security mechanisms. I've done loads of reading around the topic and feel it should be secure but expert feedback would be great. Registration script <?php // User/pass only used locally $host = 'localhost';...
stackexchange/codereview
I wrote a recursive sorting algorithm and was wondering what would be the run time complexity of this. The bulk of the work is done in the push_up function, which I think is linear in time. There are a linear amount of recursive calls though. If \$n\$ is the length of the list, would the runtime then be \$O(n^2)\$? def...
stackexchange/codereview
To put it in context, I had the assignment to do for a job interview in Node.JS, which basically making CRUD with products (and it have certain conditions). The assignment was well-understandable, and I have succeeded to make this task. After the company reviewed my code, I've got rejected because one of the main reaso...
stackexchange/codereview
This code could be better? This is the algorithm: Compare the 1st character to the last character Compare the 2nd character to the second last character and so on Stop when the middle of the string is reached Just words namespace Palindrome { class Class1 { static void Main(string[] args) { ...
stackexchange/codereview
Question: For a 1000-digit number, find the 13 adjacent digits which gives out the largest product. My code goes like this: series = '731...752963450' # the 1000 digit, simplified here. # Set up variables. adjacent_count = 13 pointer = 0 candidates = [], products_array = [] pointer_end = series.length - (adjacen...
stackexchange/codereview
This is my attempt at dealing with spurious wakeups: A new class which replaced std::condition_variable in my code. Some questions which came to my mind are (and I hope CR is the right place for that): Is this actually effective? Or will I run into concurrency-related problems? Would inheriting std::condition_variable...
stackexchange/codereview
I wrote the following function that takes a string and returns a new string with each word capitalized: first letter uppercase, following letters lower-cased. It works, but I would be interested in seeing how a more sophisticated Haskell programmer would do this (if there is already a built-in, great, but still interes...
stackexchange/codereview
Just wondering if my else {return false;} statements are superfluous... do I just need one return true; here? function has_access() { if ( is_user_logged_in() ) { $role = get_current_user_role(); $admins = array( 'Administrator', 'Agent', 'Contributor', ...
stackexchange/codereview
I'm struggling with some code that should be a very simple computation of a duration. The purpose of the code is to generate a random delay, constrained by an upper and lower limit. The reason I'm looking for advise here is that what should be a simple task, has turned into a behemoth of type conversions: package main ...
stackexchange/codereview
I'm totally new to coding and tried myself on a short text based adventure game. I got the feeling that the functions are the same ones all the time and the whole game is a bit monotonous... I'd be very thankful if anybody has some improvements or additional ideas! import random import time def nameFunction(): #hell...
stackexchange/codereview
I'm a seasoned programmer in a variety of languages (including Haskell and some ML dialects), but i'm a complete dilettante when it comes to formal logic. I've very briefly looked at Coq, and now i'm trying to dabble in theorem proving with Idris. In particular, before trying to use the interactive elaborator, I'd like...
stackexchange/codereview
I am relatively new to scripting. My programming experience stems from a QBASIC course when I was 11, and teaching myself HTML when I was a teenager (a while ago). This script resides on what is essentially a log of orders for a company. Occasionally, orders will be "shorted" if all the products are not ready in time f...
stackexchange/codereview
I am trying to remove the character from the list generated from the second string. At the end, if the array is empty it is the permutation of two strings else not. Is this logic fine? def is_permutation(string1, string2): if len(string1) != len(string2): return False string2 = list(string2) for cha...
stackexchange/codereview
I wrote this code to help with programming challenges. A lot of problems can be solved by complete search so I wrote this function that I can copy/paste between problems to generate permutations quickly. Does anyone have any comments or suggestions to improve this function? bool bruteforceGenerator(string& permutationI...
stackexchange/codereview
I am coding in java since some time but I was not always really organized about methods and commentaries, here is a quick code to use the Cesar code : package cesar_code; import java.text.Normalizer; import java.util.Scanner; public class CesarCode { private static Scanner sc = new Scanner(System.in); priva...
stackexchange/codereview
I created this Javascript function to manage six simple audio players within a page, so that when one of them is put into play, it shows the pause button, and any other player that was playing previously, shows the play button. Sometimes the play / pause mechanism gets stuck (although I don't know if it depends on too ...
stackexchange/codereview
I have a set of products(e.g. P0006, P0009, etc.) and a set of production lines (eg. L1H175, L2H175). A product can be produced on a subset of the lines set (and not necessarily all of them). If we decide to produce a product on a production line(assuming that the line can actually produce it), we need to buy the appro...
stackexchange/codereview
I wanted to create a basic String class that will hold a CString and have: constructor, destructor, copy constructor assignment operator (both from String and CString) << and >> operators to stream with cout and cin ==, < and > operators to compare Strings [ ] operator to access a certain char in a string Len() func...
stackexchange/codereview
Given constant external space (yes no HashMap), how would you improve the following code (code-wise or complexity-wise with stress on the latter) to find the majority element in an array? /** * Created by mona on 5/27/16. */ import java.util.Arrays; public class FinaMajority { public static int findMajority(int...
stackexchange/codereview
I have a year or so of experience in developing in Java. I submitted the solution for this task, but never got the feedback that was promised. Since I still would like to get a feedback on my solution, I figured that here I will find skilled developers who wish to help me and others who may have similar questions. Com...
stackexchange/codereview
This is stripped down from a project I'm working on: let userFields = { id: { dbFields: 'id', }, email: { dbFields: 'email', }, first_name: { dbFields: 'first_name', }, last_name: { dbFields: 'last_name', }, name: { dbFields: ['first_name', 'la...
stackexchange/codereview
I am testing various sorting algorithms. Right now I am testing shell sort, insertion sort and selection sort. I ran all three algorithms on a randomly-generated list of 1000 integers. The selection sort took 41 seconds, insertion sort took 34 seconds and shell sort sort took over 3 minutes. What can I do to improve my...
stackexchange/codereview
I want to implement an Agent-like object in C#. An Agent wraps some memory location (ideally storing an immutable object) and receives updates to that location. All these updates are performed asynchronously, but sequentially. In other words At any point in time, at most one [update submitted to an] Agent is being e...
stackexchange/codereview
I have this C implementation of the natural merge sort: #include "stable_sort.h" #include <stdbool.h> #include <stdlib.h> #include <stdio.h> #include <string.h> typedef struct run_length_queue { int* storage; size_t capacity; size_t head; size_t tail; size_t size; size_t mask; } run_length_qu...
stackexchange/codereview
gotoxy() allows you to place the blinking text wherever you want. I wasn't able to get it to behave the way I wanted, so you will notice I had to insert a bunch of spaces in the cout portion of the blink function. Obviously this could be refined. blink() I put a "/r" to set the cursor back to the beginning of the line,...
stackexchange/codereview
The problem: I have a function that writes an array it takes as argument to a div, in a single line. Example: writeToOutput([1,2,3]) outputs 1,2,3 The aim is to improve this function, to be able to take an array of arguments, and display them on several lines Example: writeToOutput([[1,2,3],[4,5,6]]) outputs 1,2,3 ...
stackexchange/codereview
Given any series of numbers, for example 1,2,3,4,5 and given the arithmetic operands + - * / including parenthesis, what would be the most optimal way to build a tree that contains all permutations and all expressions for these numbers and operators? It doesn't have to be in a specific programming language like Java or...
stackexchange/codereview
I'm working on an optimization code using differential evolution to solve. However, it is taking a long time to get the solution. See that I have a variable called number_of_iterations that must equal 1000000. When I consider this decision variable equal to a smaller value (eg number_of_iterations=100), the result is p...
stackexchange/codereview
A problem from Coderbyte. Find the longest word in a sentence after removing the punctuations and if two or more words are of same length return the first word Below is my solution: def cleanWord(word): # To remove punctuations punctuations = ['!','.','\'','"',',','&'] new_word = '' for c in word: if c in ...
stackexchange/codereview
I have one machine, which produces parts. In machine_failure_rate% it produces faulty parts which need to be produced again. Thus, we end up with a simple queuing problem. Can the following code be futher functionalized? I have the feeling, I can get rid of time_parts, but all I have in mind deteriorates the code as I ...
stackexchange/codereview
Please treat this as a interview at a top tech firm, and share your thoughts on how you think I did. Be honest, and leave no stone unturned. Problem: Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: Only one letter can be changed at ...
stackexchange/codereview
I implemented the Maximum Profit in Job Scheduling algorithm in JavaScript, but I'm having performance issue. The problem: We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i]. You're given the startTime, endTime and profit arrays, return the maximum p...
stackexchange/codereview
I made a program that prints out a diamond with n lines. n is equal to whatever the user inputted. I know I overuse the ternary or conditional operator, but in my opinion, it makes the code more compact, and since I am the only one reading my code, readability doesn't matter to me. My friend challenged me to write one ...
stackexchange/codereview
Goal I want to extract HTML tags and its content from a string. The content (input) is queried from WordPress database. Sample data (input) I extract this dummy data from my WordPress database: https://www.phpliveregex.com/p/tan I believe this should cover all the needed tags to parse. Expectation (output) Accepting a ...
stackexchange/codereview
In the spirit of April 2015 Community Challenge, I have created two Java-based calculators with the following codebase layout: An interface Calculeightor for describing how values can be appended into a stream and then reduced to a single result given an operator. An enum Operator to represent the operators. The GUI i...
stackexchange/codereview
I knocked this together in a few hours as I was just simply bored. I was going to add a namespace to this but decided there was no point. This is also available on Github All feedback is appreciated! <?php /** * This class will allow you to generate goo.gl links * @package Google * @subpackage Googl * @author...
stackexchange/codereview
I need to figure out what can be done to improve the performance of a A* search algorithm in PHP. The idea is to look for the shortest path, in number of hops, between two points in a "map". Actual distance is irrelevant. This is a minimalistic functional version of what I'm doing: <?php /* 1 ____ 2 ____ ...
stackexchange/codereview
This is a (relatively) cleaned-up version of a Python script I've been working on for the past day or two based on Tim Golden's first solution to the above problem. I know about watchdog but I'm trying to keep dependencies down to a minimum. I'm concerned about how Pythonic my code is, as this is the first "real" scrip...
stackexchange/codereview
I'm trying to make a good MVC model using annotations, which I will use it in a large scale GUI project. I want to respect the maximum of rules and guidelines, and be able to decorrelate every parts of the MVC. The code must be beautiful, testable and maintainable. I wrote a sample project to show you my model. What do...
stackexchange/codereview
I am a beginner in FPGAs, and I am studying Verilog HDL. Could you please check the quality of my code (a shift register)? Any comments are welcome. The shift register serializes parallel from wr_data_i data to serial_data_o and has two variations of first serialized bit. It may be most significant bit or least signifi...
stackexchange/codereview
I wrote it this just for learning. Is there holes at this code? public interface ConcurrentStack<T> { //blocking void put(T t) throws InterruptedException; //blocking T poll() throws InterruptedException; //non-blocking put boolean offer(T t); //non-blocking get T take(); } class Con...
stackexchange/codereview
Zend framework 1. Physically, the file does not exist, it is created based on database. Okay so use header? public function downloadAction() { $id = $this->getRequest()->getParam("id"); $optin = new Application_Model_Optin(); //$data = $optin->getCodesFromDownload($id); $data = array( array('cod...
stackexchange/codereview
I'm quite new to JavaScript, and I'd like a review of the code structure and syntax. It serves this little online regexp test (still a work in progress). The whole code (JavaScript, CSS & HTML) is on GitHub. application.js: function update_result_for(input, regexp_value) { var input_value = input.val(); var resul...
stackexchange/codereview
I'm working on an XNA project that loads several resources that are packed into a single file. XNA can take a WAV file stream and turn that into a SoundEffect (seen below in "case ".wav""). Since WAV files are large, I want to enable MP3 audio as one of the resources, so I found MP3Sharp, a cross-platform library that...
stackexchange/codereview
I was just tempted to write a similar piece of code to the one presented in this answer on SO (posted below). The problem is having to discriminate between different cases where exactly one case is true. In my experience switch statements are usually use to match the value of an expression against various constants. B...
stackexchange/codereview
I have an array and I need to make one function which has two parameters, array and K. I need to return a new array with only K elements reversed, the rest becoming the same as in array. I am able to get correct results but I think its performance is too slow. Is there any better solution to get the same results? var a...
stackexchange/codereview
After almost completely redoing the first version I think I finally have it. I still have a few things to add/change, but I think it's pretty good and safe. I've improved security features as well as overall functionality. I haven't run this program through pycharm yet, so there might be a few PEP 8 errors. It took me ...
stackexchange/codereview
I made my first jQuery plugin, and was hoping to get a review. I'm especially interested in comments on whether I went about building up my html and applying the css in a reasonable manner (I chose to do it all in jQuery to keep the dependencies limited). I welcome most of all comments regarding ways to improve the cod...
stackexchange/codereview
The code reads 512 bytes at a time and stores them in a buffer. When the code sees a .jpeg signature it will proceed by writing to a .jpeg file until another signature is found, thereafter the process repeats. #include <stdio.h> #include <stdlib.h> #include <cs50.h> #define infile "card.raw" #define BLOCK 512 /** * ...
stackexchange/codereview
Setup: I have ~30 parameters (dependent variables) measured simultaneously along a common time axis with ~1Hz resolution (independent variable). I need to calculate bin averages for all parameters, with a bin width of 10 seconds on the time axis. Potentially also other statistical parameters like standard deviation and...
stackexchange/codereview
This is a function to determine if a number is between x and y. It is part of a library of mine called EOL or "Everything in One Line". #include <stdbool.h> #ifndef _WINDOWS_H #include <windows.h> #endif bool between (WORD n, WORD x, WORD y) { return (n >= x && n <= y) ? (true) : (false); }
stackexchange/codereview
I have a need to update thousands of database records at a time. I am using a loop to generate the necessary PreparedStatement updates, but am hoping for a more efficient method. Normally, I would try to use a batch operation, but since the number of fields I need to update for each record differs, I need a new Prepare...
stackexchange/codereview
This code is supposed to find, in a graph, the node with the smallest maximum distance to all the other nodes. The problem from Quora is : How do I find the node that has the least maximum distance to all the other nodes in a tree? "So you're thinking about moving into an unknown city. You have been given a map of...
stackexchange/codereview
I am filtering an array whenever checkboxes are checked. if (this.deliveryConcession[0].checked) { this.allItems = this.allItems.filter(fil => fil.deliveryconcession.readytoship === this.deliveryConcession[0].checked); } if (this.deliveryConcession[1].checked) { this.allItems = t...
stackexchange/codereview
I've been working with Sanic as my default web framework, but coming from Flask, I had some issue with how to handle the database connection. So I built an asynchronous wrapper around it. I've also added an option to post process callbacks only when the whole process was successful (didn't thrown an error) and handling...
stackexchange/codereview
I have been developing a C++ driver for the incremental rotary encoder (irc) based speed sensor. It is a part of my embedded software project. The driver is basically decomposed into two layers: The first layer consists of the driver for the fpga peripheral for processing the signals generated by the irc sensor. This ...
stackexchange/codereview
I've created an admin login area for an application I am planning to code, and I've used the following login.html page to let the user type in his data (I left out parts like "id", "placeholder" etc. to make it shorter): <form method="post" action="login.php"> <input type="text" name="username"> <input type="passwo...
stackexchange/codereview
https://github.com/pixlark/vars-parser #![allow(unused_variables)] #![allow(dead_code)] #![allow(non_camel_case_types)] #[cfg(test)] mod vars_parser { use std::str::Chars; use std::iter::Peekable; use std::collections::HashMap; /// Useful wrapper for Peekable<Chars> which returns an EOF char /// w...
stackexchange/codereview
I'm new to AngularJS, coming from a jQuery background and I have a situation I've solved but only by including jQuery in an AngularJS function. Something just doesn't feel right doing this and I was hoping someone could tell me if there's a better way. (This is all code I have inherited and have amended to enable new ...
stackexchange/codereview
I've posted and gotten help to optimize my code before here and here. Now I have implemented the following changes, after very helpful advice: I have implemented a Dictionary instead of using list when looking into the extracted messages. I have implemented index on the userid and unixtime tables in my database. Bo...
stackexchange/codereview
I was going to post this in code golf, but I think it may be better suited here. I'm not really interested in scoring it beyond accepting the best answer. I'm wanting to minimize this series of IFS, if possible or necessary. I'm brand new to javascript/coding, but it just seems like there may be some redundancy here....
stackexchange/codereview
When one writes C++ code to manipulate LinkedLists, Trees, etc. one creates a tmp pointer that points to the start/root and changes that pointer as one traverses along. What would be the equivalent way of doing that in smart pointers? Here, I wrote a Trie code using std::unique_ptr to understand how to pass pointers ar...
stackexchange/codereview
Hello everyone! Here is the thing. So I wanted at first to create Robot class, I want him to move around some board. Maybe 10x10 or something like that, then i wanted to invent a Robot fights class, I want to add class players (becuase i want to play between player 1 and player 2) but here it is what I have so much. Le...
stackexchange/codereview
Below are two ways to calculate an element of the Fibonacci series. Can someone please help me understand why fib1 is so much faster (over 60x) than fib2 ? fib2 is just an assignment and a decrement whereas fib1 involves a dictionary and recursive calls. Thanks. import timeit def fib1(n, lookup=dict()): if n == 0 ...
stackexchange/codereview
Alice and Borys are playing tennis and it is unknown who served the first game. After each game, the serve changes to other player. If the server wins the game, then it is said that s/he holds the serve and if the receiver wins the game then it is said that s/he breaks the serve. If Alice won a times and Borys won b ti...
stackexchange/codereview
This is my program code for comparing if 2 images are the same. It basically uses the open dialog and opens 1 image at a time and puts it in 1 picture box. I heard that GetPixel() method may be slow. Is there a more efficient and faster way to compare 2 if 2 images are the same? Bitmap image1 = null; Bitmap image2 = n...
stackexchange/codereview
Typeclassopedia presents the following exercise: Maybe can easily be made an instance of Applicative; writing such an instance is left as an exercise for the reader. Here's my implementation: data Option a = Some a | None deriving Show instance Functor Option where fmap _ None = None fmap ...
stackexchange/codereview
I have had an attempt at the Mars Rover Kata and would very much appreciate a review and any suggestions to improve. MessageParser to parse incoming messages and create the domain models: public class MessageParser { private static readonly Regex GridDetailsRegex = new Regex(@"\d\s\d"); private stat...
stackexchange/codereview
I'm hoping someone could vet my route structure as I've really been struggling with getting something that feels right. Right now I have this nested resource structure: Rails.application.routes.draw do concern :configable do resource :config, only: %i[edit update] end resources :tags do scope module: 't...
stackexchange/codereview
I feel like I’m violating a lot of DRY rules here but can’t think of a better way to do this. I have two event methods (there are actually four total just showing two) that are doing a lot of similar actions but on different DOM elements. Is there a better way to re-factor this so I’m not repeating myself so much. ...
stackexchange/codereview
I have this short program for simulating a random packet routing algorithm: Packet.java package net.coderodde.simulation.network; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; /** * This class implements a packet being transmitted ...
stackexchange/codereview
I have the following class which represents a set of properties. public class Properties { /** String type properties. */ private final List<String> m_stringProperties = Arrays.asList("str1", "str2", "str3"); /** Float type properties. */ private final List<String> m_floatProperties = Arrays.asList("fl...
stackexchange/codereview
So this is a post as per request in a different post on stack overflow: https://stackoverflow.com/questions/62412713/why-does-my-c-sharp-xml-code-only-work-when-i-enumerate-variable-enumerable. The goal of this code is to re-format an XML-file containing a treeview of a sort of folder structure. The XML is of the follo...
stackexchange/codereview
I am studying Clojure and functional programming. I wrote this function to compute the centroid of a polygon specified as a vector of points, e.g. [[10 20] [0 11] [50 30]]). Here you can read how to compute the centroid of a polygon. Can you give me hints and suggestions on how to improve this code from a functional c...
stackexchange/codereview
I have implemented AI to tictactoe game by using Minimax Algorithm. The game looks working okay and AI is intersecting the player moves to block him from winning the game. I would like to know if I implemented the Minimax Algorithm correctly. if so, how can I improve it further. #include <iostream> #include <iomanip> #...
stackexchange/codereview
I'm creating custom classes to represent Planes and Lines on a 3d graph. To help improve the performance of my process I've started implementing __eq__ so that I can eliminate duplicate objects in a list using objList = set(objList). I'm wondering how to efficiently expand the __eq__ methods so that it can compare if t...
stackexchange/codereview
When programming debug functions I am left with 2 options, either put them all within preprocessor blocks so that they don't exist at release runtime, or put them within an if block with a debug flag constant variable (determined at launch) to control their execution. I wanted to write an improved method where in relea...
stackexchange/codereview
Is there a better way than using 2 for loops and 2 if statements deep? jsfiddle: https://jsfiddle.net/bobbyrne01/bmnk9bLz/ Code: var documentsInDatabase = [{ id: '1', revision: '1' }, { id: '2', revision: '1' }, { id: '3', revision: '1' }]; // incorrect revision of document with id of 1, and non-existent d...
stackexchange/codereview
I would like your opinion of my PowerShell function. Does it follow conventions, and what could can I do to improve it. It is made to create LDAP friendly username from a full name in Serbian language. function Get-UsernameFromFullName { [CmdletBinding()] param ( [Parameter(Position = 0, Mandatory =...
stackexchange/codereview
I want to understand how to properly nest key/pair values within a struct. My use case is to create a type to return serialized JSON on my API responses. I'm using rocket, this is my general setup: // cargo.toml [package] name = "api" version = "0.1.0" edition = "2018" [dependencies] rocket = { version = "0.5.0-rc.1",...
stackexchange/codereview
I made this quiz but the code seems to be really lengthy. Can anyone find a way to make my code shorter? Considerably shorter would be best but anything helps. I think the main problem is the repeating of the questions. choice=raw_input("What type of quiz do you want to do: maths or science? ") topic=open("topic.txt",...
stackexchange/codereview
Well, I'm writing a piece of code that will take a list of file names and should search a local drive for each file, determine if it's there or not, and return an array of all the paths found. Right now I'm using a function that searches for one file and I call this function for each file in the list: Public Function D...
stackexchange/codereview
I'm currently implementing an interner in the style of Guava's Interner, where: an intern pool is maintained for an immutable class whenever a new instance of that class is created, it's checked to see if it's equal to an existing instance in the intern pool if such an existing instance is found, it's returned, otherw...
stackexchange/codereview
There is a Name class with properties that represent different components that make up a person's name. A Name object requires a FirstName and Surname. All other fields are optional. class Name { public string FirstName { get; set; } = String.Empty; public string Surname { get; set; } = String.Empty; public...
stackexchange/codereview
Here is my code: library(gtools) library(Rmpfr) library(OBsMD) precBits=1000000 K=9 n=1000 p=mpfr(c(K:1),precBits = precBits);p=mpfr(p,precBits = precBits)/mpfr(sum(p),precBits = precBits) #p is a vector of probabilities zu.mpfr <- function(freq, u, precBits){ sum=mpfr(0,precBits = precBits) n=sum(freq) for (i i...
stackexchange/codereview
Took me a couple of days (in between working on other projects) to get the code working, but now that I do have it working I would like to know if there is a way that I could make it work better, or clean up my act JavaScript/jQuery surrounding my JSON utilization skills. I am using ASP.NET if that means anything to th...
stackexchange/codereview
I am a beginner who wrote this simple Hangman game in C for fun and to practice programming. I am looking for advice on optimizing this code and making it adhere to best practices. Are there too many variables, conditionals, and loops? #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #includ...
stackexchange/codereview
I decided to try out Python (3.x) two or so weeks ago, and this is my first real script using it. The program I've written below is slow, clunky, inefficient, inaccurate, and probably poorly coded! But it produces what I want most of the time, and it was really just a project to become accustomed to different Python te...
stackexchange/codereview
I have two Pandas DataFrames and I want to subset df_all based on the values within to_keep. Unfortunately this isn't straight forward pd.merge() or df.join() because I have multiple columns that I want to match on, and I don't care what order the match happens. I don't care if df_all['source'] matches in either to_k...
stackexchange/codereview
I have to implement an image-Carousel. Because I'll reuse the snippet within other projects which might contain all kinds of external libraries I used an immediately invoked function expression. Could my code be improved? All Hints appreciated. (function (imgPaths, imgTag, prevButton, nextButton) { var length = im...
stackexchange/codereview
var addToTeam = document.getElementsByClassName('addToTeam'), parentElement = document.getElementsByClassName('playerTypeBlock'), playerName = document.getElementsByClassName('heading'), totalVal = document.getElementById('totalvalue'), tableBody = document.querySelector('.totalPlayers'); var updateP...
stackexchange/codereview