text:
package server

import (
	"encoding/json"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"github.com/the4thamigo-uk/gameserver/pkg/domain"
	"io"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"
)

func testConfig() *Config {
	return &Config{
		Address: ":8080",
		Hangman: HangmanConfig{
			Words: []string{"word"},
			Turns: 6,
			dict:  domain.NewDictionary([]string{"word"}),
		},
	}
}

func (s *Server) serveHTTP(w http.ResponseWriter, r *http.Request) {
	s.s.Handler.ServeHTTP(w, r)
}

func unmarshalReader(r io.Reader, obj interface{}) ([]byte, error) {
	b, err := ioutil.ReadAll(r)
	if err != nil {
		return nil, err
	}
	return b, json.Unmarshal(b, obj)
}

func testServerRequest(s *Server, method string, url string, rsp interface{}) ([]byte, error) {
	w := httptest.NewRecorder()
	r, err := http.NewRequest(method, url, nil)
	if err != nil {
		return nil, err
	}
	s.serveHTTP(w, r)
	b, err := unmarshalReader(w.Result().Body, &rsp)
	if err != nil {
		return nil, err
	}
	return b, nil
}

type testHangmanResponse struct {
	Game  *domain.HangmanResult
	Links links `json:"_links"`
}

func TestServer_PlayLetterToWin(t *testing.T) {
	s := NewServer(testConfig())
	var r1 testHangmanResponse
	b1, err := testServerRequest(s, "POST", "/hangman/create", &r1)
	require.Nil(t, err)
	t.Log(string(b1))
	assert.Equal(t, 1, r1.Game.ID.Version)
	assert.Equal(t, "    ", r1.Game.Current)
	assert.Equal(t, hangmanDefaultTurns, r1.Game.Turns)
	assert.Equal(t, domain.Play, r1.Game.State)

	// play valid letter
	link2 := r1.Links[relHangmanPlayLetter]
	var r2 testHangmanResponse
	url2 := strings.Replace(link2.Href, "{letter}", "w", -1)
	b2, err := testServerRequest(s, link2.Method, url2, &r2)
	require.Nil(t, err)
	t.Log(string(b2))

	assert.Equal(t, r1.Game.ID.ID, r2.Game.ID.ID)
	assert.Equal(t, 2, r2.Game.ID.Version)
	assert.Equal(t, "W   ", r2.Game.Current)
	assert.Equal(t, hangmanDefaultTurns, r2.Game.Turns)
	assert.Equal(t, domain.Play, r2.Game.State)
	assert.True(t, *r2.Game.Success)

	link3 := r2.Links[relHangmanPlayLetter]
	var r3 testHangmanResponse
	url3 := strings.Replace(link3.Href, "{letter}", "x", -1)
	b3, err := testServerRequest(s, link3.Method, url3, &r3)
	require.Nil(t, err)
	t.Log(string(b3))

	assert.Equal(t, r1.Game.ID.ID, r3.Game.ID.ID)
	assert.Equal(t, 3, r3.Game.ID.Version)
	assert.Equal(t, "W   ", r3.Game.Current)
	assert.Equal(t, hangmanDefaultTurns-1, r3.Game.Turns)
	assert.Equal(t, domain.Play, r3.Game.State)
	assert.False(t, *r3.Game.Success)
}


text:
package models

import (
	"database/sql"
	"time"

	"github.com/gobuffalo/pop/v5"
	"github.com/gofrs/uuid"
	"github.com/pkg/errors"
	"github.com/supabase/gotrue/internal/storage"
)

type FactorState int

const (
	FactorStateUnverified FactorState = iota
	FactorStateVerified
)

func (factorState FactorState) String() string {
	switch factorState {
	case FactorStateUnverified:
		return "unverified"
	case FactorStateVerified:
		return "verified"
	}
	return ""
}

const TOTP = "totp"

type AuthenticationMethod int

const (
	OAuth AuthenticationMethod = iota
	PasswordGrant
	OTP
	TOTPSignIn
	SSOSAML
)

func (authMethod AuthenticationMethod) String() string {
	switch authMethod {
	case OAuth:
		return "oauth"
	case PasswordGrant:
		return "password"
	case OTP:
		return "otp"
	case TOTPSignIn:
		return "totp"
	case SSOSAML:
		return "sso/saml"
	}
	return ""
}

type Factor struct {
	ID           uuid.UUID   `json:"id" db:"id"`
	User         User        `json:"-" belongs_to:"user"`
	UserID       uuid.UUID   `json:"-" db:"user_id"`
	CreatedAt    time.Time   `json:"created_at" db:"created_at"`
	UpdatedAt    time.Time   `json:"updated_at" db:"updated_at"`
	Status       string      `json:"status" db:"status"`
	FriendlyName string      `json:"friendly_name,omitempty" db:"friendly_name"`
	Secret       string      `json:"-" db:"secret"`
	FactorType   string      `json:"factor_type" db:"factor_type"`
	Challenge    []Challenge `json:"-" has_many:"challenges"`
}

func (Factor) TableName() string {
	tableName := "mfa_factors"
	return tableName
}

func NewFactor(user *User, friendlyName string, factorType string, state FactorState, secret string) (*Factor, error) {
	id, err := uuid.NewV4()
	if err != nil {
		return nil, errors.Wrap(err, "Error generating unique id")
	}
	factor := &Factor{
		UserID:       user.ID,
		ID:           id,
		Status:       state.String(),
		FriendlyName: friendlyName,
		Secret:       secret,
		FactorType:   factorType,
	}
	return factor, nil
}

// FindFactorsByUser returns all factors belonging to a user ordered by timestamp
func FindFactorsByUser(tx *storage.Connection, user *User) ([]*Factor, error) {
	factors := []*Factor{}
	if err := tx.Q().Where("user_id = ?", user.ID).Order("created_at asc").All(&factors); err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return factors, nil
		}
		return nil, errors.Wrap(err, "Database error when finding MFA factors associated to user")
	}
	return factors, nil
}

func FindFactorByFactorID(tx *storage.Connection, factorID uuid.UUID) (*Factor, error) {
	factor, err := findFactor(tx, "id = ?", factorID)
	if err != nil {
		return nil, FactorNotFoundError{}
	}
	return factor, nil
}

func findFactor(tx *storage.Connection, query string, args ...interface{}) (*Factor, error) {
	obj := &Factor{}
	if err := tx.Eager().Q().Where(query, args...).First(obj); err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, FactorNotFoundError{}
		}
		return nil, errors.Wrap(err, "Database error finding factor")
	}

	return obj, nil
}

func DeleteUnverifiedFactors(tx *storage.Connection, user *User) error {
	factors := []*Factor{}
	if err := tx.Q().Where("user_id = ? AND status = ?", user.ID, FactorStateUnverified.String()).All(&factors); err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil
		}
		return errors.Wrap(err, "Database error when finding verified MFA factors")
	}
	if err := tx.Destroy(factors); err != nil {
		return err
	}

	return nil
}

func FindVerifiedFactorsByUser(tx *storage.Connection, user *User) ([]*Factor, error) {
	factors := []*Factor{}
	if err := tx.Q().Where("user_id = ? AND status = ?", user.ID, FactorStateVerified.String()).All(&factors); err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return factors, nil
		}
		return nil, errors.Wrap(err, "Database error when finding verified MFA factors")
	}
	return factors, nil
}

// UpdateFriendlyName changes the friendly name
func (f *Factor) UpdateFriendlyName(tx *storage.Connection, friendlyName string) error {
	f.FriendlyName = friendlyName
	return tx.UpdateOnly(f, "friendly_name", "updated_at")
}

// UpdateStatus modifies the factor status
func (f *Factor) UpdateStatus(tx *storage.Connection, state FactorState) error {
	f.Status = state.String()
	return tx.UpdateOnly(f, "status", "updated_at")
}

// UpdateFactorType modifies the factor type
func (f *Factor) UpdateFactorType(tx *storage.Connection, factorType string) error {
	f.FactorType = factorType
	return tx.UpdateOnly(f, "factor_type", "updated_at")
}

func (f *Factor) DowngradeSessionsToAAL1(tx *storage.Connection) error {
	sessions, err := FindSessionsByFactorID(tx, f.ID)
	if err != nil {
		return err
	}
	for _, session := range sessions {
		if err := tx.RawQuery("DELETE FROM "+(&pop.Model{Value: AMRClaim{}}).TableName()+" WHERE session_id = ? AND authentication_method = ?", session.ID, f.FactorType).Exec(); err != nil {
			return err
		}
	}
	return updateFactorAssociatedSessions(tx, f.UserID, f.ID, AAL1.String())
}

func DeleteFactorsByUserId(tx *storage.Connection, userId uuid.UUID) error {
	if err := tx.RawQuery("DELETE FROM "+(&pop.Model{Value: Factor{}}).TableName()+" WHERE user_id = ?", userId).Exec(); err != nil {
		return err
	}
	return nil
}

license: MIT

repository: Levet/gotrue

license_type: permissive

repo_name: Levet/gotrue

branch_name: refs/heads/master

gha_license_id: MIT

extension: go


text:
package main

import (
	"log"

	"github.com/slack-go/slack/slackevents"
)

// eventHandler handles interactive message response.
type eventHandler struct {
	lot             *Lot
	memberCollector *MemberCollector
}

func (h eventHandler) HandleEvent(eventPayload slackevents.EventsAPIEvent, selfUserID string) {
	switch eventPayload.Type {
	case slackevents.CallbackEvent:
		switch event := eventPayload.InnerEvent.Data.(type) {
		case *slackevents.AppMentionEvent:
			if event.User == selfUserID {
				return
			}
			members, err := h.memberCollector.Collect(event.Channel)
			if err != nil {
				log.Printf("[ERROR] Failed to collect member request: %s", err)
			}
			h.lot.DrawLots(event.Channel, members, "")
		}
	}
}

repository: k-tomoyasu/taskuji-slackbot-socketmode

repo_name: k-tomoyasu/taskuji-slackbot-socketmode

branch_name: refs/heads/main


