« first day (3592 days earlier)      last day (1357 days later) » 

12:34 AM
hey i was wondering if someone could tell me how to install the watchdogs pip for python im using visual studio code was wondering if that made any difference
 
 
3 hours later…
3:51 AM
How libpcap filters works? any useful link? I think libpcap use PF_PACKET socket and bind to specific interface(like p=pcap.pcap(name="eth0")),when call p.setfilter("udp"),what will happen ? it reads the frame and filter protocol 17(udp) at ip level ? or make another sockets(not PF_PACKET) and bind on port 17 and read data(I know port 17 is ip level not ethernet level)?
 
 
4 hours later…
7:26 AM
@Janith libpcap is pretty low-level, and I really doubt many people here have used it - it's somewhat in my domain and even I have touched it only to help a colleague. If you have exhausted the public documentation, you may want to look at the source code or ask somewhere dedicated to networking.
 
7:41 AM
oh ok
 
 
1 hour later…
 
1 hour later…
10:20 AM
@Tg1tim where lies your difficulty exactly?
Either you forgot to add key info (something doesn't work when it should) or again you forgot to do your research first
 
10:36 AM
cbg
need help resolving django error, anyone familiar with Django?
i have been stuck over it the whole night :(
 
Please just ask your question and people will help if/when they are able
 
10:55 AM
@CodyGray did you delete my comment on the question that you just hammered? Genuine question; did I cross a line there by trying to encourage them to try code or was it just superfluous? The OP is still asking me how to implement round()
 
@roganjosh Yes. It was flagged by the OP with a custom flag, and I really just didn't think it was serving any useful purpose.
I don't really think you crossed any lines. I just didn't think it was going to help.
 
Fair enough. Nice to know that they flagged me
 
Well, not as being rude.
I don't know what to say there. Even I could figure out how to modify that Python code to round a floating-point value for display.
 
That was the point I was trying to convey; at least try something but it's a tough line to tread to be relatively forceful in the suggestion but not be rude :/
And I certainly don't want to just do it for them because they'll never progress. I'm just ignoring it
 
Yeah. It wasn't rude. It was just obvious that it wasn't providing them the motivation that they needed, so no point in letting it stick around.
 
12:00 PM
@roganjosh In case you care, that question turned into a big thing. It turns out the person is actually using some library function, rather than print. They've updated the question, and I've now re-opened it, since it evidently isn't a duplicate.
I don't know what library this is, but clearly they are going to have to figure out how to pass formatting flags/options to that library's display function, because rounding an intermediate floating-point value and passing it instead isn't going to work.
 
Oh my. I'll get up to speed
 
Heh
And you thought moderating was one-and-done...
 
The way they've carried on about this, I'm just leaving it be. I really don't envy you guys and I feel a bit bad for having a hand in it, only for your sake
Next stop: angry column in the Express (or equivalent newspaper in other countries)
 
12:17 PM
They're a satisfied customer now. It was reopened.
So hopefully the headline in the Express will be positive.
 
:)
Nicely handled and <3 "one an expert in Python and the other (myself) a site moderator." That's my standout headline :P
 
I just assumed, because your name's italic in here.
And Andras doesn't kick you.
 
@CodyGray matplotlib, change is trivial
 
@CodyGray don't tempt him
 
if it "doesn't work" it's because OP is wrong
 
12:24 PM
I don't know how you can tell that's matplotlib.
You are a true expert.
 
OP's edited code is a syntax error
 
plt
 
@CodyGray that's how
@roganjosh sssh :P
 
Excuse me, I'm the expert
 
Yeah, right, like there aren't a hundred things that could be named plt.
 
12:25 PM
Sure, if you want to break the sacred pact
 
voted no MCVE
I might get smitten any moment now
Argh, I should have voted duplicate :(
one more regret in life...
 
Wasn't there some reddit thread of angry people? I wonder which of us features most
 
@roganjosh alas, no. Kevin was pulling my leg :'(
although /r/stackoverflow probably works anyway
 
You don't have to go offsite to find threads of angry people.
Vote to close as duplicate of what it was already closed as? :-)
 
OP is missing at least one parentheses from somewhere, and round(r, p, 2) will never work unless they shadowed round, and "%.2f" % more_than_one_value will never work
@CodyGray yes...
edited now...
Your new edit is correct, but it doesn't contain anything about rounding that the suggested duplicate told you to do. This is still a duplicate. — Andras Deak 7 secs ago
OK, not holding back on my downvote anymore
OP needs to *gasp* round both values independently
 
12:31 PM
Two roundings?!
 
or use two format specifiers; that would actually work better for their use case
 
Twice the fun!
At least you've got that little bit of C in your life.
 
It would be parallelizable if it weren't for the GIL. I think we should get angry about that too
 
which is, ha, exactly what stackoverflow.com/questions/455612/… does
one can also add stackoverflow.com/questions/6149006/… as a target
If I still cared about SO I'd be obliged to approach the duplicate target with a chainsaw...
plt.text(3, 760,('CORRELATION(r,p)='("%.2f" % round),r, p), fontsize=12))
oh come on
don't tell meta, but that's not even wrong
 
