This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
regexp_extract(col_value, '^(?:([^,]*)\,?){1}', 1) player_id, | |
regexp_extract(col_value, '^(?:([^,]*)\,?){2}', 1) year, | |
regexp_extract(col_value, '^(?:([^,]*)\,?){9}', 1) run | |
from temp_batting; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Borg(object): | |
_shared_state = {} | |
def __new__(cls, *args, **kwargs): | |
obj = super(Borg, cls).__new__(cls, *args, **kwargs) | |
obj.__dict__ = cls._shared_state | |
return obj | |
class Child(Borg): | |
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Duck: | |
def quack(self): | |
print("Quaaaaaack!") | |
def feathers(self): | |
print("The duck has white and gray feathers.") | |
class Person: | |
def quack(self): | |
print("The person imitates a duck.") | |
def feathers(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for x in range(0,101): | |
if (lambda i : not i % 2 and not i % 3 and not i % 4 and not i % 5 and not i % 6)(x): | |
print x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Book: | |
def __init__(self, name, authors, price, **rest): | |
'''Examples of rest: publisher, length, tags, publication date''' | |
self.name = name | |
self.authors = authors | |
self.price = price | |
self.__dict__.update(rest) | |
def __str__(self): | |
mylist=[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
class ImageDownloader(): | |
def download(self, filename): | |
urllib.urlretrieve(self.url, filename) | |
img = ImageDownloader() | |
img.url = "http://i.imgur.com/Ph4Xw.jpg" | |
img.download("duck.jpg") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FileServer(Server): | |
def __init__(self): | |
'''actions required for initializing the file server''' | |
self.name = 'FileServer' | |
self.state = State.new | |
def boot(self): | |
print('booting the {}'.format(self)) | |
'''actions required for booting the file server''' | |
self.state = State.running |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == '__main__': | |
domain = 'ftp.freebsd.org' | |
path = '/pub/FreeBSD/' | |
protocol = input('Connecting to {}. Which Protocol to use? (0-http,1-ftp): '.format(domain)) | |
if protocol == 0: | |
is_secure = bool(input('Use secure connection? (1-yes, 0-no): ')) | |
connector = HTTPConnector(is_secure) | |
else: | |
is_secure = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate_age(name): | |
try: | |
age = raw_input('Welcome {}. How old are you? '.format(name)) | |
age = int(age) | |
except ValueError as err: | |
print("Age {} is invalid, please try again...".format(age)) | |
return (False, age) | |
return (True, age) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == "__main__": | |
stock_watcher = Observable() | |
american_observer = AmericanStockMarket() | |
stock_watcher.register(american_observer) | |
stock_watcher.publish('KLSE Market Update', price='+0.5') |
OlderNewer