« first day (857 days earlier)      last day (3143 days later) » 

12:00 AM
TTGTB ;-)
 
night!
 
RELOAD!
 
YAY INTERRUPT YAY
 
lol
 
There are 1501 unanswered questions (94.3898% answered)
 
12:00 AM
INTERRUPT! - abortedf.
 
^ fail
 
That was the most tense 4 minutes ever.
TTGEF
 
haha good one ^^
 
12:17 AM
Went well @Mat'sMug your trick of adding GO every thousand or so instructions did the job nicely
 
:)
WOOHOO I HAVE A UPS!! (power just went down, thunderstorm)
4
 
Man, I wish there would be a thunderstorm around here. :-(
 
first time it actually toggles
 
> Time is short.
Precision is vital.
To disarm these bombs, one must only cut
the topmost red wires.
Beautiful story, @ Codeless Code
Is rtype redundant or is it good to have here?
class ListOfFilesInDirectory(object):

    def __init__(self, directory, extension=".*"):
        """
        Get a list of file names from a directory.
            :param directory: Where to look for files
            :param extension: The desired file extension (optional)
            :return: list of file names as strings
            :rtype: object
        """
        self.directory = directory
        self.extension = extension
 
@Phrancis I'd say it's redundant.
Your constructor shouldn't be returning a value anyways.
@Phrancis Quick question, how many methods besides __init__ does that class contain?
lol
 
Wait, people actually read those? — Mat's Mug 40 secs ago
 
Maybe on codereview.stackexchange.com or security.stackexchange.com would be it better match the flavor of the community. — peterh 39 secs ago
 
@Duga meh
 
12:58 AM
@EthanBierlein There might be one later.
 
@EthanBierlein 2 others, one is for printing the args, and the other is the one that actually does the work
 
huh
hmm
 
So the actual return I guess should be only on the method that does return the thing that documentation says it does
 
yeah
I'm trying to decide if you need an entire class though.
 
A function would probably be enough, I did want to get some practice writing classes though so I wrote it that way
 
1:13 AM
Agreed, but the general style in Python is if there's two methods, __init__ and one other, then it should be a function.
If you want to print the arguments, you can add an extra debug=False to the end of your arguments and have an if statement that will print the arguments if debug is True.
 
A class is usually a type.
 
Exactly.
 
The key word is "type".
 
Oh that's a good idea
 
Also key is "object"
 
1:14 AM
You could even build a debug decorator function. Give me a sec.
 
If in the real world you can think of having an instances of the type/object, then it should be a class.
 
Okay @Phrancis:
class Debug:
    def __init__(self, debug=True):
        self.debug = True

    def __call__(self, function):
        def wrapper(*args, **kwargs):
            print(args)
            print(kwargs)
            return function(*args, **kwargs)
        return wrapper
And you can use it like this:
@Debug(debug=True)
def f(a, b):
    return a * b

print(f(10, 10))
 
Hmm I don't understand what *args and **kwargs are
 
*args means an arbitrary number of arguments.
And **kwargs means a variable number of named arguments, like {"f": 10}, or f=10
 
Hmm interesting
Let me try it, that certainly would be a handy decorator to have
 
1:24 AM
Are you using Python 3 or 2?
 
2.7
 
Okay, then you don't need the parentheses on print, and Debug should inherit from object, like this: class Debug(object):.
 
@Phrancis Can you use 3?
I would definitely recommend switching to 3 if possible.
 
that ^^
 
@Hosch250 Probably, the SDK that was most readily available for IntelliJ was 2.7, but I did install 3 on the computer
I'm not making anything really fancy though, 2.7 has been doing quite good so far. Mostly some little scripts to do work I don't want to do by hand
/usr/bin/python /Users/francisveilleux-gaboury/IdeaProjects/PythonSandbox/src/Debug.py
(10, 10)
{}
100

Process finished with exit code 0
@EthanBierlein ^ that's what the decorator returns, what's the second value {} mean?
 
1:29 AM
It's **kwargs
 
Oh, gotcha
Then I just need to from Debug import Debug to use it eh?
 
yup
I'd recommend naming your files starting with a lowercase character though.
 
You're a good man, thanks for showing me that :)
 
No problem. :-)
 
