Skip to content

Instantly share code, notes, and snippets.

View oludouglas's full-sized avatar
🎯
Focus

Zuko oludouglas

🎯
Focus
View GitHub Profile
// 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
}
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)) {
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)
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 {
package interviews
import "testing"
type DoublyLinkedListNode struct {
value interface{}
prev *DoublyLinkedListNode
next *DoublyLinkedListNode
}
package interviews
import (
"reflect"
"testing"
)
type SinglyLinkedList struct {
val interface{}
nextnode *SinglyLinkedList
@oludouglas
oludouglas / deque.go
Last active September 15, 2020 12:50
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
package interviews
type Queue struct {
values []interface{}
}
func (q *Queue) IsEmpty() bool {
return len(q.values) == 0
}
type Stack struct {
store []interface{}
}
func (s *Stack) IsEmpty() bool {
return len(s.store) == 0
}
func (s *Stack) Size() int {
return len(s.store)
//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
}