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
@pdk
pdk / go1-err-example4.go
Created August 30, 2018 15:42
naive refactor of non-error checking in go
// GatherItems collects incoming items. If somehow we get more than n, an error is returned.
func GatherItems(n int) ([]string, error) {
checkLen := func() {
if len(items) > n {
return items, fmt.Errorf("more than %d items gathered: %d", n, len(items))
}
}
var items []string
@pdk
pdk / go1-err-example3.go
Created August 30, 2018 15:30
example of non-error checking in go 1
// GatherItems collects incoming items. If somehow we get more than n, an error is returned.
func GatherItems(n int) ([]string, error) {
var items []string
items = append(items, GetItemsFromSourceAlpha()...)
if len(items) > n {
return items, fmt.Errorf("more than %d items gathered: %d", n, len(items))
}
items = append(items, GetItemsFromSourceBeta()...)
@pdk
pdk / go1-err-example2.go
Created August 30, 2018 15:06
naive refactor of go 1 error handling
func CopyFile(src, dst string) error {
checkErr := func(err error) {
if err != nil {
return fmt.Errorf("copy %s %s: %v", src, dst, err)
}
}
r, err := os.Open(src)
checkErr(err)
defer r.Close()
@pdk
pdk / go1-err-example1.go
Last active August 30, 2018 15:33
example of go 1 error handling
func CopyFile(src, dst string) error {
r, err := os.Open(src)
if err != nil {
return fmt.Errorf("copy %s %s: %v", src, dst, err)
}
defer r.Close()
w, err = os.Create(dst)
if err != nil {
return fmt.Errorf("copy %s %s: %v", src, dst, err)
@pdk
pdk / CleanerException.java
Last active May 20, 2018 23:34
After cleaning up exception handling
public boolean isJobReady(DataSource dataSource, DateTime batchDate, Map<String, String> params)
throws BatchJobFailureException {
String alphaBatchId = params.get("batchId");
checkNotNull(alphaBatchId, "batchId is required to check status of a Blorp batch");
BlorpAlphaClient client = lookupClient(dataSource);
BatchResponse response;
try {
@pdk
pdk / isjobready.go
Last active May 3, 2018 23:28
translated java to go
func isJobReady(dataSource DataSource, batchDate time.Date, params map[string]string) (bool, error) {
alphaBatchId, ok := params["batchId"]
if !ok {
return false, fmt.Errorf("batchId value required in params")
}
client := blorp.LookupClient(dataSource)
response, err := client.status(alphaBatchId)
@pdk
pdk / exceptionfail.java
Last active May 3, 2018 20:23
exceptional failure
public boolean isJobReady(DataSource dataSource, DateTime batchDate, Map<String, String> params)
throws BatchJobFailureException {
String alphaBatchId = params.get("batchId");
checkNotNull(alphaBatchId, "batchId is required to check status of a Blorp batch");
boolean ready = false;
BlorpAlphaClient client = lookupClient(dataSource);

Keybase proof

I hereby claim:

  • I am pdk on github.
  • I am phlatphrog (https://keybase.io/phlatphrog) on keybase.
  • I have a public key ASDDmJb3H1XYC7i9yQE_BAEPZe7KkcTCCUIxzhROIWTt-Ao

To claim this, I am signing this object: