This file contains hidden or 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
// this is under the user.go file | |
func (h *Handler) loginUser(c echo.Context) error { | |
username := c.FormValue("username") | |
password := c.FormValue("password") | |
user := h.service.GetByUsername(username) | |
if user == nil || user.Password != password { | |
return echo.ErrUnauthorized | |
} |
This file contains hidden or 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" | |
) | |
// tested on plaground at https://play.golang.org/p/j3fBcTmAx37 | |
// Permutation calls f with each permutation of a. | |
func Permutation(a []rune, f func([]rune)) { |
This file contains hidden or 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 | |
// demonstrates how to create a simple http router compartible with std net/http lib | |
import ( | |
"net/http" | |
"strings" | |
) | |
type Handle func(http.ResponseWriter, *http.Request) |
This file contains hidden or 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 interviews | |
//Merge merges the sorted individual entries | |
func Merge(l, r []int) []int { | |
ret := make([]int, 0, (len(l) + len(r))) | |
for len(l) > 0 || len(r) > 0 { | |
if len(l) == 0 { | |
return append(ret, r...) | |
} | |
if len(r) == 0 { |
This file contains hidden or 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 interviews | |
import "testing" | |
type DoublyLinkedListNode struct { | |
value interface{} | |
prev *DoublyLinkedListNode | |
next *DoublyLinkedListNode | |
} |
This file contains hidden or 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 interviews | |
import ( | |
"reflect" | |
"testing" | |
) | |
type SinglyLinkedList struct { | |
val interface{} | |
nextnode *SinglyLinkedList |
This file contains hidden or 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 interviews | |
// combines power of both a queue and stack.. | |
// one can stack and pop items from both ends | |
type Deque struct { | |
values []interface{} | |
} | |
func (d *Deque) IsEmpty() bool { | |
return d.Size() == 0 |
This file contains hidden or 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 interviews | |
type Queue struct { | |
values []interface{} | |
} | |
func (q *Queue) IsEmpty() bool { | |
return len(q.values) == 0 | |
} |
This file contains hidden or 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
type Stack struct { | |
store []interface{} | |
} | |
func (s *Stack) IsEmpty() bool { | |
return len(s.store) == 0 | |
} | |
func (s *Stack) Size() int { | |
return len(s.store) |
This file contains hidden or 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
//fib(0) = 0, fib(1) = 1, fib(n) = fib(n-1) + fib(n-2) | |
func fib() func() int { | |
a, b := 0, 1 | |
return func() int { | |
defer func() { | |
a, b = b, a+b | |
}() | |
return a | |
} |
NewerOlder