Skip to content

Instantly share code, notes, and snippets.

View andrewberls's full-sized avatar

Andrew Berls andrewberls

View GitHub Profile
@andrewberls
andrewberls / scrollTo
Created February 5, 2012 19:15
jQuery Scrolling Function
function scrollTo(id) {
$('html,body').animate({scrollTop: $("#" + id).offset().top}, 'slow');
}
@andrewberls
andrewberls / Gemfile
Created July 15, 2012 21:56
Rakefile for building and minifying a CoffeeScript project
source 'http://rubygems.org'
gem "rake", "~> 0.9.2.2"
gem "uglifier", "~> 1.2.6"
gem "listen", "~> 0.4.7"
@andrewberls
andrewberls / ex.coffee
Created July 30, 2012 20:16
Nested functions
@fadeWith = (sound, duration) ->
return @ if !supported
@fadeOut duration, ->
@stop()
sound.play().fadeIn(duration)
return @
@andrewberls
andrewberls / list_remove.c
Created August 13, 2012 03:47
Remove linked list node
static int
list_remove(node* root, node* n) {
node* temp = (node*) malloc(sizeof(node));
temp = root;
node* garbage = (node*) malloc(sizeof(node));
int found = -1;
while (temp) {
if (temp->next->val == n->val) {
garbage = temp->next;
def sumDouble(ary); ary.map{|i| i*2}.inject(&:+); end
@andrewberls
andrewberls / pizza.rb
Created October 13, 2012 00:33
ACM Micro-Challenge 1
require "test/unit"
# Write a function called numPizzas, that takes the number of people present,
# the number of slices in a pizza, and the time of day, and returns the
# number of pizzas to buy (as a whole integer).
#
# Spec:
# Signature: int numPizzas(int numPeople, int slicesPerPizza, int time)
# Time is an int on 24-hour clock (0-23), e.g. 8 = 8am, 14 = 2pm
# Between 11am - 11pm: 2 slices per person, else 1
// hashtable.hpp
class HashTable {
public:
struct HashTable::HashEntry* insert(int);
struct HashEntry {
// Some stuff
};
};
@andrewberls
andrewberls / FizzBuzz_golf.rb
Created February 3, 2013 01:52
The classic FizzBuzz challenge, with an infusion of code golf
# Print the numbers from 1 to 100, except for multiples of 3 print "Fizz", for multiples of 5 print "Buzz",
# and for multiples of 3 and 5 print "FizzBuzz".
# Ex:
# 1
# 2
# Fizz
# 4
# Buzz
# Fizz
# 7
# Test cases used
#
# DOWN LEFT
# 3
# ---
# -m-
# p--
# UP RIGHT
# 3
@andrewberls
andrewberls / gist:5008788
Last active June 7, 2018 23:52
Brainfuck Interpreter Challenge
Brainfuck (http://en.wikipedia.org/wiki/Brainfuck) is an strange language noted for its extreme simplicity - programs are written using 7 commands in total, and executed sequentially.
An 'instruction pointer' starts at the first command, executes it, and normally moves forward to the next command (with one exception).
The program terminates when the instruction pointer moves past the last command.
For those familiar with Turing machines, this is a very similar concept. We'll have a 'tape' of cells holding our values, a pointer to the current cell, and an instruction pointer looping through the program.
The commands we'll be working with are as follows (here, 'pointer' refers to the current cell pointer):
> Move the cell pointer to the cell on the right
< Move the cell pointer to the cell on the left