Skip to content

Instantly share code, notes, and snippets.

@niski84
niski84 / tenant.go
Created November 16, 2018 01:30
update tenant config
// UpdateTenantConfig
func InsertOrUpdateTenantConfig(instance *confighelper.Instance, dbcfgM *dbhelper.DbConfig, dbcfgTenant *dbhelper.DbConfig, dbcfgOlap *dbhelper.DbConfig) (err error) {
// 1. update the connection strings where id_ = tenant
// 2. if records updated, return. if no record updated, continue
// 3. run stored procedure to insert a new tenantconfig record
// logging for instance
log := instance.Logger
// create DB Dirs creates dirs for postgress tabelspace(s)
// replaces tokens contained in the configMap
func CreateDBDirs(dirs []string, configMap map[string]string) (err error) {
for _, dir := range dirs {
dir = TokenReplace(dir, configMap)
_, err := os.Stat(dir)
if err != nil {
@niski84
niski84 / execSQL.go
Created November 16, 2018 01:40
executes psql.exe with arguments
// ExecSQL executes psql.exe with arguments
// assumes cmdArgs either contains sqlfile or statement. example: ("-f", "install.sql" | "-c", <sql statement> )
// singleTransaction=true to run all commands as a single-transaction/rollback on error
func ExecSQL2(log *logrus.Logger, dbcfg *DbConfig, cmdArgs []string, packageRoot string, logSuffix string, singleTransaction bool) (output []string, err error) {
log.Println("Setting Environment Variables:")
os.Setenv("VERBOSITY", "verbose")
log.Println("VERBOSITY=" + os.Getenv("VERBOSITY"))
os.Setenv("PGPASSWORD", dbcfg.Password)
@niski84
niski84 / httpDownload.go
Created November 16, 2018 01:44
golang download file
// Download File
func DownloadFile(url string, headers map[string]string, jsonData string, downloadFilePath string) (downloadedFile string, err error) {
var jsonStr = []byte(jsonData)
log.Printf("DownloadFile(): %v\n%+v...", url, jsonStr)
req, err := http.NewRequest("GET", url, bytes.NewBuffer(jsonStr))
for k,v := range(headers) {
@niski84
niski84 / interfaceKeySearch.go
Created November 16, 2018 01:46
golang: Find key in interface (recursively) and return value as interface
// Find key in interface (recursively) and return value as interface
func Find(obj interface{}, key string) (interface{}, bool) {
//if the argument is not a map, ignore it
mobj, ok := obj.(map[string]interface{})
if !ok {
return nil, false
}
@niski84
niski84 / ExecInstallSqlbyLine.go
Created November 16, 2018 01:48
Execute Install.sql line by line using regex (match full path (linux/win))
// Execute Install.sql line by line
// (install.sql still needed for test cases)
func ExecInstallSqlbyLine(instance *confighelper.Instance, dbcfg *dbhelper.DbConfig, installSqlf string, packageRoot string, logDirRoot string, logSuffix string) (err error) {
// logging for instance
log := instance.Logger
// read install.sql
raw, err := ioutil.ReadFile(installSqlf)
@niski84
niski84 / raspberry pi backup
Created December 27, 2018 02:00
raspberry pi backup (osx)
#!/bin/bash
# script to backup Pi SD card
# 2017-06-05
# DSK='disk4' # manual set disk
OUTDIR=~/temp/Pi
# Find disk with Linux partition (works for Raspbian)
# Modified for PINN/NOOBS
export DSK=`diskutil list | grep "Linux" | sed 's/.*\(disk[0-9]\).*/\1/' | uniq`
if [ $DSK ]; then
echo $DSK
@niski84
niski84 / gist:22b9d191ae3a7953c23fa76ff36258d4
Created April 12, 2021 06:54
ffmpeg cut clip from middle of video - supports mp4
# start and beginning and only go to -t time
ffmpeg -y -i "song.mp4" -t 00:03:10.00 -c copy dystopiaStart.mp4
# start at -ss and go to the end
ffmpeg -y -ss 00:19:27.00 -i "song.mp4" -c copy dystopiaEnd.mp4
# concat both clips :: update: does not work for mp4 files
#ffmpeg -i "concat:dystopiaStart.mp4|dystopiaEnd.mp4" -c copy Ffmpeg_test2.mp4
# concat demuxer method without re-encode
@niski84
niski84 / gist:3c4f73211b61a8c78bf416da99766bd4
Created December 8, 2022 19:12
AllowAccessToOnlyFewSecrets
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowAccessToGogAndGogCloneSecrets",
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue"
],
"Resource": [
@niski84
niski84 / gist:a97b50a7e07ae731786d6a380898550f
Created December 8, 2022 19:24
AllowReadAccessToDynamoDBTables
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowReadAccessToDynamoDBTables",
"Effect": "Allow",
"Action": [
"dynamodb:BatchGetItem",
"dynamodb:GetRecords",
"dynamodb:GetShardIterator",