« first day (334 days earlier)      last day (3908 days later) » 

00:25
I like this reviewer
+1 for if you name them StringType1, StringType2 etc, I'll chase you with a bat ;) — Mat's Mug 24 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 Mug 21 secs ago
(I'd downvote the answer but it's so I won't)
@Mat'sMug I'm resisting the urge to convert "Pillars of OOP" into an acronym.
8
Too late for me.
I know a No. 1, and a No. 2, but now there's a #4 PoOOP
fine, comment deleted ;)
POOP is better
00:39
What is more concerning, is the SOLID POOP that everything stands on
^^ this is why acronyms are evil!!
@Mat'sMug Those are bad. We need a Creative Replacement Acronym Program.
4
wow I asked 8 or the 13 questions
@rolfl that was my downvote, have I stirred POOP?
I'll put a comment next time. 101th downvote, I should know by now. (slaps fingers)
01:09
I still think it's really cool that I have non-example, production, on-the-app-store code which uses foo as a variable name.
QUICK Before it's deleted:
-8
Q: Hi Jonathan, Help me out please

Dawood NajamJonathan 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

LOL
> easy with the down votes people - 3 is enough – Vyren Media 2 mins ago
-15 as of this writing
@Mat'sMug and gone
my faith in Humanity as well!
Jonathan is going to be upset if you delete his inbox.
01:26
0
Q: Bring phone numbers in consistent format

PhilipI'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...

01:44
@SimonAndréForsberg Congratulations on 10k!
3
This answer thinks it's posted on PCG:
0
A: Remove duplicates from string without using additional buffer

Gurunath NavaleI 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++) {...

And this one is... well... flagging as NAA
0
A: Remove duplicates from string without using additional buffer

user3412252In the C# code if we start int j = 0 then it removes all the duplicates including the one in FOOOOOOOOLLLLLOWWWWWWWWWW UUUUP

@Mat'sMug Oh. I meant to delete that answer sometime.
As for the second answer, either the user also thinks Java == C#, or he was trying to reply to the answer.
Either way, I have deleted both.
you might think I'm crazy
oops I did it again
kill it with fire
Oops I Did Starred It Again?
4
01:58
@Jamal ROFLMAO
the song I am listening to should be my theme song...jk lol
Work B*tch
0
Q: Difficulty Understanding Solution - USACO

user3486543I'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 ...

0
Q: Pascal triangle produced for a particular integer K

bazangPlease 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(...

02:19
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-topicEdward 2 mins ago
Only been here for three days, and he's already learning well. :-)
2
02:31
side-effect of The 2nd Monitor I guess
or of being on SE for 3 months or so
One more user who actually knows what the hell belongs on this site is good enough for me.
02:48
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
@Corbin First showing up on 1 April may have given the impression I was a sock puppet.
However, I claim actual personhood even if all you see is characters on a screen. :)
Yeah, that's the assumption I made :)
Either way, glad to have you. We always need more people at CR, especially answerers :D
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.
@Edward As in Ed Beroset?
Yep. Cover blown.
:)
03:02
Nope--no memory of you at all. Pretty sure I never heard of you before. :-)
I'm sure my parole officer will be happy to hear that.
2
I noticed we went back to 95% answered, so I just posted two selfies and now have zero unanswered questions. We're still at 95% answered though.
could we have reached some point of equilibrium between answering rate and incoming zombies?
0
Q: Too many nested blocks fixed but not sure if this way is right

Pieter de VriesI 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) { ...

The classic matryoshka doll problem...
03:09
@Edward So what are you doing nowadays? As I recall, you worked for Compaq (on BIOS) back then didn't you?
@JerryCoffin Correct. These days I'm working for a "smart grid" company doing more management than direct tech work.
linked-in invite sent. -- you can read all about it. :)
Love small-world syndrome
4
0
Q: Is there a way to avoid calling the document with jQuery on click?

azngunit81I 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...

