@jfriend00 Sorry, all I wanted to do was to prevent someone else from voting to close and commenting with "I'm voting to close this question because it belongs at Code Review". I did not mean anything bad. This question could be a nice CR question, but that's a whole different story. — Simon André Forsberg4 mins ago
I write a program. Most of the time it work out really fine. But occasionally it would crash due to segfault. So I wonder whether it is proper to post such a snippet of code.
Most program contain bug. Some are big while others are small. Mine contain a little bug that I cannot find out. I need ...
Many numbers can be expressed as the sum of a square and a cube. Some of them in more than one way.
Consider the palindromic numbers that can be expressed as the sum of a
square and a cube, both greater than 1, in exactly 4 different ways.
For example, 5229225 is a palindromic number ...
ODE Solver with Least Square leastsq
Aim: I have set of experimental data, and set of ODE equations
I have to find out how to find parameters unknown in ODE fitting data
Description of Problem: I am getting an error, while debugging. pasted at the end.
The error while debugging
Descript...
Welcome to Stack Overflow. Please take the time to familiarize yourself with the Stack Overflow help file, which will help you understand what kinds of questions are appropriate for this site. This site is intended to help you obtain answers to specific programming questions, as opposed to providing tutorial, design or code review assistance. — MarsAtomic54 secs ago
I made a chat bot, that, as you talk to it, it learns to respond. But the way it speaks is strange, so if you have any ideas on how to make its response any more human, then please say so.
Anyway, you have to start a new chat bot. You'll notice that when you start his responses will be incredibl...
I've taken a stab at GPU programming. The code I'm posting below was the first assignment. It runs exactly as it should, squaring every value, when run on the virtual machine in the training website. However, when run on my machine I get what is also posted below. What gives?
#include <stdio.h>
...
Whitespace. It looks nice, and is important. Use it. There are many areas here where you could insert some whitespace, and then the code will magically become much easier to read. Here are a few areas where whitespace is needed.
One blank line between the functions in bot.
Some more blank lines...
I have to draw various instance of HeatMap, Wind and Polyline. each layer will have 1 HeatMap , 1000+ Wind arrows and 3000+ polyline. Javascript code for the Layer Manager is at http://jsfiddle.net/Nitansh/3sze2w7z/
Websocket push the data into mapData structure where i have to store the data fo...
First off, without the background code for this, it's a little hard to understand what exactly this code is doing, but I'll try to give as good a review as possible.
First off, the code inside deleteMapLayer should be indented for readability.
Secondly, don't create a function as an instance at...
In the absence of a full-fledged tutorial, I am teaching myself to program in the Factor language by writing a bunch of functions that I will eventually use in command-line scripts.
One common operation I like to perform is to change the case of names of files contained in a given directory to u...
What is the best algorithm to solve for this problem?
You are given a bunch of nodes evenly spaced in a rectangular shape. The rectangle is M nodes long and N nodes wide. Node A is in the upper left hand corner and node B is at the bottom right hand corner. How many different paths are there fro...
The straight forward hierarchy of my schema is:
Projects> deliverables> steps> assets> versions> comments
My question is, am I trying to nest things too deeply? The above hierarchy makes sense for how I plan to pull the data back out but didn't know if I should break up the chain into smaller ...
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class HeighwayGenerator : MonoBehaviour {
private List<char> direction;
private List<Vector3> dragon;
private Stack <char> stack;
private LineRenderer line;
private float magnitude = 0.0f;
public int iteration...
See the previous and initial iteration.
I have mainly refactored the code and made it a little bit robust (if serialization of a single object produces a string with new line character(s), an exception is thrown as the deserialization routine relies on assumption that the object string represent...
Problem Statement
There are N boys and N girls. Only a boy and a girl can form a dancing
pair (i.e. no same sex dancing pairs are allowed). The only other
condition in making pairs is that their absolute difference in height
should be less than or equal to K.
Find the maximum numbe...
I would like to create a plugin system to allow new controllers to be added at runtime. These will be api controllers and not views.
I know I can add controllers from other assemblies at startup by using the following and this works.
public void ConfigureServices(IServiceCollection services)
{
...
I am building game, like Ogame, or Ikariam where you can play with another users in real-time. You train some soldiers, build some vehicles, or buildings. Every building or vehicle has some level. If building has higher level you must wait longer to use it etc. Could you check my code, it is writ...
I wrote the following snippet to deal with a situation in which I have two datasets (usually the current version versus a previous one) and I need to identify what changes have occured: usually explaining the deltas of one specific column.
I want to identify what rows have been added, what rows ...
This question is not such a good match for SO. In part it's a matter of opinion, and in equal part it's a matter of code review. In general, if a wrapper/library works for you and makes your life easier, go for it. Performance should the the least of your worries. The cost to worry about is the cost of maintaining it, other people working on your code learning it, etc. — torazaburo10 secs ago
private void btn_nhap_Click(object sender, EventArgs e)
{
int a = 0;
int.TryParse(txt_Phantu.Text.Trim(), out a);
for (int i = 0; i < array.GetLength(0); i++)
{
for (int j = 0; j < array.GetLength(1); j++)
{
array[...
For practicing purposes, I challenged myself to write a program that solves the TSP and visualises the results step by step.
As for now, my program uses a simple nearest neighbour algorithm. I want my program to be flexible, so when I add a new algorithm, it will be able to visualise the result...
I'm going to be gone for about a week on a camping trip. In a place with no little or no cell reception. Which means I can't be in here, or do much on the main site.
The Problem
Given a list of dependencies ('a * 'a) list where the first item has a dependency on the second item, construct a dependency graph and then 'flatten' it into a single 'a list such that no item comes after one of its dependencies.
Constraints
I am trying to improve my functional pro...
Can someone tell me why is this code not working. Why cannot I parse the string ? And why my Method is not working ... ?
Thank you in advance :)
using System;
class HexademicalToDecimal
{
static void Main()
{
string hex = "C921";
Console.Write(hex.Length);
long resultindecimal =...
I have this code, that creates (or update) an user from an omniauth hash param
def self.find_or_create_from_auth_hash(auth_hash)
uid = auth_hash['uid']
provider = auth_hash['provider']
user = find_or_create_by(uid: uid, provider: provider)
user.name = auth_hash['info']['name'...
Inspired by Minimising the triangle
I am writing a fully tested program to solve the following problem:
A triangle needs a good foundation. Every row in the triangle is derived from the sum of the two values below it. However, there can be
no repeated values, if a value shows up more tha...
I've written a little program to calculate pi using the Nilakantha series
For this formula, take three and start alternating between adding and subtracting fractions with numerators of 4 and denominators that are the product of three consecutive integers which increase with every new iteratio...
Tip of the day: Don't even try to make cross-domain JSON POST HTTP requests with JavaScript. Just don't do it. Save yourselves the trouble. Use another approach instead.
@Mast The JavaScript is the real problem. You have no idea how many SO questions there are about this subject. I did not find any question though that was about a) cross-domain, b) send JSON data c) use POST at the same time
@nhgrif HTTP sends requests. POST is usually to update or upload certain information, in which the query indicates what should happen. Or well, that's one approach.
I want to have a TamperMonkey userscript on my computer that adds a button to chat for posting a message as @Duga. I can post as @Duga by sending data with 'application/json' or I can send it as 'application/x-www-form-urlencoded' (which my userscript currently uses, as a workaround). I wanted to have my userscript make an Ajax request to stats.zomis.net with 'application/json' data, but that failed
I can post with 'application/json' just fine using a Groovy script, but that is not JavaScript.
I either get 'application/x-www-form-urlencoded' in the header, or I get a jqXHR error and status code 0, and with the extremely informative message that it couldn't load my URL...
@skiwi it works for x-www-form-urlencoded, not for json. It's not related to cross-origin policy.
This answer is a WIP.
I don't know factor, so I'm going to try as hard as possible to give the best review I can create.
Where are the comments? While someone who knows Factor would be able to read this, someone who isn't experienced in Factor would have no idea what this is doing. Add usefu...
There are many instances of prime number sieve implementation both here and other places on the web, but I wanted something a little different. In particular, I wanted to create a static array of the first 1024 prime numbers at compile time as a simple reusable structure. I also wanted to allow...
Thanks for pointers! GHC fix alone made queries run about 20~25% quicker! I was hoping I would be able to use LINQ because the data queried are for a REST / Json RPC with a huge amount of exposed methods, the client that I have written uses a Redis data-store with entities stored in memory, which you can read more about here ConcurrentDictionary's which stores HashSet's based on Type Object-cache C# Take twoproperty.Key == "Age" && property.Value == "29" was simply an added factor I added to give it a more real world scenario. — Joachim58 secs ago
I have written the following code snippet in Ruby.It works.But I believe the codesmells have crept in.Please help me in eliminating them through a cleaner and reusable code.
class Vehicle
attr_accessor :regno,:type
def initialize(regno,type)
@regno=regno
@type=type
end
end
class Pa...
My Rails app geocodes users IP when they are created and also when they update their data only if they change their city. The geocoding is slowing down my tests ridiculously.
This seems to me to be a poor way to avoid endless geocoding when running tests but i am unsure of a better way to do th...
@EthanBierlein My suggestion: If you want to answer that factor question, play around with Factor for quite a while in IdeOne before you answer it. Try to discover different ways of doing what the OP does.
Get some understanding of the language before you answer the question.
There are quite a large number of existing implementatons of FizzBuzz but I awoke this morning in a cold sweat with the terrible revelation that Code Review had no FizzBuzz implementation in Forth! To redress this terrible oversight, I wrote this while sipping my first cup of coffee.
: FIZZBUZZ...
Are you using two or three spaces of indentation? Yes.
Are you using two and three spaces of indentation? Yes.
Are you using two xor three spaces of indentation? No.
Made me lol.
That advice could be modified to suit so many style errors on CR.
The question was written in July. The answer in November. Awesome.
Every time a post involves Python code, it has the Python tag AND the Python version tag that suits the version of Python that the post is using.
I think that is a little repetitive, and we should either:
Burn python and have Python related posts use the tag that contains the version of Python...
Every time a post involves Python code, it has the Python tag AND the Python version tag that suits the version of Python that the post is using.
I think that is a little repetitive, and we should either:
Burn python and have Python related posts use the tag that contains the version of Python...
A few years ago I modified version 1.8.1 of Jason Blevins's markdown-mode for Emacs so that when showing inline links the URL is hidden, and so that you can follow the link simply by hitting Enter. If you want to see the URL you can still see it by, say, removing the final ). It's based on linkd,...
// This method swaps rows and columns of an valid board.
// Swaping process for rows must be done same horizontal grid and
// also for column swaping process must be in vertical grid.
private int[][] swapRowsAndCols(int[][] board) {
int range = board.length == GRID_9X9 ? 7 : 5;
// defin...
I made a chat bot, that, as you talk to it, it learns to respond. But the way it speaks is strange, so if you have any ideas on how to make its response any more human, then please say so.
Anyway, you have to start a new chat bot. You'll notice that when you start his responses will be incredibl...
I think this question really belongs on Code Review because the provided code works correctly and it is only the performance which needs to be improved — barrowc17 secs ago
I'm voting to close this question as off-topic because it belongs on the Code Review StackExchange site — barrowc34 secs ago
The prompt that made me put this function together was sourced from CodingBat.
I was curious about cleaner, more correct methods of doing putting this together such as finding a cleaner way to tell if there is or is not a duplicate in the array. I am also trying to be as efficient as possible. I...
I've seen a couple questions have sections at the end of the post where it brings together all of the recommendations that have been mentioned in that post and re-writes the code using those recommendations.
Is this okay, or is it better to leave that part up to the OP of the question?
One exam...
I often say in my comments that Code Review is not the place about changing what the code does, that it is about making the code do the same thing in a better way
I want this code to run, get to the end, print the value of pi for that run, and then do it again- 40 times, without me hitting the run button again. In other words, I want to see 40 different estimations of pi in the "run" window. As you can tell I'm new to programming, I've read about for an...
I want to know that how to find the last node of a doubly circular linked list in Java, as I want to find the size or number of nodes in the circular linked list.
@JoshBeam I don't find this question to be off-topic for Stack Overflow at all. This sounds like a question about a specific programming problem (as defined in Stack Overflow's help center) to me. — Simon André Forsberg14 secs ago
Algorithms makes code fast or slow, not recursion. Some quite fast algorithms can use recursion, but that's a whole different story. Many algorithms can be written as both with recursion, and without recursion.
However, your code has a big problem. Notice how many times you call this code?
Obje...
He did need a Code Review though, but he definitely didn't ask for one.