Over the last few months, I have written a pair of Perl scripts to create a UDP chat room allowing users to send messages over the internet, encrypted with 1024-bit RSA keys. This makes the messages (AFAIK) imune to MITM attacks. The scripts include a server script and a client script, and works ...
I came across this problem:
The following iterative sequence is defined for the set of positive
integers:
n → n/2 (n is even)
n → 3n + 1 (n is odd)
Using the rule above and starting with 13, we generate the following
sequence:
13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1
...
Sidenote: this question is asking about changing the behaviour of the code for the sake of an exercise. FWIW the intention behind the exercise has been made clear by the instructor. I suggest you ask them about help with the intended solution.... This is most probably out of scope for Code Review, though — Vogel61223 secs ago
I am trying to get letters in the code to print out like 'aabbcc' if you typed 'abc' into the code. Right now it only prints the first letter, how do I get it to print all of the letters that are typed in?
def double_the_fun(a):
while i< len(a):
return (a[i]*2)
c = raw_input('Enter ...
I haven't really worked much with asynchronous code so I'm wondering if I am doing something wrong/something could go wrong. Right now of all the test cases that I have done, my code has worked but I'm not sure if I will get side effects or not.
I won't post any of the business logic, just the ...
/****************************************************
BASE CLASS GROUND Starting Position of Birds
*****************************************************/
enum Direction { North = 0, South, East, West };
class Ground
{
public:
Ground();
~Ground();
void setdirection();
virtual v...
I need to know why random forest classification doesn't support morethan 7500 observations in spark.
If i give morethan 7500 i am getting
org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 4.0 failed 1 times, most recent failure: Lost task 0.0 in stage 4.0 (TID 7, ...
For example, I have 2 variables and my code needs to select call which function according to these 2 variables' values.
if (v1 && v2) {
function1();
} else if (v1 && !v2) {
function2();
} else if (!v1 && v2) {
function3();
} else {
function(4);
}
I think the code looks not good...
Pls take a look at the following code and let me know if thats right, and if there are any room for improvements.
Strategy Class
<?php
/**
* Draw Strategy class
*/
abstract class DrawStrategy
{
abstract function draw(Shape $shape);
}
/**
* This is ConsoleDraw and takes the shape object a...
Products Class that are like
Table
Chair
etc
Pls review it and give your thoughts and let me know if there are any rooms for improvisation.
Products.php
<?php
abstract class Products
{
}
class Table extends products
{
public function __construct()
{
echo "New Table Created"...
I made this decimal to binary conversion as an exercise for myself and because it is obviously often asked during job interviews / tests.
Any hints concerning possible improvements welcomed.
// -- START : Testing the function --------
var display = document.querySelector('div');
var result ...
Integer.parseInt(...) throws this exception if the text given isn't a valid number. You'll have to make a method to catch the NumberFormatException and return 0 if you do. Here is an example of that method. You can then replace Integer.parseInt(disp.getText().toString()); for tryParseInt(disp.getText().toString()); — Kevin Cruijssen29 secs ago
I think that question is more suited for CodeReview because you do not have an actual problem you need help with, this is just an opinion based question. — MeAndSomeRandoms19 secs ago
In my country (South Africa) mobile numbers have 10 digits and always start with a "0" (e.g. 0821231231).
But they can also have the international dialling code ("+27") replacing the "0" (e.g. +27821231231).
So I have this regex
((\+27)|(^(?!\+)(0)))\d{9}
Is there anyway that this can be imp...
Apologies I'll move this over to code review if that's a more suitable place for this — Sandman11251 secs ago
ok sorry. didn't know there was a codereview.stackexchange.com now. — user25469425 secs ago
@PeteKirkham Vote to close because it's too broad or opinion-based; being on-topic on Code Review isn't a valid close reason. — Mast1 min ago
@user254694 If you're sure it works, you can post it on Code Review and delete this question. There should be a delete button on the bottom of your post. — Mast14 secs ago
Then you will get the following error in teh console (in Node)
Error
at Error (native)
at repl:1:7
at REPLServer.defaultEval (repl.js:252:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:417:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
where Foo = Error
something similar happens in Chrome as well
if an error is uncaught it will print to the console, unless it is an error thrown within a promise handler.. or an error in a callback
In my view, I have a CSS class in ruby variable which I'm using in style tag like below:
<% style_var = '.myclass {color:red}' %>
<div class="myclass">This text will be Red </div>
<style type="text/css">
<%= style_var %>
</style>
Though it is working flawlessly, my question is: "Is it a go...
Oh right... it shows me [object] Object as if it was the output of my function, but it's marked in red so I guess I should've figured it was an exception
node-style callbacks pass errors as an argument to a function instead of throwing them, so unles you explicitly throw that error it will never be caught and fail silently..
can you at least show the code where you are handling the exception?
How can I improve the following code?
private const string OAuthTokenUri = "oauth2/token";
private static string GetOAuthTokenUri(string uriAddress)
{
var uri = new Uri(uriAddress);
var baseUri = uri.GetLeftPart(UriPartial.Authority);
var s = new Uri(new Uri(baseUri), OAuthTokenUri);
...
I have rolled my own parallel merge sort and it looks like this:
ParallelMergesort.java:
package net.coderodde.util.sorting;
import java.util.Arrays;
/**
* This class implements a parallel merge sort.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Mar 9, 2016)
*/
public class Parall...
You should not calculate 3 times the $(this). This solution could be improved a lot, maybe you could make a post in codereview.stackexchange.com — ANeves1 min ago
Looking for feedback on how to better improve or simplify the code below.
(function($) {
$.fn.crosshairs = function(options) {
var settings = $.extend({
heading: false,
klass: "highlight",
thClass: "heading-highlight",
rowClass: "row-highlight",
colu...
@ANeves your last comment could be considered as a valid one. And the rest should have to be ignored as no one here is asking to do a code review. — Rajaprabhu Aravindasamy46 secs ago
I know I have this question in StackOverflow and was answered by Vitane Many thanks to him. However, I tried implementing his code, it returns me error that says it is not a structure of the type. Anyone willing to help me? Thanks in advance.
(defun smart-traversal-vacuum-agent-with-radar-progra...
I have a bunch of processes that are being executed on different virtual machines. All of those processes have a StartDate, EndDate and Resource properties. Resource is a specific virtual machine it was ran on. I generated the actual timeline for items and found out that all of those resources ha...
Thanks for the comments, I'll post the provided docs later. And yes I may post it on code review if there isn't a problem with my method — Jamie Nicholl-Shelley55 secs ago
I just wanted to build simple converter from XLS excel file to JSON. I have predefined JSON format. All fields except of two - are just simple mapping from excel to JSON. The two fields have special format, "|" separated values which should be converted to array items. I need also geocode address...
I have written a code for insertion sort, I just want some feedback whether the above implementation is correct and Can we further improve it? Thanks
public class InsertionSortNew {
static int temp;
public static void InsertionSort(int [] array){
for(int i =0;i<=array.length-...
I think I've written something like that before, but I can't find it.
function where(collection, source) {
return collection.filter(function(item) {
//check if all keys in source are present in item, if so, check if item[key] is source[key]
for (var i in source){
if (!(item.hasOwnProperty(i))){
return false;
} else {
if (item[i] != source[i]) {
return false;
}
}
}
return true;
});
}
Something like that combined with a sort @skiwi ?
Most definitely not the most appropriate way, but it works.
function largestOfFour(arr) {
var out = [];
for (var sub in arr)
{
var largest = 0;
for (var subsub in arr[sub])
{
if (arr[sub][subsub] > largest)
{
largest = arr[sub][subsub];
}
}
out.push(largest);
}
return out;
}
Consider an MMO where damage system has attributes like health, critical, defense, etc. There are 8 such attributes, and I want to calculate something which requires the user to order them based on their priority, however my algorithm determines if it wants a second priority after the first one, a third after the second, etc. etc.
Now the additional challenge is that the number of destinations you need to pick depends on the algorithm in the backend (It pretty much requests you to give one more priority because it needs more information)
However the original what you described is already mostly what I want
I'm pretty new to async/await code, and I want to ensure that the code I've written is going to be safe and not cause any deadlocks.
The RestClient in the code below will be injected as a singleton dependency via an IoC within an ASP.NET MVC application, so that the access token request is made...
That's a bummer... I think TFS should have an option to handle this, same way as you can keep the shelveset on the server when unshelving (by selecting the checkbox for that). I'll have to come up with a way to check in other people's work without interfering with the associated code reviews then. I think asking coworkers to create a copy of the original shelveset and then checking that in is what I'll do from now on. — julealgon41 secs ago
I've pulled the migration statistics for the last 90 days from the stats page:
4 of the top 5 migrations are represented in the current close vote dialog. The only missing like is at position 7 in the migration statistics for the last 90 days.
@Sandeep SoftRecs is in beta, and while in beta you won't get migration paths. Codereview guys are against because SO folks have repeatedly demonstrated they can't recognize a good codereview question. — Braiam23 hours ago
I've done this mainly as an exercise to understand these design patterns. I'm writing a theoretical install wizard which will allow users to select different options throughout, and have it execute them all at the end. I think the correct way to do this would be to use a mixture of Command and Ob...
ok spent ages on this simple problem (I'm not good at XML) below code is probably self explanatory and it works, but i think this could be done a lot easier
sample XML
<data>
<id name="ch01">
<channel>test channel 1</channel>
<gpio>3</gpio>
<
I currently manage a team of about 25 engineers and developers in a subdivision of a Canadian tech company working out of Ottawa. Things normally run smoothly, but we've had a serious problem with a senior engineer as of late.
This engineer is the sole engineer on our team with his Professional ...
@Sandeep SoftRecs is in beta, and while in beta you won't get migration paths. Codereview guys are against because SO folks have repeatedly demonstrated they can't recognize a good codereview question. — Braiam24 hours ago
I have just finished a simple C program which is basicaly composed of 3 functions:
accadd(void){} which adds some customer details to a binary file
void view(char file[30]){} which is supposed to let me view some of the data in a .txt file
void modify(char file[30]){} which verifies if number ...
Inside a function I'm calling playgame service, once I've obtained the needed data (gameBeingPlayed) I need to show a 3..2..1 counter and then start a game
chooseGameService.playGame(gameDefinitionID)
.then(function () {
vm.container.gameBeingPlayed = chooseG...
In my current MVC project, I have the following code, which uses a Dictionary<string, string>
Model:
public Dictionary<string, string> QuestionsAndAnswers { get; set; }
Controller:
for (int i = 1; i <= 5; i++)
{
if (Session[$"Question{i}Answer"] != null)
{
result.QuestionsAn...
Thanks to Mat's Mug's answer on this question Guidence on the use of Ninject as IoC Container in a WinForms MVC Application I have made some progress with my architecture, however, I have further questions. Following Mat's advice I changed my Program.cs to
static class Program
{
[STAThread]...
1.song1 5:00
2.song2 1:11
3.song3 1:53
4.song4 5:45
5.song5 3:01
6.song6 3:01
how to make xml file attribute for this and parse it through jquery and display it in html as shown above
I am using lodash to perform the following code but I find it slower than I would expected when the arrays have a lot of objects. Is there a faster solution using lodash or pure javascript?
var array1 = [{id: 1, value: 'value1'}, {id: 2, value: 'value2'}];
var array2 = [{id: 1, value: 'valueA'},...
Could you help me write a difficult query to count count posts on wordpress?
The situation is this:
There is an ads system on a wordpress web site and search
(filtering).
The home page displays a list of all categories with the number of
ads in each of them.
User enters in the form of city, ty...
Thanks for the link @roryap. I wasn't aware of the code review site - looks useful. However, this question is more of a generic issue that I come across quite freqently and wondered if there was a pattern that I could use to enforce how an interface is consumed. — Gibbonfiendjust now
@PinCrash His defense is "I expected you to look at the updated ticket" but if you saw the email context you'd see that all he was explaining was that he was removing one of the requirements because "it was just a check"
it's not even big requirements either and this would not be an issue if he had just created two new task items and assigned them to me :s
@Mat'sMug I was tempted, but I don't want to troll potential students
@PinCrash Well, he did tell me had updated the task to clarify the requirements, I guess it's just my fault that I didnt' realise he had added additional requirements because I am not a mind reader. /rant over
@gabn88 Thank you so much for code review and suggested edit. I'm not sure, what to do. May be, I should totally remove name argument from add_api_view/remove_api_view functions and strictly require that url patterns contain name argument? Because I don't want to duplicate the functionality of django's configuration as primary storage of url names. Or should I create my own optional name storage in the HybridRouter and stick with your edit? Do you have any considerations in favour of either approach? — Bob36 secs ago
I have some rather large arrays with hash values in them that looks like this: "ZjFhOTZjYzgtMmZhMy00YjdkLThmMDgtNjI4MjYxNTc3MGRlXw==ntyxntmzmzkw"
I've done a binary search, using the node.js binary-search library, so my code looks like the following (although with c_array being read in from a fi...
Here is my implementation of user-level cooperative threads in C++14, which I'm working on for a hobby project. It's not entirely finished but works pretty well so far. The target operating system is DOS (dpmi), which does not support native multi-tasking.
Here is a link to the code: https://gis...
I'll let you know.... as long as a situation similar to yesterday didn't happen
Yesterday a feature absolutely had to be implemented and deployed that day, so we implemented it and put it on the UAT environment to be tested by the person who requested it so it could be deployed this morning.
That feature was so urgent they forgot to test it on UAT and now it won't be rolled out until tomorrow morning instead
Luckily this is the last day we have dedicated for hotfixing features... after tomorrow it is back to regular sprints
BTW, sorry if I complain too much. I have to vent my frustration somewhere and as frustrated as I am I worry that raising any of these frustrations in work would cause me to be viewed as melodramatic..
To the extent it's somewhat "relatable" to others and there's nothing more serious going on, I don't think it's too terribly objectionable; that said, if you feel it would be more appropriate on the Nth that's up to you
I'm trying to find out what is the right approach to return db values from a class. This is what I came up with;
class Category {
public $result;
public $errors;
public function __construct( $pdo) {
$this->pdo = $pdo;
}
public function getCategoryNames () {
$sql = "SELECT ...
@roryap The code is heavily exemplified and would be a poor fit in it's current form for Code Review. It's quite a specific question, so I see no problems with keeping it on SO. — Mast38 secs ago
@DanPantry -- I was under the impression that CR wasn't necessarily for posting "here is my code, give me your feedback"...that specific improvements sought are fair game... Though maybe I need to study the help section a little better. I'm not saying it doesn't also work here... — roryap1 min ago
@roryap Posters on Code Review are welcome to suggest areas of specific concern or interest but answerers are free to offer feedback on any and every facet of the code in question. As such, we try to discourage specific requests as a way of managing expectations. — Zak19 secs ago
Seeing as it's October, I thought I'd do the community challenge. Due to my inexperience coding in Groovy, I decided to give Groovy a go. I'm not sure how well I followed Groovy conventions, and the rendering is quite slow. It seem that the slow rendering might have to do with locking when writin...
This question could also be boiled down to the much more general question - "Why do people fall for scams?", which is a question as old as the oldest fool. — Zibbobz2 hours ago
I want to develop a simple in-memory web request rate limiting module, I am allowed to have 50 requests from each unique cookie ID every 60 seconds.
I am wondering if the following code is an optimal way of implementing such functionality:
class RateLimiter {
private static final int MAX_R...
I have two webpages, first in the folder /webpageone/ and the second in the folder /webpagetwo/.
In webpageone I have an administrator where I can edit info in the database, after editing info I copy the databaseone.sdf to webpagetwo for access to the info.
How I can access to databaseone.sdf i...
I have implemented a program that produces a permuted index.
Actually it is this exercise:
http://stackoverflow.com/questions/4015016/what-is-a-permuted-index
My first version was here:
Implementing permuted index in C++
And according to one of the answers I splitted my program into two classes...