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 SimpleHTTPServer as shs | |
| import SocketServer as ss | |
| port = 1234 | |
| handler = shs.SimpleHTTPRequestHandler | |
| py_web_server = ss.TCPServer(('', port), handler) | |
| print 'python web server. serving at port', port | |
| py_web_server.serve_forever() | |
| """ |
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 logging | |
| def count_lines(filename): | |
| """ | |
| Count the number of lines in a file. If the file can't be opened it should be treated as an empty file | |
| :param filename: | |
| """ | |
| f = None | |
| try: |
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
| // pass by value | |
| #include <iostream> | |
| using namespace std; | |
| void foo(int y) { // y = copy of x | |
| cout << "y = " << y << endl; | |
| } | |
| int main() { |
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
| // constructors with parameters {here default constructors and constructors with parameters co-exist} | |
| // better design paradign is to merge them into one | |
| // see constructor2.cpp | |
| #include <iostream> | |
| #include <cassert> | |
| using namespace std; | |
| class Fraction { |
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
| // default constructor example in C++ | |
| #include "frac.h" | |
| using namespace std; | |
| class Fraction { | |
| private: | |
| int num; | |
| int denum; |
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
| // | |
| // registertest.cpp | |
| // cppbin | |
| // | |
| // Created by Arunprasath Shankar on 3/10/13. | |
| // Copyright (c) 2013 Arunprasath Shankar. All rights reserved. | |
| // | |
| #include <iostream> | |
| #include <iomanip> |
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
| // | |
| // cashregister.cpp | |
| // cppbin | |
| // | |
| // Created by Arunprasath Shankar on 3/10/13. | |
| // Copyright (c) 2013 Arunprasath Shankar. All rights reserved. | |
| // | |
| #include "cashregister.h" |
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
| // | |
| // cashregister.h | |
| // cppbin | |
| // | |
| // Created by Arunprasath Shankar on 3/9/13. | |
| // Copyright (c) 2013 Arunprasath Shankar. All rights reserved. | |
| // | |
| #ifndef cppbin_cashregister_h | |
| #define cppbin_cashregister_h |
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 <iostream> | |
| #include <iomanip> | |
| using namespace std; | |
| /* | |
| A simulated cash register that tracks item count and total amount due | |
| */ | |
| class CashRegister { | |
| public: | |
| void clear(); |
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 <iostream> | |
| using namespace std; | |
| void swap(int& a, int& b) { | |
| a = a-b; | |
| b = b+a; | |
| a = b-a; | |
| } | |
| int main() { | |
| int a = 10; | |
| int b = 20; |