text:
@inproceedings{shen2018bidirectional,
  title = {Bi-Directional Block Self-Attention for Fast and Memory-Efficient Sequence Modeling},
  author = {Tao Shen and Tianyi Zhou and Guodong Long and Jing Jiang and Chengqi Zhang},
  booktitle = {International Conference on Learning Representations},
  year = {2018},
  url = {https://openreview.net/forum?id=H1cWzoxA-}
}

url: https://raw.githubusercontent.com/Hugh-Shi/DL-NLP-Readings/924e4d189e5660c5b5d4854278f3df755ae2231d/Bibtex/Bi-Directional Block Self-Attention for Fast and Memory-Efficient Sequence Modeling.bib

repository: Hugh-Shi/DL-NLP-Readings

repo_name: Hugh-Shi/DL-NLP-Readings

extension: bib


text:
package model

// Choice to provide the collateral balance for the variation margin and the segregated independent amount, or the segregated independent amount only.
type CollateralBalance1Choice struct {

	// Collateral currently received (+)/delivered (-) in the base currency. This amount is after the haircut has been applied.
	TotalCollateral *ActiveCurrencyAndAmount `xml:"TtlColl"`

	// Provides details about the collateral held, in transit or that still needs to be agreed by both parties, for the variation margin and optionally the segregated independent amount.
	CollateralDetails *Collateral1 `xml:"CollDtls"`

	// Provides details about the collateral held, in transit or that still needs to be agreed by both parties, against the segregated independent amount only.
	SegregatedIndependentAmount *MarginCollateral1 `xml:"SgrtdIndpdntAmt"`
}

func (c *CollateralBalance1Choice) SetTotalCollateral(value, currency string) {
	c.TotalCollateral = NewActiveCurrencyAndAmount(value, currency)
}

func (c *CollateralBalance1Choice) AddCollateralDetails() *Collateral1 {
	c.CollateralDetails = new(Collateral1)
	return c.CollateralDetails
}

func (c *CollateralBalance1Choice) AddSegregatedIndependentAmount() *MarginCollateral1 {
	c.SegregatedIndependentAmount = new(MarginCollateral1)
	return c.SegregatedIndependentAmount
}

gha_language: Go


text:
/*
The KeyValue interface wrapper for LevelDB
*/

package leveldb

import (
	"bytes"
	"fmt"

	"github.com/bmeg/grip/kvi"
	"github.com/bmeg/grip/log"
	"github.com/syndtr/goleveldb/leveldb"
	"github.com/syndtr/goleveldb/leveldb/iterator"
	"github.com/syndtr/goleveldb/leveldb/opt"
	"github.com/syndtr/goleveldb/leveldb/util"
)

var loaded = kvi.AddKVDriver("level", NewKVInterface)

// NewKVInterface creates new LevelDB backed KVInterface at `path`
func NewKVInterface(path string, opts kvi.Options) (kvi.KVInterface, error) {
	log.Info("Starting LevelDB")

	var db *leveldb.DB
	var err error
	if opts.BulkLoad {
		o := opt.Options{}
		o.CompactionL0Trigger = 1 << 31
		db, err = leveldb.OpenFile(path, &o)
	} else {
		db, err = leveldb.OpenFile(path, nil)
	}
	if err != nil {
		return &LevelKV{}, err
	}
	return &LevelKV{db: db, opts: opts}, nil
}

// LevelKV implements the generic key value interface using the leveldb library
type LevelKV struct {
	db   *leveldb.DB
	opts kvi.Options
}

// Close database
func (l *LevelKV) Close() error {
	if l.opts.BulkLoad {
		l.db.CompactRange(util.Range{Start: nil, Limit: nil})
	}
	return l.db.Close()
}

// Get retrieves the value of key `id`
func (l *LevelKV) Get(id []byte) ([]byte, error) {
	return l.db.Get(id, nil)
}

// Delete removes a key/value from a kvstore
func (l *LevelKV) Delete(id []byte) error {
	return l.db.Delete(id, nil)
}

// DeletePrefix deletes all elements in kvstore that begin with prefix `id`
func (l *LevelKV) DeletePrefix(prefix []byte) error {
	deleteBlockSize := 10000
	for found := true; found; {
		found = false
		wb := make([][]byte, 0, deleteBlockSize)
		tx, _ := l.db.OpenTransaction()
		it := tx.NewIterator(nil, nil)
		for it.Seek(prefix); it.Valid() && bytes.HasPrefix(it.Key(), prefix) && len(wb) < deleteBlockSize-1; it.Next() {
			wb = append(wb, copyBytes(it.Key()))
		}
		it.Release()
		for _, i := range wb {
			tx.Delete(i, nil)
			found = true
		}
		tx.Commit()
	}
	return nil
}

// HasKey returns true if the key is exists in kvstore
func (l *LevelKV) HasKey(id []byte) bool {
	out, _ := l.db.Has(id, nil)
	return out
}

// Set value in kvstore
func (l *LevelKV) Set(id []byte, val []byte) error {
	return l.db.Put(id, val, nil)
}

// Update runs an alteration transaction of the kvstore
func (l *LevelKV) Update(u func(tx kvi.KVTransaction) error) error {
	tx, _ := l.db.OpenTransaction()
	ktx := levelTransaction{tx, l.db}
	defer tx.Commit()
	return u(ktx)
}

// BulkWrite is a copy of Update, with no special function yet...
func (l *LevelKV) BulkWrite(u func(tx kvi.KVBulkWrite) error) error {
	tx, _ := l.db.OpenTransaction()
	ktx := levelTransaction{tx, l.db}
	defer tx.Commit()
	return u(ktx)
}

type levelTransaction struct {
	tx *leveldb.Transaction
	db *leveldb.DB
}

func (ltx levelTransaction) Set(key, val []byte) error {
	return ltx.tx.Put(key, val, nil) //&opt.WriteOptions{NoWriteMerge: true})
}

// Delete removes key `id` from the kv store
func (ltx levelTransaction) Delete(id []byte) error {
	return ltx.tx.Delete(id, nil)
}

func (ltx levelTransaction) HasKey(id []byte) bool {
	out, _ := ltx.tx.Has(id, nil)
	return out
}

func (ltx levelTransaction) Get(id []byte) ([]byte, error) {
	o, err := ltx.tx.Get(id, nil)
	if o == nil || err != nil {
		return nil, err
	}
	return copyBytes(o), nil
}

// View run iterator on bolt keyvalue store
func (ltx levelTransaction) View(u func(it kvi.KVIterator) error) error {
	it := ltx.db.NewIterator(nil, nil)
	defer it.Release()
	lit := levelIterator{ltx.db, it, true, nil, nil}
	return u(&lit)
}

type levelIterator struct {
	db      *leveldb.DB
	it      iterator.Iterator
	forward bool
	key     []byte
	value   []byte
}

// Get retrieves the value of key `id`
func (lit *levelIterator) Get(id []byte) ([]byte, error) {
	return lit.db.Get(id, nil)
}

// Key returns the key the iterator is currently pointed at
func (lit *levelIterator) Key() []byte {
	return lit.key
}

// Value returns the valud of the iterator is currently pointed at
func (lit *levelIterator) Value() ([]byte, error) {
	return lit.value, nil
}

// Next move the iterator to the next key
func (lit *levelIterator) Next() error {
	var more bool
	if lit.forward {
		more = lit.it.Next()
	} else {
		more = lit.it.Prev()
	}
	if !more {
		lit.key = nil
		lit.value = nil
		return fmt.Errorf("Invalid")
	}
	lit.key = copyBytes(lit.it.Key())
	lit.value = copyBytes(lit.it.Value())
	return nil
}

func (lit *levelIterator) Seek(id []byte) error {
	lit.forward = true
	if lit.it.Seek(id) {
		lit.key = copyBytes(lit.it.Key())
		lit.value = copyBytes(lit.it.Value())
		return nil
	}
	return fmt.Errorf("Invalid")
}

func (lit *levelIterator) SeekReverse(id []byte) error {
	lit.forward = false
	if lit.it.Seek(id) {
		//Level iterator will land on the first value above the request
		//if we're there, move once to get below start request
		if bytes.Compare(id, lit.it.Key()) < 0 {
			lit.it.Prev()
		}
		lit.key = copyBytes(lit.it.Key())
		lit.value = copyBytes(lit.it.Value())
		return nil
	}
	return fmt.Errorf("Invalid")
}

// Valid returns true if iterator is still in valid location
func (lit *levelIterator) Valid() bool {
	if lit.key == nil || lit.value == nil {
		return false
	}
	return true
}

// View run iterator on bolt keyvalue store
func (l *LevelKV) View(u func(it kvi.KVIterator) error) error {
	it := l.db.NewIterator(nil, nil)
	defer it.Release()
	lit := levelIterator{l.db, it, true, nil, nil}
	return u(&lit)
}

func copyBytes(in []byte) []byte {
	out := make([]byte, len(in))
	copy(out, in)
	return out
}

repository: bmeg/grip

repo_name: bmeg/grip


text:
package storage

import (
	"context"
	"testing"

	"github.com/stretchr/testify/assert"
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"

	"github.com/indes/flowerss-bot/internal/model"
)

func GetTestDB(t *testing.T) *gorm.DB {
	db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"))
	if err != nil {
		t.Log(err)
		return nil
	}
	return db.Debug()
}

func TestUserStorageImpl(t *testing.T) {
	db := GetTestDB(t)
	s := NewUserStorageImpl(db)
	ctx := context.Background()
	s.Init(ctx)
	user := &model.User{
		ID: 123,
	}

	t.Run(
		"save user", func(t *testing.T) {
			err := s.CrateUser(ctx, user)
			assert.Nil(t, err)
		},
	)

	t.Run(
		"get user", func(t *testing.T) {
			got, err := s.GetUser(ctx, user.ID)
			assert.Nil(t, err)
			assert.NotNil(t, got)
			assert.Equal(t, user.ID, got.ID)
		},
	)
}

repository: indes/flowerss-bot

repo_name: indes/flowerss-bot


text:
@PhdThesis{dicostanzo07branch,
  author = 	 {Alexandre di Costanzo},
  title = 	 {{Branch-and-Bound with Peer-to-Peer for Large-Scale Grids}},
  school = 	 {University of Nice Sophia Antipolis},
  year = 	 {2007},
  month = 	 October
}

repository: thepieuvre/alex

repo_name: thepieuvre/alex

branch_name: refs/heads/gh-pages

gha_language: JavaScript


text:
# Put your BibTeX entries in this file.

@inproceedings{Ahn:2014:Flux,
	Author = {Dong H. Ahn and Jim Garlick and Mark Grondona and Don Lipari and Becky Springmeyer and Martin Schulz},
	Booktitle = {Proceedings of the 10th International Workshop on Scheduling and Resource Management for Parallel and Distributed Systems},
	Location = {Minneapolis, MN, USA},
	Month = {September},
	Title = {Flux: A Next-Generation Resource Management Framework for {Large} HPC Centers},
	Year = 2014}

@inproceedings{SLURM,
	Author = {Yoo, Andy B. and Jette, Morris A. and Grondona, Mark},
	Booktitle = {Proceedings of the 9th International Workshop on Job Scheduling Strategies for Parallel Processing (JSSPP)},
	Month = {June},
	Title = {{SLURM}: Simple Linux Utility for Resource Management},
	Year = 2003}

@misc{MOAB,
	Howpublished = {\url{http://www.adaptivecomputing.com/}},
	Note = {Retrieved April 03, 2017},
	Title = {The {Moab} Workload Manager},
	Year = 2017}

@misc{LSF,
	Howpublished = {\url{https://www.ibm.com/}},
	Note = {Retrieved April 03, 2017},
	Title = {{IBM} Spectrum {LSF}},
	Year = 2017}

@misc{PBSPro,
	Howpublished = {\url{https://github.com/PBSPro/pbspro}},
	Note = {Retrieved August 8, 2018},
	Organization = {Altair},
	Title = {{PBSPro: An HPC workload manager and job scheduler for desktops, clusters, and clouds}},
	Year = 2018}

@inproceedings{FluxSC18,
	Author = {Dong H. Ahn and Ned Bass and Albert Chu and Jim Garlick and Mark Grondona and Stephen Herbein and Joseph Koning and Tapasya Patki and Thomas R. W. Scogland and Becky Springmeyer},
	Booktitle = {Proceedings of the 13th Workshop on Workflows in Support of Large-Scale Science},
	Location = {Dallas, Texas},
	Series = {WORKS '18},
	Title = {Flux: Overcoming Scheduling Challenges for Exascale Workflows},
	Year = {2018}}

repository: curfman/ECP-ST-CAR-PUBLIC

repo_name: curfman/ECP-ST-CAR-PUBLIC


text:
package WTdown

import (
	"errors"
	"net/http"
	"os"
	"strconv"

	"github.com/jiajunhuang/gotasks/pool"

	"github.com/PuerkitoBio/goquery"
)

type NaverComic struct {
	TitleId string
	Cookies string

	epis        []string
	EpisodeName []string
}

const (
	NAVER_BASE_EPISODES_DATA_URL = "https://m.comic.naver.com/webtoon/list.nhn?sortOrder=ASC&titleId="
	NAVER_BASE_IMG_DATA_URL      = "https://m.comic.naver.com/webtoon/detail.nhn?titleId="
)

// error code, error
// 0:nil, 1:error, 2:warning, 3:info
func (nc *NaverComic) Download(start, stop, thread int, folder string) (int, error) {
	for episode := start; episode <= stop; episode++ {

		var dataURL string

		header := make(map[string]string, 2)
		header["User-Agent"] = USER_AGENT
		header["Cookie"] = nc.Cookies
		resp, err := requestWithCookieNBody(NAVER_BASE_IMG_DATA_URL+nc.TitleId+"&no="+nc.epis[episode], "GET", header, nil)
		if err != nil {
			return 1, err
		}

		doc, err := goquery.NewDocumentFromReader(resp)
		if err != nil {
			return 1, err
		}

		NumImg := doc.Find(".lazy").Length()
		if NumImg <= 0 {
			return 2, errors.New("Epi " + strconv.Itoa(episode+1) + " - Can't find Images")
		}
		err = os.MkdirAll(folder+"/"+strconv.Itoa(episode+1), os.ModePerm)
		if err != nil {
			return 1, errors.New("Epi " + strconv.Itoa(episode+1) + " - Can't make folder")
		}
		// errchan := make(chan error, NumImg)
		gopool := pool.NewGoPool(pool.WithMaxLimit(thread))

		doc.Find(".lazy").Each(func(j int, s *goquery.Selection) {
			dataURL, _ = s.Attr("data-src")
			func(dataURL string) {
				gopool.Submit(func() {
					downloadFileSingle(dataURL, folder+"/"+strconv.Itoa(episode+1)+"/"+strconv.Itoa(j+1)+".jpg")
				})
			}(dataURL)
			// go downloadFile(string(dataURL), folder+"/"+strconv.Itoa(episode)+"/"+strconv.Itoa(j+1)+".jpg", errchan)
		})

		gopool.Wait()
		// for i := 0; i < NumImg; i++ {
		// 	err = <-errchan
		// 	if err != nil {
		// 		return 1, err
		// 	}
		// }
		if err != makeHTML(episode+1, NumImg, nc.TitleId, folder+"/"+strconv.Itoa(episode+1)+"/"+strconv.Itoa(episode+1)+".html") {
			return 1, errors.New("Epi " + strconv.Itoa(episode+1) + " - Can't make HTML viewer")
		}
	}

	return 0, nil
}

func (nc *NaverComic) GetEpiData() error {
	nc.epis = make([]string, 0)
	nc.EpisodeName = make([]string, 0)

	err, totalPages := nc.getTotalPages()
	if err != nil {
		return err
	}
	intTotalPages, err := strconv.Atoi(totalPages)

	for pageNum := 1; pageNum <= intTotalPages; pageNum++ {
		nc.getDataFromEachPage(pageNum)
	}
	return nil
}

func (nc *NaverComic) getTotalPages() (error, string) {
	req, err := http.NewRequest("GET", NAVER_BASE_EPISODES_DATA_URL+nc.TitleId, nil)
	if err != nil {
		return err, ""
	}

	req.Header.Set("User-Agent", USER_AGENT)
	req.Header.Set("Cookie", nc.Cookies)
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return err, ""
	}
	defer resp.Body.Close()

	// resp, err := requestWithCookieNBody(BASE_EPISODES_DATA_URL, nil)

	doc, err := goquery.NewDocumentFromReader(resp.Body)
	if err != nil {
		return err, ""
	}
	totalPages := doc.Find(".total").Text()

	return nil, totalPages
}

// func (nc *NaverComic) getEpiTitleFromEachPage(page int, c chan error) {
// 	resp, err := http.Get(NAVER_BASE_EPISODES_DATA_URL + nc.TitleId + "&page=" + strconv.Itoa(page))
// 	if err != nil {
// 		c <- err
// 	}
// 	doc, err := goquery.NewDocumentFromReader(resp.Body)
// 	doc.Find(".item").Each(func(_ int, s *goquery.Selection) {
// 		_, state := s.Attr("data-title-id")
// 		if state {
// 			// strnumEpi, _ := s.Attr("data-no")
// 			// numEpi, err := strconv.Atoi(strnumEpi)
// 			// if err != nil {
// 			// 	log.Println("data-no is not a int")
// 			// }
// 			nc.epis = append(nc.epis,s.Find(".name").Text())
// 		}
// 	})
// 	c <- nil
// }

// func (nc *NaverComic) LoadTitlesURL() error {

// 	err, totalPages := nc.getTotalPages()
// 	if err != nil {
// 		return err
// 	}
// 	intTotalPages, err := strconv.Atoi(totalPages)
// 	nc.episodeName = make([]string, intTotalPages*30)

// 	c := make(chan error, intTotalPages)
// 	for pageNum := 1; pageNum <= intTotalPages; pageNum++ {
// 		nc.getDataNumFromEachPage(pageNum, c)
// 	}
// 	for pageNum := 1; pageNum <= intTotalPages; pageNum++ {
// 		errormessage := <-c
// 		if errormessage != nil {
// 			return errormessage
// 		}
// 	}
// 	return nil
// }

func (nc *NaverComic) getDataFromEachPage(page int) error {
	req, err := http.NewRequest("GET", NAVER_BASE_EPISODES_DATA_URL+nc.TitleId+"&page="+strconv.Itoa(page), nil)
	if err != nil {
		return err
	}

	req.Header.Set("User-Agent", USER_AGENT)
	req.Header.Set("Cookie", nc.Cookies)
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	doc, err := goquery.NewDocumentFromReader(resp.Body)
	if err != nil {
		return err
	}
	doc.Find(".item").Each(func(_ int, s *goquery.Selection) {
		_, state := s.Attr("data-title-id")
		if state {
			strnumEpi, _ := s.Attr("data-no")
			numEpi, _ := strconv.Atoi(strnumEpi)
			// if err != nil {
			// 	log.Println("data-no is not a int")
			// }
			nc.epis = append(nc.epis, strconv.Itoa(numEpi))
			nc.EpisodeName = append(nc.EpisodeName, s.Find(".name").Text())
		}
	})
	return err
}

// func (nc *NaverComic) LoadEpisodesTitle() []string {
// 	return nc.episodeName
// }

// req, err := http.NewRequest("GET", BASE_EPISODES_DATA_URL+nc.titleId, nil)
// if err != nil {
// 	return err, ""
// }

// client := &http.Client{}
// resp, err := client.Do(req)
// if err != nil {
// 	return err, ""
// }
// defer resp.Body.Close()


text:
// Copyright 2011 Alexander Orlov <alexander.orlov@loxal.net>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// RESTful commander service backend
package commander

import (
	"encoding/json"
	"flag"
	"fmt"
	"io"
	"loxal/test"
	"net/http"
	"strings"
	"time"

	"appengine"
	"appengine/datastore"
	"appengine/user"
)

type Cmd struct {
	Name, Call, Desc string
	Creator, User    string
	Created, Updated time.Time
}

func serveError(c appengine.Context, w http.ResponseWriter, err error) {
	w.WriteHeader(http.StatusInternalServerError)
	w.Header().Set("Content-Type", contentTypeText)
	io.WriteString(w, "Internal Server Error")
	c.Errorf("%s", err)
}

func serve404(w http.ResponseWriter) {
	w.WriteHeader(http.StatusNotFound)
	w.Header().Set("Content-Type", contentTypeText)
	io.WriteString(w, "Not Found")
}

func getUser(c appengine.Context) string {
	u := user.Current(c)
	if u == nil {
		return ""
	}

	return u.Email
}

func createCmd(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	if !cmdExists(c, r.FormValue("name")) && !cmdHasInvalidCharacters(r.FormValue("name")) {
		currentUser := getUser(c)
		cmd := &Cmd{
			Name:    r.FormValue("name"),
			Call:    r.FormValue("call"),
			Desc:    r.FormValue("desc"),
			Creator: currentUser,
			User:    currentUser,
			Created: time.Now(),
			Updated: time.Now(),
		}

		if _, err := datastore.Put(c, datastore.NewIncompleteKey(c, "Cmd", nil), cmd); err != nil {
			serveError(c, w, err)
			return
		}

		addCacheItem(r, cmd)
		return
	}

	w.WriteHeader(http.StatusBadRequest)
}

// Constraint Check
func cmdExists(c appengine.Context, name string) (ok bool) {
	count, _ := datastore.NewQuery("Cmd").Filter("Name =", strings.ToLower(name)).Filter("Creator =", getUser(c)).Count(c)

	if count > 0 {
		return true
	}
	return
}

// Constraint Check
func cmdHasInvalidCharacters(name string) (ok bool) {
	// command name shouldn't contain "#" because it's the HTML anchor marker and
	// might cause problems in a RESTful context (acts as a delimiter)
	if strings.Contains(name, "#") || strings.Contains(name, "%") {
		return true
	}
	return
}

func listCmds(r *http.Request) (cmds []*Cmd) {
	c := appengine.NewContext(r)
	datastore.NewQuery("Cmd").Filter("Creator =", getUser(c)).GetAll(c, &cmds)

	return cmds
}

func listCmdsAsJSON(w http.ResponseWriter, r *http.Request) {
	cmds := listCmds(r)

	w.Header().Set("Content-Type", contentTypeJSON)
	fmt.Fprint(w, `{"cmds": [`)
	lenCmds := len(cmds)
	for i := range cmds {
		cmdJSONed, _ := json.Marshal(cmds[i])
		fmt.Fprint(w, string(cmdJSONed))
		if lenCmds-1 != i {
			fmt.Fprintln(w, ",")
		}
	}
	fmt.Fprint(w, "]}")
}

// Returns the RESTful associated with a certain command
//func exec(cmd string) (call string) {
func getCmd(r *http.Request) (call, query string) {
	const sep = "+"
	rawQuery := strings.Split(r.URL.RawQuery, sep)
	getCacheItem(r, rawQuery[0])

	cmds := listCmds(r)

	for i := range cmds {
		if cmds[i].Name == rawQuery[0] {
			call = cmds[0].Call
			query = strings.Join(rawQuery[1:], sep)
			return call, query
		}
	}

	const defaultRestCall = "http://www.google.com/search?q="
	call = defaultRestCall
	query = strings.Join(rawQuery[:], sep)

	return call, query
}

func exec(w http.ResponseWriter, r *http.Request) {
	//test.TestFlag(w)
	fmt.Fprintf(w, test.ParseQuery("task --add='myNewTask bond'"))

	call, query := getCmd(r)
	http.Redirect(w, r, call+query, http.StatusFound)
}

func cmd(w http.ResponseWriter, r *http.Request) {
	var _ = flag.PrintDefaults // delete before submitting
	c := appengine.NewContext(r)
	var cmds []*Cmd
	cmdName := r.FormValue("name")
	_, err := datastore.NewQuery("Cmd").Filter("Name =", cmdName).GetAll(c, &cmds)
	fmt.Fprintln(w, err)
	fmt.Fprintln(w, r.FormValue("cmd"))
}

func cmdDelete(cmdName string, c appengine.Context) (ok bool) {
	q := datastore.NewQuery("Cmd").Filter("Name =", cmdName).Filter("Creator =", getUser(c)).KeysOnly()
	keys, _ := q.GetAll(c, nil)
	if err := datastore.Delete(c, keys[0]); err != nil {
		return
	}
	return true
}

func cmdDeletion(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	cmdDelete(r.FormValue("name"), c)
	http.Redirect(w, r, indexHandler, http.StatusFound)
}

func cmdUpdation(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	cmd := &Cmd{
		Name:    r.FormValue("edit-name"),
		Call:    r.FormValue("edit-call"),
		Desc:    r.FormValue("edit-desc"),
		User:    getUser(c),
		Updated: time.Now(),
	}

	if ok, err := cmdUpdate(cmd, c); err != nil {
		fmt.Fprintln(w, err, ok)
	}
}

func cmdUpdate(cmd *Cmd, c appengine.Context) (ok bool, err error) {
	q := datastore.NewQuery("Cmd").Filter("Name =", cmd.Name).Filter("Creator =", getUser(c)).KeysOnly()
	keys, _ := q.GetAll(c, nil)

	var cmdInDS Cmd
	datastore.Get(c, keys[0], &cmdInDS)
	cmd.Creator = cmdInDS.Creator
	cmd.Created = cmdInDS.Created

	if _, err := datastore.Put(c, keys[0], cmd); err != nil {
		return false, err
	}
	return true, nil
}

func authentication(r *http.Request) (usr, url string, isAdmin bool) {
	c := appengine.NewContext(r)
	u := user.Current(c)

	if u == nil {
		url, _ = user.LoginURL(c, indexHandler)
	} else {
		usr = u.Email
		isAdmin = user.IsAdmin(c)
		url, _ = user.LogoutURL(c, indexHandler)
	}

	return usr, url, isAdmin
}

func authenticate(w http.ResponseWriter, r *http.Request) {
	user, url, isAdmin := authentication(r)

	w.Header().Set("Content-Type", contentTypeJSON)
	fmt.Fprintf(w, `{"user": "%s", "isAdmin": "%t", "url": "%s"}`, user, isAdmin, url)
}

const indexHandler = "/"
const cmdUpdateHandler = "/cmd/update"
const cmdDeleteHandler = "/cmd/delete"
const cmdCreateHandler = "/cmd/create"
const cmdListHandler = "/cmd/list.json"
const reflectHandler = "/test/reflect"

const contentTypeJSON = "application/json; charset=utf-8"
const contentTypeText = "text/plain; charset=utf-8"

func init() {
	http.HandleFunc(reflectHandler, test.ReflectFunc)
	http.HandleFunc("/cmd/auth.json", authenticate)
	http.HandleFunc(cmdDeleteHandler, cmdDeletion)
	http.HandleFunc(cmdUpdateHandler, cmdUpdation)
	http.HandleFunc(cmdCreateHandler, createCmd)
	http.HandleFunc(cmdListHandler, listCmdsAsJSON)
	http.HandleFunc("/cmd", cmd)
	http.HandleFunc("/cmd/exec", exec)
}

repository: loxal/Sem

repo_name: loxal/Sem


text:
// Copyright 2019-present Open Networking Foundation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cluster

import (
	"context"
	"fmt"
	"time"

	"github.com/onosproject/onos-test/pkg/util/logging"
	"github.com/onosproject/onos-topo/api/device"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/util/intstr"
)

const (
	networkType          = "network"
	networkLabel         = "network"
	networkImage         = "opennetworking/mn-stratum:latest"
	networkDeviceType    = "Stratum"
	networkDeviceVersion = "1.0.0"
	stratumPortName      = "stratum"
	stratumPort          = 28000
)

// TopoType topology type
type TopoType int

const (
	// Single node topology
	Single TopoType = iota
	// Linear linear topology type
	Linear
	// Custom topology type
	Custom
)

func (d TopoType) String() string {
	return [...]string{"linear", "single"}[d]
}

func newNetwork(cluster *Cluster, name string) *Network {
	node := newNode(cluster)
	node.SetImage(networkImage)
	node.SetName(name)
	node.SetPort(0)
	return &Network{
		Node:          node,
		add:           true,
		deviceType:    networkDeviceType,
		deviceVersion: networkDeviceVersion,
	}
}

// Network is an implementation of the Network interface
type Network struct {
	// TODO: Network should be a Service with a Node per device
	*Node
	topoType      TopoType
	topo          string
	devices       int
	add           bool
	deviceType    string
	deviceVersion string
	deviceTimeout *time.Duration
}

// Devices returns a list of devices in the network
func (s *Network) Devices() ([]*Node, error) {
	services, err := s.kubeClient.CoreV1().Services(s.namespace).List(metav1.ListOptions{
		LabelSelector: "type=network,network=" + s.name,
	})
	if err != nil {
		return nil, err
	}

	devices := make([]*Node, len(services.Items))
	for i, service := range services.Items {
		node := newNode(s.cluster)
		node.SetName(service.Name)
		node.SetPort(stratumPort)
		devices[i] = node
	}
	return devices, nil
}

// AddDevices returns whether to add the devices to the topo service
func (s *Network) AddDevices() bool {
	return s.add
}

// SetAddDevices sets whether to add the devices to the topo service
func (s *Network) SetAddDevices(add bool) {
	s.add = add
}

// DeviceType returns the device type
func (s *Network) DeviceType() string {
	return s.deviceType
}

// SetDeviceType sets the device type
func (s *Network) SetDeviceType(deviceType string) {
	s.deviceType = deviceType
}

// DeviceVersion returns the device version
func (s *Network) DeviceVersion() string {
	return s.deviceVersion
}

// SetDeviceVersion sets the device version
func (s *Network) SetDeviceVersion(version string) {
	s.deviceVersion = version
}

// DeviceTimeout returns the device timeout
func (s *Network) DeviceTimeout() *time.Duration {
	return s.deviceTimeout
}

// SetDeviceTimeout sets the device timeout
func (s *Network) SetDeviceTimeout(timeout time.Duration) {
	s.deviceTimeout = &timeout
}

// SetSingle sets the network topology to single
func (s *Network) SetSingle() *Network {
	s.topoType = Single
	return s
}

// SetLinear sets the network to a linear topology
func (s *Network) SetLinear(devices int) *Network {
	s.topoType = Linear
	s.devices = devices
	return s
}

// SetTopo sets the network topology
func (s *Network) SetTopo(topo string, devices int) *Network {
	s.topoType = Custom
	s.topo = topo
	s.devices = devices
	return s
}

// Setup sets up the network
func (s *Network) Setup() error {
	step := logging.NewStep(s.namespace, fmt.Sprintf("Add network %s", s.Name()))
	step.Start()
	step.Logf("Creating %s Pod", s.Name())
	if err := s.createPod(); err != nil {
		step.Fail(err)
		return err
	}
	step.Logf("Creating %s Service", s.Name())
	if err := s.createService(); err != nil {
		step.Fail(err)
		return err
	}
	step.Logf("Waiting for %s to become ready", s.Name())
	if err := s.awaitReady(); err != nil {
		step.Fail(err)
		return err
	}
	if s.add {
		step.Logf("Adding %s devices to topo service", s.Name())
		if err := s.addDevices(); err != nil {
			step.Fail(err)
			return err
		}
	}
	step.Complete()
	return nil
}

// getLabels gets the network labels
func (s *Network) getLabels() map[string]string {
	labels := getLabels(networkType)
	labels[networkLabel] = s.name
	return labels
}

// getDeviceNames returns a list of device names
func (s *Network) getDeviceNames() []string {
	numDevices := s.getNumDevices()
	names := make([]string, numDevices)
	for i := 0; i < numDevices; i++ {
		names[i] = fmt.Sprintf("%.12s-%d", s.name, i)
	}
	return names
}

// getDevicePorts returns a map of device names and ports
func (s *Network) getDevicePorts() map[string]int32 {
	names := s.getDeviceNames()
	ports := make(map[string]int32)
	var port int32 = 50001
	for _, name := range names {
		ports[name] = port
		port++
	}
	return ports
}

// createPod creates a stratum Network pod
func (s *Network) createPod() error {
	var topoSpec string
	switch s.topoType {
	case Single:
		topoSpec = "single"
	case Linear:
		topoSpec = fmt.Sprintf("linear,%d", s.devices)
	case Custom:
		topoSpec = s.topo
	}

	devices := s.getDevicePorts()
	ports := make([]corev1.ContainerPort, 0, len(devices))
	for device, port := range s.getDevicePorts() {
		ports = append(ports, corev1.ContainerPort{
			Name:          device,
			ContainerPort: port,
		})
	}

	var isPrivileged = true
	pod := &corev1.Pod{
		ObjectMeta: metav1.ObjectMeta{
			Name:      s.name,
			Namespace: s.namespace,
			Labels:    s.getLabels(),
		},
		Spec: corev1.PodSpec{
			Containers: []corev1.Container{
				{
					Name:            "stratum-simulator",
					Image:           s.image,
					ImagePullPolicy: s.pullPolicy,
					Stdin:           true,
					Args:            []string{"--topo", topoSpec},
					Ports:           ports,
					ReadinessProbe: &corev1.Probe{
						Handler: corev1.Handler{
							TCPSocket: &corev1.TCPSocketAction{
								Port: intstr.FromInt(50001),
							},
						},
						PeriodSeconds:    1,
						FailureThreshold: 30,
					},
					LivenessProbe: &corev1.Probe{
						Handler: corev1.Handler{
							TCPSocket: &corev1.TCPSocketAction{
								Port: intstr.FromInt(50001),
							},
						},
						InitialDelaySeconds: 15,
						PeriodSeconds:       20,
					},
					SecurityContext: &corev1.SecurityContext{
						Privileged: &isPrivileged,
					},
				},
			},
		},
	}

	_, err := s.kubeClient.CoreV1().Pods(s.namespace).Create(pod)
	return err
}

// awaitReady waits for the given simulator to complete startup
func (s *Network) awaitReady() error {
	for {
		pod, err := s.kubeClient.CoreV1().Pods(s.namespace).Get(s.name, metav1.GetOptions{})
		if err != nil {
			return err
		} else if len(pod.Status.ContainerStatuses) > 0 && pod.Status.ContainerStatuses[0].Ready {
			return nil
		} else {
			time.Sleep(100 * time.Millisecond)
		}
	}
}

// getNumDevices returns the number of devices in the topology
func (s *Network) getNumDevices() int {
	switch s.topoType {
	case Single:
		return 1
	default:
		return s.devices
	}
}

// createService creates a Network service
func (s *Network) createService() error {
	for device, port := range s.getDevicePorts() {
		service := &corev1.Service{
			ObjectMeta: metav1.ObjectMeta{
				Name:      device,
				Namespace: s.namespace,
				Labels:    s.getLabels(),
			},
			Spec: corev1.ServiceSpec{
				Selector: s.getLabels(),
				Ports: []corev1.ServicePort{
					{
						Name:       stratumPortName,
						Port:       stratumPort,
						TargetPort: intstr.FromInt(int(port)),
					},
				},
			},
		}
		_, err := s.kubeClient.CoreV1().Services(s.namespace).Create(service)
		if err != nil {
			return err
		}
	}
	return nil
}

// addDevices adds the network's devices to the topo service
func (s *Network) addDevices() error {
	devices, err := s.Devices()
	if err != nil {
		return err
	}
	for _, device := range devices {
		if err := s.addDevice(device); err != nil {
			return err
		}
	}
	return nil
}

// addDevice adds the given device to the topo service
func (s *Network) addDevice(node *Node) error {
	tlsConfig, err := s.Credentials()
	if err != nil {
		return err
	}

	conn, err := grpc.Dial(s.cluster.Topo().Address(s.cluster.Topo().Ports()[0].Name), grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)))
	if err != nil {
		return err
	}
	defer conn.Close()

	ctx, cancel := context.WithTimeout(context.Background(), topoTimeout)
	defer cancel()
	client := device.NewDeviceServiceClient(conn)
	_, err = client.Add(ctx, &device.AddRequest{
		Device: &device.Device{
			ID:      device.ID(node.Name()),
			Address: node.Address(),
			Type:    device.Type(s.deviceType),
			Version: s.deviceVersion,
			Timeout: s.deviceTimeout,
			TLS: device.TlsConfig{
				Plain: true,
			},
		},
	})
	return err
}

// TearDown removes the network from the cluster
func (s *Network) TearDown() error {
	step := logging.NewStep(s.namespace, fmt.Sprintf("Remove network %s", s.Name()))

	var err error
	step.Logf("Removing %s devices", s.Name())
	if e := s.removeDevices(); e != nil {
		err = e
	}
	step.Logf("Deleting %s Pod", s.Name())
	if e := s.deletePod(); e != nil {
		err = e
	}
	step.Logf("Deleting %s Service", s.Name())
	if e := s.deleteService(); e != nil {
		err = e
	}
	step.Complete()
	return err
}

// removeDevices removes the devices from the topo service
func (s *Network) removeDevices() error {
	devices, err := s.Devices()
	if err != nil {
		return err
	}
	for _, device := range devices {
		if e := s.removeDevice(device); e != nil {
			err = e
		}
	}
	return err
}

// removeDevice removes the given device from the topo service
func (s *Network) removeDevice(node *Node) error {
	tlsConfig, err := s.Credentials()
	if err != nil {
		return err
	}

	conn, err := grpc.Dial(s.cluster.Topo().Address(s.cluster.Topo().Ports()[0].Name), grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)))
	if err != nil {
		return err
	}
	defer conn.Close()

	client := device.NewDeviceServiceClient(conn)

	ctx, cancel := context.WithTimeout(context.Background(), topoTimeout)
	response, err := client.Get(ctx, &device.GetRequest{
		ID: device.ID(node.Name()),
	})
	cancel()
	if err != nil {
		return err
	}

	ctx, cancel = context.WithTimeout(context.Background(), topoTimeout)
	_, err = client.Remove(ctx, &device.RemoveRequest{
		Device: response.Device,
	})
	cancel()
	return err
}

// deletePod deletes a network Pod by name
func (s *Network) deletePod() error {
	return s.kubeClient.CoreV1().Pods(s.namespace).Delete(s.name, &metav1.DeleteOptions{})
}

// deleteService deletes all network Service by name
func (s *Network) deleteService() error {
	label := "type=network,network=" + s.name
	serviceList, _ := s.kubeClient.CoreV1().Services(s.namespace).List(metav1.ListOptions{
		LabelSelector: label,
	})

	for _, svc := range serviceList.Items {
		err := s.kubeClient.CoreV1().Services(s.namespace).Delete(svc.Name, &metav1.DeleteOptions{})
		if err != nil {
			return err
		}
	}

	return nil
}


text:
package format

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestHTML(t *testing.T) {
	value, err := HTML("")("is this HTML?")

	require.Nil(t, err)
	require.Equal(t, "is this HTML?", value)
}

repository: benpate/rosetta

repo_name: benpate/rosetta


text:
require xorg-lib-common.inc
DEPENDS += "xproto virtual/libx11"
PR = "${INC_PR}.0"

SRC_URI[archive.md5sum] = "285e07976274572e1f1e68edee09b70a"
SRC_URI[archive.sha256sum] = "f6b3c00e1c0aab0729563115d3d798e14c9210b4e10fccb484efe1c5eae85657"

repository: trini/openembedded

repo_name: trini/openembedded

extension: bb


text:
/*
Finnhub API

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

API version: 1.0.0
*/

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

package finnhub

import (
	"encoding/json"
)

// StockSymbol struct for StockSymbol
type StockSymbol struct {
	// Symbol description
	Description *string `json:"description,omitempty"`
	// Display symbol name.
	DisplaySymbol *string `json:"displaySymbol,omitempty"`
	// Unique symbol used to identify this symbol used in <code>/stock/candle</code> endpoint.
	Symbol *string `json:"symbol,omitempty"`
	// Security type.
	Type *string `json:"type,omitempty"`
	// Primary exchange's MIC.
	Mic *string `json:"mic,omitempty"`
	// FIGI identifier.
	Figi *string `json:"figi,omitempty"`
	// Price's currency. This might be different from the reporting currency of fundamental data.
	Currency *string `json:"currency,omitempty"`
}

// NewStockSymbol instantiates a new StockSymbol object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewStockSymbol() *StockSymbol {
	this := StockSymbol{}
	return &this
}

// NewStockSymbolWithDefaults instantiates a new StockSymbol object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewStockSymbolWithDefaults() *StockSymbol {
	this := StockSymbol{}
	return &this
}

// GetDescription returns the Description field value if set, zero value otherwise.
func (o *StockSymbol) GetDescription() string {
	if o == nil || o.Description == nil {
		var ret string
		return ret
	}
	return *o.Description
}

// GetDescriptionOk returns a tuple with the Description field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *StockSymbol) GetDescriptionOk() (*string, bool) {
	if o == nil || o.Description == nil {
		return nil, false
	}
	return o.Description, true
}

