0
votes
0answers
3 views
Better way to write the following code?
Is there a better, more elegant solution to the following method?
Boolean[] spades = new Boolean[10]; // 40 cards deck
foreach (Card card in m_Cards.Where(card => (card.Suit == Suit.Spades)))
...
1
vote
1answer
24 views
Is this the proper way to do it?
I'm not sure if this is the way I should be doing this
if its true then it is supposed to enable/disable python/ruby
is this the correct way?
public void init() throws IOException {
...
2
votes
1answer
39 views
improve the design of class “accuracy” in Python
I am learning about the class and methods in Python.
The class Accuracy is a class of several (13 in total) statistic values between a reference polygon and one or more segmented polygons based on ...
1
vote
1answer
29 views
Should I call a method (i.e. size()) multiple times or store it (if I know the value will not change)
I have a function that searches the shortest vector in a vector of vectors of pointers.
Which is a better way?
std::vector<std::vector<void*>> const& ways
{
size_t i = SIZE_MAX;
...
1
vote
1answer
23 views
PHP generic array group by using lambda
K.I.S.S
But how about some error and misuse control? I am wishing it were .NET HAHA.
<?php
function array_group_by($arr, $key_selector) {
$result = array();
foreach($arr as $i){
...
0
votes
0answers
17 views
Multi-threaded Winforms Conventions for Main()
I'm trying to find a good pattern for new applications (and for refactoring old ones).
Maybe it's just me, but I dislike spawning my main logic thread from inside my main form thread (so far I always ...
0
votes
0answers
9 views
Implementation of a managed wrapper DLL
Not entirely sure on how to handle errors on this,
Is returning a nullptr in case of bad parameters okay or is it better to return a ENFMPCodegenData.Empty like there is Rectangle.Empty or ...
1
vote
3answers
10 views
Improve VBA code Excel
Im looking for someone who can improve my code, bacause at the moment it takes 3 min. to execute. I'm new to VBA so it's probably bad coding. Normally if you are good in VBA you will understand the ...
-1
votes
1answer
31 views
PHP shopping cart [closed]
When i submit there is only one product from cart on mail, last one and total price is calculate all item but i cant see them on mail
function emailcartview() {
$total=0;
$totalvalue=0;
...
1
vote
0answers
14 views
Java alphabeta search
This code was adapted from this alphabeta pseudocode. AlphaBeta search is often mentioned but getting the code 100% correct is tricky.
IGame is an interface with two methods:
getScore() - evaluates ...
1
vote
0answers
29 views
Validating Javascript function arguments
I just devised a way to validate Javascript function arguments with a one-line call to an inner function declared at the bottom which gets hoisted. Am wondering if this might be a useful pattern. ...
1
vote
2answers
25 views
Excel instances: release and kill
Please check my code below. I don't have any problems but I'm not aware how far the code will work, release and kill excel instances..
try
{
wBook = xCel.Workbooks.Open(excelfilepath); ...
1
vote
1answer
50 views
Leap year algorithm in Ruby
I wrote two functions of determining leap year.
(Kabisat means leap year in indonesia.)
def kabisat? y
return false if y%4!=0
return true if y%100!=0
y%400==0
end
def ...
1
vote
2answers
61 views
Code Jam - Alien Language
I'm mostly looking for performance Suggestions. Feel free to include more than just that.
Since Code Jam is coming* around I thought I would look at some of the previous questions. Alien Language is ...
2
votes
0answers
83 views
Am I coding Java in C#?
Note: This ended up being much longer than I was expecting. I have a number of side questions that relate to specific parts of the code for if you don't want to slog through all this mess.
Background
...
0
votes
1answer
52 views
Faster JavaScript fuzzy string matching function?
I'm using the following function to fuzzy match strings:
function fuzzy_match(str,pattern){
pattern = pattern.split("").reduce(function(a,b){ return a+".*"+b; });
return (new ...
0
votes
0answers
11 views
Injecting SelectList objects into ViewData to enable using EditorFor on dropdown based properties?
I have developed a system whereby I use an attribute to state which SelectList to use for an 'FK' property. I would appreciate some feedback mainly on by good practice, and also on any ways to do this ...
4
votes
2answers
78 views
How can I make this method less verbose?
I point to my problem in the comments of my code.
I have a class RomanNumeral:
public class RomanNumeral {
private String romaNumera;
private String romans = "IVXLCDM";
public ...
1
vote
2answers
49 views
Set Visible Interface from Method/Class
So I started feeling like my code was becoming a little cluttered in the graphics
void render() {
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
...
1
vote
0answers
41 views
Database calls with Python Flask and SQLAlchemy
I am creating a Python Flask webservice and this is basically how I am doing all of my database calls if a webservice needs to interact with the database:
@event.route("/somepath/<value>", ...
1
vote
0answers
20 views
Send message with SignalR to client(s) from injected (IoC) method
I am new with SignalR and still a newbie with IoC Container SimpleInjector and I am wondering if there are any side effects and/or if I'm save with my chosen approach.
In my web app I have a SetupHub ...
1
vote
2answers
19 views
Can you review my random number wrapper class
I made this class to handle any min max integer value and return a random number in the entered parameter range. I tested it to work with all combinations(I think). But is this totally wrong or ...
3
votes
1answer
44 views
Improve on CSS3 Selectors
I'm trying to change the background-color of each .achievement div. The content is being generated dynamically so I can't add a class easily to each one.
I have it working with selectors like ...
1
vote
1answer
80 views
Looking for architectural feedback on my PHP MVC Framework [closed]
I wrote this a while back:
https://github.com/chintanparikh/Serene
I'm looking for feedback on the architecture/Object Oriented Design of the framework.
What I thought was neat: In the COre folder, ...
1
vote
0answers
65 views
Learning the basics of Javascript with a tetris game
I want to get a better feeling for how Javascript works and how to use it well. I coded up this tetris game, and have iterated over the code base and improved it a couple of times now.
I hope the ...
1
vote
2answers
40 views
php most efficient way to check if a variable contains only certain chars
I have a small function which I regularly use to check if a variable contains only [a-z][0-9] and the special chars '-' and '_'. Currently I'm using the following:
function is_clean($string){
...
0
votes
0answers
59 views
How to optimize this algorithm? (solving systems of linear equations)
I am working on a programming challenge described here:
http://www.enigmagroup.org/missions/programming/9/
Basically, you have a 6x6 table where the first 5 columns and rows are comprised of ...
-3
votes
0answers
42 views
Microprocessor in java [closed]
Please someone help me to do the program. Design and implemention the objects necessary to simulate the CPU of the microprocessor design described below.
REGISTERS
ACC - Accumulator
XREG - X ...
2
votes
0answers
20 views
single-threaded socket server
I wrote a basic Clojure single-threaded socket server, mostly following Java examples; in particular I'd appreciate feedback on three things,
how I handle mutable state (I/O, managing connections).
...
2
votes
1answer
34 views
Scope Resolution Operators and class variables in PHP OOP
I am new to this site, so I apologize if this question is not welcome. I am also new to OOP in PHP. I have done a lot of research on OOP and I keep seeming to read different opinions on several items, ...
4
votes
3answers
112 views
Handling optimistic concurrency violations
I'm trying to establish a concurrency violation verification in my SQL updates using C# and raw SQL.
What I'm doing now is storing the TimeStamp value in a byte[] upon selection and before updating ...
2
votes
1answer
85 views
Enums with different methods, useful or abuse?
I'm wondering if the way I wrote our TextHelper class is a really a proper way to do it.
We have products that are interlinked in different ways and every product has multiple text fields that might ...
1
vote
2answers
127 views
Javascript: How to handle an unknown number of arguments?
I'm writing a function that takes between one and three arguments (function callback [, number limit] [, regexp pattern]). Since the second two are both optional, I need to determine which arguement ...
3
votes
0answers
47 views
Optimizing PHP script fetching entire HTML pages
The following script should get links which are stored in a text file (line by line), then put them into an array and finally scan each links' source code for a certain line. If this line is found, it ...
1
vote
1answer
108 views
Getting familiar with OOP - Factories
I have no idea if I'm doing this efficiently, or ideally, but I've written what I think is a factory. Please help me understand if this is good practice, or if there is another direction I should take ...
1
vote
1answer
77 views
Random Sentences code review
This program use random number generator to create sentences. It prints 20 sentences randomly.
Here is the code:
#include <stdio.h>
#include <string.h>
#include <time.h>
#include ...
0
votes
0answers
40 views
'Universal' WinForms TextBox Text 'Two-Way' Binder
Below is the code of a custom C# class I have called UniversalTextBoxTextBinder. I'm interested to hear the code review comments to find out the limitations of this 'universal' solution as well as to ...
-1
votes
0answers
30 views
Which pattern(s) are applicable for a form which opens in a different modes with minor changes? [closed]
Which pattern(s) are applicable for a form which opens in a different modes with minor changes?
Mode 1 changes:
Add a button that performs additional operation
Mode 2 changes:
Runs an additional ...
3
votes
4answers
295 views
Console.Readline & Lists
I am learning C# from a book, and there is an exercise as follows:
Write a program that has a person enter full name, age, and phone
number. Display this information with formatting. Also ...
2
votes
2answers
46 views
Simple DBLayer class review
I have created a simple DBLayer class. But I am not sure whether this class have any bug/issue using in production.
public class DBLayer
{
private static string connectionString = ...
3
votes
2answers
87 views
Refactoring from .. in .. select to more compact one
Is it possible to write the two following lines of code in a more compact one?
IEnumerable<int> collection = from partnerNumbers in contract.Contact.PartnerNumbers select partnerNumbers.Pnr;
...
2
votes
1answer
79 views
CSS Code Quality
Is this a good CSS?
.table1 thead tr td, .table1 tbody tr td, .table2 thead tr td, .table3 tbody tr td:first-child,
.table4 tbody tr td:first-child, .table7 tbody tr td:first-child ...
1
vote
1answer
35 views
How to optimize the pagination query?
This is completely optimization question, I have a pagination query like that
$this->paginate = array(
'fields' => array(
'DISTINCT Contact.contact_id',
...
4
votes
4answers
184 views
JavaScript: How to provide one-time calculations to frequently used methods
I'm new to JS/JQuery and wrote some JavaScript/JQuery lines to create a "pulsating" object.
I get the "pulse" effect by increasing/resizing the object and then bringing it back to its original state ...
1
vote
2answers
110 views
Modify or not modify your objects when creating computing functions?
See the examples below:
function map_cloning(obj,fn){
result = {};
for (var key in obj)
result[key] = fn(obj[key]);
return result;
};
function map_modifying(obj,fn){
for (var ...
2
votes
2answers
91 views
How can this this URL Checker be made cleaner?
I have a table full of URLs, some of which will occasionally become invalid. As part of a system I'm writing to go through the links periodically, and test if they are valid (or redirect to valid ...
3
votes
4answers
144 views
how can I improve this code and how do I add memory to it?
So I created this code were its basically a game and I need help, because I know there are many ways to improve easier than what I am doing. I am doing it the basic way I know I can but I know there ...
0
votes
0answers
12 views
Android database access
For my simple Android application I don't want to use an ORM, anyway I'd like to have a db-communcation layer easy to user, to read and efficient.
This is my solution: every entity (ex: Person) as an ...
0
votes
0answers
39 views
How to split String in multiple parts by index [closed]
I want to know how to split in Java a String by index....
But i want to pass multiples index and brake this String in varios parts...
2
votes
0answers
26 views
Beginner create android application which should react for received sms and he wants to somebody check his code
I created application which react for received sms. It works but i'm not programmer and i don't know if there are no some conflicts (I only find a code, copy it and did some changes). Could somebody ...