- Beautiful is better than ugly.
- Explicit is better than implicit.
- Simple is better than complex.
- Complex is better than complicated.
- Flat is better than nested.
- Sparse is better than dense.
- Readability counts.
- Special cases aren't special enough to break the rules.
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
-- Preview the currently active BBEdit document using Marked. For easy access, add as a service. | |
tell application "BBEdit" | |
activate | |
-- Ask BBEdit for it's active document. | |
set the_document to active document of text window 1 | |
-- If the file doesn't alreay exist, ask the user to save it. | |
if not the_document's on disk then |
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
# Convert a normal word to pig latin | |
# A Codecademy Python assignment (that drove many nuts!) | |
# Dr. Steven B. Combs, coding novice | |
pyg = 'ay' # create a variable that contains 'ay' | |
original = raw_input('Enter a word: ') # request input from the user | |
if len(original) > 0 and original.isalpha(): # does the variable contain any, and if so, only alpha characters | |
word = original.lower() # convert variable original to all lower case characters |
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
<!-- | |
Sample CSS file that creates multiple 50px by 50px squares of varying color. The yellow square is a link. | |
A Codecademy HTML5 assignment | |
Dr. Steven B. Combs, HTML5 novice | |
--> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Result</title> |
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
# Sample function that utilizes the splat (*) argument to accept multiple input strings | |
# A Codecademy Python assignment | |
# Dr. Steven B. Combs, coding novice | |
def favorite_actors(*actors): | |
"""Prints out your favorite actorS (plural!)""" | |
print "Your favorite actors are:" , actors | |
favorite_actors("Michael Palin", "John Cleese", "Graham Chapman") |
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
# Sample function code to square a number | |
# Identical to the sqrt function in the math module | |
# Dr. Steven B. Combs, coding novice | |
def square(n): | |
"""Returns the square of a number.""" | |
squared = n**2 | |
print "%d squared is %d." % (n, squared) | |
return squared | |
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
# Cube a number if divisible by three with no remainder | |
# A Codecademy Python assignment | |
# Dr. Steven B. Combs, coding novice | |
def cube(n): | |
"""Cube a number""" | |
n = n ** 3 # Cube the number | |
print n # Print the number | |
return n # Return |
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
# Collection of notes that describe module and function useage | |
# Dr. Steven B. Combs, coding novice | |
# Import basics | |
import module # Imports a module | |
from module import function # Imports a single function from a module | |
from module import * # Imports all functions from a module | |
# Import samples | |
import math # Imports the math module |
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
# Shutdown Function | |
# A Codecademy Python (Review: Functions) assignment | |
# Dr. Steven B. Combs, coding novice | |
def shut_down(s): | |
if s.lower() == "yes": | |
return "Shutting down..." | |
elif s.lower() == "no": | |
return "Shutdown aborted!" | |
else: |
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
# Number is Integer or Float - return Absolute Function | |
# A Codecademy Python (Review: Built-In Functions) assignment | |
# Dr. Steven B. Combs, coding novice | |
def distance_from_zero(a): | |
"""Integer or Float to Absolute""" | |
if type(a) == int or type(a) == float: | |
return abs(a) | |
else: | |
return "Not an integer or float!" |
OlderNewer