Skip to content

Instantly share code, notes, and snippets.

@rajivm
rajivm / interview-cron.md
Last active November 11, 2021 22:41 — forked from kjhangiani/interview-cron.md
CRON to Dates API Endpoint

Cron2Date Parser

Summary

Create an API endpoint that accepts a json payload of cron strings, and returns a json payload of valid dates for these strings. Include any applicable tests for this endpoint using the testing platform of your choice.

Details

Frequency Object

A 'frequency' is an object that contains two attributes: name <string> and crons <Array> The crons property is a javascript array of strings (with cron format of "* * * * * *" representing "[sec] [min] [hr] [date] [month] [day of week]"). The following is an array of frequency objects.

Keybase proof

I hereby claim:

  • I am rajivm on github.
  • I am rajivm (https://keybase.io/rajivm) on keybase.
  • I have a public key ASCdbTPm7hgIW_PoN6YNYvrlZZg1cr44vDyzPHvoStlfUwo

To claim this, I am signing this object:

@rajivm
rajivm / soft_forbidden_attrs.rb
Created April 22, 2015 18:49
Rails 3 Forbidden Attributes with soft failures (i.e. in production, allow params anyways, but log the problem)
module ActiveModel
class ForbiddenAttributes < StandardError
end
module SoftForbiddenAttributesProtection
def sanitize_for_mass_assignment(*options)
new_attributes = options.first
if !new_attributes.respond_to?(:permitted?) || new_attributes.permitted?
super
elsif Rails.env.production?