instruction_seed
stringlengths
71
95.1k
_source
stringclasses
1 value
I have a class that (among others) needs to run an action at fixed intervals of time. So I created a thread for this: struct Logger { std::chrono::milliseconds flush_interval_; std::thread flush_thread_; Logger(...) : flush_thread_{&Logger::flush_thread_function, this}, ... {} auto flush_cb() -> void; // ...
stackexchange/codereview
I implemented the golden section search algorithm recursively in Lisp. My code is: (defconstant phi 0.618033988749895D0) (defun linemin (f x1 x2 &key (xi1 (- x2 (* (- x2 x1) phi))) (xi2 (+ x1 (* (- x2 x1) phi))) (tol 0.001)) (if (> tol (- xi2 xi1)) ...
stackexchange/codereview
My goal was to have a single page display bulk amounts of media without the need to load new pages. I also wanted it to be able to load fast, so the generator uses a JavaScript array to display one item at a time. The user can move through the array backwards and forwards with the use of two buttons. Images, video and ...
stackexchange/codereview
Even though I have asked a question here related to my app using Swing and creating JPanel, I still have other ones about best practice making applications. I'm using Java 8. I have this class screening which contains Film and Auditorium classes. At the moment the class looks like this: Screening.java package cinema.sc...
stackexchange/codereview
In this code the angle between the minute and hour hands of an analog clock are found and calculated and the smaller angle between them returned. This code works perfectly and I am getting back the results I expect. We were told to do this and any testing if necessary. I got asked this in an interview question and want...
stackexchange/codereview
This is something I've done a few times, but I've found it to feel a bit error-prone with so many conditions, and am wondering if anyone can point me in the direction of a cleaner way. This is a PATCH route for editing a user. Super admin and admin users are both able to change other users (with some limitations) while...
stackexchange/codereview
Lets imagine we have an Article entity, with data imported from a legacy database. It contains an appendix column with type integer. This column is always filled with values 0, 1 or nil, so we decide to call it in_appendix with type boolean. We want to preserve all existent data so we convert the data like this: class ...
stackexchange/codereview
I'm fairly new to real world Java so I tried to rewrite an old app I wrote in vanilla java. I've made this one a lot more OO and used a dependency/build manager (Gradle). Now I just want to see what more experienced devs have to say about the project. This is the main code snippet that does most of the work. Any com...
stackexchange/codereview
I am creating a KotH (King of the Hill) challenge for Programming Puzzles and Code Golf. Other site users will write programs that play Texplode (a version of this game on a square grid). The program works, but I don't think it's anywhere near perfect; I don't often publish C programs so I rarely get any critique on th...
stackexchange/codereview
As I understand, the constructor chaining can be applied to cases when we have some common data to initialize. I have 3 constructors that accept 3 different types of arguments and have some common data. I'm not sure if I can do constructor chaining. public class RStandart { private readonly SqlConnection _objConn; ...
stackexchange/codereview
Introduction/Disclaimer This is a project for educational purposes. I'm not intending to replace the "award-winning" Collections Framework in java.util. I'm just looking for constructive criticism. For obvious reasons, I'm tagging it as reinventing-the-wheel. I'd like to see someone break my code. Preferably in a multi...
stackexchange/codereview
My goal is to accept user input regex in the following forms /regex|here/i /regex|here/ regex|here From there I want to be able to pass that to a function and return a RexExp object for use later with string.match() I came up with the below to achieve that, and not break the caller which is expecting the RegExp object ...
stackexchange/codereview
This may be a better fit for another board, but here goes: I've made a very simple gem that acts as a days-of-the-week bitmask. To be hip, I registered it on CodeClimate, where it's currently scoring a B/3.0 grade. Since there's only 1 extremely simple class, the B is bugging me. CodeClimate's reason is that there's to...
stackexchange/codereview
This has been asked a few times here, but I was wondering what I could do to improve the efficiency and readability of my code. My programming skill has gotten rusty, so I would like to elicit all constructive criticism that can make me write code better. init: #include <iostream> using namespace std; merge() //The m...
stackexchange/codereview
I am building a simple Store Management System and I have 4 classes, 3 of which are for Product, Vendor and Orders. The last one is my main class where the actual GUI is built. On it I have 800 lines of different functions that represent the different views and actions in the program. Is that ok? Should I make a class ...
stackexchange/codereview
It has been a long time I used c++. So I brushing over concepts for interview preparation. Can you please help me with code review? If you have any observations/bugs/alternatives please point out. For better formatting, I have shared code here feel free to open issues. :) Thanks a ton in advance. #include <cstring> #in...
stackexchange/codereview
So in this problem I am given an NxN matrix, in which each value of the matrix represents an altitude. I need to find the best path from the top-left corner to the bottom-right one, my moves being limited to down and right. Also, the path needs to be chosen in such way that the differences in altitude are the smallest...
stackexchange/codereview
Multithreaded Excel + VBScript Timer After reviewing these post: Snake in Excel in… VBA? and Drawing a snake using arrow keys in Excel using VBA, I decided to work on creating a VBA Timer. The typical Timers patterns used in the VBA have serious drawbacks. API Sleep - Stops the code execution until the sleep period is...
stackexchange/codereview
I wanted to implement this as short and effective as I could without using anything that is not basics, in order to improve my skills. I would appreciate input about things like memory leaks I missed, simpler way of doing things instead reinventing the wheel, methods I should have used / implemented / not implemented (...
stackexchange/codereview
I'm new to hash codes/hash tables, so I'm very unsure of my implementation. I want to create a hash table, but I can only use arrays. Specifically, I want to be able to insert things like a dictionary (a word and its meaning). Here is what I have: public class HashTable { String[][] table; int tableSize; H...
stackexchange/codereview
I'm making a MacOS app that will do some analysis on the user's calendar data. For now it only supports Apple's native calendar (EventKit), but I will later add support to Google, outlook, etc. Models/Events/Base.swift: import Foundation struct EventData { var title: String; var startDate: Date; var endDat...
stackexchange/codereview
This is a fun little program I made of a fruit machine gambler, aka "slot machine". What mistakes am I making? How can I make this better OOP programming, less spaghetti? var spin = false; var value1, value2, value3, value4; var holdFirst, holdSecond, holdThird, holdForth = false; var first, second, third, forth; ...
stackexchange/codereview
The frontend has a table with hundreds of rows. Each row consists of different inputs (text, file, checkbox etc.). The user can change any row and any input he wants before clicking the "Save Changes" button. It then needs to update the data in the database. I want to only send the modified data, or at least only the m...
stackexchange/codereview
I have a list of 9000 dictionaries and I am sending them to an API in batches of 100 (limit of the API). The API returns the list of 100 dictionaries just expanded with more key/value pairs. So both lists look something like this: [ {Key1:Val1, Key2:Val2}, {Key1:Val3, Key2:Val4}, ... ] and returns: [ {Key1:Val1, Key2:...
stackexchange/codereview
This is a very simple ball game in which we have to avoid projectiles falling from the sky. This is my second project and first game. Please review and tell where I can improve. import time import random import pygame pygame.init() #colors black=(0,0,0) white=(255,255,255) red=(255,0,0) green=(0,255,0) blue=(0,0,255) ...
stackexchange/codereview
Input: String : Title; List Tags Problem statement: Need to map title to tags, e.g. title is "china man japan beijing bell" and tags are ["china man" "beijing bell"], output should be ["china man" "japan" "beijing bell"] What I am doing: List<String> getTitleSplits(String title, List<String> tags) { List<S...
stackexchange/codereview
I've created a program that shows the time needed to sort a random array of integers. An example is: user@computer:~/projects/sortc$ ./sortc 50000 Naive sort: 4.501963s Bubble sort: 5.769375s Insert sort: 1.969153s Quick sort: 2.161162s I implemented in C the common sort algorithms: insert, quick, bu...
stackexchange/codereview
I'm looking for a review of the following code. Is there a better way to remove all properties that evaluate to truthy for a given function? Is there a better way to prevent a stack overflow in the recursive function? This is the entire Node.js module: // The removePropertiesWhereTruthy function accepts the following...
stackexchange/codereview
I'm posting my code for a LeetCode problem copied here. If you would like to review, please do so. Thank you for your time! Problem Given two words (begin and end), and a dictionary's word list, find all shortest transformation sequence(s) from begin to end, such that: Only one letter can be changed at a time. Each tr...
stackexchange/codereview
This is a small web scraping project I made in 2 hours that targets the website remote.co . I am looking forward for improvements in my code. I know about the inconsistency with the WebDriverWait and time.sleep() waits, but when I used the WebDriverWait to wait until the load_more button was clickable and ran the progr...
stackexchange/codereview
This method finds the common ancestor of two nodes in a binary tree. Any style suggestions or ways to make it more idiomatic? Is the algorithm correct? Rubocop says the cyclomatic complexity is too high, how would you break this up? class Node def initialize(value = nil, left = nil, right = nil) @value = value ...
stackexchange/codereview
I want to define a matrix of values with a very simple pattern. I've achieved it with the code below but it's ugly - very difficult to read (I find) and surely not as optimal, in terms of performance, as it could be. The former is really what I'm trying to address here. I feel this can be done much more elegantly and w...
stackexchange/codereview
I've been working on this pong game for the last 10 days, and I'd like to know of your opinions about it, what could I change to make my code better? #include <stdio.h> #include <allegro5/allegro.h> #include "allegro5/allegro.h" #include "allegro5/allegro_image.h" #include <allegro5/allegro_native_dialog.h> #include <...
stackexchange/codereview
I have implemented both some sorting algorithms (namely bubble sort and merge sort), as well as a command-line interface, in Clojure for fun and to test my Clojure abilities (I've tampered with Clojure for a while now, but I'm still quite a beginner). The code looks alright, but I think the styling of some parts of the...
stackexchange/codereview
This code is for a Telegram bot I created. Basically if the user types in Whats the news,Whats the technology news,Whats going on in Syria, Whats happening in New York City, etc it will retrieve 4 articles from google news related to the users query. This uses CoreNLP to analyze the sentence. Just by the way I am only ...
stackexchange/codereview
I am creating an add-in for a piece of software our company uses, so I'm working pretty extensively with that program's API. There are many COM object members which return or contain an array that I need to work with. Sometimes functions will return an uninitialized array (Null or "Nothing" return) or sometimes they m...
stackexchange/codereview
I have written a slideshow application and I am looking for some reviews: import sys import os import utils from PyQt4 import QtGui,QtCore class SlideShowPics(QtGui.QMainWindow): """ SlideShowPics class defines the methods for UI and working logic """ def __init__(self, imgLst, parent=None): ...
stackexchange/codereview
Why will this code work for a smaller multiple like 10 but time out for anything over 13? Can this code be revised to work for larger numbers? (I have an alternate solution but wanted to see if this code could be fixed to work for more multiples.) #2520 is the smallest number that can be divided by each of the numbers...
stackexchange/codereview
In groovy I have a list of files A and also another list of files B. I want to remove all the files from A that have a filename that also occurs in the list of files B. I wrote the following code: List<File> removeByName(final List<File> files, final List<File> removalFiles) { final Set<String> removalNames = remov...
stackexchange/codereview
I have had this keylogger code for a while now (a few years*), and I figured I would put it up for review. Here is what I would like reviewed (in order): Portability - right now, this program can only work on Windows systems. In what ways can I make this more portable? (I feel like I would have to go digging for POSI...
stackexchange/codereview
I have tried many possible methods here but I am still not able to reduce the time complexity of below algorithm. The basic layout of my problem is as follows: I have a string that is composed of only H's and V's. There can be not more than 10 H's and 10 V's possible. I need to find the Kth lexicographical order of su...
stackexchange/codereview
I'm sending data from a form with a variable number of fields via an Ajax call. Some of the fields are grouped together so I have opted to send them as an array of JSON objects to keep the groupings, but there are a number of ways of doing this. For client-side, is it better to read the form as JavaScript objects and ...
stackexchange/codereview
Fellow JS devs, I have come across a fairly simple question which has puzzled me. When the user submits a form I disable all inputs and submit button changes to a loading animation (fa-spinner from fontawesome). Once the form submit is complete then I restore the previous state, and enable everything back. My question ...
stackexchange/codereview
As a hobbyist programmer I have been reading "The Art of Multiprocessor Programming" (Herlihy, Maurice; Shavit, Nir) and converting the Java spin locks into C++ - I have enjoyed this and learned a lot. I have implemented the CLH spin queue lock (due to Travis Craig, Erik Hagersten, and Anders Landin) but I feel unhappy...
stackexchange/codereview
I'm trying to improve my code to find all the prime numbers within a set range as fast as possible, and I am trying to make it even faster. On my github page here, I have some optimization settings within Visual Studio that help improve the speed. #include <iostream> #include <fstream> #include <Windows.h> #include <co...
stackexchange/codereview
Today I have learned alot and still learning. I have came to a situation where I have realized that I have created a database with multiple functions that does similar stuff but different queries. However by looking at the code we can see a similar "path" of these functions and I have tried and tried to know how I can ...
stackexchange/codereview
According to shootout.alioth.debian.org, Racket is not much slower than C#, at least in the same order of magnitude due to its JIT compiler. However, I'm seeing at least two degrees of magnitude slowdown in my implementation of the RC4 cipher in C# vs. Racket. (Disclaimer: I am not using RC4, in this case a hilariousl...
stackexchange/codereview
I'm trying to implement sum of 2 array using multi threading. I expected that when I use more threads it will be faster than when I use one thread, but that isn't the case. public static int[] a = new int[100]; public static int[] b = new int[100]; public static int[] c = new int[a.Length]; publ...
stackexchange/codereview
My function converts an improper fraction to a mixed number (it does not AND should not simplify the fraction). // Improper fraction to mixed number // n = numerator // d = denominator // i = number function improperFractionToMixedNumber(n, d) { i = (n / d) >> 0; n -= i * d; return [i, n, d]; } // Con...
stackexchange/codereview
I am creating list of dictionary from two different results. I appreciate any improvement suggested. redditFile = urllib2.urlopen("http://www.bing.com/images?q="+word) redditHtml = redditFile.read() redditFile.close() soup = BeautifulSoup(redditHtml) productDivs = soup.findAll('div', attrs={'class' : 'dg_u'}) for div ...
stackexchange/codereview
So I got kind of a weird format returned from the api I'm calling it's the following: [ [ 1609065000000, "22739.71000000", "22795.73000000", "22700.39000000", "22779.08000000", "38.81782800", 1609065899999, "883167.94526884", 2261, "18....
stackexchange/codereview
Given Roy wanted to increase his typing speed for programming contests. So, his friend advised him to type the sentence "The quick brown fox jumps over the lazy dog" repeatedly, because it is a pangram. (Pangrams are sentences constructed by using every letter of the alphabet at least once.) After typing the sentenc...
stackexchange/codereview
In my project, I had three BackgroundWorkers that can be run independently, but I also wanted to allow the user to "Run All" of them, but not at the same time. They need to be run one after the other. So, I devised this class to create a Queue of BackgroundWorkers, subscribe to their RunWorkerCompleted event handler, a...
stackexchange/codereview
I have created mini-opengl program that draw simple chess board on screen by using SFML windows model only. The program runs fine. The main purpose of this program is to keep it as simple as possible and it is not rely on any of OpenGL helper functions like glOrtho or gluOrtho2D for converting coodinates. Also, it is n...
stackexchange/codereview
I've always used fgets to read a file. However, I want to read a file that may have embedded \0. I thought of using ftell to query the size, but it doesn't seem to work on all files. I've got a test file, 31 32 33 00 34 35 36 0A E2 82 AC 0D 0A 61 Here is my fgets. #include <stdlib.h> /* EXIT */ #include <stdio.h> /* ...
stackexchange/codereview
I made a script to start something akin to a "session" in which I start services and open tcp and udp ports in the firewall in order to work with, for example, a full stack project, and stop and close the corresponding services and ports once I'm done using them. When I call the script, I place the services with the -s...
stackexchange/codereview
I'm prepping for a tech interview coming up and trying to have a better understanding of what I should look out for in writing code. Also, feel free to correct the terminology that I use as I want to be able to talk about my code clearly and succinctly. One of the specifications for the tech interview process is that I...
stackexchange/codereview
This program generates 6 random numbers between 0 and 45 and the numbers cannot be repeated. Can this code be improved? $numbers = []; $i = 1; while($i <= 6) { $number = mt_rand(0, 45); if(!in_array($number, $numbers)) { array_push($numbers, $number); $i++; } } sort($numbers); echo ...
stackexchange/codereview
I have a website that keeps track of 'changes' that users make. These changes come in all shapes and sizes and each shape and size has a different MySQL table to store them in. In total there are 8 different tables. Each table has completely different columns, so I don't think a simple JOIN would be possible, however t...
stackexchange/codereview
Short Story: I created this website last year in plain HTML, CSS, JS which I can't even remember how I wrote that and now I can't even edit the website without breaking it. So, I'm re-writing everything in a proper way using React. So, I'm making a website using React ( I'm still learning ) and I got confused about us...
stackexchange/codereview
I've found a good example of how to do this in Java and how you can get the same behavior in c#, so I've made made an attempt at it: public class CircularReferenceOne { public int Identifier; public CircularReferenceTwo CR2; public CircularReferenceOne HCopy() { var track = new Dictionary<int,...
stackexchange/codereview
I started self-learning Bash scripting yesterday, and I finished my first successful "advance" script. Goal To create an interactive step-by-step script to that allowed customizing various parts of the process of creating permanent swapfiles. I based my idea off of Ask Ubuntu Answer's #1 and #2. Background While creati...
stackexchange/codereview
I wrote up a script a while back to let me play around with fractals. The idea was to have direct access to the script that creates the fractal. None of that close, edit, then run hassle; just edit then run. renderscript.py contains the GUI: import tkinter as tk from tkinter.filedialog import askopenfilename, asksaveas...
stackexchange/codereview
I created a project using VLCJ and a probability function to create a media player that plays your favorite media more often than the others, because I wanted to hear my favorite music and videos more than my least favorite. This involved a lot of event listeners that were all at the bottom of my main class file where ...
stackexchange/codereview
This is a sample exercise tutorial that would be used to test understanding of how simple classes communicate/message and are designed. Tester class public class GuessingGameTester { public static void main(String[] args){ //create a new game GuessingGame g1 = new GuessingGame(); //call th...
stackexchange/codereview
I'm working on a network sniffer program, whose structure uses 3 main classes: Frame Class - One per monitored frame, holds reference to all the other sub frames Parse Class - Holds the hex value of the entire frame Protocol Classes - Individual classes for each network protocol When a new frame is captured its sent ...
stackexchange/codereview
This is my first C program I just wrote in like 30 minutes and I was wondering if you could give me any pointers on ways to improve this. I'm decent at programming (around 5 years experience), but have no experience with C so I imagine I'm not following the proper idioms and/or doing things properly. Note: I didn't mak...
stackexchange/codereview
I'm writing a program that is going to analyse some data imported from an Excel spreadsheet. It is currently running quite slow (couple seconds on an average machine) and I was wondering whether it could be sped up in any way. There are three classes containing the data. This first class contains experimental runs. The...
stackexchange/codereview
Update After examining the NameRulesUnicode64k.xlsm spreadsheet in excel-names, it appears that my NameIsValid() is in close agreement. When examining whether or not a single character is OK as a valid name, there are only 2 discrepancies across 65,535 characters: Chr-Code Char Other Case OK ... NameIsValid() ...
stackexchange/codereview
I am developing a class (in a C# MVC 5 project) that originally had a using block within a single method, and it got to be very huge after placing formatting statements and other code in the using block. I am using the Nuget Epplus package to export a model's contents to an Excel document, and all of the tutorials I ca...
stackexchange/codereview
I have to do some encoding and then assign the result to a label. Is there a more optimal (or concise) way to write this? // encoding fix NSString *correctStringTitle = [NSString stringWithCString: [[item objectForKey:@"main_tag"] cStringUsingEncoding:NSISOLatin1StringEncoding] ...
stackexchange/codereview
I've been doing network programming using C#'s TcpClient for several years. The code below is an asynchronous wrapper for TcpClient that I developed throughout these years. The key methods are: ConnectAsync() - connects asynchronously; RemoteServerInfo is a simple class containing Host, Port, and a boolean indicating ...
stackexchange/codereview
I'm creating an array of dates that won't be selectable in a calendar. The following works, although the way I've gone about it is quite long-winded. I was wondering if there is a more elegant way of getting all the dates in a month, where dates don't fall on various days a project does run on. It's probably more clea...
stackexchange/codereview
I created a code that import the data regularly into a selected workbook. The code run well, it takes less than 20 seconds before the data is imported successfully. How does it work? I get a monthly data with Excel format. I want the data to be imported into my workbook to be analysed further. Step by step The first ...
stackexchange/codereview
I've written a minimal unit test framework. The goal was to allow assertions of booleans, for equality and catched exceptions. Two things are bugging the most. That assertions have to rely on macros and using a function pointer type instead of one of the more modern C++ ways. Are there ways to further minimize? What C+...
stackexchange/codereview
I'm a new programmer, so any help is welcome. Preferably to make it faster, avoid heavy memory usage, and so on. #! /usr/bin/env python """ This module is a frame work for a Genetic Algorithm. :param GenePool: See this documentation for how to use this module.. :type GenePool: GenePool Author: Fernand...
stackexchange/codereview
I've created a small class to generate unique random strings. It works fine. I also want to log the collisions of the generated strings. I check if the generated string is in the array for uniquness: public static function add(&$array = [], $length = 1) { $hash = self::rand_str($length); while (in_array($hash, ...
stackexchange/codereview
Today I had an interview where I was asked to solve "Given an binary tree, convert it to binary search tree in minimum time, space complexity". I wrote this code, but got the feedback that complexity could be improved without using sort and without using external storage. How to do it? ##code goes below##: class Node:...
stackexchange/codereview
Given an unique string that represents a sequence of characters, the class should implement three methods (getNextChar, getNextString and the genSequence generator). How it works We give a sequence of characters. For example: "abc" We give a starting string. For example: "a" The generator yields the following strings ...
stackexchange/codereview
This is the AuthenticationService I made based on Barry Jaspan's design, which is way better than the code of which I asked in a question a couple of months ago. I would like it mainly reviewed on a couple of aspects: Readability (clean code) Accurate comments Accurate naming (especially for the last class) Authentic...
stackexchange/codereview
Just a very simplified and stright-forward way of serialize/deserialize to/from JSON using standard .NET 4+ libs. I was trying to avoid "complexity", so get rid of 3rd part libs and heavy-infrastructured standard libs. #region JSON API public static string ObjectToJson(object o, Type t, Type[] pTypes = null) ...
stackexchange/codereview
I am referring to the book Design Patterns For Dummies to learn about design patterns. I wrote an adapter design pattern, as mentioned in the book. Is it proper or does it need some modification? #include<iostream> #include<sstream> using namespace std; class AceInterface { public: virtual void setName(string n...
stackexchange/codereview
I'm a student that have been learning java for the last year. I have recently created a little program that creates a backup of a directory (it creates a directory named backup0 and copies all files of the original directory), if there's already a folder named backup0 it needs to create one folder with a different numb...
stackexchange/codereview
A little background: My app has two models called mapgroups and usergroups. A map belongs to a group and a user belongs to group. You can go in a group and add maps which is how maps are "assigned" to a user. These will show up on their dashboard. class User < ApplicationRecord def fetch_maps @groups = self.grou...
stackexchange/codereview
My react.js Image component will load an image from a URL or base64 string, do some processing on it and put it on a canvas. The "preload" prop is a 10x10 pixel image that is blurred just a little bit to make it look smoother. The blur algorithm itself is very fast (I also tried removing it, but got the same results i...
stackexchange/codereview
I wrote implementation of LRU in java and want to know if it can be improved further both in space and time complexity. Input: Number of frames and reference string for pages. Output: Number of page faults. Also I am a little skeptical about its correctness because I got 6/10 in my practical lab. Kindly ignore OOP's a...
stackexchange/codereview
I'm a noob. I wrote this code to convert bools to ints and ints to bools as a past-time but I would like to know whether to continue programming - this is the kind of thing I've been doing, no useful scripts at all. So, I wanted a program and not a module and that's why I wrote the decorator tab: for output. "|" means ...
stackexchange/codereview
I'm trying to have a main App view with references of all my views to manage and call transitions between theses views. But, I have circular dependencies. app.js define([ 'jquery', 'underscore', 'backbone', 'views/viewOne' ], function ($, _, Backbone, ViewOne) { 'use strict'; var AppView = Bac...
stackexchange/codereview
I’ve written a basic implementation of Breakout using Java 8 & Slick (~400 lines of code). Please let me know of any design/OOP improvements that can be made (any improvements in general are welcome, but I’m specifically looking for design & OOP improvements). Game - the main class package breakout; import org.newdawn...
stackexchange/codereview
I have some code that allows me to enumerate over months in a year. This code is used both in a Web application as well as a standalone exe. Although it doesn't have to be efficient it is used a lot so if there are any improvements that would be great (I haven't done any profiling). It also needs to be thread-safe. ...
stackexchange/codereview
CasperJS doesn't allow continue statement inside a casper.then functions. This was my solution but I'm not happy about it. Is there a better way to achieve this effect? casper.start(); casper.then(function() { var current = 1; var end = 4; var skip; for (;current < end;) { ...
stackexchange/codereview
The fourth project, continuing my C++ saga with terrible post names. :P An approximate value of pi can be calculated using the series given below: $$ \pi \approx 4 \left[ 1 - \dfrac{1}{3} + \dfrac{1}{5} - \dfrac{1}{7} + \dfrac{1}{9} - \cdots + \dfrac{\left( -1\right)^n}{2n + 1} \right] $$ Write a C++ program to cal...
stackexchange/codereview
Could anyone provide any constructive criticism? I'm trying to get a jump on data structures before classes start. One thing is that I should add a copy constructor and assignment operator. Changes made: got rid of using namespace std. As the code allows users to specify a cap, if they wish, for their stack any ideas o...
stackexchange/codereview
Because neither sklearn nor Pandas provide a straightforward and complete one-hot encoder, I decided to write one myself. Both Pandas and sklearn do have an encoder with no option to decode, and the sklearn.LabelEncoder that has the decoding only produces that, labels. Here's the class: import numpy as np class OneHot...
stackexchange/codereview
If I have a oneliner in C such as size_t maxSizeOf(const char *s) { return strlen(s) > M_MAX_SIZE ? M_MAX_SIZE : strlen(s); } would it be better to have a macro defined such that #define MAX_SIZE_OF(s) (strlen(s) > M_MAX_SIZE ? M_MAX_SIZE : strlen(s)) or would it be better to have size_t maxSizeOf(const char ...
stackexchange/codereview
Is my Application.php class secure for continuing development? The Application.php acts as a registry for the whole application. I tried not to rewrite already working code that is being pulled from Zend Framework and PhalconPHP, but allow myself to have freedom with using frameworks within my web application. Also, pl...
stackexchange/codereview
I just made a small Luhn Checksum validator Description of Luhn Checksum Every number in the Integer gets added individually together, but every second digit gets instead doubled and added. If the doubled number is over ten each individual digit gets added. It works, but is there a way to make it more elegant and maybe...
stackexchange/codereview
Based on the previous question, I have implemented all suggestions. Also, I worked a bit in this project to improve it. Summary of improvements: split the code into multiple files as .hpp and .cpp removed STL functions used only one sf::RectangleShape for border instead of std::vector. I would like to know how I can ...
stackexchange/codereview
I'm using Microsoft SQL Server 2014 Express. I found myself wanting to add the Columns CompanyNameChangeDate (1 through 10) and CompanyNameChangePreviousName (1 through 10) to a table in my database. I wrote the following query to do it: declare @i int set @i = 0 Declare @nameChangeDatePrefix as varchar(255) = 'Compan...
stackexchange/codereview
For taking part in a course, I need to learn some Java. Unfortunately they only teach Java 1.6, so I understand that later versions could simplify the below code a lot, but I have to stick with 1.6 though, at least for the course. I have zero prior knowledge of Java, in order to prepare for the course, I implemented a...
stackexchange/codereview