// HasDescription returns a boolean if a field has been set.
func (o *StockSymbol) HasDescription() bool {
	if o != nil && o.Description != nil {
		return true
	}

	return false
}

// SetDescription gets a reference to the given string and assigns it to the Description field.
func (o *StockSymbol) SetDescription(v string) {
	o.Description = &v
}

// GetDisplaySymbol returns the DisplaySymbol field value if set, zero value otherwise.
func (o *StockSymbol) GetDisplaySymbol() string {
	if o == nil || o.DisplaySymbol == nil {
		var ret string
		return ret
	}
	return *o.DisplaySymbol
}

// GetDisplaySymbolOk returns a tuple with the DisplaySymbol field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *StockSymbol) GetDisplaySymbolOk() (*string, bool) {
	if o == nil || o.DisplaySymbol == nil {
		return nil, false
	}
	return o.DisplaySymbol, true
}

// HasDisplaySymbol returns a boolean if a field has been set.
func (o *StockSymbol) HasDisplaySymbol() bool {
	if o != nil && o.DisplaySymbol != nil {
		return true
	}

	return false
}

// SetDisplaySymbol gets a reference to the given string and assigns it to the DisplaySymbol field.
func (o *StockSymbol) SetDisplaySymbol(v string) {
	o.DisplaySymbol = &v
}