Either of you familiar with VB.NET documentation?
 
1:31 AM
@EthanBierlein Any particular reason?
 
I can't figure out how to add XML docs to a VB.NET enum.
C# you just use the /// type of comment...
 
@Phrancis Personally, I feel like it's more "Pythonic", but that's just my opinion.
@Hosch250 Try '''
 
@EthanBierlein Genius.
 
Does it work?
 
LOL, I clearly don't know VB.NET well at all.
 
1:32 AM
Ethan beat me to it
 
@EthanBierlein Yeah, it works.
 
''' TODO: Refactor all this VB to C#
4
 
@Phrancis Actually, I'm changing my C# to VB.
 
sputter
 
1:34 AM
@Phrancis No, that is not a good doc comment at all!
@EthanBierlein Yeah, I'm writing VB.NET analyzers/code fixes for VSDiagnostics.
 
@EthanBierlein does that wrapper return self?
 
No, it returns/calls the function you're decorating.
 
Ohhhh
What kind of Python sorcery is that?
 
I'm not sure it's sorcery.
In any language you can return a function call.
If the function doesn't have a return it just returns None.
 
One of these days, I'll understand more complicated things like that
 
1:43 AM
@Phrancis You will.
 
It just hasn't "clicked" yet
 
We'll pound it into you with a mallet ;)
 
@Phrancis Wait, do you not understand decorators?
It's actually pretty easy to explain without code.
 
Personally, I don't understand decorators, because I've never had to use them.
 
Well, it's pretty simple.
 
1:45 AM
I'm listening, @EthanBierlein.
 
No, not really I don't. I think the only decorator I've ever used is Java's @Override and even then I don't really understand what it does
 
Oh, those decorators.
 
Say I have multiple functions, and I all want them to be wrapped in a try-except block that prints a crash log if an exception is caught.
 
There is a WPF something called "decorator" too.
 
Rather than wrapping each function in a try-except block, with the crash log code, I can define a decorator which "wraps" the code of each function with a try-except block.
That's what a decorator is. It "decorates" the function's code.
 
1:49 AM
That sounds cool
Got any examples/articles off-hand?
 
Sure, I have one from my Cactus project which is exactly what I described above.
 
@EthanBierlein That actually is quite a simple concept!
 
Here we go:
from contextlib import redirect_stdout
from traceback import format_exc
from pprint import pformat
from sys import exit, maxsize
from os import path
from time import strftime
import platform

def _cactus_class_method_exception_handle(function):
    """
    This function provides a general wrapper for
    handling errors with the Cactus engine. Example
    usage:

        @_cactus_class_method_exception_handle
        def my_class_method(self, args):
            code
    """
    def wrapper(self, *args, **kwargs):
 
Cool. How would you use that?
 
Lol, it's in the docstring:
@_cactus_class_method_exception_handle
def my_class_method(self, args):
    ...
 
1:53 AM
in Cardshifter TCG, 8 hours ago, by skiwi
@Phrancis Haha... Developers... Read the manual...
 
This decorator is special, because it's designed to work with class methods.
Which is why the first argument of wrapper is self.
 
LOL.
 
Here's the PEP for decorators: python.org/dev/peps/pep-0318
 
@EthanBierlein Eh, I'm busy writing C#.
 
Hmm
I might try decorators in C#
 
1:57 AM
Does C# have decorators?
I've never heard of them.
 
I don't think so.
But there's probably some way to do them.
 
Hmm. That doesn't look liek Python decorators.
 
It doesn't.
I picked up a silver badge for question views on Programmers, and my question is Hot.
Can anyone explain what SCOTCH stands for in a programming reference?
Very interesting monologue going on in The Whiteboard: chat.stackexchange.com/rooms/21/the-whiteboard
 
