View blog__building-up-tests-via-context-and-let-in-ruby.rb
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
describe "#generate" do | |
let(:subject) { described_class.generate(name, player) } | |
let(:player) { Player.create(user_name: "Ronald McDonald", display_name: "Mac") } | |
let(:name) { "Ronnie the Rat" } | |
context "with defaults" do | |
it { expect(subject.name).to eq name } | |
end | |
context "with nil player" do |
View constructBTree.go
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
/** | |
* Definition for a binary tree node. | |
* type TreeNode struct { | |
* Val int | |
* Left *TreeNode | |
* Right *TreeNode | |
* } | |
*/ | |
type stateEntry struct { |
View btreePrune.go
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
/** | |
* Definition for a binary tree node. | |
* type TreeNode struct { | |
* Val int | |
* Left *TreeNode | |
* Right *TreeNode | |
* } | |
*/ | |
type state struct { |
View sumSubarray.go
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
const breakpoint = int(1e9+7) | |
func popStack(i int, arr []int, result int, stack []int) (int, []int) { | |
end := len(stack)-1 | |
prevMinIndex := stack[end] | |
stack[end] = 0 | |
stack = stack[:end] | |
nextPrevIndex := -1 | |
if len(stack) > 0 { |
View heap.go
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 "container/heap" | |
type CountPriorityQueueItem struct { | |
Value, Count, index int | |
} | |
type CountPriorityQueue struct { | |
items []*CountPriorityQueueItem | |
byValue map[int]*CountPriorityQueueItem | |
} |
View regexp.go
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 "fmt" | |
import "unicode/utf8" | |
type Regexp struct { | |
matchers []regexpMatch | |
} | |
type regexpMatch interface { | |
matches(in rune) bool | |
maxLength() int |
View calculator.go
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
package hello | |
import ( | |
"fmt" | |
"strconv" | |
) | |
type Expression struct { | |
op operator | |
a, b Expresser |
View graph-cycle.go
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
package hello | |
import "fmt" | |
type Graph struct { | |
nodeByID map[int]*GraphVertex | |
} | |
type GraphVertex struct { | |
ID int |
View Crawler.go
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
package main | |
import ( | |
"fmt" | |
) | |
type Fetcher interface { | |
// Fetch returns the body of URL and | |
// a slice of URLs found on that page. | |
Fetch(url string) (body string, urls []string, err error) |
View get-part-counts.sql
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
SELECT parts.name, COUNT(*) FROM part_server INNER JOIN parts on parts.id = part_server.part_id GROUP BY part_id; |
NewerOlder