Hi guys I'm in an intro to comp sci course that uses java and I was just wondering if there is some sort of function or method to calculate distance between two points, say for example: the distance from (50,10) to (100,45). I know in calculus we used the formula d=[(x2 - x1)^2 + (y2 - y1)^2]^1/...
@retailcoder No, it's the inevitable lull after a period of frantic activity. We just need a new topic. Speaking of which, time to put some music back on.
Hi guys I'm in an intro to comp sci course that uses java and I was just wondering if there is some sort of function or method to calculate distance between two points, say for example: the distance from (50,10) to (100,45). I know in calculus we used the formula d=[(x2 - x1)^2 + (y2 - y1)^2]^1/...
If you think about what that formula means, then just learn basic Java syntax and math functions, you shouldn't have a too hard time to figure out how to do it in Java... — Simon André Forsberg52 secs ago
@SimonAndréForsberg bah, you know what, I'm stupid. I worked like an idiot for 4 days refactoring indecent code (a 4K-liner button click handler), and all my boss is telling me is "so, is it working now?" and "I don't care how crippled it is, the person that wrote it would have made it work by now" - I have a different definition of "working". One that doesn't involve a memory leak, a SqlConnection, DataSet and SqlDataAdapter recycled 162 times and never disposed of, TONS of inline XML, etc, etc, etc.
@SimonAndréForsberg no offense to @rolfl, but my answer was like "if you want someone that will just 'make it work' and make this spaghetti shit even worse, I'm the wrong guy, you need a monkey ".
I actually did a bit of refactoring myself today, even though I am not supposed to do that. But no one knows I did that, yet. Only a matter of time before they will find out. I have an answer prepared though: "You wanted a more advanced feature, I made sure that the code also is more advanced which will make it easier to extend the functionality later."
I accepted an answer, got +2 and now I need to downvote 2 answers to fix my OCD. Suggestions anyone? (excluding @Malachi's answer on my xmlCmd question)
What is the current 'ethic' about posting your answers here in Chat .... I know that I backed off doing that a few weeks ago, and as a result I don't have as many up-votes on my answers.
it's just a matter of exposure - I wonder if I can make @StackExchange post your new answers here (belated as always, but still)... but that wouldn't be fair.
@retailcoder - that is the point: ".. but that wouldn't be fair." ... it's not really fair that the things that get seen are the things that are upvoted (not necessarily, but largely true).
@retailcoder Speaking of old chat posts, I have to say that I'm happy with 79/3.89 :) (that of course does not mean that I will stop answering, or that you should stop up-voting me... it just means... ah, nevermind...)
I think it solves a few problems: 1. pimp factor - everything gets pimped, and no-one feels cheap. 2. only answers, not edits, or Jamalizing 3. more views, more votes, more happiness.
Odd. There's an RSS feed for every question, so technically a chatroom could have a feed for answers on a specific question. But it doesn't look like @StackExchange is going to post site-wide new answers here.
The first thing I would like to say is that I do have a fully functioning script, but the script is ugly, and I am wondering if there is a way to optimize it is all. Now, what the script does is look to see if I have at least 6 news articles in my database. If I have at least 6 news articles it b...
I obtain the txt var from the DOM (that's the only way I've got by now and can't change it) and it's a formatted JSON, here's an example of the expected JSON output:
{"SE DIO AVISO A CENTRAL":true,"OTRO":false,"SE DIO AVISO A SEGURIDAD CIUDADANA":true,"SIN ACCIÓN":false,"SE DIO AVISO A AMBULANCI...
Many beta-sites suffer with a problem of voting. Code Review is one of them. We at Code Review have realized that it is hard to vote for answers that you're not aware of, therefore some of us (no monkeys named) posts a link to a recent answer every now and then in the chat.
Instead of us posting...
The first thing I would like to say is that I do have a fully functioning script, but the script is ugly, and I am wondering if there is a way to optimize it.
The script looks to see if I have at least 6 news articles in my database.
If I have at least 6 news articles, it branches into a neste...
You are basically mimicking the behavior of join here. Simply collecting the correct values into an array and then joining these values will be simpler.
This is what I would counter-propose:
try{
var o = jQuery.parseJSON( s ),
keys = [];
jQuery.each(o, function(key, value){
if(val...
Even though maybe not exactly what you want, the closest thing that is already existing is Code Review.
Code Review can, among other things, help you with:
Reviewing working code
Reducing code duplication
Improving your usage of design patterns
Highlight potential bugs that you are not already...
@Jamal We should really stop doing things at the same time ^^
Even though that's not exactly what he's looking for, I couldn't resist :)
It's pretty easy if you're a 1-rep user on SO who hates negative numbers. Speaking of which, proposing mandatory comments for downvotes is a great way of getting dwonvotes.
I'm kind of new to Python. So, I wonder which method is better to use in a function to find an element in a list.
First:
def search_binary(xs,target):
count = 0
for i in xs:
if i == target:
return count
count = count +1
else:
count = c...
If your list is sorted you can use binary search (your second code), and it will be faster for large lists, but if it's undorted you'll have to keep to linear search. The Python library provides fast implementation of both methods, so you really don't need to roll your own:
>>> a = range(10)
>>>...
This compiler, implemented in C++, takes brainfuck code and produces a valid (but still obfuscated) C program, which in turn can be compiled to a native binary.
Expected usage is as follows:
Build the compiler
$ c++ -o bfc bfc.cpp
Compile a brainfuck program (example) to C
$ ./bfc ascii.bf
...
The following code is ported from here: https://github.com/Theodosis/parallel-programming/blob/master/pthreads/bitonic/pbitonic.c#L376
from itertools import takewhile, count
def sort(pairs_to_compare, data):
data = copy(data)
for i in pairs_to_compare:
if (data[i[0]] < data[i[1]...
The following code is ported from here: https://github.com/Theodosis/parallel-programming/blob/master/pthreads/bitonic/pbitonic.c#L376
from itertools import takewhile, count
def sort(pairs_to_compare, data):
data = copy(data)
for i in pairs_to_compare:
if (data[i[0]] < data[i[1]...
Sometimes it seems like no one reads the CR FAQ at all... I wonder if it would be possible to have some kind of tacky "don't post non-working code" on the question posting page.
If you had several attributes (particular, amount, ...), you might consider doing it this way:
class Items
attr_accessor :attributes
def initialize(*attributes)
@attributes = attributes
end
end
items = [Items.new('food', 1000), Items.new('drink', 2000)]
attributes_strings = items.map(&...
I personaly try to stay away from using the var keyword, as sometimes it tends to make code unreadable for example var result = ReturnResult(); when reading this I don't really know what the type is at a glance. And try to initialize ur variables outside of the foreach loop. I would normally decl...
The strangest to me is when people who have a few thousand rep on SO post complete and utter garbage on CR. You think they would have a feel of the SE network, but meh....
Even on SO, that question would get downvoted to oblivion. High-rep users aren't expected to post questions consisting of "it doesn't work, and I don't know why."
This compiler, implemented in C++, takes brainfuck code and produces a valid (but still obfuscated) C program, which in turn can be compiled to a native binary.
Expected usage is as follows:
Build the compiler
$ c++ -o bfc bfc.cpp
Compile a brainfuck program (example) to C
$ ./bfc ascii.bf
...
modern compilers tend to completely separate parsing of input and generation of output. typically input is parsed into an AST by a parsing component and then the AST is optimized and output as whatever the target is
but anyway, if you take a formal langs class, you should in theory be able to make a crude parser after that. at least from a mathematical perspective :)
I'm just getting into testing and wanted to see if someone can tell me if I'm writing tests correctly. I'm using C#, NUnit, & Should.
This is the class I'm testing:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection.E...