@rolfl not just a small world -- it's kinda crowded, too.
That's true.
03:18
@Edward I'll I'll keep my eyes open (though nothing seems to have shown up yet).
Seems like kind of a shame to waste such a good coder on mere management, but such is life I guess. :-)
@JerryCoffin: I've always wondered: what's that in your avatar?
I think it's some kind of insect bug
@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.
Ah. All this time I thought it was some kind of spider.
this answer is WinstonEwertesque:
3
A: Job queue that performs actions

nhgrifLet'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: ...

03:23
@Mat'sMug That's a pretty roundabout way of saying "long". :-)
epic!
@Edward I think I've found you there.
@JerryCoffin the NSA apologizes for the email delay.
@Edward I doubt that. Apologizing would involve saying something and we all know they Never Say Anything.
Hm... Needs Some Acronyms.
03:29
@JerryCoffin True enough.
It's late here and I have an appointment with Mr. Sandman. See y'all later.
@Edward G'night.
'night!
Funny, I actually learned something while reviewing my own Dictionary<TKey, TValue> implementation... Doctor, I get a answering my own CR questions, is there a cure?
@Mat'sMug Maybe, but you really don't want it.
I really don't want it, and if I did I wouldn't really want it. Uh, ...Mr.Sandman has another appointment here, see you tomorrow!
@Mat'sMug C ya.
03:39
1
Q: Infix-to-postfix parser using Dijkstra's shunting yard algorithm

mebobI'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)...

04:10
0
Q: Javascript/Ajax coding standard

user256009I 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...

0
Q: Optimizing code for quering multiple related records in Rails

bschaefferI 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...

04:41
0
Q: Properly handling NOT operators for nodejs

majimbooConverting 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 ...

05:07
@StackExchange ... assembly to JavaScript? That's a new one... o.O
it begs the question...for the love of god WHY
05:20
0
Q: Auto-Format GPA while typing : REVISED

James Anderson Jr.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...

05:58
morning
06:24
0
Q: Return complete binary tree in following string format (Parent ( leftchild (leftchild, rightchild), rightchild(leftchild,rightchild) )

JavaDeveloperGiven 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...

1
Q: A Library Class : Point

ambigram_makerI 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;...

06:40
0
Q: Tag soup: [dijkstra]

200_successA 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 ...

06:57
0
Q: Performance analysis of 3 digits sum

LiondancerI 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...

@skiwi monking
Monking @Vogel612
I'm wondering if a somewhat more technical question is also correct for CR?
no clue...
It is definately working code, that may be possible to be improved upon
you'd need code...
where's the but(t) then?
07:09
It's just one class
which is relatively small
I think it's reviewable though
@skiwi you do know the Mug can write a 2-Pages review on 2 lines of code, do you?
hehe
It first deserves a trip to SO though, to get it working...
07:28
0
Q: Appropriateness of [teaching] tag

200_successThe 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...

damn
private SingleExecutionThreadPoolExecutor<UniqueTimePath> executor;
0
Q: Largest Palindrome Checker

user3296744import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; public class LargestPalindrome{ static ArrayList palinList=new ArrayList(); public static void splitString(){ String actualString="ABCBAHELLOHOWRACECARAREYOUILOVEUEVOLIIAMAIDOINGGOOD"; for(int i=0 ; i

Hell everybody! :)
goto hell(yourself);
;)
That was so stupid, I have a .bat file for long that cleans up testing directories, but I forgot to add that it should not touch the config file...
07:50
0
A: What's a Zombie? And what are the many other memes of Code Review?

MorwennMeme: 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.
@Morwenn I believe that was on my first Day here, that this meme came up....
08:07
0
Q: Extending ThreadPoolExecutor

skiwiI 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...

@StackExchange You're slow
The serial votes yesterday got reversed btw, have received +16 this night on SO
@skiwi serial votes?
@Vogel612 Yeah, someone had done 8 random downvotes on my answers yesterday on SO, I was suspecting it was the same person
and it was true?
not bad, you are now officialy a target of internet-hate
It was reversed, so I am thinking that it was true
08:38
0
Q: Django Rest Framework - add/remove to a list

j-aI 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...

@200_success Thank you thank you, fish and moderator! :)
Monking!
Morning @SimonAndréForsberg!
Monking
Good morning all
08:55
0
Q: Reducing lines of methods of Python class

codiousHow 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 ...

Monking @NiallSzalkai
@Vogel612 How is it going so far? :D
well I should refactor the current Data-Access-Layer of the application in our company...
but the classes are quite tightly coupled...
and I'm really not in the mood..
so.....
Wow! The serial voting on SO just continous again...
@Vogel612 Sounds better than my shitty admin job!
09:06
@Vogel612 If you're not in the mood, then you browse SO and CR
lol I really am double your rep? @skiwi
that surprised me..
@Vogel612 I'm not that active on CR... still don't have much time for it
Most of my rep is on SO
@skiwi And yet you're in the CR chatroom?
09:22
@SimonAndréForsberg Yes, I am!
@skiwi Then get some CR rep!
@SimonAndréForsberg I will, you may always help me!
You could take a look at some of my questions and post an answer about a better way to do it with Java 8 :)
Not all my questions are meant to be for Java 8 though
but I have found two that may use Java 8
10
Q: First missing positive with only primitives

