Skip to content

Instantly share code, notes, and snippets.

View eclecticmiraclecat's full-sized avatar

eclecticmiraclecat

View GitHub Profile
@eclecticmiraclecat
eclecticmiraclecat / spread kindness
Created July 6, 2015 03:52
make the world a beautiful place
#!/usr/bin/python
import praw
import pdb
import re
import os
import time
user_agent = ("spread kindness /u/eclecticmiraclecat13")
r = praw.Reddit(user_agent=user_agent)
@eclecticmiraclecat
eclecticmiraclecat / apache2
Created February 13, 2018 12:36
monit script to check number of apache processes
check program apache2 with path "/bin/bash -c '[ $(/bin/ps auxwww | /bin/grep apache | /bin/grep -v grep | /usr/bin/wc -l) -gt 2 ]'"
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
restart program = "/etc/init.d/apache2 restart"
if status != 0 then restart
>>> class Foo:
... def __get__(self, instance, owner_class):
... print('hello from foo')
...
>>> class Bar:
... foo = Foo()
...
>>> b = Bar()
>>> b.foo
hello from foo
>>> class Foo:
... def hello(self):
... print(self.__class__.__name__)
...
>>> class Bar(Foo):
... pass
...
>>> b = Bar()
>>> b.hello()
Bar
>>> class Num:
... def __init__(self, value):
... self.value = value
... def __add__(self, other):
... return self.value + other.value
...
>>> num1 = Num(1)
>>> num2 = Num(2)
>>> num1 + num2
3
>>> class Foo:
... def __getattr__(self, name):
... setattr(self, name, 'N/A')
... return getattr(self, name)
...
>>> f = Foo()
>>> f.x
'N/A'
>>> f.__dict__
{'x': 'N/A'}
>>> class Foo:
... def __init__(self, x, y):
... self.x = x
... self.y = y
...
>>> f = Foo(x=2, y=3)
>>> f.x
2
>>> getattr(f, 'x')
2
>>> class Parent:
... def __init__(self, value):
... self.value = value
... def spam(self):
... print('Parent.spam', self.value)
... def grok(self):
... print('Parent.grok')
... self.spam()
...
>>> p = Parent(42)
>>> class Upper:
... def uppercase(self, value):
... print(value.upper())
...
>>> u = Upper()
>>> u.uppercase('hi')
HI
>>> class DashUpper(Upper):
... def uppercase(self, value):
... value = f'--{value}--'
>>> class Parent:
... def spam(self):
... print('Parent.spam')
...
>>> class A(Parent):
... def spam(self):
... print('A.spam')
... super().spam()
...
>>> class B(A):