Skip to content

Instantly share code, notes, and snippets.

View ttacon's full-sized avatar
🏡
Working from home

Trey Tacon ttacon

🏡
Working from home
View GitHub Profile
@ttacon
ttacon / diff-after-chore-commit.diff
Last active December 14, 2019 15:56
git-hunks-example-initial-git-diff
diff --git example.js example.js
index d5dd17d..1abd66a 100644
--- example.js
+++ example.js
@@ -13,7 +13,7 @@ function exampleCall({ nameObj } = {}) {
lastName: nameObj.lastName
};
- if (!nameObj.firstName && !nameObj.lastName) {
+ if (!nameObj || (!nameObj.firstName && !nameObj.lastName)) {
module.exports = function (context, callback) {
callback(null, [
{
title: "Type a URL or other text and press return.",
text: context.query.text
}
]);
}
module.exports = function (context, callback) {
callback(null, {
body: `<img src="https://api.qrserver.com/v1/create-qr-code/?size=100x100&qzone=1&data=${encodeURIComponent(context.query.text)}">`
});
}
@ttacon
ttacon / profile.sh
Last active November 30, 2016 16:00
profile.sh - Harness script for remotely profiling node process on AWS EC2 instances
#!/bin/bash
#
# See: https://mixmax.com/blog/determining-why-that-server-is-on-fire for details.
#
# Example usage: ./profile.sh $INSTANCE_ID [$DURATION] [$PID]
# Where:
# - $INSTANCE_ID is the EC2 identifier of the instance to profile the node
# processes on.
# - $DURATION is an optional duration specified in seconds (defaults to 30).
# - $PID is a specific process ID to profile, by default we profile all `node`
@ttacon
ttacon / perf.sh
Created November 30, 2016 15:55
perf.sh - Bash template for building flamegraphs of node process on remote instances
#!/bin/bash
#
# See: https://mixmax.com/blog/determining-why-that-server-is-on-fire for usage.
#
###########
echo "installing perf..."
sudo yum install -y perf
echo "fixing file perms..."
@ttacon
ttacon / mapvaluetypes.go
Created March 5, 2015 17:19
Go: map[string]interface{} vs map[string]string
package mem
import "testing"
// So if you're encoding small types (i.e. for JSON on the fly) there is a difference.
//
// maptypes$ go test -bench=. -benchtime=20s
// testing: warning: no tests to run
// PASS
// Benchmark_MapStringInterface 20000000 1407 ns/op 352 B/op 3 allocs/op
@ttacon
ttacon / bufferstringwriter_test.go
Last active August 29, 2015 14:12
Fastest way to make a *byte.Buffer from a string
package main
import (
"bytes"
"math/rand"
"testing"
)
// go test -v -bench=. -benchtime=10s
//
package main
import (
"fmt"
"reflect"
)
func main() {
a := 0
b := 1
@ttacon
ttacon / writestring_test.go
Created September 23, 2014 20:02
fmt.Fprint vs bytes.WriteString
package writestring
import (
"bytes"
"fmt"
"math/rand"
"testing"
)
// go test -bench=. -benchtime 20s
@ttacon
ttacon / switch_test.go
Last active August 29, 2015 14:06
Switch on type vs type assertion
package typeassertion
import (
"errors"
"testing"
)
// go test -bench=. -benchtime 20s
//
// Benchmark_SwitchType 100000000 483 ns/op