This file contains 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
#!/usr/bin/env python | |
import random | |
def makeSentence(part1, part2, part3, n=10): | |
"""return n random sentences""" | |
#convert to lists | |
p1 = part1.split('\n') | |
p2 = part2.split('\n') | |
p3 = part3.split('\n') |
This file contains 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
parse_git_branch () { | |
git branch 2> /dev/null | grep '*' | sed 's#*\ \(.*\)#(git::\1)#' | |
} | |
export PS1="$PS1\$(parse_git_branch) " |
This file contains 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-syntax while-less | |
(syntax-rules (do) | |
[(while-less e1 do e2) | |
(if (< e1 e2) | |
#t | |
e2)])) | |
;; this is obviously wrong, but I'm not sure how to eval e2 until (< e1 e2) | |
This file contains 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
//return the nth to last item in a linked list | |
public static void nthToLast(LinkedListNode n, Integer i) { | |
LinkedListNode p1 = n; | |
LinkedListNode p2 = n; | |
// just iterate p2 for i steps and wait for it to hit null | |
while (i != 0) { | |
p2 = p2.next; | |
i--; | |
} | |
while (p2 != null) { |
This file contains 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
// given a sorted array, create a BST | |
public static void add(int[] arr, int start, int end) { | |
int mid = (start + end) / 2; | |
TreeNode n = new TreeNode(arr[mid]); | |
n.left = add(arr, start, mid-1); | |
n.right = add(arr, mid+1, end); | |
return n | |
} | |
public static TreeNode makeBST(int[] arr, int start, int end) { |
This file contains 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
;; A small portion of the MUPL assignment | |
#lang racket | |
(provide (all-defined-out)) ;; so we can put tests in a second file | |
;; definition of structures for MUPL programs - Do NOT change | |
(struct var (string) #:transparent) ;; a variable, e.g., (var "foo") | |
(struct int (num) #:transparent) ;; a constant number, e.g., (int 17) | |
(struct add (e1 e2) #:transparent) ;; add two expressions | |
(struct ifgreater (e1 e2 e3 e4) #:transparent) ;; if e1 > e2 then e3 else e4 |
This file contains 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
#!/usr/bin/ruby | |
#file: get_jetset.rb | |
require 'net/http' | |
require 'open-uri' | |
path = '/home/tippenein/podcasts/jet-set-planet/' | |
uri = URI('http://kfai.org/jet-set-planet') |
This file contains 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
# have a folder full of txt files to word count | |
cat `find . -type f` | tr -cs [:alpha:] [n*] | sort | uniq -c | sort -nr > results.txt |
This file contains 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
#!/usr/bin/env python | |
import markdown | |
import sys | |
import codecs | |
if __name__ == '__main__': | |
in_file = codecs.open(sys.argv[1], mode="r", encoding="utf-8") | |
text = input_file.read() | |
html = markdown.markdown(text) |
This file contains 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 random import Random | |
class BloomFilter: | |
# http://en.wikipedia.org/wiki/Bloom_filter | |
def __init__(self, num_bytes, num_probes, iterable=set()): | |
self.array = bytearray(num_bytes) | |
self.num_probes = num_probes | |
self.num_bins = num_bytes * 8 | |
self.update(iterable) |
OlderNewer