All Questions
0
votes
0answers
5 views
Dependency injection class in C++
In a recent project I started passing dependencies to classes as constructor arguments, instead of using local instances. This makes unit testing straightforward (with mock objects), but manual ...
0
votes
1answer
10 views
Notify owner of post and other commenters
I have a rails4 app. When a user comments on a post it should send a notification to all the guys who commented on the post and to the post creator. I have a working method in the controller, but it's ...
-2
votes
1answer
22 views
Thread-safe access to multiple objects [on hold]
I have two thread-safe collection in which one's item is other collection's key. Whenever a new Foo comes in, it will be both added to list and map. To ensure thread-safety, both operations are ...
-1
votes
1answer
8 views
New to batch, would like some assistance (please advise if incorrect section) [on hold]
Firstly, I apologise for formatting, new to this site and iphone app.
I've done a small amount of research. Have made a small batch to move mp3 files from my downloads folder, but now it's time for ...
3
votes
2answers
133 views
Can this simple breadth first search be less ugly?
The following code performs breadth first search on a mockup tree
...
0
votes
0answers
7 views
fetch data from multiple tables
I have three primary tables.
1. Customer
2. Product
3. Order
relations:
many to many between product and order.
...
2
votes
1answer
16 views
2
votes
0answers
16 views
Slow multiplication in a modulo
I am willing to get a linear output of a product in a ring Z/nZ
For that I have successfully implemented a code that does a Product in a modulo
However, it is not optimized to output the steps ...
3
votes
1answer
32 views
Cleaning up C# method that copies file dependencies
I have written the following code, and it works great, but I'm not satisfied. I really love the book "Clean Code" by Uncle Bob and I try to apply all his principles when coding, but I'm having a tough ...
1
vote
1answer
25 views
Coding style for my little animation plugin
I have been writing a small particle plugin since I want to learn how physiks works for games. Now I have tried to get this as clean as I possible could but It feels something is missing. Am I ...
-5
votes
0answers
28 views
1
vote
0answers
34 views
Submitting a JSON
I have service to which I have to submit a JSON but I have to send the JSON multiple times and the code is slow. How can I improve the performance?
...
0
votes
1answer
12 views
Angular console like window - first directive
I've asked question on SO how to rewrite jQuery code to Angular. Because I got no answers I've tried to create something by my own.
This is my version of code:
...
3
votes
2answers
424 views
Reverse words in Java
Short and Spicy question is that If input is how are you and output should beyou are how.
...
2
votes
1answer
23 views
0
votes
0answers
7 views
obj c - create gif from uiimage array [on hold]
I'm modifying a library to create a gif from an nsmutablearray containing images.
I'm getting the following exception in the following code.
PS: I'm trying to hardcore the images going in for now ...
3
votes
0answers
42 views
Preventing SQL injection without using prepared statements
I'm learning OOP and totally new to this way of coding. I've always scripted PHP the procedurial way. Now I've written a working class, which creates a database connection and has the method to create ...
1
vote
1answer
30 views
PHP Login script getting bypassed allowing access to my admin pages
I have a site where a friendly hacker says they have accessed my admin area. I am not able to see how this is possible so any help would be greatly appreciated. I am using PDO prepared statements to ...
1
vote
1answer
36 views
“Destroy the Asteroid” Game
I made this game for my computer science class.
Here is my professor 's requirements:
Write a Processing program that draws a triangle in the middle of the window.
Rotate the triangle when the left ...
2
votes
0answers
37 views
Recursive Breadth First Search for Knights Tour
This was written as an experiment in performance, based on another question here on CodeReview. Input into the algorithm is the number of squares on one edge of the chess board, the point of origin, ...
3
votes
2answers
162 views
Display or hide drawer with onClick
The following is my code for my "drawer" to be display or hidden on the basis whether it has been clicked or not. I want to make this better as personally its messy. Any tips?
...
3
votes
1answer
39 views
TicTacToe 5x5 win or draw algorithm
I have file which contains a lot of boards from TicTacToe 5x5.
First line says how many boards this file contains (n*5x5).
We check the winner in Horizontals, Verticals and Diagonals lines.
Player A ...
2
votes
0answers
13 views
Memcached load generation
I have this code in python 2.7, it is working but right now it is not giving me the throughput that I want. The main function has the load generation loop (where it is putting work in Queue). I am ...
0
votes
2answers
36 views
Possible logic flaw [on hold]
I'm writing this method that elaborates an image name..
I think my logic is not being the best one here but I'm not very savvy in programming yet.
Right now it looks like this:
...
1
vote
0answers
26 views
A command line Java program for computing grade point average - follow-up
(See the previous and initial iteration.)
I have refactored the API based on excellent review by cbojar. Also, a honorary mention goes to janos for pruning some unnecessary code out of the transcript ...
0
votes
1answer
18 views
Improving the running time of finding the count of pairs satisfying a symmetric relation
I had an online coding test yesterday. The question is not hard to solve, but I could not achieve the required running time. The question is as follow:
Given \$1 <= M\$, \$N <= 10^5\$ find the ...
4
votes
1answer
42 views
Generating XKCD passwords
Obviously, everyone should use a password manager to generate and store long unique random strings of characters for the vast majority of their passwords. However, one still needs to memorize a master ...
-1
votes
0answers
8 views
Monitoring an output file and killing a program when possible strings are found [on hold]
My first attempt was with this code below which function is to dynamically monitor the outputs of a program and then kill the program if possible strings are found. It worked when I was looking for ...
1
vote
2answers
57 views
Controller method to manage SMS subscriptions
I have a huge method in my controller that is not DRY and just could use some general TLC. I'm new to ruby and I have not refactored my own code before, only contrived code you find on tutorials. ...
4
votes
1answer
44 views
Equivalent passwords ACPC 2014
I am preparing for ACM-TCPC (Tunisia). So I started solving problems from past ACM-ACPC versions. But I got stuck in the Problem I from 2014.
The problem consist of finding the number of ...
3
votes
1answer
23 views
Generic Vector Implementation
I'm in the process of writing a Generic Container Library in C called CGCL (https://github.com/ta5578/C-Generic-Container-Library). One of the generic containers I'm implementing is the vector ...
0
votes
1answer
18 views
SICP - exercise 1.12 - pascal's triangle
From SICP:
Exercise 1.12: The following pattern of numbers is called Pascal’s triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
. . .
The numbers at the ...
2
votes
0answers
17 views
Modularised Document Construction
The goal: A set of configurable options, combined with a standardised data source, to produce a standardised Report.
This question: One module of said document, with accompanying code.
Input: ...
2
votes
1answer
20 views
Changing a user status flag, with validation
I am writing a function which on update of any attribute of model sets the status of variable is_kyc_verified to false.
Here is the code of the User model and the ...
1
vote
1answer
63 views
Find pairs in binary search tree in which sum of nodes keys is equal key
There is a task:
Given a binary search tree of \$n\$ nodes, find all the pair of nodes whose sum is equal to a given number \$k\$ in \$O(n)\$ time and constant space.
Please let me know if you ...
1
vote
0answers
14 views
Samba Access Wrapper V2
Follow up on this post.
I created a Python module to access Samba shares some time ago, using Mike Teos' SMB module as some kind of a base to it. It is mostly a wrapper, but as I said, I wrote it ...
1
vote
1answer
16 views
Remove non-printable characters from string in Python 3
My aim is to print bytes string lines in Python 3, but truncate each line to a maximum width so that it fits the current terminal window.
My first attempt was only ...
-1
votes
1answer
46 views
Computing logits for a vector and for all vectors in a set
I've had to write two different functions (shown below), but I want to combine the two functions into one. Is there a way to do this?
softmax_a_set() takes a list ...
4
votes
1answer
34 views
Local variable lookup table
I'm currently in the process of writing my own programming language and the Virtual Machine for the language is responsible for handing all of the local variable scopes.
I need to support the ...
-2
votes
0answers
25 views
math expression evaluation in c# [on hold]
I have a math expression '(M1-M2)*2' as an input where M1, M2 has data points from two different CSV files. I need to implement the expression on clicking a button 'calculate' which reads data from ...
1
vote
2answers
638 views
Which is correct : Open one Connection for inserting List of objects or open connection for every single insertion?
I have written the following method twice but I don't know which is better from performance perspective, code design and best practice.
First:
...
0
votes
2answers
55 views
Random Walk simulator seems slow, are there ways to optimize my code?
I'm trying to write a short random walk simulator in which an agent has a 50% chance on each "round" to either move toward x or back to its initial position. If the agent is already at its initial ...
1
vote
1answer
42 views
Performance issue in generic sql utility
I recently working in .Net field and under circumstances had to write a program to execute sql from external source file.I have written the code and works fine but when it goes to Production server,It ...
3
votes
1answer
45 views
How to optimize the algorithm that extract all pairs of numbers from collection of numbers, which sum matches the particular number?
I had to write the method that extract all pairs of numbers from collection of numbers, which sum matches the particular number.
My code is as following:
...
5
votes
4answers
127 views
Removing duplicates in an array
Problem: Remove duplicates from a given array of integers.
I want this method to work without using data sets except an array.
My code is currently \$O(n^2 + n) = O(n^2)\$. How do I shorten this? My ...
3
votes
1answer
24 views
Number-Guessing Game in Rust
I don't yet see a code review for a number-guessing game in Rust. Since I am just learning the language, and since the number-guessing game is part of the official Rust tutorial, I thought it would be ...
3
votes
2answers
51 views
Swing GUI in Java
I'm learning Java at the moment and I'm currently trying to make a GUI using Swing. I've done some reading and people usually prefer and advice to use composition instead of inheritance of e.g. ...
1
vote
0answers
26 views
Add transactional Units of Work to incorrect NHibernate usage (microsessions, single object actions)
This code is part of a quite huge repository using NHibernate in a wrong way: no units of work, but microsessions for every object loading and saving (ignorant of Persistence Ignorance, coded like ...
4
votes
1answer
44 views
Game Networking between 2 players
I'm making a game and I want to establish a network connection between 2 players through a server(so the players are clients).
So far all I have is:
...
2
votes
1answer
47 views
Counting the number of increasing sub-sequences
The problem is to find the number of increasing sub-sequence of a string with only digit characters.
Answer may be very large, so output it modulo 10^9+7.
I have been able to get a O(n) solution ...