All Questions
0
votes
0answers
3 views
Are these good examples of functions that do one thing only or am I getting a little carried away?
I'm reading Robert C. Martin's "Clean Code" and for the past few days I've been fiddling with its function writing guidelines. At first I thought the idea of functions being two/three lines long to be ...
1
vote
0answers
11 views
How to reduce foreach loops
I've below code for determining items which are not there in other list and that are in common. How to reduce it to simpler code with possibly less loops.
foreach(var i in list1.Except(list2))
{
...
1
vote
0answers
23 views
First time using std::map — am I developing any bad habits here?
This is from an older question of mine that I decided to revisit: Simple and efficient code for finding factors and prime factorization?
In that question, someone suggested I use an std::map to hold ...
0
votes
0answers
8 views
implement hmac sha1 in C
I am trying out a small piece of code that would generate Hmac-sha1. I have been asked to code the hmac implementation myself using the OpenSSL libs for SHA1 calculation.
After 'wiki'ing for the ...
3
votes
1answer
34 views
Whats a good way to create a sorted hash counting the occurances of a number in an array in ruby?
I figured something like this
a= [1, 2, 3, 2, 2, 2, 3, 1, 1, 1, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
a.inject({}) { |h, el| h[el] = a.count(el) if h[el].nil? ; h }.sort_by ...
0
votes
0answers
14 views
recvfrom() Ubuntu socket programming
I have a client code that is supposed to perform webchat with other clients on the server. When I run this code on two different hosts at the same time, I'm able to successfully send out messages ...
0
votes
2answers
40 views
How to make this code cleaner
Is there a way to write this code block cleaner and more readable?
var shareNavigate = function () {
scope.sharingActions.shareOnFacebook().done(function () {
...
0
votes
0answers
7 views
Is this proper code for removing a CCSprite under certain conditions?
This is a "answer" to my own question over at stackoverflow, head over there to see what I am trying to accomplish. ...
0
votes
1answer
29 views
One to one record mapping without any common column between two tables in sql server
I'm trying to join two tables based on one to one mapping without any common column.
For example, I have 3 records in first table and 2 records in second table then the mapping should be as follows
...
2
votes
2answers
36 views
Are these memory-allocation wrapper functions kosher with all C compilers?
I have never been entirely comfortable using malloc() and free() directly. For one thing, 99% of the time that I would like to call malloc, I would prefer it to take two arguments like calloc and do ...
2
votes
3answers
63 views
Need an advice - refactoring
I'm making a comparing section, which I've just started typing, trying to get something working. It's working now, but as you can see its pretty messy. I feel this could be done in one or two less ...
0
votes
0answers
13 views
Ascii Table in brainfuck
I made my first brainfuck program today, which prints the numbers 0-255 and the corresponding character.
I was wondering if I could improve my program, as I'm repeating my self a lot (eg. 3 x copy ...
-2
votes
0answers
20 views
Rewriting a code segment using a loop structure in C [closed]
It is required to rewrite the following code segment in C and remove all unreachable statements. There are many different approaches depending on experience. I tried some couple of solutions. I want ...
4
votes
4answers
63 views
How to get rid of semantic duplication
I am breaking my head with how to get rid of semantic duplication(Code that is syntactically the same but does different things).
I can't find anywhere a post or something that mentions a bit how to ...
3
votes
2answers
45 views
Replacing simple jQuery methods for better use
There are a few common jQuery call I find my self calling when creating my app. I need some help and maybe a better way to do all this or rewrite it.
1) Singleton Selector
If I want to select only ...
0
votes
2answers
50 views
Try, catch, exceptions with java
Is this code good for checking if the variable texto is empty or not? How would it be done with try and catch?
public class RedProfesionalException extends Exception {
public ...
1
vote
2answers
37 views
Java Theory: Classes Design for Currency, Futures and Metals Analysis 1
This is a continuation from here:
http://stackoverflow.com/questions/16761207/java-theory-classes-design-for-currency-futures-and-metals-analysis
I have created 2 classes for now.
1) Historical Data ...
0
votes
0answers
28 views
Can anyone optimize the code for parallel programming and efficiency?
The parallel programming can be used in finding row total or column total.
namespace OneWayAnovaTable
{
public partial class OneWayAnovaTable : Form
{
public OneWayAnovaTable()
{
...
2
votes
0answers
24 views
I have a mathematical expression evaluator. The code works fine. Code reviews and suggestion to improve coding style are welcome
using ExpressionEvaluatorLibrary;
namespace ExpressionEvaluator
{
class Program
{
static void Main(string[] args)
{
ConsoleKeyInfo cki = new ConsoleKeyInfo();
...
2
votes
2answers
80 views
Is there any way to make my project Euler#14 solution faster?
I'm solving project euler problems and uploading my solutions to github.
Some of my solutions are just based on math and are thanks to that very fast, but #14 is way too slow, and I have no idea how ...
0
votes
2answers
30 views
Is there a better way of writing this code?
I have made a mini image gallery which consists of one large div which has a background image of one of the galleries images.
Underneath that there are five thumbnail images, that when clicked, ...
0
votes
0answers
14 views
Best way to do a Determinant of a Binary Matrix C++
I'm looking for the best way to do a determinant, for determinants until 15x15 and looking for speed
int Determinant(const vector<vector<int> > &a,int n)
{
int i,j,j1,j2;
int ...
-2
votes
0answers
8 views
Flash AS3 XML. full sample read/modify/write [closed]
can anyone provide a full sample of how to manage XML file via Flash AS3, which contains read/modify/write functionality
I searched a lot for such sample but I didn't find any.
Thanx
1
vote
0answers
23 views
Concurrent hash map for memoization
I'm developing a concurrent hash map for DP memoization. The assumptions behind its design are the following:
no erase operations are possible
once the value corresponding to a key is written, it is ...
1
vote
1answer
23 views
DRY cursors: preventing T-SQL's FETCH statement from being repeated
Please assume I've exhaustively tried to come up with a set-based solution to my T-SQL problem, and that I need to use a cursor. The following is the typical1 boilerplate for a T-SQL cursor:
...
2
votes
0answers
18 views
Faster 3D Hilbert Curve in C
I need to compute a 30- or 60-bit Hilbert curve index from three 10- or 20-bit integer inputs. I need it in C or C++ and I need it to be as fast as possible.
Here is the working version that I have, ...
3
votes
2answers
45 views
Dining philosophers problem
Now I know this dining philosophers problem is researched a lot and there are resources everywhere. But I wrote a simple code to solve this problem with C and then turned to Internet to see if its ...
3
votes
1answer
37 views
Very simple implementation of observer pattern in C++
I'm reading on design patterns for a software engineering class. I am doing small implementations of some I find the most interesting / applicable to better understand them.
I'd like a code review on ...
1
vote
1answer
29 views
DRY up Rails Navigation Code
In my Rails 4 app i used to have every view contain a content_for :nav tag which included all of the links for the nav bar in my layout. This was getting annoying because if i wanted to add a button i ...
1
vote
0answers
30 views
Review of 2d Vector class
I'll keep this short. I've never actually done professional C++. I don't really know any of the 'best practices'. I'd like to get some review on a simple class that I've made.
My Vector2d.h file:
...
0
votes
1answer
30 views
Is it necessary to move OpenFileDialog code for opening the files and put it into a separate method?
I want to separate the code inside my Add button click event from the code in order to make my code looks more arranged.
this is my code before these changes (i am using BackgroundWorker in order to ...
1
vote
1answer
26 views
Javascript objects listening to their own events
I have been playing with event driven javascript lately, and have wondered if it's a good/bad thing for objects listening for their own events as a way of abstracting and simplifying internal logic.
...
2
votes
3answers
62 views
Game Of Life 3 in Java
I have this version of John Conway's Game Of Life in Java:
Frame class:
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import ...
1
vote
0answers
22 views
Improve my SQL select statement
I have three tables for a blog system.
The blog
CREATE TABLE IF NOT EXISTS lm_blog(
blog_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(80) NOT NULL UNIQUE,
action ...
3
votes
1answer
79 views
How can I improve this C++ 'genetic algorithm' implementation?
now that I am almost done with my uni studies, I'm about to start jobhunting (aiming mostly for a Gameplay Programmer), and so I've created a code sample that I will link with my applications.
...
2
votes
0answers
26 views
Rigidness and verbose nature of XML parsing
I've been developing a simple console application in C++ using the TinyXML2 library, and I honestly can't help but feel what I'm doing is not very robust. Maybe that's just the nature of parsing XML ...
-1
votes
0answers
22 views
Need help optimizing this jQuery code [closed]
Below is a slider code that if used for more than one slider in the same page will not save each slide position. I need to have 8 sliders like this in the same page, so I repeat it 8 times. Would be ...
0
votes
0answers
37 views
Calculate work progress in percentage of batches that contain tasks and task contain sub tasks
I was being referred to here from stackoverflow.
I am trying to calculate work progress in percentage. I have multiple batches, and each batch contains a set of tasks and each task also contains a ...
1
vote
0answers
20 views
Collision System in Pong-like game - How good is this code? (Blitzmax)
I am writing a game like Pong. Therefor I am using an entity system approach, so I use component based design.
The hardest part until now was to write the collision system. As I just began with the ...
2
votes
2answers
45 views
More Elegant Solution to Logging Class
I got this class in C# which works fine. But I was wondering if there was a more elegant solution to what I am trying to do. It looks rather clumsy and inefficient for a Logging functionality.
The ...
1
vote
1answer
15 views
Sleepsort in Go
I implemented sleepsort in Go. I am new to channels, and I'd like to get some advice on them, especially on how to close channels after N messages have been sent on them. Currently I use a counter and ...
1
vote
1answer
17 views
Asp.net MVC4, Lamba Sorting
I have the List method that takes sorting parameter to sort result. and the sorting parameter value is same to column name. And this is my code,
public ActionResult List(string sorting = "Name", ...
0
votes
0answers
21 views
MySQL vs PDO execution time
I'm having some issues understanding why PDO is 6X slower executing a query than the depreciated MySQL query function. Here's my code:
$conn = new PDO('mysql:host=localhost;dbname=work', 'root', ...
3
votes
2answers
90 views
Looking for a better solution to my OO code
I would like if this could be kept to a post providing concrete examples of how I could solve my problem better, and not about which one would be "best" as such :) I would simply love some insight to ...
0
votes
1answer
21 views
Need to clean up my code and add the ability to resize the image
I have the following code:
<?php
include '../../inc/config.php';
$size = isset($_REQUEST['size']) ? $_REQUEST['size'] : 'full';
$image = isset($_REQUEST['image']) ? $_REQUEST['image'] : FALSE;
...
0
votes
0answers
11 views
Type conversion from FORTRAN to C#
I have in F2008
module mod_Blood
use mod_liquid
implicit none
type, public :: typ_BloodComponents
character(len=5) :: name
real(DP):: salt
real(DP):: RBC
end type typ_BloodComponents
...
2
votes
2answers
76 views
Ruby multiples of 3 and 5 code challenge
I have implemented the first coding challenge on http://projecteuler.net/. I would love to get it reviewed by some expert rubyists! Thanks in advance :)
# Multiples of 3 and 5
#
# If we list all of ...
2
votes
2answers
57 views
Extension methods for class Type
While working on one of my projects I actively used Reflection. While working with class Type I expected methods: TryGetMember, TryGetProperty, TryGetField, TryGetMethod. I've implemented them as ...
4
votes
2answers
76 views
Is the following code well written?
The following program is supposed to return the length of a 'hidden' string within each of the sentences of another string, using pointers and avoiding as much as possible the use of [] as a means to ...
0
votes
1answer
48 views
Class design question
i have Winform application and i want to separate the button click event from the main form.
my application has Add button who add files into my Listbox and until now all my code was inside this ...