Simon André ForsbergAs 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...

9
Q: Follow-up to tool for posting Code Review questions

Simon André ForsbergDescription 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...

I've got no time for it now, but I might do it later....
It's my experience that answers tends to give you more reputation than asking questions :)
You tend to earn a lot of rep on SO by instructing people in the Java 8 way to do it, the same can be applied here.
09:31
Well, answers tend to get upvoted faster, and give double rep!
When am I going to fix my linked list then?
Linked Lists are not important, only reputation is important!
I just did the unthinkable..
I created a Controller class responsible for chosing / removing a certain instance from a List<T> without even importing T
You mean T as a generic type? Or as a concrete type?
Concrete...
it's a model type.
good ol' POJO
How did you not import T then :D
You used Class<T> ?
rather T.class
09:43
well i'd need to import T for that too, so no.
	@Inject
	IAddressService addressService;

	@Inject
	CustomerDetailsManager customerDetailsManager;

	@Inject
	AddressEditController addressEditController;

	public void makeMainLocation(long newMainId) {
		addressService.makeMainAddress(newMainId);
		customerDetailsManager.reloadCurrentCustomer();
	}

	public String editAddress(long addrId) {
		redirectToAddressView(addrId);
		return Pages.CUSTOMER_DETAILS;
	}

	public String deleteAddress(long addrId) {
		processDeleteAddress(addrId);
		return Pages.CUSTOMER_DETAILS;
that's the complete class...
without headers tho...
T would have been Address, but who needs that ;)
@Vogel612 via injection?
You mean 3 * n + 1, not 3 * n + n. Although it might be educational to see what happens with 3 * n + n. — gnasher729 8 mins ago
nope..
It just moves completely over Id.
ah
ouch
and the id for the public String methods comes from View.
Why is there no checked AlreadyDeletedException?
09:46
there isn't even List<Address> anywhere in my code...
Via an IllegalAccessException hurts
nono... I think it's a NPE if there already was a deletion..
Address managedAddress = entityManager.find(Address.class, delete);
if (managedAddress != null)
    entityManager.remove(managedAddress);
I mean naming an exception hurts
You shouldn't need to name an exception, the excepiton class should tell ^^
that's the code for deletion
eh? That code is useles..
it does nothing..
wat.
0
Q: Setting global environment vars from Python

A T#!/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'): ...

09:50
I just removed about 20 lines of totally useless, absolutely never called code..
@Vogel612 Great ^^
thanks for that one ;)
I was so obsessed by the names, that I did not even realise it was empty code.
the fun thing is, the service was worse...
@Vogel612 If I would do that with the code I had to deal with at work, I could probably clean up about 10% of the entire code base...
09:54
 try{
     // code above
 } catch (OptimisticLockException e){
     facesContext.addMessage(/*...*/);
}
@SimonAndréForsberg So your first part of the answer boils down to that Netbeans equals and hashCode generation is a bit broken? ^^
@skiwi NetBeans really generated that for you?
@SimonAndréForsberg yes
Did you generate them at the same time really?
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...
0
Q: JSON result returns [Object Object]

user256009My 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->...

