Skip to content

Instantly share code, notes, and snippets.

@zhuyifei1999
Created July 13, 2019 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhuyifei1999/4000f01cf33394bc674cc30b61456b21 to your computer and use it in GitHub Desktop.
Save zhuyifei1999/4000f01cf33394bc674cc30b61456b21 to your computer and use it in GitHub Desktop.
JS1 is utterly satanic, but so is Python... or is it?
# Inspired by:
# https://www.reddit.com/r/AskReddit/comments/ccbpzr/what_book_fucked_you_up_mentally/etmirvt/
import code
class NS(dict):
def __setitem__(self, key, val):
if key in self and hasattr(self[key], 'assign'):
return self[key].assign.__get__(self[key])(val)
return super(NS, self).__setitem__(key, val)
code.interact(local=NS())
# >>> x = (lambda: None)
# >>> x.size = 0
# >>> x.assign = lambda self, n: setattr(self, 'size', n)
# >>> x = 30
# >>> x.size
# 30
# >>> x.assign = lambda self, n: setattr(self, 'size', n * 2)
# >>> x = 50
# >>> x.size
# 100
# >>> import random, signal
# >>> signal.signal(signal.SIGALRM, lambda signum, frame: (lambda rd: setattr(x, 'assign', lambda self, n: setattr(self, 'size', n * rd)))(random.random()))
# <Handlers.SIG_DFL: 0>
# >>> signal.setitimer(signal.ITIMER_REAL, 1, 1)
# (0.0, 0.0)
# >>> x = 10; x.size
# 9.851146270855914
# >>> x = 10; x.size
# 3.0629361758247864
# >>> x = 10; x.size
# 3.0629361758247864
# >>> x = 10; x.size
# 3.0629361758247864
# >>> x = 10; x.size
# 4.8760695045651765
# >>> x = 10; x.size
# 4.8760695045651765
# >>> x = 10; x.size
# 5.469714851041719
# >>> x = 10; x.size
# 5.469714851041719
# >>> x = 10; x.size
# 3.9915335156157816
# >>> x = 10; x.size
# 3.9915335156157816
# >>> x = 10; x.size
# 3.9915335156157816
# >>> x = 10; x.size
# 5.988438611695427
# >>> x = 10; x.size
# 5.988438611695427
# >>> x = 10; x.size
# 5.988438611695427
# >>> x = 10; x.size
# 0.9312613818017534
# >>> x = 10; x.size
# 0.9312613818017534
# >>> x = 10; x.size
# 0.9312613818017534
# >>> x = 10; x.size
# 0.9312613818017534
# >>> x = 10; x.size
# 6.840876611391985
# >>> x = 10; x.size
# 6.840876611391985
# >>> x = 10; x.size
# 6.840876611391985
# >>> x = 10; x.size
# 6.840876611391985
# >>> x = 10; x.size
# 2.5695834315824118
# >>> x = 10; x.size
# 2.5695834315824118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment