instruction stringlengths 71 71.9k |
|---|
Here is my C solution for Sherlock and Queries @ Hackerrank.
Watson gives to Sherlock an array: \$A_1, A_2, ..., A_N\$. He also gives to
Sherlock two other arrays: \$B_1, B_2, ..., B_M\$ and \$C_1, C_2, ..., C_M\$.
Then Watson asks Sherlock to perform the following program:
for i = 1 to M do
for j = 1 to N do
... |
I want to use dependency injection with Unity in my application. I am not following repository pattern and unit-of-work (and don't want to). I also have ViewModel in my controller action method. Please review my code and add your comments.
public class ProductCatagoryController : Controller
{
private dataBaseContex... |
I would like comments on my implementation of a stack:
template <class T>
class Stack {
public:
void pop(T& element);
void push(const T& element);
Stack();
private:
int elementCount_;
int stackTop_;
static const int MAX_ELEMS = 10;
T elementArray_[MAX_ELEMS];
};
template <c... |
I have a scenario where my BaseRepository gets a lot of commands in a short time period. At other moments, this doesn't happen. What I want to achieve is to throttle these commands. I.e., when a command must be executed, wait for a short period (0.2s) for any other calls. If none are made, execute the command (go to th... |
I have written a Tic Tac Toe application with the focus of clear design and easy to read code.
The current algorithms are very crude. I also want to separate them using interfaces. Any tips on improving the design, and making the code cleaner, change variable names?
TicTacToe.java
package tictactoe;
public class TicTa... |
Ruby doesn't have a pass method to 'do nothing' the way Python does - if I want a ternary statement to do something on true, but nothing on false (as in the code below). Is it bad practice in Ruby to fake it this way?
beverage_links = []
beverage_info.each do |bvg|
self.is_menu_item?(bvg) ? beverage_links << bvg["h... |
As part of some code I've written, I needed to perform a 1-D convolution. This convolution ends up happening quite often, so I wanted to optimise it (in some way other than using a FFT, though I could do this if necessary). I expect that my convolution kernels will be ~100, and the vector they are convolved with ~5k.
m... |
A program that creates a grid 10x10 and assigns a random number in each tile. It then asks you if you want to:
create a new grid
view the current one
count how many of each number there are in the grid
sum the rows
sum the columns
exit the program
import java.util.Arrays;
import java.util.Random;
import java.util.Sca... |
I need an implementation of PBKDF2 in C#. There is already a class Rfc2898DeriveBytes, but it uses SHA1, and I need SHA512. The problem that I faced with during implementation is intensive allocation of memory after each hash computing iteration. The proposed solution is to change a little bit SHA512Managed class imple... |
I just recently made an attempt at implementing what I have been led to understand is called a RoundStack, simply meaning contrary to .NET Stack's default behavior of doubling internal array size when it hits capacity, simply starts dropping off items at the bottom of the stack. I am developing this class for the purpo... |
I'm trying to grasp this whole MVC design pattern idea but I'm in the dark if I'm doing it correct. This is where I need some feedback on what I've done so far. Here's what I'm wondering:
Does the hideMenu and showMenu fall under the view or controller?
Have I put viewNewPage in the correct block?
How can I make the a... |
This is "my" version of a basic C++ calculator, that requires a single line input (like 1+1) to calculate the result. I have been (self)learning the language for 2 months now. I don't pretend to have invented this code, but I haven't taken the time to search for this variation.
The functions included are:
Addition: 1 ... |
I was wondering if such a design was a bad idea in C#. Here I have a static class EventLog which holds a list of instances of Event class. This is a simple event log of actions players can do in a game. What can I be doing in a better way?
public class EventLog
{
private const int maxEventsInLog = 50;
private s... |
Original post:
Tic Tac Toe game with emphasis on design and readability
I got great help, but I feel like I have to ask how I can keep the GUI and logic loosely coupled. Is there any best practice that I should follow?
I tried to pass MainFrame object to Games constructor instead, but then I had to redesign MainFrame ... |
I made a Python 3(.4.2) program that only adds classes and is meant to be imported. It allows the creation of files that store usernames and hashed passwords. It uses salting as well. It also can easily check if any given string is the original password (through the User.check() attribute of the User class.)
"""A simpl... |
This is what my class hierarchy looks like. I have an abstract superclass, AbstractLinkedMyList, that contains common operations for both sorted and unsorted linked list.
Here's the declaration for it and the method I have a question about:
public abstract class AbstractLinkedMyList<Type> implements MyList<Type> {
... |
I am trying to reverse a sentence contained in a string and return a string in the quickest way possible using the least amount of memory. Also I don't want to use any unsafe code, so no pointers are allowed. Please let me know if anything can be improved.
My input example is
string mystring = "Hello! my name is";
... |
I have made a merge sort algorithm but am unsure of the 'Space Usage' of the algorithm.
public class Sorting {
public static void mergeSort(int[] arr) {
if (arr.length == 1) {
return;
}
int[] newArrLeft = new int[arr.length / 2];
int[] newArrRight = new int[arr.length - ... |
Challenge: Design a cash register program
Specifications: Your register currently has the following bills/coins within it:
'PENNY': .01,
'NICKEL': .05,
'DIME': .10,
'QUARTER': .25,
'HALF DOLLAR': .50,
'ONE': 1.00,
'TWO': 2.00,
'FIVE': 5.00,
'TEN': 10.00,
'TWENTY': 20.00,
'FIFTY': 50.00,
'ONE HUNDRED': 100.00
Your progr... |
For a game implementation, I have a very large overview map with multiple layers (namely base-map / units / highlight & info / fov-shading) of which the first is CPU-intensive to generate. I have implemented a caching mechanism in which the base layer is drawn once and held in system memory, then drawn on demand by th... |
I'm creating an event loop for an asynchronous event execution library for PHP in PHP. Note that this is for a library and not an application. My event loop is just that -- a simple event loop that doesn't know how to poll / wait for anything specific. It just executes callbacks in order.
Events being waited for are ab... |
I updated my code based on the feedback from my previous question. There is one for the home page and one for the product pages:
Home page code:
<div itemscope itemtype="http://schema.org/TravelAgency">
<span itemprop="name">NAME OF TRAVEL AGENCY</span>
<link itemprop="url" href="HOME PAGE URL">
<span itemprop="descrip... |
I came across this blog post by Adam Drake from around a year ago which is now making the rounds again.
I made some improvements to his code, but wish to see if there are additional tweaks that could be made to make it run even faster.
The task is to extract chess game results from PGN files. The files contain sequenc... |
I want to use the variables that have been declared in a config.php file in a class for testing. I am not sure if this is the right way like I have done it.
I have a configuration file, config.php:
class Config {
public $hosts = array(
'a' => '192.168.1.10'
'b' => '192.168.1.11',
);
public... |
The method creates a link, an edge between two nodes, and calculates the Euclidean distance.
I'm testing that after linking, the link does indeed exist, and that the distance is correct.
I've used a variety of test cases, to check that it works for both horizontal and vertical links (just incase there's a divide by ze... |
Word Ladder
Given a start word and a goal word, convert the start word to the goal word by changing one letter at a time. Each step must also be a valid word.
Is my code modular? I mean are functions are concise, class design etc.? Could someone please review the code and let me know if code is good and if it has so... |
In our application the views and the viewmodels are created in parallel to increase the performance and when the viewmodel is created it is attached to the datacontext.
While there is no datacontext the view shows an indefinite progressbar. To hide it we use the following code:
<!-- Loading background. It gets remo... |
My question is mostly directed towards the principles of object-oriented programming.
I have an Android application and one of the activities has a ListView.
In this ListView, I am displaying a list of players and their leagues. Therefore I have constructed the ListViewModel to be either a league or a player, inflatin... |
Part 2 of this question. I've rewritten most parts of the code, for the better I hope. The code now has some more logic and less readability.
Functions included in the calculator:
Addition
User input 2+2 Program output 4
Subtraction
User input 2-2 Program output 0
Multiplication
User input 2*2 Program output 4
Divis... |
I'm not very familiar with MPI. I've written this little piece of code to draw the Mandelbrot fractal processing each row of the image in parallel. It works but it's really slow. I've written code to perform the same task with OpenMP and with no parallelization, and both run instantly with the default parameters, where... |
Here is how it looks at the beginning:
And after I can add random counts of line edits:
Or delete them:
The main purpose is the possibility to add or delete QlineEdits which stores user names and each QlineEdit adds a username to the vector in the right order (index) like this:
users =>
[0] = "a";
[1] = "b";
[2] ... |
I implemented merge sort with C++ and would like to get some feedback.
#include <iterator>
#include <vector>
template<typename It>
std::vector<typename It::value_type> merge(const It begin, const It mid, const It end)
{
std::vector<typename It::value_type> v;
It it_l{ begin }, it_r{ mid };
const It it_mid{... |
I've made an attempt at a recursive Red-Black tree in Java. I realise that some of my code could be condensed but I tried to favour readability with this code as Red-Black trees can be somewhat confusing.
The tree is implemented as per the method in Lafore (Data Structures and Algorithms in Java), this implementation p... |
I'm writing my own HTTP client, kinda like cURL. (I already know I'm reinventing the wheel, this is more or less getting an inside look of HTTP 1.x before 2 becomes a thing.)
So far pages download perfectly fine using OS provided socket libs. (Linux/Mac)
So what the problem/question is, how can I better my client? One ... |
Suppose there is a huge bitmap, huge_bitmap, in the drawable-nodpi folder. I want to create a custom view with huge_bitmap as its background:
public class CustomView extends View {
private Bitmap mBackground;
public CustomView(Context context) {
super(context);
}
public CustomView(Context con... |
I'm working on this snippet of code within a PHP file. The upload function is working but I suspect it is not secure. I move all the files into an upload folder within the site folder. I think that some of this could be tricked into uploading malicious files but I'm not sure how it would be done and more importantly, h... |
I was going through this tutorial for Pretty Printing a binary search tree and decided to implement my own version. Here is my implementation. This version works only for trees that are complete binary tree. I would like to know what all optimisations can be done (errors present can be removed) in the code.
public clas... |
I'm currently working on an enormous, enterprise level project. There are about 130 other devs on said project, and I aim to document my code in the clearest way, so others may easily see what I'm doing and why. I'm using JSDoc style comments to summarize my functions, but sometimes I feel the need to break it down to ... |
Previous question:
Text-based Snake game on Window
Summary of improvements:
Removed unnecessary functions such as clearScreen()
Added new Matrix and range helper classes
Implemented double-buffer by using WriteConsoleOutputA
Added the color
Split into separate files
How can I improve this game?
World.h
#pragma once
#... |
The goal of my code is to sort data into two categories. It must use a local copy of the initial data from Collar (Top View).csv. My code creates a Collection of items called Collars using the initial data file, then moves each Collar into its respective category based upon its E dimension. I would like feedback on if ... |
I asked this question a few days ago. The question is about producing moving/rolling windows of an array in Python as in the following example:
from skimage.util import view_as_windows
view_as_windows(np.arange(10*10).reshape(10,10), (4,4),4)
Out[14]:
array([[[[ 0, 1, 2, 3],
[10, 11, 12, 13],
[20,... |
My task is pretty simple and my code works, it's just that my code feels a bit clumsy to me (and probably will for you too).
I have a view controller (HomeViewController) with a scrollView, inside this scroll view I have a label, and the scroll view is set to scroll horizontally. So now we have a view controller with a... |
I want to assign the row of a matrix the return value of a function, but the only way I can figure out how to do this is with a for-loop. I'm assuming this is bad and vectorization would be better.
I'm trying to implement the first principle of the Neural Engineering Framework for a class. The function of the code is t... |
I have created an awesome cheat/fan page for the game Doodle Creatures with the help of some cool people in The 2nd Monitor. Is there anything I can do to improve this code?
Here is my ASP.NET markup:
<asp:SqlDataSource ID="SQL_CreatureCombos" runat="server" ConnectionString='<%$ ConnectionStrings:KJAI_DBConnectionStri... |
For a list li, I want to print only the values of the triplets a, b, c where 0 <= index(a) < index(b) < index(c) < len(li).
Example:
f([6, 3, 88, 4])
6 3 88
6 3 4
6 88 4
3 88 4
Here is my solution, but it is O(n**3) (time complexity):
def f(li):
for i, n in enumerate(li):
for j, o in enumerate(li):
... |
I recently started playing around with R and am currently trying to plot GPS data points onto a perspective plot. I have a script that works and I get my desired results out of it and it works ok for my test file of about 12000 data points, but when I increase the amount of data points to about 4 million it takes a whi... |
I'm working through the common divisibility tests, and implementing them in Racket. I'm working on divisible by three, for which I thought it'd be nice to keep summing until I got to a single digit (which I can then check for divisibility by 3).
My code is here, but it feels like there are rather a lot of steps, and I... |
The following is the description of the R build system I am using (very happy) with Sublime Text 2 on linux (Crunchbang). With it, I am able to:
to source the current file.R to an interactive R session;
to send the current selection to an interactive R session (supports multi selection);
to output plots and *.Rout fil... |
How can duplication be removed from this?
class Authentication
PROVIDERS = if Rails.env.production?
%w(weibo open_wechat wechat)
else
%w(weibo open_wechat wechat developer)
end.freeze
end
|
I'm working on a PHP based web application.
While building the UserStorage class, (which acts as a storage source for user data, and implements the UserStorageInterface), I noticed something. The get method fetches the user data from the storage source, and returns it:
public function get($identifier = null, $alias = n... |
I have tried to write a small part of a Poker game to check the Poker hand rankings. Please review and provide your feedback.
package com.sa.test.conditions.poker;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
class Hand {
Card[] cards;
public Card[] getCards() {
return car... |
Lately I have been learning about serialization so I decided to write a little helper class for my application to make it easy to use this feature in multiple places. I actually mixed some generics in the code and want to hear your feedback on my overall approach.
SerializationService.cs
public class SerializationServ... |
What I am planning on doing is pulling the first post of my news section. This was made for VBulletin and now I need to add it for IPb.
package com.rigory.loader.main.services;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
i... |
Here's a function that splits given string according to predefined patterns. It's part of a trigger function used to populate one table from another. I want to be sure that I'm not making any mistakes.
CREATE TRIGGER insert_t2
AFTER INSERT ON t1
FOR EACH ROW
EXECUTE PROCEDURE insert_t2();
CREATE OR REPLACE FUNCTION in... |
I have improved the Pretty Printing of binary tree that I implemented previously. In this follow up I have made changes such that every tree is printed (not just a Complete binary tree).
Here is my changed implementation. Please suggest any improvements that are required.
public class PrettyPrintTree {
public Tre... |
This is a follow up on my previous question:
A grid and a menu walked into a program
I integrated classes into the mix.
The program now asks how big you want the grid to be.
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
class NumberGrid {
private static final int RANDOM_NUMBER = 1... |
I'm a beginner in C++, and I'd like you to review the class I wrote for the Game Of Life.
GameOfLife.h
#include <vector>
#include <iostream>
using namespace std;
class GameOfLife{
public:
GameOfLife(void);
GameOfLife(const unsigned &, const unsigned &);
~GameOfLife(void);
void disp... |
I have resolved the Problem presented in Project Euler #10:
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
But this code takes too long before producing a result, 12.4195167 minutes to be exact.
What should I do to optimize this code?
public class summationOfPr... |
I have this contract:
public interface Stack<T> {
void push(T object);
T pop();
int size();
}
I am curious what you think about my test of the size() and pop() in order to prevent bugs (underlying data structure in not being cleaned) in implementation like below:
Implementation:
public class StackImpl impl... |
I have several huge 100MB text files that I need to scan through to pick out certain frame numbers which relate to a specific log packet of interest. My plan was to scan for these frame numbers and drop them into a list (often 6000+ frames per text file!). Ok so far, but there is second packet of interest which shoul... |
I have written the below code to handle accessing and parsing the data presented in XML format from our server room environmental monitor.
The plan is to call this class from a controller/view handling the "dashboard" on our Intranet page.
Is there any way I could optimize the class? should the methods really be static... |
I'm looking for some hints or advice regarding efficiency, performance and some good coding practices. Also I'm curious about synchronization. The server is multithreaded, so I think some operations should be synchronized.
HttpServer.java
import java.io.IOException;
import java.io.InputStream;
import java.util.Properti... |
This is a follow up to:
Lvl 1 upgradeable attributes
From before:
I've built the groundwork for an attributes (as in Strength,
Intelligence, not as in DebuggerHidden, TestMethod) framework for my
game. Each attribute can be upgraded and downgraded individually as
well as part of a bulk change (such as for upgr... |
This is a follow up of:
Messenger supporting notifications and requests
Shoot the Messenger pt. 2
Shoot the Messenger Part 3
I've written a lightweight (I think) class that acts as a messenger
service between classes for both notifications (fire and forget
updates to other classes) and requests (a notification s... |
I have a WPF C# application that I want to move to a MVVM pattern.
My first step is to remove the button click handlers from the code behind of the UI.
I've found some examples online and then modified them to my needs. Is the following code a good way to use buttons without the code-behind click handlers? And is this ... |
While answering this question, I wanted to use a generic sum of Collection function. Java doesn't have a native method, so I wrote one. There are a couple things I don't like about it though, so I wrote a more specific method for my answer.
public static <T extends Number, U extends Collection<T>> BigInteger sum(U ... |
I have a project that relies on finding all cycles in a graph that pass through a vertex at most k times. Naturally, I'm sticking with the case of k=1 for the sake of development right now. I've come to the conclusion that this algorithm as a depth first search is at worst \$O(kn^{kn})\$ for a complete graph, but I rar... |
I created a pretty complex algorithm for calculating matches on a Bejeweled board that kept track of matches involving wilds. After doing some in-game testing, I found quite a few bugs that needed to be eliminated.
In order to deal with this problem, I first created an undo system for the game, and then when I saw u... |
I have an array filled with 5 other arrays that consists of arrays of 2 values (first a date then a count):
[
[
[dt, cnt], [dt, cnt], ....
],
[
[dt, cnt], [dt, cnt], ....
],
[
[dt, cnt], [dt, cnt], ....
],
[
[dt, cnt], [dt, cnt], ....
],
[
[dt, cnt], [dt, cnt], ....
... |
I still feel like I struggle to grasp some concepts of SOLID principles at times, and am hoping for some clarification here.
The following classes are entities in an Entity Framework project.
namespace MyCompany.MyProduct.Core {
public abstract class DataError {
public int ErrorId { get; set; }
pub... |
This is the a bit of code that works with Echonest API's pyechonest and remix libraries combined with matplotlib.pyplot to offer a simple visual representation of the start and end "parts" of a music track:
#!/usr/bin/env python
# encoding: utf=8
"""
mix_track_utils.py
Analyze music track using echonest API with pyech... |
Project Euler #5:
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
Here is my solution:
class SmallestMultiple {
private static final int MAX = 20;
... |
Project Euler #6:
The sum of the squares of the first ten natural numbers is,
\$1^2+2^2+ ... + 10^2 = 385\$
The square of the sum of the first ten natural numbers is,
\$(1+2+ ... + 10)^2 = 55^2 = 3025\$
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is \$... |
Feedback I would love to hear: Since this is really my first real JavaScript app, being that I can never find a project I want to actually work on, I want to know how I can improve my JS techniques. Am I doing a good job separating logic? Am I using good techniques? Should I completely forget about vanilla JS and just ... |
The problem statement can be found here.
Description (short):
Input
The input stream contains a set of integer numbers \$A_i\$ (\$0 \le A_i \le 10^{18}\$). The numbers are separated by any number of spaces and line breaks. A size of the input stream does not exceed 256 KB.
Output
For each number \$A_i\$ from the last ... |
I'm using SFML to manage my windows and I'm writing this engine to visualize some PSO work. I'm trying to make it generic enough that I can extend it for other simulations later on and keep it as minimal as possible. (I'm going to copy this design pattern to a freeglut initialized openGL 3D engine w/CUDA later on as we... |
I had a problem to define propTypes for my React class. I ran into solution that doesn't feel right:
let React = require('react')
let CallerCard = require('caller-card')
class CallerDetailsPanel {
render() {
return (
<div className='caller-details-panel'>
<CallerCard person={this.props.callerData.o... |
This is the code I've written to find the maximum-weight independent set of a graph path. It's a standard problem with a well-known dynamic programming solution of linear complexity. Since it's a graph path, it's simplified down to a sequence of vertex weights, and we need to find the subset of non-adjacent vertices ha... |
I once asked a similar question but in C#. Now I have the same problem in powershell..
What is the fastest way, to search files newer than 15 minutes, in a file system with more than 1 million files?
Is there any faster way than using pipe?
Get-ChildItem -Path $path -Recurse | Select Name, PSIsContainer, Directory, Las... |
The graphic guy wants to display dates like
16. February
17. - 24. February, or
25. February - 02. March.
Here is my solution:
$d1 = new \DateTime('2015-02-06');
$d2 = new \DateTime('2015-03-02');
$dateDiff = $d1->diff($d2);
if (intval($dateDiff->d) != 0) {
$d = $d1->format('d.') . ' ' . ($d1->format('m') != $d2... |
I've tried to make a better any than before:
#ifndef ANY_HPP
# define ANY_HPP
# pragma once
#include <cassert>
#include <cstdint>
#include <stdexcept>
#include <typeinfo>
#include <type_traits>
#include <utility>
class any
{
public:
template <typename T>
using remove_cvr = ::std::remove_cv<
typename ::s... |
Is there any way to easily remove synchronization from this code, when there is a validation step before acquiring a lock?
I tried an AtomicReference<Pair<Integer, Double>> to hold the state. But that complicates the algorithm a lot because I have to use compareAndSet() in accept(), and then if that returns false, I ha... |
This is a simple program I've made using Qt Creator and Pyside:
I made a list of activities that I would like to enforce
Then I made a program that randomly pick them based on chance
It has some buttons to set an activity as Completed/Postponed
It can be added new activities for extra 'points'
Some activities can take... |
I'm trying to have a HTML / CSS structure for flexible layouts for forms. I tried to look at Bootstrap codes for help with this (without actually using Bootstrap itself). I've gone with something along these lines:
http://cssdeck.com/labs/stidyuic
* {padding: 0; margin: 0; box-sizing: border-box;}
body {width: 80%; m... |
I've made a strange method with multiples conditionals, creating a lot of Lists and I was wondering if I could write it in a better and more legible way.
def findRooms(room:Room) = {
...
if(room.id != null && !room.id.isEmpty)
query+=("_id" -> room.id)
if(room.members != null && room.members.length > ... |
I currently have this code:
<Window x:Class="Listener.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="600" Width="800" Loaded="Window_Loaded" WindowStyle="None" AllowsTransparency="True" Backgroun... |
I'm making a road tax data calculator/parser for practice. I do this because I want to learn more about OOP and arrays with its functionality.
On my previous post, I made this same application but also included the ability to decode the data and putted it in right format. Now, I've already done that with a different ap... |
I have a search form where users can enter ValidFrom and ValidTo dates,
There are three conditions:
ValidFrom and ValidTo NOT NULL
Action: Get values between two dates
ValidFrom is NOTNULL and ValidTo is NULL
Action: Get values where date is greater than ValidFrom
ValidFROM is NULL and ValidTo is NOTNULL
Action: get v... |
I've seen a lot of Objective-C implementations but I'd like to do it in Swift.
I did it like this and it seems to work just fine. Does anyone have comments and/or improvements to make?
import SystemConfiguration
class EnvData: NSObject {
class func getSSID() -> String {
var currentSSID = ""
let ... |
In my project, for inserting an autosuggestion function (also in presence of little insertion errors, like Google), I've created this class:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.SortedSet;
import java.util.TreeSet;
... |
I have a series if statements where I am trying to find the highest resolution file in an set of files. Is there a way that I can refactor this code to be shorter and or cleaner?
begin
icon = icons.find { |name, _| name.downcase.include? 'xxxhdpi' }
if icon.nil?
icon = icons.find { |name, _| name.downcase.inclu... |
I am very new to network programming and I'm thinking I have probably misconstrued the creation of an appropriate TCP listener. The code I have below works perfectly, but I have a feeling it's a "hack and slash" miracle and could come apart easily when set into my production environment. What can I do to improve this r... |
How can I refactor this method to look cleaner and free from 2 If statements?
If NullableDate.HasValue Then
Dim DayCount As Integer = (DateTime.Now.Date - NullableDate.Value).TotalDays
Dim positive As Boolean = DayCount >= 0
dim TimeLenght as Integer
If positive Then
If DayCount <= 364 Then
... |
I have a custom class I've written which allows me to validate individual properties of items, without firing validation errors on other properties. This allows me to individually validate what my users are editing without flinging up a lot of red mess on fields they haven't gotten to yet.
The validator uses reflection... |
I am a newcomer to jQuery and am working on an app that allows the user to paint images. To do that, I've created a color palette, and if a user clicks on a color, the paint brush successfully changes to that color. However, my code looks really ugly. I really want to clean it up.
$(document).ready(function() {
... |
I'm wondering wether there is a way to walk through every branch of this switch without using goto
public static List<KpiGroup> GetKpiGroups(int siteId, int topLevelProjectId, SiteDetailsModel.KpiCategory category, bool applyMapFilters)
{
var kpiGroups = new List<KpiGroup>();
switch (category)
... |
Below is the code to find the minimum average waiting time for customers at a store. I want improve the time complexity of the code. As an overview of the logic, I start from currentTime = 0 and increment it by preparation time of the current order (as only one order can be prepared at any given time). When that order ... |
I would love to hear any thoughtful suggestions on how to improve my programming style in order to be more understandable.
Listed below is a sample of my code which I wrote in Eclipse:
//Implement using a linked list
public class FrequencyBag<T>
{
// TO DO: Instance Variables
private Node firstNode;
private int numOfIt... |
I'm wondering if my code is just a tad too long to post here, but if the only consequence seems to be getting high-level reviews, then that's perfectly fine.
This is my implementation of Hangman in C++, split up into a handful of classes. I'm familiar with the syntax of curly brace languages but lack experience with th... |
Project Euler #7:
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?
Here is my solution:
public class PrimeFinder {
public static void main(String[] args) {
long time = System.nanoTime();
int result = getNthPrim... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.