Skip to content

Instantly share code, notes, and snippets.

@zallarak
zallarak / gist:4533914
Created January 14, 2013 21:58
simple locu api wrapper
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,
@zallarak
zallarak / post_request.js
Created December 4, 2012 23:07
javascript post request
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);
@zallarak
zallarak / string_concatenation.js
Created February 3, 2012 23:38
String concatenation in JavaScript
function StringBuffer() {
this.__strings__ = new Array;
}
StringBuffer.prototype.append = function(str) {
this.__strings__.push(str);
};
StringBuffer.prototype.toString = function() {
return this.__strings__.join(" ");
@zallarak
zallarak / binary_tree_1.scm
Created January 16, 2012 12:39
Binary trees in Scheme
; 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)))))
@zallarak
zallarak / sym_diff_1.scm
Created January 14, 2012 23:12
Symbolic differentiation
; 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
@zallarak
zallarak / merge_sort_2.py
Created January 12, 2012 02:05
Merge sort part 2
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
@zallarak
zallarak / merge_sort_1.py
Created January 12, 2012 01:58
Merge sort part 1
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:]
@zallarak
zallarak / leaves_in_a_tree.scm
Created January 9, 2012 18:35
Counting the leaves in a tree in Scheme (Lisp)
(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
@zallarak
zallarak / hierarchical_data_structures_1.scm
Created January 9, 2012 16:38
Creating a tree in Scheme (Lisp)
; 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:
@zallarak
zallarak / linked_list_2.scm
Created January 9, 2012 01:51
Mapping a linked list in Scheme (Lisp)
; 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))