// GetSymbol returns the Symbol field value if set, zero value otherwise.
func (o *StockSymbol) GetSymbol() string {
	if o == nil || o.Symbol == nil {
		var ret string
		return ret
	}
	return *o.Symbol
}

// GetSymbolOk returns a tuple with the Symbol field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *StockSymbol) GetSymbolOk() (*string, bool) {
	if o == nil || o.Symbol == nil {
		return nil, false
	}
	return o.Symbol, true
}

// HasSymbol returns a boolean if a field has been set.
func (o *StockSymbol) HasSymbol() bool {
	if o != nil && o.Symbol != nil {
		return true
	}

	return false
}

// SetSymbol gets a reference to the given string and assigns it to the Symbol field.
func (o *StockSymbol) SetSymbol(v string) {
	o.Symbol = &v
}

// GetType returns the Type field value if set, zero value otherwise.
func (o *StockSymbol) GetType() string {
	if o == nil || o.Type == nil {
		var ret string
		return ret
	}
	return *o.Type
}

// GetTypeOk returns a tuple with the Type field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *StockSymbol) GetTypeOk() (*string, bool) {
	if o == nil || o.Type == nil {
		return nil, false
	}
	return o.Type, true
}

// HasType returns a boolean if a field has been set.
func (o *StockSymbol) HasType() bool {
	if o != nil && o.Type != nil {
		return true
	}

	return false
}

