Skip to content

Instantly share code, notes, and snippets.

@cronin101
cronin101 / replacement_selection_sort.py
Last active August 29, 2015 13:55
Replacement Selection Sort - from Advanced Databases Lecture 6
import heapq
import random
class HeapSorter:
def __init__(self, num_blocks, input_sequence):
self.num_blocks = num_blocks
self.input_sequence = input_sequence
def sorted(self):
return heapq.merge(*self.__sorted_subsequences__())
@cronin101
cronin101 / report.tex
Last active January 3, 2016 21:08
example latex layout
\documentclass[10pt, a4paper]{article} % use "amsart" instead of "article" for AMSLaTeX format
\usepackage{microtype}
\usepackage[textwidth=17cm,textheight=24cm]{geometry}
\usepackage{fullpage} % See geometry.pdf to learn the layout options. There are lots.
\usepackage{helvet}
\usepackage{listings}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[normalem]{ulem}
\usepackage{epstopdf}
\usepackage{rotating}
@cronin101
cronin101 / traversal.rb
Last active January 1, 2016 00:39
Interview question about tree reconstruction.
# Exercise:
# Given the Pre-order and In-order traversals of a tree,
# reconstruct the original tree structure.
#
# Pre-order node output: Node (Left) (Right)
# In-order node output: (Left) Node (Right)
#
# Example:
# 'a'
# | |
@cronin101
cronin101 / practical1.R
Created December 11, 2013 15:28
Arse Crypt
# Read the CSV file into R
citations <- read.csv("citations2013.csv")
# At this point, people were told to attach(). Apparently that's icky.
print("Dataset contains the following columns:")
print(names(citations))
print("Length of citations$Citations2013:")
print(length(citations$Citations2013))
@cronin101
cronin101 / mrCount.hs
Last active December 28, 2015 00:09
MapReduce and token-counting in Haskell.
import Control.Arrow
import Data.Function
import Data.List
import Data.Ord
-- mapReduce key_func val_func reduce_func --
mapReduce :: Ord c => (b1 -> c) -> (b1 -> b) -> ([b] -> c1) -> [b1] -> [(c, c1)]
mapReduce k r v = reduce' r . group' . map' k v
where
reduce' f = map (fst . head &&& f . map snd)
@cronin101
cronin101 / test.rb
Created November 8, 2013 14:11
foo_test
def foo
puts "This is a test"
end
@cronin101
cronin101 / spiral.rb
Created October 31, 2013 12:02
Flattening a matrix stored as a list of lists, in clockwise spiral pattern. From a coding interview - sorry about the Ruby, recruiters (I'm not actually sorry.)
def spiral_flatten(matrix_chunks)
[].tap do |result|
until matrix_chunks.empty?
result.concat matrix_chunks.shift
matrix_chunks[0..-2].to_a.each { |chunk| result << chunk.pop }
break if matrix_chunks.empty?
result.concat matrix_chunks.pop.reverse
matrix_chunks[1..-1].to_a.reverse_each { |chunk| result << chunk.shift }
end
end
@cronin101
cronin101 / tty
Created October 26, 2013 15:51
Testing random name generation for an anonymised chat client. Sometimes random selection works very nicely.
λ server git:(client/server-model) ✗ ruby pearserver.rb
# Connection from 1
<Ryan White(1)> yo
# Connection from 2
# Connection from 3
<James Maverick(2)> hey
<Daniel Harris(3)> what's up?
# Connection from 4
<Daniel Lannister(4)> hey
# Connection from 5
@cronin101
cronin101 / demo.md
Last active December 26, 2015 07:39
no more $ hadoop dfs -

Starting up:

[bw1425n01]s0925570: ./hshell.rb

Clearing previous output:

s0925570@hadoop $ rmr ~/data/output
Deleted hdfs://bw1425n01.inf.ed.ac.uk/user/s0925570/data/output
@cronin101
cronin101 / redstone.md
Last active December 25, 2015 16:19
Redstone circuit ideas