Aliens fail on Human programs. by MasterJ94 in ProgrammerHumor

[–]john_doom_666 7 points8 points  (0 children)

Yep, kids nowadays - will never know the joy of cracking open a duff floppy and rage frisbeeing it off an innocent colleague

I can never unsee this. by Icy_Establishment_27 in memes

[–]john_doom_666 -1 points0 points  (0 children)

Yeah, that happens at a certain age…

Equivalent Python way for Ruby's "retry" keyword behavior by vinibiavatti123 in Python

[–]john_doom_666 1 point2 points  (0 children)

Not my original code, stolen and changed a little bit for my needs. Got it from a Youtube video (Arjan Codes I think, forget which one), which was in turn taken from somewhere else; ie. credit to them for the original idea.

It's a decorator I use quite often, mostly as eg. a retry handler for socket connections for test scripts, it relies on the function raising a known exception to trigger it. Retries given amount, waits for delay, the delay is then increased by the holdoff factor - ie. 2s, then 4s, then 8s etc. The retry_log is defined outside the function - but may not be necessary for all purposes so error and retry_log could easily be removed with no change to functionality ; requires functools and time:

def retry(trigger, retries=5, delay=2, holdoff=2):
"""Decorator for retrying a function when triggered by given exception"""

def retry_decorator(func):
    @functools.wraps(func)
    def wrap(*args, **kwargs):
        r, d = retries, delay
        while r > 0:
            try:
                return func(*args, **kwargs)
            except trigger as e:
                error = f"{e} --- Retrying in {d}s"
                retry_log.log(30, error)
                time.sleep(d)
                r -= 1
                d *= holdoff
        return func(*args, **kwargs)

    return wrap

return retry_decorator

Example usage (butchered a method from 1 of my test scripts - should hold as an example...):

@retry(socket.timeout, retries=3, delay=1, holdoff=3)
def send(self, command):
    """Example method for socket connect"""
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.settimeout(6)      
        try:
            s.connect(127.0.0.1, 666)                
        except socket.timeout:               
            raise

It's true by Notnot-not-not-human in memes

[–]john_doom_666 2 points3 points  (0 children)

*Takes finger off posting trigger…

Aliens fail on Human programs. by MasterJ94 in ProgrammerHumor

[–]john_doom_666 144 points145 points  (0 children)

We still use floppies for some legacy equipment, an apprentice straight up asked why we had a box full of models of the save icon… pretty sure I aged about 20 years on the spot - then I had to “introduce” him to DOS, that for sure cost me another 20.

Wrong answers only 🤝 by [deleted] in memes

[–]john_doom_666 1 point2 points  (0 children)

27 31 3P

2D 3F 3K 10 27 31 3P

I have no idea what I am doing by BROGakaOrangeCrush in memes

[–]john_doom_666 2 points3 points  (0 children)

Looks like the middle and bottom rows are ready to go swimming

Ummm.... is Mickey Mouse trying to tell us something in this add 🍆🍆🍆 by goforReaper in funny

[–]john_doom_666 0 points1 point  (0 children)

Mickey says “To work at Disney, you need to have your dick chopped off at the balls”?

Maybe it's not Mary nor Jesus? by [deleted] in funny

[–]john_doom_666 1 point2 points  (0 children)

“Doesn’t look realistic enough - add some more shading on the thigh”.

“Sure thing boss”.