@EthanBierlein Look at the big example towards the bottom
      // Create video
      Video video = new Video("Spielberg", "Jaws", 23, 92);
      video.Display();

      // Make video borrowable, then borrow and display
      Console.WriteLine("\nMaking video borrowable:");

      Borrowable borrowvideo = new Borrowable(video);
      borrowvideo.BorrowItem("Customer #1");
      borrowvideo.BorrowItem("Customer #2");
Borrowable is the decorator (towards the very bottom)
(not sure it works quite the same or not, but it looks like they're not foreign concepts between C# and Python)
 
2:09 AM
The pattern behind it is the decorator pattern, yes. There is no syntactic sugar for it in C# but you could homebrew something that uses attributes and code-generation to generate the "verbose" decorator pattern usage
 
Here is the C# expert!
 
@Phrancis You know that decorator code I gave you?
I missed one thing.
There should be an if statement in it, like this:
 
@Mat'sMug You too.
 
:p
 
2:17 AM
class Debug:
    def __init__(self, debug=True):
        self.debug = True

    def __call__(self, function):
        def wrapper(*args, **kwargs):
            if self.debug:
                print(args)
                print(kwargs)
            return function(*args, **kwargs)
        return wrapper
 
What I was really doing is predicting you coming in before hand ;)
 
pfffffft
eh, how's The 2nd Monitor doing tonight?
 
great
 
Absolutely snoring.
 
lol
 
2:19 AM
Depends. Can you tell me how to stop writing essays as answers?
 
@itsbruce I'm soooooo the wrong person to ask that to :D
 
@itsbruce I like reading essay answers.
 
Same here.
 
All the more since I have trouble writing them.
 
Speaking of answers...
Does anyone want to critique my answere here?
 
2:20 AM
@Hosch250 I have the opposite problem
 
Maybe you know more than me.
Want to upload your brain somewhere so I can download it and add to mine?
 
I probably just talk more
 
@EthanBierlein OK thanks for the update, I'll add that in :)
 
@itsbruce I'm very quite in person, but you should see the essays I write for class.
I just polished off an 8 page essay (APA style, double spaced, Times New Roman, 12 point) for class, not including the title and reference pages.
And that wasn't an assigned length either.
My forum discussions are often one full page in standard Word style.
 
It's possible I write long answers as a way of putting off doing any actual work
5
 
2:24 AM
in Code Review Moderator Election 2015, Jun 29 at 19:34, by Mat's Mug
is there a character limit to the nomination post?
in Code Review Moderator Election 2015, Jun 29 at 20:01, by Hosch250
Darn, I'm too long by 400-odd characters!
in Code Review Moderator Election 2015, Jun 29 at 20:02, by Mat's Mug
> too long by 1881 characters
:)
 
@Mat'sMug I had just started too.
 
Thanks santa!
 
Good thing you won and I didn't. I wouldn't make a very good mod.
 
Same with me too.
It was an interesting experience, running for moderator, though.
 
It was an interesting experience coming in last.
It won't happen again.
 
2:34 AM
3
Q: Binary tree implementation in Scala

user3453363This is my implementation of a binary tree in Scala. How can this be made better? abstract class BinaryTreeNode[+A] case class MyBinaryTreeNode[A](var data: A,var left: BinaryTreeNode[A],var right: BinaryTreeNode[A]) (implicit ordering: Ordering[A]) extends BinaryTreeNode[A] { override def...

Why the hell did I write nearly 3 pages of an answer to that? Could be shortened to "That isn't an implementation". And the OP would be more likely to read that.
 
> That's not a node, it's a tree
Shouldn't that be:
> That's not a tree, it's a node
 
Both versions are accurate
 
@EthanBierlein why did you self.debug = True in the init instead of self.debug = debug ?
Meh, mobile trying to type code == fail
 
For want of a backtick?
 
^^
 
2:43 AM
@Phrancis Whoops. Brainfart moment. That should be self.debug == debug.
 
Ok I figured that might overwrite whatever you passed to it to True so it would defeat the purpose of giving a default value
 
Yeah.
 
I have a problem where I tried "from Debug import Debug" from within a file in a child directory, said module was not found
 
Try doing from ChildDir.Debug import Debug
Make sure ChildDir has an empty __init__.py file in it.
 
> asked 6 days ago

viewed 37 times

active today
it's not your fault.
;-)
 
