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
| #http://learnpythonthehardway.org/book/ex17.html | |
| from sys import argv, exit | |
| from os.path import exists | |
| script, from_file, to_file = argv | |
| try: | |
| with open(from_file) as file: | |
| pass | |
| except IOError as e: |
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
| #http://learnpythonthehardway.org/book/ex18.html | |
| # this one is like your scripts with argv | |
| #What does the * in *args do? | |
| #That tells Python to take all the arguments to the function and then put them in args as a list. It's like argv that you've been using, but for functions. It's not normally used too often unless specifically needed. | |
| def print_two(*args): | |
| arg1, arg2 = args | |
| print "arg1: %r, arg2: %r" % (arg1, arg2) | |
| # ok, that *args is actually pointless, we can just do this | |
| def print_two_again(arg1, arg2): |
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
| from song import Song | |
| happy_b_day_dict = { | |
| 'name' : "Happy Birthday", | |
| 'lyrics': ["Happy birthday to you", | |
| "I don't want to get sued", | |
| "So I'll stop right there"] | |
| } | |
| happy_b_day = Song(happy_b_day_dict) |
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
| Canoe Canoe come out and play with me today? | |
| Lettuce Lettuce in, it's cold out here. | |
| Honey bee Honey bee a dear and get me some juice. | |
| Wooden shoe Wooden shoe like to hear another joke? | |
| A broken pencil Oh never mind it's pointless. | |
| Cow says No silly, a cow says Mooooo! | |
| Double W! | |
| Mikey Mikey doesn't fit in the keyhole! | |
| Atch Bless you! | |
| I am You don't know who you are? |
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
| #include <SoftwareSerial.h> | |
| #include <SyRenSimplified.h> | |
| SoftwareSerial motor01_Serial(NOT_A_PIN, 11); // RX, TX | |
| SoftwareSerial motor02_Serial(NOT_A_PIN, 10); // RX, TX | |
| //LED status pin, refecting state of system incase of motor failure. | |
| const int ledPin = 5; // the pin that the LED is attached to | |
| SyRenSimplified Motor01(motor01_Serial); // Use SWSerial as the serial port. |
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
| var move = 0; | |
| var jump = function(faceX, faceY) { | |
| fill(255, 255, 0); | |
| ellipse(faceX, faceY, 180, 180); // face | |
| fill(46, 46, 41); | |
| ellipse(faceX - 30, faceY - 50, 30, 30); // eyes | |
| ellipse(faceX + 44, faceY - 55, 30, 30); | |
| fill(252, 65, 65); | |
| ellipse(faceX + 19, faceY + 32, 82, 81); // mouth | |
| }; |
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
| // Working with numbers in strings | |
| import UIKit | |
| var str = "Hello, playground" | |
| let myInt:Int = 7; | |
| let myDouble:Double = 8.4; | |
| // basic | |
| print("The result of \(myInt) multiplied by \(myDouble) is \(Double(myInt) * myDouble)"); | |
| // formating fancy |
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
| //: Embedding JavaScript in Swift | |
| import UIKit | |
| import JavaScriptCore | |
| var str = "Hello, playground" | |
| //from http://nshipster.com/javascriptcore/ | |
| let context1 = JSContext() |
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
| let myDictionary = [ | |
| "20" : "banna", | |
| "60" : "apple", | |
| "30" : "cucumber", | |
| "10" : "starfruit" | |
| ] | |
| //assume that sort() kinda takes 2 arguments i.e. sort(dictionary element a, dictionary element b) | |
| //woriking its way down the array (http://www.sorting-algorithms.com/bubble-sort) | |
| //compare the 0th assumed parameter(a) with the 1st assumed parameter (b), using the key (0 after decimal) |
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
| //Concat strings | |
| print(["one","two","three"].reduce("This string comes before: ",combine:{$0 + $1})) | |
| //Sum an Int array | |
| let numbers = [Int](0..<10) | |
| let total = numbers.reduce(0, combine: +) | |
| //same as numbers.reduce(0, combine: {$0 + $1}) | |
| //Dictionary values |