+1 for if you name them StringType1, StringType2 etc, I'll chase you with a bat ;) — Mat's Mug24 secs ago
Is this comment completely off?
Encapsulation enables Abstraction; together with Inheritance and Polymorphism, it's one of the 4 pillars of OOP, on which everything stands - including SOLID. — Mat's Mug21 secs ago
Jonathan you are absolutely write.
But In my pc when I add that html my file in google chrome browser, it does not downloads. When I open that html in internet explorer it works and my file opens or downloads. can you help me solving that problem?
Thank you
I'm using this code to bring my phone numbers in a consistent format.
Desired: +(country code)phone number
possible patterns:
01721234567 -> change to desired pattern
00491234567 -> change to desired pattern
+4912345678 -> do nothing, already desired pattern
This is what I use:
String num...
I have used C# to code. Duplicates are removed inline.
public static void removeDuplicate(char[] inpStr)
{
if (inpStr == null) return;
if (inpStr.Length < 2) return;
for (int i = 0; i < inpStr.Length; ++i)
{
int j, k;
for (j = 1; j < inpStr.Length; j++)
{...
I'm a beginner to competitive programming, and I'm trying to practice for the USACO.
I was reviewing old problems, and this solution stumped me.
Problem link: http://usaco.org/index.php?page=viewproblem2&cpid=188
Solution link: http://usaco.org/current/data/sol_typo.html
I was attempting to ...
Please be brutal and let me know what you think of the code below, if written at an interview. Thanks.
Problem:
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return [1,3,3,1].
Time it took : 25 minutes(perfectly working solution)
Space Complexity : O(...
The purpose for Code Review is to get others to review code you've written to help you improve it and perhaps to become a better programmer. Since your question doesn't contain code that you've written to review, it's not really on topic here. See codereview.stackexchange.com/help/on-topic — Edward2 mins ago
Only been here for three days, and he's already learning well. :-)
Wait... I thought we had confirmed that Edward was just someone else in disguise? Is that a new user? Edit: whoops... Looks like I got confused. Long SE history, just new to CR :p
I've been around SE for a little while on an occasional basis, but around computers in general for a long time. @JerryCoffin may remember me as a moderator of 80XXX back in the 1990s or so.
I have previeous;y posted my php code with way to many nested blocks I hope I fixed it right.
Many thanks to anyone who helps.
Pieter de Vries
PS: I would like some tips on my OOP because this is very new to me.
class event {
//Builds the event in html
public function renderEvent($Array) {
...
I have taken a look at several answered questions on Stack Overflow about jQuery's new (since 1.9.1 upgrade)
.on('click','',function(){}
and that you need to delegate. However, in each one, it just provides the solution to fix the issue, but I need a bit more finest or an explanation to why it...
@Jamal A wasp I found behind my house one evening. From the looks of things, newly hatched and not quite able to fly yet. Flew away a few minutes later after his (her?) wings dried.
Let's make your relevant enum more relevant:
typedef NS_ENUM(NSInteger, JobType) {
MiningJob = 0,
LadderJob,
BottomBuildJob,
WallBuildJob,
RoomBuildJob
};
Now let's change the argument type of all the methods where we want to send a job type:
As example, get rid of this:
...
Funny, I actually learned something while reviewing my own Dictionary<TKey, TValue> implementation... Doctor, I get a warm-fuzzy answering my own CR questions, is there a cure?
I've been trying to expand my programming horizons, and have entered the world of grammars and parsing, which I'm brand new to. I have been improving a little implementation of Dijkstra's shunting yard algorithm that currently handles negatives and parentheses correctly (which took a bit of work)...
I have here a set of code that is used for retrieving and storing conversation for a chat application if found this from a tutorial and tweak it a little bit. This script works fine but my concern is if its the standard way can somebody please check this for me if its deprecated or a bad practice...
I have an Account, User and Group model. All User and Group records belong to an Account, so it is possible for both users and groups to be related to various accounts.
Basically, I have some really hacky, pieced together SQL queries that lookup all Account records related to a given User or Gro...
Converting assembly code to nodejs,
Having the assembly code:
CMP AL, DL // DL = 09, AL = 35
JA SHORT // jump is taken
SUB DL,AL // ---> jumped
JMP SHORT // ---> jumped
NOT AL // AL = 35
INC AL // AL = CA (which is 202)
ADD DL, AL // AL = CB, DL = 09
Converted to nodejs code:
if ...
I need to further simplify this solution to auto-format a text-box field intended only for the user to enter their college Grade Point Average (GPA). Here is my code:
<label for="collegeGPA">GPA:</label>
<input type="text" name="collegeGPA" id="collegeGPA" maxlength="4" style="width:45px;" onpas...
Given a complete binary tree returns the following format (Parent ( leftchild (leftchild, rightchild), rightchild(leftchild,rightchild) ). Looking for code review, optimizations and best practices.
public final class PreOrderList {
private TreeNode root;
/**
* Constructs a binary...
I am trying to create a library of my own which contains (among others), a class called Point. As the name suggests, it is intended to encapsulate a point represented in 2D space. This is what I've come up with:
package geom;
import static java.lang.Math.atan2;
import static java.lang.Math.cos;...
A few weeks ago, the question Dijkstra-like routing algorithm introduced the dijkstra tag, intending to refer to Dijkstra's shortest-path algorithm.
Now, the question Infix-to-postfix parser using Dijkstra's shunting yard algorithm has been posed, and Jamal has added the dijkstra tag to it.
Of ...
I have a method that finds 3 numbers in an array that add up to a desired number.
code:
public static void threeSum(int[] arr, int sum) {
quicksort(arr, 0, arr.length - 1);
for (int i = 0; i < arr.length - 2; i++) {
for (int j = 1; j < arr.length - 1; j++) {
for (int...
The teaching tag was recently created. There are now three questions carrying the tag.
Its intended purpose is described in its tag wiki:
Much like the [beginner] tag, this tag should call out that extra care
should be taken reviewing the code. Your code review might impact how
students...
Meme: Exploding bear traps
Originator: Grace Note
Cultural Height: The 2nd Monitor, Website Graduation
Background: During the endless talk about Code Review graduation, some were wondering whether Code Review could even graduate some day or was doomed and would close. The answer was as follows...
@Vogel612 Ok, that was probably one of my worst typos.
I have implemented a ThreadPoolExecutor that will run a Consumer<T> only on elements not already consumed. This code uses Java 8.
The background behind this is that I scan a directory every x time units for which files are present, I must maintain a 100% accuracy on finding files and other mecha...
I have a model Collection which has a many to many relation to a model Item.
I want to be able to add or remove items to this collection using Django Rest Framework.
Option1 - make an action:
class CollectionViewSet(viewsets.ModelViewSet):
queryset = Collection.objects.all()
serializer...
How could I reduce the length of my functions restricting them to max 10 lines?
Other comments are welcome on the sourcecode general.
import config_files
import math
from datetime import datetime
import importlib
import sys
from scan_twittosphere import *
from tweets ...
As soon as I saw the First missing positive question, I decided to write my own method for this before writing my review on the question.
Judge me by the same standards as bazang wants to be judged, i.e. As if this was written for a big company such as Google for an interview.
I wasn't sure how...
Description
This is a follow-up question to Tool for creating Code Review questions.
Things that has changed include:
Removed replacing four spaces with one tab, all tabs and all spaces in the code itself is now left as-is.
Added file extensions to the output.
Switched order of lines and byte...
#!/usr/bin/env python
from os import environ, path, name as os_name, getuid
from sys import exit
from fileinput import input
if os_name != 'nt' and getuid() != 0:
print "Rerun {0} as `sudo`".format(__file__)
exit(1)
def custom_vars(e_vars):
if not path.isfile('custom_vars.txt'):
...
If you would generate hashCode first, without any fields, then generate equals with some fields added then I'd understand it. But this is just... nuts...
My code is working fine and returning results but after I have added a loop hoping that it would return all my data from my database
it only returns
[Object Object]
Here is my whole Php code
$con3 = new PDO("mysql:host=". db_host .";dbname=db", db_username , db_password);
$con3->...
@skiwi Because the .contains and .add needs to be done within the same locking. Otherwise, .contains can return false for two threads, causing them both to call .add, and both will call super.execute
I don't think this is the right stackexchange to post this kind of question don't think there is a stackexchange for this kind of question anyways.
I pretty much have a bug on my website which a similar website doesn't seem to have and I can't figure out the cause of it.
My website is http://ww...
I have an application which I'm trying to write unit tests for (Yeah I know, talk about bad practices)
I have the following class here
public class UserManagementService : IUserManagementService
{
private static readonly IUserDao userDao = DataAccess.UserDao;
private static readonly...
I am writing a simple interpreter for esolang ArrayPL I made. And I want someone who knows Python really good take a look at it. Maybe you will see some way to improve the code? Also, I am not very sure loops in ArrayPL are working OK...
Here is the source file:
#!/usr/bin/env python
##Interpre...
I'm doing VBA macros and need to use Arrays of values extensively. After the below help from @TonyDallimore in StackOverflow, I've decided to use nested variant arrays.
http://stackoverflow.com/questions/20971161/vba-chrashes-when-trying-to-execute-generated-sub/20973615#20973615
I have no form...
I should have another bridge class that takes in the element, the Consumer<E> and an Executor, and decides for itself if it should pass the elements on to the threadpoolexecutor or not.
Well the first implementation was that I implemented the list's in the threaded Consumer<T>s, to find out that it was saving lists per thread, so I refactored it one method up
And that refactoring up appeared to be the threadpoolexecutor
@skiwi "I should have another bridge class that takes in the element, the Consumer<E> and an Executor" this you can accomplish simply by not extending the threadpoolexecutor and using it as a private field instead.
I have below enum. I need to get the description by code. I have below code. It is working but can it be improved still?
public enum Maps {
COLOR_RED("ABC", "abc description");
private final String code;
private final String description;
private static Map<String, String> mMap...
public class SingleExecutionExecutorBridge<T> implements Consumer<T> {
private final Consumer<T> consumer;
private final Executor executor;
private final Set<T> elementsInProcess = new HashSet<>();
private final Object lock = new Object();
public SingleExecutionExecutorBridge(final Consumer<T> consumer, final Executor executor) {
this.consumer = consumer;
this.executor = executor;
}
@Override
public void accept(final T element) {
@skiwi I would use the version with a synchronizedSet and using the .add method only. And rename it to SingleExecutionBridge. Besides that, it looks neat and clean.
I need to use SQL extensively in VBA macros that I write. Since the DB is from our enterprise application, I use vendor's library for this.
I generate dynamic queries, sometimes with many joins, unions and the queries can be quite complex.
The procedure that I coded screams "I'm open to SQL inj...
I agree with @SimonAndréForsberg and @palacsint's answers, I have however reconsidered the design and noticed that I do not even want to really use composition for the ThreadPoolExecutor.
I have refactored the code to the class below, where the following assumptions hold:
- The Consumer<T> is al...
I got the point of PEP8 naming conventions,
docstrings going inside methods,
catching exceptions and printing them,
not doing import *. will correct them.
I need a bit of advice on the robustness and flexibility for the following code. do you find the variable names descriptive and the flow ...
@skiwi by the looks of it, that entire class SingleExecutionExecutorBridge is designed to add parallelism (a fork) to a stream of items being collected.
Why have the class when either a) the stream can be parallel b) the collector can do its own parallelism.
You are right, I don't see the whole picture, but, you could have a BlockingQueue<T> and your collector could just a -> queue.add(a), then have your executor service pulling items off the queue as needed.
why make your collector delegate to another collector.
I am saying that, assuming you can't use the native parallelism of the actual Stream API, that you could merge your executor service in to a single collector, or have it outside the stream entirely, yes.
@Edward you seem like a nice guy, why don't you keep it that way ..... ;-)
@skiwi - you should think about it, because, I don't understand the bigger picture, but looking at your class, and in fact, looking at your whole question, ... well, my spidey-senses are tingling, there's something wrong.
So the two functions below both send emails via PHPMailer but both hold different messages (which use different data from the db). I was just wondering (as I plan to use PHPMailer more) a way to consolidate these functions into perhaps a sendMail() function which could handle different data varia...
I started refactoring it, because I wanted a ThreadPoolExecutor that has the property that it would not execute tasks, that have already been submitted
But wouldn't it be better to have a ThreadPoolExecutor that would take care of this for me? The only issue with it, is that it breaks the contracts if I were to implement it.
@SimonAndréForsberg Because I need a specialized parallel execution, in a config file I can set the amount of threads it will use when executing (requirement)
@skiwi - then keep the stream as a single-thread stream, have a HashSet in a filter, that returns true if the item has not yet been processed, and then your collector just needs to submit the item to a standard FixedThreadPool.
@SimonAndréForsberg Consider that I put 100 invoices in this system The program has at least 6 stages (picking file from directory, processing, writing to different directory)
Stage 1 may not block the whole pc
The job of the concurrency cap is to provide a balanced way of distributing resources over the different stages
So setting it such that one stage uses 50% of the resources is allowed, but we cannot allow that stage 1 will use 100% resources and that the other stages would be dead