This is my first code using templates and I wanted to know if the code looks good?
I have some doubts like what's the best way to report error to user (queue full/empty), I checked a link online http://www.cprogramming.com/tutorial/computersciencetheory/queuecode.html
where they use assert() so ...
Although there is a blinking LED, the way this comes about is quite a bit different. This could be called a dead man's switch because as long as your holding the button down, the blinking doesn't start until the button is released. It is connected as follows;
/*
Blink 2017-Mar-26 by Peter ...
I have recently coded my own authentication system and wondered if there was any way I could make it better? I coded it with Laravel 5.4. getView is called on Route::get and onPost is called on Route::post
use Auth;
use App\User;
use App\Http\Controllers\Controller;
use Validator;
use Redir...
I have originally written the following Matlab code to find intersection between a set of Axes Aligned Bounding Boxes (AABB) and space partitions (here 8 partitions). I believe it is readable by itself, moreover, I have added some comments for even more clarity.
function [A,B] = AABBPart(bbx,it)...
I'm trying to make minesweeper similar to windows 3.1 minesweeper by using OpenGL / GLUT. The game still in early stage but playable. I would like to know, how can I improve it.
#include <cstdlib>
#include <gl/glut.h>
#include <ctime>
enum { MINE = 9 };
enum { TILE_SIZE = 20 };
enum { BOARD_SIZ...
This is too broad, and it really isn't on-topic here. What you're asking for is basically code review. So, you might consider asking about it on Code Review, but not in its current form. You would need to be more precise and ask a specific question about a specific concern. Right now, this is a lot like asking, "What are best practices for web app development? Is mine good?" That's just much too broad. — Ed Cottrell ♦26 secs ago
I've been working on a CSV parser as of late, which you can find the source code for here. Recently I've decided to add an iterator to it, following along with the template here: Preparation for std::iterator being deprecated.
However, I've never written an iterator, and I feel like I'm not doin...
This answer on Stack Overflow includes an implementation for a Java BlockingQueue with unique elements:
/**
* Linked blocking queue with {@link #add(Object)} method, which adds only element, that is not already in the queue.
*/
public class SetBlockingQueue<T> extends LinkedBlockingQueue<T> {
...
The problem my code solves is listed below. I know my code can be improved, it takes a while to run when bigger arrays are entered as input.
"Problem - Given an array of integers, sum consecutive even numbers and consecutive odd numbers. Repeat the process while it can be done and return the len...
Please help me to review my site [originvietnam.com][1]
[1]: https://originvietnam.com/halong-bay-cruises/ - is it good code for search engine? any recommendation? thanks
The task is: Given an array A of size N, find all combinations of four elements in the array whose sum is equal to a given value K.
The specific requirements are:
The combinations must be distinct
Each quadruple is separated by a delimiter "$", and must be printed in ascending order
Here ar...
Here are two very small blocks of code I wrote while trying to fix a bug in AngularJS. Both do the same thing. I'm trying to understand how the two differ, mainly in terms of the tradeoff between cpu and memory efficiency.
Here is version 1:
function findSearch(url) {
var index = url.indexOf(...
My Code is working as needed, however I want this to be review on the basis of optimization and runtime.
import operator
import functools
def string_color(string):
if len(string) > 2:
a = [ord(i) for i in list(string)]
return padhexa(hex(sum(a)%256))[8:].upper()+padhexa(hex(f...
This is my solution to Google Code Jam 2008 round 1C problem B. I think it's very elegant. However, I wonder if it's too concise. What could I improve here?
Code:
from functools import lru_cache
M = 2*3*5*7
uglies = list(filter(lambda n: (int(n)%2 == 0 or
int(n)...
Im new to swift and this has me stumped... Im not understanding why my for loop is not adding the objects into the mutable array.
thanks for your help!
`class someClass: UITableViewController {
var items = NSMutableArray()
override func viewDidLoad() {
super.viewDidLoad()
SDK.sharedI...
I have a project and I got an advice to use promises to make actions called one after another when it needed (in my project I call 2 actions to add a new todo (1) and to clear text (2) in input above todo's list).
However I am not completely shure if I need the redux-thunk and don't understand ho...
I want to avoid using multiple if and else condition here
if (decode) {
Imagepath = bucket + "/" + key;
Result.pages.push({
Id: Processid,
ValidTicket: decode ? true : false
...
I often make changes on my code-base and manually using sed, awk or perl -pi -e is not always as efficient as having a simple alias: git pie.
Furthermore, because I am working on Cygwin, I cannot do real in-place replacement without a temporary file that I have to manually suppress afterwards. ...
I made a simple calendar in PHP 7.0, could anyone help with simplification? Any advice appreciated. It works, but I totally believe it can be improved. I am a beginner.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$chosen_year = filt...
The task was to write function that compare areas of two random generated geometric shapes (circle, square, rectangle) using base class with virtual function.
Am I doing it right in terms of memory menagment? Will my figures generated inside generateRandomShape() by new Square() etc. last in mem...
I recently got an invite for the Google Foo bar Challenge, it was nice all the way when I started the Level 1 challenge, and now am in Level 2 (Stage 2) when I got stuck with the mysterious Test 5 case failure
Here is the challenge:
Numbers Station Coded Messages
When you went undercove...
Hello again, thank you for your reply. I have been playing with the code according to your recommendations but am still unclear. I have reinstated this question on stack exchange so could you please kindly respond on there as you would have originally had this not been closed? codereview.stackexchange.com/questions/158876/… — ShaunHill52 secs ago
Here is a program I wrote in C to generate HTML5 from a plain-text file.
(If you’re thinking this sort of task would be better done in Python, I
agree, but I wanted to brush up on my C, so here we are.)
I’m looking for feedback on correctness; readability and
maintainability; under- or over-comm...
I've been tasked with creating a workshop for new programmers. As part of this, I want to set them a few puzzles.
What I need is something simple/short(ish) for them to figure out - 'what does this code do'? This will probably be written in Pseudo Code.
The next step will be for them to refact...
If someone could help me resolve it(if it was bad), that would be good too :)
This is the problem:
Airport
Pretend we are operating a small airport with a single runway. We need to develop a data structure to help scheduling airplanes to take off and land from this runway. Each time a plane ...
@Dave the fact that you can write an answer does not necessarily make it a good question. The initial phrasing was among the lines of "How can this code be improved?". Ignoring the compiler errors, that's opinion-based as there were no hard requirements (performance, terseness, reusability) and thus not even a good fit for Code Review. Then there's the problem that there are an infinite number of ways this code can ben fixed, making it too broad. In the end it's off-topic because no Minimal, Complete, and Verifiable example with accurate problem description was given. Nobody is helpen by a "fixed it for you" code dump. — CodeCaster20 secs ago
The task - invoke code written on c++ in another process to prevent memory JVM crashing in case if c++ library will corrupt memory.
@RestController
public class MyRestController {
@RequestMapping(path = "some/path", method = RequestMethod.POST)
public StubObject get(@RequestBody StubObje...
This Python function takes two arguments:
chr_list which is a mutable sequence of characters c
chr_counts which maps to each character c the number of occurrences n
For each character in chr_list, it inserts this character into the list before its last occurrence n-1 times. The resulting list...
I am having below code which get and set the data in the cache using the synchronized block and i want to know if i can optimize the below code :-
AtomicReferenceTest<Integer> cachedIntRef = new AtomicReference<Integer>();
boolean wasCached = true;
Integer cachedInt = cachedIntRe...
Introduction
I want to develop this project for more than two years. I just started do it couple days ago. I used for detect plant or residue pixels in crop row image but it provides a good example how to detect green and red color which at that time I can not found it on Stackoverflow/Stackexch...
"The solutions I did try to implement I could get compiling correctly, I am still very inexperienced with haskell and would appreciate an explanation on how to create a higher order function using my parameters." That sounds like you want your solution reviewed. For a review, head over to Code Review. — Zeta39 secs ago
for learning purpose of the language python, i have implemented a function that creates a k-d-Tree from a list of 2-d Points. I would like to refer to this question where i asked about the k-d-Tree in c k-d-Tree in c. However the python code takes about 14seconds for 1million points. So my questi...
I always make my string fields multiples of 2, i.e.
[StringLength(32)]
Does this matter at all for performance, or will a string length/varchar size of 33 perform equivalently?
By performance I mean data access times, database storage size, compiled code running on server... anything else I'm ...
So I've written up what the title says.
Obviously, I'm looking for speed, safety and ease of use. To achieve the perfect ratio I've made some functions straight away crash if the input is wrong (in debug mode only, otherwise UD). The design is inspired by the C++ counterpart.
Will be glad to ...
I'm bundling my css in my app as follows
bundles.Add(new StyleBundle("~/MyApp /Content/css")
.Include("~/MyApp/Content/css/vendors.css", new CssRewriteUrlTransform())
.Include("~/MyApp/Content/css/base.css", new CssRewriteUrlTransform())
...
Please help me in this requirement.
I have input.csv file with below details,
Name,ID,DOB,age
How do I move the columns Name,ID,age to another csv called output.csv.
Thanks in advance!!
I asked a similar question yesterday and got a brilliant answer, but unsure how I could adapt these methods.
The methods perform a BFS on a state and then store the values in a multi-dimensional array.
You can see that the code is repeating itself, just with different array dimensions.
Method ...
I always disliked how basic html tooltips are and often find myself employing modals to display more information, but it feels like the wrong solution from a UX perspective in most cases.
To that end, I have put together the following solution.
Due to the self-taught nature of my work, I fully ...
In a course I'm doing, I was given the task of finding the closest pair of points among the given 𝑛 points. The program that passed all test cases was the following:
import math
if __name__ == '__main__':
n = int(input())
P = []
for i in range(n):
line = input().split()
...
I've posted my simple ciphers on Code Review several days ago (link: here). I refactored my code and tried to define a more general "cipher" function, according to Zeta's excellent advice. I've split the code to make it more readable.
General cipher
This function takes an encoding function, "ze...
class WrapperForSomething {
auto somethingBeingWrapped;
void foo() {
// some data preparations
return somethingBeingWrapped.foo(); // this line - with or w/o return?
}
}
Assuming we cannot inherit from somethingBeingWrapped. I'm talking here only about cases where our metho...
Stack Overflow is for solving problems with code - not taking completed code and asking for it to be improved. Your question might be on topic at Code Review but make sure you read their rules before posting. — mason17 secs ago
Yes load the value into an array cycle through the array adding the values to that array or a different array then assign the values back to the range. If you want more specificity post your working code and request on codereview.stackexchange.com where this question belongs. — Scott Craner36 secs ago
Okay, here we go again :D (stackoverflow.com/questions/43050747/where-is-a-limit-of-overdesign?noredirect=1#comment73187856_43050747)
So a while back i started working on "LimitlessUI" - library for winforms(github.com/WithoutCaps/LimitlessUI). And one of the items that i created was "material s...
https://repl.it/Gg7g
There is the first part of the code, the problem is it only gives me the largest prime factor, I also need the smallest prime factor. Can someone give me some advice on how to do this? Or provide me with code that does this? I am just starting out so I might not understand y...
After reading InfernoJS docs (createRenderer), I wanted to reproduce the same behavior with a use case.
Statement:
By using functional programming, render a list of Books with a react-like framework.
My code:
function getBooks(page: number = 1) {
const books$ = rxrest.all<Book>('books'...
This question is an elaboration of my question. Just like the previous implementation, all operations (except clear) run in exact or amortized constant time.
I have taken into account all points made by @Emily L., and my data structure looks like this:
StatisticsNumberSet.java
package net.code...
I would like to write a pseudo version of a parallel List.map with the help of Event and Thread module.
open Thread
open Event
let rec tmap f ls =
let c = new_channel () in match ls with
| [] -> []
| h::t -> let _ = create (fun c -> sync (send c (f h :: tmap f t))) c in
...
I am using Matlab and heres what I am trying to do.
I'm building a matrix representing 5 point stencil Laplacie equation from a fonction f (Ai) (Or something). This part is done and probably work. Then I need to take this matrix Ai and transform it into a matrix (Af) which work when I resolve it...
The question asks to
Write a program tail that prints the last n lines of its input. By default, n is 10, let us say, but it can be changed by an optional arguement, so that
tail -n
prints the last n lines
Now, my program takes an optional arguement n at the command line, asks for...
Q: An nn matrix contains numbers from 1 to nn and is generated in the
fashion:
The first row is of numbers starting from 1 to n left to right, Second row is from n+1 to 2n right to left, 3rd row is from 2n+1 to 3n left to right and so on.
Example n = 4
Matrix would look somet...
I am new to C# and am leaning ASP.NET MVC and Entity Framework and I am trying to create an application where a user can manager Job Postings and Applicants where an Applicant can apply for many Jobs.
I am trying to pull a list of Applicants, along with a list of the Jobs they have applied for.
...
I'm writing a composer package that allows you to validate your data in easy and cleaner way,
I'm trying my best to follow the best design practices while working on this package.
Now i want you guys to review the code an tell me what I'm doing wrong and how it can be written in a better way.
...
This is my third attempt to create a easy to use html builder because I wasn't really satisfied with the first one that wasn't extendable at all and even the one using dynamics wasn't much better. It was difficult to use due to everything being dynamic and had to be casted everywhere but what's w...
@JesperJuhl especially in a case like factorial where one would expect the next iteration to build on the previous. While everything is safe and syntactically correct (excluding operator <<), the lack of synchronization should raise alarm bells that the algorithm is not quite right. Mind you I do remember seeing a lock-less multithreaded factorial on Code Review once. I'll post a link if I can find it again. — user458130123 secs ago
Long time coder, but very very new to C++. Basically trying to put together my first real-sized C++ project and running into some questions on how exactly I should structure things.
At first I had this file with a couple of util functions:
#include <math.h>
#include <vector>
#include <iostream>...
One obvious bug: what if len(self.ls) < self.val (e.g. it is empty) when get_list is called? In general, questions asking for review of working code belong on Code Review; once you've fixed the issue I mention, maybe ask there? — jonrsharpe22 secs ago
Yeah then you'd get an error, thanks for pointing that out. + thanks for letting me know about Code Review - i had no idea it existed. — Jaff54 secs ago
var datesArray = Array<Dictionary<String,Any>>()
//datesArray is from array of months and every month have dates
func tableView(_ tableView: UITableView, cellForRowAt indexPath:IndexPath) -> UITableViewCell {
let date = datesArray[indexPath.row]
if let cell = tableView.dequeue...
Here is my solution for the following task: Given an integer n, print the minimum number of operations needed to obtain the number n starting from the number 1, and the sequence of numbers towards the number n. The allowed operations are: multiply by 2; multiply by 3; add 1:
def min_operations(x...
I am currently working through a python course about objected oriented programming. I was given this first assignment to work on:
Create a simple class, MaxSizeList, that acts a little bit like a
list, with a pre-configured limit on its size.
Here some test calling code that imports ...
Execution restricted to one core for portability. Average time (without printBoard()) on Intel(R) Celeron(R) CPU N2840 of 100 runs:
GCC 5.4.0 with -O3: 0.48885504s
Clang 3.8.0 with -O3: 0.52578794s
My ideas for further optimization were board reflection and rotation, but I don't know how to i...
Background:
I've written a Twitter bot, @answering_yelp, which responds to another Twitter bot, @hard_to_yelp. They scrape yelp reviews for sentences which start "How hard is it to..." and my bot answer with some version of how hard it is.
I recently refactored the code to handle changes to the...
Long time coder, but very very new to C++. I'm trying to put together my first real-sized project and figuring out what I need to change about my script-kiddie style of C++ to get there. Below is my working code.
#include <math.h>
#include <vector>
#include <iostream>
#include <stdexcept>
enum ...
May I suggest to post it to [Code Review]? — Zich55 secs ago
I did read it. And it looks very much like a code review kind of post. I don't see where you have a specific error you are trying to resolve or something isn't working as you intended it to. Is there a feature in the Github API you are missing? Perhaps. Its up to you to read through that. — Ju66ernaut29 secs ago
I'm writing a pixel library to do an AJAX request. So, I'm not allowed to use any helper.
function ajax(options) {
var xhr = new XMLHttpRequest();
var opts = Object.assign({
withCredentials: false,
method: 'GET'
}, options);
xhr.withCredentials = options.withCredentials;
xhr....
I'm implementing alpha-beta pruning for a chess engine in TypeScript
Here's the code:
public static alphabetta(board: Board, player: Player = Player.CPU, move?: Move, depth: number = 0,
α: number = -Infinity, β: number = +Infinity): EvaluatedMove {
const { gameOver, winner } = board;
...
I'm currently writing a little tool to get into Go.
As I'm not familiar with the language I'm especially looking for
Conventional go stuff.
utility.go feels wrong.Should I wrap the client and email/password into a struct in utility? What would you advice.
Every critic on any thing is very we...
Troubleshooting systems need to identify the device and load the correct troubleshooting routine before
analysing the problem.
For example, initialising the troubleshooting routine may require this conversation:
System: ‘What type of device?’
User: ‘Phone’
System: ‘Which make of phone is it?’
Use...
After taking a course in C++ I have written my first program and I'm looking for some feedback. Both on coding style and maybe algorithmic improvements. The code can also be found at GitHub. It compiles and runs fine, but is not very robust for user input.
I opted to try to emulate the game Min...
I just started making a text adventure using Haskell, but because this the largest project I have done in Haskell, I wanted to ask about it here before I got too far on it. I am still pretty new to Haskell, so I would really appreciate any advice at all on how this could be improved. Thanks so mu...