2:52 AM
0
Q: Opening all the links

Dhrubo NaskarI am looking to improve my code structure. In this code it is opening all the links with ?pid= in the url. However, the structure of the code can be improved. for a in self.soup.find_all(href=True): href = a['href'] if not href or len(href) <= 1: continue if href[...

 
So, sometimes I think people should read other answers before they post theirs.
Like this one
 
That's essentially a copy of your code, if I'm right.
 
Well, mostly. I have more parenthesis, and use std c99 constructs, but, yeah, the logic is essentially the same.
 
wow
 
I'm flagging as NAA
 
2:58 AM
@Ethan It's different enough that he might have thought it up independently
 
it's not NAA
 
@itsbruce Well, possibly.
 
While either not looking or having spent ages typing it and only seeing the other answer after hitting submit
 
It is suspiciously similar though.
 
My original assessment stands, people should read other answers first, that's all.
 
2:59 AM
He did also answer about two hours after you posted your answer.
 
Downvote it, if you find it is not good
 
His version is scrappy
 
Thing is, I am not really a C person, so I go back and look to see what other people find that's better than what i found, and I am surprised to see the same basic answer repeated. I did not downvote ;-) I think it's a good suggestion - the concept.... I would have suggested it myself, oh, I did.
Meh, I should shut up when I find these things.
 
"Oh, I pointlessly created j outside the for loop. OK, I'll reuse it equally pointlessly"
 
3:02 AM
@Malachi - my answer should have that same comment. I often give an answer without reviewing the code.
I just dump an alternative, and explain it's faster... without reviewing the OP's in more detail.
 
@rolfl what should have happened?
 
Ding... damn, some time the sound just turns on again.....
 
lol
 
Night
 
Night.
 
3:05 AM
'night!
 
Mat's nothing special, it's just a duplicate answer.
I answered, got upvotes, accepts. It's all good. The other answer is just saying the same thing in a different way, does not add much value, but does not really take any away, either.
 
why are you using a while loop?
 
because there is no need to introduce a further variable, and the increment and condition can be in different places.
All for loops are just syntax sugar for while loops anyway.
 
And C-style for loops are one of the most overused and badly used control structures ever
 
I sometimes feel that for-loops should be reserved for only the most simple conditionals.... If you ever have an 'empty' clause in the for-loop, or a double-expression clause, then you should have a while instead.
 
3:09 AM
@rolfl C-64 FOR loops are the only implemented loops ;-)
 
Otherwise there's just too much logic on a single line.....
declaration, initialization, conditional, and step - that's a lot of logic for a single line.
 
Frequent source of error
 
0
Q: Better rand() API

user83996I use this document as a basis for my mini-library: Motivation The std::rand friends are discouraged in C++14, so we want: A direct replacement to the std::rand friends. Despite of the security issues, std::rand is considered both handy and useful as a global uniform random num...

 
Agreed, common source of error - cramming too much in to a for loop....
 
yeah
 
3:11 AM
@200_success: Are you any good with memory allocation in C++? I need a little help.
 
Mat's, as an academic exercise, consider what it is about my answer which is OK, but why the other answer needs the post notice?
 
But so ingrained that may Java coders still use them despite 11 years of generics. Groovy didn't have them originally "just use each(), dammit!" but was forced to add them for the JSR
 
I like the enhanced for in Java, it's nice sugar.... but I am finding that streams is often nicer too.
I guess that makes Java more Groovy?
 
@rolfl I didn't add that notice. I'm still undecided about how to handle "dupe answers". I think downvote and go would be it.
 
3:14 AM
Streams makes it finally have some sensible combinator functions for collections. Might see some actual use in about 10 years
 