1:09 PM
It's gone now
 
And so endeth the epic tale (maybe; there's still the Meta post that's been rolled back) and possibly The Scouring of the Shire. Because reasons.
 
If the "Scouring of the Shire" means complaining on Twitter then yeah that will probably happen
 
Oh well. My focus has now shifted to why lat/long isn't the de facto way of listing coordinates and some libraries require long/lat
 
> You should only try to run syntactically valid python.
Can we get this framed, @AndrasDeak?
 
@roganjosh silly math people with their x/y grids.
Unless it's a library for navigate then it's just wrong to have long first
 
1:20 PM
The real wrong-ness is that it matters...
The interface should be sufficiently strongly typed that it doesn't care which one is first.
 
Seems everyone is having a fun Sunday? :p
 
You mean that it can distinguish between 2 floats that both exist within valid ranges?
I'm also sorry to poop on this parade but the library is OSRM, written in C++ :P
 
C++ isn't perfect (feel free to quote me)
 
Sweet. Hopefully there a 2-for-1 on at the framing store :)
@JonClements been kinda dull. Just plodding along, y'know
 
Huh? I mean I use a Builder with lat/long stuff so it's extra clear at construction
 
1:24 PM
@LinkBerest Bob can do it - yes he can :p
 
@LinkBerest My reply was to Cody, sorry :)
 
@roganjosh so no keyword args?
 
Mine too :)
 
@AndrasDeak why would you need them? The order being reversed is obvious
 
I see :P
@CodyGray subject to fair use, otherwise 10% royalty.
 
1:30 PM
All my usage will be fair, I assure you.
 
@AndrasDeak poor negotiation. The royalty should be the baseline, then add the premium
 
What can I say, I have a soft spot for Cody. Charity for those affflicted with C++.
 
We would contain the afflicted but the lat/long --> long/lat mixup means that we can't effectively trace them
 
@AndrasDeak Should probably save the charity stuff for PHP sufferers...
 
@AndrasDeak not really in C++ (or Java unless you do some really hacky things with annotations). You typically have a builder like MapClass::create().withLat(10.1).withLong(12.1)
 
1:38 PM
ew
 
Java looks nearly the same
 
Named args are implemented using this crazy thing called a struct...
 
And I love Python's kwarg because of this
@CodyGray which whoever made rogan's code didn't use so that's the only other way I know of
 
@CodyGray must be new in C++22
 
But then my knowledge of C++ is very rusty
So I can easily be wrong :)
 
1:44 PM
@LinkBerest unintentional pun?
 
@LinkBerest it's a query string to their API and (to my knowledge) it doesn't take named parameters
(In reality I was only trying to score a point against C++ :P)
 
@CodyGray lol
 
.... coordinates only? Whelp, that's a fun design
 