09:58
@SimonAndréForsberg I know, your solution is definately better! Btw, is there a reason why I cannot just wrap the list into a synchronizedlist?
Alt + Shift + S , H and eclipse generates hashCode and equals for you, with fields you can choose..
@skiwi You could, but.... ah... wait a minute! Edit incoming!
@skiwi Edit applied!
Time to read your reedited review
Also @SimonAndréForsberg, the suggestion on shutdown(), does it not garbage collect everything by itself?
@skiwi Garbage collecting and calling shutdown() are two separate things.
yeah ok, true
I think the synchronization on a lock is more understandable
Can you explain why you do the .contains() in the synchronized (lock) aswell?
10:10
@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
@SimonAndréForsberg Ah sorry, I see now that you moved some lines (because of that)
There is a problem though
And what's that?
It's nothing
It's no issue as the execute() method cannot give exceptions any way as the runnable is executed on a different thread
10:46
0
Q: Not refreshing / drawing Canvas Screen when no animations on screen

user3435580I 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...

0
Q: Refactoring method to make it unit testing friendly

the 8th bitI 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...

does this qualify for a review?
0
A: Performance analysis of 3 digits sum

user40012This won't change the Big O but the second loop can start at j = i + 1.

Well, it seems to be an improvement suggestion.
It's a minor one, but still.
One of the moderators might add a post notice to it, I'm not sure. @Jamal?
11:03
0
Q: Can someone take a look at this code for interpreter

Vik2015I 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...

0
Q: VBA Rank of variant array with variable dimensions

TeeracroptusI'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 had lunch
@SimonAndréForsberg What do you think of inheritance vs composition on my question?
@skiwi I'm not really sure about that one actually.
I think what palacsint brought up does make sense
Monking!
What about a workaround, adding a getThreadPoolExecutor()?
@Vogel612 I upvoted it.... new user, valid answer, even though minimal.
11:18
@skiwi I've made up my mind, I think palacsint is absolutely right. And no, I don't think you should add a getter for that, what good would that do?
Scrap that workaround, then people can use the normal execute()
Monking @rolfl
As it currently stands, you're breaking the contract of the Executor interface.
morning @rolfl
Ah yeah, breaking implementation contracts might be an issue
Shold I even be extending ThreadPoolExecutor
11:19
"Executes the given command at some time in the future." - That you are not doing. Instead you are currently doing nothing
our concurrency guru is here now though
Morning.
No, you should use a private ThreadPoolExecutor that you are delegating stuff to
that is the meaning of "composition over inheritance"
Monking, @nhgrif
The problem is that the ThreadPoolExecutor works on Runnables
MONKING!
2
11:20
I want to work with the elements itself
I think I'm doing it all wrong.
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.
Does that sound reasonable?
I am looking at your problem description, and I am wondering why you are implementing a ThreadPoolExecutor... they seem to be different things
I have to commute, will be in the office in 40 ...
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.
@SimonAndréForsberg Why the need for a private field though? I want an already instantiated executor in my bridge
@skiwi Then you need to store the executor as a private field, don't you?
11:28
Yeah true
But no need for delegating etc.
So it's not even composition
You can of course get rid of your multiple constructors and only using one constructor that takes a previously instantiated executor as a parameter
Well, you gotta be delegating something don't you? How else do you expect them to run on the ExecutorService?
So I would still call it composition.
Well... maybe
Hmm, mindf*** incoming
Hang on, need to work this out
0
Q: Java enum containing a hash map for look up?

user755806I 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...

@SimonAndréForsberg here:
    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.
11:36
Should the Executor not be in the name? I don't know myself either
I'm wondering if posting that class with explanation as answer to my own question is something I ought to do or not...
@skiwi It already has "Execution" in the name, you really need "Executor" as well?
I think you can post that class with explanation as an answer, might get you some rep :)
0
Q: VBA Dynamic SQL and SQL injection

TeeracroptusI 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...

12:15
0
A: Extending ThreadPoolExecutor

skiwiI 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...