// SetType gets a reference to the given string and assigns it to the Type field.
func (o *StockSymbol) SetType(v string) {
	o.Type = &v
}

// GetMic returns the Mic field value if set, zero value otherwise.
func (o *StockSymbol) GetMic() string {
	if o == nil || o.Mic == nil {
		var ret string
		return ret
	}
	return *o.Mic
}

// GetMicOk returns a tuple with the Mic field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *StockSymbol) GetMicOk() (*string, bool) {
	if o == nil || o.Mic == nil {
		return nil, false
	}
	return o.Mic, true
}

// HasMic returns a boolean if a field has been set.
func (o *StockSymbol) HasMic() bool {
	if o != nil && o.Mic != nil {
		return true
	}

	return false
}

// SetMic gets a reference to the given string and assigns it to the Mic field.
func (o *StockSymbol) SetMic(v string) {
	o.Mic = &v
}

// GetFigi returns the Figi field value if set, zero value otherwise.
func (o *StockSymbol) GetFigi() string {
	if o == nil || o.Figi == nil {
		var ret string
		return ret
	}
	return *o.Figi
}

// GetFigiOk returns a tuple with the Figi field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *StockSymbol) GetFigiOk() (*string, bool) {
	if o == nil || o.Figi == nil {
		return nil, false
	}
	return o.Figi, true
}

// HasFigi returns a boolean if a field has been set.
func (o *StockSymbol) HasFigi() bool {
	if o != nil && o.Figi != nil {
		return true
	}

	return false
}

// SetFigi gets a reference to the given string and assigns it to the Figi field.
func (o *StockSymbol) SetFigi(v string) {
	o.Figi = &v
}

// GetCurrency returns the Currency field value if set, zero value otherwise.
func (o *StockSymbol) GetCurrency() string {
	if o == nil || o.Currency == nil {
		var ret string
		return ret
	}
	return *o.Currency
}

// GetCurrencyOk returns a tuple with the Currency field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *StockSymbol) GetCurrencyOk() (*string, bool) {
	if o == nil || o.Currency == nil {
		return nil, false
	}
	return o.Currency, true
}

// HasCurrency returns a boolean if a field has been set.
func (o *StockSymbol) HasCurrency() bool {
	if o != nil && o.Currency != nil {
		return true
	}

	return false
}

// SetCurrency gets a reference to the given string and assigns it to the Currency field.
func (o *StockSymbol) SetCurrency(v string) {
	o.Currency = &v
}

func (o StockSymbol) MarshalJSON() ([]byte, error) {
	toSerialize := map[string]interface{}{}
	if o.Description != nil {
		toSerialize["description"] = o.Description
	}
	if o.DisplaySymbol != nil {
		toSerialize["displaySymbol"] = o.DisplaySymbol
	}
	if o.Symbol != nil {
		toSerialize["symbol"] = o.Symbol
	}
	if o.Type != nil {
		toSerialize["type"] = o.Type
	}
	if o.Mic != nil {
		toSerialize["mic"] = o.Mic
	}
	if o.Figi != nil {
		toSerialize["figi"] = o.Figi
	}
	if o.Currency != nil {
		toSerialize["currency"] = o.Currency
	}
	return json.Marshal(toSerialize)
}

type NullableStockSymbol struct {
	value *StockSymbol
	isSet bool
}

func (v NullableStockSymbol) Get() *StockSymbol {
	return v.value
}

func (v *NullableStockSymbol) Set(val *StockSymbol) {
	v.value = val
	v.isSet = true
}

func (v NullableStockSymbol) IsSet() bool {
	return v.isSet
}

func (v *NullableStockSymbol) Unset() {
	v.value = nil
	v.isSet = false
}

func NewNullableStockSymbol(val *StockSymbol) *NullableStockSymbol {
	return &NullableStockSymbol{value: val, isSet: true}
}

func (v NullableStockSymbol) MarshalJSON() ([]byte, error) {
	return json.Marshal(v.value)
}

func (v *NullableStockSymbol) UnmarshalJSON(src []byte) error {
	v.isSet = true
	return json.Unmarshal(src, &v.value)
}

repository: bennythejudge/finnhub-go

repo_name: bennythejudge/finnhub-go


text:
package config

type TxConfig struct {
	Genesis       *Genesis                   `yaml:"Genesis"`
	Organizations []*Organization            `yaml:"Organizations"`
	Channels      map[string][]*Organization `yaml:"Channels"`
}
type Genesis struct {
	OrdererType string   `yaml:"OrdererType"`
	Addresses   []string `yaml:"Addresses"`
}
type Organization struct {
	Name   string `yaml:"Name"`
	MSPDir string `yaml:"MSPDir"`
}

repository: Gordon-H/mini-ledger

repo_name: Gordon-H/mini-ledger


text:
@article{Eldeeb2019b,
 author = {Eldeeb, Hisham and Abdel-Khalik, Ayman S and Hackl, Christoph M},
 date = {2018-04-05},
 doi = {10.1109/TIE.2018.2823684},
 journal = {IEEE Transactions on Industrial Electronics},
 month = {Jan},
 number = {1},
 pages = {141--151},
 title = {Dynamic Modeling of Dual Three-Phase IPMSM Drives With Different Neutral Configurations},
 volume = {66},
 year = {2019}
}


