コード例 #1
0
ファイル: session.go プロジェクト: elago/ela
func (sess *Session) getPath(key string) string {
	length := len(key) - 3
	dir1 := com.SubString(key, 0, 1)
	dir2 := com.SubString(key, 1, 2)
	file := com.SubString(key, 3, length)
	return filepath.Join(sess.path, dir1, dir2, file)
}
コード例 #2
0
ファイル: ccpp.go プロジェクト: kien8995/judger
func checkTimer(cmd *exec.Cmd, comp *Compile, id int) {
	for {
		// if building process hava exit normally, exit timer
		if BuildProcessHaveExit {
			log.Blueln("Building Process Exit Normally.")
			return
		}

		stn := time.Now()
		now := stn.UnixNano()
		// over 10s
		if now-BuildStartTime > 10*1000000000 {
			comp.buildOverTime = true
			log.Warnln("Building Out of Time, Terminated!")
			cmd.Process.Kill()

			systemTag := com.SubString(runtime.GOOS, 0, 5)
			if systemTag == "linux" {
				// ps -ef|grep cc1|grep 5.c|awk '{print $2}'|xargs kill -9
				cleanScript := fmt.Sprintf("ps -ef|grep cc1|grep %d.c|awk '{print $2}'|xargs kill -9", id)
				cleanCmd := exec.Command("sh",
					"-c",
					cleanScript,
				)
				err := cleanCmd.Run()
				if err != nil {
					log.Warnln("clean orphan failed")
				}
			}
			return
		}
	}
}
コード例 #3
0
ファイル: client.go プロジェクト: kien8995/judger
// start the session
func (this *JClient) Start(ip string, port int, password string) error {
	// not login, first time
	this.login = false

	// default # to get the real sep
	this.mark = "#"
	addr := fmt.Sprintf("%s:%d", ip, port)
	conn, err := net.Dial("tcp", addr)
	if err != nil {
		if conn != nil {
			conn.Close()
		}

		log.Warnln("connect judge server failed in port:", port)

		return err
	} else {
		this.conn = conn
		this.connected = true
		content, err := this.read()
		if err != nil {
			return err
		}

		// get seperater mark
		reg := regexp.MustCompile(`/[\d\D]+$`)
		if arr := reg.FindAllString(content, -1); len(arr) > 0 {
			this.mark = com.SubString(arr[0], 1, 1)
		}

		log.Blueln(content)
	}

	// login
	loginRequest := map[string]interface{}{
		"action":   "login",
		"password": password,
	}

	response, err := this.Request(loginRequest)
	if err != nil {
		return err
	}

	result, ok := response["result"].(bool)
	if !result || !ok {
		return errors.New("login failed.")
	}

	sid, ok := response["sid"].(string)
	if ok {
		this.sid = sid
	} else {
		this.sid = ""
	}

	this.login = true

	return err
}
コード例 #4
0
ファイル: xmlrpc.go プロジェクト: dw250100785/blog-1
// 新建文章
func newPost(params interface{}) string {
	username := params.([]interface{})[1].(string)
	password := params.([]interface{})[2].(string)
	result := login(username, password)

	if result {
		str := com.ReadFile("views/rpcxml/response_new_post.xml")

		title := params.([]interface{})[3].(map[string]interface{})["title"].(string)
		content := params.([]interface{})[3].(map[string]interface{})["description"].(string)
		keywords := ""
		categories := params.([]interface{})[3].(map[string]interface{})["categories"]
		if categories != nil {
			cata := categories.([]interface{})
			for _, v := range cata {
				keywords = fmt.Sprintf(keywords+"%s,", v.(string))
			}
			keywords = strings.TrimSuffix(keywords, ",")
		}

		id, err := AddArticle(title, content, keywords, com.SubString(content, 0, 100), username)

		if err == nil {
			return fmt.Sprintf(str, id)
		} else {
			str := com.ReadFile("views/rpcxml/response_failed.xml")
			return fmt.Sprintf(str, "文章发布失败! 注意标题不能重名")
		}

	} else {
		return com.ReadFile("views/rpcxml/response_login_failed.xml")
	}
}
コード例 #5
0
ファイル: session.go プロジェクト: kien8995/judger
// create session and add session into database
func (this *SessionTab) CreateSession() (string, error) {
	sid := com.Md5(com.CreateGUID())
	sid = com.SubString(sid, 0, 7)
	o := orm.NewOrm()
	var sess SessionTab

	sess.Session = sid
	sess.CreateTime = time.Now()

	_, err := o.Insert(&sess)

	return sid, err
}
コード例 #6
0
func TestGet(t *testing.T) {
	article, _ := services.ArticleById(35120)
	var content = html.UnescapeString(article.Content)
	if len(content) == 0 {
		return
	}
	reader := strings.NewReader(content)
	doc, _ := goquery.NewDocumentFromReader(reader)
	text := doc.Text()
	text = strings.Replace(text, " ", "", -1)
	text = strings.Replace(text, "\n", "", -1)
	text = strings.Replace(text, "\t", "", -1)
	subText := com.SubString(text, 0, 160)
	beego.Error(subText)
}
コード例 #7
0
ファイル: article.go プロジェクト: zld406504302/beego_study
func (a Article) ShortContent(subLength int) string {
	var content = html.UnescapeString(a.Content)
	if len(content) == 0 {
		return ""
	}
	reader := strings.NewReader(content)
	doc, _ := goquery.NewDocumentFromReader(reader)
	text := doc.Text()
	text = strings.Replace(text, " ", "", -1)
	text = strings.Replace(text, "\n", "", -1)
	text = strings.Replace(text, "#", "", -1)
	text = strings.Replace(text, "*", "", -1)
	subText := com.SubString(text, 0, 160)
	return subText
}