Though I will concede that it's the most astonishing library of any I have come across. It took me hours of cross-referencing to convince myself that it actually did generate a 1000x1000 matrix of real-road distances in the time it did
To say it's fast is a dramatic understatement
 
1:50 PM
A string?
Wow, yeah. Not an ideal API design.
Imagine the inefficiency! Formatting, then parsing a string! So wasteful!
 
@CodyGray okay I was wrong they use a struct ;D
@roganjosh hmm....when I dealt in fresh produce tracking - this would have been highly useful so I see the appeal
 
I originally used graphhopper, and OSRM had some big debate about whether their matrix API should give distance and time, so you used to have to download a different branch. In the end it looks like they conceded and merged it all together
Contraction Hierarchies FTW :)
 
2:08 PM
well, using wormholes - time and distance don't really matter or something... so you probably should have stuck with that :p
 
That only works if you have a TARDIS
 
Got one on a key ring if that counts? :p
 
I think that contracting a wormhole is one of the Millennium Prizes. Probably.
 
@LinkBerest Oh no, my friend. There's a lot more fun to be had with heuristics :P
 
2:18 PM
@JonClements Its bigger on the inside :p
 
When I was originally working with Jsprit, we had drivers delivering their own lunch break. Only, that meant that the algorithm deployed every driver because they all had their own lunch break to deliver, so I just threw the warehouse into another dimension and made excess drivers deliver there since it was prohibitively expensive to deliver it anywhere else. A fun 2 weeks of sleepless nights
 
@python_learner that's the joke :)
 
3:05 PM
I have programmed many things but, to this day, the only thing that has impressed my kids was the quick Minecraft mod to add TARDIS skins and a teleport pad which made it "bigger on the inside"
 
3:30 PM
Hi. How can I define a Generic class that can only get a certian class and its subclasses as the input?
class A:
    pass


class B(A):
    pass


T = TypeVar("T")


class Generify(Generic[T]):  # T should be an instance of a subclass of A
    def do_something(self) -> T:
        return T()
 
yo @AndrasDeak I have a smaller list now, transformed into a np.array, with proper rectangular shape, and it's even slower? lol
 
How are you planning to use this Generify class? Where does the value for T come from?
 
^ same questions also: is this something that bound (maybe with a Union) will not work on?
 
3:50 PM
@PedroSpinola sorry to hear that
 
@Aran-Fey I'm planning to create instances of Generify for each subclass of A in the example. In do_something I will call a method of class A.
 
How? Can you show us some code?
 
@FarhoodET you need to constrain T, e.g. T = TypeVar("T", bound=A)
I know that question descriptions must be English, but does SO have any rule against code in foreign languages?
 
4:09 PM
Don't think so
 
No rule it needs to be in English but it's advised it should be as it'll help more people comprehend it - with the caveat things are named sensible of course :p
ugh... knew today was going to be yam when I got up early to get something running and the computer kept crashing... arhghghghghghgghghghhg :(
 
Have you tried wiggling the rear view mirror?
 
<throws sausage roll>
 
@MisterMiyagi oh - I forgot that magically fixes all sorts of problems... even repairs cars that have been driven over a 500m cliff... :p
 
It might appease the Machine Spirits.
 
4:29 PM
Maybe I'll go for closing the code editor and bash prompts and do something else...
@roganjosh have messaged you btw - up for a game of something?
 
5:11 PM
cbg, if I have a number of text fields in a webpage is there any way flask can read only the changed fields when the form is submitted?
 
No. But flask can easily detect which fields have changed since it sent the form. If you want to reduce what gets sent to flask to those fields that the user has changed you'll find you need to resort to fancy client-side (browser) programming, I should think.
 
what is the function or method I have to use to detect? I will google on that
 
What do you want to detect? Sounds like a JS problem to me
 
5:26 PM
the other thing to consider @python_learner is what do you get from doing this as opposed to not worrying if anything has changed or not?
 
so I have a flask generated page where the text fields are dynamically generated for each row in my db, so if the user edits a text field and clicks on submit I want all the changed fields to be updated in my db
so I want to be able to detect where the values are changed so I can do my db operations on submit, perhaps there is a better way?
 
It's ugly stuff
 
:/ , so you understand what I want to achieve? is there a better way?
 
Years of flask and this is my biggest foe. I don't know a clean way to do that
 
unless there's some reason I'm missing... just updating everything from the form won't make a difference if anything has changed or not?
 
5:30 PM
Well, you might be able to add a callback when a value is changed
 
I was under the assumption that doing one update query (if one row is changed) would be faster than updating all irrespective of the edit
 
...or hold onto the data sent in the response to the GET and compare it to what is received in the PUT? Loop over a dictionary or list (whatever format you get the data), and then do whatever you want to with the keys/items that don't compare equal?
 
@python_learner so you're displaying multiple rows on the front-end? I'm struggling to picture what you're doing here...
 
Just how much data are we talking about here? Dozens of fields? Hundreds? Thousands?
 
Can you just give an MCVE please? I suspect we're all imagining slightly different things
 
5:33 PM
how do you do flask mcve for databases?
 
oh... are you thinking that updating one column in a row is faster than updating 2 columns in a row?
 
yes
@MisterMiyagi 100 rows is the highest it will reach
 
@python_learner that's your problem to figure out :P
 
maybe by fractions of a nanosecond... don't worry about it - just update the entire row... keeps the code simple
 
ok, is there any related SO questions, I just cant get the right keywords
 
5:36 PM
Not that I'm aware of
 
have you got the form displaying data and working when you submit data and you're just trying to optimise?
 
I have the form displayed, I just wanted to get only the required data on submit, so yes
 
okay - so don't worry about that - just submit it... job done
 
also maybe not needed in my case but do you thread in flask pages like you do for GUI's?
I am pretty sure I dont need this for my app, just curious
 
Well, what server are you using to run your app?
 
5:39 PM
now its the flask one, but we are asked to use nginx for the final demo
 
Flask doesn't have a server
 
flask run ?
it says its a dev server
 
It comes from werkzeug
re: threads, I answered that
 
ohh, silly me, I have used werkzeug.security didnt know it also had the server realted stuff
 
I wonder where werkzeug.security came from :P
 
5:44 PM
@roganjosh impressive answering a flask question before davidism jumped on it :p
 
that answer has a lot, I will have to take my time
 
6:03 PM
Not only that but all the links are off in terms of the lines they refer to. What a ball-and-chain
 
Let's say, hypothetically speaking, you would want to do pattern matching by abusing function signatures+annotations to specify a pattern. Would you expect ignored parts to be throwaway parameters (_, __, etc.) or suppressed parts of other parameters?
# ignored parameter
@magic
def decimal(integral: DIGITS, _: Literal('.'), fractional: DIGITS = 0): ...

# suppressed part
@magic
def decimal(integral: DIGITS, fractional: Suppress('.') + DIGITS = 0): ...
 
It's a bit of a weird question, because it's only natural that the former will work. It's not a feature that you have to implement or anything. Nothing prevents anyone from creating throwaway parameters. So the question is really whether anyone would expect the 2nd version to work, and I think the answer is no, because it seems kind of pointless
 
6:20 PM
How would these be called?
 
@MisterMiyagi careful... you may end up summoning Paul :p
 
6:41 PM
@AndrasDeak Similar to multiple dispatch, as part of a combination of patterns. E.g. numbers = decimal | fractional | scientific then numbers("12.3") would match and invoke decimal(integral="12", fractional="3").
Though there is a hypothetical subthread in a hypothetical person pondering whether this could be adequate for types (not just strings) as well. In which case Aran's comment seems more applicable than the suspiciously-pyparsing-inspired case.
@JonClements Do I get-out-of-jail-free by claiming Paul started the entire thing with publishing a fun-to-use parsing library?
 
Nope - you have to roll a double :)
 
