Live data from Hacker News

5 Years of Bad Ideas -- Python tips, tricks, and chicanery

scribd.com

21–30 of 45 posts

Re: 5 Years of Bad Ideas -- Python tips, tricks, and chicanery

#21

Hey Scribd and or Google Chrome team. I was just tricked into clicking an ad that simply said "play now" underneath the first slide. I thought it was going to start a slide show of the presentation. Scribd, if you are going to let just anybody advertise on your site you need to clearly mark what is an ad and what isn't. Google team, clicking the add opened a tab that when attempting to close opened a custom dialog wi…

What? You killed Chrome because of what? What is a custom dialog? How is a "custom dialog" going to create a vulnerability?

There is a long history of such dialogs being used to exploit browsers and cause the execution of arbitrary code. For instance, such a dialog may be used to generate a true user click event, which the browser may then treat differently than an event that can be faked by Javascript. This entices malware developers to create dialogs in which you'll click on something, they don't really care what, they just need an authentic click.

Yes, it shouldn't do anything, but that doesn't mean it won't. I've hard-killed my browser for the same reason a couple of times.

Re: 5 Years of Bad Ideas -- Python tips, tricks, and chicanery

#23
Sometimes magic is necessary but these slides right here contain some serious voodoo.

That said I've used monkey patching before which can be quite useful when you don't want to change the underlying library too much but don't want to make a complete fork. Specifically I've monkey patched methods onto the User model in Django.

Re: 5 Years of Bad Ideas -- Python tips, tricks, and chicanery

#24

Here's a shell function. Pipe the scribd html page into it and, voila!, out pops .jpg urls for each page of the PDF document. Feed them to curl or whatever you program you use. Open them with your browser or your image viewer. Pipe them to ghostscript, remake the PDF to your own specs. Whatever. But for the love of God, stay away from scribd.com That site is an annoyance and I doubt it will ever improve. scrib(){ sed…

suggestion: you could make that more useful by dumping it into a gist and including a comment block on how to set it up in an rc file

Re: 5 Years of Bad Ideas -- Python tips, tricks, and chicanery

#25

Earlier quoted context omitted.

Your link just goes to the first page. Is this presumably the code you're referencing? import gc, sys def find_names(obj): frame = sys._getframe(1) while frame is not None: frame.f_locals frame = frame.f_back result = set() for referrer in gc.get_referrers(obj): if isinstance(referrer, dict): for k, v in referrer.iteritems(): if v is obj: result.add(k) return tuple(result)

yup, thanks for the heads up, it worked for me. I realized that most of that was unnecessary, this is what I was talking about: import gc, sys def show(*args): for obj in args: frame = sys._getframe(1) for k,v in frame.f_locals.iteritems(): if v is obj: print "%s=%r" % (k,v) a, b, c, d, e, = False, 1, [1,2,3], {'x':2 }, map show(a, b, c, d, e) outputs: a=False b=1 c=[1, 2, 3] d={'x': 2} e= [ http://codepad.org/4JogU0…

Not so useful when you have shared pool.

    a = 10
    b = 10
    show(a)
Or

    a = 'test'
    b = 'test'
    show(a)

Re: 5 Years of Bad Ideas -- Python tips, tricks, and chicanery

#26
post #5

Wow. I'm a numpy aficionado and connoisseur.. I'm sad to say I really don't understand most of whats going on in this code...

> I'm sad to say I really don't understand most of whats going on in this code..

Don't be:) Most of the dark voodoo there is not used(macros, implicit self), some of it is used only by toolmakers(finding request, changing traceback messages, import hooks), and then a small part is used here and there by regular applications(monkey patching; "names of variables" sounds useful but it won't work with shared pool. `a = 10; b = 10; show_names(a)` will show both "a" and "b")

Re: 5 Years of Bad Ideas -- Python tips, tricks, and chicanery

#27
post #23

Sometimes magic is necessary but these slides right here contain some serious voodoo. That said I've used monkey patching before which can be quite useful when you don't want to change the underlying library too much but don't want to make a complete fork. Specifically I've monkey patched methods onto the User model in Django.

What is meant by Python magic? What is and isn't magic? Why would you want to use it and why might it be considered a bad idea?

Re: 5 Years of Bad Ideas -- Python tips, tricks, and chicanery

#28
post #23

Sometimes magic is necessary but these slides right here contain some serious voodoo. That said I've used monkey patching before which can be quite useful when you don't want to change the underlying library too much but don't want to make a complete fork. Specifically I've monkey patched methods onto the User model in Django.

What is meant by Python magic? What is and isn't magic? Why would you want to use it and why might it be considered a bad idea?

My definition of magic:

Magic is anything which makes other code behave in a way that would require reading the magic to understand, despite not being apparent in the magicked code.

Good because it makes many things a lot easier, bad because it makes code a lot less explicit and simple and increases cognitive load (you need to always consider the magic not just the current code you're looking at).

Re: 5 Years of Bad Ideas -- Python tips, tricks, and chicanery

#29
post #26
post #5

Wow. I'm a numpy aficionado and connoisseur.. I'm sad to say I really don't understand most of whats going on in this code...

> I'm sad to say I really don't understand most of whats going on in this code.. Don't be:) Most of the dark voodoo there is not used(macros, implicit self), some of it is used only by toolmakers(finding request, changing traceback messages, import hooks), and then a small part is used here and there by regular applications(monkey patching; "names of variables" sounds useful but it won't work with shared pool. `a = 1…

> but it won't work with shared pool. `a = 10; b = 10; show_names(a)` will show both "a" and "b")

That will actually show nothing because strings are not tracked by the cyclic garbage collector because they can never be part of cycles.

Re: 5 Years of Bad Ideas -- Python tips, tricks, and chicanery

#30

Oh man, there is so much black magic in those slides. I hope to high heaven that as few people as possible read that. Especially not any future employers. Judging by the number of projects I have seen recently that are predicated on defining new keywords and recognizing them through magic decorators, it may be too late.

This is one of the reasons I love Go: simple, clean, concise, expressive, and completely free of dark magic.

Code does what it says, and says what it does.

You don't get to feel so clever doing magic tricks, but you gain a lot of time by not having decipher and debug such magic tricks.

Post reply on HN