Skip to content

Instantly share code, notes, and snippets.

View pcote's full-sized avatar
🏠
Working from home

Emma Cote pcote

🏠
Working from home
View GitHub Profile
@pcote
pcote / full_custom_filter_example.html
Created April 28, 2017 22:12
An example on how to set up a full custom filter in angularjs in which the filter in question can take an argument.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Custom Angular Filter Example</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
class MyClass(object):
def __init__(self, msg):
self.msg = msg
def say_stuff(self):
print("Standard say stuff message: {}\n\n".format(self.msg))
ob = MyClass("Here is the original message")
def say_stuff():
class MyClass(object):
def __init__(self, msg):
self.msg = msg
def say_stuff(self):
print("Standard say stuff message: {}\n\n".format(self.msg))
def say_other_stuff(self):
print("New say_stuff says this: {}\n\n".format(self.msg))
class MyClass(object):
pass
ob = MyClass()
def say_stuff(self):
print("The say stuff message here is: {}\n\n".format(self.msg))
setattr(MyClass, "say_stuff", say_stuff)
setattr(ob, "msg", "Patched in message for patched in class")
class MyClass(object):
def say_stuff(self):
print("Say stuff message is: {}\n\n".format(self.msg))
ob = MyClass()
setattr(ob, "msg", "Here is a message from a setattr")
ob.say_stuff()
class MyClass(object):
def say_stuff(self):
print("Say stuff message is: {}\n\n".format(self.msg))
class MyClass(object):
def say_stuff(self):
print("Say stuff message is: {}\n\n".format(self.msg))
class OtherClass(object):
def __init__(self, msg):
self.msg = msg
say_stuff = MyClass.say_stuff
say_stuff(ob1)
class MyClass(object):
def __init__(her, msg):
her.msg = msg
def say_stuff(her):
print("Say stuff message is: {}\n\n".format(her.msg))
# normal call and instantiation
ob1 = MyClass("Hello there, This is me.")
ob1.say_stuff()
class MyClass(object):
def __init__(self, msg):
self.msg = msg
def say_stuff(self):
print("Say stuff message is: {}\n\n".format(self.msg))
# normal call and instantiation
ob1 = MyClass("Hello there, first example.")