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|
@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>
@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: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 / 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 / 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 / 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 / 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 / 48.go
Created September 1, 2014 22:47
Project Euler : 48
package main
import "math"
import "fmt"
func ret(base float64) float64 {
if base == 1 {
return 1
} else {
return ret(base - 1) + math.Pow(base, base)
@rvandervort
rvandervort / 008.scala
Created January 26, 2015 00:10
008.scala
// Answer is supposed to be : 23514624000
object Eight {
val sampleData = "73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557668966489504452445231617318564030987111217223831136222989342338030813533627661428280644448664523874930358907296290491560440772390713810515859307960866701724271218839987979087922749219016997208880937766572733300105336788122023542180975125454059475224352584907711670556013604839586446706324415722155397536978179778461740649551492908625693219784686224828397224137565705605749026140797296865241453510047482166370484403199890008895243450658541227588666881164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004224219022671055626321111109370544217506941658960408071984038509624554443629812309878799272442849091888458015616609791913387549920052406368991256071760605886116467109405077541002256983155200055935729