Skip to content

Instantly share code, notes, and snippets.

View rhcarvalho's full-sized avatar
🛡️

Rodolfo Carvalho rhcarvalho

🛡️
View GitHub Profile
@rhcarvalho
rhcarvalho / console.log
Last active February 23, 2016 09:46
go1.6-crash-experiments
✔ /tmp
10:31 $ go version
go version go1.6 linux/amd64
✔ /tmp
10:31 $ go run deadlock.go
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan receive]:
main.main()
/tmp/deadlock.go:12 +0x76
@rhcarvalho
rhcarvalho / bench_go1.4.2.txt
Last active October 6, 2015 11:22
How to check if a string is empty in Go
$ go test -v -bench . strcmp_test.go
testing: warning: no tests to run
PASS
BenchmarkEmptyString 2000000000 0.78 ns/op
BenchmarkLen0 2000000000 0.94 ns/op
ok command-line-arguments 3.617s
@rhcarvalho
rhcarvalho / buildstr_test.go
Last active September 8, 2015 09:17
Comparing how to build a long string
package buildstr_test
import (
"fmt"
"testing"
)
type EnvVar struct {
Name string
Value string

How do file and dir permissions look like depending on how we layout our Dockerfile?

RUN yum install first, COPY contrib next (#57):

$ ls -la /var/lib/pgsql/
total 48
drwxrwxrwx.  4 postgres postgres 4096 Aug 27 12:35 .
drwxr-xr-x. 12 root     root     4096 Aug 26 14:43 ..
drwxrwxrwx.  3 root     root     4096 Aug 26 14:43 .pki

Cannot reuse volume if container is run by a different user

$ VOLUME_DIR=`mktemp -d --tmpdir pg-data.XXXXX | tee >(xargs chmod a+rwx)`
$ echo $VOLUME_DIR 
/tmp/pg-data.26hxm

$ docker run --rm -u 12345 -v ${VOLUME_DIR}:/var/lib/pgsql/data -e POSTGRESQL_USER=u -e POSTGRESQL_PASSWORD=p -e POSTGRESQL_DATABASE=db openshift/postgresql-92-centos7

(...snip...)
@rhcarvalho
rhcarvalho / go test
Last active August 29, 2015 14:27
Compare sorting structs and pointer to structs
$ go test -bench . -benchmem
testing: warning: no tests to run
PASS
BenchmarkVal5 10000000 161 ns/op 32 B/op 1 allocs/op
BenchmarkPtr5 10000000 152 ns/op 32 B/op 1 allocs/op
BenchmarkValFromPtr5 1000000 2280 ns/op 1312 B/op 2 allocs/op
BenchmarkPtrFromVal5 3000000 334 ns/op 80 B/op 2 allocs/op
BenchmarkVal50 300000 4120 ns/op 32 B/op 1 allocs/op
BenchmarkPtr50 500000 3174 ns/op 32 B/op 1 allocs/op
BenchmarkValFromPtr50 100000 19084 ns/op 12320 B/op 2 allocs/op
@rhcarvalho
rhcarvalho / main.go
Last active August 29, 2015 14:27
comparing strings.Join to concatenating strings
package test
import "strings"
func stringjoin(key, namespace string) {
_ = strings.Join([]string{namespace, "build.", key}, "")
}
func concat(key, namespace string) {
_ = namespace + "build." + key
{
"id": "foobar",
"kind": "List",
"apiVersion": "v1beta3",
"name": "foobar",
"items": [
{
"apiVersion" : "v1beta3",
"kind": "Service",
"metadata" : {
@rhcarvalho
rhcarvalho / glue.py
Created February 8, 2015 17:01
Glueing together independent WSGI apps
import random
from django_demo.wsgi import application as django_app
from falcon_demo.hello import app as falcon_app
falcon_prefix = r'/falcon'
random_prefix = r'/random'
def random_app(environ, start_response):
return random.choice([falcon_app, django_app])(environ, start_response)
@rhcarvalho
rhcarvalho / README.md
Created March 3, 2014 15:57
Finding typos in Django

Usage

  1. Run collectwords.py with file paths as arguments to build a database of words.
  2. Run spellcheck.py to mark misspells.
  3. Use sqlite3 shell or anything else to output misspelled words to a file.
  4. Go through the file eliminating false positives.
  5. Search through the codebase and fix typo by typo :-)