Skip to content

Instantly share code, notes, and snippets.

@ahirschberg
ahirschberg / demo.rb
Created December 3, 2014 19:43
Gist Embed
def gist_is_neat()
puts "check me out, I'm embedded code"
@ahirschberg
ahirschberg / ListQueue.java
Last active August 29, 2015 14:11
Strange EIMACS exercise
public class ListQueue extends LinkedList<Object>
{
// write your code here
}
public class MainClass
{
public static void main( String[] args )
{
LinkedList<Object> q = new ListQueue();
@ahirschberg
ahirschberg / ListQueueSolution.java
Created December 16, 2014 19:36
EIMACS Queue Solution
public class ListQueue extends LinkedList<Object>
{
public boolean isEmpty() { return size() == 0; }
public boolean add( Object x )
{
addLast( x );
return true;
}
public Object remove() { return removeFirst(); }
}
@ahirschberg
ahirschberg / lsp1.rb
Created January 12, 2015 19:59
Liskov Substitution Principal example 1
# Implementation 1
class Base
## returns a positive integer from 1..100, inclusive
def get_number
5
end
end
@ahirschberg
ahirschberg / lsp2.rb
Created January 12, 2015 20:04
Liskov Substitution Principal example 2
# Implementation 2
class Base
## gets the number of files in the current directory, otherwise raises DiskError
def get_number
5
end
end
@ahirschberg
ahirschberg / lsp3.rb
Created January 13, 2015 01:02
Liskov Substitution Principal example 3
# Implementation 3
class Base
def get_number
raise NotImplementedError
end
end
def get_random_number
8 ## <-- number was chosen at random
end
@ahirschberg
ahirschberg / llist.c
Created January 16, 2015 19:43
Sam's C Linked List implementation
#include <stdlib.h>
#include <stdio.h>
struct listnode {
int head;
struct listnode *tail;
};
struct listnode *cons(int data, struct listnode *list) {
struct listnode *newlist = malloc(sizeof (struct listnode));
// bad code
var url_request = getJSON("https://librivox.org/api/feed/audiobooks/title/^" + input + "?&format=json");
url_request.response // -> null
// good code
getJSON("https://librivox.org/api/feed/audiobooks/title/^" + input + "?&format=json",
function(url_request) {
url_request.response // -> Object { books: Array[50] }
});