instruction
stringlengths
71
71.9k
I created a really modular way of creating a feature-rich table, including filter input text, sortable columns by ascending and descending order, and the ability to order table rows onMount. This is my first big react endeavor some I'm interested in any and all feedback I can get. Here's the live example. Here's the br...
Can the following code snippet be optimized or am I doing it right? <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"> <mask id="a"> <circle cx="50" cy="50" r="50" fill="#fff"/> <rect x="50" width="5" height="100%"/> </mask> <rect width="100" height="100" fill="gray" mask="url(#a)" /> </svg> http://jsfi...
I didn't use multi-threading so far as I didn't need to. But as far as I've read, implementing them will make my program slightly faster than it actually is. from validate_email import validate_email import os # the program is reading each line from "emails.txt" and after it checks each email it will remove duplicates...
(See also Noughts and Crosses GUI game in Java - Part 2/2: GUI) I was working on a GUI game of Noughts and Crosses, and this is what I finally got: Unfortunately, the entire source code for the program does not fit in a single, so I have to try to split them in logical parts: this post is about Model and a little bit...
(See also Noughts and Crosses GUI game in Java - Part 1/2: AI) This part is dedicated to the View/Controller of the MVC pattern. So once again these are the building blocks of the Noughts and Crosses game: ConfigurationFrame.java: package net.coderodde.game.crosses; import java.awt.Color; import java.awt.GridLayout;...
I built a simple proxy using Meteor and its Iron Router. It currently fails at passing through other than 200 or 500 status codes, which I guess suffices. Is this proxy.js the best way to bypass CORS without modifying remote or Apache/Nginx server settings? "use strict" // call with "/proxy?url=" + encodeURIComponent(...
I have read a lot about serialization and I cannot figure out how I am able to serialize then deserialize multiple objects. I am very much a newb to Java, so please bear with me. My code currently works, but my logic is flawed. I have an object called "club", which contains several fields to be serialized e.g teamname....
So I've been writing a unit test using Rhino Mocks to a controller in my ASP MVC application. The test passes, but I'm interested in your opinion and if there's something I should be doing differently or what it could be. Here's my test method: [TestMethod] public void TestSlideView() { // Arrange ...
In this problem, you need to calculate someone's pay by multiplying their salary (double)by the hours (int) worked. If they worked for more than 8 hours, you pay them 1.5 times their salary for however many hours more they worked. Here is my solution. public static double pay(double a, int b) { if (b > 8) { return ...
The problem When you work with Python interactively (e.g. in an IPython shell or notebook) and run a computationally intensive operation like fitting a machine-learning model that is implemented in a native code, you cannot interrupt the operation since the native code does not return execution control to the Python in...
I'm writing a animate method to perform DOM animations. I know there are a lot of libraries out there that already does that (and I use some ideas of them) but I usually prefer writing my own code to pinpoint my problem. The code below is working perfectly, but something with the structure is making me uncomfortable. I...
I'm working on a project where I often want to turn class instances into dictionaries to write them to MongoDB. I'd like some feedback on the following: def getDict(self): self.dict = dict() for key in self.__dict__.keys(): if key not in self.NOT_INCLUDE: # class variable try: ...
This is my code for The Mysts of Aesthoth so far. I'd like to know if I'm following best practices, and what can be improved. /* ______________________________________ This Program was made by: Andrew Tew ______________________________________ */ #include <iostream> #include <string> using namespace std; int main() ...
I'm looking for tips on cleaning this up. I think it's legible, but it sure ain't pretty. In particular, I'd love to clean up the hitCheck function. I've dealt with switches before in other languages, so I was kind of stuck on trying simulating that. getReady looks messy to me, but I'm not sure how I'd go about tidying...
I saw this question, but was unable to answer because of my inexistant knowledge of Rust, so I decided to try and write an algorithm on my own and put it for review. There is the casual way to compute factorials: \$n! = \prod\limits_{k=1}^n k\$ public static BigInteger fact(BigInteger n) => n == 0 ? 1 : n*fact(n - 1);...
I'm creating an RPG type game, and now I am working on procedural town generation. The algorithm for that creates some roads going horizontally and vertically, and then attempts to place buildings in the open spaces. Once a building is successfully placed, I use this algorithm to iterate through the positions of the w...
This is the seconds version of an interpreter yesterday. It's supposed to be used for code golf, but it currently can't do much. import re, functools, time stack = [""] * 9 def run(file): f = open(file, 'r') code = f.read() f.close() parse(code) def prompt(): """Lets the user input commands and ...
Can somebody help me make the code below smarter and free of redundancy? The code does exactly what I want, but I believe there are many redundant loops and arrays. from collections import Counter import csv import re with open("/Users/max/train.csv", 'r') as file: reviews = list(csv.reader(file)) def get_texts(rev...
Here is the Euler problem referenced, it says: The decimal number, 585 = 1001001001\$_2\$ (binary), is palindromic in both bases. Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2. (Please note that the palindromic number, in either base, may not include leading zero...
What do you think about quality of code in this method? It should: Generate new key based on keys in array The key should start with "TG" Code should find the max number in array keys with "TG-" and increment this number It should have 7 digits No need to check what if there is a key TG9999999, and what if array is em...
This is the Save function on my PurchaseOrder model in my real world production system. This code needs to write the state of the model to the database schema. It's grown over time as things have been added, so I'd like to work it a bit cleaner. As you can see, it's gotten very messy and is hard to work with now. Do yo...
I need to create matrices that follow a specific format: the matrix is a square NxN matrix and the off-diagonals all have the same value (param) and the diagonals have values such that the rows sum to zero (in other words, they are equal to 0 - param * (N-1). The output is a numpy array Here is my code. Is there any wa...
So I have part of a library which deals with scopes in Google+ integration, and I'm curious on the overall view of it. Yes, things are stringly typed in one of the methods, that is because this has to be COMpatible, which does not support enum's. I have (purposefully) omitted XML documentation, as most people think I g...
I am trying to turn my code into a working library (my first). Currently you simply call GridNav() and it sets up and executes. I am currently refactoring out all the necessary variables. The trouble I am having is the animations property. I want users to be able to override the property. (function(window, document, $,...
This question is a spiritual successor to Console class that handles multiple buffers. I was mostly interested in implementing one of the suggestions of using an iterator range and fixing the interface for Terminal. That means most of the code will be absent. Also, while the code above is intended for a freestanding en...
Inspired by this question, I modified the script to run a simple simulation of Taylor-Green vortex using LBM and post-processes it using P5*js (an official Javascript port of the Processing API). Unfortunately, it is not performing well, but as I am new to Javascript programming, I lack the insight to really optimize t...
I've written a program to find the odds of either side winning a battle in Risk, and how many men they would have left. I've finished, but I feel that it can be improved since it doesn't function if the battle gets too big (with "too big" being ridiculously small, to the point of being near-useless). Can anybody find a...
After reading about Strand Sort on Wikipedia and testing the provided Python version, I decided to try my hand at a faster implementation. I've studied the "Time Complexity" page, read many different approaches to mergesort (and borrowed some), tested the code myself with profiler, line_profiler, and timeit, and I thin...
I am trying to give show a UI friendly dump of the cache status <h1>Cache Status</h1> <table class="tables dataTables"> <tr> <th>Cache</th> <th style="text-align : center;">Created Time</th> <th style="text-align : center;">Last Updated</th> <th style="text-align : center;">Last Hit</th> <th style="text-alig...
A more proper version of this utility can be found at the following link here: Giveth me thy easier user input in C++ - follow up. I've always been a little bothered by the fact, that in order to get user input in C++, one had to use up to three lines of code in an ugly manner like the below to get user input for a sp...
I have two lists of Strings and two lists of objects. I need to copy the list of strings to the correspondence list of objects with specific values. public List<Name> retrieveCitiesAndCountries(){ List<String> list1 = new ArrayList<String>(); //list of cities List<String> list2 = new ArrayList<String>(); //list of ...
I don't know what is the common name for this data structure I named it like this due to a definition in wikipedia that states the following: In a 'multiply linked list', each node contains two or more link fields, each field being used to connect the same set of data records in a different order (e.g., by name, ...
I came across a question at the Udacity Intro to Computer Science course: Define a procedure, find_last, that takes as input two strings, a search string and a target string, and returns the last position in the search string where the target string appears, or -1 if there are no occurrences. Example: find_last('aaaa...
I created functions to read bit data from arbitrary bit position of a char array to long long int, and I also created a function to write data to a char array from vector bool. However, I do not really like my implementation since I think it has a burdensome implementation when reading and writing bits. Can anyone see ...
I asked this question first on StackOverflow but I didn't get an answer and was advised to try here too. So here we go. I have implemented Kadane's algorithm for a 2D array in Python 2 with known boundaries, but I'm using the implementation for an online contest and the time it takes is more than the time given. So tha...
Genetic drift — along with natural selection, mutation, and migration — is one of the basic mechanisms of evolution. In each generation, some individuals may, just by chance, leave behind a few more descendents (and genes, of course!) than other individuals. The genes of the next generation will be the genes of the "l...
I am using the universal selector in CSS: #containerDiv.containerTable tr td * { max-width:240px; } But Visual Studio suggests: "Performance: Never use the universal selector. It has a big negative impact on browser rendering" Will this have such a big impact? If so how can I overcome this? I have used * before an...
This is a follow-up to System backup on Linux. I've done a lot to my script since I asked my first question and I think I could improve a lot while doing this. The script still does the same, only a bit neater and cleaner. So let me explain what I changed, and sometimes why I've changed it. At first I changed all the ...
I'm new to F#, so I've ported an old Python script I have to F#. It scans a directory for files named something like Game.Of.Thrones.S01E02.xvidblahblah.mp4 or The_Wire_s03e04.somethingelse.avi, and renames them to a nice form like TheWire_s03e04_Hamsterdam.avi (where Hamsterdam is the episode's title, found from a web...
I'll be honest this isn't all my code, I have made some tweaks to bring it more up to date. The main goal is to do some browser detection and add classes to whichever element we want. I am simply looking for your input regarding the code. // Detect browser and add appropriate classes to calling element, typically 'html...
I am very new to matrix math. I have the following that sets the rotation in a 4x4 matrix. It is pretty ugly, so can anyone suggest how I could clean this up? I would like to not have to call MultiplyTwoMatrixes twice. A better way of copying the 3x3 matrix into the end 4x4 matrix would be nice as well. void MultiplyTw...
I wrote the following code to get the translated string from Resource Manager. The method GetTranslatedString is called more than 50 times in my project. public static string GetTranslatedString(string input, string culture) { if (string.IsNullOrEmpty(input)) return input; string retInput = input;...
I have two datasets: A list containing about 4200 string elements A list containing about 119,000 string elements I'm taking each element from list 1 and looping through each element in list 2 using the jaro-winkler algorithm to find a "good" match based on a desired confidence threshold. I know that this process wil...
Given an array of numbers I've to write a function to return the string "Arithmetic" if the sequence follows an arithmetic pattern or return "Geometric" if it follows a geometric pattern. If the sequence doesn't follow either pattern return "neither arithmetic and geometric". I'm a beginner and I thought of following s...
My first real program in python, so probably needs a lot of work. I've been taking a class and it's really slow and I was self taught most over past 2 weeks. Anything I should do differently? #Programmer: Delirious Mistakes #Date: October 7, 2015 #File: Advanced Shape Calculator V1 #This file will calculate the measu...
Following this post and this other post here we are with another review request. The code that follows contains the definition of logic gates (binary gates like the AND, OR gate, and unary gates like NOT). They are a part of an open-source application I have started to build. I'm following the Observer pattern to build...
I want to make class to retry doing what I want if specific exception happen for n times before throwing exception, so I write below class and used Builder to build it could you please review it and update me with your feedback: public class Retry implements Runnable { private final long sleep; private final Runnable r...
I've been toying around with Unity 5 lately, and in an effort to start making an actual game, I've built a ball controller similar to the one found in the Unity tutorial Roll-a-ball. In essence, the player controls a small ball that rolls around a "level". The ball can accelerate at a rate in the range \$1\rightarrow10...
I am trying to improve the performance of my scraper and plug up any possible security leaks (identifying information being revealed). Ideally, I would like to achieve a performance of 10 pages per second. What would I need to do to achieve the biggest performance boost besides get a faster connection / dedicated serv...
I'm multiplying 4x4 matrices for learning purposes. How can I optimize this for performance? HTML <table class="matrex-1"> <tr><td class="0-0">-1</td><td class="1-0">0</td><td class="2-0">-1</td><td class="3-0">0</td></tr> <tr><td class="0-1">8</td><td class="1-1">-9</td><td class="2-1">8</td><td class="3-1">-9...
I wrote a little function to create a sorted-map with vectors of coordinates as keys and an empty map as a default value: (defn empty-board [rows cols] (into (sorted-map) (for [x (range cols) y (range rows)] [[x y] {}]))) Is there is a more idiomatic way of achieving this?
I need to make a matrix (in the form of a numpy array) by taking a list of parameters of length N and returning an array of dimensions N+1 x N+1 where the off-diagonals are symmetric and each triangle is made up of the values given. The diagonals are equal to 0 - the row sum of the off-diagonals. I don't really like ha...
I'm just starting to learn CoffeeScript and am trying to work through simple examples, this one being Prim's algorithm. I'd like feedback on everything but especially on making this script take advantage of the features of CoffeeScript most effectively. nodes_dir = { 0 : [1], 1 : [0, 2, 3, 5], 2 : [1, 4], 3 : [1, 4, 5]...
So I am a newbie obviously, This was part of a small assignment I had to do for Uni, and it works alright. It just reads a number from the console and then outputs the Greek letter Φ (sort of). Sure it could use some outofbound exceptions etc, but my question is this: My code overall (not just in this example) seems a ...
I have an array of this fashion: var arr = ["akira",9248,"padilla",100]; I'm using filter to take the names and the points: var names = arr.filter(function(e,i){return i%2 == 0}); var points = arr.filter(function(e,i){return i%2 !== 0}); Then I do this to obtain turn it into object: console.log(JSON.stringify(_.objec...
I implemented Project Euler problem 40 in Java. It works correctly, producing the correct answer. During the course of implementing this program, I wrote a method that directly calculates a digit of Champernowne's constant, as opposed to the obvious brute-force approach. While brute-force is fast, this method takes und...
This is the first couple lines of my new (will be) 8-bit co-op horror game. This is just the code for the first player text-based adventure storyline for the console game. Please critique. //Andrew Tew /* First EVER Co-Op Horror Game! */ #include <iostream> #include <string> using namespace std; int main() { //Decla...
Attack-Rooks is a challenge proposed by ACM-ICPC as a variant of the N-Queens problem, using Rooks instead of Queens. Of course, to disallow the trivial "fill the diagonal" solution, pawns are used to block the rooks from capturing each other. Given a NxN (N > 0) chess board containing some pawns, output the highest p...
The problem is to find out the squares between two numbers, inclusive of the numbers. The two numbers are in the range between 1 and 109. long numberOne = in.nextLong(); long numberTwo = in.nextLong(); int count=0; for(long j=numberOne;j<=numberTwo;j++){ double numSqu...
This appears to work. Are there any edge cases I am missing? What are your thoughts on the algorithm and implementation? template <typename el> void Linkedlist<el>::reverse() { Node<el> * oldHead = head; Node<el> * tailAfterReversal = recReverseList( head->getNextNode() ); oldHead->setNextNode(NULL); ta...
My program gets some input values and outputs Fibonacci values. Generally, I'm adding single numbers from the right to left, and I'm saving it in the sum value and get rest of it and add to string. (The value of "second" will always be larger than "first"). Is there some way to speed up my code? #include <iostream> #in...
I have implemented the Stack using two Queues q1 and q2 respectively as shown below in the code. I would like to get you reviews on whether it's an efficient way of implementing it or now. For Pop operation : I will keep on removing elements from the Queue q1 and adding it to Queue 2 until only one element remains in ...
In this code, I am creating a COM object to programatically access internet explorer. In order to access this object's properties and methods, I am writing wrapper functions like navigate or setVisible. Is there a cleaner or easier way to use COM objects from C? Moreover, can you point out things that I could have done...
I have this slightly popular Swift library called IJReachability up on Github. It checks the network connection status. Due to my office workload I've been very busy in the past few months so I couldn't attend to the project and keep in touch with the folks who are contributing. Now I'm back and hoping to dust off the ...
How efficient is this program? How could I make it more efficient? package main; import java.math.BigInteger; public class Ackermann { public static void main(String[] args) { System.out.println(ack(BigInteger.valueOf(4),BigInteger.valueOf(2))); } public static BigInteger ack(BigInteger a, BigI...
I designed this file after learning from this awesome answer from user2407038 on Stack Overflow. The idea of the module is to replace code like: test0 = print $ foldr (+) 0 [0..100] test1 = print $ foldr (:) [] (sequence [[0..10],[0..10]]) test2 = mapM_ print $ do j <- [0..10] i <- [0..10] return (i,j) Whi...
I'm newbie in Python and I wrote a tool called Caesar Encryption Tool. At the moment it only encrypts. It takes a plain text and a key from the user then encrypts the plain text using the key. How can this code be improved? # This is version 1.0 Caesar Encryption Tool and it will be improved. # This tool is written by ...
How could I optimize this binary search tree? #include<stdio.h> #include<stdlib.h> struct NODE { int info; struct NODE *right; struct NODE *left; struct NODE *parent; }; typedef struct NODE node; node *createnode(node *temp,int number) { temp=(node*)malloc(sizeof(node)); temp->info=number; ...
I am new to object oriented design with JavaScript and am trying to make a PublicGame class with some methods that puts itself in a map of games. It calls killGame on itself if there aren't enough players. I feel like my design is way off. I won't be able to test my design though until the rest of my group members fini...
I'm starting just now with CoffeeScript and I found out that I can't solve problems like looping and recursives with just one line. I would like to improve the code that I just wrote using built-in CoffeeScript helpers. 'use strict' file_system = require 'fs' Types = require './types' Extract = each_file: (in...
The goal of the following code is to be able to use an Xbox Controller in a Java program, it works with the jinput library. Unfortunately this library is rather old, has little to no documentation and uses a polling system. There are some existing event-based (xbox) controller input systems, but most of them are embedd...
Why Codility detects my solution for Tape Equilibrium to have complexity of \$O(n^2)\$. How can I make my code better? import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.IntStream; class Solution { public int solution(int[] A) { ...
One of the tasks I find myself doing repeatedly is to filter the incoming inputs that will be stored in models. Examples of this include trimming, removing repeated or unnecessary pre/suffixes, commas or dashes in numbers, etc. This is similar to validation, but Laravel's built-in Validator does not appear to have this...
The original question Given two binary trees, return true if they are structurally identical, and false otherwise. Are AVL trees equal? Are AVL trees equal? - revision 2 This revision on GitHub In this revision: equals() is documented. Two trees are equal if they are structurally identical. AvlTree has a type para...
These two classes are part of a networking layer module that I am building: public abstract class BaseRequest { protected RequestCreator mCreator; public BaseRequest() { setupRequestCreator(); } private setupRequestCreator() { mCreator = new RequestCreator.Builder() .heade...
I have been lately working in my C++, and I finished up this trie, and I want to know how my C++ is looking so far. Node.hpp #pragma once #include <memory> static const int ALPHABETSIZE = 26; struct Node { bool isEnd; int prefixCount; std::shared_ptr<Node> child[ALPHABETSIZE]; }; Trie.hpp #pragma once ...
This code is used to deep overlay saved state (as an object) over a template object, which is the current model, this model can change (e.g have new attributes added), and a simple _.clone call will not cut it since that does a shallow copy, and will copy nested arrays/objects byref. This code works, and I'm curious if...
I was recently working on a game using the SFML library, Later on, I experienced performance issues due to collision detection. I have been told to use a QuadTree structure to optimize the collision detection. I have implemented the basic of the QuadTree functionality and it seems work fine in my game. The full project...
I recently found my first program I wrote using Logo and was wondering if it could have been improved: to gnome repeat 180 [bk 1 rt 1] repeat 180 [bk 1 rt 1/4] rt 97 repeat 180 [bk 1 rt 1/4] pu lt 90 fd 50 lt 90 fd 25 rt 90 pd repeat 90 [fd 1/2 rt 1/4] repeat 180 [bk 1/2 lt 1/4] pu rt 60 fd 50 pd ...
Recently, I added this 'batch' based rendering system in my game engine, which takes care of rendering Spatials (those are actually wrappers for a mesh and a transform) by giving it an environment parameter (taking care of uniform values, like light, fog, environmentMaps, ...). I would like to ask your advice on how I...
I need help with optimizing a piece of code I've written in C#, which is very sloppy right now. I needed to write code that tracks the amount of money a hospital has made at the end of the day, depending on the amount of patients. Here are some conditions and details: Code has to display the cost for the patient and t...
I really want to have a nice design pattern for my Node.js project. This is my state diagram. As I'm coding this, I'm wondering if it's better to separate state logic from the class? So instead I would only have my class be responsible for initial construction and then emitting state changes which get handled elsewhere...
I am a semi-beginner in C++ and I have a project in C++ to convert a hexadecimal integer into decimal equivalent, but I extended it and now this program can also convert a fractional part. Logic I have used: First the whole program is inside a do-while loop so that the user can convert a number as many time as desired...
I have the following simple program which calculates and returns the nearest power of 2 of a given number. Because I use increments and decrements to find the closest power, this takes a very long time when working with higher numbers. Is there any way to reduce the run time of the program when working with larger numb...
I wrote the following code for Slick Slider, which changes the content below based on the current slide data-index. I just wonder if there is a more efficient way to do it? http://codepen.io/pjmtokyo/pen/JYyjew $('.slider').on('afterChange', function(event, slick, currentSlide, nextSlide){ var elSlide = $(slick.$s...
Project Euler Problem #4: Largest palindrome product: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. I got the correct answer for the problem, but I want...
What is the best way to conditionally use an operator? All 3 methods seemed acceptable to me, and the last 2 better. If you're curious: I've got a list which is unsorted, and many other lists which may or may not contain a smaller selection of sorted indices referencing the unsorted list. Processed data is being ident...
Problem: Find a multiple of a given decimal number \$N\$ that looks like a binary number. The input will consist of at most \$ 2 \times 10^5 \$ lines, each line consist of an integer \$N\$ (\$0 \lt N \lt 10^{12} \$). Find its described multiple \$M (\ne 0\$), this number \$M\$ must be less than \$10^{12}\$. If there is...
This is my implentation of Bucket Sort, but I see myself using way too many for loops, is this necessary? public static void bucketSort(Student[] students) { final String[] courses = { "IB", "IG", "IN", "IS", "IT" }; final int amountOfBuckets = courses.length; final int n = students.length; if (n == ...
Given two input directed graphs \$G_1 = (V_1, A_1)\$ and \$G_2 = (V_2, A_2)\$, the problem of isomorphism asks whether the two directed graphs are isomorphic, or in other words, whether the two input graphs have precisely the same structure. Formally, two input graphs \$G_1\$ and \$G_2\$ are isomorphic if and only if t...
1. Description 1.1. Functionality The objective of these types is to provide type erasure for any function while maintaining the ability to provide a return value through a combination of std::promise<T> and its associated std::future<T>. 1.2. Motivation This is useful for any sort of dispatch manager, a thread pool th...
When reviewing questions here on Code Review SE, I sometimes find my self wanting to test different functions in order to do a performance review. However since I'm inherently lazy, I wonder what is the most effective or best practice for doing timing of functions in Python? To make this an apt question for Code Review...
For my planned Sudoku with Handicap challenge over at codegolf.SE, I need a driver program. I've decided to write it in Python, for learning purposes. Since I've got no Python experience, I thought I put it here to see whether it can be improved. The code is intended to implement the rules as written in the the linked ...
I'm following a YouTube video and am wondering if there are any other efficient ways of doing this. Is it possible to do it with an interface too? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Learning { class Program { sta...
For quite a while now I've been writing a bit of Ruby code, but so far I still don't think it was good idiomatic Ruby. But there's been a new requirement and I tried my best writing it better, more cleanly compared to my previous code. One of the things I did is read another code base that I though was well written (ca...
I'm reading through the chapter on inheritance from C++ Primer 5th Edition. It asks Organize the following type into an inheritance hierarchy: (b) Geometric primitives (such as box, circle, sphere, cone) Identify some of the likely virtual functions as well as public and protected members. I was hoping this is a suit...
I would like to concatenate a series of strings populated from an XHR response. So, I've chosen to do it like this: $.post('/API',null,'json') .done(function(response){ if (response.status === 'success') { location = response.data.city + ', ' + response.data.state; } }) .fail(fu...
Can this Python code be written in a more Pythonic way? ''' This scripts ask a user for the capital city of Peru, South America ''' question = 'What is the capital city of Peru?' answer = 'Lima' # Ask question print question # Game continues as long as question is not answered # Game ends after 3 failed attempts end...
I am studying the merge sort algorithm and implemented it. In the mergeSort function, I am allocating two new vectors. Can I do it without allocating extra memory? Are there any other suggestions? #ifndef MERGE_SORT #define MERGE_SORT #include <vector> template<typename T> void merge(std::vector<T>& array, std::vecto...
I'm pretty new to the world of lock-free programming and would love some feedback on this code. I have been testing the queue with multiple producers and consumers, and with no unexpected output (yet). Is there anything I could have missed or should improve? template <typename Type, std::size_t Capacity = 100> struct c...