Skip to content

Instantly share code, notes, and snippets.

View rvandervort's full-sized avatar

Roger Vandervort rvandervort

  • Seeking my next opportunity.
  • Pittsburgh, PA USA
View GitHub Profile
@rvandervort
rvandervort / pascal.rb
Created January 6, 2012 08:56
Pascal's Triangle in Ruby
def pascal_calc(row_num)
if row_num == 0
return [1]
end
previous = pascal_calc(row_num - 1)
ret = []
(previous.length - 1).times do |i|
DATA: lv_test TYPE STRING.
@rvandervort
rvandervort / zipToTuples.scala
Created July 5, 2016 19:23
Scala -- given two maps with identical keys, return a map that contains the keys and tuple of values from both maps
type TheMap: Map[String, String]
// a and b really should have the same keys
// If not, entries from b will be lost.
def zipToTuples(a: TheMap, b: TheMap) =
(a.keys zip (a.values zip b.values)).toMap
@rvandervort
rvandervort / 8-puzzle.rb
Created April 1, 2013 11:50
8-puzzle solver with flexible node selection
require 'priority_queue'
require 'set'
=begin
- solve the 8 puzzle
Basically, we have to treat each "State" as a node in the graph.
Add each 'move we can make' from the current state into the frontier
but only if we haven't visited it yet.
@rvandervort
rvandervort / simple_graph_bfs.rb
Created March 15, 2013 02:10
simple bfs in ruby
class Graph
def initialize
@nodes = {}
@edges = {}
end
def add_node(key, node)
@nodes[key] = node
@edges[key] = {}
@rvandervort
rvandervort / counting_inversions.py
Last active December 12, 2015 02:08
Divide and conquer algorithm for counting array inversions
def sort_and_count(array):
if len(array) <= 1:
return 0, array
mid = len(array) / 2
left_array = array[0:mid]
right_array = array[mid:len(array)]
left_result = sort_and_count(left_array)
@rvandervort
rvandervort / index.html
Created January 16, 2013 20:28
10 x 10 battleship board in canvas
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<canvas id="opponent_board" width="800" height="800"></canvas>
<script type="text/javascript">
var canvas = document.getElementById('opponent_board');
var context = canvas.getContext("2d");
@rvandervort
rvandervort / gist:3517648
Created August 29, 2012 19:32
Palindrome checker in ruby
class String
def palindrome?
is_p = true
ch = self.gsub(/ /,"").chars.to_a
compares = ch.length / 2
back_index = ch.length - 1
compares.times do |i|
@rvandervort
rvandervort / monkeypath_capybara.rb
Created June 18, 2012 02:34
Monkey-patch Capybara to not reset sessions after each example
# Don't let capybara reset sessions
# See : https://github.com/jnicklas/capybara/blob/master/lib/capybara/rspec.rb#L16
module Capybara
class << self
alias_method :old_reset_sessions!, :reset_sessions!
def reset_sessions!; end
end
@rvandervort
rvandervort / gist:1839038
Created February 15, 2012 21:13
Have vim run the current file through rspec
map <silent> <F3> :!clear && bundle exec rspec "%:p"<CR>