@Phrancis Remove the .Debug from the from selenium_scripts.Debug import Debug.
 
No difference :\
 
Meh, your directory structure is messed, and inconsistent with the code....
Move selenium_scripts.py to your src folder?
I forget how python handles local-files and imports.
 
anyone else noticed that?
 
@Jamal What's up?
 
3:18 AM
1
A: Shift positive integers in C

200_successYour function has undefined behaviour. You can see this clearly if you just examine the variable i. int i; … for (…) { if (values[i] < 0) … … } You're using i before it has been initialized. If your function doesn't crash, consider yourself lucky, and if it actually produces the inte...

@200_success nice catch here!
 
I haven't even finished reading the code.
 
@200_success I'm having to answer a question for a homework assignment. In our given example, an std::bad_alloc exception is being thrown. I've determined that it's not being thrown from new, but from a getter that dereferences a pointer member assigned to a local variable allocated with new.
(Yes, this is bad code, but that's not the point of the assignment.)
I'll paste it here as well.
class dynamicthingy
{
public:
	std::string *name;
	void setname(char *n)
	{
		std::string *newname = new std::string(n);
		if (name != NULL) delete name;
		name = newname;
	}
	std::string getname() { return *name; }
	dynamicthingy() { name = NULL; }
};
 
name is public — is anything else screwing around with its value?
 
@rolfl Good enough for me, that works :)
 
@200_success I'll provide the given test code as well.
dynamicthingy dt1, dt2;
dt1.setname("Ster");
dt2 = dt1;
std::cout << dt1.getname() << dt2.getname() << std::endl;
dt1.setname("Rick");
std::cout << dt1.getname() << dt2.getname() << std::endl;
 
3:26 AM
Oh, dt2=dt1 looks suspicious.
 
^^^
 
There's no destructor for dynamicthingy?
 
I've found out that removing the second setter stops the error.
There wasn't one provided (but we were asked to explain the severe problem with this code).
Which, yes, was the lack of destructor. But I can add it myself in case he expected us to do that before.
Nope, it doesn't solve it.
 
OK!
So, how many std::string objects ever get created?
 
It looks like three, including the data member.
 
3:31 AM
Sorry, let me rephrase.
How many std::string objects ever get created within the setname calls?
 
bad_alloc can be thrown from string = operator.....: cplusplus.com/reference/string/string/operator=
 
@rolfl Derp. I didn't bother to check the std::string documentation. I only checked it for new.
@200_success It looks like one per call.
 
It's uncetain as to why you would get a fail-to-malloc issue on the assignment, so my suggestion is just a different place to look, not necessarily an actual answer.
 
Based on that link, I suppose the dereferencing in the getter is attempting to do this, but is failing.
 
For the last dt2.getname() call, what do you expect should be the result?
 
3:35 AM
(I vote for Ster ....) ;-)
 
@200_success When I change the location of delete, I get an output without the exception, which appears to be Rick.
This probably has to do with the shallow copy being done.
However, overloading operator= didn't fix this, either.
 
@Phrancis Ah, that's your problem. You can't import scripts from a parent directory without using the __import__ function, which explicitly handles file paths.
 
Out of interest, why this:
		std::string *newname = new std::string(n);
		if (name != NULL) delete name;
		name = newname;
instead of:
		if (name != NULL) delete name;
		name = new std::string(n);
 
That's just what he gave us.
 
@EthanBierlein Shall I go read about __import__ function, then? My directory structure might not be pretty, but they're all just little scripts, maybe I can organize them a bit better when I learn how
 
3:40 AM
Also, how can you be sure that you can delete name.... it's not used elsewhere?
 
And yes, that's similar to the change I've made to fix the error.
 
@Phrancis Yes. I'd go look at __import__. Either that, or restructure your file setup.
 
OK
 
I guess that's what he's looking for.
 
What I know about C++ is about as dangerous as what I know about ..... psychology.
 
3:41 AM
If you (or anyone) has a bit of reading material on making good file setups/structures, I'd definitely put that on my to-do list
 
