diff --git a/defensive-programming-reversim-2013.key b/defensive-programming-reversim-2013.key new file mode 100644 index 0000000..c2c79c6 Binary files /dev/null and b/defensive-programming-reversim-2013.key differ diff --git a/defensive_programming/1108864_o.gif b/defensive_programming/1108864_o.gif new file mode 100644 index 0000000..f6c2d60 Binary files /dev/null and b/defensive_programming/1108864_o.gif differ diff --git a/defensive_programming/always_safeguard_from_exception.rb b/defensive_programming/always_safeguard_from_exception.rb new file mode 100644 index 0000000..a3f81ce --- /dev/null +++ b/defensive_programming/always_safeguard_from_exception.rb @@ -0,0 +1,3 @@ +@current_user ||= User.find(session[:user_id]) rescue nil + +@current_user ||= User.find(session[:user_id]) if session[:user_id].present? \ No newline at end of file diff --git a/defensive_programming/always_validate_input.png b/defensive_programming/always_validate_input.png new file mode 100644 index 0000000..534459f Binary files /dev/null and b/defensive_programming/always_validate_input.png differ diff --git a/defensive_programming/always_validate_your_input.rb b/defensive_programming/always_validate_your_input.rb new file mode 100644 index 0000000..53290e6 --- /dev/null +++ b/defensive_programming/always_validate_your_input.rb @@ -0,0 +1,42 @@ +class Foo + def Bar(num, str) + if str.isA(String) + puts "Stringify Bar" + act_on_string(str) + elsif num.isA(Fixnum) + puts "Fixnumy Bar" + act_on_integer(num) + else + do_something_else(num, str) + puts "I don't know what this is" + end + end + + private + def act_on_string(str) + if str.isA(String) + # do some action + else + raise Exception + end + end + + def act_on_integer(str) + if str.isA(Number) + # do some action + else + raise Exception + end + end + + def do_something_else(num, str) + if str.isA(String) + # do some action + elsif num.isA(Fixnum) + # do something else + else + raise Exception + end + end + +end diff --git a/defensive_programming/be_aware.gif b/defensive_programming/be_aware.gif new file mode 100644 index 0000000..bae50cc Binary files /dev/null and b/defensive_programming/be_aware.gif differ diff --git a/defensive_programming/design-patterns.png b/defensive_programming/design-patterns.png new file mode 100644 index 0000000..66e85d7 Binary files /dev/null and b/defensive_programming/design-patterns.png differ diff --git a/defensive_programming/every_rule.jpeg b/defensive_programming/every_rule.jpeg new file mode 100644 index 0000000..55be435 Binary files /dev/null and b/defensive_programming/every_rule.jpeg differ diff --git a/defensive_programming/exceptions_alternative.png b/defensive_programming/exceptions_alternative.png new file mode 100644 index 0000000..5c09a81 Binary files /dev/null and b/defensive_programming/exceptions_alternative.png differ diff --git a/defensive_programming/exceptions_dangerous.png b/defensive_programming/exceptions_dangerous.png new file mode 100644 index 0000000..3ae7700 Binary files /dev/null and b/defensive_programming/exceptions_dangerous.png differ diff --git a/defensive_programming/friend.jpg b/defensive_programming/friend.jpg new file mode 100644 index 0000000..a790ead Binary files /dev/null and b/defensive_programming/friend.jpg differ diff --git a/defensive_programming/happy_coder.gif b/defensive_programming/happy_coder.gif new file mode 100644 index 0000000..95468de Binary files /dev/null and b/defensive_programming/happy_coder.gif differ diff --git a/defensive_programming/less.jpg b/defensive_programming/less.jpg new file mode 100644 index 0000000..699b295 Binary files /dev/null and b/defensive_programming/less.jpg differ diff --git a/defensive_programming/lock.png b/defensive_programming/lock.png new file mode 100644 index 0000000..583a6f8 Binary files /dev/null and b/defensive_programming/lock.png differ diff --git a/defensive_programming/naming.png b/defensive_programming/naming.png new file mode 100644 index 0000000..cf52930 Binary files /dev/null and b/defensive_programming/naming.png differ diff --git a/defensive_programming/naming.rb b/defensive_programming/naming.rb new file mode 100644 index 0000000..5842164 --- /dev/null +++ b/defensive_programming/naming.rb @@ -0,0 +1,6 @@ +class class_name + + def take_and_send(queue, msg) + end + +end \ No newline at end of file diff --git a/defensive_programming/patterns.jpeg b/defensive_programming/patterns.jpeg new file mode 100644 index 0000000..9093325 Binary files /dev/null and b/defensive_programming/patterns.jpeg differ diff --git a/defensive_programming/psychology.jpeg b/defensive_programming/psychology.jpeg new file mode 100644 index 0000000..d4d2073 Binary files /dev/null and b/defensive_programming/psychology.jpeg differ diff --git a/defensive_programming/remember-fear.png b/defensive_programming/remember-fear.png new file mode 100644 index 0000000..affe642 Binary files /dev/null and b/defensive_programming/remember-fear.png differ diff --git a/defensive_programming/ruby.jpeg b/defensive_programming/ruby.jpeg new file mode 100644 index 0000000..31799ed Binary files /dev/null and b/defensive_programming/ruby.jpeg differ diff --git a/defensive_programming/work_done.gif b/defensive_programming/work_done.gif new file mode 100644 index 0000000..e42e3ca Binary files /dev/null and b/defensive_programming/work_done.gif differ diff --git a/lock.png b/lock.png new file mode 100644 index 0000000..83a69eb Binary files /dev/null and b/lock.png differ