This seems broken to me:
@Override
public void accept(final T element) {
    if (!elementsInProcess.add(element)) {
        return;
    }
    executor.execute(() -> consumer.accept(element));
}
Why is your one consumer delegating in a different thread to another?
Why do you need the intermediary... why not just make the consumer instance do the parallelism....?
I think there is a design problem here, an over-engineering.
I don't think so, but well... let me digest your comments
I thought about the same thing (perhaps?) just now, there's really no need for the Executor to be sent to the class. That could be extracted from it.
I'm confused now
The executor is only used on one line, and the consumer as well, and that's the same line.
12:22
Anyway, any benefits of parallel consumption are probably negated by the SynchronizedSet.
The execution times are fairly high by the way, that's no worry
@rolfl That depends on how long the execution itself take, doesn't it?
That is true ^^^
On execution time we are talking about seconds for this project
Oh, that's slow.
12:24
Sorry, we don't have Watson here at my place...
I can sell you one .... ;-)
Can I pay it?
doubt it...
executor.execute(() -> consumer.accept(element));, what was dubious about this?
0
Q: robustness and maintanability based on descriptiveness of variables and docstrings

codiousI 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 ...

12:25
@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.
I'm not sure if you see the whole picture, or if I am showing the whole picture
Hmm let's play it the other way around, what would you suggest then if you say that the code is redundant?
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.
I'm realy thinking now...
alternatively, you can make your collector feed Callables on to the executorservice.
@rolfl sounds like a job for a linked list. <ducking>
5
12:31
You say that the only functionality it provides is the elementsInProcess, and that that functionality could be factored out to the top layer?
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 ..... ;-)
2
^^^ooops ... much better.,
So I should refactor the refactored code into another refactorization of the codebase?
Does an Executor mind if I directly inject into his BlockingQueue?
And that sounded awkward...
@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.
@rolfl Is it safe to directly add elements to a blockingQueue, which is being used by an ExecutorService?
@rolfl Must remember that not everyone knows my sarcastic side ... :(
@skiwi first you have to get the queue, and that requires abstracting the service.
I think your problem can be solved a simpler way.
I just don't know what your problem is.....
@skiwi What's your problem?
12:41
I have the following:
Files.list(directory)
        .map(UniqueTimePath::new)
        .forEach(singleExecutionExecutorBridge::accept);
which used to call .forEach(fileConsumer::accept)
I only want it to accept, if the element has not been accepted yet
Sounds like the job of a filter()
0
Q: Optimising and consolidating multiple PHPMailer functions

jshjohnsonSo 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...

So not even needing to keep a reference to the queue indeed...
Why did I make it so complicated then?
^^^ that is what I have been asking
only hmm, then in the foreach I need a small delegate (local method) that also adds it to the list
And then the need for synchronizatio also disappears
As that's not the stream's job, but the executor's job
But now, we are back at the start @rolfl
12:47
26 mins ago, by rolfl
I think there is a design problem here, an over-engineering.
I started refactoring it, because I wanted a ThreadPoolExecutor that has the property that it would not execute tasks, that have already been submitted
You need to ensure that only one item gets through the filter.
Which I now still have not accomplished
The trick is to only sumbit new tasks, and you can do that in your filter with a synchronized set.
private void checkDirectory() {
    try {
        Files.list(directory)
                .map(UniqueTimePath::new)
                .filter(path -> !pathsSubmitted.contains(path))
                .forEach(path -> {
                    pathsSubmitted.add(path);
                    executor.execute(() -> fileConsumer.accept(path));
                });
        innerRun();
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}
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.
12:50
Something like filter(a -> {chm.put(a, true) == null;}) where chm is a ConcurrentHashMap
@skiwi Why do you need a ThreadPoolExecutor when you can use a parallelStream?
^^^ exactly
@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 And why do you need that 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.
12:53
^^ Yup, what monkey said
@SimonAndréForsberg Because multiple processes will operate on a system, that should not conflict, and every action has a running time of seconds
@rolfl Wait, what? I need to digest that.
Still don't see the actual need for the config file...
So you say I should implement functionality in a custom collector?
I think using .forEach can work just as good as a collector.
or better
@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

« first day (334 days earlier)      last day (3908 days later) »