instruction_seed stringlengths 71 95.1k | _source stringclasses 1
value |
|---|---|
I am trying to solve the below problem from an online coding site:
Fredo is pretty good at dealing large numbers. So, once his friend
Zeus gave him an array of N numbers, followed by Q queries which he
has to answer. In each query, he defines the type of the query and the
number f for which Fredo has to answer. ... | stackexchange/codereview |
I am making this program that is going to calculate distance from randomly generated dots (with x and y coordinates) to 5 bigger ones and then its going to put each smaller dot into the group with bigger one that is nearest to it. So, i am making this with classes and every dot is made as an object. I made 2 arrays of ... | stackexchange/codereview |
I wanted to create a basic String class that will hold a CString and have:
constructor, destructor, copy constructor
assignment operator (both from String and CString)
<< and >> operators to stream with cout and cin
==, < and > operators to compare Strings
[ ] operator to access a certain char in a string
Len() func... | stackexchange/codereview |
I have a file with word frequency logs from a very messy corpus of scraped Polish text that I am trying to clean to get accurate word frequencies. Since this is a big text file, I divided it into batches.
Here is a snippet from the original file:
1 środka(byłe
1 środka.było
1 środkacccxli.
1 (środkach)
1 „środkac... | stackexchange/codereview |
WeatherForecastRequest is only simple HTTP parameters wrapper. It is using to get forecast from the openweathermap.
At first here is utility class (used to simplify actions to post http request, receive response from server and convert it to String):
// import packages from org.apache.http.***
public class HttpRequest... | stackexchange/codereview |
I solved the Nested List Python challenge on HackerRank.com passing all test cases. Although this problem can likely be solved with a short script with clever one-liners, my approach was instead to solve it in a clean, understandable way in functional style.
Here is a summary of the challenge, see link above for full d... | stackexchange/codereview |
Following is the string: (I'm getting that from config file so its not constant):
string sequence = "Concat({ACCOUNT_NUM},substring(FormatDate(yyyyMMddHHmmss,DateNow())
,2,12), GetLast(GetNextSequence(seq_relation),1))";
It contains multiple custom methods and I want them somewhere in the same order as they appear in ... | stackexchange/codereview |
I'm learning OOP and the first exercise of the course was to made a Stopwatch class. I did it really fast and decided to make an interface for this little app.
I created the interface. Basically I want to know if the aproach that I used is fine, if I needed to create another class to control the ui, etc. I'm really los... | stackexchange/codereview |
I wrote the following a while ago (using regex code I found on Stack Overflow), and I have the following concern I'd like addressed: should there be an std::move() around the passing of the string into the parameter in the second version of the function, ExpandEnv(std::string const &text), to the rvalue version? Conver... | stackexchange/codereview |
I have a typing log in which rows are grouped by consecutive package_name, and within those groups rows are grouped if they are logged within 180,000 ms from each other. This is working but is there a cleaner way to achieve it? An edge case would be when more than 1000 consecutive episodes are logged for the same packa... | stackexchange/codereview |
Over the weekend I decided to start work on my own version of FastMember. I began with my take on an implementation of TypeAccessor so that I could work with the properties of any type, create an instance of the type, and one or two other little tricks. I've reached a point where I'm out of ideas on how to improve the ... | stackexchange/codereview |
I'm building an event recorder. So far the code looks clean, but I feel like I'm missing something that can make this code even better.
Is composition a better solution? If yes, how can I do it properly in this context. Do you know a better way to share the Recorder across all other components? Will it be better to ini... | stackexchange/codereview |
I have a headless application that does either of two things.
If table does not exist within database create it and copy all the data over
OR
If table exists update it
Now I usually use access layers but this application is a bit older so I can't. This is what I've written.
using System.Collections.Generic;
using S... | stackexchange/codereview |
I've got a method which removes quantity from inventory when an order is completed. If there is not enough inventory quantity available, the order completion fails and the sql transaction is rolled back. Otherwise, transaction is commited.
I'm using Dapper for MySQL database access
public async Task<(bool, stri... | stackexchange/codereview |
I recently had the need to loop from zero to some limit only known at runtime. Instead of writing:
for(int i = 0; i < limit; ++i)
{
// Some repetitive thing
}
I wanted to write something similar to what I often use in Python and D:
for i in range(0, limit):
# Some repetitive thing
foreach(i; 0 .. limit)
{
... | stackexchange/codereview |
I'm a student and this is one of my assignments. My professor basically confirmed that my code is correct but all he grades on is if I finished the assignment correctly but not the coding style. I think I did poorly in terms of code style and implementation. I'm very frustrated and would like some guidance on how to im... | stackexchange/codereview |
from collections.abc import Iterator
import itertools
import pathlib
import string
PRIORITY = {v: i for i, v in enumerate(string.ascii_letters, start=1)}
def parse(f: pathlib.Path) -> Iterator[str]:
yield from f.read_text().splitlines()
def parse_line_blocks(f: pathlib.Path, block_size: int) -> Iterator[list[... | stackexchange/codereview |
Introduction
I am still learning both swift and ReactiveCocoa, and instead of directly applying it to one of my projects, I have instead worked a few hours on implementing a silly form with it.
My form has these elements:
Email
Password
Confirmation
Reset button
Submit button (not implemented)
There are three validat... | stackexchange/codereview |
Alright, so my code is 'all over' and missing some fundamentals as regarding to the MVC design pattern.I should separate my concerns and I don't have a model layer and i'm clueless to how to implement it in the current situation.
My two classes are :
public class GuiPanel extends JPanel {
public ImageIcon resource01;... | stackexchange/codereview |
Problem statement: Given an array of N integers, find and print its number of negative subarrays (i.e sub arrays having negative summation) on a new line.
My code: Taking order of 3 time. How can I improve my java code?
import java.util.Scanner;
public class NegativeSumOfArray {
public static void main... | stackexchange/codereview |
Problem statement
Write an IIFE in which we have to validate the input provided from a form using closures. The form consists of name, email, phone, address in which name, email and phone number should not be left blank. Also validate that the given email is a valid email id using JavaScript.
Objective
This assignment... | stackexchange/codereview |
I have a dashboard like interface, that can have many tabs. There can be as many or as few tabs as the user likes, with the user being allowed to re order them as they wish. Exactly like browsers do.
My problem is moving the tabs position, for example, look at these tabs:
[Sales] [Admin] [Finance] [Development]
If th... | stackexchange/codereview |
I've got this little module that returns basic user data required for a web app that's extracted from a large number of columns per row. I was asked to replace the small, column specific select statement I'd prepared with a stored procedure that returns the entire row. This moves column pruning into the server.
I've m... | stackexchange/codereview |
I have this method that is working as i want:
public static <T> List<T> convertDados(Class<T> entity, List<HashMap<String, String>> dados) throws NoSuchMethodException,
SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
Field[] fields = ... | stackexchange/codereview |
I've developed a spreadsheet that has evolved over several years to help keep track of the number of student contact hours that have been used to help flag up when students have run out / are running out of allocated hours (so that additional hour requests can be made if necessary).
There is a master workbook, which co... | stackexchange/codereview |
For a class last fall I was working on a "cloud backup" system. Originally in Pascal, I decided to rewrite it in C# and expand the feature set. Below is the FileSystemWatcher "manager" class which captures events from one to many FileSystemWatchers. It doesn't trigger any events of its own, yet, but I'm curious if t... | stackexchange/codereview |
This is an attempt to create interfaces holding the boilerplate code of basic JPA interactions.
Code in question/review
JPAInteraction.java
package personal.learn.jpa.jpa_all.config;
import javax.persistence.EntityManager;
public interface JPAInteraction {
default void close(EntityManager entityManager) {
... | stackexchange/codereview |
At work we are interfacing with the Jira cloud storage for our ticket management system. I created a base class to make the process easier on the user side, and I did my best to make it re-usable and generic. I wasn't able to figure out a generic way to gain the access token authorization since I used Selenium to man... | stackexchange/codereview |
I found this code for Java to find if graph has cycles and I edited it to print out path of cycle. I use adjacency list. As it is directed weighted graph I will need to implement compensations of cycles (if we have (1)--(2500)--> (2)--(2000)--> (3)--(1000)-->(1) then (1)--(1500)--> (2)--(1000)--> (3)--(0)-->(1)). Neve... | stackexchange/codereview |
Today I faced a difficult problem where I needed to step through several totally unrelated classes, and I suspected (among others) an object aliasing problem somewhere deep in the framework layers.
In Eclipse, I had several breakpoints at which I could look at some of the objects and variables. But as soon as the frame... | stackexchange/codereview |
I made a small program that tests numbers against some properties:
Welcome to Numbers!
Is it odd? 4
No
Is it a multiple of 18? 38
No
Is it big? 100
Yes
That's basically it :)
My code is:
import System.IO
import Text.Read
askUser :: String -> IO Double
askUser str = do
putStr str
num <- fmap readMaybe getLine
... | stackexchange/codereview |
I've written an ActiveAdmin mixin, such that you can include it and call simple_menu_for Foo, to reduce duplicate code when working with simple models. Here is the main part, which will connect all others. It works, but code looks little bit ugly. Maybe there is an alternative to using the class_variable_set method?
... | stackexchange/codereview |
I have a csv file
1;(same.)
2;Type...
3; (who are you?)
4; I am a talker whom the world has not yet seen. And you?
5; (leave.)
6;Connect to the Internet - I'll leave...
7; (I would like to.)
8;He would like to! And you're a no-brainer guy!
The objective was to make it look like
row1 Question - '(same.)' - answer- 'T... | stackexchange/codereview |
This is a revised copy of the Mail Crypt library based on the recommendations from the last post, as well as reviewing recommendations from the first post that I misunderstood.
[Last post] Mail Crypt Library for encrypted email
[First Post] Mail Crypt CLI encrypted email wrapper for Gmail
Change Log:
Removed try/ex... | stackexchange/codereview |
Update: This question has a follow-up here
A utility class to handle the ubiquitous "turn off ScreenUpdating, Calculation, Events etc" for executing VBA code, and remembering what those values were before they were changed so they can be restored later on.
Also comes with a module of Unit Tests (courtesy of Rubberduc... | stackexchange/codereview |
I would like your opinion on my Java implementation of the merge sort algorithm on an integer array, since I'm not really into algorithms I'd like to know from you if this is a correct implementation and if it can be improved somehow.
For example, it requires a lot of space for the sub arrays, but this should be normal... | stackexchange/codereview |
The assignment problem is about assigning tasks to workers, where each pair (worker, task) has a cost. The Hungarian algorithm builds an optimal solution for this problem. It has two variants, depending on the representation of the cost relationships: one with bipartite graphs, and one with cost matrices. I have implem... | stackexchange/codereview |
I have a function which sends an email via outlook when given text, a subject, and recipients shown below:
def __Emailer(text, subject, recipient, auto=True):
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
if type(recipient) == type([]):
... | stackexchange/codereview |
I have a use-case where I need to retrieve all members with specific attributes in the class and interface hierarchy - I usually need the first match and apply its rules to child members. The built-in GetCustomAttributes are too limited becuase they work only for a single member and don't support interfaces.
Implement... | stackexchange/codereview |
The module has three functions:
get_property_from_dict, retrieves a dictionary property's from a given path.
token_collect_from_dict, builds a list of tokens and their location from a given dictionary.
token_replace_in_dict, replaces a tokens in a dictionary with supplied values.
I want to use these functions in a la... | stackexchange/codereview |
Preliminary rant:
System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary.
Oh. My.
So I finally got fed up with how default exception information is beyond useless.
For a part of the project I will mostly no longer use the this[TKey key] property to access my Dictionaryies but ... | stackexchange/codereview |
I'm learning C, and wrote this program outside of my assignments in order to practice pointer manipulation and data structures, step by step. I want to ensure that this program follows well known conventions, has excellent style and readability, and uses pointers as efficiently as possible, before I move on to more com... | stackexchange/codereview |
I want to make some sort of NMEA AIS data generator. Now I wrote this code and it works quite well (does what I need from it), but I am sure it is bad and is to be optimized.
The problem I see is that I convert integer to 6-bit word binary via string variables and I am sure it's not optimal at all.
#!/usr/bin/python
i... | stackexchange/codereview |
I have a abstract class which is extended by many many other classes:
What I have done:
public abstract class AbstractActionHandler {
protected WorkItem currentWI;
protected String status;
protected String field;
protected void init(WorkItem currentWI, String status, String field) throws IllegalArgume... | stackexchange/codereview |
I am writing a program for my trading application. Over the months the program has been growing steadily, and what is used to be a small program now I would call a medium size program (about 1000-2000 lines in total), and it will keep growing as I add more features to it. It has grown to a point where it start to get ... | stackexchange/codereview |
Sometimes we have this code blocks that is repeated in the same controller again and again, I reviewed the Repository Pattern but I didn't understand how to deal with some kind of these duplication.
Here is a sample of what I got here:
$orders = ( new OrderList() )
->where( 'order_state_id', '!=', null )
... | stackexchange/codereview |
I need to merge two objects in a code path that is going to be heavily used. The code works, but I am concerned it is not optimized enough for speed and I am looking for any suggestions to improve/replace what I have come up with. I originally started working off an example at the end of this issue: https://stackover... | stackexchange/codereview |
I have written code to solve the prime generator problem. I am given an input which contains in the first line the number of test cases, and for each test case, I am given a range and I have to print the list of prime numbers in that range. However, it doesn't pass and says that time limit has exceeded. I tried optimiz... | stackexchange/codereview |
I was wondering on how to make the execution time faster. Is there a way to make it faster with this method or do I need to make with another method? If someone have any solution please help me. because I'm really struggling with this and I tried many different things and my lecture said that this code's execution time... | stackexchange/codereview |
I wrote a wrapper class in PHP to use Telegram bot API. What do you think about it?
I used this class in some projects and it doesn't have any problem but I want to know if it is optimized?
<?php
/**
* A wrapper class for telegram bot api
* you can find source code in https://github.com/smoqadam/php-telegram-bot
*
... | stackexchange/codereview |
Problem statement
Write an IIFE in which we have to validate the input provided from a form using closures. The form consists of name, email, phone, address in which name, email and phone number should not be left blank. Also validate that the given email is a valid email id using JavaScript.
Objective
This assignment... | stackexchange/codereview |
First let's introduce the problem:
I have a list like [{10,18}, {19,25}, {26,50}] and i have an input (n), when (n) inside one of objects in a list i will get this object and when (n) not higher then all objects in a list I want to get the higher object.
Take this list for example List<MyObject> list = [{10,18}, {19,... | stackexchange/codereview |
Below is my answer to the Google Code Jam's answer to the Store Credit. As usual the code run's perfectly well, however, my credit_pos function gives a warning when returning the temp array..
You receive a credit C at a local store and would like to buy two
items. You first walk through the store and create a list L... | stackexchange/codereview |
For my first Kotlin project, I'm implementing the Redux pattern with simple Increment and Decrement buttons and a text view to display the current value.
My main questions have to do with Kotlin and Android idioms and how I structured my code. Is the below a radical departure to how Kotlin is normally written? For exam... | stackexchange/codereview |
I wrote a tiny shell script that basically installs a script into your system by copying it to someplace like /usr/local/bin, chmodding it, and adding it to your PATH. It works on both Unix and Windows (via an emulation layer like MSys or Cygwin). Its source code is available on GitHub. Here is the script in its entire... | stackexchange/codereview |
Given an infinite number of different coin types (such as pennies,
nickels, dimes, quarters) find out how many ways n cents can be
represented.
My code appears to work (although I am curious to know if it has any correctness issue). But I feel like the memoization I am doing is a bit inelegant. Can we do without ... | stackexchange/codereview |
I'm implementing rsa and aes classes in java, but i have some trouble with the rsa implementation.
Since i have two keys in asymetric encryption, with two different types, i've made two differents methods, one for each. Is there a better/cleaner way to do that?
private static byte[] doCrypto(
int cipherMode,
... | stackexchange/codereview |
Originally Posted on Stack Overflow
First of all I want to say that I'm new to PDO. I did tried it once but since I found the oop solution complicated and even impossible (SELECT * FROM table_name) I decided to use PDO.
But I'm not sure if I do it right, so I'd like to take criticism about what I've done. I'm "translat... | stackexchange/codereview |
This is my 3rd JavaScript canvas game. It's basically just snake right now but I am planning on adding some more aspects to it soon. I was wondering if I could get some feedback especially on how I'm checking if the snake crosses itself in the game function.
class Block {
constructor(x, y, w, h, col) {
this.x =... | stackexchange/codereview |
I am trying to follow the template provided here to create a doubly linked list in java. This homework is based on this lecture. Can someone please review my implementation?
No change to this part of the code
/* DListNode.java */
/**
* A DListNode is a node in a DList (doubly-linked list).
*/
public class DListN... | stackexchange/codereview |
The exercise is explained in the comments. Do you have any suggestion?
package com.atreceno.it.javanese.attic;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import ja... | stackexchange/codereview |
So I based my "algorithm" on the poke method defined by Persi Diaconis. You start with the card at the bottom of a given deck and then poke the top card into a random position in the deck. At first the probability of this happening is 1/52 but once a card is below the bottom most card it increases to 2/52 since there i... | stackexchange/codereview |
I've solved Project Euler #15 in Haskell, but I feel like there might be a better way to express my solution that I'm not seeing. I start out defining my types:
import qualified Data.Map.Strict as Map
import Data.List
data Position = Position Int Int
deriving (Show, Eq, Ord)
start :: Position
start = ... | stackexchange/codereview |
I need to be able to atomically add a 32-bit floating point value to a location in memory. Here is what I came up with. While the code is Windows-specific, I'll extend it with Linux support using __sync_bool_compare_and_swap().
While I tested this code and it appeared to work fine, I'll appreciate a fresh look from ano... | stackexchange/codereview |
First, a reminder of the RSA algorithm and what my program implements:
Take two distinct, large primes p and q
Ideally these have a similar byte-length
Multiply p and q and store the result in n
Find the totient for n using the formula $$\varphi(n)=(p-1)(q-1)$$
Take an e coprime that is greater, than 1 and less than... | stackexchange/codereview |
I have written a Java class to replace text in file. The file contains database configurations and is as follows:
test.properties
#local
db.url=jdbc:oracle:thin:@localhost:test
#db.user=testa
#db.password=testa
db.user=testb
db.password=testb
#db.user=testc
#db.password=testc
# is a comment character. Now db sche... | stackexchange/codereview |
I wrote a NodeJS HTTP server specifically for serving static files. I didn't bother much about security since the server is going to be used locally in my Electron application.
function buildStaticServer() {
const fs = require("fs");
const urlModule = require("url");
return require("http").createServer(func... | stackexchange/codereview |
function fillFormInputs(data) {
$('input[name="name"]').val(data.name);
$('input[name="surname"]').val(data.surname);
$('input[name="patronymic"]').val(data.patronymic);
$('input[name="email"]').val(data.email);
$('input[name="skype"]').val(data.skype);
$('input[name="icq"]').val(data.icq);
$('input[name=... | stackexchange/codereview |
I've solved the Word Squares problem:
Given a set of words (without duplicates), find all word squares you can build from them.
A sequence of words forms a valid word square if the kth row and column read the exact same string, where 0 ≤ k < max(numRows, numColumns).
For example, the word sequence ["ball","area","lead... | stackexchange/codereview |
My JavaScript code is slow for large inputs. However, it is especially slow in IE. The browser will freeze for about a minute while the select is being reloaded. Any ideas for how to optimize this code, especially for IE?
function reloadSelectWithJSON (elementid,query){
/* It is assumed that the elementid passe... | stackexchange/codereview |
I have decided to create a program that can factor and solve quadratic expressions in micropython, where the standard library is limited, and i have no idea how to implement external modules onto it, so i had to bake this program from scratch.
The simple premise is, that it can factor and solve most quadratic expressio... | stackexchange/codereview |
I wrote a pretty basic setup script that handles most of the setup for a Three-server solution. The solution and setup file are available on GitHub
The three servers are Redis, HAProxy and Node / Cron.
All three options handle only solution specific stuff (not including installing the frameworks)
I felt like my usage o... | stackexchange/codereview |
I'm trying to implement the repository pattern in the following manner:
Interface:
public interface ISurveyRepository
{
Survey Add(Survey survey);
IEnumerable<Survey> GetAll();
Survey GetById(int id);
bool Update(Survey survey);
bool Delete(int id);
}
Implementation:
public class SurveyRepository ... | stackexchange/codereview |
I want to write the test case for Service class.
My Service Class dynamic-form.service.ts
import { HttpClient, HttpBackend } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
@Injectable({
providedIn: 'root'
})
export class DynamicFormService {
priv... | stackexchange/codereview |
Hello I have the following code, where I need to do many checks of calls from the database,
My TypeEnum:
export enum ProductTypes {
equipament = 'equipament',
component = 'component',
}
this is my use case class:
export class AssignProductUseCase
implements
IUseCase<AssignProductDTO, Promise<Either<AppError,... | stackexchange/codereview |
Since I have just started Javascript, I am trying to solve a few problems and improve myself. I encountered such a question. I tried to do everything step by step from the question, but I do not think that my code is efficient. Can someone help me develop it?
Please code for a JavaScript function that accepts two argu... | stackexchange/codereview |
How could the following code be made more concise?
HTML structure
<body>
<header>
<ul id="main-nav">
<li></li>
<li></li>
<li></li>
</ul>
</header>
<section>
<div class="toggle">
<div class="secondState"></div>
</div>
</secti... | stackexchange/codereview |
Business logic
It would take us too far to explain the whole business case behind this code, so I'll try to be as succinct as possible.
There are Persons,
and Persons can have Profiles,
and the combination of those two is a PersonProfile.
There is also a table called ProfilesToReplace, which contains Profiles that... | stackexchange/codereview |
I wrote a class TranslateIt for translating text files with Yandex.Translate service. I feel the code is rather bulky. Is it better to decompose it to several methods? I'm eager to know opinions of experienced people.
import requests
import os
import chardet
class TranslateIt(object):
"""
methods
translate... | stackexchange/codereview |
I'm making a project that will scrape some online store for an item, gets the data and stores it in a remote database that I have, and also able to read the database and display the data on a dashboard that uses Flask. It roughly works now, but I'd appreciate some inputs on how to make the design better, since I'm a be... | stackexchange/codereview |
The complete problem definition can be summarized as "find the largest sum of for paths from the top to the bottom of a triangle of integers". I decided to read the triangle in from a file which can be found here.
My solution
#!/usr/bin/python
"""chicks' answer to Euler Project problem #18"""
import sys
import string... | stackexchange/codereview |
I'm trying to implement a TaskScheduler that runs all tasks in the order they are submitted, on a single dedicated thread. Here's my implementation, using a BlockingCollection:
class SequentialScheduler : TaskScheduler, IDisposable {
readonly BlockingCollection<Task> m_taskQueue = new BlockingCollection<Task>();
... | stackexchange/codereview |
I have the following domain model:
class Holding
------------
Account account;
DataSourceProduct dataSourceProduct;
class Account
-------------
String name;
class DataSourceProduct
-------------
DataSource dataSource;
Product product;
// other product data specific to the data source
class Product
--------------
St... | stackexchange/codereview |
This takes two sets of five random points stored as a NumPy matrix, and then calculates the NumPy matrix between a point of the first set and a point of the second set. While the code works, I feel it's inelegant, as if I was writing in PHP or some other language. How can the function CalculateMatrixDistances be improv... | stackexchange/codereview |
This is from a high performance server that needs to block anyone who is doing more than limit requests per seconds seconds.
You call check and if it returns true you process the request, otherwise you block it.
It maintains a circular queue, initialized to 0, of the last times the event was triggered.
I use time() bec... | stackexchange/codereview |
This is my first Machine Learning algorithm using Python and SkLearn. The code works, which is pretty awesome. I'm getting about 65-70% of accuracy after training it with about 4k rows of data.
Although it works, it seems like is less than optimal. I'm guessing it would be better to organize it with functions and etc -... | stackexchange/codereview |
I've recently written a Vulkan library for creating 2D applications with ease. The catch was I need std::lock_guard for my window resize event to resize resources related to the window on a secondary render thread (separate from the main GLFW window thread).
While testing on an AMD machine (running on an AMD APU 5600G)... | stackexchange/codereview |
I'm implementing Kruskal's algorithm in C++11 and would like feedback on style and performance on my graph data structure and algorithm for educational purposes (for production code, I'd use a pre-existing library). The main design questions I have are:
Is there a better way to implement the handle class for the graph ... | stackexchange/codereview |
This is my solution to the "Permutations" problem from Leetcode:
Given a collection of distinct numbers, return all possible permutations.
I know this is a common routine that can be done much faster using itertools.permutations but I want to write it to learn the algorithm itself.
I would like any general feedback o... | stackexchange/codereview |
This code works when compiled on gcc 4.8.2.
I would appreciate any comments on my style and the readability of my code, and any improvements that I could make to make the code more readable and/or performant.
Problem:
Largest product in a series
Solution:
/*
* file: pe_008.cc
* title: Largest product in a grid... | stackexchange/codereview |
I have been working on a board game in C++ using Qt. The game consists of four players with four different colors.
This is all working fine, but I want to know if there is any other way to do this. Any ideas on how to improve this code and especially ideas on completely different ways to achieve the same are welcome.I... | stackexchange/codereview |
The program reads a file containing a list of numbers, and then writes the ones divisible by 3 to another file, and prints the remaining ones (non-divisible) to a third file.
Declaring, opening, and closing the files is alone over 50% of the code, is there anyway to make it more compact?
#include <stdio.h>
#include <s... | stackexchange/codereview |
This is the smallest SSCCE of my project. I get flickering on the screen with this code.
Main class (on which I start the application)
import javax.swing.JFrame;
public class MainFrame {
public static void main(String[] args) {
final JFrame frame = new JFrame();
final GamePanel gamePanel ... | stackexchange/codereview |
I've recently vectorized most of the code for an optimization problem but this one still eludes me. As the procedure and not the actual values are important here, I have replaced the original matrices with random dummies.
Problem:
Given a matrix A of shape (m x n) and a three dimensional matrix B of shape (n x (n-1)*r ... | stackexchange/codereview |
I am working on some code and I have come across the following:
private int getPosition() {
List<IDescriptor> fragmentDescriptors = new ArrayList<IDescriptor>(mDescriptors);
int position = -1;
for (IDescriptor fragmentDescriptor : fragmentDescriptors) {
if (fragmentDescriptor instanceof VideoD... | stackexchange/codereview |
Originally, I was going to post a question about how to condense four repetitive functions into a single function, but I wound up figuring it out myself before I could even post it.
However, the original idea that I had was to break down some of the repetitive sections into their own function and use those new sub-func... | stackexchange/codereview |
To bootstrap our application we have a configuration stored in a JSON file. This config holds different settings, like definition of endpoints (e. g. an API or SMS gateway etc.) or some default values for login.
endpoint.ts
export const isEndpoint = (candidate: any): candidate is Endpoint => {
return (
candidate ... | stackexchange/codereview |
I know there are thousands of posts and questions around the topic of Float Discrepancy. And this is not really a question but a discussion for it.
After sitting repeatedly in front of the same problem, I made the following class to handle it once and for all of our projects. The direct value comparison is from the bo... | stackexchange/codereview |
I'm drawing a pixel by pixel image with the following code:
coord = np.where(np.all(imagen == (0, 0, 0), axis=-1))
cv2.imshow('imagen', imagen)
a = coord[0]
b = coord[1]
for x,y in zip(a,b):
rectObs.append(pygame.Rect((y,x),(1,1)))
for rect in rectObs:
pygame.draw.rect(screen, black, rect,20)
This code det... | stackexchange/codereview |
Here is my class that handle all MarshMallow Permissions I prefer separate it class as I will call its methods in all my apps.
At first I get used to check permission by this way:
private void CheckPermissionGranted() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ActivityCompat.checkSelfPermis... | stackexchange/codereview |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.