Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Patrick Kelly pdk

🏠
Working from home
View GitHub Profile
View trump-summary.md

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

View dbcount.go
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/lib/pq"
)
@pdk
pdk / daysInMonth.go
Created Apr 18, 2019
compute number of days in a month
View daysInMonth.go
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 Aug 30, 2018
chaining error checks
View chaincheck.go
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 Aug 30, 2018
checkErr consumer
View checkerrconsume.go
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 Aug 30, 2018
log fatal example
View logfatal.go
func LogFatalIfErr(..., err error) ... {
if err != nil {
log.Fatalf("%s", err)
}
return ...
}
@pdk
pdk / consume.go
Created Aug 30, 2018
go consumer functions
View consume.go
func LogError(..., err error) (..., error) {
if err != nil {
log.Printf("%s", err)
}
return ..., err
}
@pdk
pdk / go1-err-example5.go
Created Aug 30, 2018
example of makro with parameter
View go1-err-example5.go
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 Aug 30, 2018
using makro for non-error values
View go1-err-example5.go
// 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 Aug 30, 2018
example of new makro keyword
View go1-err-example5.go
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()