Skip to content

Instantly share code, notes, and snippets.

@Schwad
Schwad / euler2.rb
Created July 1, 2014 03:42 — forked from pjc/euler2.rb
# Create Fibonnaci Array
a = [1,2]
upto = 4_000_000
while a[-2] + a[-1] < upto
a << a[-2] + a[-1]
end
# Create sum of even Fibonnaci numbers
sum = 0
a.each { |x| sum+= x if x.even? }
def matching_brackets?(arg)
opener_symbols = ["{", "(", "["]
closer_symbols = ["}", ")", "]"]
openers = Hash.new(0)
closers = Hash.new(0)
openers['('] = arg.scan(/\(/).length
openers['['] = arg.scan(/\[/).length
openers['{'] = arg.scan(/\{/).length
closers[')'] = arg.scan(/\)/).length
closers[']'] = arg.scan(/\]/).length
@Schwad
Schwad / The Technical Interview Cheat Sheet.md
Created September 26, 2016 07:52 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
Error: Typescript found the following errors:
/Users/nickschwaderer/Desktop/getting_started/home-library/tmp/broccoli_type_script_compiler-input_base_path-ujnWpQpT.tmp/0/src/app/home-library.component.ts (2, 10): Module '"/Users/nickschwaderer/Desktop/getting_started/home-library/node_modules/@angular/core/index"' has no exported mng 'Http'.
at BroccoliTypeScriptCompiler._doIncrementalBuild (/Users/nickschwaderer/Desktop/getting_started/home-library/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:115:19)
at BroccoliTypeScriptCompiler.build (/Users/nickschwaderer/Desktop/getting_started/home-library/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:43:10)
at /Users/nickschwaderer/Desktop/getting_started/home-library/node_modules/angular-cli/node_modules/broccoli-caching-writer/index.js:149:21
at tryCatch (/Users/nickschwaderer/Desktop/getting_started/home-library/node_modules/angular-cli/node_modules/broccoli-caching-writer/node_modules/rsvp/dist/rsvp.js:538:12)
at
@Schwad
Schwad / ruby-versions-through-time.rb
Created April 7, 2017 08:44
Dates and versions of ruby, built as strings into an array.
[
["1995-12-21", "0.95"],
["1996-12-25", "1.0-961225"],
["1997-12-25", "1.0-971225"],
["1998-07-17", "1.1c0"],
["1998-07-24", "1.1c1"],
["1998-08-11", "1.1c2"],
["1998-08-27", "1.1c3"],
["1998-09-03", "1.1c4"],
["1998-09-08", "1.1c5"],
@Schwad
Schwad / nostalgic_case.rb
Created July 30, 2017 11:30
Nostalgic Case extension for String class in ruby.
class String
def nostalgic_case
upcase.chars.join(" ")
end
end
def index
@books = Book.all
end
#=> Rendering books/index.html.haml within layouts/application
def show
@book = Book.find(params[:id])
render 'unexpected'
end
#=> Rendering books/unexpected.html.haml within layouts/application
def extra_curricular_activity
@book = Book.find(params[:id])
render 'show'
@book.update_column(:title, 'Surprise Surprise')
end
#=> SQL (7.1ms) UPDATE "books" SET "title" = 'Surprise Surprise' WHERE "books"."id" = $1 [["id", 1]]
def double_render_error
@books = Book.all
render 'index'
render 'show'
end
#=> AbstractController::DoubleRenderError - Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action.