7:43 PM
@MisterMiyagi I see...
 
@MisterMiyagi one of my well received answers was about Spanish language issues with a library so I don't think its a problem (note I also pointed towards Spanish SO as a "just in case you didn't know" way)
 
 
2 hours later…
9:35 PM
@MisterMiyagi Nicest thing anyone has said to me all day
So you are thinking about parsing patterns as method parameter types? Hmmm....
 
9:48 PM
Kind of a way to define an expression and attach a parse action at the same time.
 
10:04 PM
Something like this?
integer = pp.Word(pp.nums)

# decimal = integer + pp.Suppress(".") + integer

def as_pp_expr(fn):
    argspec = inspect.signature(fn)
    ret = pp.And(expr.default(name) for name, expr in argspec.parameters.items())
    ret.addParseAction(lambda t: fn(**t.asDict()))
    return ret

@as_pp_expr
def decimal(integral=integer, _=pp.Suppress("."), fractional=integer):
    return "<{}.{}>".format(integral, fractional)

print(decimal.parseString("12.3"))
And it prints ['<12.3>']
That's pretty crazy
One thing I got lucky with was that Python would take whatever the decorator returns and assign it to the name of the decorated method. I'd hoped that would work, but wasn't sure until I actually ran it.
 
Oof, took me like 5 minutes to figure out what expr.default(name) is doing there... I was convinced that was a mistake
 
I should probably use the long form here, for explicitness sake. expr.default.setResultsName(name) would be better.
 
10:39 PM
guys I'm running a specific function with complex maths involving np.log and exp(), millions of times in my algorithm. If I use a np.array for the data inputs to this function instead of dictionary references, should it go faster in all cases? or is there an exception?
 
Nov 19 '18 at 11:57, by Andras Deak
OP thinks that numpy is magic pixie dust. If they were using numpy anyway it would be evident from the code and tags. If they get a numpy answer they'll import numpy for this single step which will cost them 10x the runtime
Using a 3-element numpy array might not be faster than a 3-element list. Using a 10000-element numpy array will be faster than looping over a 10000-element list.
but passing a 100-element numpy array and a 100-element list to a numpy math function will probably not make a difference
 
I see! when you say list, is it interchangeable with dictionary references, in this particular case?
cause the maximum total of elements (int) I have in a given time in this particular np.array is around 150, so small
 
If the "dictionary reference" points to a list then yes, I mean that
you never quite give enough info to reconstruct your data structures so I can only keep saying general things
 
remember when I showed you my constraint function? data points (float/int) were referenced using a dictionary entry like d['a']['b'], etc
I don't know the right words, so I apologize
my data structure is all dictionary, only functions no classes, and I'm optimizing the solver function by transfering data from dictionary to np.array
that's all
 
Hello all
 
10:53 PM
hi there
 
11:18 PM
@PedroSpinola turning nested dict lookups to numpy arrays won't automatically make your code faster. What I told you was that you could perhaps achieve some speedup with numexpr if your arrays are large enough, but for that you'd have to switch to proper arrays, or at least dereference those nested dict items before computing your expression with numexpr (this could just mean a few more lines in your code, inside your solver, rather than a major refactor of your codebase).
But now you told me that your arrays have size ~150 which means that numexpr will probably not give you anything
 
11:36 PM
Yeah I understand
I'm under the impression refering directly to the dictionary might even be slightly faster, because I don't need to translate that dict to a single list (which takes a function), but I might be wrong
I'll now try to implement that stuff we talked about the other day so that make differential evolution can take workers = -1 and not return an error. I hope this adds some speed :D
 
It will, it will be roughly n times faster on n cores
 
awesome, can't wait for it :D
thanks for all the help mate ^^
 
anyone good with C++ and Python (ctypes stuff)?
 
11:53 PM
@Abbecuby if this is about your fresh question on the main site: we ask not to ask for help here with fresh questions on the main site
 
ok
 

« first day (3592 days earlier)      last day (1357 days later) »