Skip to content

Instantly share code, notes, and snippets.

@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 :-)
@rhcarvalho
rhcarvalho / sqlite_matchinfo.go
Created July 30, 2013 20:05
Retrieve `matchinfo` from FTS4 table on SQLite.
package main
import (
"bytes"
"database/sql"
"encoding/binary"
_ "github.com/mattn/go-sqlite3"
"log"
)
@rhcarvalho
rhcarvalho / gist:3236931
Created August 2, 2012 13:06
MongoDB convering indexes
$ mongo
MongoDB shell version: 2.0.4
connecting to: test
> doc = {_id: 42, name: "propedeutica", power: 0.92}
{ "_id" : 42, "name" : "propedeutica", "power" : 0.92 }
> db.foobar.insert(doc)
> db.foobar.ensureIndex({name: 1})
> db.foobar.find({name: "propedeutica"}).explain()
{
"cursor" : "BtreeCursor name_1",