I recently read and answered Martin R's Recursive flattening of Swift sequences and continued to play around with the code until I arrived at something that was both pretty cool and possibly an abomination. So I figured I'd come back to CR with it and ask others' opinions.
If you want a full con...
Implementation of a Robust (i.e. with a finite plane thickness) Sutherland–Hodgman algorithm for clipping polygons against an axis-aligned bounding box. I use the following code only for clipping triangles. So the clipped polygon can consist only of at most 9 vertices. The code of Point, BBox and...
SVN is surprisingly easy to use for simple things like that. If you integrate it in your menu it even has icons telling you exactly what function you need when.
The reason for not recommending git to designers is that designers produce large quantities of data (Photoshop files are huge and do not play nicely with git's delta-compression), but git requires every user to download a copy of all the revisions of all the files in the repository. So if designers store their work in git, then it quickly becomes very time-consuming to clone a repository.
Subversion is better in that respect (it only requires users to download copies of the files they are working on), but has its own problems (in particular, branching performance is very poor).
The (old) Ariane Rocket software bug is interesting reading. One software bug, £300 Million+ of rocket and satellites turned into so much fiery debris. around.com/ariane.html
I have a model that needs to be saved in to a MongoDB collection. To get the collection name I have two options before me.
1) Attribute
I decorate the class with a custom attribute and use reflection to access the value inside it. I can then cache this with the type to avoid future lookups.
[M...
The institution I work for uses an application that has an awful software bug causing useless span tags to appear next to "misspelled" words in iframes. For instance, HTML that should look like this...
<span class="myClass">Hello! My name is Tabitha.</span>
...might look like this instead:
<s...
As an exercise to learn Rust I decided to implement a Bit Vector library, with inspiration from std::vec::Vec for which methods to provide.
I have the following code:
extern crate num;
use std::cmp::Eq;
use std::ops::{BitAnd,BitOrAssign,Index,Shl};
use num::{One,Zero,Unsigned,NumCast};
pub tr...
Coordinated Universal Time (French: Temps universel coordonné), abbreviated as UTC, is the primary time standard by which the world regulates clocks and time. It is, within about 1 second, mean solar time at 0° longitude; it does not observe daylight saving time. It is one of several closely related successors to Greenwich Mean Time (GMT). For most purposes, UTC is considered interchangeable with GMT, but GMT is no longer precisely defined by the scientific community.
UTC was officially formalized in 1960 by the International Radio Consultative Committee in Recommendation 374, having been initiated...
Technically, if you're looking for advice on improving working code rather than fixing a bug, you should post the code to Code Review rather than here; however you have three nested loops iterating over large ranges; it's unlikely that approach is going to be rapid — Dave32 secs ago
@DanPantry Yes, git-lfs (large file support) is a workaround for the problem I described. But note that it's an extension (not built into git) and that it requires a server.
It's for an entire program that will later be a review -- this just a question however and probably quick for you. It has to do with how to properly use strcpy
I was doing something else at first but then I realized that I was setting the pointer and at the end they just all had the last value, so I looked into how to properly do it and found strcpy
@Legato In that use case there should be no need for copying at all — you'll be reading the input into a buffer that you've malloc'ed, so then you can just put a pointer to the buffer into the array
@syb0rg memcpy if you already know the length of the string for some reason, sure
See, now I'm not sure which I should be using, should I create a snippet? Mind, I've written 1 C program and pointers and memory allocation are low level things that have been abstracted until, though I do understand the concepts.
KITTEH HAS IMPROOVD CODE SKILLS, AN NAO HAS BETTR CODE 4 U
This is an improvement of my original Haskell Lolcats Translator, and now features a function to do the translation (recursively?) using a map. I still have two let statements, which I know are frowned upon, but I couldn't get both the s...
I created this program and coding for the task mentioned. Could some advice if this is right.
import java.util.*;
public class Dice
{
public static void main(String[] args)
{
String name;
int bet;
String option;
Scanner input = new Scanner(System.in);
Syste...
As someone completely new to the language sometimes you don't know which is correct / best. Up-votes and duplicates do help though, but those are applied parsimoniously. Also, sometimes things aren't updated.
I have the following manager class that handles access and caching attributes from classes. I am a bit worried about the caching mechanism.
Is there a better way of handling it?
public static class AttributeManager
{
private static Dictionary<Type, Attribute> _cache = new Dictionary<...
By the way, it is usually not necessary to read the whole of a file into an array in memory — the usual thing to do would be to read one line at a time, and process it before reading the next line
That way you don't need to allocate memory for the whole file
I am rewording my earlier question. Below is a code that I am using to generate an HTML table based on some criteria. This is just a sample class, in real we are using a class with complex business logic and then generating an html table.
Is there a better way to generate HTML tables without wr...
Can't say much about that without seeing the rest of your code - one line doesn't really give a lot of information about its efficiency. Take a look at Code Review and post the whole code there; they'll soon speed you up if it's possible — Dave25 secs ago
A Word.Application object exposes an .Activate Method.
An Excel.Application object, on the other hand, only exposes an .ActivateMicrosoftApp method which performs a notably different function to "activate this particular application object".
Why isn't there an Excel.Application.Activate Method?
Welcome to IT. Struggle, learn, grow. We have ALL been making this up as we've been going on. — Richard U49 mins ago
Appropriate?
Speaking as somebody in your situation only recently (though in my case, I was literally on my own when it came to learning how to program), Come to Code Review. It's not quite as effective as having your own personal mentor, but it's pretty damned close. — Zak23 secs ago
I'm a business student who just started to learn VBA. I am trying to write a macro for a project but only have minimal experience actually stepping into the code. The macro I have written is to delete all row entries which do not meet my criteria if they contain certain words, including removing ...
Posting "horrible implementation of xyz #23" to Code Review is hardly going to betray a company's competitive edge, but it is important to make sure your boss agrees with that statement before you do so.
@Zak That would be unethical and possibly ineffective — in many cases "to do X" would narrow the set of candidates so that someone in the know could guess
"Here's my code that I've posted against the terms of my employment agreement and I'm hoping no-one at my company will ever Google for any of the variable names in it"
Just need to wrap my brain around a good way to form a number such that the last digits of the number is p1 and the number is divisible by p2, where (p1,p2) forms a twin prime.
Easier with an example... (101,103) -> 48101. Because last digits are 101 and 48101/103 is an integer
@N3buchadnezzar You have p + q(10^k) == 0 (mod p + 2) and want to solve for q. Now p == p (mod p + 2), so that means q(10^k) == 2 (mod p + 2). So q is 2 divided by 10^k (mod p + 2).
@syb0rg Sorry, just now saw your message from earlier. The ... is part of a very long string map definition that bears no significance on the functionality of the code.
@MichaelBrandonMorris I disagree actually, one recommendation (based on the length of the table) might be to export it to a file, or do something else to represent it better
I did a very simple Rails application as example for a job interview
with a simple client to post data.
I didn't get approved so I would appreciate if you could point out where I did bad and how I could improve it.
I would also really some reference to read more about what I'm lacking here.
Thanks
@syb0rg Fair enough, but how many lines is too many for a code review? 100 lines of strings? 1000? If I did that, you'd be scrolling a very long time to see the 10 lines of code that actually do something.
(i) q is 2 divided by 10^k (mod p + 2), but you've done the division the other way round; (ii) you can't use ordinary division here, you have to use modular division
Modular division is the opposite of modular multiplication: for example, 1000 × 48 == 2 (mod 103), so 2 ÷ 1000 == 48 (mod 103). There's no built-in operator in Python that computes modular division — it's up to you to implement it.
I'm writing a simple shell and want to parse and execute a simple shell script.
PAGER=more
if type less > /dev/null;then PAGER=less; fi
echo $PAGER
printenv|grep $1|$PAGER
The above sets a pager and greps the environment variables for a variable.
I run the script from my shell after I start...
@StudentL if you have a specific programming issue, feel free to ask on Stack Overflow if you cannot find an existing post with your answer. Code Review comments are not the place to fix your code. — Mat's Mug ♦6 secs ago
The following code takes in an point array and removes all of the nearby points whilst averaging them based on the conditions past in.
The variable _nCornerTolerance is an int that is calculated prior in the class. Typically it is around 5;
private Point[] AverageNearbyPoints(Point[] points, bo...
My first time with web programming.
just wondering how bad it is.
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Restaurant Menu With JQuery</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://code.jquery.com/j...
Allow me to strongly doubt that. Turns out robust code isn't tested manually by stepping through, but by specifically writing a Sub procedure in a dedicated test module, that only runs that code you want to test; if the procedure does 20 other things, there's no way to test it cleanly and automatically. I don't know why basic OOP and clean code principles get systematically thrown out the window whenever we're talking about VBA code, AFAIK VBA is just as capable of SOLID and OOP code as Java or C# is. — Mat's Mug1 min ago
@syb0rg I hardly find myself qualified to review someone's code man! The extent of my knowledge has come from the help you guys gave me on my practice class project!
It would be better to actually write modules to break it up and actually test those individually, but I'd say all, it sounds like the asker simply didn't even think about that use of comments.
@StudentL I remember and sort of still do feel like I'm not qualified to give people other answers, but the truth is even if it's only minor you can contribute a bit, and you'll get so much out of it.
Besides the fact I feel that, I somehow have 50+ answers...somehow.
Recently, i have been indulging in a lot of codility challenges to improve my coding performance. For each of this exercise, I always aim for simple solutions as opposed to complicated ones that arrive at the same answer . The question is
Two positive integers N and M are given. Integer N re...
I did a small sample application for an Interview. Since I didn't got accepted I would like your opinion on how to improve it.
The aux methods are private.
I have a usage_common to remove duplication in the usage and usage_instance methods
add_item_hash is used because the format written in the ...
Challenge
Write a program which reads a file and outputs a specified number of lines, sorted on length in descending order.
Specifications
The first argument is a path to a file.
The file contains multiple lines.
The first line indicates the number of lines to output.
The following lines a...
@StudentL Even if you can't answer anything for a while, even just asking is creating a valuable opportunity for you to learn until you can / someone else to answer. I think I asked 30 or so questions before I started answering. So, don't let it dissuade you if you don't find anything at first.
@N3buchadnezzar That code show you how to compute the modular inverse. To compute modular division is one small step further.
For example, modinv(1000, 103) returns 24. That means that 1 ÷ 1000 ≡ 24 (mod 103). But what you want is not 1 ÷ 1000 (mod 103), but rather, 2 ÷ 1000 (mod 103).
@LovetoCode If you would like to have your code reviewed you might wanna take a look at codereview.stackexchange.com maybe you'll get some more and / or better help on that site. — Mango44 secs ago