This file contains 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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains 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 psycopg2 | |
class Database: | |
def __init__(self, dbname, user, password): | |
self.conn = psycopg2.connect(database=dbname, user=user, password=password) | |
self.cur = self.conn.cursor() | |
def query(self, query): | |
self.cur.execute(query) |
This file contains 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
package decorator_pattern | |
abstract class Beverage { | |
open var description: String = "Beverage UnKnown" | |
//Every beverage must define its own cost | |
abstract fun cost() | |
} |
This file contains 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 Espresso: Beverage() { | |
override var description: String="Espresso coffee" | |
override fun cost(): Double { | |
return 1.99 | |
} | |
} |
This file contains 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
abstract class CondimentDecorator: Beverage() { | |
abstract override var description: String | |
} | |
class Soya(var beverage: Beverage): CondimentDecorator() { | |
override fun cost(): Double { | |
return beverage.cost() + 1.0 | |
} |
This file contains 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
fun main(args: Array<String>) { | |
var beverage: Beverage | |
beverage = Espresso() | |
println(" Your Order: \n ${beverage.description}\n Total Cost: ${beverage.cost()}") | |
} |
This file contains 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
fun main(args: Array<String>) { | |
var beverage: Beverage | |
beverage = Espresso() | |
var beverageWithTopping = Mocha(beverage) | |
//Mocha decorates Espresso | |
println("You bought ${beverageWithTopping.description} Total cost: ${beverageWithTopping.cost()}") | |
//If we decide to add a new topping ontop of Mocha, we just need to wrap the beverageWithTopping inside the Topping e.g | |
beverageWithTopping = Soya(beverageWithTopping) |
This file contains 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
from django.db import models | |
class Author(models.Model): | |
name = models.CharField(max_length=255) | |
email = models.EmailField() |
This file contains 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 Article(models.Model): | |
title = models.CharField(max_length=120) | |
description = models.TextField() | |
body = models.TextField() | |
author = models.ForeignKey('Author', related_name='articles') |
This file contains 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
from django.contrib import admin | |
from .models import Article, Author | |
admin.site.register(Article) | |
admin.site.register(Author) |
OlderNewer