Skip to content

Instantly share code, notes, and snippets.

@kevbuchanan
kevbuchanan / vim.md
Last active August 3, 2017 08:44
Vim Cheatsheet

#Vim Cheatsheet (with NerdTree)

Navigation

up, down, left, right - k, j, h, l

go to line - : , line number, enter

Files

While in nerdtree

@kevbuchanan
kevbuchanan / insertion_sort.rb
Created October 16, 2013 17:10
Insertion Sort - Ruby
def insertion_sort(array)
0.upto(array.length - 1).each do |index|
element = array[index]
position = index
while element < array[position - 1] && position > 0
array[position] = array[position - 1]
array[position - 1] = element
position -= 1
end
end
class Chord
NOTE_POSITIONS = {
'C' => 0,
'B#' => 0,
'Db' => 1,
'C#' => 1,
'D' => 2,
'Eb' => 3,
'D#' => 3,
'Fb' => 4,
@kevbuchanan
kevbuchanan / rspec_jasmine.md
Last active July 27, 2016 14:53
A basic comparison of RSpec and Jasmine tests.

RSpec vs Jasmine

A very basic intro to Jasmine tests for those familiar with RSpec

let/before

  let(:post) { Post.new("My Title", "My Content") }
 var post
function Frame(rolls) {
if (rolls[0] == 10) {
this.rolls = [rolls[0]]
}
else {
this.rolls = rolls
}
}
Frame.prototype.rollScore = function() {
class Frame
attr_reader :rolls
def initialize(rolls)
@rolls = rolls.first == 10 ? [rolls.first] : rolls
end
def roll_score
@rolls.inject(:+)
end
@kevbuchanan
kevbuchanan / numbers_in_words.rb
Created August 27, 2013 19:29
Number in Words
VALUES = { 1000000000000 => 'trillion ', 1000000000 => 'billion ', 1000000 => 'million ', 1000 => 'thousand ', 1 => '' }
TENS = ['', '', 'twenty ', 'thirty ', 'forty ', 'fifty ', 'sixty ', 'seventy ', 'eighty ', 'ninety ']
ONES = ['', 'one ', 'two ', 'three ', 'four ', 'five ', 'six ', 'seven ', 'eight ', 'nine ']
TEENS = ['ten ', 'eleven ', 'twelve ', 'thirteen ', 'fourteen ', 'fifteen ', 'sixteen ', 'seventeen ', 'eighteen ', 'nineteen ']
def to_word(number)
power = 1000**(Math.log10(number).floor / 3)
to_write = number / power
number_as_word = get_hundreds(to_write) + get_tens(to_write) + get_ones(to_write) + VALUES[power]
number_as_word << to_word(number % power) unless number % power == 0
@kevbuchanan
kevbuchanan / zoo.js
Last active December 20, 2015 05:39 — forked from dbc-challenges/zoo.js
//------------------------------------------------------------------------------------------------------------------
// YOUR CODE: Create your Zoo "object literal" and Animal "constructor" and "prototypes" here.
//------------------------------------------------------------------------------------------------------------------
var Zoo = {
init : function(animals){
this.animals = animals
},
bipeds : function(){
return this.animals.filter(function(element){
return (element.legs == 2);
@kevbuchanan
kevbuchanan / binary_tree.rb
Last active December 19, 2015 20:58
Binary Search Tree
class Node
attr_accessor :value, :left, :right
def initialize(value, left = nil, right = nil)
@value, @left, @right = value, left, right
end
def delete(node)
if @left.value == node.value
@left = nil
class Vehicle
attr_reader :wheels, :color, :gas_mileage
attr_accessor :status, :speed
def initialize(args)
@wheels = args[:wheels]
@color = args[:color]
@status = :stopped
@speed = 0
@gas_mileage = [true, false].sample
end