Skip to content

Instantly share code, notes, and snippets.

@firelyu
firelyu / double_slice.go
Created February 10, 2017 14:15
Double the length of slice interface
// http://stackoverflow.com/questions/42151307/how-to-determine-the-element-type-of-slice-interface#answer-42151765
// Call reflect.MakeSlice(), reflect.SliceOf() and reflect.Copy
func doubleSlice(s interface{}) (interface{}, error) {
if reflect.TypeOf(s).Kind() != reflect.Slice {
err := errors.New("The interface is not a slice.")
return nil, err
}
v := reflect.ValueOf(s)
newLength := v.Len()
@firelyu
firelyu / replace.sh
Created September 7, 2017 01:29
Replace the first match
sed -i \
-e "s/^\(local\s\+all\s\+all\s\+\)peer/\1trust5/g" \
-e "0,/^host.*ident/s/^\(host\s\+all\s\+all\s\+\)[0-9:\.\/]\+\(\s\+\)ident/\10.0.0.0\/0\2md5/" \ # replace the first match
-e "s/^\(host.*ident\)/#\1/g" \
$PGDATA_ROOT/pgsql/9.6/pg_hba.conf
sed -i \
-e "s/^#listen_addresses = 'localhost'\(.*\)/listen_addresses = '*'\1/g" \
$PGDATA_ROOT/pgsql/9.6/postgresql.conf