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
| LOCU_API_KEY = 'xxx' | |
| def get_response(params, api_category='venue', api_type='search'): | |
| """ | |
| Takes a dictionary of params and queries the Locu API, returns | |
| a requests.response object. | |
| """ | |
| def get_api_url(params): | |
| base = 'http://api.locu.com/v1_0/{0}/{1}/?api_key={3}&'.format( | |
| api_category, |
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
| function postRequest(path, params, method) { | |
| method = method || 'POST'; | |
| var form = document.createElement("form"); | |
| form.setAttribute("method", method); | |
| form.setAttribute("action", path); | |
| for(var key in params) { | |
| if(params.hasOwnProperty(key)) { | |
| var hiddenField = document.createElement("input"); | |
| hiddenField.setAttribute("type", "hidden"); | |
| hiddenField.setAttribute("name", key); |
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
| function StringBuffer() { | |
| this.__strings__ = new Array; | |
| } | |
| StringBuffer.prototype.append = function(str) { | |
| this.__strings__.push(str); | |
| }; | |
| StringBuffer.prototype.toString = function() { | |
| return this.__strings__.join(" "); |
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
| ; sets as unordered lists: | |
| ; a set for now is defined as as being able | |
| ; to undergo the following operations | |
| ; 1) element-of-set? checks if x is in set | |
| (define (element-of-set? x set) | |
| (cond ((null? set) false) | |
| ((equal? x (car set)) true) | |
| (else (element-of-set? x (cdr set))))) |
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
| ; Symbolic differentiation | |
| (define (deriv exp var) | |
| (cond ((number? exp) 0) | |
| ((variable? exp) | |
| (if (same-variable? exp var) 1 0)) | |
| ((sum? exp) | |
| (make-sum (deriv (addend exp) var) | |
| (deriv (augend exp) var))) | |
| ((product? exp) | |
| (make-sum |
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 Merge(left, right): | |
| output = [] | |
| x, y = 0, 0 | |
| while x < len(left) and y < len(right): | |
| if left[x] <= right[y]: | |
| output.append(left[x]) | |
| x += 1 | |
| else: | |
| output.append(right[y]) | |
| y += 1 |
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 MergeSort(a): | |
| """ | |
| Takes a list, returns a list. | |
| """ | |
| if (len(a) < 2): | |
| return a | |
| else: | |
| mid = (len(a)) / 2 | |
| left = a[:mid] | |
| right = a[mid:] |
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
| (define (count-leaves t) | |
| (cond ((null? t) 0) | |
| ((not (pair? t)) 1) | |
| (else (+ (count-leaves (car t)) | |
| (count-leaves (cdr t)))))) | |
| ; The general logic of this function is: | |
| ; If the tree is null, return 0 | |
| ; elif: return 1 if at a leaf. We know | |
| ; That we're at a leaf if the position is not null and not a pair |
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
| ; This creates a simple tree | |
| (define tree-1 (cons (list 1 2) (list 3 4))) | |
| ; Quick linked list review | |
| (list 1 2 3 4) ;is equivalent to: | |
| (cons 1 (cons 2 (cons 3 (cons 4 ())))) | |
| ; And here is some interpreter action | |
| ; just for practice: |
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
| ; Mapping a singly linked list in Scheme. | |
| ; map-1 - the name of our mapping function | |
| ; proc - the tranformation | |
| ; items - the list | |
| (define (map-1 proc items) | |
| (if (null? items) | |
| () | |
| (cons (proc (car items)) |