instruction_seed
stringlengths
71
95.1k
_source
stringclasses
1 value
<?php define('AES_256_CBC', 'aes-256-cbc'); // both stored in a file on server $encryption_key = openssl_random_pseudo_bytes(32); $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(AES_256_CBC)); $user_id = 1123; $exp = time() + (365 * 24 * 60 * 60); $data = [ "user_id" => $user_id, "exp" ...
stackexchange/codereview
I am using spring boot in my application. @EnableAutoConfiguration @SpringBootApplication public class PushMysqlTestApplication implements CommandLineRunner { private static Logger LOGGER = LoggerFactory.getLogger(RunQuery.class); @Autowired JdbcTemplate jdbcTemplate; public static void main(String[] ...
stackexchange/codereview
This is my first salesforce code. It seems to me there is too much data lookup but I don't know enough about saleforce apex coding to say. The purpose of the code is to set the entitlement based on the record type when inserting a new Case record. The business reason for this code is the proper assignment of Entitlemen...
stackexchange/codereview
I've written a new malloc implementation similar to dlmalloc and was hoping for feedback on it. The goals for this library are: Easy to read and maintain Be more memory conserving High efficiency and good performance Portability The documentation is here and the code could be found here. /********************** mallo...
stackexchange/codereview
This helper class is supposed to validate the user input from a text based wifi login form. The entire process is basically this: I use the create_voucher function of this API passing voucher_duration to set the amount of time for which the voucher is going to be valid and $this->clean['name']." ".$this->clean['surname...
stackexchange/codereview
I am going in a circle over and over trying to write a "supermarket" application using OOP. The app should be useful for the employees of a supermarket. The app reads data from a CSV file which looks like this: name,amount soap,4 rice,5 bread,10 The supermarket has cashiers and managers. Cashiers should only be able t...
stackexchange/codereview
I'm toying around with a Caesar cipher that supports keys. The cool thing about it is that, unlike most Caesar ciphers you see, it works with byte arrays, not just strings, so you can encode text as well as files and other data. Of course, if you're looking for true security, you wouldn't want Caesar encryption of any ...
stackexchange/codereview
As an example code I've given here, I have the feeling the use of std::shared_ptr is wrong and should be replaced using a std::unique_ptr because there's no real shared ownership semantics, besides of temporary needs. How could that code be refactored correctly, e.g. using std::unique_ptr instead? #include <memory> #in...
stackexchange/codereview
I have written a small plugin library for CKFinder that I would like some critiques on. The library is located here. If you are looking for where to start, check out plugin.php and hook function in here in the assets/ckfinder/core/connector/php/php5/CommandHandler/ folder. I would really love to hear your critiques on:...
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
My FeatureSerivce provides only basic APIs, so it is good in dealing with single features. Like I can configure only one feauture at a time: public FeatureService Configure(string name, Func<FeatureOptions, FeatureOptions> configure) This might qiuckly get a lot of work when everything that has something to do with ...
stackexchange/codereview
SQL Server 2017 The table contains duplicate contracts per factory with different From and To dates. I'd like to select the correct row based on a declared YearMonth parameter. If this falls in the range between From and To date this row should be selected otherwise the fallback row with the default date 199401 should ...
stackexchange/codereview
I am currently working on a game, and I get the configuration in an .ini file, and I get information with this library https://github.com/benhoyt/inih I would like to improve the readability / performance of this code, as I do not know much about good practices. include "project.h" // typedef struct s_server_conf { //...
stackexchange/codereview
I need to make an unknown number of api calls, up to 5 max probably. But most samples I've seen show only a couple of async calls so are effectively hard coded to the number of calls being made. This is what I came up with as a demonstration, it has an array with three sleep times in it to simulate an API call of varia...
stackexchange/codereview
I wrote a simple image scraper for the Desktop Wallpaper project by The Fox is Black. The site is a fantastic (yet, apparently dead) blog full of fabulous images. However, there's no way to download an entire bundle of images, hence this simple scraper. I'm putting the code up for scrutiny. Any areas for code style and...
stackexchange/codereview
I've tried to create optimal in terms of performance and memmory consumption. But also I've tried to make it functional and scala way. I want to get you comment on how to make it more 'scala'stic object LifeGame extends App { trait Matrix extends Iterable[(Int, Int)] { def apply(p: (Int, Int)): Boolean ...
stackexchange/codereview
Coming from a C/C++ background, this was my first python code I wrote to grasp a few basic concepts. The game involves giving random arithmetic operations to the users and scoring their responses. Player has 3 lives i.e he can mark 3 wrong answers at most. I've tried to time the game i.e the player gets 60 seconds to s...
stackexchange/codereview
Objective: The goal of this script is to tokenize and print out all the words from the provided bible.txt file. Constraints: It should differentiate between 'U.K' and 'UK.' when removing extra symbols from the word. It should exclude duplicates. It should exclude words that contain digits. Existing code: #!/usr/bin/e...
stackexchange/codereview
Can anyone help me improve my instr() function? int myInstr(wchar_t *str, wchar_t c, int start, int dir){ int pos = 0, result = 0, len; wchar_t *p1; //Left if(dir == 0) { p1 = str; len = lstrlen(str); while(pos < len) { if(*p1 == c) { ...
stackexchange/codereview
I recently started programming and chose C# as my first language. After a couple of weeks/month now I tried to make my own Sudoku solver in a console application. I'm happy with the result, and tried to clean up my code. But I'm not sure what I can do better at this point. I was uncertain if I created too many function...
stackexchange/codereview
Here's my class for providing a singleton instance of a Redis connection. What do you think? from redis import StrictRedis import os class RedisConnection(object): REDIS_URL = os.environ['REDIS_URL'] def __init__(self): self._redis = StrictRedis.from_url(self.REDIS_URL) def redis(self): ...
stackexchange/codereview
In my effort to learn Rust I've tried implementing an Iterator that splits up a buffer in two halves, and correlates both halves by sliding them over each other with different positions (lags). You could use this e.g. to do autocorrelation, given a correlation function between two buffers (dot product for example). I'm...
stackexchange/codereview
I'm really new to OpenCV. :) I have been working on this for almost an entire day. After hours of sleepless work I would like to know if I can further improve my code. I have written some code to select only the black markings on the images. These black markings are child contours. Whilst my code is able to select some...
stackexchange/codereview
I'm using jQuery to swap images on hover. There's a main image, and a gallery of thumbs. When the thumb is hovered over/touched, the larger version of it populates the main image, and the smaller version of the original populates the thumb. This happens via swapping src and data- attributes. This all works, but being r...
stackexchange/codereview
I had to create an executable to search and replace strings in a file. This is to be used in my installer for text file manipulation. I have various placeholders in configuration files that I need to replace with proper values after querying the end user system. I have written the following code. This being my first re...
stackexchange/codereview
I implemented this context manager for importing modules from arbitrary directories. Good? Bad? - Keen to get thoughts: Implementation import sys class CustomPath: def __init__(self, path:str): self.original_path = sys.path self.custom_path = path def __enter__(self): sys.pa...
stackexchange/codereview
I'm parsing out specific values on web pages with BeautifulSoup. However, since I'm using RegEx, my program is taking forever to run. Would love ideas on how to speed this up. from bs4 import BeautifulSoup import datetime import json from progressbar import progressbar import pdb import pickle import re class Listi...
stackexchange/codereview
Could someone tell me how I can improve this please? It's similar to my other question just another version of it. using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sahara.Base.Game.Rooms { internal class Active...
stackexchange/codereview
Endpoints to save a Pandoc document to the database using persistent. Prior to being stored, the code strips out all of the paragraph content (the [Inline]'s) and stores these using the type Stream. Each extraction is marked with the relevant Stream id in the Pandoc document (ie <span data-stream-id="3"/> in HTML). Whe...
stackexchange/codereview
I am trying to improve the algorithms for the following code! The problem I am trying to solve is that I have nested loops that don't look efficient. This includes the Sales_item.h file from C++ primer 5th edition that may have to be updated if we want to go another design route. #include <iostream> #include <fstream>...
stackexchange/codereview
In an interview I was asked the following problem: Given a range of numbers (0 - 100) or (0 - 1000), find all the numbers whose digit add up to 5. I started off with a brute force way to iterate over all the numbers and filter out numbers whose digits do not add up to 5. The numbers remaining will be the answer. It ...
stackexchange/codereview
I'm trying to make a reusable data layer that is mostly generated from a database via T4 templates. On top of this data layer, I'd like to have WebAPI endpoints for each repository, with most of the basic CRUD operations generated/from a base class. The generics are somewhat getting out of hand, and I don't know if I'm...
stackexchange/codereview
I have written a very XNA spritebatch like interface for drawing sprites in OpenGL. When begin is called the vertex data buffer is mapped to a float*. The index buffer and vertex buffer are bound in begin, and it's assumed no other drawing is done in this OpenGL context between begin and end. In between begin and end, ...
stackexchange/codereview
I required a trigger, whenever the window text selection cleared. Finally I found this approach. Using the same id, I have added multiple event handlers, but I am not sure my work is the best. Is there a better way to do this? $('#tenderContent').on('mouseup', '.tenderdocument', function (e) { e.stopPropagation()...
stackexchange/codereview
I am trying to abstract data from a complex and create a EventDto. And I was able to do it using foreach but the syntax is dreadful. Is there a better way of writing this code? public class EventDtO { public string Id { get; set; } public string Title { get; set; } public string CategoryTitle { get; set;...
stackexchange/codereview
Please review my code based off of a responsive Initializr template. It's functional and visually correct, but I know there's better ways to write the code. Let me know if I can layout the HTML5 better and/or best practices I'm not using for CSS selectors because I feel my stylesheet is all over the place. HTML <!D...
stackexchange/codereview
The use case is to convert an array of objects into a hash map where one property is the key and the other property is the value. Common case of using this is converting a "link" object in a hypermedia response into a hash map of links. jsfiddle function toHashMap(data, name, value) { return _.zipObject(_.pluck(dat...
stackexchange/codereview
I implemented a Double linked list in c++ to practice. I reviewed the code myself and I would like others perspective about the improvements that could be made. I have also noticed that I don't take fully advantage of many c++ features nor use them in my code. Any comments about significant performance improvements are...
stackexchange/codereview
I created the following HtmlHelper extension method for my Asp.Net MVC Razor views because the ternary syntax sucks when you need to use it intermixed with markup. Is there a better way to write this and are there any potential type safety issues with it? public static string GetValueTernary(this HtmlHelper htmlHelper,...
stackexchange/codereview
I am automating the building and unit testing of a personal project using shell scripts , CMake and make on the latest version of Fedora Linux. I have also tested building on the latest version of Ubuntu. I had to decrease the minimum CMake version on Ubuntu to make it work. Parts of the unit testing have previously be...
stackexchange/codereview
As you can see from my predicate iterate, I am repeating Z is X-3 and Z is X-2, the scenarios are different if the value is 0 or greater than 0. thus why the duplicates, Was wondering if there was a way round this iterate([], []). %Nothing to change iterate([1|T], T). iterate([X|T], [Z|T]) :- % Chan...
stackexchange/codereview
I wrote a program sometime ago that reads csv files, sorts, reorders and groups their columns/rows' content (with itertools) and later labels the groups using a dictionary. The groups and dictionary are then flattened and rows of length N (columns) are uploaded to a spreadsheet. This is another function, not specific t...
stackexchange/codereview
I've just complete a Pig Latin translator as a code kata and I was hoping someone would review it for me. Here is the kata: PigLatin Kata Create a PigLatin class that is initialized with a string - detail: The string is a list of words separated by spaces: 'hello world' - detail: The string is accessed b...
stackexchange/codereview
I've been trying to find the minimum steps it takes for a number to be reduced to 1 given the three following steps: Divide by 2 Increment by 1 Decrease by 1 My code is as follows: def answer(n): num = long(n) count = 0 while num > 1: #When number is odd if num%2 == 1: #If the numb...
stackexchange/codereview
I'm working on a booking application and am in the process of porting some legacy code to a more SOLID and testable architecture. Right now I'm working on the process of canceling bookings. Over the years, we have changed the steps involved here. The core has been the same (update booking entity status, make the timesl...
stackexchange/codereview
I have this Java solution to LeetCode's 3Sum problem. I would be really grateful if I could get feedback on correctness, scalability, efficiency, coding best practices, and OOP design. I'm relatively new to Java. class Solution { public List<List<Integer>> threeSum(int[] nums) { List l1 = new ArrayList<...
stackexchange/codereview
I am using Bootstrap v5.3 to create a card layout, and I want it to be SEO-friendly (see this link for my SEO-friendly criteria). Below is my card component I wish to optimize and, if possible, to drop some classes from <div> elements for cleaner markup. I am considering to put all styling inside a style file, which is...
stackexchange/codereview
I am having some issue to use PHP5 password_hash() function. My server is not supporting it, so I am using a function to hash. Is this one secure? public function Pass_Hash ($password) { $blowfish_salt = bin2hex(openssl_random_pseudo_bytes(22)); $hash = md5(crypt($password, "X1;G^COU8U`Bo*A6@9<on5yQ6P87M]...
stackexchange/codereview
In the below code there are 3 inputs. First line of input is the number of testcases for which the program will run where (1<=testcases<=10) and i is an int. For each testcase Second and third input will be a String where (1<=Stringlength<=10^5) Output Now for the output we need to compare both the strings and remove s...
stackexchange/codereview
I am currently implementing a thread-safe in-memory cache mechanism, with the intent of storing objects that are expensive to create or often used by the system. I also want to include an expiration policy, i.e number of times an object was accessed and when it was last accessed. This will be used to scavenge, so I opt...
stackexchange/codereview
There is a tree of start folder, it's subfolders, their subfolders, etc. In each folder, subfolder, etc. there are the same structured XML files stored. books.xml <xml> <book> <author>Isak Azimov</author> <name>End of spirit</name> </book> <book> <author>熱い</author> <name>Happiness of plants</name> </bo...
stackexchange/codereview
I have an XML Parser in Java using WoodStox that I wrote. This parser is going to be parsing through extremely large files, could be 5+GB. The goal of the parser is to convert a nest XML file into a CSV. The XML file is going to be formatted in such a way where there will be a 'rowTag' that has the actual information t...
stackexchange/codereview
Today I had an interview, where I was asked to solve this question. A \$N*M\$ matrix is called a palindromic matrix, if for all of its rows and columns, elements read from left to right in a row are same as elements read from right to left, and similarly, elements read from top to bottom in a column are same as element...
stackexchange/codereview
I am trying to find the longest repeated string in text with python, both quickly and space efficiently. I created an implementation of a suffix tree in order to make the processing fast, but the code fails on large files due to memory problems. I am purposely not using any advanced libraries for this particular code....
stackexchange/codereview
Simple function which returns a text representation for numbers in range [1...1000]. N100 = 'hundred' N1000 = 'one thousand' N1_9 = [ 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', ] N10_19 = [ 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'sev...
stackexchange/codereview
Recently, I worked on one of the Codility Training - Genomic Range Query (please refer to one of the evaluation report for the detail of the task. The solution in Python is based on prefix sum, and was adjust in accordance to this article. import copy def solution(S, P, Q): length_s = len(S) length_q = len(Q) ...
stackexchange/codereview
This is a Google foobar question. The gist of it is that I have to find the shortest path from top left to bottom right in a 2d array of 1's and 0's, where I can only traverse on 0's. However, the twist is that I can change one 1 to a 0. My code works for the first three test cases, but it fails the final two (not sure...
stackexchange/codereview
Follow up to: Printing Command Line Unicode Chess Board A couple people from the previous question mentioned looking into coloring the command line with ANSI escape sequences. In Python, colorama seems to handle this quite nicely. Below is my attempt at using it for printing out a chess board. from enum import Enum f...
stackexchange/codereview
attributes is an array with all attributes selected by the user. attributeList is a Mongo collection declared in [root]/lib and contains all possible attributes. I'm using two loops in order to match attributes. For those that match, new fields "operator" and "value" are added and will be used in the template. Do you s...
stackexchange/codereview
I use bluebird promises. I want to promisify my requests from communication layer: Utils.js //Question: is there more beautiful way to do that? promisifyXMLHttpRequest(xhr, timeout = 0, timeoutCallback = _.noop, responseHandler = response => JSON.parse(response).data) { const requestPromise = new Promise((resolve, ...
stackexchange/codereview
This code will generate a pseudorandom alphanumeric string of given length. I would welcome suggestions on how to make it more random. Beyond that, have I made any convention violations, Exception cases, and the like? Also, is there any way to make it faster? public class Test { public static String getRandomAlphaN...
stackexchange/codereview
I am trying to create a script that shows my login modal on page load. I have a button that opens the register modal and closes the login modal if clicked. Here is the script I am using: $(document).ready(function(){ $('#loginmodal').modal('show') }); $(".hidelogopenreg").click( function() { $(...
stackexchange/codereview
I am using a global class (like a global model) that acts like a sql abstraction layer for my application. I am using it without problems now, but since the application I am creating is getting bigger, I would like this class to be reviewed if this is really a fine abstrraction layer. I cannot use a proper ORM or frame...
stackexchange/codereview
I'm new to Pandas, and slightly new to Python as well (but not development in general). I've got a chunk of code that works, but it feels like I'm missing out on the Pandas/Python way of doing something, and would love some feedback. In short, I'm doing calculations over a fixed period of time (say 60 months) where I a...
stackexchange/codereview
I need to parallelise a for loop that does quite a lot of processing over thousands of items. I came up with this basic loop that seems to work quite effectively on a small test. template<class T, class C> void parallel_for_each(std::vector<T>* ts, C callable, uint poolsize = (std::thread::hardware_concurrency()+1)*2) ...
stackexchange/codereview
I would like a fair minded critique of this code to get some feedback. I am not trying to re-invent the mold here, and I know there are plugins galore I could have used to do what I am doing here, but the point was to do it myself so that I can learn more and become better. I have included comments to try and best expl...
stackexchange/codereview
I have this Enum from which I am calling the appropriate execute method based on what type of enum (eventType) is passed. public enum EventType { EventA { @Override public Map<String, Map<String, String>> execute(Map<String, String> eventMapHolder) { if (eventMapHolder.isEmpty()) { return Immut...
stackexchange/codereview
I would like to achieve something I believe is pretty standard: A) My VB.NET client (ideally targetting Framework 4.0) sends a text string to my Apache/PHP Server via an HTTPS POST request. B) My Server responds with a Signature of that text string. Private key used by the Server is always the same, and public key used...
stackexchange/codereview
In the Startup.cs of my ASP.NET Core application I want to configure the LoggingFactory so that it logs into the database. Therefore I create following DBLoggerExtensions class to add a context: public static class DBLoggerExtensions { public static ILoggerFactory AddContext(this ILoggerFactory factory,Func<string,...
stackexchange/codereview
A simple game of TicTacToe. Please review for style and other. Is this a proper ViewModel? namespace TicTacToe3 { public partial class MainWindow : Window { private ViewModel viewModel; public MainWindow() { InitializeComponent(); viewModel = new ViewModel(); ...
stackexchange/codereview
I know how to write simple RSpec tests and unit tests. I just want to know if this is good enough or if there are any improvements I can make. I intend to test the the toggle_property method of the TaskItemUserReference model which updates the property, completed from false to true or vice versa. Relationships User has...
stackexchange/codereview
I'm very new to programming and I decided to start my journey with Python. It's my fifth day of learning and decided to try myself out and make a very simple slot machine. I was stuck for hours because I had issues with the balance counter but finally managed to make it work. Would you please rate it or give your opini...
stackexchange/codereview
The following scenario came out of a discussion I was having with a fellow developer on this project. He likes to execute an Ienumerable as soon as possible, hence why he’s doing it inside of the method. Whereas, I’m thinking that if you wait until the object is actually needed, using differed execution, you’re elimina...
stackexchange/codereview
After reading about the composite pattern from Design Patterns, I thought to re-implement the code mentioned in the motivation section using the modern C++ concept/idioms: #include<iostream> #include<vector> #include<string> #include<memory> #include<algorithm> /*****************************************/ template<typ...
stackexchange/codereview
The goal is to loop through an array of days-of-the-week (array values are stored as strings, eg: 'Mon, Tues, Weds', etc) and output some HTML when today's day is encountered. The file is a CMS's .tpl file, so the PHP sits directly alongside the HTML. My current, working code is: <?php $dayofweek = date('w'); forea...
stackexchange/codereview
I am doing this Project Euler Question #9: A Pythagorean triplet is a set of three natural numbers, \$a < b < c\$, for which, $$a^2 + b^2 = c^2$$ For example, \$3^2 + 4^2 = 9 + 16 = 25 = 5^2\$. There exists exactly one Pythagorean triplet for which \$a + b + c = > 1000\$. Find the product \$abc\$. I have implemente...
stackexchange/codereview
I have a Node project and am trying to make my code better, so I've created a new folder with a file like following which encapsulates the read and write file. This is working and my question is if it's good practice since I need to use the call to read and write file in several place in my code. var fs = require('fs')...
stackexchange/codereview
This is my solution to exercise 1.6 in Cracking the Coding Interview. I am interested in receiving feedback on the coding style and time/space complexity. The exercise statement is: Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa wou...
stackexchange/codereview
There are lots of shell programs that have /bin/sh as interpreter, yet use some features that are specific to bash or other popular shells. I have written a little program that detects these unportable features. It is not meant to compete with ShellCheck, its purpose is only to catch a few common mistakes. Since the pr...
stackexchange/codereview
I have a list of lists (many tokenised sentences). For anyone who doesn't know what tokenised sentences are, my list is like so: list1 = [['hello', 'my', 'name'], ['this', 'is', 'stack', 'exchange'], ... ] I have a list of key words as well, key_words. For every sentence in list, I want to check if it is in key_words...
stackexchange/codereview
I'm working on refactoring some existing code to be a bit more extensible and am wanting to create a generic factory API for starting D3 charts. Currently, my factory looks like this: import { select as d3Select } from 'd3'; const protoChart = { width: window.innerWidth, height: window.innerHeight, margin: { ...
stackexchange/codereview
I have a section of code I use to extract an event log out of a large text file. It works well, it's just my use of list(itertools.takewhile(...)) that feels a little sketchy to me. Is there a nicer way of doing this? import itertools testdata = ''' Lots of other lines... Really quite a few. ************* * Event Lo...
stackexchange/codereview
I know several there have been several posts about Tic Tac Toe games previously, nonetheless I was really hoping that you may take a look at my attempt. I have tried to keep it as modularized as possible to minimize side effects. I started teaching myself C only about a month ago, so any and all advice would be greatly...
stackexchange/codereview
The problem in simple words: I have three arrays of double values (x-, y- and z-coordinates) and need to find the index of the point which has minimum distance to a reference points. I do not need the actual value of this distance. If the minimum distance is not unique, any index where its value occurs may be returned....
stackexchange/codereview
I got some really good responses here last time, which really helped out quite a bit, so I thought I'd try again with a new batch. Below is the second phase of my first Java project: Intercommunication between panels. This builds upon the old code, though it has been heavily modified since the first version. Many of th...
stackexchange/codereview
I am new to ReactJS as a fun alternative to the old boring JS and for practicing I tried to make a sort of "tabby cat" app similar to the browser extension one (tabbycats.club) where you get a new random cat image/name/background color for every new tab or page reload. But I feel like my current code is quite messed up...
stackexchange/codereview
I would like a code review on the coding I did for my assignment. The reason I have asked here is because my lecturer has no intention of going through (Don't ask me why, I asked before and he said no..) and I have no idea if I am doing it right or not.. All my other classmates seems to have different answers too, some...
stackexchange/codereview
I'm having a dip into F# and am attempting not to write it like it's C#. One area that bothers me is using members of System.String. These often need to be chained together, but the only way to do so that I've seen so far is pretty much the same as C#. For example, I've written a function to generate the pretty bit at ...
stackexchange/codereview
I am using knockout in my project. I have some models like EmployeeModel, ServiceModel etc which user can update. On UI I give the user a Cancel control button by which he can revert the changes. On cancel I have to revert the model change back to its original state. For this I found these two good approaches by @rniem...
stackexchange/codereview
I am wanting to implement an AlertDialog with a list into my app and I created a sample to see if I can get the result that I am looking for. It seems I do have the result I wanted but before I implement it into my actual app, is there a way to make my code better?: activity_main.xml: <?xml version="1.0" encoding="utf-...
stackexchange/codereview
As a side toy project for my Genetic Algorithm, I decided to try to create a macro that lets you use maximize: ... subject to: ... linear problem notation to generate fitness functions. Those fitness functions can then be used in a genetic algorithm to solve linear problems through brute force. Yes, I'm aware genetic a...
stackexchange/codereview
For the implementation of the Playfair encryption I needed a custom struct called Cell. This is because I not only need an array of characters I also want to get Elements in a matrix based on their "cartesian" position. public struct Cell { public char character; public int X; public int Y;...
stackexchange/codereview
This is my first program with C# and VS and was originally a VBA Add-In I wrote. I have embarked on this as a learning exercise. The code does work and provides the desired output in a new workbook. The code below is called from a button on a custom ribbon created in Excel. It collects data from other workbooks w/o ope...
stackexchange/codereview
I have two variables that could be the same. In such a case I am assigning one of them to be undefined. Is this code the best way I can write it? let folderOwner = $("#change-folder-owner").val(); let folderUser = $("#user_name_alias").data('value'); folderOwner = (folderOwner === folderUser) ? undefined :...
stackexchange/codereview
I am having a trouble speeding up my implementation. The question is, given a range of numbers from long a to long b, find how many lucky numbers are between a and b inclusive. A number is a lucky number if it contains either 1 or 3. If it contains both 1 and 3, it is not a lucky number. Currently, I am iterating over ...
stackexchange/codereview
Not sure how subjective this question is however I am looking for a peer review and general feedback on the intuitiveness and scaffolding potential of a framework concept. I have a gist on GitHub here: node.js MVVM framework concept Is this more or less intuitive then using pseudo code and a template engine, such as ha...
stackexchange/codereview
My model is based on the Ultimatum Game. I won't go into the intuition behind it but generally speaking it functions as follows: The game consists of a n × n lattice on which an agent is placed at each node. During each time step, each player on each node plays against a random neighbour by playing a particular strate...
stackexchange/codereview
I would value your opinion on the following piece of code. I am rather new to both Python and Monte Carlo analysis, so I was wondering whether the routine makes sense to more experienced and knowledgeable users. import numpy as np import scipy.optimize from scipy.optimize import curve_fit from scipy.stats import kde d...
stackexchange/codereview
Here the task (in Indonesian). I think my binary search algorithm is correct. Ideone #include<bits/stdc++.h> using namespace std; vector<pair<string, string>> v; int awal1 = 1; string check(string s, int awal, int akhir){ int tengah = (awal+akhir)/2; bool temukan = false; if(v[tengah].first == s){ ...
stackexchange/codereview
I keep seeing /subsite/../global/css/file.css when I look at my website's source code, and today I decided that I want to get rid of the unnecessary traversal in the path itself, so it becomes /global/css/file.css. I made myself a function which I now use for all paths. Here is the base of my function that accomplishes...
stackexchange/codereview