instruction_seed stringlengths 71 95.1k | _source stringclasses 1
value |
|---|---|
I've been playing with a simple toyrobot exercise to brush up some of my forgotten language skills and was wondering if there was a nicer way to implement my main command parsing loop. I think the use of the two maps and the nested ternary operator is readable but would be interested in seeing other approaches.
#inclu... | stackexchange/codereview |
I slowly made an Imgur client and everything works but I have few questions about how to make classes more OOP and cleaner.
Is that correct to make generateToken static when it is private?
Is calling the method from the constructor an anti-pattern?
public class ImgurClient extends Imgur {
public ImgurClient(Stri... | stackexchange/codereview |
I'm creating a tool to analyze a card game which is played by three players. A Card is associated with a number of points and looks like this:
public enum Card
{
FIRST_CARD(1),
SECOND_CARD(2);
private final int points;
private Card(final int points)
{
this.points = points;
}
... | stackexchange/codereview |
As a follow up to my previous question I've improved the code + algorithm. The compression now works the following way:
Each character is followed by a length byte. The top 3 bits of that byte denote the number of additional length bytes which encode the count. The count is stored in "little endian order" (least signif... | stackexchange/codereview |
I have a tree view with a list of cars and a webservice to get the details for each car.
On page load, there are no cars selected so the details footer is loaded with all cars.
$.ajax({
type: 'POST',
url: '@Url.Content("/GTracker/Cars/CarTreeDetails")',
data: { "id": [] }, // not cars filter
... | stackexchange/codereview |
This is part of this topic.
Problem:
I need to read a file with BigIntegers and make some analysis "on-the-fly" with each read number (get prime numbers count, get armstrong numbers count). Right now I have this code, but it works very slow:
package ee.raintree.test.numbers;
import java.io.File;
import java.io.FileInp... | stackexchange/codereview |
At the moment, prtscn takes a server, and a list of port ranges to test (of the form x,y-z,a-c,d,e etc). The -v option will show all ports being scanned, and the -r option will return the first open port in the list. If -r is passed, the list of port ranges is optional. In this case, if the port list is missing, -r wil... | stackexchange/codereview |
My company develops a Spring web application that exposes a REST API and right now we're starting to look into pagination for the methods that load data from some heavy tables.
We initially looked into Spring Data JPA but had some difficulties in integrating the Repository logic so in the end I integrated only the bean... | stackexchange/codereview |
This is what the function is doing: it gets two arrays of tuples with 5 items each - hand = [H1,H2,H3,H4,H5] and board = [B1,B2,B3,B4,B5]
What I need to do is check all arrays formed by 2 items from hand and 3 items from board, like combination = [Hn,Hm,Bi,Bj,Bk] (100 combinations in total)
Then I need to compare each ... | 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 |
The following code clears 11 columns that contain lists that are used for data validation on another worksheet. This list is constantly changing due to records being added/removed from the source data. Basically I'm checking every value in a column, and if it meets all of my criteria I'm adding it to my data validation... | stackexchange/codereview |
Preamble: it's a self-assigned and pure syntetic task to learn (and remember what I already knew) C# threads and synchronization and data structures.
The original question was here https://stackoverflow.com/questions/16458937/synchronization-of-remote-files-download
The short task explanation:
Let's say I have a dictio... | stackexchange/codereview |
I have put together a small VBScript to gather a bunch of information and email at scheduled intervals, so that one day, should it happen, and my computers are stolen, I may be able to provide relevant and accurate information to the authorities to expedite their return.
I wanted to share what I have done in an effort ... | stackexchange/codereview |
This code is a multi-threaded version of filter that uses pipes to communicate between the workers and the main thread. I am looking for any ways to make this code cleaner. I'm also interested in if there is anything I can do to make this play nicely with infinite iterators.
from multiprocessing import Process, Pipe
fr... | stackexchange/codereview |
I have a PHP class:
<?php
//connectionclass.php
class connectionclass{
public $conn;
public $warn;
public $err;
function __construct(){
$this->connect();
}
private function connect(){
$this->conn = @ new mysqli('localhost', 'sever_user', 'user_password');
if ($this->conn->connect_error) {
$this->conn = ... | stackexchange/codereview |
Our Project architecture is AngularJS + MVC + WebAPI. Angular JS would call MVC action and MVC action further calls API methods. Below are some of the action methods we used for calling api methods.
Note that our project is in its final stage, and as such we cannot modify the existing architecture. We have to use Ang... | stackexchange/codereview |
I write a lot of mini apps. Each app has its own InputHandler for input from the keyboard. It's time to make a lib for that purpose - a CommandLineInterface.
NOTE: there exists a follow up Question here
Can you review my code on
Design
OOP
Clean Code
Naming (my bad englisch leads to bad naming)
Interface CommandLineI... | stackexchange/codereview |
When we select the 'info' list in the select field, the article with type 'info' characteristic automatically showed up, and when we select 'Berita' list in the select field, the articles with type 'Berita' characteristic automatically show up.
This is a long script that uses a post method. Can you help me make it sim... | stackexchange/codereview |
For some time it has been bothering me that there is apparently no way to directly initialize variables from input streams (something like int i << std::cin;)
My solution is this:
#include <iostream>
#include <iomanip>
#include <string>
template<class T>
T get(std::istream& in){
T tmp;
in >> tmp;
return tm... | stackexchange/codereview |
I'm learning PHP and I know too many ways to configure the application.
I use this method:
Folder:
app
config
app.php
db.php
src
class.php
index.php
File:
// app.php
return [
'environment' => 'development',
'meta' => [
'description' => 'Description',
'title' => 'Title'... | stackexchange/codereview |
Business Logic
I have a company referral form, and in that form I have dropdown to select from a company list. But when a company is not found in the dropdown, the user can select option as "others", upon which a textbox will appear. Now the user can add the company in the textbox and will fill rest of the "referral fo... | stackexchange/codereview |
I'm using Entity Framework 6 with database first. See the image for the relevant database schema
I have the following method to save a Set to the database:
/// <summary>
/// Saves the list of data sources. This assumes that the ModelTemplateID, SetNumber and TaskNumber
/// are already properly set. Adds a new record to... | stackexchange/codereview |
#!/bin/bash
# Used to add/remove printers from system (lp)
# Copyright Fresh Computer Systems Pty Ltd.
GREP_OPTIONS='--color=tty'
export GREP_OPTIONS
sanity() {
# Are we root?
if [ $EUID != '0' ]; then
exitError "You must be root to run this script." 1
fi
if [ ! -x /usr/sbin/lpadmin -a ! -x... | stackexchange/codereview |
I'm working on a GPyT (generative python transformer) project and I have written the below script to download lots of Python files from github.com to train my model. It works fine, but there is a problem I guess because it becomes slower with every file it downloads. It takes more time to download new files and while t... | stackexchange/codereview |
Any advice would be great. I watched a few videos over the last 3 weeks and made a program up; what do you think?
The program is a business ideal for a few computers in a shop, some computers with training and the rest of the computers without. (for gaming, etc.)
import java.util.Scanner;
public class n_com {
pu... | stackexchange/codereview |
Verifying the user's input is almost always required, even in really simple apps such as console calculator. Due to the wide variety of scenarios where this is useful I decided to make a few classes that will make the process easier.
I currently have 2 classes for validation, one for input that will require parsing and... | stackexchange/codereview |
Not sure this is the right place, but I'll have a try.
I'm trying to implement a mutex with capacity, which can be achieved easily with buffered channel like this:
var ch = make(chan struct{}, 1000)
func Enter(ctx context.Context) error {
select {
case ch<- struct{}{}:
return nil
case ... | stackexchange/codereview |
I have a dictionary of parameters and value, and the function creates a URL query string from it:
Private Function _BuildUrlFromPermalinkArgumentDictionnary(ByVal oParameters As Dictionary(Of String, String))
Dim returnString As String = ""
For Each kvp In oParameters
returnString += kvp.Key + "=" + kvp... | stackexchange/codereview |
Hello guys i wrote this function code:
function gematria(text){
var newText = text.toLowerCase(); // handle capital letters
var startValue=0; //initialize value to zero
for(let i=0 ; i<newText.length; i++){ // loop through every letter on the text
let currentCharValue = newText.charCodeAt(i) - 96; // get the... | stackexchange/codereview |
I often use a ViewModel class that contains a collection of Contacts and allows me to iterated through the collection with Previous and Next buttons.
I find that I've got duplicate versions of this class all over the place and I'd like to make my code reusable.
How would I go about making the following code reusable (i... | stackexchange/codereview |
TLDR: I don't develop for a living. If someone could point me in the right direction to make my script more readable/pythonic I would appreciate the assistance.
In particular I'm struggling with the charts found in makeCharts() and code-flow throughout.
I have tried writing makeCharts() section as a for loop for work... | stackexchange/codereview |
I made a piece of software that basically adds the functionality of a compose key to Windows, after switching from one keyboard layout to another (for programming reasons), and being unable to find a piece of proper software that did what I wanted.
This was my first venture into making applications for Windows, never t... | stackexchange/codereview |
I have created several mixins for a button to attempt to reduce duplication and contribute to the overall improvement of performance. I am looking for guidance on how to tighten this up so it is as DRY (Don't Repeat Yourself) as possible. Or is it already as DRY as possible?
Here is the code:
// mixin - button shape
... | stackexchange/codereview |
I'm a total newbie at parsing, so I figured I'd start by writing instances of Read for HList, which does not currently have them. I'd appreciate some feedback on the following:
{-# LANGUAGE
DataKinds
,KindSignatures
,FlexibleContexts
,FlexibleInstances
,TypeOperators
,GADTs
,ScopedTypeVariables
#-}
module MyH... | stackexchange/codereview |
I made a simple program in which I compare two images pixel by pixel and determine if the pictures are the same. I'm trying to adapt it to MPI, but I'm afraid that the communications are taking too long, making it way more inefficient than its sequential counterpart. I have tried with images of very big resolution and ... | stackexchange/codereview |
I have telerik radgrid that has an SQL backend. What this function is doing is conditionally formatting the cells with in the radgrid. It checks each column to see if the min and max values are within range and the min and max values change depending on the value in the sample_hour column. My question, is there any mor... | stackexchange/codereview |
I have this Java class for producing rotations of an input string:
StringRotator.java
package net.coderodde.util;
import java.util.Objects;
/**
* This class implements a data type for rotating strings.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Mar 24, 2016)
*/
public class StringRotator {
/**
... | stackexchange/codereview |
Is this okay?
public class BaseRepository<T> where T : class
{
private readonly DbContext _dbContext;
public BaseRepository(DbContext dbContext)
{
_dbContext = dbContext;
}
public T Get(Func<T, bool> predicate)
{
return GetAll(predicate).FirstOrDefault();
}
public IEnu... | stackexchange/codereview |
I'll start off by saying I'm way off in how this should be done. After spending much time on getting this to be clean it wasn't going to happen so I just did it anyway I could.
I'm trying to make some FlxStates that will show off some nice menus that I want to create. What I'm doing in this code is moving UI buttons f... | stackexchange/codereview |
I would much appreciate your advice on this design I am going to implement. I am relatively new to object programming and I am not so sure about the delegate pattern.
I need to provide the implementation of a class that implements several interfaces of different nature. As the class would be huge I am thinking on using... | stackexchange/codereview |
Recently me and colleague had a discussion about the following piece of code (simple bool function that checks if string is a number, +1000 not allowed, -1000, 1234 ... allowed).
He felt that it was hackish, while I thought it was nice, clean and elegant (since it uses STL, not hand made loops).
So is this a judgemen... | stackexchange/codereview |
Here I have some simple code that worries me, look at the second to last line of code, I have to return spam in order to change spam in the global space. Also is it bad to be writing code in this space and I should create a function or class to call from that space which contains most my code?
I found out very recently... | stackexchange/codereview |
What do you think about my implementation of linked list, which gets values from keyboard? I implemented three basic functions: print, insert and size.
class Node:
def __init__(self):
self.data = None
self.next = None
class LinkedList:
def __init__(self):
se... | stackexchange/codereview |
My context is a very simple filter-like program that streams lines from an input file into an output file, filtering out lines the user (well, me) doesn't want. The filter is rather easy, simply requiring a particular value for some 'column' in the input file. Options are easily expressed with argparse:
parser.add_argu... | stackexchange/codereview |
I was solving the 3rd problem at Project Euler which requires me to calculate the largest prime factor of 600851475143 which I think is a really large number (more than 6 billion).
QB64
At first, I tried solving this problem using QB64.
CLS
n = 600851475143
FOR x = 1 TO n
IF n MOD x = 0 THEN
FOR y = 1 TO ... | stackexchange/codereview |
StringBuilder class is a common class that many have become accustom to, including me.
An individual posted a question regarding if there was a comparable method in typescript. Several solutions were mention or linked, but none contained a class. Here is a small class that embodies some of the common StringBuilder meth... | stackexchange/codereview |
I decided to try make my own way to save normal python data yesterday after coming across the minecraft NBT format, it's more limited than cPickle but appears to produce shorter results and so far works reliably (if a little slower). It works on the type of the input, and is currently compatible with bool, int, str, di... | stackexchange/codereview |
I'm using the command pattern to enable actions in my game to be undoable. ICommand defines individual commands, ICommandHandler does the undo-redo logic and might be decorated with other handlers like logging etc.
public interface ICommand
{
void Execute();
void Undo();
}
public interface ICommandHandler
{
... | stackexchange/codereview |
The idea is to add a given 16-bit number N to each element of an array of 16-bit integers of arbitrary length, taking advantage of 64-bit integer types and instructions to perform the additions 4 at a time. The function accepts an arbitrary nonzero length. As far as I can tell there is no undefined behavior, but I woul... | stackexchange/codereview |
I have been changing this code and I don't get to make it much better. I changed a little bit the structure, reimplemeted a new function for splitting Strings which is more efficient, etc. I have been tested with MR-Unit (it's part of map-reduce code).
I'm testing the code with 1.5 millions calls. It takes about 35 sec... | stackexchange/codereview |
I have implemented the following logic: a base class, Animal, has a vector, friends. A derived class, Dog, then inherits from Animal.
I then want to implement a set_friends() function that can be passed a Dog object and then fill its friends vector. I then want to be able to call print_friends() from the base class to ... | stackexchange/codereview |
I passed a technical test the other day, one part included a cheap string validation and I am wondering this can be further improved to be more versatile to requirement changes.
The requirements were something like that
Create a Validate method, which accepts a string and returns true if it's valid and false if it's ... | stackexchange/codereview |
I'm looking for a very simple (at first sight) CommandBus, which will handle some ICommand publication. The CommandBus implementation will find the appropriate IHandler to Execute the Command and then Notify some possible IObservers.
My first step is to make it work, I've chosen to use a synchronous dependency injectio... | stackexchange/codereview |
I would like you to take a look at this simple script I wrote that's supposed to emulate the Unix sort [FILE] | uniq -cd command. What's different about my script though is that it also lists line numbers telling the user where occurrences of duplicate lines are located in the file. Please, tell me what you think as we... | stackexchange/codereview |
Suppose we have stock price history, and we are allowed to buy only once and sell only once. The problem is to find the maximum profit we can make. Here is my code that I tested for basic test cases. I'm wondering if there are possible improvements for logic correctness.
My major idea is to keep record of in history mi... | stackexchange/codereview |
I've created a lock-free job queue and with the tests I've written, which is also very fast.
That makes me doubt my benchmark procedure, so I'm hoping the collective knowledge will shed some light on the validity of those.
The test basically increments an atomic value (each job is a single increment) until the predefin... | stackexchange/codereview |
I'd like some tips on optimizing the following code.
I'm a bit concerned that I'm 'polluting the global namespace' by not wrapping it in a function. The commented out var rotator { init { came from a JavaScript tutorial but I'm not sure it's the jQuery way? Should I wrap it in $(function()... instead?
$(document).ready... | stackexchange/codereview |
This is my first attempt at refactoring - FindIngredients and I'm wondering where I can improve. The github link in the code directs to the project that still has the old code.
The user has data validated selections to make in cells B2 through H12 on Sheets("Plan"). Each type of meal has certain selections from the ing... | stackexchange/codereview |
Can someone review this?
The header file can be viewed here.
#include <stdio.h>
#include <stdbool.h>
#include <math.h> // searches default library classpaths
#include "Rational.h" // searchs my directory
// let's the compiler know that this is a function
static bool Rational_isPositive(Rational rational);
static double... | stackexchange/codereview |
I had to write a cycle that loops a log file and assigns a given status according to some logic.
I didn't post the whole code but this is the script that bugs me the most... why?
Well, first:
I thought I was writing OO... but I guess, I didn't
Each import from Status is an Enum, it might be wrong, and I auto-assign e... | stackexchange/codereview |
The standard library heapq in python doesn't support updating keys as a public method, which makes it hard to be used as a priority queue. Although the official documentation has suggested a workaround, it is somewhat convoluted. So I decided to implement my own priority queue as a min-heap.
Here is my code:
class Heap... | stackexchange/codereview |
This library management program can do following functions:
Add a book to the library
Display all available books
Lend books to students
Return books to the library
Display students who have yet to return a book
Question: How do you refactor this code so that it follows OOP, reads better, is manageable and is... | stackexchange/codereview |
The idea here is to pick a skill at random for the player each round. Four skills will be chosen, they are all random, and the same skill can repeat multiple times.
The player has a skill level for each ability. The higher the skill level, the greater the chance that the skill will be chosen.
Rather than use floats a... | stackexchange/codereview |
I have been woring on AJAX and JQuery site. Here is my simple implemtation. i am looking forward to getting your reviews for any improvement/replacement for code mentioned below.
Brief explanation: when someone want to submit the form with specified ID, all form fields are assigned to appropriate variables. After that... | stackexchange/codereview |
Permutate() is supposed to generate all possible permutations of the source sequence:
foreach(var s in "abc".Permutate())
Console.WriteLine(s); // abc
// acb
// bac
// bca
// cab
//... | stackexchange/codereview |
Generate a linked list of any type using macros. The linked list contains functions for adding and removing elements to both ends and also at the middle. You can also add elements relatively to a list node. It also comes with an iterator that can go back and forwards through the list.
Macros that generate a linked list... | stackexchange/codereview |
Inspired by this post, I wanted to be able, in any vba project I could be working on, to create a test class and write test methods. Like this:
ThisWorkbook Workbook | class module (client code)
Option Explicit
Public Sub TestAreEqual()
Assert.AreEqual 12, 34, "Values should be equal."
End Sub
Public Sub TestAr... | stackexchange/codereview |
So I've written a URL router which also allows for wildcards (path parameters).
A URL like /users/{uuid} can be added and then, when a user sends a request to the server with the following target /users/955b2a88-ae80-11ea-b3de-0242ac130004, the uuid will then equal 955b2a88-ae80-11ea-b3de-0242ac130004.
Example:
PathMat... | stackexchange/codereview |
I will admit that this code looks sloppy and repetitive. Which is why I'm asking how I can improve the efficiency and readability of this code.
// Sidebar tab highlight when clicked
$("#sidebar-tabs-container table td").click(function() {
$("#sidebar-tabs-container table td").removeClass("sidebar-tab-selected");
$(... | stackexchange/codereview |
I'm trying to devise a tkinter gui, that, among others, lets users choose a 'working folder' and a 'destination folder (and there is more coming). I stripped the code to its bare functionality hereunder.
I found myself duplicating code for the selection of both the 'working folder' and the 'destination' folder. I came ... | stackexchange/codereview |
I have several hundreds gigabytes of photos, approximately half of them are duplicates. Average photo's size is about 4 MB, but some files (video) have size more than 100 MB.
I want to do the following:
Find all duplicates and move them into the separate directory - "Trash_bin".
Move all unique files into a "Unique_pi... | stackexchange/codereview |
Does anyone have any recommendations for how I could make this async.waterfall call neater? Ideally I'd be able to do something like:
async.waterfall([
serializeUser(user_id),
generateAccessToken(user_id),
generateRefreshToken(user_id)
], function(error, results) {
//my user, access token, and refresh token a... | stackexchange/codereview |
I currently have an implementation that helps us deduplicate data but I know it's slow.
Here's an example, note that I'm using OpenStruct here when really these are Mongoid objects pulled from the database.
require 'ostruct'
vendor_data = [
OpenStruct.new(activity_id: "abc123"),
OpenStruct.new(activity_id: "def456... | stackexchange/codereview |
Dynamically growing arrays are a type of array. They are very useful when you don't know the exact size of the array at design time. First you need to define an initial number of elements. (Wikipedia)
I have written a Python solution and converted it to Cython.
Cython can be used to improve the speed of nested for loo... | stackexchange/codereview |
The HexToString function returning maximum of 16kb even for sources greater than 16KB
string HexStringToString(string HexString)
{
string stringValue = "";
for (int i = 2; i < HexString.Length / 2; i++) // Starting from position too just to avoid the 0x Hex Code that messes stuff up
... | stackexchange/codereview |
I am trying to track relationships among people. I came up with my own solution, but I'm wondering if there might be another way or better way of doing this. To keep it simplified, I'll post just the bare bones.
Let's say I have created the tables: person, person_relation, and people_relation for a MYSQL database using... | stackexchange/codereview |
Thanks in advance for your interest in my first PyPI project.
While there happen to be a number of projects out there to help with creating & consuming Excel workbooks, I was unable to find one that made working with pywin32 any easier, so I built it myself. Using pywin32 for automating Excel with best practices happen... | stackexchange/codereview |
I am trying to grasp the concept of delegates and protocols in Swift. So I have implemented my own PlayableMedia protocol with two concrete classes BlueRayMedia and DVDMedia like so:
protocol PlayableMedia {
func play()
func stop()
}
class BlueRayMedia:PlayableMedia {
func play() {
println("BlueRa... | stackexchange/codereview |
My favourite 3rd party library isn't getting maintained so now I need to make my own library for interfacing with Riot Games' API. Epic.
Problem is that there are rules, such as:
100 requests in 2 minutes
20 requests in 1 second
So I made an API request scheduler.
import asyncio
import time
from collections import de... | stackexchange/codereview |
I came up with this small implementation of an Okapi BM25+ ranker using Ruby. I cooked it up in a very short time so it's very simple but I'm trying to think whether there's a better way to write it. In particular, I'm wondering if I should have something like a Ranker class -- intuitively I feel as though I should but... | stackexchange/codereview |
I'm taking a text file that looks like this:
77, 66, 80, 81
40, 5, 35, -1
51, 58, 62, 34
0, -1, 21, 18
61, 69, 58, 49
81, 82, 90, 76
44, 51, 60, -1
64, 63, 60, 66
-1, 38, 41, 50
69, 80, 72, 75
and I'm counting which numbers fall in a certain bracket:
f = open("//path to file", "r")
text = f.read()
split = text.spl... | stackexchange/codereview |
I have previously asked here for a review of my Pong game. Since then I have implemented most of the recommendations but I'm not sure I did so correctly, the result can be found on my github.
Would it be possible to get another review? Below is the whole source code of the game:
main.cpp
/*
* Pong game
* Author: Ch... | stackexchange/codereview |
A few weeks ago, I developed a terminal game that increases your typing speed. The game is all about typing, providing difficulty levels from easy to hard. I feel like this terminal game won't become as popular as my others, so I need tips on how I could improve this code to make it shorter, easier to run, and more ent... | stackexchange/codereview |
I am solving Word Break II from leetcode:
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences.
Note:
The same word in the dictionary may be reused multiple times... | stackexchange/codereview |
I have a class that is all about doing HTTP requests, and logging (in file system & database). It's only using 3 dependencies to do these things, so I'm fine with the code so far.
Here it is for convenience :
<?php
namespace App\Services\Pivotal\Request;
use App\Core\Request\HttpRequest;
use App\Core\Request\Log\Requ... | stackexchange/codereview |
I was assigned the connected components labeling (CCL) algorithm and in order to implement the CCL algorithm I first had to implement the Union-Find algorithm.
This is my try at it, any review and tip would be greatly appreciated
classdef UnionFind < handle
properties
PARENT = containers.Map('KeyType', 'doub... | stackexchange/codereview |
I've seen a number of questions on Stack Overflow of the kind of "How do I sort on fields X AND Y?" The most common answers to those questions consists of "Write a custom Comparator."
But what if you have 3 fields you can sort on? Or 13? or 300? My solution is this utility class, so that rather than writing a billion d... | stackexchange/codereview |
This is the K&R Exercise 1-14 of C. The exercise ask you to print a histogram of the frequencies of different characters in input. How can I improve my code? The main doubt is the part when I have to increase letters in the array.
#include <stdio.h>
#include <ctype.h>
int main()
{
int ch,
nwhite,
... | stackexchange/codereview |
I want to have 2 separate pages at the root URL for logged-in users and logged-out users. (at "/").
After advice on this sub, this is what I've come up with, using parallel routes. But is that OK, or can be done better:
/layout.tsx:
import './globals.css'
import type { Metadata } from 'next'
import { Inter } from '... | stackexchange/codereview |
This was a portion of a skills test given to me by a company. The task was to write a method that takes a string, reverses it, and sets the vowels as capitals and consonants to lowercase. I was also told to prove that my implementation works.
using System;
using System.Diagnostics;
namespace StringOperation
{
usi... | stackexchange/codereview |
I have a basic websocket server implemented in C++. I'm using Intel TBB's concurrent hash_map to store all the users, uniquely identified by the id. The concurrent hash map will hold a key value pair of <int> and <std::set<string>> where the int is the user's id, and the <std::set<string>> is a set of all instances of ... | stackexchange/codereview |
I have written code to check any birthday input's validity. As I am new in programming, and after going through several debugging steps, the code became very ugly.
month_dict = {'jan':'January',
'feb':'February',
'mar':'March',
'may':'May',
'jul':'July',
'sep':'Septembe... | stackexchange/codereview |
I have a program that searches for prime numbers in an array specified by the user. The program starts by asking how big the user wants the array to be, then asks how many threads to split the computations.
I tested 1000 numbers, 10,0000, 100,000 and 1 million, and they all yielded results in a fairly reasonably time.... | stackexchange/codereview |
I'm currently developing a TYPO3 Extension in PHP and developed a Hook.
TYPO3 has the concept of Hooks where you can execute your own code as specific points. As defined in our definition of done, we want to PHPUnit-test our code base.
I did some small tests before, so I'm familiar with the basic concepts. Below you ca... | stackexchange/codereview |
As an old COBOL coder, all this OOP stuff is foriegn. Would someone please take a look at this program? I'm looking for suggestions for ways to improve this program. While it works, I'm sure there's many way to make it better, particularly in the areas of memory management, OOP methodology, and idioms. Any advice is we... | stackexchange/codereview |
I'm trying to get a good grasp on recursion by implementing document.getElementsByClassName. I've made something that works but I'd like to know if there is some blatant refactoring that should be done or perhaps some not-so-edge cases that might break it.
var getElementsByClassName = function(className){
var result ... | stackexchange/codereview |
This is code for finding if inequality \$abc > 2(\text{area of triangle})\$
where \$a\$, \$b\$ and \$c\$ are the sides of any triangle.
The below, and repl, code work as intended. However they take a long time. Can the performance be improved without reducing max_tries?
import random
import math
hn=100000000
num=0
ma... | stackexchange/codereview |
The program below correctly calculates factorials, until the limit for an unsigned long long integer is exceeded.
My question has to do with loops and exiting loops. The program uses one infinite while loop and the break statement to exit 2 while loops.
Do working, professional programmers handle loops this way? If not... | stackexchange/codereview |
I wrote a bash script for the Raspberry Pi 3 (Raspbian) which has the main task of setting up a LAN to WLAN router. In addition it makes some things nicer for the intended users who have Windows background only. It will be used on a Pi 3 with built-in WLAN and the official 7" display only.
Preconditions to run the scri... | stackexchange/codereview |
Please give me some pointers on how I can improve this project with Python 2.7.
import json
import urllib
urls = ["https://data.calgary.ca/resource/kqmd-3dsq.json","https://data.calgary.ca/resource/4wni-k3sg.json"]
print " \nThis is Json Data Parser Program. \nThis program will print the Unique Voting Station Name from... | stackexchange/codereview |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.