Basically, I think the issue is that if you're going to do things this way, then name needs to have a reference count.
 
Monkey's code does work. I'll answer based on this.
 
Ooh, 3 rep away from 200 on Gamedev.SE...
 
But that's just a trivial simplification — essentially the same code.
 
The only difference is the second copy-=-operator, @200_success
The first one takes a copy to newname, then another copy to name.
Aso, i am not sure what the * does in std::string *newname
TTGTB.
 
3:49 AM
0
Q: Implementing double check locking using boolean flag

LeronAs a C# developer I was proposed to use this pattern for locking: private bool checked; private object _lockingObject = new object(); if(!checked) { lock(_lockingObject); if(checked) {return something;} //Proceed with the operation that requires thread safety checked = true; } ...

 
@rolfl It constructs newname as a pointer to an std::string.
Goodnight!
 
Night
 
Night
 
Hey @Phrancis, I was thinking that I might expand a little on the Debug decorator, and put it up for review tomorrow. Does that sound good?
 
For sure man
 
3:57 AM
Cool
 
If you don't mind could you ping me when you do?
 
Will do.
 
It's super useful, I must say
 
Agreed
Anyways, I really need to be heading off to bed. I have to get up at 6AM tomorrow and it's already 11PM.
Goodnight all. Again.
 
OK later
 
4:01 AM
@rolfl name is a pointer. name = … just changes the pointer. It doesn't invoke the std::string copy operator.
 
Weird. The final question for this homework provides a little extra code with different tests, and the question states that the solution for the previous question shouldn't work with this new code. However, it does seem to work.
 
4:50 AM
0
Q: Takes in two sorted lists and outputs a sorted list that is their union

Rakesh Ranjan Sukla Write a function that takes in two sorted lists and outputs a sorted list that is their union def answer(list1, list2): len1 = len(list1) len2 = len(list2) final_list = [] j = 0 k = 0 for i in range(len1+len2): if k == len1: final_list.append...

0
Q: Multi-threading 4 Accelerometers - Data Unstable

AdamI just started learning C++ this year. Currently, I'm using four accelerometers to calculate human body movement for my school project. I tried to use multi-thread but the data outputs are unstable as such when I tried multiple times, some of the data would change. It does give correct output dat...

 
5:13 AM
Night, all.
 
 
1 hour later…
6:29 AM
Writer of this answer posted 3 answers on the same question. Can't imagine that's how it's supposed to work.
0
A: Calculating a pattern-match score on a ten-element array

ErikRHere is some more advice based on this part of your code: ... if howSim > 70: patFound = 1 plotPatAr.append(eachPattern) if patFound == 1: for eachPatt in plotPat...

 
@Mast Related:
20
Q: Should one person have multiple answers?

Jeremy HeilerThis question came up in regards to my comment on this post. If somebody has two different approaches for reviewing a piece of code, should they combine them into one answer, or have separate answers?

 
0
Q: C#: Application: Else statement issue

Dio KingNewbie here. I'm inquiring about a program I'm writing that is an application that brings up a series of option boxes. It's relatively simple. The only thing I can't figure out is why the else statement is not working, when the user chooses no to the question about unlimited access. I tried movin...

 
@MartinR Thanks. A bit old to be very helpful (the CR of 2 years ago isn't the CR of now), but at least it allows it.
Not a fan though.
 
@Mast I'll second that.
 
Zak
7:04 AM
Monking @all
 
7:44 AM
-1
Q: FizzBuzz is giving error msg: for number in range(1,n+1): TypeError: Can't convert 'int' object to str implicitly

Hamed Haddadianfrom future import print_function author = 'hamed' def fizzbuzz(n): result= [] for number in range(1,n+1): if (number % 3 ==0 and number % 5 ==0): result.append("fizzbuzz") elif number % 3 == 0: result.append("buzz") elif number % 5 == 0: result.appen...

 
7:55 AM
IMO, this question is more suited for codereview. — Tunaki 32 secs ago
 

« first day (857 days earlier)      last day (3143 days later) »