I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!
\
I want to build a system which uses rules. These rules will change hourly (i.e. "this rule is effective from 2pm to 6pm"). The rules must support arbitrarily complex logic on just 2-3 pre-defined variables and result in a boolean:
item.a > 10 && item.b == 0 || item.category == FOOTWEAR
These rules will be executed hundreds of times per second so I can't afford the overhead of plain old eval
. I want to reload the current effective ruleset from the database hourly, precompile each rule's logic string and execute it via the quickest method possible. It might look something like this:
class Rule
#!/usr/bin/env ruby | |
def run | |
ARGF.each_slice($options[:columns]) do |values| | |
puts values.map(&:chomp).join($options[:separator]) | |
end | |
end | |
require "optparse" |
# speed up pluck | |
class ActiveRecord::Relation | |
class RailsDateTimeDecoder < PG::SimpleDecoder | |
def decode(string, tuple=nil, field=nil) | |
if Rails.version >= "4.2.0" | |
@caster ||= ActiveRecord::Type::DateTime.new | |
@caster.type_cast_from_database(string) | |
else |
module AROpts | |
module Helpers | |
def GT(val); AROpts::GT.new(val); end | |
def LT(val); AROpts::LT.new(val); end | |
def GTE(val); AROpts::GTE.new(val); end | |
def LTE(val); AROpts::LTE.new(val); end | |
end | |
GenericOp = Struct.new(:expression) |
Not all random values are created equal - for security-related code, you need a specific kind of random value.
A summary of this article, if you don't want to read the entire thing:
- Don't use
Math.random()
. There are extremely few cases whereMath.random()
is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case. - Don't use
crypto.getRandomBytes
directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable. - If you want to generate random tokens or API keys: Use
uuid
, specifically theuuid.v4()
method. Avoidnode-uuid
- it's not the same package, and doesn't produce reliably secure random values. - If you want to generate random numbers in a range: Use
random-number-csprng
.
You should seriously consider reading the entire article, though - it's
// This is an advanced example! It is not intended for use in application code. | |
// Libraries like Relay may make use of this technique to save some time on low-end mobile devices. | |
// Most components should just initiate async requests in componentDidMount. | |
class ExampleComponent extends React.Component { | |
_hasUnmounted = false; | |
state = { | |
externalData: null, | |
}; |
body { | |
margin: 0 auto; | |
width: 900px; | |
font-family: Trebuchet MS; | |
font-size: 16px; | |
line-height: 23px; | |
margin-top: 20px; | |
background: #fff8ec; | |
} |
I bundled these up into groups and wrote some thoughts about why I ask them!
If these helped you, I'd love to hear about it!! I'm on twitter @vcarl_ or send me an email [email protected]
https://blog.vcarl.com/interview-questions-onboarding-workplace/
- How long will it take to deploy my first change? To become productive? To understand the codebase?
- What kind of equipment will I be provided? Will the company pay/reimburse me if I want something specific?
server { | |
root /var/www/status.icu; | |
index index.html; | |
server_name status.icu; | |
location / { | |
try_files $uri $uri/ =500; | |
} | |
location ~ /200 { |