All Questions
1
vote
0answers
5 views
Python DefaultDict implementation in JavaScript
I found Python's default dict and ordered dict incredibly useful, hence I attempted an implementation in JS. As JavaScript objects only supports string as key, it is not as powerful as the Python ...
0
votes
0answers
8 views
Change color of link if radio button is not checked
I have created an online exam system in PHP and JavaScript. In the HTML page, my questions are fetched from the database. If any question is unanswered or the radio button is unchecked, then the ...
0
votes
0answers
6 views
isset and automatically save to variable [on hold]
To check if the structure of array exists I would use:
if (isset($_aConfig['Routes'][$_sRouteName]) {
}
But in same time later I need to access it and I don't ...
0
votes
0answers
9 views
Module based todo list
This is my todo list based on the Module Pattern. This is working fine and just want to know two things.
Can my code be simplified? Once I've added a list, if I refresh the page, then these lists are ...
1
vote
1answer
5 views
Shuffle the element of the array randomly
I have written the code to shuffle the element of the array. Please let me know of any loopholes in the written code.
...
1
vote
1answer
14 views
Various recursive functions
I made a few recursive functions for learning purposes which do a variety of tasks. Here is my current and functioning code:
...
-2
votes
0answers
4 views
How to draw a simple hollow asterisk rectangle of rows & column provided by the console in C#?
Could someone advise me on a simple way to implement Hollow Rectangles in C#? I have been able to make a rectangle and the hollow rectangle programs I've looked at either contained or arrays or were ...
0
votes
0answers
5 views
Can't access elements of the array after for loop [on hold]
I tried to display the elements of a char array after the for loop wherein I assigned the value but when I display it after the loop, there were no output as if the array is empty. Can you please help ...
1
vote
0answers
9 views
C++: Implement a Deque using a Doubly Linked List [on hold]
My assignment is to implement a deque data structure through the use of a Doubly Linked List. For some reason an "unhandled exception" occurs in Visual Studio whenever I try to run it, and the output ...
0
votes
0answers
8 views
Simplify SQL query that utilizes GROUP BY and HAVING BY and uses aggregation
I am taking Stanford's Introduction to Databases Self-Paced online course. I have gone through the videos in the SQL mini-course, and I am having trouble completing the exercises.
The following is ...
0
votes
2answers
23 views
Check whether a date is a valid future date
I'm looking to increase the conciseness of this code. I realize that I can use Joda (or Java 8's new date API), but if I were to keep this to just Java 7, any suggestions? (I care less about ...
0
votes
0answers
13 views
Find the peak element using BS
A peak element is an element that is greater than its neighbors.
Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.
The array may contain multiple peaks, in that ...
1
vote
0answers
11 views
Follow up on CRTP with multi-level hierarchy
I was working on a similar problem to this post, asked a question on the Eigen Mailing List, and Gabriel pointed me to the above post, from which I was able to get my code working again. He further ...
1
vote
2answers
21 views
Titleize words in a sentence but with some conditions
Below is the code I have written to capatilize all the words of a sentence except if
1: The words belong to the littleWords list.
2: The word would be capatilized if its the first word of the ...
1
vote
0answers
9 views
File reader and streamer component running in its own thread on Android
In an Android project,
I have a class whose job is to read lines from a file,
and then pump those lines to a message handling thread,
looping forever until told to stop.
The main operation of this ...
1
vote
1answer
19 views
Merging website info into an array
I'm scraping a title and a link from a website and placing them in a single array.
The $i variable seems a bit wrong to me, or is it perfectly fine?
...
3
votes
1answer
29 views
Generating a zoo of animals
The pattern I've come up here is for the AnimalGenerator itself, outside of the (abstract) Factory Pattern used within it. The factory classes themselves are not ...
3
votes
1answer
16 views
Iterate over large list of lists and replace its elements
I have a large list of lists, where each list contains words/characters as elements, and each list is of different length and may contain same words/characters more than once, as for example:
...
3
votes
1answer
64 views
Optimizing code to find maximum XOR in Java
This problem is from HackerRank (not a competition, just for practice)
Basically what you do is take in two integers as a range and then finding the maximum XOR from a pair of integers in that ...
-3
votes
2answers
28 views
Cleaning up code? [on hold]
This was my first attempt at a github pull request, and I was asked to cleanup my code before it will be merged. I am not familiar with cleaning up code, so I have no idea what could be cleaned.
...
1
vote
1answer
31 views
Party Invitation - Trimming the Invitation List
I am learning Java right now and am coding some simple programs to practice. Right now, one of my for loops has an inelegant way of ending the loop. I was wondering ...
4
votes
1answer
133 views
Listing the first 100 prime numbers
I thought of this implementation, and I want to get feedback from you.. what design would you use for printing first 100 prime numbers?
I used the fact that, if the number is not divisible by any ...
3
votes
0answers
24 views
Caching in PHP using the filesystem
I wrote a simple class to cache data on a filesystem. The class also provides an internal cache using a static variable to avoid reading from disk for each request.
...
2
votes
1answer
39 views
Find the smallest number of square numbers to create n
An interview question I got -
Given int n, find the smallest number of square numbers that fit inside n.
Example:
...
3
votes
1answer
32 views
Is my login system secure?
I am recently making a CMS and I need a secure login system, so this is my code. How is it?
First: the HTMLcode for signup and login:
...
2
votes
0answers
21 views
Measure Method executing time - 2nd Attempt
Long time ago I've written a method that would allow me to measure the amount of time the a method takes to run. I've decided to tweak this method and make use of TPL since measuring a method may take ...
0
votes
0answers
8 views
Using atom to reference state in clojure
I am a newbie in clojure, and I am trying to implement a 2d fighting game in clojure both for fun and learning.
Since the characters in a fighter game are essentially state machines, I constructed ...
3
votes
2answers
94 views
Solving a practical problem involving square of root of a number
A student has a book containing 411 pages.
She read a certain number of pages on the first day and created a rule to work out how many pages she had to read on each succeeding day.
She decided ...
1
vote
2answers
23 views
Alternate for nested Ajax requests
I have one button on clicking I need multiple things need to be done, so I went for AJAX and PHP:
...
3
votes
1answer
32 views
UpdateGame function for Tetris
I am writing a Tetris game while learning Haskell and I'm trying to make the following code more concise and easier to read. How can I improve it?
Note that the function is not finished yet (There is ...
0
votes
0answers
8 views
How to make Bash array output selectable [on hold]
I am new to bash scripting.
I am calling a bash script from perl file, I have to write a bash script that do the following things.
1-First change the directory
2-Run the ls command
3-Stores the ...
3
votes
1answer
23 views
Removing duplicates from an array
I recently wrote this JavaScript algorithm for removing duplicates from an array as part of a job interview process, but was turned down for the position after submitting the code. I didn't receive ...
2
votes
2answers
37 views
Sort ArrayList in a better way
I have a list of categories (in this example I used String but in my project I have a model) which must be sorted like this:
on top we should have 2 categories ...
3
votes
1answer
20 views
MemoryWriter Helper class
I have created this memory writer helper to ease the write into memory process and I want your suggestions regarding it. I am very new to C++ but have 6 years knowledge of .NET languages like VB and ...
6
votes
3answers
186 views
Is the way I'm handling deck (card) generation the wisest way to do it?
My Deck Class:
(In case it isn't clear, a Card is just an object with two enums, one for suit and one for value).
I'm ...
0
votes
1answer
13 views
Creating object Nodes an easier way
I am required to create a bunch of object nodes to an object:
...
1
vote
0answers
10 views
Commute info entry fragment for Android app
This is a simple app for taking down a user's home and work address, the days of their commute, and the times they go to work and go home. The times and workweek are entered via TimePicker dialogs ...
-1
votes
0answers
15 views
Overriding FilterRead read() method in java [on hold]
I am trying to override the read method of FilterReader in java. My goal is to substitute one run of characters for another. I have accomplished this, but the code fails to stop and eventually the jvm ...
4
votes
1answer
17 views
Fast Thread- and multiprocess-safe file operations in python under Linux
I'm trying to implement an alternative to python built-in open(), but safe for use in multi-threaded and multiprocessing environment. I'm using advisory locking, ...
2
votes
1answer
26 views
Query about advertiser calls times out
I'm a bit of a rookie MySQL coder and I've been tasked with building a query that will join and filter several very large tables (one with ~210 million rows, one with 10 million, one with 2.5 million, ...
3
votes
0answers
25 views
How can I speed up the reading and writing of pixels of BufferedImages?
I'm working on a project that takes in a video file and does some image processing on each individual frame. The first step in that processing is to take each source frame and generate three ...
2
votes
2answers
33 views
Generating a 64 bit unique integer in Java
I need to generate a 64 bit unique integer in Java. I need to make sure that there is very few or no collisions if possible.
I came up with the below code which works fine:
...
3
votes
3answers
108 views
Stack Exchange Data Explorer T-SQL to Find Users by Most Badges
I very infrequently use SQL. I need more experience, so I have created a data explorer query to find those users with most of any particular badge (have to edit the query itself right now to alter ...
1
vote
2answers
18 views
Handling with the 'error' parameter inside a callback function in node.js
I have multiple controllers and every controller has this error handler:
if (error) {
res.render('error', {
error: error
});
}
Sometimes I have more ...
11
votes
4answers
1k views
To understand what recursion is, you must first understand recursion
This is the second assignment for my CS2 course:
Write a recursive C++ function writeLine() that writes a character repeatedly to form a line of n ...
3
votes
0answers
228 views
Polyglot array_extend() function for Javascript and PHP
This is a polyglot function I've made out of fun.
The goal is to grab n arrays (or Javascript Objects) and 'extend' them in ...
3
votes
1answer
26 views
Reducing repetition of sequence-like properties
I have a class that is a wrapper for memory positions of a hardware device.
I need to data-bind each of this positions, so I created a class with hardcoded properties, one for each position, so that ...
3
votes
1answer
62 views
Memory leak using UserControls
I seem to have a memory leak on this method but can't figure it out. This method is called every 10sec by a timer which acts like a refresh.
...
3
votes
2answers
45 views
Reverse Polish Notation calculator in Python
After reading the definition, I made a simple Reverse Polish Notation (RPN) calculator in Python.
Originally it had just 4 operators (using import operator and a ...
5
votes
3answers
56 views
Design of a remoteControl class for connecting to electronic devices
In a course that I'm taking on learning object oriented programming in java, I have completed an assignment for modeling a home entertainment system and the ability for a user to be able to use a ...