Skip to content

Instantly share code, notes, and snippets.

View pdk's full-sized avatar
🏠
Working from home

Patrick Kelly pdk

🏠
Working from home
View GitHub Profile

Donald Trump has been the worst president this country has ever had. And I don't say that hyperbolically. He is. But he is a consequential president. And he has brought this country in three short years to a place of weakness that is simply unimaginable if you were pondering where we are today from the day where Barack Obama left office. And there were a lot of us on that day who were deeply skeptical and very worried about what a Trump presidency would be. But this is a moment of unparalleled national humiliation, of weakness.

When you listen to the President, these are the musings of an imbecile. An idiot. And I don't use those words to name call. I use them because they are the precise words of the English language to describe his behavior. His comportment. His actions. We've never seen a level of incompetence, a level of ineptitude so staggering on a daily basis by anybody in the history of the country whose ever been charged with substantial responsibilities.

It's just astonishing that this man is pres

package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/lib/pq"
)
@pdk
pdk / daysInMonth.go
Created April 18, 2019 06:17
compute number of days in a month
func daysInMonth(y, m int) int {
dayZero := 0
return time.Date(y, time.Month(m+1), dayZero, 0, 0, 0, 0, time.UTC).Day()
}
@pdk
pdk / chaincheck.go
Created August 30, 2018 17:21
chaining error checks
func DoSomethingComplicated() error {
makro checkErrAlpha(..., err error) ... {
if err != nil && IsSpecificErrorType(err) {
return fmt.Errorf("specific error happened: %s", err)
}
}
makro checkErrBeta(..., err error) ... {
checkErrAlpha(..., err)
if err != nil {
@pdk
pdk / checkerrconsume.go
Last active August 30, 2018 16:55
checkErr consumer
func CopyFile(src, dst string) error {
makro checkErr(..., err error) ... {
if err != nil {
return fmt.Errorf("copy %s %s: %v", src, dst, err)
}
}
r := checkErr(os.Open(src))
defer r.Close()
@pdk
pdk / logfatal.go
Created August 30, 2018 16:46
log fatal example
func LogFatalIfErr(..., err error) ... {
if err != nil {
log.Fatalf("%s", err)
}
return ...
}
@pdk
pdk / consume.go
Created August 30, 2018 16:42
go consumer functions
func LogError(..., err error) (..., error) {
if err != nil {
log.Printf("%s", err)
}
return ..., err
}
@pdk
pdk / go1-err-example5.go
Created August 30, 2018 16:10
example of makro with parameter
func CopyFile(src, dst string) error {
makro checkErr(place string) {
if err != nil {
return fmt.Errorf("copy %s %s failed after %s: %v", src, dst, place, err)
}
}
r, err := os.Open(src)
checkErr("open")
defer r.Close()
@pdk
pdk / go1-err-example5.go
Created August 30, 2018 16:04
using makro for non-error values
// GatherItems collects incoming items. If somehow we get more than n, an error is returned.
func GatherItems(n int) ([]string, error) {
makro checkLen {
if len(items) > n {
return items, fmt.Errorf("more than %d items gathered: %d", n, len(items))
}
}
var items []string
@pdk
pdk / go1-err-example5.go
Last active August 30, 2018 16:02
example of new makro keyword
func CopyFile(src, dst string) error {
makro checkErr() {
if err != nil {
return fmt.Errorf("copy %s %s: %v", src, dst, err)
}
}
r, err := os.Open(src)
checkErr()
defer r.Close()