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: Calculator | |
| */ | |
| class Calculator(var x: Int, var y: Int) { | |
| var temp = 0 | |
| def add(): Int = { | |
| return x + y | |
| } | |
| def subtract(): Int = { |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| # Find potential outliers in values array | |
| # and visualize them on a plot | |
| def is_outlier(value, p25, p75): | |
| """Check if value is an outlier | |
| """ | |
| lower = p25 - 1.5 * (p75 - p25) | |
| upper = p75 + 1.5 * (p75 - p25) | |
| return value <= lower or value >= upper | |
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
| # Reference: http://stackoverflow.com/questions/22354094/pythonic-way-of-detecting-outliers-in-one-dimensional-observation-data/22357811#22357811 | |
| import numpy as np | |
| def is_outlier(points, thresh=3.5): | |
| """ | |
| Returns a boolean array with True if points are outliers and False | |
| otherwise. | |
| Parameters: | |
| ----------- | |
| points : An numobservations by numdimensions array of observations |
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 compress_seq(seq, limit=5): | |
| ''' | |
| Compress a sequence to a short on by compress a long-continuously-apprearing | |
| sub-sequence into limited length. | |
| Args: | |
| seq: the sequence to be compressed. | |
| limit: the sub-sequence length limitation. | |
| Returns: |
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
| void foo(int[] array) { | |
| int sum = 6; | |
| int product = 1; | |
| for (int i = 6; i < array.length ; i++) { | |
| sum += array[i]; | |
| } | |
| for (int i = 6; i < array.length; i++) { | |
| product *= array[i] ; | |
| } | |
| System.out.println(sum + ", " + product); |
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 KnuthMorrisPratt(text, pattern): | |
| '''Yields all starting positions of copies of the pattern in the text. | |
| Calling conventions are similar to string.find, but its arguments can be | |
| lists or iterators, not just strings, it returns all matches, not just | |
| the first one, and it does not need the whole text in memory at once. | |
| Whenever it yields, it will have read the text exactly up to and including | |
| the match that caused the yield.''' | |
| # allow indexing into pattern and protect against change during yield |
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 seq_in_seq(subseq, seq): | |
| """Return an index of `subseq`uence in the `seq`uence. | |
| Or `-1` if `subseq` is not a subsequence of the `seq`. | |
| The time complexity of the algorithm is O(n*m), where | |
| n, m = len(seq), len(subseq) | |
| >>> index([1,2], range(5)) | |
| 1 | |
| >>> index(range(1, 6), range(5)) |
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
| print __file__ | |
| print os.curdir | |
| print os.getcwd() | |
| print os.chdir('.') | |
| print os.getcwd() | |
| print os.path.dirname(__file__) | |
| print os.pardir | |
| print os.path.abspath(os.path.join(os.path.dirname( __file__ ), os.pardir)) | |
| print os.path.join(os.path.dirname( __file__ ), os.pardir) |
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
| """ | |
| Results: | |
| multiple_update: 57 ms | |
| copy_and_update: 46 ms | |
| dict_constructor: 56 ms | |
| kwargs_hack: 45 ms | |
| dict_comprehension: 45 ms | |
| concatenate_items: 166 ms | |
| union_items: 163 ms |