Skip to content

Instantly share code, notes, and snippets.

View bswinnerton's full-sized avatar

Brooks Swinnerton bswinnerton

View GitHub Profile

Keybase proof

I hereby claim:

  • I am bswinnerton on github.
  • I am bswinnerton (https://keybase.io/bswinnerton) on keybase.
  • I have a public key whose fingerprint is B157 7B86 DC69 A3D1 AA57 3178 7274 3B7D E552 E25A

To claim this, I am signing this object:

Back End Web Development

Ruby

Data types

  1. String - denoted by single or double quotes
    e.g. "Brooks", 'brooks'

  2. Integer (aka Fixnum) - A whole number
    e.g. 1, 42

@bswinnerton
bswinnerton / git-commit-editor.vim
Created February 18, 2017 15:39 — forked from aroben/git-commit-editor.vim
Vim script to show git commit diff in vertical split while writing commit messages
" Put this in your .vimrc and whenever you `git commit` you'll see the diff of your commit next to your commit message.
" For the most accurate diffs, use `git config --global commit.verbose true`
" BufRead seems more appropriate here but for some reason the final `wincmd p` doesn't work if we do that.
autocmd VimEnter COMMIT_EDITMSG call OpenCommitMessageDiff()
function OpenCommitMessageDiff()
" Save the contents of the z register
let old_z = getreg("z")
let old_z_type = getregtype("z")
module SerializableAttributes
extend ActiveSupport::Concern
included do
class << self
attr_reader :serializable_column
end
before_save :update_serializable_column
class Fixnum
def sam_prime?
return false if self == 1
2.upto(Math.sqrt(self).to_i) { |n| return false if self % n == 0 }
return true
end
def refactored_prime?
2.upto(Math.sqrt(self).to_i) { |n| return false if self % n == 0 }
self == 1 ? false : true
@bswinnerton
bswinnerton / array.rb
Last active January 2, 2016 06:39
Matrix Challenge
class Array
def spiral
array = []
array << self.shift
array << self.transpose.reverse.spiral unless self.empty?
array.flatten
end
end
require 'rspec'
describe 'fib(n)' do
it 'calculates a fibonacci number based on index' do
expect(fib(6)).to eq(8)
end
end
def fib(n)
require 'rspec'
describe 'is_prime?' do
it 'calculates if a given number is prime' do
expect(is_prime?(5)).to eq(true)
end
end
describe 'prime(n)' do
it 'calculates the nth prime' do