This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// return all combinations of array elements for size n | |
// ex) combinations([1,2,3], 2) => [[1,2], [2,3], [1,3]] | |
// use backtracking & recursion | |
// iteration: for each element | |
// add element | |
// recurse with element | |
// remove element | |
// continue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} numCourses | |
* @param {number[][]} prerequisites | |
* @return {number[]} | |
*/ | |
var findOrder = function(numCourses, prerequisites) { | |
let adjList = {}; | |
let indegree = {}; | |
let topologicalOrder = []; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { PureComponent } from 'react' | |
import PropTypes from 'prop-types' | |
import Button from 'lib/shared-react-components/buttons/Button' | |
export default class Ellipsis extends PureComponent { | |
render () { | |
if (!this.props.visible) return null | |
return ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Registrar.Billing.Invoice do | |
import Ecto.Changeset | |
def changeset(%Invoice{} = invoice, attrs \\ %{}) do | |
invoice | |
|> cast(attrs, [ | |
:amount_due, | |
:due_date, | |
:scheduled_send_date, | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Registrar.Billing.Invoice do | |
import Ecto.Changeset | |
def changeset(%Invoice{} = invoice, attrs \\ %{}) do | |
invoice | |
|> cast(attrs, [ | |
:amount_due, | |
:due_date, | |
:scheduled_send_date | |
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Registrar.Billing.Invoice do | |
import Ecto.Changeset | |
def mark_closed_changeset(%Invoice{} = invoice, attrs \\ %{}) do | |
invoice | |
|> cast(attrs, [ | |
:closed_at | |
]) | |
|> validate_required([ | |
:closed_at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Registrar.Billing.Invoice do | |
import Ecto.Changeset | |
def mark_paid_changeset(%Invoice{} = invoice, attrs \\ %{}) do | |
invoice | |
|> cast(attrs, [ | |
:paid_at | |
]) | |
|> validate_required([ | |
:paid_at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex> attributes = %{amount_due: 3000, due_date: "2019-04-30", scheduled_send_date: "2019-04-25", | |
iex> closed_at: "2019-05-01"} | |
iex> changeset = Registrar.Billing.Invoice.changeset(%Invoice{}, attributes) | |
iex> #Ecto.Changeset< | |
action: nil, | |
changes: %{amount_due: 3000, due_date: ~D[2019-04-30], scheduled_send_date: ~D[2019-04-25]}, | |
errors: [], | |
data: #Registrar.Billing.Invoice<>, | |
valid?: true | |
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Registrar.Billing.Invoice do | |
# assume that we have an Ecto.Schema defined with all the fields this module needs to know about | |
import Ecto.Changeset | |
def changeset(%Invoice{} = invoice, attrs \\ %{}) do | |
invoice | |
|> cast(attrs, [ | |
:amount_due, | |
:due_date, | |
:scheduled_send_date |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InvoicesController < ApplicationController | |
def update | |
# The developer reasons that adding a timestamp to the params to | |
# leverage the existing code will do the trick | |
if params[:cancel] | |
invoice_params[:closed_at] = Time.current | |
end |
NewerOlder