All Questions
1
vote
0answers
3 views
Returning Key Values from Stored Procedures
I wonder which is better practice when I need to return the primary key value of a newly inserted record from a SQL stored procedure. Consider the following implementations:
As Return Value
CREATE ...
0
votes
0answers
7 views
Is there a more efficient way to code this “Item-picker”?
I would love to show you one of my bigger scripts to improve my technique.
This Script is some Kind of Itempicker. You choose your Item first (toprow), then pick a color. The color of the active Item ...
2
votes
0answers
7 views
Thoughts on organizing code for multiple mysql queries in php scripts
I have a web application where I connect with a MySQL database using PDO and in some scripts there are a lot of queries one after the other which don't necessarily concern the same tables. i.e I will ...
2
votes
0answers
6 views
Bitwise Flag code for Python
I am looking for feedback on this compact Python API for defining bitwise flags and setting/manipulating them.
Under the hood, FlagType extends int and all operations are true bitwise, so there is ...
0
votes
1answer
10 views
2D Array: Retrieve the “Left” Item
I am creating a game that contains a Board and Pieces. The Board is basically a 2D array of Pieces. [Think smaller chess board]
One of the things that I want to accomplish is to be able to retrieve ...
-1
votes
0answers
7 views
Regex expression
I have a file that I get from pulling out values from a Microsoft Lync 2013 conversation that has RTF formatting tags. An example file would be like:
Here is my file:
...
2
votes
1answer
32 views
Better Javascript to find unique values in an array
My objective is to make an array of unique keys from a list of objects. Example:
Input:
var input = [{"a":1, "b":2}, {"a":3, "c":4}, {"a":5}]
Output:
[ "a", "b", "c" ]
Current approach:
var ...
0
votes
0answers
11 views
Use of pointers in a a C++ header file, good or bad practice
My question is that I have a Qt application and I build a window and its quite a complicated window that uses lots of widgets and stackedwidgets and gridlayouts, because of this the constructor gets ...
2
votes
2answers
27 views
How to make this python function and its inverse more beautiful and symmetric?
I like the radix function and found a really neat way to compute it's inverse in python with a lambda and reduce (so I really feel like I'm learning my cool functional programming stuff) :
def ...
7
votes
0answers
45 views
Named operators in C++
A post by Yakk alerted me to the idea of named operators in C++. This look splendid (albeit very unorthodox). For instance, the following code can be made to compile trivially:
vector<int> ...
1
vote
0answers
20 views
File uploader in php
I can't get a peer review where I work, I was wondering how my code was and how could it be improved.
https://github.com/lamondea/uploader
Is it a good practice to use functions in classes or should ...
3
votes
1answer
56 views
Best way to unit test methods that call other methods inside same class
I was recently discussing with some friends which of the following 2 methods is best to stub return results or calls to methods inside same class from methods inside same class.
This is a very ...
1
vote
1answer
14 views
A good example of codeigniter MVC?
What is the difference between this two way and Which one is best? What do you suggest?
1.
Use of query (db) directly in CI_Controller. as:
$id = $this->input->post('id');
$query = ...
3
votes
2answers
29 views
Defining of new, temporary, variables or usage of already known ones?
I want to check if the length of phone number is appropriate for specified country (let's consider that only some countries have restriction, another countries accept phone number with various ...
1
vote
0answers
19 views
mvc example: form post
I try to improve my code: separate html/php, much clear, next time change will be easier.
After do research about MVC/OOP, I made below code for example to learn,
I understand this is not the MVC ...
-1
votes
1answer
28 views
What are these bitwise operations doing? [closed]
I found a snippet of code on the PHP manual which packs 64 bit integers. APparently this is necessary because pack() always treats numbers as 32 bit integers even on 64 bit architectures.
I don't ...
0
votes
0answers
11 views
My second attempt at canvas spatial grid collision? Did I get it?
After posting my first question and my first attempt which you can see here,
My first attempt at canvas spatial grid collision? Please be honest!
I have re-written it to try and implement what the ...
1
vote
2answers
33 views
Form Validation (JQuery)
I made a simple form validation. It's working alright. The thing is I want my code to be optimized. Can somebody show me some pointers to improve my code? Thanks in advance.
...
-1
votes
0answers
8 views
Trying to run a simple gets.chomp in Sublime [closed]
For some reason when I run:
name = gets.chomp
puts name
I get the error:
gets:1:in ': undefined methodchomp' for nil:NilClass (NoMethodError)
If I remove the .chomp and run:
name = gets
puts ...
2
votes
1answer
45 views
Thread Safety issues in the multithreading code
I am working on a project in which I have two tables in a different database with different schemas. So that means I have two different connection parameters for those two tables to connect using ...
2
votes
1answer
26 views
Add event listener when window loads
I've been using this code for quite some time, but am wondering if there's any improvements I can make to it. Basically it's just code that runs when the page loads or if the code is run after page ...
-1
votes
0answers
10 views
Please review my code: Bootstrap + HTML5 boilerplate in ASP.NET MVC 4 [closed]
I have added Twitter Bootstrap and HTML5 Boilerplate in ASP.NET MVC 4 Project. I just want to know if there is any performance problem or misplaced code.
I have used intializr in this project, which ...
2
votes
1answer
24 views
Python: Combing two programs that analyze strings
I am trying to combine two programs that analyze strings into one program. The result should look at a parent string and determine if a sub-string has an exact match or a "close" match within the ...
-1
votes
0answers
23 views
Stuck on C++ while loop : simple [closed]
How do I make this so it asks if they want to calculate the area of a shape after every time through the loop? Right now it brings them back up to cin >> choice; but I want it to ask them every time ...
0
votes
0answers
9 views
Render arbitrary jade in express
We've got a "catch-all" in app.js that renders a .jade file if it exists:
app.get('*', routes.render);
index.js
render: function(req, res) {
fs.exists('views' + req.url + '.jade', ...
2
votes
2answers
33 views
A defined macro to copy selected values of std::vector to an array using std::copy
Thought I share this piece of code to the world. But be aware, I am not sure if this piece of code is safe and efficient. Feel free to improve it or give some feedback and suggestions.
#pragma region ...
3
votes
1answer
72 views
Is this code as weird as I think it is?
Combing through legacy code, I found this:
public static void SetupSiteDeptBox(string siteNo, System.Windows.Forms.ComboBox cbo, ref Hashtable DeptHash)
{
DeptHash.Clear();
if (siteNo != "")
...
1
vote
1answer
63 views
Is there a valid answer to this “Why?” comment?
This is probably too little to go on for a definitive answer, but in looking over some legacy code, I found this (a previous peruser commented "Why?") in what serves as the main form in a Windows CE / ...
1
vote
1answer
40 views
Is this enum declaration “wrong,” or is it just me?
Legacy code has this enum declaration:
public enum ChangeListTypes
{
Always = 1,
Never = 2,
CostChange = 3,
None = 0
}
I would have done it this way:
public enum ChangeListTypes
{
...
-1
votes
0answers
35 views
Improve Design of this Java Application [closed]
I completed a group assignment for a Java course, but due to deadlines I was unable to really make it as clean as I wouldve liked. Since its over now and I have submitted the assignment I would like ...
2
votes
2answers
78 views
Determine if an int is within range
Can I somehow make this a bit cleaner using Math.[Somthing], without making a method for it !?
int MaxSpeed = 50;
if (Speed.X > MaxSpeed)
Speed.X = MaxSpeed;
if (Speed.X < MaxSpeed * -1)
...
1
vote
0answers
11 views
EXCEL VBA Populate ComboBox
Are there any shorter/fastest version of code below? Appreciate any help.
'Sheets("Summary(FG)") ComboBox1 items
For b = 3 To Sheets("CustomerList").Cells(3, 2).SpecialCells(xlLastCell).row
If ...
0
votes
3answers
63 views
New to LINQ, not sure this is best practice
So i have a super class that has a 3 child classes. Those 3 child classes have multiple classes of their own. I was having troubles saving this into XML, so I decided to parse it out and do a little ...
3
votes
2answers
61 views
Ways to improve the code of my Black Jack game in c++
I am a little new/rusty to this C++ stuff. Is this bad code? Ways to improve it?
#include <windows.h>
#include <string>
#include <iostream>
#include <cstdlib>
...
2
votes
1answer
27 views
python unique_list class
Please review unique_list:
unique_list implements a list where all items are unique.
Functionality can also be described as set with order.
unique_list should behave as a python list except:
Adding ...
2
votes
1answer
42 views
multi-recursive replacement function
I wrote a function for creating all possible translations of a source string, based on a multiple translation map. It works, but generates a lot of intermediate maps (see line marked with *). Is there ...
1
vote
0answers
3 views
PostgreSQL: Get all recursive dependencies of a single database object
I've written a SELECT statement that creates a List of all objects that depend on a single object, so that if I wanted to DROP that object I could DROP all referenced objects first without using ...
4
votes
4answers
79 views
Little log engine in C
I programmed a little log engine in C I plan to use in my project and maybe some others in future. I am very novice C programmer and would like to have feedback of some experienced ones on this. It's ...
2
votes
1answer
91 views
Getting Country Based on IP - Java
Im using Struts2, Google App Engine. Below is my program for getting the country based on IP of the visitor of the website.
In my Struts2 action:
HttpServletRequest request = ...
3
votes
1answer
54 views
My first attempt at canvas spatial grid collision? Please be honest!
The code,
$(document).ready(function() {
window.addEventListener('keydown', keyPress, true); // event listener for keyboard presses
function keyPress(evt) {
if(engine.activeBlock) { // block is ...
-1
votes
0answers
11 views
Stripchart using raphael.js in IE8 [closed]
I'm using Raphael.js to help in creating a Stripchart, but unfortunately it's not displaying the actual data in IE8. The grid for the chart is displaying but that's about it. Does anything in the code ...
1
vote
1answer
71 views
Am I using pointers correctly?
I'm a newb at C++ and I was wondering whether I used pointers correctly and whether it was appropriate to use them in this context.
Any other tips/information would be appreciated.
#include ...
5
votes
3answers
107 views
Which is considered better: push(array,value) or push(value,array)?
This is valid for many other functions.
get(array,key) or get(key,array) ?
find(array,value) or find(value,array) ?
Etc...
2
votes
1answer
99 views
Too slow two strings comparer
I have 2 strings for example:
abcabc and bcabca
or
aaaabb and abaaba
I checked that second string is the same or not like first string but shifted.
bcabca = ..abca + bc...
Here is code it works ...
2
votes
1answer
33 views
Semantically correct markup at practice
I'm writting a mark up for:
And here is my HTML:
<div id="container">
<header>
<h1><img src="images/logo.png" alt="Jessica Priston - ...
3
votes
1answer
56 views
Java multithreaded file server and client. Emulate TCP over UDP
This is for homework.
My task was similar to my last assignment but this time I had to do it with UDP instead of TCP. This basically means I had to emulate TCP over UDP.
Multithreading was an ...
4
votes
3answers
88 views
Simple C++ File Indexer
I didn't realize I am not a very good programmer at recently. I just come out from Uni, I want to become a reliable teammate. Please help me to improve my coding style/habbits. I have carefully ...
2
votes
1answer
55 views
If statement, is the shortened version readable enough?
I have to perform an IF statement in my Javascript code. I utilised the first method shown below:
(someVar1 !== "someString") && (someVar2[i].disabled = (someVar3.find("." + someVar4).length ...
2
votes
2answers
29 views
Passing Context in CoffeeScript
I'm trying to migrate from JavaScript to CoffeeScript. However I'm not sure about the best way to optimize the code generated by js2coffee.
Below is the original JavaScript source :
var async = ...
1
vote
0answers
21 views
How's my matrix library look?
I've written a short library for manipulating matrices for 3D drawing. I've tried to strike a balance between speed and readability. Anything to improve?
%!
%mat.ps
%Matrix and Vector math routines
...