<commit_before>package main

import "github.com/go-martini/martini"
import "os/exec"
import "fmt"
import "strconv"
import "redis"
import "bytes"
import "flag"
import "math/rand"
import "time"
//import "net/http"


func Check(prog string) int {
	acceptedList := []string {"boltactiongame", "test"}
	for i:=0; i<len(acceptedList); i++ {
		if acceptedList[i] == prog {
			return 1
		}
	}
	return 0

}

//returns cmd struct of program
func Execute(prog string) *exec.Cmd {
	cmd := exec.Command("./"+prog)
	e := cmd.Start()
	if e!=nil {
		fmt.Println("Error runninng program ", e)
	}
	return cmd

}

func RedisPush(cmdI *exec.Cmd) int {
	spec := redis.DefaultSpec().Password("<PASSWORD>")
	client, e := redis.NewAsynchClientWithSpec(spec)
	if e!= nil {
		fmt.Println("error creating client for: ", e)
	}
	defer client.Quit()
	pidString := strconv.Itoa(cmdI.Process.Pid)
	var buf bytes.Buffer
	buf.Write([]byte(pidString))
	_,e = client.Rpush("server:pids", buf.Bytes())
	if e != nil {
		fmt.Println("error writing to list")
		return 0
	}
	return 1
}

func main() {
	rand.Seed(time.Now().UnixNano())
	var portArg = flag.Int("p",rand.Intn(65000-10000)+10000, "specifies port, default is random int between 10000-65000")
	var mapArg = flag.String("m", "default map  value", "description of map")
	flag.Parse()
	fmt.Println(strconv.Itoa(*portArg))
	fmt.Println(*mapArg)
	processL := make([]*exec.Cmd, 100)
	m := martini.Classic()
	m.Post("/launch/:name",  func(params martini.Params) string {
		e := Check(params["name"])
		if e==1 {
			cmdInfo := Execute(params["name"])
			for i:=0; i<len(processL); i++ {
				if processL[i]==nil {
					processL[i]=cmdInfo
					//suc := RedisPush(cmdInfo)
					RedisPush(cmdInfo)
					break
				}
			}
			//fmt.Println(processL)
			return "launching " + params["name"] + "with pid " + strconv.Itoa(cmdInfo.Process.Pid) 	
		} else {
			return "not accepted"
		}	
	})<commit_msg>queries postgres db, modified redis list to hash<commit_after>package main

import "github.com/go-martini/martini"
import "os/exec"
import "fmt"
import "strconv"
import "redis"
import "bytes"
import "flag"
import "math/rand"
import "time"
import "database/sql"
import _ "github.com/lib/pq"



func Check(prog string) int {
	acceptedList := []string {"boltactiongame", "test"}
	for i:=0; i<len(acceptedList); i++ {
		if acceptedList[i] == prog {
			return 1
		}
	}
	return 0

}

//returns cmd struct of program
func Execute(prog string) *exec.Cmd {
	cmd := exec.Command("./"+prog)
	e := cmd.Start()
	if e!=nil {
		fmt.Println("Error runninng program ", e)
	}
	return cmd

}

func RedisPush(cmdI *exec.Cmd) int {
	spec := redis.DefaultSpec().Password("<PASSWORD>")
	client, e := redis.NewSynchClientWithSpec(spec)
	if e!= nil {
		fmt.Println("error creating client for: ", e)
	}
	defer client.Quit()
	pidString := strconv.Itoa(cmdI.Process.Pid)
	var buf bytes.Buffer
	buf.Write([]byte(pidString))
	e = client.Hset("server:pids", "pid", buf.Bytes())
	if e != nil {
		fmt.Println("error writing to list")
		return 0
	}
	return 1
}

func PostGresQueryIDS() []int {
	db, err := sql.Open("postgres", "user=thoriumnet password=<PASSWORD> dbname=thoriumnet host=localhost")
	if err != nil {
		fmt.Println("err: ", err)
	}
	var game_id int
	game_ids := make([]int, 100)
	rows, err := db.Query("SELECT * FROM games;")
	if err != nil {
		fmt.Println("err2: ", err)
	}
	defer rows.Close()
	for rows.Next() {
		err := rows.Scan(&game_id)
		if err != nil {
			fmt.Println("err3: ", err)
		}
		for index,_ := range game_ids {
			if game_ids[index]==0 {
				game_ids[index]=game_id;
				break
			}
		}
	}
	return game_ids
}

func main() {
	rand.Seed(time.Now().UnixNano())
	var portArg = flag.Int("p",rand.Intn(65000-10000)+10000, "specifies port, default is random int between 10000-65000")
	var mapArg = flag.String("m", "default map  value", "description of map")
	flag.Parse()
	fmt.Println(strconv.Itoa(*portArg))
	fmt.Println(*mapArg)
	processL := make([]*exec.Cmd, 100)
	currentGames := PostGresQueryIDS()
	for _,value := range currentGames {
		if value != 0 {
			fmt.Println(value)
		}
	}
	m := martini.Classic()
	m.Post("/launch/:name",  func(params martini.Params) string {
		e := Check(params["name"])
		if e==1 {
			cmdInfo := Execute(params["name"])
			for i:=0; i<len(processL); i++ {
				if processL[i]==nil {
					processL[i]=cmdInfo
					//suc := RedisPush(cmdInfo)
					RedisPush(cmdInfo)
					break
				}
			}
			//fmt.Println(processL)
			return "launching " + params["name"] + "with pid " + strconv.Itoa(cmdInfo.Process.Pid) 	
		} else {
			return "not accepted"
		}	
	})
{'fraction_non_alphanumeric': 0.16994320664045434, 'fraction_numerical': 0.016819571865443424, 'mean_word_length': 3.8816631130063968, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4392330', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1746, 'n_words': 400}