Kitchen to Coding


A blog to document my progress from chef to software engineer

Setting up OmniAuth

Ok, going to set up Omniauth in my rails app today. OmniAuth is a tool that allows us to use authentication providers like Facebook, Google, etc. alongside traditional username and password. This allows for easy and secure access to the application for the user. So, let ‘s look at what it takes to set it up.


Game Logic with Timer & Recursion

Today I’m creating a game with my flash cards, and so I figured I’d go through the game logic for this post. The game is very straight forward: it’s essentially multiple choice with timed rounds, and the scoring takes into account the timer - for a correct answer, score += timer, incorrect answer score -= timer, and no answer score -= 10 (each round is 10 seconds). This way the player can get a higher score depending on how fast they are but can also be penalized more heavily if they rush their answer.


Sudoku Validator with JavaScript

Ok, this week I did a simple validator for Sudoku solutions. As you probably know, a valid Sudoku solution will have the numbers 1-9 on every row and column, and each 3 x 3 box will also have numbers 1-9. Checking is fairly simple enough, but the challenge is making the code concise, clean, and easy to go through. My solution isn’t the most elegant, but it’ll do for now.


RSpec Testing with Rails

I need to redo a project, so I figured this was a great opportunity to begin implementing tests. I decided to use RSpec and keep things very simple. First of all, I needed to add the rspec gem to the gemfile:

group :development, :test do
  gem 'rspec-rails', ">= 3.9.0"
end

Run bundle install and now RSpec is available to use. Next step is creating a spec directory with a models directory under that, and then we can create a file for a model tester. In this case, we will test the model Deck, which will have name and level attributes. So, creating the file deck_spec.rb - and this is where our tests will go for this ruby model: ```

./spec/models/deck_spec.rb


Implementing Serializer with Rails API

Been spending a bit more time lately on mapping out how to optimize the backend to my Sous Chef application, and I decided to implement a serializer to handle the initialization info for the user. Essentially, a serializer is a service class designated for the logic needed to assemble the API data that is requested. This way we can keep it out of the controller or model and follow the ever important Single Responsibility principal.