Skip to content

Instantly share code, notes, and snippets.

View zailleh's full-sized avatar

Tim Caldwell zailleh

View GitHub Profile
def addition_function # declare this outside of the case and loop so we can call it repeatedly
puts "Which numbers would you like to add?"
n1 = gets.chomp.to_i
n2 = gets.chomp.to_i
answer = n1 + n2
puts "The sum is: #{answer}"
end
def show_menu
puts "Calculator"
@zailleh
zailleh / atom_snippits.md
Last active July 6, 2018 02:14
A brief cheat-sheet on adding custom snippets to Atom

Creating Snippets in Atom

Main Points

  1. Where to Add Snippets
  2. How to find out the language selector (scope)
  3. How to format a snippit

Where to Add Snippets

In Atom, you can add snippets by going to the Atom menu and going to Snippets...

@zailleh
zailleh / ruby_luhn_monkey_patch.rb
Created July 13, 2018 00:34
Monkey Patch for the Integer class in Ruby to add Luhn algorithm features.
class Integer
def luhn_sum
num = self.to_s.chars
sum = 0
num.reverse.each_with_index do |n,i|
n = n.to_i
n *= 2 if i % 2 == 1
@zailleh
zailleh / pre-commit
Last active October 11, 2019 02:55
Git pre-commit for Rubocop
#!/bin/sh
BRANCH=$(git branch | grep \* | cut -d ' ' -f2)
REF=$(git merge-base master $BRANCH)
DIFFS=$(git diff --diff-filter AM --name-only --relative $REF)
if [ "$DIFFS" != "" ]
then
echo "Checking for rubocop offenses..."
OFFENSES=$(rubocop $(echo "$DIFFS"))
if [ "$(echo $OFFENSES | grep 'no offenses')" == "" ]
then