« first day (858 days earlier)      last day (2488 days later) » 

2:00 AM
Don't know. I haven't run it.
But something like T result = new T().
ew yuck what's going on there
Why don't you use Convert.ChangeType()?
@JeroenVannevel Does that actually work on generics?
2:01 AM
Maybe if you throw in 2 or 3 casts to object
            resultValue = (T)Convert.ChangeType(line, type);
            return true;
            return false;
Seems to be working.
I wonder how well it works on custom types.
I'm in bed with too few clothes to look too deep into it now, but I've always been able to resort to Convert.ChangeType() when needed
It depends on whether it implements IConvertible
Seems to be working for the basic types.
Because they all implement it
2:04 AM
Well, so far it works.
So I'm changing where T : struct to where T : IConvertible.
@JeroenVannevel You should add that as an answer for +1's.
Ugh. Fine. But I'm going for a one-liner then.
Almost done.
@JeroenVannevel LOL
Well that's actually a really good suggestion, so you have earned the +1 for it.
@JeroenVannevel MSDN link if you are too lazy.
Finally. It's done.
2:08 AM
Q: get a better node.js script

Tiago KotrykThis script is to unfollow-follow on twitter, how would you rewrite it in order to limit the quantaty of people to follow and specially to add a time wait between the follows? T.get('friends/ids', { screen_name: 'geekykaran', count: 2000 }, function(err, data, response) { var idList = da...

God, that took waaay too long.
@CaptainObvious get a better title
At least I contributed something good.
@Hosch250 I took your ternary suggestions and raise you one.
2:10 AM
A: Route some questions to [url-routing]

Ethan BierleinIt's done. I had a little bit of trouble coming up with titles for these questions, so if anyone wants to go through and try to fix some of the titles, that'd be nice. I did find one false positive that didn't require the tag url-routing though: Ultimate Tic Tac Toe A.K.A. Tic Tactics

                if (pass)

                Console.WriteLine("Invalid value [{0}]", line);

                string resultMessage = failureMessage ?? message;

                if (!requireValue)
                    resultMessage += $" [{defaultValue}]";

                Console.Write(resultMessage + ": ");
Be quiet @Duga. It's just me.
I've got to look into Convert.ChangeType.
I completely forgot about ?? until you mentioned ternaries, by the way @Hosch250. So thanks for that! :)
Unfortunately, this is the wrong place to ask. Once you get your code to work as intended, please come back with it and we can help you make it better. What does the API's documentation say about adding followers? — Mat's Mug ♦ 7 secs ago
2:14 AM
Woah, @JeroenVannevel @Mat'sMug I just learned something really odd about C# and type inference.
It cannot infer types from delegate types.
Wait, hold on.
I forgot about the optional parameters.
You can't omit optional parameters in the middle of a method.
@EBrown you know that any method that matches a delegate's signature and return type can be used with that delegate?
Unless you name them.
@Mat'sMug Yes, but that wasn't the point.
2:16 AM
@EBrown Duh, what do you expect?
        int numberOfCores = Environment.ProcessorCount - 1;
        numberOfCores = Prompt($"Enter the number of cores to use (1 to {Environment.ProcessorCount})",
                               $"The value must be between 1 and {Environment.ProcessorCount}",
                               delegate (int x) { return x >= 1 && x <= Environment.ProcessorCount; });
That would compile.
        int numberOfCores = Environment.ProcessorCount - 1;
        numberOfCores = Prompt($"Enter the number of cores to use (1 to {Environment.ProcessorCount})",
                               delegate (int x) { return x >= 1 && x <= Environment.ProcessorCount; });
That would not.
I forgot that you have to do:
you know, you just gave method overloading an official advantage over optional args
        int numberOfCores = Environment.ProcessorCount - 1;
        numberOfCores = Prompt($"Enter the number of cores to use (1 to {Environment.ProcessorCount})",
                               validationMethod: delegate (int x) { return x >= 1 && x <= Environment.ProcessorCount; });
@Mat'sMug Yes I did.
And if you did allow it, you know what would happen?
Suppose you had this method signature? void foo(int i = 0, string s = "", int j = 0)
@Hosch250 compiler problems with resolving method overloads
2:18 AM
Now you call foo(9), is that i, or j?
@Hosch250 Well it would always be i.
For simplicity, you could assume i, but some people would be sure to think it was j.
What if you call foo("", 9) though?
@EBrown "always" being "never"?
@Hosch250 j in that case.
If you were going to allow optional parameters you would likely have something to determine that in place.
2:19 AM
Yeah, but it would be extremely difficult to implement this.
And it would be sure to introduce bugs.
@Hosch250 Every feature introduces bugs.
That's an invalid argument.
Not like this.
Hell, ternary has inserted plenty of bugs.
I don't like that optional parameters don't have to be named in your foo(9) example
2:20 AM
@EBrown feature === bug
Permitting the lack of braces has inserted plenty of bugs.
All features have bugs associated with them. (That's just the nature of things.)
Using macro #define in C/C++ has bugs.
Some are more statistically likely to introduce bugs.
And that, in fact, is not present in C# for that reason.
And I meant users would use it incorrectly, introducing bugs.
Even though I much prefer a macro #define lerp(x, y, z) ... instead of public static float Lerp(float x, float y, float z) { ... }.
Because I know for a fact that #define lerp(x, y, z) would always be inlined.
2:22 AM
And until .NET 4.5, you could not expect that methods would be inlined.
What if you used it like string Lerp(string x, string y, string z)?
@Hosch250 That's a risk of having this feature.
I would rather have the feature for those of us that know how to use it properly than not have it for those that don't.
It is a good reason to not have this bug.
@Hosch250 Then by that logic it's a good reason not to have optional parameter bugs, or method overloading bugs.
2:24 AM
Method overloading?
Or ternary bugs.
There is only one possible method you can call with a set of parameters anyway.
 public static void DoSomething(int x) { }
 public static void DoSomething(double x) { }
That introduces at least one issue.
How do I know if DoSomething(0) will call the int or double variant? Oh, right, I have to assume that just because 0 is an int, it will always call the int variant.
2:25 AM
So, if I want to call the double variant, I have to use DoSomething(0f) or DoSomething(0.0).
double would be 0.0.
Which is a bug as well.
0f is nasty
@EBrown 0 is an int literal
2:26 AM
At any rate, that's merely pedantic.
And I argue that you shouldn't use magic values.
The point is, it's a bug in my case.
@JeroenVannevel what's wrong with 0f?
Just like your i/j issue is a bug in your case.
@Mat'sMug It will get widened to a double so it will fit in that DoSomething(double) overload
(nasty in this context)
2:27 AM
My point is, you can take any feature of a language and make it into a bug.
true of every language. bugs have no language barriers.
So just because implied optional parameters would be a bug in one case, does not mean we should just omit them altogether.
Just like my #define lerp(x, y, z) which is a bug for some values of the term.
Well, I don't want them.
@Mat'sMug Actually.. I tried talking to this mosquito last night and I don't think he understood me
2:28 AM
You can always make a feature request on Roslyn.
@Hosch250 Right, because they'll listen to some low-level like me.
The whole feature-request thing for Roslyn seems like a joke.
Honestly, I would love to see optional parameters able to determine which parameter fits them best by default.
I wouldn't want to.
Now, suppose I have this method signature: foo(int i, string s)
@EBrown that doesn't sound like a good idea. say it out loud. self-aware parameters that decide where they go.
And I call it like this: foo("", 0).
Why would you support that?
It amounts to the same thing.
If I have SomeMethod(int i = 0, string s = "", int j = 0) and I did SomeMethod(1), I would expect it to use SomeMethod(i: 1) (as it does now). If I did SomeMethod(1, 1)I would expect it to use SomeMethod(i: 1, j: 1) (which it won't do now). If I did SomeMethod("String", 1), I would expect it to use SomeMethod(s: "String", j: 1) (which it won't do now). If I did SomeMethod(1, "") I would expect it to do SomeMethod(i: 1, s: "") (which it does now).
@Hosch250 No, it doesn't.
You're being argumentative now.
2:32 AM
Yes it does.
If the Roslyn team were really to do something like this, there would be rules.
For the same reason there are rules for anything.
There would be rules for this too.
We don't know what those rules would be, but my suggestion would be to only fit types if they fit in order.
I.e. If you can resolve the first parameter to a type, and then resolve the next parameter to a type after the first type in the prototype, etc, then allow it.
So, your situation is invalid.
For example, foo(int i, string s, int j) called as foo(0, 0, "").
The first 0 would be i.
Because once the string type is resolved, the int type cannot be.
2:33 AM
Why not?
that would incur quite much overhead to every single method call out there it seems
In that example, the second 0 can be resolved to j, but the final parameter (your string of "") cannot be resolved past that.
@Mat'sMug It may, we don't necessarily know that.
It could easily be a compile-time replacement.
Yes it can, because none of these parameters are optional.
@EBrown right
And there is a string parameter in the method.
2:34 AM
@Hosch250 Whatever, I'm too tired for pedant's.
hey, why not post it as a suggestion
You're being argumentative for the sake of argument.
I'm being argumentative because I think this isn't a good idea.
@Mat'sMug I.e. SomeMethod(1, 1) could easily be replaced with SomeMethod(i: 1, j: 1) compile-time, and add no extra overhead.
The problem would be if the signature of the SomeMethod changes order.
If you really want it, you can always fork Roslyn, change it, and make a PR.
2:35 AM
That's when you would have issues.
It might not be accepted, but you could always start your own language.
VS doesn't have a reorder params refactoring?
@Mat'sMug It does.
@Mat'sMug It does, but consider the following scenario:
SomeMethod has the signature SomeMethod(int i = 0, string s = "", int j = 0) at compile time, so the call SomeMethod(1, 2) gets replaced with SomeMethod(i: 1, j: 2) at compile time. Now, later, SomeMethod is changed to SomeMethod(int j = 0, string s = "", int i = 0) but the original code is not refactored (different project/library/etc), so the original call (which should now be SomeMethod(j: 1, i: 2)) is still SomeMethod(i: 1, j: 2).
That's where we run into problems.
that's a PICNIC
2:39 AM
@Mat'sMug ?
Assume I'm tired.
Problem In Chair, Not In Computer.
I'll probably write this up as a potential feature-request for Roslyn now, just to see their comments.
but the original code is not refactored
@Mat'sMug Right, but that's a bug.
I think if C# allowed that, and it worked, it would not be a feature that promotes clear, obvious code.
2:41 AM
What the flip... man...
And since we're actually trying to point out the faults/benefits of this scenario, that's a bug.
My Regex works, but my calling it is borked :\
@Mat'sMug Maybe, but personally, it seems more logical than SomeMethod(1, j: 2).
To me, I would rather see SomeMethod(1, 2) than SomeMethod(1, j: 2).
@Phrancis Code?
I wouldn't.
2:42 AM
Just like, to me, I would rather see if (pass) break; than if (pass) { break; }.
@Hosch250 That's the great thing about a language feature, you don't have to use it!
I would see SomeMethod and go WT*? Is there a new overload?
@EBrown I'd have to see others using it!
If we ruled out features just because people don't like it, we'd never have any.
I, personally, hate ternary operators.
But, they are still there.
If you don't like auto-resolved optionals, don't use them!
with open("/Users/francisveilleux-gaboury/Downloads/output.txt", "w") as output:
    for file_name in file_names.list_of_files():
        # print file_name
        full_file_path = source_directory + file_name
        # print full_file_path
        with open(full_file_path, "r") as source_file:
            for line in source_file:
                # print line
                url_match = re.search(url_regex, line)
                if url_match \
                        and any(value in line for value in filter_include) \
See comments near end
If you don't like chocolate cake, then don't buy chocolate cake!
Same principle here, just a different scenario.
@EBrown I have a rule: if a single argument needs to be named, I name every argument in the method call
2:45 AM
@Phrancis Mkay, what are you trying to do specifically?
@Mat'sMug That doesn't mean everyone does.
So just because you do, should we mandate that across the board?
You guys seem to want to eliminate the potential for a very time-saving feature on the basis that you alone don't like it.
if I remove the .group(1) on the print I get <_sre.SRE_Match object at 0x102ef0b90>
OK, XY Problem I think :)
But trust me when I tell you, there are plenty of programmers out there which prefer if (pass) break; to if (pass) { break; }.
And I know none of you do.
@EBrown Time-saving? Tell that to the person who has to write it.
@Hosch250 I have to write it now.
2:46 AM
It will take you years.
@Phrancis So you're trying to obtain the matched string?
Especially if you had to update intellisense in VS and R#...
My X problem is, this is searching for a match (which it finds when applicable): url_match = re.search(url_regex, line)
@EBrown that's as many programmers that have yet to discover CR! ;o)
@EthanBierlein Bingo
2:47 AM
I have to write: numberOfCores = Prompt($"Enter the number of cores to use (1 to {Environment.ProcessorCount})", false, validationMethod: delegate (int x) { return x >= 1 && x <= Environment.ProcessorCount; }); instead of numberOfCores = Prompt($"Enter the number of cores to use (1 to {Environment.ProcessorCount})", false, delegate (int x) { return x >= 1 && x <= Environment.ProcessorCount; });
Which to me, is a waste of time.
Because there is only one possible resolution to that method.
How about vali + TAB?
If I remember correctly, it will return a list of all matches.
Then you can just check the length of the returned matches for a length greater than zero.
Is it possible to call the index of an element in the returned list of strings?
2:49 AM
print, assign or whatever... not call
(my bad)
Yeah, just get the value by index:
match_list[ ... ]
So match_list[0] I guess would get the first index value?
re.findall returns a list of strings, after all.
@Phrancis Yes.
Let me try that then
I'll let you guys know when I write up this Roslyn feature request.
Then you can officially put your opinions on the books.
2:56 AM
Well, I'm going to bed.
Let me know if it works @Phrancis.
So far, so good. I got one more issue though, this one hopefully simpler?
        for line in source_file:
            # print line
            url_match = re.search(url_regex, line)
            if url_match:
                url_list = re.findall(url_regex, line)
                url = url_list[0]
                if any(value in url for value in filter_include) \
                        and any(value not in url for value in filter_exclude):
                    print "// " + url
                print line
On the else: print line it always adds an extra \n after each line
(or seems to, anyways)
^^ wtf
It works but it's really weird
Q: OOP paradigm implementation of a Dictionary

overexchangeBelow is the implementation of interface Dictionary using chained hash table class HashTableChained. I used non static member class in class DblyLinkList but Joshua Bloch says in Effective Java - item 22 : Favour static member classes over non static /* DblyLinkList.java */ package JavaCollect...

Q: Access html elements using javascript functions

AikanároI'm looking for some pattern or best practice for the scenario when HTML elements changes its id. Let's say I have a function that fill some inputs from data returned from an ajax request. $.get("getPersonData" { id : $("#personid").val() }, function(data){ $("#name").val(data.name); $("#...

Man, I'm going to get lynched when I post this for review
3:17 AM
Q: How do I implement these Vector class Constructors?

Amantemplate class SimpleVector { public: // constructors SimpleVector(); SimpleVector( int newCapacity ); SimpleVector( int newCapacity, const DataType &fillValue ); SimpleVector( const SimpleVector &copiedVector ); // destructor ~SimpleVector( ); ////////////////////////////////...

@Mat'sMug @Hosch250 Either of you wish to preview this feature request for Roslyn?
Either way it won't get posted until tomorrow (when I have a fresh head and cup of coffee).
@200_success: About that C++ problem of mine yesterday: I was told that it was a shallow/deep copy issue. Monkey's solution was partially correct, but I did still need to overload the copy constructor and operator=.
3:42 AM
Depending on your intentions, you can solve it using a deep copy, or you can solve it by reference counting.
He's probably expecting us to go with a deep copy.
@EBrown Sure.
Q: Plug-in base architecture for extensible application

AjmeraInfoHow can start with plug-in based architecture? I know couple of tricks like below but still don't know where to start. MEF Delegates and events Reflection I would like to make like WordPress hook "do_action" is that possible with c#.net?

@Duga Why is that suspected as answer invalidation? The edit was not done by the OP, and no code blocks were touched.
3:57 AM
@200_success She currently complains about any answer edit with answers (I'm not sure about the answers).
@Simon That's way too sensitive. Can those warnings be directed into another chat room for now?
4:30 AM
Q: Get Wikimedia attributions for images

PhrancisWe are using images from Wikimedia commons for some of Cardshifter's game artwork. I selected some art for each card to make a .jpg file to use in the game clients, and added a URL to the original file as a comment for reference. This is what one card looks like: // https://en.wikipedia.org/wiki...

@EthanBierlein ^^"
5:00 AM
@Duga Think we're OK on this one
I picked up the silver view and vote badges on my Programmers question.
5:20 AM
Q: Print the length of words as a vertical histogram

cody.codesI thought I'd give it a shot. What I came up with is from a culmination of my last two submissions, incorporating most of the feedback from this community, including better naming of variables, initialization, and making my program a bit more user-friendly. I'm not sure which optimizations I can ...

Looks like magic
5:37 AM
6:24 AM
Yes, I am pretty sure that you can speed this up by at least one order of magnitude by writing it fully in numpy and avoiding unnecessary for loops. Since you already have working code, this could be a good candidate for Code Review. If you decide to post there please check the instructions on how to post at Code Review. — cel 5 secs ago
7:08 AM
Q: arrow anti pattern with crutch

user75534How to impore this code and avoid crutch? Maybe use case operator? public bool Crutch; public void Resize(SizeChangedEventArgs input) { if (input.NewSize.Width < 450 && Crutch) { if (!ServiceLocator.Current.GetInstance<MultiViewModel>().EightBoxesCommandIsEnabled...

Q: Codeigniter form flow for model and controller

ViralWorking with Codeigniter most of the time (about one and a half year now). I came across many form validation code flows, here are my best two selected shots which i created for a client recently. I only care about model and controller, views do not need to be reviewed. Features of both codes:...

7:27 AM
I'm voting to close this question as off-topic because it is a request for a code review. — Raedwald 28 secs ago
7:40 AM
Q: Convert roman to arabic

amkoroewI started to teach myself Haskell recently. Here is some code I wrote to convert a roman numeral into an arabic numeral: import Control.Arrow ((>>>)) import Data.Maybe (fromJust) fromRoman :: String -> Int fromRoman = translateFromRoman >>> applyNegationRule >>> sum translateFromRoman :: String -

8:00 AM
Monking @all
Monking @all
Monking @all
Monking @ all
8:16 AM
@BrianKH I guess you're right, next time I'll post questions like this at CodeReview. Thanks! — Anton Melnikov 5 secs ago
Q: JSLint: Unexpected assignment expression

LoveAndHappinessI get this warning: Unexpected assignment expression. return task.completed = true; // Line 63, Pos 39 When using this code: completeAll: function () { this.tasks = this.tasks.filter(function (task) { return task.completed = true; }); } Why? And how else could I write this ...

8:29 AM
8:50 AM
Monking all
Why did StackOverflow bot just post that question?
Also I think codereview.stackexchange.com is better for this. — FelisCatus 57 secs ago
@SuperBiasedMan Because it's tagged .
Ahh, I was looking in the comments and question post to try find that, not the tags.
@VimalanJayaGanesh Code Review is only for code that's working as the OP intended. They're asking how to fix something so it would be off topic for CR — SuperBiasedMan 1 min ago
9:16 AM
@Duga Nice work!
In my opinion, roll back!
If anyone thinks the same, please do it.
It's not invalidating any code, I would just comment that follow-up questions are better.
9:32 AM
@IsmaelMiguel I rolled it back. Also it isn't invalidating answers its is hard to decide which version should now be reviewed.
Well, I didn't said it invalidated anything
That part had been for @Morwenn ;-)
hey @skiwi
9:34 AM
Q: Java Static Code Analyser Which fix basic issues

Ragustatic code analyzer which can fix some basic level of violation in PMD automatically.(like naming convention issues and equals issues)

false positive @Duga
@Duga @SimonForsberg Duga is picking up Rollbacks.
Are rollbacks programmatically distinct? They appear as regular edits.
The title is fixed
It's always with the format "Rollback to Revision \d+"
9:47 AM
@200_success have patience, I see the problems.
@IsmaelMiguel that can easily be fixed.
Looking forward for the fix
@Phrancis If you don't understand the print str, syntax I can explain it. I wasn't sure if you understood what was going on there or not.
10:07 AM
This is rather interesting...
We Dutch people say "Gefeliciteerd" on someone's birthday, it literally translates to "Congratulations"... Appereantly foreigners think it's strange
It's like congratulating someone for surviving another year ;)
I don't find it strange at all
I find weird, in general, celebrating birthdays
Q: Javascript / jquery indentation

topleftI'm new to js and actually trying to write a perfectly clean source code. I'm using gulp to concatenate and minify my files, as well as removing comments. So the end result will always be the same in production environment : a single line without spaces. But for dev environment, I'm trying to a...

@CaptainObvious I don't think the O.P. wants a code review but a whitespace-usage-review
@IsmaelMiguel sounds like a Code Review to me
10:21 AM
I'm answering that then, with a review to the whole code
Hooray for consistently formatted data
Q: Number of contracts for persons and performance

MegaTronCould you please suggest me how can I improve this script: select CAN.PersoonName , ISNULL(CON.ContractCount, 0), from Candidate CAN left join (select PersoonID, COUNT(*) ContractCount from Contract group by PersoonID) CON on CAN.PersoonID = CON...

How's your Excel crasher going?
It doesn't crash anymore :)
sounds like a good start..
10:28 AM
IT's about 50 times faster, and went from 70% accuracy to 100%
heya @Zak can I ask you some strange questions about VBA equality??
@Vogel612 go ahead
drop by in the Rubberducking room, it's for the duck anyways
Is this real SQL syntax:
select ISNULL(CON.ContractCount, 0)
, CAN.PersoonName
, ...
10:32 AM
The ... isn't
the ... looks suspicious, otherwise it's fine
That's a placeholder for unwritten values
Yeah that's what I was wondering about, doesn't that mean it's incomplete code?
Maybe. best to ask for clarification from the OP first
CAN.PersoonID = CON .PersoonID <-- persoon?
10:36 AM
@IsmaelMiguel Found the Dutch programmer!
It means "person"
One of the things that ticks me the most is code written in other languages
I mean
Javascript in french, Java in Portuguese (I've seen this before) and those mixes
Yeah but it must suck having to conform to English just cause. I hate having to write color all the time and that's only a tiny thing.
this seems like a reaosnable question?
Same old A-B review
Yeah the close vote on it was because of not including code, but they include a bunch.
10:42 AM
But this time it is like A-B-A'-B'-C-F-A
The question needs some clarification
I think it might have been because in an earlier revision they said they'd soon link to more external code, but that's now been replaced with the promised link.
Guys I finallly finished my 8 queens solver in Haskell
50 lines of pure mind-bending-ness
34 non-blank lines
14 lines of type declarations
20 lines of night hard logic
Just 50 lines, at least you have something to brag about ;)
10:49 AM
@skiwi 34 non-blank ;P
5 seconds for one solution to 8 board. 1 minute for one solution to 9 board
@Caridorc that doesn't sound very effective
@SimonForsberg but it is what I get for applying dumb bruteforce
Q: Minesweeper analyze goes to N-Queensland

Simon ForsbergAs @rolfl recently solved the N-Queens problem, I figured that it was time also for me to solve it. My approach is significantly different from @rolfl's. I quickly realized that the N-Queens problem is just another Constraint Satisfaction Problem (CSP). Earlier, I have written a whole bunch of c...

> My code is significantly slower than @rolfl's (size 11 takes 3.5 seconds for me, while it takes 9 ms for @rolfl)
9 ms to solve n-queens size 11 is just... nuts... bananas...

« first day (858 days earlier)      last day (2488 days later) »