Today I learned about a state machine compiler and code generator. It provides a small DSL that you can use to describe a state machine and the transitions between the states, which will be compiled to create a number of classes, and then all you have to do is provide the code for the actions. Here, actions, states, and transitions are defined terms that are described in the documentation for the smc tool.
Continue reading Using the State Machine Compiler with Python →
Earlier this year, when I was looking for work, I got the same recursive maze problem three interviews in a row. Recursion is cute and clever, but you generally want to use iterative solutions in production.
Continue reading The Recursive Maze Problem →
I had trouble posting to my Rails server from an Angular controller until I found this SO post. In /app/controllers/application_controller.rb
I added the following code.
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
after_action :set_csrf_cookie_for_ng
def set_csrf_cookie_for_ng
cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
end
protected
# In Rails 4.2 and above
def verified_request?
super || valid_authenticity_token?(session, request.headers['X-XSRF-TOKEN'])
end
end
Blog about math, programming, and data.