text:
@book{Mitchell,
  title = {{Machine Learning}},
  author = {Mitchell, T.M.},
  isbn = {9780071154673},
  lccn = {97007692},
  series = {McGraw-Hill International Editions},
  url = {https://books.google.com.br/books?id=EoYBngEACAAJ},
  year = {1997},
  publisher = {McGraw-Hill},
}

@book{Hastie_2009,
  author = {Trevor Hastie and Robert Tibshirani and Jerome Friedman},
  doi = {10.1007/978-0-387-84858-7},
  url = {http://dx.doi.org/10.1007/978-0-387-84858-7},
  year = {2009},
  publisher = {Springer New York},
  title = {{The Elements of Statistical Learning}},
}

@article{Kaelbling_1996,
    author = {Leslie Pack Kaelbling and Michael L. Littman and Andrew W. Moore},
    title = {Reinforcement learning: a survey},
    journal = {Journal of Artificial Intelligence Research},
    year = {1996},
    volume = {4},
    pages = {237--285}
}

@book{Mohri_2012,
 author = {Mohri, Mehryar and Rostamizadeh, Afshin and Talwalkar, Ameet},
 title = {Foundations of Machine Learning},
 year = {2012},
 isbn = {026201825X, 9780262018258},
 publisher = {The MIT Press},
}

@online{Udacity,
  author = {Udacity},
  title = {{Machine Learning Engineer Nanodegree} P4 Project Repository},
  year = 2016,
  url = {https://github.com/udacity/machine-learning/tree/master/projects/smartcab},
  urldate = {2016-07-03}
}

@book{richert2013building,
  title={Building Machine Learning Systems with Python},
  author={Richert, W.},
  isbn={9781782161417},
  url={https://books.google.com.br/books?id=C-yglCEcK0sC},
  year={2013},
  publisher={Packt Publishing}
}


text:
package main

import (
	"encoding/csv"
	"encoding/json"
	"io/ioutil"
	"log"
	"net/http"
	"os"
	"regexp"
	"strconv"
	"strings"
)

const (
	IdFile      = "Players.csv"
	OutputFile  = "Data.csv"
	Concurrency = 8
	UrlBase     = "https://www.playgwent.com/en/profile/"
	Debug       = false
)

type Player struct {
	Current  ProfileData
	Total    ProfileData
	Losses   int
	Draws    int
	MMR      int
	Rank     int
	Prestige int
	Level    int
	Id       string
}

type ProfileData struct {
	Overall  int       `json:"overall"`
	Factions []Faction `json:"factions"`
}

type Faction struct {
	Slug  string `json:"slug"`
	Count int    `json:"count"`
}

func NewPlayer(name string) Player {
	p := Player{}
	p.Id = name
	p.Rank = 30

	return p
}

func main() {
	log.SetOutput(os.Stderr)
	players := make([]Player, 0)
	sem := make(chan bool, Concurrency)

	//Regexs for parsing the pages
	privateRegex := regexp.MustCompile(`THIS PLAYER PROFILE IS PRIVATE`)
	prestigeRegex := regexp.MustCompile(`prestige--(?P<prestige>[0-9]*)"><strong>[\s]*(?P<level>[0-9]*)`)
	winsRegex := regexp.MustCompile(`var profileDataWins = (?P<json>.*?);`)
	lossesRegex := regexp.MustCompile(`Losses</td><td>(?P<matches>[0-9,]*) matches</td>`)
	drawsRegex := regexp.MustCompile(`Draws</td><td>(?P<matches>[0-9,]*) matches</td>`)
	currentRegex := regexp.MustCompile(`var profileDataCurrent = (?P<json>.*?);`)
	mmrRegex := regexp.MustCompile(`(?P<mmr>[0-9][0-9,]*) MMR`)
	rankRegex := regexp.MustCompile(`-details__rank"><strong>(?P<rank>[0-9]*)<`)

	//Load Ids from file
	f, err := os.Open(IdFile)
	checkError(err)
	defer f.Close()

	lines, err := csv.NewReader(f).ReadAll()
	checkError(err)
	for _, line := range lines {
		players = append(players, NewPlayer(line[0]))
	}

	//Do we need a mutex here? We're writing to distinct players..
	for i, _ := range players {
		sem <- true
		go func(p *Player) {
			defer func() { <-sem }()

			resp, err := http.Get(UrlBase + p.Id)
			checkError(err)
			defer resp.Body.Close()
			if resp.StatusCode == http.StatusOK {
				bodyBytes, err := ioutil.ReadAll(resp.Body)
				checkError(err)
				bodyString := string(bodyBytes)
				//Check for private
				matched := privateRegex.MatchString(bodyString)
				if matched {
					if Debug {
						log.Println(p.Id + "'s profile is private")
					}
				} else {
					//Get stats
					winsMatch := winsRegex.FindStringSubmatch(bodyString)
					err = json.Unmarshal([]byte(winsMatch[1]), &p.Total)
					checkError(err)
					currentMatch := currentRegex.FindStringSubmatch(bodyString)
					err = json.Unmarshal([]byte(currentMatch[1]), &p.Current)
					mmrMatch := mmrRegex.FindStringSubmatch(bodyString)
					prestigeMatch := prestigeRegex.FindStringSubmatch(bodyString)
					checkError(err)
					if len(mmrMatch) > 1 {
						p.MMR, err = strconv.Atoi(strings.ReplaceAll(mmrMatch[1], ",", ""))
						checkError(err)
					}
					lossesMatch := lossesRegex.FindStringSubmatch(bodyString)
					if len(mmrMatch) > 1 {
						p.Losses, err = strconv.Atoi(strings.ReplaceAll(lossesMatch[1], ",", ""))
						checkError(err)
					}
					drawsMatch := drawsRegex.FindStringSubmatch(bodyString)
					if len(mmrMatch) > 1 {
						p.Draws, err = strconv.Atoi(strings.ReplaceAll(drawsMatch[1], ",", ""))
						checkError(err)
					}
					rankMatch := rankRegex.FindStringSubmatch(bodyString)
					if len(mmrMatch) > 1 {
						p.Rank, err = strconv.Atoi(rankMatch[1])
						checkError(err)
					}
					if len(prestigeMatch) > 1 {
						p.Prestige, err = strconv.Atoi(prestigeMatch[1])
						checkError(err)
						p.Level, err = strconv.Atoi(prestigeMatch[2])
						checkError(err)
					}

					if Debug {
						log.Println(p.Id, ":", "Rank:", p.Rank, "All:", p.Total.Overall, "Wins:", p.Current.Overall, "Losses:", p.Losses, "Draws:", p.Draws, "MMR:", p.MMR)
					}
				}
			}

		}(&players[i])
	}

	for i := 0; i < cap(sem); i++ {
		sem <- true
	}

	file, err := os.Create(OutputFile)
	checkError(err)
	defer file.Close()

	writer := csv.NewWriter(file)
	defer writer.Flush()

	//There is more data than this but currently this is all that's relevant
	err = writer.Write([]string{"id", "rank", "total wins", "current wins", "current losses", "current draws", "MMR", "prestige", "level"})
	checkError(err)

	for _, p := range players {
		err := writer.Write([]string{p.Id, strconv.Itoa(p.Rank), strconv.Itoa(p.Total.Overall), strconv.Itoa(p.Current.Overall), strconv.Itoa(p.Losses), strconv.Itoa(p.Draws), strconv.Itoa(p.MMR), strconv.Itoa(p.Prestige), strconv.Itoa(p.Level)})
		checkError(err)
	}
}

func checkError(err error) {
	if err != nil {
		log.Fatal(err)
	}
}


text:
package SmallData

func search(hashTable *HashTable, k int) *HashTableData {
	index := hashCode(k)

	for _, _ = range hashTable.Table {
		if hashTable.Table[index].Key == k {
			return &hashTable.Table[index]
		}

		index++
		index %= maxTableSize
	}

	return nil
}

// Search searchs for the HashTableData entry of the value of the given int key
func (ht *HashTable) SearchForData(k int) *HashTableData {
	return search(ht, k)
}

// SearchString searchs for the string Value of the given string Key
func (ht *HashTable) SearchString(k string) string {
	dat := ht.SearchForData(hashString(k))

	if dat == nil {
		warningf("value for key: %s not found", k)
		return ""
	}

	return string(dat.Value)
}

// SearchString searchs for the string Value of the given string Hashed Key Int
func (ht *HashTable) SearchKey(k int) string {

	dat := search(ht, k)

	if dat == nil {
		warningf("value for key: %d not found", k)
		return ""
	}

	return string(dat.Value)
}

repository: wesleyParriott/SmallData

repo_name: wesleyParriott/SmallData


text:
import {createTemplate, findTextNode} from './create';
import {parse} from './parse';

let makeFront = () => {
    // find nodes
    var hanziText = document.getElementById('hz');
    var pinyinText = document.getElementById('py');

    // make sure to grab text nodes
    hanziText  = findTextNode(hanziText);
    pinyinText = findTextNode(pinyinText);
    hanziText  = (hanziText  === undefined) ? "" : hanziText.nodeValue;
    pinyinText = (pinyinText === undefined) ? "" : pinyinText.nodeValue;

    // parse words
    var words = parse(hanziText, pinyinText);

    // create template from the words
    createTemplate(words,'ch','hz','py');
}

export {makeFront};

repository: adrianderstroff/anki-chinese-template

repo_name: adrianderstroff/anki-chinese-template

gha_language: CSS

extension: js


text:
@INPROCEEDINGS{5380860,
author={di Costanzo, A. and Chao Jin and Varela, C.A. and Buyya, R.},
booktitle={e-Science, 2009. e-Science '09. Fifth IEEE International Conference on},
title={Enabling Computational Steering with an Asynchronous-Iterative Computation Framework},
year={2009},
month={Dec},
pages={255-262},
keywords={grid computing;Hadoop;Sloan Digital Sky Survey;asynchronous iterative MapReduce programming model;asynchronous-iterative computation framework;computational steering;dynamic interaction;heterogeneous sites;large-scale grid computing environment;multi-cluster grid;synchronisation;virtual machines;Chaos;Computational modeling;Computer science;Grid computing;High performance computing;Large-scale systems;Power engineering and energy;Resource management;Software engineering;Virtual machining},
doi={10.1109/e-Science.2009.43},}


text:
/*
 * satellite-js v1.1
 * (c) 2013 Shashwat Kandadai and UCSC
 * https://github.com/shashwatak/satellite-js
 * License: MIT
 */

function doppler_factor (my_location, position, velocity) {
    var current_range = Math.sqrt(
                        Math.pow(position[0] - my_location[0], 2) +
                        Math.pow(position[1] - my_location[1], 2) +
                        Math.pow(position[2] - my_location[2], 2));
    var next_pos   = [position[0] + velocity[0],
                      position[1] + velocity[1],
                      position[2] + velocity[2]];
    var next_range =  Math.sqrt(
                      Math.pow(next_pos[0] - my_location[0], 2) +
                      Math.pow(next_pos[1] - my_location[1], 2) +
                      Math.pow(next_pos[2] - my_location[2], 2));
    var range_rate =  next_range - current_range;

    function sign (value) {if (value >= 0) {return 1;} else {return -1;}};
    range_rate *= sign(range_rate);
    var c = 299792.458; // Speed of light in km/s
    var factor = (1 + range_rate/c);
    return factor;
}

satellite.doppler_factor = doppler_factor;

repository: anoved/satellite-js

repo_name: anoved/satellite-js


text:
@InProceedings{malioutov13,
  pdf = {http://jmlr.org/proceedings/papers/v28/malioutov13.pdf},
  number = {3},
  section = {cycle-3},
  title = {Exact Rule Learning via Boolean Compressed Sensing},
  author = {Malioutov, Dmitry and Varshney, Kush},
  pages = {765-773},
  abstract = {We propose an interpretable rule-based classification system based on ideas from Boolean compressed sensing. We represent the problem of learning individual conjunctive clauses or individual disjunctive clauses as a Boolean group testing problem, and apply a novel linear programming relaxation to find solutions. We derive results for exact rule recovery which parallel the conditions for exact recovery of sparse signals in the compressed sensing literature: although the general rule recovery problem is NP-hard, under some conditions on the Boolean `sensing' matrix, the rule can be recovered exactly. This is an exciting development in rule learning where most prior work focused on heuristic solutions. Furthermore we construct rule sets from these learned clauses using set covering and boosting.  We show competitive classification accuracy using the proposed approach.},
}

repository: mreid/papersite

repo_name: mreid/papersite

gha_language: TeX


text:
package department_event

import (
	"github.com/pkg/errors"
	"openscrm/app/models"
	gowx "openscrm/pkg/easywework"
)

// EventDeleteDepartment
// Description: 删除部门事件回调
// Detail: 删除DB, 更新tagGroup的可用部门
func EventDeleteDepartment(msg *gowx.RxMessage) error {
	if msg.MsgType != gowx.MessageTypeEvent ||
		msg.Event != gowx.EventTypeChangeContact ||
		msg.ChangeType != gowx.ChangeTypeDeleteParty {
		return errors.New("wrong handler for the callback event")
	}
	eventDeleteParty, ok := msg.EventDeleteParty()
	if !ok {
		return errors.New("msg.EventEditExternalContact failed")
	}
	err := models.DB.
		Where("ext_corp_id = ?", msg.ToUserID).
		Where("ext_id = ?", eventDeleteParty.GetID()).
		Delete(&models.Department{}).Error
	if err != nil {
		err = errors.WithStack(err)
		return err
	}

	//models.DB.Model(&models.TagGroup{}).Where("")
	return nil
}

repository: coder-layne/api-server

repo_name: coder-layne/api-server


text:
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
//     http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package main

import (
	"flag"
	"fmt"
	"io"
	"os"
	"os/exec"
	"runtime"
	"sync"

	"github.com/aws/amazon-vpc-cni-plugins/network/netns"
	"github.com/aws/amazon-vpc-cni-plugins/version"
)

// netnsexec netnsNameOrPath cmd [arg]...
func main() {
	// Parse arguments.
	var printVersion bool
	flag.BoolVar(&printVersion, version.Command, false, "prints version and exits")
	flag.Parse()

	if printVersion {
		versionInfo, _ := version.String()
		fmt.Println(versionInfo)
		os.Exit(0)
	}

	args := flag.Args()
	if len(args) < 2 {
		fmt.Println("netnsexec netnsNameOrPath cmd [arg]...")
		os.Exit(0)
	}

	nsName := args[0]
	cmdName := args[1]

	// Ensure that goroutines do not change OS threads during namespace operations.
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ns, err := netns.GetNetNS(nsName)
	if err != nil {
		fmt.Printf("Failed to find netns %s: %v.\n", nsName, err)
		os.Exit(1)
	}

	err = ns.Run(func() error {
		cmd := exec.Command(cmdName, args[2:]...)

		var errStdout, errStderr error
		cmdStdout, _ := cmd.StdoutPipe()
		cmdStderr, _ := cmd.StderrPipe()

		err := cmd.Start()
		if err != nil {
			return fmt.Errorf("cmd.Start() failed: %v", err)
		}

		// Redirect cmd's stdout and stderr.
		var wg sync.WaitGroup
		wg.Add(1)
		go func() {
			_, errStdout = io.Copy(os.Stdout, cmdStdout)
			wg.Done()
		}()

		_, errStderr = io.Copy(os.Stderr, cmdStderr)
		wg.Wait()

		err = cmd.Wait()

		if err != nil {
			return fmt.Errorf("cmd.Wait() failed: %v", err)
		}

		if errStdout != nil || errStderr != nil {
			return fmt.Errorf("failed to capture stdout: %v or stderr: %v", errStdout, errStderr)
		}

		return err
	})

	if err != nil {
		fmt.Printf("Failed to run command %s: %v.\n", cmdName, err)
		os.Exit(1)
	}
}

repository: aws/amazon-vpc-cni-plugins

repo_name: aws/amazon-vpc-cni-plugins


text:
package mvcc

import (
	"github.com/apple/foundationdb/bindings/go/src/fdb"

	"github.com/shestakovda/fdbx/v2/db"
)

func getOpts(args []Option) (o options) {
	// Объем выборки "грязных" записей в процессе вакуума
	o.vpack = 0

	// Объем выборки "грязных" записей в процессе работы
	o.spack = 0

	// Максимальное кол-во байт, которое могут занимать строки, сохраняемые в рамках одной физической транзакции
	o.rowmem = 9000000

	// Максимальное кол-во байт, которое может занимать "чистое" значение ключа, с запасом на накладные расходы
	o.rowsize = 90000

	for i := range args {
		args[i](&o)
	}

	return
}

type options struct {
	lock     bool
	reverse  bool
	physical bool
	limit    int
	rowmem   int
	rowsize  int
	vpack    uint64
	spack    uint64
	from     fdb.Key
	last     fdb.Key
	onInsert RowHandler
	onUpdate RowHandler
	onDelete RowHandler
	onVacuum RowHandler
	onLock   RowHandler
	writer   db.Writer
}

func Lock() Option                    { return func(o *options) { o.lock = true } }
func Last(k fdb.Key) Option           { return func(o *options) { o.last = k } }
func From(k fdb.Key) Option           { return func(o *options) { o.from = k } }
func Limit(l int) Option              { return func(o *options) { o.limit = l } }
func Writer(w db.Writer) Option       { return func(o *options) { o.writer = w } }
func Reverse() Option                 { return func(o *options) { o.reverse = true } }
func Physical() Option                { return func(o *options) { o.physical = true } }
func OnInsert(hdl RowHandler) Option  { return func(o *options) { o.onInsert = hdl } }
func OnUpdate(hdl RowHandler) Option  { return func(o *options) { o.onUpdate = hdl } }
func OnDelete(hdl RowHandler) Option  { return func(o *options) { o.onDelete = hdl } }
func OnVacuum(hdl RowHandler) Option  { return func(o *options) { o.onVacuum = hdl } }
func Exclusive(hdl RowHandler) Option { return func(o *options) { o.lock = true; o.onLock = hdl } }
func SelectPack(size int) Option      { return func(o *options) { o.spack = uint64(size) } }
func MaxRowMem(size int) Option       { return func(o *options) { o.rowmem = size } }
func MaxRowSize(size int) Option      { return func(o *options) { o.rowsize = size } }

repository: kanosaki/fdbx

repo_name: kanosaki/fdbx


text:
package data

import (
	"github.com/dstpierre/gosaas/model"
)

// DB is a database agnostic abstraction that contains a reference to
// the database connection.
//
// At this moment MongoDB and an in-memory data provider are supported.
type DB struct {
	// DatabaseName is the name of the database used.
	DatabaseName string
	// Connection is the reference to the database connection.
	Connection *model.Connection
	// CopySession indicates if the database connection should be copy of each requests (used for MongoDB).
	CopySession bool

	// Users contains the data access functions related to account, user and billing.
	Users UserServices
	// Webhooks contains the data access functions related to managing Webhooks.
	Webhooks WebhookServices
}

// SessionRefresher is an interface that contains a function to copy the database session.
type SessionRefresher interface {
	RefreshSession(*model.Connection, string)
}

// SessionCloser is an interface that contains a function to close the database session.
type SessionCloser interface {
	Close()
}

// UserServices is an interface that contians all functions related to account, user and billing.
type UserServices interface {
	SessionRefresher
	SessionCloser
	SignUp(email, password string) (*model.Account, error)
	AddToken(accountID, userID model.Key, name string) (*model.AccessToken, error)
	RemoveToken(accountID, userID, tokenID model.Key) error
	Auth(accountID model.Key, token string, pat bool) (*model.Account, *model.User, error)
	GetUserByEmail(email string) (*model.User, error)
	GetDetail(id model.Key) (*model.Account, error)
	GetByStripe(stripeId string) (*model.Account, error)
	SetSeats(id model.Key, seats int) error
	ConvertToPaid(id model.Key, stripeID, subID, plan string, yearly bool, seats int) error
	ChangePlan(id model.Key, plan string, yearly bool) error
	Cancel(id model.Key) error
}

// AdminServices TODO: investigate this...
type AdminServices interface {
	SessionRefresher
	SessionCloser
	LogRequests(reqs []model.APIRequest) error
}

// WebhookServices is an interface that contains all functions to manage webhook.
type WebhookServices interface {
	SessionRefresher
	SessionCloser
	Add(accountID model.Key, events, url string) error
	List(accountID model.Key) ([]model.Webhook, error)
	Delete(accountID model.Key, event, url string) error
	AllSubscriptions(event string) ([]model.Webhook, error)
}

repository: albertogviana/gosaas

repo_name: albertogviana/gosaas


text:
// Package boltx contains a collection of tools for [BoltDB](https://github.com/boltdb/bolt). It tries to simplify the
// handling of models in a BoltDB bucket without being too opinionated.
//
// It's basically assumes that models implement `encoding.BinaryMarshaler` and `encoding.BinaryUnmarshaler` from Go's
// standard library.
//
//   type model struct { ... }
//
//   func (m *model) MarshalBinary() ([]byte, error) { ... }
//
//   func (m *model) UnmarshalBinary([]byte) (error) { ... }
//
// Those methods should handle the (de)serialization of the model. The interfaces are than used by the functions of
// this package to store and load models.
//
//   model := &model{}
//
//   boltx.PutModel(bucket, []byte("key"), model)
//
//   boltx.GetModel(bucket, []byte("key"), model)
package boltx

repository: simia-tech/boltx

repo_name: simia-tech/boltx


text:
SUMMARY = "CD paranoia libraries from libcdio"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504"

DEPENDS = "libcdio"

SRC_URI = "http://ftp.gnu.org/gnu/libcdio/${BPN}-${PV}.tar.bz2"
SRC_URI[md5sum] = "0255aa50e660db7f2c39658b9c565814"
SRC_URI[sha256sum] = "ec1d9b1d5a28cc042f2cb33a7cc0a2b5ce5525f102bc4c15db1fac322559a493"

inherit autotools pkgconfig

EXTRA_OECONF = "--enable-cpp-progs --disable-static --disable-example-progs"


text:
// Copyright (c) 2016 Huawei Technologies Co., Ltd. All Rights Reserved.
//
//    Licensed under the Apache License, Version 2.0 (the "License"); you may
//    not use this file except in compliance with the License. You may obtain
//    a copy of the License at
//
//         http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
//    License for the specific language governing permissions and limitations
//    under the License.

/*
This module implements a entry into the OpenSDS northbound service.

*/

package northbound

import (
	"encoding/json"
	"io/ioutil"
	"log"
	"reflect"

	"github.com/opensds/opensds/pkg/controller/api"
	"github.com/opensds/opensds/pkg/controller/api/v1/shares"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
)

var falseShareResponse api.ShareResponse
var falseShareDetailResponse api.ShareDetailResponse
var falseAllSharesResponse []api.ShareResponse
var falseAllSharesDetailResponse []api.ShareDetailResponse

type ShareController struct {
	beego.Controller
}

func (this *ShareController) Post() {
	this.Ctx.Output.Header("Content-Type", "application/json")
	this.Ctx.Output.ContentType("application/json")

	resourceType := this.Ctx.Input.Param(":resource")
	reqBody, err := ioutil.ReadAll(this.Ctx.Request.Body)
	if err != nil {
		log.Println("Read share request body failed:", err)
		resBody, _ := json.Marshal("Read share request body failed!")
		this.Ctx.Output.Body(resBody)
	}

	shareRequest := &shares.ShareRequest{
		ResourceType: resourceType,
	}
	if err = json.Unmarshal(reqBody, shareRequest); err != nil {
		log.Println("Parse share request body failed:", err)
		resBody, _ := json.Marshal("Parse share request body failed!")
		this.Ctx.Output.Body(resBody)
	}

	result, err := shares.CreateShare(shareRequest)
	if err != nil {
		log.Println(err)
		resBody, _ := json.Marshal("Create share failed!")
		this.Ctx.Output.Body(resBody)
	} else {
		if reflect.DeepEqual(result, falseShareResponse) {
			log.Println("Create share failed!")
			resBody, _ := json.Marshal("Create share failed!")
			this.Ctx.Output.Body(resBody)
		} else {
			resBody, _ := json.Marshal(result)
			this.Ctx.Output.Body(resBody)
		}
	}
}

func (this *ShareController) Get() {
	this.Ctx.Output.Header("Content-Type", "application/json")
	this.Ctx.Output.ContentType("application/json")

	resourceType := this.Ctx.Input.Param(":resource")

	shareRequest := &shares.ShareRequest{
		ResourceType: resourceType,
		AllowDetails: false,
	}
	result, err := shares.ListShares(shareRequest)
	if err != nil {
		log.Println(err)
		resBody, _ := json.Marshal("List shares failed!")
		this.Ctx.Output.Body(resBody)
	} else {
		if reflect.DeepEqual(result, falseAllSharesResponse) {
			log.Println("List shares failed!")
			resBody, _ := json.Marshal("List shares failed!")
			this.Ctx.Output.Body(resBody)
		} else {
			resBody, _ := json.Marshal(result)
			this.Ctx.Output.Body(resBody)
		}
	}
}

func (this *ShareController) Put() {
	this.Ctx.Output.Header("Content-Type", "application/json")
	this.Ctx.Output.ContentType("application/json")
	resBody, _ := json.Marshal("Not supported!")
	this.Ctx.Output.Body(resBody)
}

func (this *ShareController) Delete() {
	this.Ctx.Output.Header("Content-Type", "application/json")
	this.Ctx.Output.ContentType("application/json")

	resourceType := this.Ctx.Input.Param(":resource")
	reqBody, err := ioutil.ReadAll(this.Ctx.Request.Body)
	if err != nil {
		log.Println("Read share request body failed:", err)
		resBody, _ := json.Marshal("Read share request body failed!")
		this.Ctx.Output.Body(resBody)
	}

	shareRequest := &shares.ShareRequest{
		ResourceType: resourceType,
	}
	if err = json.Unmarshal(reqBody, shareRequest); err != nil {
		log.Println("Parse share request body failed:", err)
		resBody, _ := json.Marshal("Parse share request body failed!")
		this.Ctx.Output.Body(resBody)
	}

	result := shares.DeleteShare(shareRequest)
	resBody, _ := json.Marshal(result)
	this.Ctx.Output.Body(resBody)
}

func GetShare(ctx *context.Context) {
	ctx.Output.Header("Content-Type", "application/json")
	ctx.Output.ContentType("application/json")

	resourceType := ctx.Input.Param(":resource")
	volId := ctx.Input.Param(":id")

	shareRequest := &shares.ShareRequest{
		ResourceType: resourceType,
		Id:           volId,
	}
	result, err := shares.GetShare(shareRequest)
	if err != nil {
		log.Println(err)
		resBody, _ := json.Marshal("Get share failed!")
		ctx.Output.Body(resBody)
	} else {
		if reflect.DeepEqual(result, falseAllSharesResponse) {
			log.Println("Get share failed!")
			resBody, _ := json.Marshal("Get share failed!")
			ctx.Output.Body(resBody)
		} else {
			resBody, _ := json.Marshal(result)
			ctx.Output.Body(resBody)
		}
	}
}

func AttachShare(ctx *context.Context) {
	ctx.Output.Header("Content-Type", "application/json")
	ctx.Output.ContentType("application/json")

	reqBody, err := ioutil.ReadAll(ctx.Request.Body)
	if err != nil {
		log.Println("Read share request body failed:", err)
		resBody, _ := json.Marshal("Read share request body failed!")
		ctx.Output.Body(resBody)
	}

	shareRequest := &shares.ShareRequest{}
	if err = json.Unmarshal(reqBody, shareRequest); err != nil {
		log.Println("Parse share request body failed:", err)
		resBody, _ := json.Marshal("Parse share request body failed!")
		ctx.Output.Body(resBody)
	}

	result := shares.AttachShare(shareRequest)
	resBody, _ := json.Marshal(result)
	ctx.Output.Body(resBody)
}

func DetachShare(ctx *context.Context) {
	ctx.Output.Header("Content-Type", "application/json")
	ctx.Output.ContentType("application/json")

	reqBody, err := ioutil.ReadAll(ctx.Request.Body)
	if err != nil {
		log.Println("Read share request body failed:", err)
		resBody, _ := json.Marshal("Read share request body failed!")
		ctx.Output.Body(resBody)
	}

	shareRequest := &shares.ShareRequest{}
	if err = json.Unmarshal(reqBody, shareRequest); err != nil {
		log.Println("Parse share request body failed:", err)
		resBody, _ := json.Marshal("Parse share request body failed!")
		ctx.Output.Body(resBody)
	}

	result := shares.DetachShare(shareRequest)
	resBody, _ := json.Marshal(result)
	ctx.Output.Body(resBody)
}

func MountShare(ctx *context.Context) {
	ctx.Output.Header("Content-Type", "application/json")
	ctx.Output.ContentType("application/json")

	reqBody, err := ioutil.ReadAll(ctx.Request.Body)
	if err != nil {
		log.Println("Read share request body failed:", err)
		resBody, _ := json.Marshal("Read share request body failed!")
		ctx.Output.Body(resBody)
	}

	shareRequest := &shares.ShareRequest{}
	if err = json.Unmarshal(reqBody, shareRequest); err != nil {
		log.Println("Parse share request body failed:", err)
		resBody, _ := json.Marshal("Parse share request body failed!")
		ctx.Output.Body(resBody)
	}

	result := shares.MountShare(shareRequest)
	resBody, _ := json.Marshal(result)
	ctx.Output.Body(resBody)
}

func UnmountShare(ctx *context.Context) {
	ctx.Output.Header("Content-Type", "application/json")
	ctx.Output.ContentType("application/json")

	reqBody, err := ioutil.ReadAll(ctx.Request.Body)
	if err != nil {
		log.Println("Read share request body failed:", err)
		resBody, _ := json.Marshal("Read share request body failed!")
		ctx.Output.Body(resBody)
	}

	shareRequest := &shares.ShareRequest{}
	if err = json.Unmarshal(reqBody, shareRequest); err != nil {
		log.Println("Parse share request body failed:", err)
		resBody, _ := json.Marshal("Parse share request body failed!")
		ctx.Output.Body(resBody)
	}

	result := shares.UnmountShare(shareRequest)
	resBody, _ := json.Marshal(result)
	ctx.Output.Body(resBody)
}

repository: freesky-edward/opensds

repo_name: freesky-edward/opensds


text:
package clusters

import (
	"errors"
	"io/ioutil"
	"strings"
)

// Old Legion is here for completeness and in case it needs to be queried.
// In practice, it probably won't be used much.
var clusterAccountingDBs = map[string]string{
	"myriad":   "myriad_sgelogs",
	"legion":   "legion_sgelogs",
	"grace":    "grace_sgelogs",
	"thomas":   "thomas_sgelogs",
	"michael":  "michael_sgelogs",
	"kathleen": "kathleen_sgelogs",
	"young":    "young_sgelogs", // I hate this
	"legion1":  "sgelogs",
	"legion2":  "sgelogs2",
	"legion3":  "legion_sgelogs", // Currently a synonym for "legion"
}

// We used to use regexes to work out which cluster the current hostname was from,
//  but since the namespace collapse of Legion from login{05..09} to login{01..02},
//  hostname can no longer be reliably used to find cluster name.
func GetClusterNameFromSGEIdent() (string, error) {
	clusterNameBytes, err := ioutil.ReadFile("/opt/sge/default/common/cluster_name")
	if err != nil {
		return "", errors.New("could not get cluster name: " + err.Error())
	}

	// The ident file has a trailing newline
	clusterName := strings.TrimSuffix(string(clusterNameBytes), "\n")

	return clusterName, nil
}

// Wrapper function so that caller does not need to know what method is used.
func GetLocalClusterName() (string, error) {
	clusterName, err := GetClusterNameFromSGEIdent()
	if err != nil {
		return "", err
	}
	return clusterName, nil
}

func GetClusterAccountingDBName(clusterName string) (string, error) {
	dbName, wasPresent := clusterAccountingDBs[clusterName]
	if wasPresent == false {
		return "", errors.New("This cluster [" + clusterName + "] does not have a known associated accounting DB.")
	}
	return dbName, nil
}

func GetLocalClusterAccountingDBName() (string, error) {
	clusterName, err := GetLocalClusterName()
	if err != nil {
		return "", err
	}
	return GetClusterAccountingDBName(clusterName)
}

repository: UCL-RITS/go-clustertools

repo_name: UCL-RITS/go-clustertools


text:
Automatically generated by Mendeley Desktop 1.19.4
Any changes to this file will be lost if it is regenerated by Mendeley.

BibTeX export options can be customized via Preferences -> BibTeX in Mendeley Desktop

@misc{Of,
archivePrefix = {arXiv},
arxivId = {NIHMS150003},
author = {Of, Rofessor},
booktitle = {ASA Refresher Courses in Anesthesiology},
doi = {10.1109/TDEI.2009.5211872},
eprint = {NIHMS150003},
isbn = {1070-9878},
issn = {10709878},
pmid = {24335434},
title = {{H l u a}}
}

license: Unlicense

repository: sepmein/references

repo_name: sepmein/references


text:
include bluez-utils.inc

PR = "r1"

DEPENDS += "dbus"
SRC_URI += "file://dbus-2.24.patch;patch=1 \
	    file://hciattach-ti-bts.patch;patch=1"
EXTRA_OECONF += "--with-dbus"

repository: BackupTheBerlios/openslug-svn

repo_name: BackupTheBerlios/openslug-svn


text:
@Inbook{AdHocNetworksBook,
  author="Gerla, Mario",
  editor="Mohapatra, Prasant
      and Krishnamurthy, Srikanth V.",
  title="Ad Hoc Networks",
  bookTitle="Ad Hoc Networks: Technologies and Protocols",
  year="2005",
  publisher="Springer US",
  address="Boston, MA",
  pages="1--22",
  isbn="978-0-387-22690-3",
  doi="10.1007/0-387-22690-7_1",
}

@article{D2D,
  title = "An overview of device-to-device communication in cellular networks",
  journal = "ICT Express",
  year = "2017",
  issn = "2405-9595",
  doi = "10.1016/j.icte.2017.08.002",
  author = "Udit Narayana Kar and Debarshi Kumar Sanyal",
  keywords = "Device-to-device communication (D2D), Cellular network, 5G,
      Resource management, LTE direct"
}

@online{Briar,
 title = {Briar: a messaging app designed for activists},
 author = {Briar},
 year = {2016},
 urldate = {2018-02-25},
 URL = {https://briarproject.org/how-it-works.html},
}

@online{FireChat,
 title = {FireChat: a messaging app without Internet access or cellular data},
 author = {FireChat},
 year = {2016},
 urldate = {2018-02-25},
 URL = {https://www.opengarden.com/firechat.html},
}

repository: dbosk/bibsp

repo_name: dbosk/bibsp


text:
@article{loyd-pnasusa-104-14266-2007,
 abstract = {The thermal evolution of Earth is governed by the rate of
secular cooling and the amount of radiogenic heating. If mantle
heat sources are known, surface heat flow at different times may
be used to deduce the efficiency of convective cooling and
ultimately the temporal character of plate tectonics. We estimate
global heat flow from 65 Ma to the present using seafloor age
reconstructions and a modified half-space cooling model, and we
find that heat flow has decreased by similar to 0.15% every
million years during the Cenozoic. By examining geometric trends
in plate reconstructions since 120 Ma, we show that the reduction
in heat flow is due to a decrease in the area of ridge-proximal
oceanic crust. Even accounting for uncertainties in plate
reconstructions, the rate of heat flow decrease is an order of
magnitude faster than estimates based on smooth, parameterized
cooling models. This implies that heat flow experiences short-term
fluctuations associated with plate tectonic cyclicity. Continental
separation does not appear to directly control convective
wavelengths, but rather indirectly affects how oceanic plate
systems adjust to accommodate global heat transport. Given that
today's heat flow may be unusually low, secular cooling rates
estimated from present-day values will tend to underestimate the
average cooling rate. Thus, a mechanism that causes less efficient
tectonic heat transport at higher temperatures may be required to
prevent an unreasonably hot mantle in the recent past.},
 author = {Sean Loyd and Thorsten W.  Beckert and Cliton P. Conrad
and Carolina Lithgow-Bertelloni and Frank A. Corsetti},
 entrydate = {2020/07/13},
 journal = {Proc. National Acad. Sciences United States Am.},
 number = {36},
 pages = {14266--14271},
 title = {Time variability in Cenozoic reconstructions of mantle
heat flow: Plate tectonic cycles and implications for Earth's
thermal evolution},
 volume = {104},
 year = {2007}
}

repository: xiyuanbao/kgb

repo_name: xiyuanbao/kgb