instruction stringlengths 71 71.9k |
|---|
I would like to improve everything that can be improved. I don't understand regex a lot and what could be wrong. The main improve that I am looking for is related with errors. I want make the code robust to deal well with all kinds of errors. I could try to run in production and wait to see the errors, but I can't. At ... |
This is a working program I made to roll dice a specified number of times, show how many times each number (2-12) occurred, and the percentage of the total rolls that each number got.
I'm trying to make improvements to the efficiency of my code. I've already found one, as noted beside int[] results on line 15. Are ther... |
I've recently begun to teach myself to code. One simple project that I wanted to do was create a Caesar cipher that works well. Now that I feel I've accomplished that task, I'd like to know how I'm doing with overall code quality. Here's the code.
import java.util.Scanner;
public class Encryptor
{
private char[] ... |
I've been studying computer science for around two school terms now. Currently, I'm making a Caesar Cipher program as a base for my examination, this is so that I can use the 15 hours to either add, or improve my code. Please, give me some feedback on how to improve my code or, at least, make it clearer.
class Function... |
It would be great if I could get this code reviewed.
I would love tips on how I could improve my code.
Problem
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 of all available items. From this list you would like to buy two items that add up... |
I'm currently creating a game engine for my personal project.
And I'm currently implementing Entity and Component System.
Classes and Interfaces Definitions
Here the classes and interfaces that involved to this problem:
Entity: abstract class for any entity in the game, it does not implement any interface or class. ... |
I've completed the small challenge in the eloquent JS book to create a chess board pattern:
Write a program that creates a string that represents an 8×8 grid,
using newline characters to separate lines. At each position of the
grid there is either a space or a “#” character. The characters should
form a chess bo... |
I have a code which checks if any of the 4 textfields on our server contains text. If even one of the four textboxes is not empty, the generated table won´t skip that row and will draw it, otherwise the row will be completely skipped and not shown in the table.
For that I declared the variables for the words and the B... |
I am working on an app in which I need to get destination list from server and set it in autocomplete text view. I am using text watcher and on its onTextChanged event I am fetching destinations data using async task. My problem is I am not sure that am I doing it in a right way. Please review my code below
FragmentHot... |
I'm learning PHP, HTML and SQL - and wondered if anyone could take a look at this code and give me some feedback?
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
<title>Store product information</title>
</head>
<body>
<?php
$host = "localhost";
$database = "shopDB";
$us... |
Yesterday I had posted a question regarding optimizing editMethod here on code-review. Thanks to an awesome answer by Pimgd, I was able to merge conditional checks, checking conditions and few other things.
I am posting this as a follow-up question for the other question for further optimization of the method. All sug... |
This is the code for an AngularJS controller that I've written:
app.controller('employeeController', function (employeeService) {
var Controller = this;
Controller.employees = {};
Controller.fetchedEmployee = {};
Controller.populateTable = function (data) {
Controller.employees = data;
}... |
I'm a .net programmer with littler experience in AngularJs and Javascript.
I have implemented an AlertService, AlertsController and Alerts view for alerts/notifications in my system. PaymentService is a service that uses the alert service to notify user of things.
Could you please give me any comments about my code?
A... |
I made this Tic Tac Toe game and I would like to know your opinion and what can be improved. I also want advice about making it check if someone wins. I'm 10th grader, so I still need to learn a lot.
#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
char x1,x2,x3,x4,x5,x6,x7,x8,x9;
int x, i, a;
... |
I tried to write a lock-free list in C++. Unfortunately, the performance compared to an std::list secured with a simple mutex is bad.
What do you think? Are there major performance or code-style issues?
#include <atomic>
template <typename T>
// lock-free list-container
class lf_list {
// ~~~~~~~~~~~~~~~~~~~~~... |
I am looking for the elements that are zeroes in a square matrix (of size n), as a list of pair. I don't really like the following code, some condition seems rendundant but my knowledge of OCaml is limited and I can't find an elegant way to refactor it:
let find_zeroes input_matrix n =
let rec aux i j n =
i... |
Intro to Computer Science project here. Calculates the hat, waist, and jacket size of the user when given age, height, and weight. Seems to output correctly.
Here are the guidelines for the assignment.
Write a program that asks for the user’s height, weight, and age, and
then computes clothing sizes according to t... |
I am going deep on this array in order to make an id comparison. I want to know if there is a way to use like a kind of flatten function to avoid using _.each the way I am using it because I think it is not a good practice.
.json file:
[
{
"enterprise" : [
{
"id" : "743512",
"name" : "Hellen... |
I need to find the percentile where a list of values is higher than a threshold. I am doing this in the context of optimization, so it important that the answer is precise. I am also trying to minimize compute time. I have a O(n) solution which is not very precise, then I use scipy's minimize optimizer to find the exac... |
I have the following code made to output the following:
Is there an efficient way to simplify it and not have to repeat the same if(!empty($st[$i]['feedback'])) { code block 2 times just to seperate 2 feedback lines with a echo '</div><br><div class="row center">';?
<?php
//Get 4 Feedback from Database;
$st = fetch("... |
name = company_location
for i, j in enumerate (list):
if j == 'Last 10 Accidents':
last = i
try:
date1 = list[last+28]
employee1 = list[last+31]
days_lost1 = list[last+49]
days_paid1 = list[last+43]
with open("report.csv","a+") as report:
... |
I need to calculate the minimum number of jumps to reach the end of an Array with dice throw.
Array values may be negative/positive:
When positive - move forward
When negative - go back
The array may also contain an R value, which means that the player have to throw the dice again.
The start position is marked on ou... |
(See the next iteration.)
I have this tiny library for building HTML pages in Java code:
HtmlViewComponent.java
package net.coderodde.html.view;
/**
* This abstract class defines the API for logical HTML view components, that
* may consist of other view components;
*
* @author Rodion "rodde" Efremov
* @version ... |
I want to generate statistical reports and I have many different where clauses so the function became long. I did much refactoring, but it is not enough. Can someone help me with some techniques that these techniques make the function short and easily readable?
public static function allRejUserByProv($prov = '', $gende... |
I posted a similar question “Curious Numbers” (HackerRank PE 34) recently (but in a different language/platform altogether). I'm starting to learn JavaScript and decided to take the challenge again and adapt it to this language's features and quirks.
While I could have written many of the functions below using for-loo... |
Inspired by a PPCG answer, I wrote this code, which shuffles the autoboxing caches of Number subclasses.
This leads to, among other things, outputting 2 + 2 = -72 after invocation of EvilStuff.doEvilStuff(Class<? extends Number>,String,int). (The result differs for different invocations, due to reshuffling).
I use a s... |
(See the previous (and first) iteration.)
Now, I have incorporated all the modifications proposed by janos, and, thus, I have the following:
HtmlViewComponent.java
package net.coderodde.html.view;
/**
* This abstract class defines the API for logical HTML view components, that
* may consist of other view components... |
I am currently making Pong in C++/SDL2 and after a while of tinkering, I have come up with a solution!
This function gets the hit position and returns the necessary direction change:
MoveDirection Ball::getHitPos(const Player& player) const
{
MoveDirection dir; //Direction of movement
//If ball is moving left
... |
I would like to get my code for implementation of simple sorting algorithms in idiomatic python code reviewed. I am looking for feedback on python idioms used, better ways of doing the same thing. I am familiar with FP, and I am willing to put in effort to get myself familiar with pythonic idioms such as list comprehen... |
I'm currently attempting to learn Haskell after a fair history of imperative programming. When I saw the Pizza Hut Pi Day math problems, I thought the first one would be a good candidate for my Haskell experimenting. The question is:
I’m thinking of a ten-digit integer whose digits are all distinct. It happens that t... |
This program uses UDP broadcast to find app servers on the local network. When a server receives a client broadcast, it sends a port (integer) to the client which will later be used to create a TCP connection.
The Server portion of my code is written in C#. The UdpPoller method returns an IObservable<IPEndPoint> which... |
I have inherited a PHP base class for an API call to a music provider.
It is functional, however it makes me feel that there are some "magic" nature behind it that makes me un-easy (or maybe I'm not knowledgeable enough to understand it completely).
After initializing the apiObject I can make calls such as:
$results = ... |
The function wants to achieve to find all distinct subsets that sum up to an given number.
results = []
def rec_subset_sum(current_elements, available_elements):
for i, inspected_element in enumerate(current_elements):
# Get list of all smaller available elements
smaller_elements = [q for q in avai... |
I want this to be similar to the STL algorithms but I don't find it elegant nor concise at all:
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
using E = double;
template <typename IT>
E std_dev(IT begin, IT end){
auto N = std::distance(begin, end);
E average = std::accumulate(be... |
I decided to finally write up a Tic-Tac-Toe implementation. Since I'm currently learning web development, I decided to write it in JavaScript.
My main problem, and what I want reviewed here is my checks to see if there are any winning plays on the board.
I figured the easiest way to start out with would be to "brute-fo... |
This is basically a program that takes the first line of a file and makes a map using ggGgg h gGgGg s makes ggGgg equals h and gGgGg equals s. Now the rest of the file makes sentences with these. Idea is from here.
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <map>
#include <stde... |
This question has already got some reviews, so I could partially improve my code: please look at my self-answer below, which also contains comments about the review.
I'm frequently interested to answer SO questions regarding (JS) objects and/or arrays manipulation.
When providing a snippet, and if the actual result lo... |
I have created an application that I will be using for pentesting. It creates a list of random IP addresses, pings them, and adds ports to them (but it's not complete).
It works exactly how it should, and I just want to know if there's a better way to write this specific aspect of the program.
require 'colored'
require... |
Since I have my own virtual machine and an assembler for it, I decided to test it with a FizzBuzz implementation. I have this:
fizzbuzz.toy
const reg4 100
const reg2 1
loop_begin: // The main loop counting from 1 to 100
add reg2 reg1
cmp reg1 reg4
ja end
pusha
push reg1
call print_func... |
Executive summary
The twist is that the consumers do not consume, they just read. The producer makes items continuously in one of two alternating slots. Readers read from the other slot. When producer comes up with a new item it waits until readers are done with their read slot (that would become the new write slot). T... |
I've written an event dispatcher for a private project which task is to collect events from different threads and dispatch them in a single thread:
namespace events
{
namespace
{
// unfortunately make_unique is not part of c++11 so we use our own
template <typename T, typename... Args>
std::unique_ptr<T> make_unique(Ar... |
I've made a simple netcat in Python and would appreciate any advice/opinions of how I've implemented it.
test.py:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import netcat
def main(*args):
netcat.connect('localhost', 4444)
netcat.listen('', 4444)
if __name__ == '__main__':
sys.exit(main(*... |
This bit of code initializes an array of any given size where each index corresponds to a thread and a value. That is, index 0 has 0, index 1 has 1, and so on. Then, the values, 0 to n, in the indexes are summed.
This code as part of an assignment though I'm wondering if there are any ways it could be improved? Namely... |
I have created a Bukkit/Spigot plugin for Minecraft servers because I wanted to change the dynamic of mining to prevent people with really bright monitors or the Fullbright mod from being able to skip using torches when mining.
I created this plugin a while back when I used to run a Minecraft server, but since then hav... |
To learn about concurrency in Clojure, I wrote a function that accomplishes the following:
Takes a (possibly lazy or infinite) sequence of functions representing tasks to be run asynchronously
Runs the tasks asynchronously and in parallel
Immediately returns a lazy sequence of promises that can be deref'd to get the r... |
I have a piece of Clojure code that reverses a string recursively.
It is working but too slow (because I got the problem from Codewars and I cannot validate it before it timeouts).
The algorithm is :
take a string ex. "abc" and reverse it (r "abc") -> "cba"
take the first position and reverse from there "c" + (r "ba")... |
I use console a lot, so I thought this may help me. It's supposed to be simple, safe, and fast. Any ideas?
http://ideone.com/INXub0
#include <iostream>
using namespace std;
class Console
{
public:
template<typename ...Args>
static bool WriteLine(const std::string& format, Args&&... args)
{
bool suc... |
You are given a list of \$N\$ people who are attending ACM-ICPC World Finals. Each of them are either well versed in a topic or they are not. Find out the maximum number of topics a 2-person team can know. And also find out how many teams can know that maximum number of topics.
Note Suppose \$a\$, \$b\$, and \$c\$ are ... |
Previously asked here.
I would like to get my code for implementation of simple sorting algorithms in idiomatic python code reviewed. I am looking for feedback on python idioms used, better ways of doing the same thing. I am familiar with FP, and I am willing to put in effort to get myself familiar with pythonic idioms... |
This question is everywhere, and I looked at many answers. A lot suggest using mysql_real_escape_string but that isn't an option, since it's depreciated now.
Being a rookie at PHP/SQL and especially when it comes to security, I can only hope some of you may be able to help out here. I know for a fact that some of thes... |
This parses two digits and returns the rest of the string.
Input:
"20asg"
Output:
{ number: 20, left: "asg" }
Input:
"9asg"
Output:
{ number: 9, left: "asg" }
function readDigit(str) {
var digitMap = {
0: 0,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
9: 9
};
var ... |
Does the following code is written correct witout redundant code ?
or maybe using Jquery it can be written better?
I need to find matching between properties insdie oData & oPushObj
and fill aSelData with this content.
This code is working as expected
jQuery.each(aDataCollection, function(iIndex, oData) {
... |
I have a system that only outputs reports in Excel 97-2003, and a second system (for the user to look at) that only accepts these reports in CSV format. The reports manager was previously opening each of the fifteen XLS reports, find/replacing all the commas with semicolons, saving as CSV, and renaming each file to th... |
I built this auto registering registry to look into a package and import all modules and register any classes that are a subclass of a base class. I use it as a registry for a model's choices in Django and to be able to do a getattr on the class to get properties in a service that processes some data based on choices s... |
At first, I created an unbeatable Tic-Tac-Toe game in Python. However, I wanted a better interface, so I used a PHP backend that runs the script and simple JavaScript that sends user commands to the script.
index.html: (excuse stupid class names)
<html>
<head>
<script src='jquery.js'></script>
<link rel="shortcut i... |
Problem from hackerrank:
You’re given the pointer to the head nodes of two sorted linked lists.
The data in both lists will be sorted in ascending order. Change the
next pointers to obtain a single, merged linked list which also has
data in ascending order. Either head pointer given may be null meaning
that the corres... |
I'm looking for some feedback on my lock-free queue, based on Disruptor, mainly for any potential concurrency issues, such as where I need additional fences. It looks correct to me, and I can't seem to able to break it, but I'm only testing it on my x86 machine.
#pragma once
#include <atomic>
#include <cstdint>
templ... |
To test the queue I perfected from one of my CR questions, I've developed a maze program that receives an input maze, starting and end positions, and solves it. I have separate software that handles the maze execution and file parsing. I'm curious as to whether my implementation is optimal (fully expecting it to not be... |
I've been learning F# for a month or so and I'm wondering how good my "functional" aspect of coding is. When I first started, I did this using an iterative approach with a lot of <- and mutables etc. I tried to rewrite it as functional as possible. Any critique is appreciated.
This code prints out all anagrams in the e... |
I made a calendar that displays text documents according to month. Thankfully it works, although I could really use some help how to make it more better looking and efficient. I'm new to programming but I have horrible organization skills, and can't really understand the concept of classes, and __init__.
from Tkinter i... |
My code communicates with a Raspberry Pi (with a static IP address) running on a network. The client sends a signal to the Pi, and the Pi sends back a double (encoded as a string) with the angle correction needed for another routine of the code (the Pi does some image processing, but that doesn't matter).
The main exec... |
I'm trying to solve PRIME1 in SPOJ with the following Scala snippet:
Peter wants to generate some prime numbers for his cryptosystem. Help
him! Your task is to generate all prime numbers between two given
numbers!
Input
The input begins with the number \$t\$ of test cases in a single line
(\$t \le 0\$). In each... |
I wrote this together for a test I'm doing that parses the Heroku access log. What I'm mainly interested is if this code follow common best practices and if there are any improvements I can make in terms of memory efficiency.
Here is a line from the Heroku from their docs:
2010-09-16T15:13:46.723498+00:00 heroku[route... |
I've just completed the Gilded Rose Refactoring Kata in Java. I took the approach that I would fully characterise the existing behaviour with 100% unit test coverage before refactoring.
Although this got me there, it took me about 2 hours and got me thinking - is there another approach to testing that would facilitate ... |
Given a string representing of an IP address, such as "127.43.23.59", return a 32 bit integer representation of this string. The 32 bit integer is separated into four bytes, where each byte is one of the numbers in the string, separated by dots. If you & 0xFF with the returned integer, it should return 59. If you & 0x... |
(See the next iteration.)
I have this command line program for computing GPA (grade point average). Given credit sequence \$\langle c_1, c_2, \dots, c_n \rangle\$ and grade sequence \$\langle g_1, g_2, \dots, g_n \rangle\$ (I assume European grades, i.e., \$g_i \in \{ 1, 2, 3, 4, 5 \}\$ for all \$i \in \{1, 2, \dots, n... |
I have got it working in a way so that there is one superclass, MathObject. In this implementation there is only a Constant subclass. I was forced to implement an abstract MathObject add(MathObject that) and an abstract MathObject add(Constant that) for reasons.
I would like to get that abstract MathObject add(Constant... |
I'm playing with Haskell's list comprehensions, tuples, and foldr.
The exercise I've given myself is to find all triangles with a perimeter of length 26 in the set of triangles whose edges range from 1 to 10 in length.
main = do
print triangles
triangles = [(a,b,c) | a <- [1..10], b <- [1..10], c <- [1..10], hasPeri... |
I made a small demo in JavaScript using HTML5 canvas, which renders a rotating sphere. The sphere is generated by first creating a set amount of points (currently 50, represented by vectors) randomly, then choosing the one with the highest distance from the already generated points, so I get an even distribution, then ... |
When iterating over the members of an object for logging the keys / values one gets a "stair case" effect.
Therefore I wrote myself this function which takes care for a left-alignment of the values.
Any hints concerning flaws and improvement-recommendations welcome.
// #### START TEST #######################
var pers... |
I have written a function that is designed to convert an object into an array of key/pair values ("flattening it") like so:
Input
{
"a": true,
"b": {
"c": 500
}
}
Output
[
["a", true],
["b", [
["c", 500]
]
]
Here is the code I have written to do it:
function isCyclicObject(object, seenObjects) {
... |
I'm currently working on building a simple REST API using Ruby on Rails. I noticed that a lot of the things I did were a bit redundant, especially the models. Just to clarify: I want this to be a REST API which returns JSON, without any views (I want to be able to access it from different applications, mainly Apache Co... |
I tried to prove to myself that MJPEG stream decoding can be accomplished using bare-bones .NET.
So I wrote a class that decode MJPEG streams, trying to keep tips in mind:
No allocation, except the two arrays during startup
Using a delegate called in a separate Task, so the image processing/display by the caller does ... |
I'm developing a console app which is supposed to teach how the bitwise operators in C# work. It will include tutorials, training fields and all that good stuff. I have a problem with the naming of my variables. I have a few classes, however, their names are quite long and the variables that I'm passing to the construc... |
Rubberduck has been using an extension method to export code files, notably for source control purposes.
While testing source control, I ran into a weird bug in the VBIDE API, which caused UserForm modules to perpetually be treated as "modified", because every time we exported them, the VBIDE API would add an empty lin... |
I am trying to increase my understanding of classes, so I tried to implement a simple address book program that holds ten names with that names corresponding address. The program works correctly and I am proud of what I have done so far, but I am looking to see if there is any aspect that can be made better, and or nee... |
Following on from my two previous posts.
An alternative vector
An Alternative Vector (Copy Assignment Operator)
I have written a detailed blog about how to write a minimal vector like class. This set of articles has been inspired by multiple posts here on http://codereview.stackexchange.com (See Sources).
Index
Res... |
The problem is to find the number of increasing sub-sequence of a string with only digit characters.
Answer may be very large, so output it modulo 10^9+7.
I have been able to get a O(n) solution using segment trees. However , the the code is quite inefficient owing to loops with constant but large runtime. How can I m... |
I'm making a game and I want to establish a network connection between 2 players through a server.
So far all I have is:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class Server ext... |
This code is part of a quite huge repository using NHibernate in a wrong way: no units of work, but microsessions for every object loading and saving (ignorant of Persistence Ignorance, coded like naive SQL or file access).
The TransactionalSessionContainer has been existing for a while now, but, if used, only in a few... |
I don't yet see a code review for a number-guessing game in Rust. Since I am just learning the language, and since the number-guessing game is part of the official Rust tutorial, I thought it would be beneficial both for me and for this site to open a code review request.
I've started with the official tutorial and the... |
Problem: Remove duplicates from a given array of integers.
I want this method to work without using data sets except an array.
My code is currently \$O(n^2 + n) = O(n^2)\$. How do I shorten this? My main goal in writing this code was in the mindset that I am in an interview and that I am given only 20 minutes to solve ... |
I had to write the method that extract all pairs of numbers from collection of numbers, which sum matches the particular number.
static void Main(string[] args)
{
var inputCollection = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var targetNumber = 12;
var pairs = ExtractPairs.Extract(inputCollection, ... |
I recently working in .Net field and under circumstances had to write a program to execute sql from external source file.I have written the code and works fine but when it goes to Production server,It crashes becasuse of too amny files to handle.
Can someone just look and guide the improvement areas.
Input Params-
Mode... |
I'm trying to write a short random walk simulator in which an agent has a 50% chance on each "round" to either move toward x or back to its initial position. If the agent is already at its initial position and has to move back, it stays there instead.
I'm getting a lot of variance in the results and running the functio... |
I have written the following method twice but I don't know which is better from performance perspective, code design and best practice.
First:
public int Insert()
{
int affectedRow = -1;
using (IfxConnection con = new IfxConnection(ConfigurationManager.ConnectionStrings["sh"].ToString(... |
I'm currently in the process of writing my own programming language and the Virtual Machine for the language is responsible for handing all of the local variable scopes.
I need to support the following operations as fast as possible:
putLocal - puts an object into the stack
getLocal - retrieves an object from the stac... |
I've had to write two different functions (shown below), but I want to combine the two functions into one. Is there a way to do this?
softmax_a_set() takes a list of numpy arrays, applies softmax() to each individual numpy array, and then returns a list of processed numpy arrays.
def softmax(a_vector):
"""Compute ... |
My aim is to print bytes string lines in Python 3, but truncate each line to a maximum width so that it fits the current terminal window.
My first attempt was only print(output[:max_width]), but this did not work because Python counts e.g. tabs \t as one character, but the terminal displays them as multiple characters.... |
There is a task:
Given a binary search tree of \$n\$ nodes, find all the pair of nodes whose sum is equal to a given number \$k\$ in \$O(n)\$ time and constant space.
Please let me know if you find bugs on any data set.
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
static class Node
... |
I am writing a function which on update of any attribute of model sets the status of variable is_kyc_verified to false.
Here is the code of the User model and the method which changes the status:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :time... |
The goal: A set of configurable options, combined with a standardised data source, to produce a standardised Report.
This question: One module of said document, with accompanying code.
Input: (Dropdown selection): An Attitude To Risk (ATR) Value. 1 to 5.
Business Logic: Select from pre-configured descriptions and hard... |
From SICP:
Exercise 1.12: The following pattern of numbers is called Pascal’s triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
. . .
The numbers at the edge of the triangle are all 1, and each number inside the triangle is the sum of the two numbers above it. Write a proced... |
I'm in the process of writing a Generic Container Library in C called CGCL. One of the generic containers I'm implementing is the vector container.
I'm writing this library to improve my knowledge of different data structures, improve my C coding skills, improve my skills with generic programming in C (as opposed to t... |
I am preparing for ACM-TCPC (Tunisia). So I started solving problems from past ACM-ACPC versions. But I got stuck in the Problem I from 2014.
The problem consists of finding the number of non-equivalent passwords in list of passwords. Two passwords, A and B, are equivalent if len(A) == len(B) and |A[i] -B[i]| is the s... |
Obviously, everyone should use a password manager to generate and store long unique random strings of characters for the vast majority of their passwords. However, one still needs to memorize a master password for their password vault! I figured that I would write my own little script to generate such a password, XKCD ... |
I had an online coding test yesterday. The question is not hard to solve, but I could not achieve the required running time. The question is as follow:
Given \$1 <= M\$, \$N <= 10^5\$ find the count of pairs A, B:
1 <= A <= M and 1 <= B <= N
\$(A^{1/3} + B^{1/3})^3\$ is an integer
Here was my solution:
I notice that ... |
I have a huge method in my controller that is not DRY and just could use some general TLC. I'm new to ruby and I have not refactored my own code before, only contrived code you find on tutorials. Below I will show my controller, just to be clear I'm not looking for a full answer just maybe where I should start and some... |
I'm writing this method that elaborates an image name..
I think my logic is not being the best one here but I'm not very savvy in programming yet.
Right now it looks like this:
if($this->isCustom($product)){
$image_path = PRODUCT_IMAGE_PATH . $this->order['order_number'] . $index . '.jpg';
$inde... |
This is working but right now it is not giving me the throughput that I want. The main function has the load generation loop (where it is putting work in Queue). I am trying to model a Poisson arrival process for the memcached requests (keys are randomly generated and this is handled in sendRequest). Right now it takes... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.