text:
SUMMARY = "Wrapper for libv4l2_nvvidconv to work around STREAMOFF segfault issue"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=d58123d89b8fdb1ac2cb445de95dbb79"

COMPATIBLE_MACHINE = "(tegra)"

DEPENDS = "libv4l"

SRC_REPO = "github.com/OE4T/nvvidconv-plugin-wrapper.git;protocol=https"
SRCBRANCH = "main"
SRC_URI = "git://${SRC_REPO};branch=${SRCBRANCH}"
# Corresponds to v1.0.1 tag
SRCREV = "0b2f038a6c715e73e0c38ae8ec1680f4406d655d"
PV = "1.0.1"

S = "${WORKDIR}/git"

inherit cmake pkgconfig features_check

REQUIRED_DISTRO_FEATURES = "opengl"

FILES:${PN} = "${libdir}/libv4l/plugins/*${SOLIBSDEV}"

PACKAGE_ARCH = "${TEGRA_PKGARCH}"

repository: SOL-Space-Operating-Linux/meta-tegra

repo_name: SOL-Space-Operating-Linux/meta-tegra


text:
@article{paper-dremel,
  review =      {},
  Title =	    {Dremel: Interactive Analysis of Web-Scale Datasets},
  Author = 	    {Sergey Melnik and Andrey Gubarev and Jing Jing Long and Geoffrey Romer and Shiva Shivakumar and Matt Tolton and Theo Vassilakis},
  Year = 	    2011,
  Month =       jun,
  Publisher= 	{ACM New York NY, USA},
  Pages = 	    {114-123},
  Numpage =     9,
  Volume=	    {54},
  Journal = 	{Communications of the ACM},
  Doi=          {10.1145/1953122.1953148},
  ISSN =        {0001-0782},
  Owner = 	    {S17-IR-2002},
  Url = 	    {http://cacm.acm.org/magazines/2011/6/108648-dremel-interactive-analysis-of-web-scale-datasets/fulltext}
}

@book{book-hadoop,
  review =      {},
  status =      {incomplete},
  Title =	    {Professional Hadoop Solutions},
  Author =	    {Boris Lublinsky, Kevin T. Smith, Alexey Yakubovich},
  Publisher =	{Wiley Publishing},
  Year =	    2013,
   Address =	{Indianapoli, Indiana},
  ISBN =	    {9781118611937},
  Owner = 	    {S17-IR-2002}
}

@book{book-hadoop-apps,
  review =      {},
  status =      {incomplete},
  Title =	    {Hadoop Application Architectures},
  Author =	    {Mark Grover, Ted Malaska, Jonathan Seidman, Gwen Shapira},
  Publisher =	{O'Reilly Media Inc},
  Year =	    2015,
   Address =	{Sebastopol, California},
  ISBN =	    {9781491900086},
  Owner = 	    {S17-IR-2002}
}

@misc{twitter-dremel,
  review =      {},
  Title = 		{Dremel made simple with Parquet},
  Author = 		{{Twittter}},
  HowPublished ={Web Page},
  Month = 		feb,
  Note = 		{Accessed: 2017-02-15},
  Year = 		2017,
  Owner = 		{S17-IR-2002},
  Url =         {https://blog.twitter.com/2013/dremel-made-simple-with-parquet}
}

@misc{www-dremel,
  review =      {},
  Title = 		{DInside Capacitor, BigQuery’s next-generation columnar storage format},
  Author = 		{{Google}},
  HowPublished ={Web Page},
  Month = 		feb,
  Note = 		{Accessed: 2017-02-20},
  Year = 		2017,
  Owner = 		{S17-IR-2002},
  Url =         {https://cloud.google.com/blog/big-data/2016/04/inside-capacitor-bigqueys-next-generation-columnar-storage-format}
}

@misc{wiki-drill,
  review =      {},
  Title = 		{Apache Drill},
  Author = 		{{wikipedia}},
  HowPublished ={Web Page},
  Month = 		feb,
  Note = 		{Accessed: 2017-02-20},
  Year = 		2017,
  Owner = 		{S17-IR-2002},
  Url =         {https://en.wikipedia.org/wiki/Apache_Drill}
}

license_type: permissive

branch_name: refs/heads/master

extension: bib


text:
package bitbucket

import "github.com/mitchellh/mapstructure"

type Page struct {
	Size   int64  `json:"size"`    // Total number of objects in the response. This is an optional element that is not provided in all responses, as it can be expensive to compute.
	Number int    `json:"page"`    // Page number of the current results. This is an optional element that is not provided in all responses.
	Length int    `json:"pagelen"` // Current number of objects on the existing page. Globally, the minimum length is 10 and the maximum is 100. Some APIs may specify a different default.
	Next   string `json:"next"`    // Link to the next page if it exists. The last page of a collection does not have this value. Use this link to navigate the result set and refrain from constructing your own URLs.
	// Link toe previous page if it exists. A collections first page does not have this value. This is an optional element that is not provided in all responses. Some result sets strictly support forward navigation and never provide previous links. Clients must anticipate that backwards navigation is not always available.Client
	// Use this link to navigate the result set and refrain from constructing your own URLs.
	Previous string        `json:"previous"`
	Values   []interface{} `json:"values"` // The list of objects. This contains at most pagelen objects.
}

func (p Page) Repositories() []Repository {
	list := []Repository{}
	for _, each := range p.Values {
		var r Repository
		mapstructure.Decode(each, &r)
		list = append(list, r)
	}
	return list
}

license: MIT

repository: emicklei/go-bitbucket

repo_name: emicklei/go-bitbucket

extension: go


text:
@InProceedings{10.1007/978-3-319-21996-7_1,
author="Ben Youssef, Atef
and Chollet, Mathieu
and Jones, Haza{\"e}l
and Sabouret, Nicolas
and Pelachaud, Catherine
and Ochs, Magalie",
editor="Brinkman, Willem-Paul
and Broekens, Joost
and Heylen, Dirk",
title="Towards a Socially Adaptive Virtual Agent",
booktitle="Intelligent Virtual Agents",
year="2015",
publisher="Springer International Publishing",
address="Cham",
pages="3--16",
abstract="This paper presents a socially adaptive virtual agent that can adapt its behaviour according to social constructs (e.g. attitude, relationship) that are updated depending on the behaviour of its interlocutor. We consider the context of job interviews with the virtual agent playing the role of the recruiter. The evaluation of our approach is based on a comparison of the socially adaptive agent to a simple scripted agent and to an emotionally-reactive one. Videos of these three different agents in situation have been created and evaluated by 83 participants. This subjective evaluation shows that the simulation and expression of social attitude is perceived by the users and impacts on the evaluation of the agent's credibility. We also found that while the emotion expression of the virtual agent has an immediate impact on the user's experience, the impact of the virtual agent's attitude expression's impact is stronger after a few speaking turns.",
isbn="978-3-319-21996-7"
}

repository: matchollet/academic-kickstart

repo_name: matchollet/academic-kickstart


text:
require dtc-native.inc

SRC_URI = "git://www.jdl.com/software/dtc.git;protocol=git"

S = "${WORKDIR}/git"

extension: bb


text:
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"html/template"
	"math"
	"net"
	"net/http"
	"os"
	"os/signal"
	"regexp"
	"strconv"
	"strings"
	"syscall"
	"time"

	"github.com/desdic/godmarcparser/cfg"
	"github.com/desdic/godmarcparser/dmarc"
	"github.com/desdic/godmarcparser/spf"

	"github.com/gorilla/mux"
	log "github.com/sirupsen/logrus"
)

var (
	isdomain = regexp.MustCompile(`^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9][a-zA-Z0-9-_]{1,61}[a-zA-Z0-9]))\.([a-zA-Z]{2,6}|[a-zA-Z0-9-]{2,30}\.[a-zA-Z]{2,3})$`)
	isip     = regexp.MustCompile(`((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))`)
)

func statusHandler(ctx context.Context, fn func(context.Context, http.ResponseWriter, *http.Request)) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		fn(ctx, w, r)
	}
}

func handleReports(ctx context.Context, w http.ResponseWriter, r *http.Request) {

	v := r.URL.Query()

	page := 1

	p := v.Get("page")
	if p != "" {
		i, err := strconv.Atoi(p)
		if err != nil {
			errors <- fmt.Errorf("Cannot convert page to int: %v", err)
			http.Error(w, "page is not a number", http.StatusBadRequest)
			return
		}
		page = i
	}

	if page < 1 {
		page = 1
	}

	pagesize := 30

	offset := (page - 1) * pagesize

	reports, err := s.ReadReports(ctx, offset, pagesize)
	if err != nil {
		errors <- fmt.Errorf("Unable to read reports: %v", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	totalpages := 1
	if len(reports) > 0 {
		totalpages = int(math.Ceil(float64(reports[0].Items / pagesize)))
	}

	var pages []int

	before := page - 1
	if before < 0 {
		before = 0
	}

	if before > 3 {
		before = 3
	}

	after := page + 3
	if after > 3 {
		after = 3
	}

	if page+3 > totalpages {
		after = 1 + (totalpages - page)
	}

	for i := before; i > 0; i-- {
		pages = append(pages, page-i)
	}

	pages = append(pages, page)

	for i := 1; i < after+1; i++ {
		pages = append(pages, page+i)
	}

	data := dmarc.Reports{Reports: reports, CurPage: page, LastPage: page - 1, NextPage: page + 1, TotalPages: totalpages + 1, Pages: pages}

	tmpl, err := template.ParseFiles("templates/reports.html")
	if err != nil {
		errors <- fmt.Errorf("Unable to parse templates/reports.html: %v", err)
		return
	}

	w.Header().Set("Content-Type", "text/html")
	if err = tmpl.Execute(w, data); err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		errors <- fmt.Errorf("Error running template: %v", err)
		return
	}
}

func handleReport(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	id, err := strconv.ParseInt(vars["id"], 10, 64)
	if err != nil {
		errors <- fmt.Errorf("Unable to convert %s to int64", vars["id"])
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	report, err := s.ReadReport(ctx, id)
	if err != nil {
		errors <- fmt.Errorf("Unable to read report %d: %v", id, err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	tmpl, err := template.ParseFiles("templates/report.html")
	if err != nil {
		errors <- fmt.Errorf("Unable to parse templates/report.html: %v", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	w.Header().Set("Content-Type", "text/html")
	if err = tmpl.Execute(w, report); err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		errors <- fmt.Errorf("Error running template: %v", err)
		return
	}
}

func isIPv4(address string) bool {
	return strings.Count(address, ":") < 2
}

func isIPv6(address string) bool {
	return strings.Count(address, ":") >= 2
}

type acidr struct {
	Cidr   string
	Within bool
}

type alist struct {
	Domain    string
	IP        string
	Reverse   string
	Spfrecord string
	Cidrs     []acidr
	Breakdown string
}

func flattenBreakDown(ip net.IP, b spf.BreakDown) (list []acidr) {
	for _, l := range b.Rules {
		iplist := strings.Split(l.Value, ",")
		for _, i := range iplist {
			_, ipnet, err := net.ParseCIDR(i)
			if err != nil {
				log.Errorf("Error parsing CIDR %s: %v:", i, err)
				return
			}

			within := false
			if ipnet.Contains(ip) {
				within = true
			}
			list = append(list, acidr{Cidr: i, Within: within})
		}
	}

	for _, i := range b.Includes {
		list = append(list, flattenBreakDown(ip, i)...)
	}

	return list
}

func handleAnalyse(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	domain := vars["domain"]
	ip := vars["ip"]

	if !isdomain.MatchString(domain) {
		_, err := fmt.Fprintf(w, "Got %#v but its not a valid domain name", domain)
		if err != nil {
			log.Errorf("Unable to send data: %v", err)
		}
		return
	}

	if !isip.MatchString(ip) {
		_, err := fmt.Fprintf(w, "Got %#v but its not a valid IP address", ip)
		if err != nil {
			log.Errorf("Unable to send data: %v", err)
		}
		return
	}

	spfresults, err := spf.Get(domain)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		log.Errorf("Unable to lookup IPs: %v", err)
		return
	}

	var analasis alist

	analasis.Domain = domain
	analasis.IP = ip
	analasis.Spfrecord = spfresults.Record

	l, err := net.LookupAddr(ip)
	if err != nil {
		log.Warningf("Unable to do reverse lookup on %s: %v", ip, err)
	}
	analasis.Reverse = strings.Join(l, ",")

	b, err := json.MarshalIndent(spfresults, "", "\t")
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		log.Errorf("Unable to convert SPF results to json")
		return
	}

	analasis.Breakdown = string(b)

	ipcidr := ip + "/128"
	if isIPv4(ip) {
		ipcidr = ip + "/32"
	}

	ipB, _, err := net.ParseCIDR(ipcidr)
	if err != nil {
		log.Errorf("Error creating CIDR %s: %v:", ipcidr, err)
		return
	}

	analasis.Cidrs = flattenBreakDown(ipB, spfresults)

	tmpl, err := template.ParseFiles("templates/analyse.html")
	if err != nil {
		errors <- fmt.Errorf("Unable to parse templates/analyse.html: %v", err)
		return
	}

	w.Header().Set("Content-Type", "text/html")
	if err = tmpl.Execute(w, analasis); err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		errors <- fmt.Errorf("Error running template: %v", err)
		return
	}
}

func defaultHandler(w http.ResponseWriter, r *http.Request) {
	log.Debug("Default handler invoked due to missing route or file")
	http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
}

func httpHandler(ctx context.Context) http.Handler {

	r := mux.NewRouter()
	log.Debug("Adding /static")
	r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))

	log.Debug("Adding handler for /")
	r.HandleFunc("/", LogHTTP(statusHandler(ctx, handleReports)))

	log.Debug("Adding handler for /report")
	r.HandleFunc("/report/{id:[0-9]+}", LogHTTP(statusHandler(ctx, handleReport))).Name("report")

	log.Debug("Adding handler for /analyze")
	r.HandleFunc("/analyse/{domain:[a-z0-9.-]+}/{ip:[a-f0-9.:]+}", LogHTTP(statusHandler(ctx, handleAnalyse))).Name("analyse")

	// Default handler (Used for logging 404)
	r.NotFoundHandler = LogHTTP(http.HandlerFunc(defaultHandler))

	return r
}

func httpStart(ctx context.Context, cancel context.CancelFunc, cfg cfg.HTTPCfg) (*http.Server, chan os.Signal) {

	srv := &http.Server{
		Handler:      httpHandler(ctx),
		Addr:         cfg.Port,
		WriteTimeout: time.Second * time.Duration(cfg.WriteTimeout),
		ReadTimeout:  time.Second * time.Duration(cfg.ReadTimeout),
		IdleTimeout:  time.Second * time.Duration(cfg.IdleTimeout),
	}

	go func(srv *http.Server) {
		log.Infof("Starting webserver on port %s", srv.Addr)
		if err := srv.ListenAndServe(); err != nil {
			log.Errorf("ListenAndServe: %v", err)
			cancel()
			return
		}
	}(srv)

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)

	return srv, c
}

repository: desdic/godmarcparser

repo_name: desdic/godmarcparser

gha_license_id: MIT

gha_language: Go


text:
@article{Fouda_etal18a,
 author = {M. E. Fouda and E. Neftci and A. Eltawil and F. Kurdahi},
 doi = {10.1109/TNANO.2018.2880734},
 issn = {},
 journal = {IEEE Transactions on Nanotechnology},
 keywords = {blind source separation;feature extraction;Hebbian learning;independent component analysis;Laplace equations;neural nets;random-access storage;titanium compounds;unsupervised learning;Laplacian signals demixing;device variability;local unsupervised learning algorithm;resistive random-access memories;feature extraction;RRAM;asymmetric nonlinear weight update behavior;error-gated Hebbian rule;ICA;independent component analysis;blind source separation problem;neuromorphic circuits;TiO2;Programming;Switches;Heuristic algorithms;Independent component analysis;Feature extraction;Training;Hardware;RRAMs;memristor;ICA;unsupervised learning;brain-inspired learning},
 month = {November},
 number = {},
 pages = {611--615},
 title = {Independent Component Analysis Using RRAMs},
 volume = {18},
 year = {2018}
}

repository: eneftci/academic-kickstart

repo_name: eneftci/academic-kickstart


text:
# Find clang-tidy
#
# Module dependencies:
#   FindPackageHandleStandardArgs
#
# Cache Variables:
#   CLANG_TIDY_ROOT_DIR
#
# Non-cache variables for users of the module:
#   ClangTidy_EXECUTABLE
#   ClangTidy_FOUND
#   ClangTidy_VERSION

file(TO_CMAKE_PATH "${CLANG_TIDY_ROOT_DIR}" CLANG_TIDY_ROOT_DIR)
set(CLANG_TIDY_ROOT_DIR
    "${CLANG_TIDY_ROOT_DIR}"
    CACHE
    PATH
    "Path to directory containing clang-tidy executable")

if(CLANG_TIDY_ROOT_DIR)
    find_program(ClangTidy_EXECUTABLE
        NAMES clang-tidy
        PATHS "${CLANG_TIDY_ROOT_DIR}"
        NO_DEFAULT_PATH
        DOC "Path to clang-tidy executable")
else()
    find_program(ClangTidy_EXECUTABLE
        NAMES clang-tidy
        DOC "Path to clang-tidy executable")
endif()

mark_as_advanced(ClangTidy_EXECUTABLE ClangTidy_FOUND ClangTidy_VERSION)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ClangTidy
    FOUND_VAR ClangTidy_FOUND
    REQUIRED_VARS ClangTidy_EXECUTABLE
    VERSION_VAR ClangTidy_VERSION)

extension: cmake


text:
@article{Caputi012017AssessingThePossibility,
 author = {Theodore L. Caputi},
 doi = {10.12806/v16/i1/t2},
 journal = {Journal of Leadership Education},
 month = {jan},
 number = {1},
 pages = {115--132},
 publisher = {Journal of Leadership Education},
 title = {Assessing the Possibility of Leadership Education as Psychosocial-Based Problem Behavior Prevention for Adolescents: A Review of the Literature},
 url = {https://doi.org/10.12806%2Fv16%2Fi1%2Ft2},
 volume = {16},
 year = {2017}
}

repository: yesiknowjava/theodorecaputihugo

repo_name: yesiknowjava/theodorecaputihugo


text:
DESCRIPTION = "Skin Red Heat HD. Daconi and mmark"
MAINTAINER = "SIFTeam"

inherit gitpkgv

PV = "1.0+git${SRCPV}"
PKGV = "1.0+git${GITPKGV}"
PR = "r0"
SRCREV = ${AUTOREV}

PV_font-nmsbd2 = "20120113"
PR_font-nmsbd2 = "r0"
PKGV_font-nmsbd2 = "${PV_font-nmsbd2}"
DESCRIPTION_font-nmsbd2 = "Nmsbd2 font"

PV_font-verdanar = "20120113"
PR_font-verdanar = "r0"
PKGV_font-verdanar = "${PV_font-verdanar}"
DESCRIPTION_font-verdanar = "Verdana_R font"

PACKAGES = "${PN} font-nmsbd2 font-verdanar"
PROVIDES = "${PN} font-nmsbd2 font-verdanar"

SRC_URI = "git://github.com/SIFTeam/skin-redheathd.git;protocol=git"

FILES_${PN} = "/usr/share/enigma2"
FILES_font-nmsbd2 = "/usr/share/fonts/nmsbd2.ttf"
FILES_font-verdanar = "/usr/share/fonts/Verdana_R.ttf"

RDEPENDS_${PN} = "font-nmsbd2 font-verdanar"

S = "${WORKDIR}/git"

do_install() {
	install -d ${D}/usr/share
	cp -rp ${S}/usr/share/* ${D}/usr/share/
	chmod -R a+rX ${D}/usr/share/enigma2/
	chmod 644 ${D}/usr/share/fonts/*.ttf
}

repository: edwarekuo/openembedded

repo_name: edwarekuo/openembedded


text:
package bot

import (
	"fmt"
	"log"
	"math/rand"
	"time"
)

// WTF bot bans user for random interval
type WTF struct {
	superUser   SuperUser
	minDuration time.Duration
	maxDuration time.Duration
	rand        func(n int64) int64 // tests may change it
	lastWtf     time.Time
	tooSoon     time.Duration // tests may change it
}

// NewWTF makes a random ban bot
func NewWTF(minDuration, maxDuration time.Duration, superUser SuperUser) *WTF {
	log.Printf("[INFO] WTF bot with %v-%v interval", minDuration, maxDuration)
	return &WTF{minDuration: minDuration, maxDuration: maxDuration, rand: rand.Int63n, superUser: superUser, tooSoon: time.Minute}
}

// OnMessage sets duration of ban randomly
func (w *WTF) OnMessage(msg Message) (response Response) {

	wtfContains := WTFSteroidChecker{
		Message: msg.Text}

	if !wtfContains.Contains() {
		return Response{}
	}

	wtfUser := msg.From
	var wtfChannelID int64
	var wtfChannelUsername string
	if w.superUser.IsSuper(msg.From.Username) {
		if msg.ReplyTo.From.ID == 0 { // not reply, ignore for supers
			return Response{}
		}
		wtfRequested := fmt.Sprintf("[INFO] wtf requested by %q for %q, id:%d", msg.From.Username, msg.ReplyTo.From.Username, msg.ReplyTo.From.ID)
		if msg.ReplyTo.SenderChat.ID != 0 {
			wtfChannelID = msg.ReplyTo.SenderChat.ID
			wtfChannelUsername = msg.ReplyTo.SenderChat.UserName
			wtfRequested = fmt.Sprintf("[INFO] wtf requested by %q for %q, id:%d", msg.From.Username, wtfChannelUsername, wtfChannelID)
		}
		log.Print(wtfRequested)
		wtfUser = msg.ReplyTo.From // set WTF user from ReplyTo.From for supers, so it will ban the user replied to
	}

	if w.superUser.IsSuper(wtfUser.Username) {
		log.Printf("[WARN] WTF requested of user %q, ignored (super)", wtfUser.Username)
		return Response{} // don't allow supers to ban other supers
	}

	// message from channel, not banned by superuser above
	if msg.From.ID == 136817688 && wtfChannelID == 0 {
		wtfChannelID = msg.SenderChat.ID
		wtfChannelUsername = msg.SenderChat.UserName
	}

	mention := "@" + wtfUser.Username
	if wtfUser.Username == "" {
		mention = wtfUser.DisplayName
	}
	if wtfChannelID != 0 {
		mention = "@" + wtfChannelUsername
	}

	banDuration := w.minDuration + time.Second*time.Duration(w.rand(int64(w.maxDuration.Seconds()-w.minDuration.Seconds())))
	if time.Since(w.lastWtf) < w.tooSoon { // if last wtf was less than 1 minute ago, add more time to ban duration
		increase := time.Hour * 5 * time.Duration(w.tooSoon.Seconds()-time.Since(w.lastWtf).Seconds())
		log.Printf("[INFO] wtf from %v in %v is too soon, adding %v to ban duration", mention, time.Since(w.lastWtf), increase)
		banDuration += increase
	}
	switch w.rand(10) {
	case 1:
		banDuration = time.Hour * 666
	case 2:
		banDuration = time.Minute*77 + time.Second*7
	}
	w.lastWtf = time.Now()

	durationString := HumanizeDuration(banDuration)
	if wtfChannelID != 0 {
		durationString = "навсегда"
	}

	return Response{
		Text:        fmt.Sprintf("%s получает бан на %v", EscapeMarkDownV1Text(mention), durationString),
		Send:        true,
		BanInterval: banDuration,
		User:        wtfUser,
		ChannelID:   wtfChannelID,
	}
}

// ReactOn keys
func (w *WTF) ReactOn() []string {
	return []string{"wtf!", "wtf?"}
}

// Help returns help message
func (w *WTF) Help() string {
	return GenHelpMsg(w.ReactOn(), "если не повезет, блокирует пользователя на какое-то время")
}

repository: radio-t/super-bot

repo_name: radio-t/super-bot


text:
import React from "react";
import Header from "../Header";
import TasksList from "../TasksList";

import "../../normalize.css";
import { Page, Wrapper, PopupBlock } from "./styles";

const ToDoList = () => {
  return (
    <Page>
      <Wrapper>
        <Header />
        <TasksList />
      </Wrapper>
      <PopupBlock id="popup" />
    </Page>
  );
};

export default ToDoList;

repository: bashmakovartur/testToDoApplication

repo_name: bashmakovartur/testToDoApplication

extension: js


text:
package v1

import (
	"encoding/json"
	"fmt"
	"net/http"
	"strconv"
	"time"

	"github.com/crowdsecurity/crowdsec/pkg/database/ent"
	"github.com/crowdsecurity/crowdsec/pkg/fflag"
	"github.com/crowdsecurity/crowdsec/pkg/models"
	"github.com/gin-gonic/gin"
	log "github.com/sirupsen/logrus"
)

// Format decisions for the bouncers
func FormatDecisions(decisions []*ent.Decision) []*models.Decision {
	var results []*models.Decision

	for _, dbDecision := range decisions {
		duration := dbDecision.Until.Sub(time.Now().UTC()).String()
		decision := models.Decision{
			ID:       int64(dbDecision.ID),
			Duration: &duration,
			Scenario: &dbDecision.Scenario,
			Scope:    &dbDecision.Scope,
			Value:    &dbDecision.Value,
			Type:     &dbDecision.Type,
			Origin:   &dbDecision.Origin,
			UUID:     dbDecision.UUID,
		}
		results = append(results, &decision)
	}
	return results
}

func (c *Controller) GetDecision(gctx *gin.Context) {
	var err error
	var results []*models.Decision
	var data []*ent.Decision

	bouncerInfo, err := getBouncerFromContext(gctx)
	if err != nil {
		gctx.JSON(http.StatusUnauthorized, gin.H{"message": "not allowed"})
		return
	}

	data, err = c.DBClient.QueryDecisionWithFilter(gctx.Request.URL.Query())
	if err != nil {
		c.HandleDBErrors(gctx, err)
		return
	}

	results = FormatDecisions(data)
	/*let's follow a naive logic : when a bouncer queries /decisions, if the answer is empty, we assume there is no decision for this ip/user/...,
	but if it's non-empty, it means that there is one or more decisions for this target*/
	if len(results) > 0 {
		PrometheusBouncersHasNonEmptyDecision(gctx)
	} else {
		PrometheusBouncersHasEmptyDecision(gctx)
	}

	if gctx.Request.Method == http.MethodHead {
		gctx.String(http.StatusOK, "")
		return
	}

	if time.Now().UTC().Sub(bouncerInfo.LastPull) >= time.Minute {
		if err := c.DBClient.UpdateBouncerLastPull(time.Now().UTC(), bouncerInfo.ID); err != nil {
			log.Errorf("failed to update bouncer last pull: %v", err)
		}
	}

	gctx.JSON(http.StatusOK, results)
}

func (c *Controller) DeleteDecisionById(gctx *gin.Context) {
	var err error

	decisionIDStr := gctx.Param("decision_id")
	decisionID, err := strconv.Atoi(decisionIDStr)
	if err != nil {
		gctx.JSON(http.StatusBadRequest, gin.H{"message": "decision_id must be valid integer"})
		return
	}
	nbDeleted, deletedFromDB, err := c.DBClient.SoftDeleteDecisionByID(decisionID)
	if err != nil {
		c.HandleDBErrors(gctx, err)
		return
	}
	//transform deleted decisions to be sendable to capi
	deletedDecisions := FormatDecisions(deletedFromDB)

	if c.DecisionDeleteChan != nil {
		c.DecisionDeleteChan <- deletedDecisions
	}

	deleteDecisionResp := models.DeleteDecisionResponse{
		NbDeleted: strconv.Itoa(nbDeleted),
	}

	gctx.JSON(http.StatusOK, deleteDecisionResp)
}

func (c *Controller) DeleteDecisions(gctx *gin.Context) {
	var err error
	nbDeleted, deletedFromDB, err := c.DBClient.SoftDeleteDecisionsWithFilter(gctx.Request.URL.Query())
	if err != nil {
		c.HandleDBErrors(gctx, err)
		return
	}
	//transform deleted decisions to be sendable to capi
	deletedDecisions := FormatDecisions(deletedFromDB)

	if c.DecisionDeleteChan != nil {
		c.DecisionDeleteChan <- deletedDecisions
	}

	deleteDecisionResp := models.DeleteDecisionResponse{
		NbDeleted: nbDeleted,
	}
	gctx.JSON(http.StatusOK, deleteDecisionResp)
}

func writeStartupDecisions(gctx *gin.Context, filters map[string][]string, dbFunc func(map[string][]string) ([]*ent.Decision, error)) error {
	// respBuffer := bytes.NewBuffer([]byte{})
	limit := 30000 //FIXME : make it configurable
	needComma := false
	lastId := 0

	limitStr := fmt.Sprintf("%d", limit)
	filters["limit"] = []string{limitStr}
	for {
		if lastId > 0 {
			lastIdStr := fmt.Sprintf("%d", lastId)
			filters["id_gt"] = []string{lastIdStr}
		}

		data, err := dbFunc(filters)
		if err != nil {
			return err
		}
		if len(data) > 0 {
			lastId = data[len(data)-1].ID
			results := FormatDecisions(data)
			for _, decision := range results {
				decisionJSON, _ := json.Marshal(decision)
				if needComma {
					//respBuffer.Write([]byte(","))
					gctx.Writer.Write([]byte(","))
				} else {
					needComma = true
				}
				//respBuffer.Write(decisionJSON)
				//_, err := gctx.Writer.Write(respBuffer.Bytes())
				_, err := gctx.Writer.Write(decisionJSON)
				if err != nil {
					gctx.Writer.Flush()
					return err
				}
				//respBuffer.Reset()
			}
		}
		log.Debugf("startup: %d decisions returned (limit: %d, lastid: %d)", len(data), limit, lastId)
		if len(data) < limit {
			gctx.Writer.Flush()
			break
		}
	}
	return nil
}

func writeDeltaDecisions(gctx *gin.Context, filters map[string][]string, lastPull time.Time, dbFunc func(time.Time, map[string][]string) ([]*ent.Decision, error)) error {
	//respBuffer := bytes.NewBuffer([]byte{})
	limit := 30000 //FIXME : make it configurable
	needComma := false
	lastId := 0

	limitStr := fmt.Sprintf("%d", limit)
	filters["limit"] = []string{limitStr}
	for {
		if lastId > 0 {
			lastIdStr := fmt.Sprintf("%d", lastId)
			filters["id_gt"] = []string{lastIdStr}
		}

		data, err := dbFunc(lastPull, filters)
		if err != nil {
			return err
		}
		if len(data) > 0 {
			lastId = data[len(data)-1].ID
			results := FormatDecisions(data)
			for _, decision := range results {
				decisionJSON, _ := json.Marshal(decision)
				if needComma {
					//respBuffer.Write([]byte(","))
					gctx.Writer.Write([]byte(","))
				} else {
					needComma = true
				}
				//respBuffer.Write(decisionJSON)
				//_, err := gctx.Writer.Write(respBuffer.Bytes())
				_, err := gctx.Writer.Write(decisionJSON)
				if err != nil {
					gctx.Writer.Flush()
					return err
				}
				//respBuffer.Reset()
			}
		}
		log.Debugf("startup: %d decisions returned (limit: %d, lastid: %d)", len(data), limit, lastId)
		if len(data) < limit {
			gctx.Writer.Flush()
			break
		}
	}
	return nil
}

func (c *Controller) StreamDecisionChunked(gctx *gin.Context, bouncerInfo *ent.Bouncer, streamStartTime time.Time, filters map[string][]string) error {
	var err error

	gctx.Writer.Header().Set("Content-Type", "application/json")
	gctx.Writer.Header().Set("Transfer-Encoding", "chunked")
	gctx.Writer.WriteHeader(http.StatusOK)
	gctx.Writer.Write([]byte(`{"new": [`)) //No need to check for errors, the doc says it always returns nil

	// if the blocker just started, return all decisions
	if val, ok := gctx.Request.URL.Query()["startup"]; ok && val[0] == "true" {
		//Active decisions

		err := writeStartupDecisions(gctx, filters, c.DBClient.QueryAllDecisionsWithFilters)

		if err != nil {
			log.Errorf("failed sending new decisions for startup: %v", err)
			gctx.Writer.Write([]byte(`], "deleted": []}`))
			gctx.Writer.Flush()
			return err
		}

		gctx.Writer.Write([]byte(`], "deleted": [`))
		//Expired decisions
		err = writeStartupDecisions(gctx, filters, c.DBClient.QueryExpiredDecisionsWithFilters)
		if err != nil {
			log.Errorf("failed sending expired decisions for startup: %v", err)
			gctx.Writer.Write([]byte(`]}`))
			gctx.Writer.Flush()
			return err
		}

		gctx.Writer.Write([]byte(`]}`))
		gctx.Writer.Flush()
	} else {
		err = writeDeltaDecisions(gctx, filters, bouncerInfo.LastPull, c.DBClient.QueryNewDecisionsSinceWithFilters)
		if err != nil {
			log.Errorf("failed sending new decisions for delta: %v", err)
			gctx.Writer.Write([]byte(`], "deleted": []}`))
			gctx.Writer.Flush()
			return err
		}

		gctx.Writer.Write([]byte(`], "deleted": [`))

		err = writeDeltaDecisions(gctx, filters, bouncerInfo.LastPull, c.DBClient.QueryExpiredDecisionsSinceWithFilters)

		if err != nil {
			log.Errorf("failed sending expired decisions for delta: %v", err)
			gctx.Writer.Write([]byte(`]}`))
			gctx.Writer.Flush()
			return err
		}

		gctx.Writer.Write([]byte(`]}`))
		gctx.Writer.Flush()
	}
	return nil
}

func (c *Controller) StreamDecisionNonChunked(gctx *gin.Context, bouncerInfo *ent.Bouncer, streamStartTime time.Time, filters map[string][]string) error {
	var data []*ent.Decision
	var err error
	ret := make(map[string][]*models.Decision, 0)
	ret["new"] = []*models.Decision{}
	ret["deleted"] = []*models.Decision{}

	if val, ok := gctx.Request.URL.Query()["startup"]; ok {
		if val[0] == "true" {
			data, err = c.DBClient.QueryAllDecisionsWithFilters(filters)
			if err != nil {
				log.Errorf("failed querying decisions: %v", err)
				gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
				return err
			}
			//data = KeepLongestDecision(data)
			ret["new"] = FormatDecisions(data)

			// getting expired decisions
			data, err = c.DBClient.QueryExpiredDecisionsWithFilters(filters)
			if err != nil {
				log.Errorf("unable to query expired decision for '%s' : %v", bouncerInfo.Name, err)
				gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
				return err
			}
			ret["deleted"] = FormatDecisions(data)

			gctx.JSON(http.StatusOK, ret)
			return nil
		}
	}

	// getting new decisions
	data, err = c.DBClient.QueryNewDecisionsSinceWithFilters(bouncerInfo.LastPull, filters)
	if err != nil {
		log.Errorf("unable to query new decision for '%s' : %v", bouncerInfo.Name, err)
		gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
		return err
	}
	//data = KeepLongestDecision(data)
	ret["new"] = FormatDecisions(data)

	// getting expired decisions
	data, err = c.DBClient.QueryExpiredDecisionsSinceWithFilters(bouncerInfo.LastPull.Add((-2 * time.Second)), filters) // do we want to give exactly lastPull time ?
	if err != nil {
		log.Errorf("unable to query expired decision for '%s' : %v", bouncerInfo.Name, err)
		gctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
		return err
	}
	ret["deleted"] = FormatDecisions(data)
	gctx.JSON(http.StatusOK, ret)
	return nil
}

func (c *Controller) StreamDecision(gctx *gin.Context) {
	var err error

	streamStartTime := time.Now().UTC()
	bouncerInfo, err := getBouncerFromContext(gctx)
	if err != nil {
		gctx.JSON(http.StatusUnauthorized, gin.H{"message": "not allowed"})
		return
	}

	if gctx.Request.Method == http.MethodHead {
		//For HEAD, just return as the bouncer won't get a body anyway, so no need to query the db
		//We also don't update the last pull time, as it would mess with the delta sent on the next request (if done without startup=true)
		gctx.String(http.StatusOK, "")
		return
	}

	filters := gctx.Request.URL.Query()
	if _, ok := filters["scopes"]; !ok {
		filters["scopes"] = []string{"ip,range"}
	}

	if fflag.ChunkedDecisionsStream.IsEnabled() {
		err = c.StreamDecisionChunked(gctx, bouncerInfo, streamStartTime, filters)
	} else {
		err = c.StreamDecisionNonChunked(gctx, bouncerInfo, streamStartTime, filters)
	}

	if err == nil {
		//Only update the last pull time if no error occurred when sending the decisions to avoid missing decisions
		if err := c.DBClient.UpdateBouncerLastPull(streamStartTime, bouncerInfo.ID); err != nil {
			log.Errorf("unable to update bouncer '%s' pull: %v", bouncerInfo.Name, err)
		}
	}
}

repository: crowdsecurity/crowdsec

repo_name: crowdsecurity/crowdsec


text:
// Copyright 2022 Dolthub, Inc.
//
// 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 sysbench

import (
	"testing"

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

func TestPopulateHistogram(t *testing.T) {

	tests := []struct {
		name string
		in   []byte
		exp  Result
	}{
		{
			name: "w/ histogram",
			in: []byte(`
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)

Creating table 'sbtest1'...
Inserting 10000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)

Running the test with following options:
Number of threads: 1
Initializing random number generator from seed (1).

Initializing worker threads...

Threads started!

Latency histogram (values are in milliseconds)
       value  ------------- distribution ------------- count
       1.319 |****                                     3
       1.343 |********                                 6
       1.367 |******************                       14
       1.392 |*********************                    17
       1.417 |*******************************          25
       1.443 |**************************************** 32
       1.469 |************************                 19
       1.496 |*******************                      15
       1.523 |******                                   5
       1.551 |******                                   5
       1.579 |********                                 6
       1.608 |********                                 6
       1.637 |******                                   5
       1.667 |***                                      2
       1.697 |*****                                    4
       1.791 |*                                        1
       1.891 |*                                        1
       2.106 |****                                     3
       2.184 |***                                      2
       2.223 |****                                     3
       2.264 |***                                      2
       2.305 |****                                     3
       2.347 |****                                     3
       2.389 |****                                     3
       2.433 |******                                   5
       2.477 |***                                      2
       2.522 |****                                     3
       2.568 |***                                      2
       2.662 |*                                        1
       2.760 |*                                        1
       3.130 |*                                        1

SQL statistics:
    queries performed:
        read:                            200
        write:                           0
        other:                           0
        total:                           200
    transactions:                        200    (609.48 per sec.)
    queries:                             200    (609.48 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          0.3272s
    total number of events:              200

Latency (ms):
         min:                                    1.32
         avg:                                    1.62
         max:                                    3.14
         95th percentile:                        2.43
         sum:                                  324.91

Threads fairness:
    events (avg/stddev):           200.0000/0.00
    execution time (avg/stddev):   0.3249/0.00

sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)

Dropping table 'sbtest1'...`),
			exp: Result{
				time:   .327,
				iters:  200,
				avg:    1.62,
				median: 1.496,
				stddev: .369,
				hist: &Hist{
					bins: []float64{1.319, 1.343, 1.367, 1.392, 1.417, 1.443, 1.469, 1.496, 1.523, 1.551, 1.579, 1.608, 1.637, 1.667, 1.697, 1.791, 1.891, 2.106, 2.184, 2.223, 2.264, 2.305, 2.347, 2.389, 2.433, 2.477, 2.522, 2.568, 2.662, 2.760, 3.130},
					cnts: []int{3, 6, 14, 17, 25, 32, 19, 15, 5, 5, 6, 6, 5, 2, 4, 1, 1, 3, 2, 3, 2, 3, 3, 3, 5, 2, 3, 2, 1, 1, 1},
					cnt:  200,
					mn:   1.623,
					md:   1.496,
					v:    .136,
				},
			},
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			r := &Result{}
			r.populateHistogram(tt.in)
			require.Equal(t, r.String(), tt.exp.String())
		})
	}
}

func TestLogJoin(t *testing.T) {
	t.Skip()
	scriptDir := "/Users/max-hoffman/go/src/github.com/dolthub/systab-sysbench-scripts"
	RunTestsFile(t, "testdata/log-join.yaml", scriptDir)
}

repository: dolthub/dolt

repo_name: dolthub/dolt

branch_name: refs/heads/main


text:
// Code generated by smithy-go-codegen DO NOT EDIT.

package lookoutequipment

import (
	"context"
	"fmt"
	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
	"github.com/aws/aws-sdk-go-v2/service/lookoutequipment/types"
	"github.com/aws/smithy-go/middleware"
	smithyhttp "github.com/aws/smithy-go/transport/http"
)

// Creates a container for a collection of data being ingested for analysis. The
// dataset contains the metadata describing where the data is and what the data
// actually looks like. In other words, it contains the location of the data
// source, the data schema, and other information. A dataset also contains any tags
// associated with the ingested data.
func (c *Client) CreateDataset(ctx context.Context, params *CreateDatasetInput, optFns ...func(*Options)) (*CreateDatasetOutput, error) {
	if params == nil {
		params = &CreateDatasetInput{}
	}

	result, metadata, err := c.invokeOperation(ctx, "CreateDataset", params, optFns, addOperationCreateDatasetMiddlewares)
	if err != nil {
		return nil, err
	}

	out := result.(*CreateDatasetOutput)
	out.ResultMetadata = metadata
	return out, nil
}

type CreateDatasetInput struct {

	// A unique identifier for the request. If you do not set the client request token,
	// Amazon Lookout for Equipment generates one.
	//
	// This member is required.
	ClientToken *string

	// The name of the dataset being created.
	//
	// This member is required.
	DatasetName *string

	// A JSON description of the data that is in each time series dataset, including
	// names, column names, and data types.
	//
	// This member is required.
	DatasetSchema *types.DatasetSchema

	// Provides the identifier of the AWS KMS customer master key (CMK) used to encrypt
	// dataset data by Amazon Lookout for Equipment.
	ServerSideKmsKeyId *string

	// Any tags associated with the ingested data described in the dataset.
	Tags []types.Tag
}

type CreateDatasetOutput struct {

	// The Amazon Resource Name (ARN) of the dataset being created.
	DatasetArn *string

	// The name of the dataset being created.
	DatasetName *string

	// Indicates the status of the CreateDataset operation.
	Status types.DatasetStatus

	// Metadata pertaining to the operation's result.
	ResultMetadata middleware.Metadata
}

func addOperationCreateDatasetMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&awsAwsjson10_serializeOpCreateDataset{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&awsAwsjson10_deserializeOpCreateDataset{}, middleware.After)
	if err != nil {
		return err
	}
	if err = addSetLoggerMiddleware(stack, options); err != nil {
		return err
	}
	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
		return err
	}
	if err = addResolveEndpointMiddleware(stack, options); err != nil {
		return err
	}
	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
		return err
	}
	if err = addRetryMiddlewares(stack, options); err != nil {
		return err
	}
	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
		return err
	}
	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
		return err
	}
	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
		return err
	}
	if err = addClientUserAgent(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = addIdempotencyToken_opCreateDatasetMiddleware(stack, options); err != nil {
		return err
	}
	if err = addOpCreateDatasetValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateDataset(options.Region), middleware.Before); err != nil {
		return err
	}
	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
		return err
	}
	if err = addResponseErrorMiddleware(stack); err != nil {
		return err
	}
	if err = addRequestResponseLogging(stack, options); err != nil {
		return err
	}
	return nil
}

type idempotencyToken_initializeOpCreateDataset struct {
	tokenProvider IdempotencyTokenProvider
}

func (*idempotencyToken_initializeOpCreateDataset) ID() string {
	return "OperationIdempotencyTokenAutoFill"
}

func (m *idempotencyToken_initializeOpCreateDataset) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
) {
	if m.tokenProvider == nil {
		return next.HandleInitialize(ctx, in)
	}

	input, ok := in.Parameters.(*CreateDatasetInput)
	if !ok {
		return out, metadata, fmt.Errorf("expected middleware input to be of type *CreateDatasetInput ")
	}

	if input.ClientToken == nil {
		t, err := m.tokenProvider.GetIdempotencyToken()
		if err != nil {
			return out, metadata, err
		}
		input.ClientToken = &t
	}
	return next.HandleInitialize(ctx, in)
}
func addIdempotencyToken_opCreateDatasetMiddleware(stack *middleware.Stack, cfg Options) error {
	return stack.Initialize.Add(&idempotencyToken_initializeOpCreateDataset{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
}

func newServiceMetadataMiddleware_opCreateDataset(region string) *awsmiddleware.RegisterServiceMetadata {
	return &awsmiddleware.RegisterServiceMetadata{
		Region:        region,
		ServiceID:     ServiceID,
		SigningName:   "lookoutequipment",
		OperationName: "CreateDataset",
	}
}


text:
# CMake generated Testfile for
# Source directory: /Users/chihiro/Programs/opencv/opencv_contrib/modules/tracking
# Build directory: /Users/chihiro/Programs/opencv/opencv/release/modules/tracking
#
# This file includes the relevant testing commands required for
# testing this directory and lists subdirectories to be tested as well.
add_test(opencv_test_tracking "/Users/chihiro/Programs/opencv/opencv/release/bin/opencv_test_tracking" "--gtest_output=xml:opencv_test_tracking.xml")
set_tests_properties(opencv_test_tracking PROPERTIES  LABELS "Extra;opencv_tracking;Accuracy" WORKING_DIRECTORY "/Users/chihiro/Programs/opencv/opencv/release/test-reports/accuracy")
add_test(opencv_perf_tracking "/Users/chihiro/Programs/opencv/opencv/release/bin/opencv_perf_tracking" "--gtest_output=xml:opencv_perf_tracking.xml")
set_tests_properties(opencv_perf_tracking PROPERTIES  LABELS "Extra;opencv_tracking;Performance" WORKING_DIRECTORY "/Users/chihiro/Programs/opencv/opencv/release/test-reports/performance")
add_test(opencv_sanity_tracking "/Users/chihiro/Programs/opencv/opencv/release/bin/opencv_perf_tracking" "--gtest_output=xml:opencv_perf_tracking.xml" "--perf_min_samples=1" "--perf_force_samples=1" "--perf_verify_sanity")
set_tests_properties(opencv_sanity_tracking PROPERTIES  LABELS "Extra;opencv_tracking;Sanity" WORKING_DIRECTORY "/Users/chihiro/Programs/opencv/opencv/release/test-reports/sanity")

repository: chicn/opencv

repo_name: chicn/opencv


text:
macro(ncnn_add_shader NCNN_SHADER_SRC)
    get_filename_component(NCNN_SHADER_SRC_NAME_WE ${NCNN_SHADER_SRC} NAME_WE)
    set(NCNN_SHADER_COMP_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${NCNN_SHADER_SRC_NAME_WE}.comp.hex.h)

    add_custom_command(
        OUTPUT ${NCNN_SHADER_COMP_HEADER}
        COMMAND ${CMAKE_COMMAND} -DSHADER_SRC=${NCNN_SHADER_SRC} -DSHADER_COMP_HEADER=${NCNN_SHADER_COMP_HEADER} -P "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/ncnn_generate_shader_comp_header.cmake"
        DEPENDS ${NCNN_SHADER_SRC}
        COMMENT "Preprocessing shader source ${NCNN_SHADER_SRC_NAME_WE}.comp"
        VERBATIM
    )
    set_source_files_properties(${NCNN_SHADER_COMP_HEADER} PROPERTIES GENERATED TRUE)

    get_filename_component(NCNN_SHADER_COMP_HEADER_NAME ${NCNN_SHADER_COMP_HEADER} NAME)
    string(APPEND layer_shader_spv_data "#include \"${NCNN_SHADER_COMP_HEADER_NAME}\"\n")

    get_filename_component(NCNN_SHADER_SRC_NAME_WE ${NCNN_SHADER_SRC} NAME_WE)
    string(APPEND layer_shader_registry "{${NCNN_SHADER_SRC_NAME_WE}_comp_data,sizeof(${NCNN_SHADER_SRC_NAME_WE}_comp_data)},\n")

    list(APPEND NCNN_SHADER_SPV_HEX_FILES ${NCNN_SHADER_COMP_HEADER})

    # generate layer_shader_type_enum file
    set(layer_shader_type_enum "${layer_shader_type_enum}${NCNN_SHADER_SRC_NAME_WE} = ${__LAYER_SHADER_TYPE_ENUM_INDEX},\n")
    math(EXPR __LAYER_SHADER_TYPE_ENUM_INDEX "${__LAYER_SHADER_TYPE_ENUM_INDEX}+1")
endmacro()


text:
package datahub

import (
	"errors"
	"net/url"

	datahubutils "github.com/containers-ai/alameda/operator/pkg/utils/datahub"
)

type retry struct {
	Interval int64 `mapstructure:"interval"`
	Timeout  int64 `mapstructure:"timeout"`
}

type Config struct {
	Address string `mapstructure:"address"`
	Retry   retry  `mapstructure:"retry"`
}

func NewConfig() *Config {

	c := Config{}
	c.init()
	return &c
}

func (c *Config) init() {
	c.Address = datahubutils.GetDatahubAddress()
	c.Retry = retry{
		Interval: 3,
		Timeout:  30,
	}
}

func (c *Config) Validate() error {

	var err error

	_, err = url.Parse(c.Address)
	if err != nil {
		return errors.New("datahub config validate failed: " + err.Error())
	}

	return nil
}

repository: cochicde/alameda

repo_name: cochicde/alameda


text:
package writer

import (
	"encoding/json"
	"io"
	"strconv"
	"unicode/utf8"
)

const (
	// The maximum size that a byte can be encoded as.
	maxByteEncodeSize = 6

	// The size, in bytes, that can be encoded at a time.
	bufSize = 16384

	// The max size, in bytes, that an encoded value can be.
	actualBufSize = (bufSize * maxByteEncodeSize)
)

var hex = "0123456789abcdef"

type Writer struct {
	w   io.Writer
	buf [actualBufSize + 64]byte
	pos int
}

// NewWriter creates a new JSON writer.
func NewWriter(w io.Writer) *Writer {
	return &Writer{w: w}
}

// Flush writes all data in the buffer to the writer.
func (w *Writer) Flush() error {
	if w.pos > 0 {
		if _, err := w.w.Write(w.buf[0:w.pos]); err != nil {
			return err
		}
		w.pos = 0
	}
	return nil
}

// check verifies there is space in the buffer.
func (w *Writer) check() error {
	if w.pos > actualBufSize {
		return w.Flush()
	}
	return nil
}

// writeByte writes a single byte to the buffer and increments the position.
func (w *Writer) writeByte(c byte) {
	w.buf[w.pos] = c
	w.pos++
}

// writeString writes a string to the buffer and increments the position.
func (w *Writer) writeString(s string) {
	copy(w.buf[w.pos:], s)
	w.pos += len(s)
}

// WriteByte writes a single byte.
func (w *Writer) WriteByte(c byte) error {
	if err := w.check(); err != nil {
		return err
	}
	w.buf[w.pos] = c
	w.pos++
	return nil
}

// WriteString writes a JSON string to the writer. Parts of this function are
// borrowed from the encoding/json package.
func (w *Writer) WriteString(v string) error {
	bufsz := (actualBufSize - w.pos) / maxByteEncodeSize

	w.writeByte('"')
	for i := 0; i < len(v); i += bufsz {
		if i > 0 {
			bufsz = bufSize
			if err := w.Flush(); err != nil {
				return err
			}
		}

		// Extract substring.
		end := i + bufsz
		if end > len(v) {
			end = len(v)
		}
		bufend := end + utf8.UTFMax
		if bufend > len(v) {
			bufend = len(v)
		}
		sub := v[i:bufend]
		sublen := end - i

		prev := 0
		for j := 0; j < sublen; {
			if b := sub[j]; b < utf8.RuneSelf {
				if 0x20 <= b && b != '\\' && b != '"' && b != '<' && b != '>' {
					j++
					continue
				}
				if prev < j {
					w.writeString(sub[prev:j])
				}
				switch b {
				case '\\':
					w.writeByte('\\')
					w.writeByte('\\')
				case '"':
					w.writeByte('\\')
					w.writeByte('"')
				case '\n':
					w.writeByte('\\')
					w.writeByte('n')
				case '\r':
					w.writeByte('\\')
					w.writeByte('r')
				default:
					// This encodes bytes < 0x20 except for \n and \r,
					// as well as < and >. The latter are escaped because they
					// can lead to security holes when user-controlled strings
					// are rendered into JSON and served to some browsers.
					w.writeByte('\\')
					w.writeByte('u')
					w.writeByte('0')
					w.writeByte('0')
					w.writeByte(hex[b>>4])
					w.writeByte(hex[b&0xF])
				}
				j++
				prev = j
				continue
			}
			c, size := utf8.DecodeRuneInString(sub[j:])
			if c == utf8.RuneError && size == 1 {
				return &json.InvalidUTF8Error{S: v}
			}
			j += size

			// If we cross the buffer end then adjust the outer loop
			if j > bufsz {
				i += j - bufsz
				sublen += j - bufsz
			}
		}
		if prev < sublen {
			w.writeString(sub[prev:sublen])
		}
	}
	w.writeByte('"')
	return nil
}

// WriteInt encodes and writes an integer.
func (w *Writer) WriteInt(v int) error {
	return w.WriteInt64(int64(v))
}

// WriteInt64 encodes and writes a 64-bit integer.
func (w *Writer) WriteInt64(v int64) error {
	if err := w.check(); err != nil {
		return err
	}

	buf := strconv.AppendInt(w.buf[w.pos:w.pos], v, 10)
	w.pos += len(buf)
	return nil
}

// WriteUint encodes and writes an unsigned integer.
func (w *Writer) WriteUint(v uint) error {
	return w.WriteUint64(uint64(v))
}

// WriteUint encodes and writes an unsigned integer.
func (w *Writer) WriteUint64(v uint64) error {
	if err := w.check(); err != nil {
		return err
	}

	buf := strconv.AppendUint(w.buf[w.pos:w.pos], v, 10)
	w.pos += len(buf)
	return nil
}

// WriteFloat32 encodes and writes a 32-bit float.
func (w *Writer) WriteFloat32(v float32) error {
	if err := w.check(); err != nil {
		return err
	}
	buf := strconv.AppendFloat(w.buf[w.pos:w.pos], float64(v), 'g', -1, 32)
	w.pos += len(buf)
	return nil
}

// WriteFloat64 encodes and writes a 64-bit float.
func (w *Writer) WriteFloat64(v float64) error {
	if err := w.check(); err != nil {
		return err
	}
	buf := strconv.AppendFloat(w.buf[w.pos:w.pos], v, 'g', -1, 64)
	w.pos += len(buf)
	return nil
}

// WriteBool writes a boolean.
func (w *Writer) WriteBool(v bool) error {
	if err := w.check(); err != nil {
		return err
	}
	if v {
		w.buf[w.pos+0] = 't'
		w.buf[w.pos+1] = 'r'
		w.buf[w.pos+2] = 'u'
		w.buf[w.pos+3] = 'e'
		w.pos += 4
	} else {
		w.buf[w.pos+0] = 'f'
		w.buf[w.pos+1] = 'a'
		w.buf[w.pos+2] = 'l'
		w.buf[w.pos+3] = 's'
		w.buf[w.pos+4] = 'e'
		w.pos += 5
	}
	return nil
}

// WriteNull writes "null".
func (w *Writer) WriteNull() error {
	if err := w.check(); err != nil {
		return err
	}
	w.buf[w.pos+0] = 'n'
	w.buf[w.pos+1] = 'u'
	w.buf[w.pos+2] = 'l'
	w.buf[w.pos+3] = 'l'
	w.pos += 4
	return nil
}

// WriteMap writes a map.
func (w *Writer) WriteMap(v map[string]interface{}) error {
	if err := w.check(); err != nil {
		return err
	}

	w.buf[w.pos] = '{'
	w.pos++

	var index int
	for key, value := range v {
		if index > 0 {
			w.buf[w.pos] = ','
			w.pos++
		}

		// Write key and colon.
		if err := w.WriteString(key); err != nil {
			return err
		}
		w.buf[w.pos] = ':'
		w.pos++

		// Write value.
		if value == nil {
			if err := w.WriteNull(); err != nil {
				return err
			}

		} else {
			switch value := value.(type) {
			case string:
				if err := w.WriteString(value); err != nil {
					return err
				}
			case int:
				if err := w.WriteInt(value); err != nil {
					return err
				}
			case int64:
				if err := w.WriteInt64(value); err != nil {
					return err
				}
			case uint:
				if err := w.WriteUint(value); err != nil {
					return err
				}
			case uint64:
				if err := w.WriteUint64(value); err != nil {
					return err
				}
			case float32:
				if err := w.WriteFloat32(value); err != nil {
					return err
				}
			case float64:
				if err := w.WriteFloat64(value); err != nil {
					return err
				}
			case bool:
				if err := w.WriteBool(value); err != nil {
					return err
				}
			case map[string]interface{}:
				if err := w.WriteMap(value); err != nil {
					return err
				}
			}
		}

		index++
	}

	w.buf[w.pos] = '}'
	w.pos++

	return nil
}

repository: ngaut/megajson

repo_name: ngaut/megajson


text:
/*
 * Copyright 2020 National Library of Norway.
 *
 * 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 session

import (
	"context"
	"encoding/json"
	"fmt"
	"math"
	"net/http"
	"runtime/debug"
	"strconv"
	"strings"
	"time"

	"github.com/chromedp/cdproto/browser"
	"github.com/chromedp/cdproto/cdp"
	"github.com/chromedp/cdproto/fetch"
	"github.com/chromedp/cdproto/network"
	"github.com/chromedp/cdproto/page"
	"github.com/chromedp/cdproto/runtime"
	"github.com/chromedp/cdproto/security"
	"github.com/chromedp/cdproto/serviceworker"
	"github.com/chromedp/cdproto/target"
	"github.com/chromedp/chromedp"
	"github.com/chromedp/chromedp/device"
	"github.com/google/uuid"
	configV1 "github.com/nlnwa/veidemann-api/go/config/v1"
	frontierV1 "github.com/nlnwa/veidemann-api/go/frontier/v1"
	logV1 "github.com/nlnwa/veidemann-api/go/log/v1"
	"github.com/nlnwa/veidemann-browser-controller/database"
	"github.com/nlnwa/veidemann-browser-controller/errors"
	"github.com/nlnwa/veidemann-browser-controller/frontier"
	"github.com/nlnwa/veidemann-browser-controller/logwriter"
	"github.com/nlnwa/veidemann-browser-controller/requests"
	"github.com/nlnwa/veidemann-browser-controller/screenshotwriter"
	"github.com/nlnwa/veidemann-browser-controller/syncx"
	"github.com/nlnwa/whatwg-url/url"
	"github.com/opentracing/opentracing-go"
	tracelog "github.com/opentracing/opentracing-go/log"
	"github.com/rs/zerolog"
	zlog "github.com/rs/zerolog/log"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"google.golang.org/protobuf/types/known/timestamppb"
)

type Session struct {
	Id                int
	ctx               context.Context
	browserHost       string
	browserPort       int
	browserTimeout    int
	proxyHost         string
	proxyPort         int
	browserWsEndpoint string
	workspaceEndpoint string
	UserAgent         string
	browserVersion    string
	Requests          requests.RequestRegistry
	currentLoading    int32
	frameWg           *syncx.WaitGroup
	loadCancel        func()
	netActivityTimer  *syncx.CompletionTimer
	timer             *syncx.CompletionTimer
	RequestedUrl      *frontierV1.QueuedUri
	CrawlConfig       *configV1.CrawlConfig
	browserConfig     *configV1.BrowserConfig
	PolitenessConfig  *configV1.ConfigObject
	configCache       database.ConfigCache
	screenShotWriter  screenshotwriter.ScreenshotWriter
	logWriter         logwriter.LogWriter
	scripts           *sessionScripts
	logger            zerolog.Logger
}

func newDefaultSession(opts ...Option) *Session {
	s := &Session{
		browserHost:    "localhost",
		browserPort:    3000,
		browserTimeout: 500 * 1000,
		proxyPort:      3000,
	}
	for _, opt := range opts {
		opt.apply(s)
	}
	return s
}

func New(sessionId int, opts ...Option) (*Session, error) {
	s := newDefaultSession(opts...)
	s.Id = sessionId
	s.logger = zlog.Logger.With().Int("session", sessionId).Logger()

	ws, err := url.Parse("ws://" + s.browserHost + ":" + strconv.Itoa(s.browserPort))
	if err != nil {
		return nil, err
	}
	query := ws.SearchParams()
	if s.proxyHost != "" {
		proxy := "http://" + s.proxyHost + ":" + strconv.Itoa(s.proxyPort+s.Id)
		query.Set("--proxy-server", proxy)
	}
	query.Append("--ignore-certificate-errors", "")
	query.Append("headless", "true")
	query.Append("timeout", strconv.Itoa(s.browserTimeout))
	query.Append("trackingId", strconv.Itoa(s.Id))

	s.browserWsEndpoint = ws.String()

	work, err := url.Parse("http://" + s.browserHost + ":" + strconv.Itoa(s.browserPort) + "/workspace")
	if err != nil {
		return nil, err
	}
	s.workspaceEndpoint = work.String()

	return s, nil
}

func newDirectSession(uri, crawlExecutionId, jobExecutionId string, opts ...Option) (*Session, error) {
	sess := newDefaultSession(opts...)
	sess.Id = 0

	sess.logger = zlog.Logger.With().
		Str("uri", uri).
		Str("eid", crawlExecutionId).
		Str("jid", jobExecutionId).
		Int("session", sess.Id).
		Str("userAgent", sess.UserAgent).
		Logger()

	QUri := &frontierV1.QueuedUri{
		Uri:            uri,
		ExecutionId:    crawlExecutionId,
		JobExecutionId: jobExecutionId,
	}
	sess.RequestedUrl = QUri

	return sess, nil
}

func (sess *Session) Notify(reqId string) error {
	log := sess.logger

	if reqId == "" {
		log.Warn().Msg("Received notify with empty request ID")
	}
	select {
	case <-sess.ctx.Done():
		return status.Errorf(codes.Canceled, "Session is canceled")
	default:
		if sess.netActivityTimer != nil {
			sess.netActivityTimer.Notify()
		}
		if sess.timer != nil {
			sess.timer.Notify()
		}
		return nil
	}
}

func (sess *Session) Context() context.Context {
	return sess.ctx
}

func (sess *Session) Fetch(ctx context.Context, phs *frontierV1.PageHarvestSpec) (result *frontier.RenderResult, err error) {
	span, ctx := opentracing.StartSpanFromContext(ctx, "fetch")
	defer span.Finish()

	span.SetTag("eid", phs.GetQueuedUri().GetExecutionId()).
		SetTag("jeid", phs.GetQueuedUri().GetJobExecutionId()).
		LogFields(
			tracelog.String("uri", phs.GetQueuedUri().GetUri()),
			tracelog.String("seed", phs.GetQueuedUri().GetSeedUri()),
		)
	sess.logger = sess.logger.With().
		Str("uri", phs.GetQueuedUri().GetUri()).
		Str("eid", phs.GetQueuedUri().GetExecutionId()).
		Logger()
	log := sess.logger

	// Ensure that bugs in implementation is logged and handled
	defer func() {
		if r := recover(); r != nil {
			var fetchError errors.FetchError
			switch v := r.(type) {
			case errors.FetchError:
				fetchError = v
			case error:
				fetchError = errors.New(-5, "Runtime error", v.Error())
			default:
				fetchError = errors.New(-5, "Runtime error", fmt.Sprintf("%s", v))
			}
			// Add stacktrace to error
			fetchError.CommonsError().Detail += "\n" + string(debug.Stack())
			err = fetchError
		}
	}()

	log.Debug().Msg("Start fetch")
	sess.RequestedUrl = phs.GetQueuedUri()
	sess.CrawlConfig = phs.GetCrawlConfig().GetCrawlConfig()

	bConf, err := sess.configCache.GetConfigObject(ctx, sess.CrawlConfig.BrowserConfigRef)
	if err != nil {
		return nil, fmt.Errorf("failed to get browser config: %v", err)
	}
	sess.browserConfig = bConf.GetBrowserConfig()

	sess.PolitenessConfig, err = sess.configCache.GetConfigObject(ctx, sess.CrawlConfig.PolitenessRef)
	if err != nil {
		return nil, fmt.Errorf("failed to get politeness config: %v", err)
	}

	maxTotalTime := time.Duration(sess.browserConfig.PageLoadTimeoutMs) * time.Millisecond
	maxIdleTime := time.Duration(sess.browserConfig.MaxInactivityTimeMs) * time.Millisecond

	if scripts, err := sess.loadScripts(ctx); err != nil {
		return nil, fmt.Errorf("failed to load scripts: %w", err)
	} else {
		sess.scripts = scripts
	}

	allocatorContext, allocatorCancel := chromedp.NewRemoteAllocator(ctx, sess.browserWsEndpoint)
	defer allocatorCancel()
	defer sess.cleanWorkspace()

	// create context
	cdpCtx, cdpCancel := chromedp.NewContext(allocatorContext)
	defer cdpCancel()
	sess.ctx = cdpCtx

	// ensure the first tab is created
	var userAgent string
	if err := chromedp.Run(sess.ctx,
		chromedp.ActionFunc(func(ctx context.Context) error {
			_, sess.browserVersion, _, userAgent, _, err = browser.GetVersion().Do(ctx)
			return err
		}),
	); err != nil {
		return nil, fmt.Errorf("failed to start browser: %w", err)
	}

	var loadCtx context.Context
	loadCtx, sess.loadCancel = context.WithTimeout(sess.ctx, maxTotalTime)
	defer sess.loadCancel()

	sess.frameWg = syncx.NewWaitGroup(loadCtx)
	sess.Requests = requests.NewRegistry(sess.frameWg)

	sess.initListeners(cdpCtx)

	sess.netActivityTimer = syncx.NewCompletionTimer(1*time.Second, maxTotalTime, nil)
	sess.timer = syncx.NewCompletionTimer(maxIdleTime, maxTotalTime, sess.Requests.MatchCrawlLogs)

	sess.UserAgent = sess.browserConfig.UserAgent
	if sess.UserAgent == "" {
		sess.UserAgent = strings.ReplaceAll(userAgent, "HeadlessChrome", "Chrome")
	}

	deviceInfo := &device.Info{
		Name:      "Desktop",
		UserAgent: sess.UserAgent,
		Width:     int64(sess.browserConfig.WindowWidth),
		Height:    int64(sess.browserConfig.WindowHeight),
		Scale:     1,
		Landscape: false,
		Mobile:    false,
		Touch:     false,
	}

	// run task list
	if err := chromedp.Run(sess.ctx,
		security.SetIgnoreCertificateErrors(true),
		network.SetCacheDisabled(true),
		serviceworker.Enable(),
		chromedp.Emulate(deviceInfo),
		fetch.Enable(),
		network.Enable(),
		page.Enable(),
		network.SetCookies(sess.getCookieParams(sess.RequestedUrl)),
		runtime.Enable(),
		target.SetAutoAttach(true, true).WithFlatten(true),
	); err != nil {
		return nil, fmt.Errorf("failed initializing browser: %w", err)
	}

	// Navigate
	fetchStart := time.Now()
	if err := chromedp.Run(loadCtx,
		chromedp.ActionFunc(func(ctx context.Context) error {
			_, _, _, err := page.Navigate(sess.RequestedUrl.Uri).WithTransitionType(page.TransitionTypeOther).Do(ctx)
			return err
		}),
	); err != nil {
		if err == context.Canceled && sess.Requests.InitialRequest().FromCache {
			return nil, errors.New(-4100, "Already seen", "Initial request was found in cache. Url: "+sess.RequestedUrl.Uri)
		} else if err == context.DeadlineExceeded {
			return nil, errors.New(-5004, "Runtime exceeded", "Pageload timed out. Url: "+sess.RequestedUrl.Uri)
		} else {
			return nil, fmt.Errorf("failed navigation: %w", err)
		}
	}

	// Give scripts a chance to start by waiting for network activity to slow down
	_ = sess.netActivityTimer.WaitForCompletion()
	sess.netActivityTimer.Reset()

	if err := sess.executeScripts(loadCtx, configV1.BrowserScript_ON_NEW_DOCUMENT); err != nil {
		log.Warn().
			Str("phase", configV1.BrowserScript_ON_NEW_DOCUMENT.String()).
			Err(err).Msg("Failed to execute scripts")
		return nil, fmt.Errorf("failed executing scripts in %v phase: %w", configV1.BrowserScript_ON_NEW_DOCUMENT, err)
	}
	if err := sess.executeScripts(loadCtx, configV1.BrowserScript_ON_LOAD); err != nil {
		log.Warn().
			Str("phase", configV1.BrowserScript_ON_LOAD.String()).
			Err(err).Msg("Failed to execute scripts")
	}

	// Wait for frames to finish loading
	err = sess.frameWg.Wait()
	switch err {
	case syncx.Cancelled:
		if sess.Requests.InitialRequest().FromCache {
			return nil, errors.New(-4100, "Already seen", "Initial request was found in cache. Url: "+sess.RequestedUrl.Uri)
		}
	case syncx.ExceededMaxTime:
		if sess.Requests.InitialRequest() == nil || sess.Requests.InitialRequest().CrawlLog == nil {
			return nil, errors.New(-5004, "Runtime exceeded", "Pageload timed out. Url: "+sess.RequestedUrl.Uri)
		}
	}

	// Wait for all outstanding requests to receive a response
	err = sess.timer.WaitForCompletion()
	if err != nil {
		log.Warn().Err(err).Msg("Fetch timed out")
	}

	fetchDuration := time.Since(fetchStart)

	sess.Requests.FinalizeResponses(sess.RequestedUrl)

	if sess.CrawlConfig.GetExtra().CreateScreenshot {
		sess.saveScreenshot()
	}
	outlinks := sess.extractOutlinks()
	log.Debug().Msgf("Found %d outlinks.", len(outlinks))
	cookies := sess.extractCookies()

	err = chromedp.Cancel(cdpCtx)
	if err != nil {
		log.Warn().Err(err).Msg("Close browser")
	}

	var crawlLogCount int32
	var bytesDownloaded int64
	var resources []*logV1.PageLog_Resource
	var crawlLogs []*logV1.CrawlLog

	sess.Requests.Walk(func(r *requests.Request) {
		if r.CrawlLog.GetWarcId() != "" {
			crawlLogs = append(crawlLogs, r.CrawlLog)
			crawlLogCount++
			bytesDownloaded += r.CrawlLog.Size
		} else {
			log.Trace().Msgf("Skipping write of %v %v %v, From cache %v, Has CrawlLog: %v", r.RequestId, r.Method, r.Url, r.FromCache, r.CrawlLog != nil)
		}

		if r.CrawlLog != nil {
			resource := &logV1.PageLog_Resource{
				Uri:           r.Url,
				FromCache:     r.FromCache,
				Renderable:    false,
				ResourceType:  r.ResourceType,
				ContentType:   r.CrawlLog.ContentType,
				StatusCode:    r.CrawlLog.StatusCode,
				DiscoveryPath: r.CrawlLog.DiscoveryPath,
				WarcId:        r.CrawlLog.WarcId,
				Referrer:      r.Referrer,
				Error:         r.CrawlLog.Error,
				Method:        r.Method,
			}
			resources = append(resources, resource)
		} else if !r.FromCache {
			log.Warn().Msgf("No crawllog for resource. Skipping %v %v %v. Got new: %v, Got complete %v", r.RequestId, r.Method, r.Url, r.GotNew, r.GotComplete)
		}
	})
	if err := sess.logWriter.WriteCrawlLogs(ctx, crawlLogs); err != nil {
		log.Error().Err(err).Msg("Writing crawl logs")
	} else {
		log.Debug().Msgf("Wrote %d crawlLogs", len(crawlLogs))
	}

	if sess.Requests.InitialRequest() != nil && sess.Requests.InitialRequest().CrawlLog != nil {
		warcId := sess.Requests.InitialRequest().CrawlLog.WarcId
		if warcId == "" {
			warcId = uuid.New().String()
		}
		pageLog := &logV1.PageLog{
			WarcId:              warcId,
			Uri:                 sess.RequestedUrl.Uri,
			ExecutionId:         sess.RequestedUrl.ExecutionId,
			Referrer:            sess.Requests.InitialRequest().Referrer,
			JobExecutionId:      sess.RequestedUrl.JobExecutionId,
			CollectionFinalName: sess.Requests.InitialRequest().CrawlLog.CollectionFinalName,
			Method:              sess.Requests.InitialRequest().Method,
			Resource:            resources,
			Outlink:             outlinks,
		}
		if err := sess.logWriter.WritePageLog(ctx, pageLog); err != nil {
			log.Error().Err(err).Msg("Error writing pageLog")
		} else {
			log.Debug().Msg("Pagelog written")
		}
	} else {
		return nil, fmt.Errorf("missing initial request: %w", err)
	}

	qUris := make([]*frontierV1.QueuedUri, len(outlinks))
	for i, uri := range outlinks {
		qUris[i] = &frontierV1.QueuedUri{
			ExecutionId:         sess.RequestedUrl.ExecutionId,
			DiscoveredTimeStamp: timestamppb.Now(),
			Uri:                 uri,
			DiscoveryPath:       sess.Requests.RootRequest().CrawlLog.DiscoveryPath + "L",
			Referrer:            sess.Requests.RootRequest().Url,
			Cookies:             cookies,
			JobExecutionId:      sess.RequestedUrl.JobExecutionId,
		}
	}
	result = &frontier.RenderResult{
		BytesDownloaded: bytesDownloaded,
		UriCount:        crawlLogCount,
		Outlinks:        qUris,
		Error:           sess.Requests.InitialRequest().CrawlLog.Error,
		PageFetchTimeMs: fetchDuration.Milliseconds(),
	}

	log.Debug().Msg("Fetch done")
	return result, nil
}

// cleanWorkspace removes downloaded resources in browser container
func (sess *Session) cleanWorkspace() {
	log := sess.logger

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	r, err := http.NewRequestWithContext(ctx, "DELETE", sess.workspaceEndpoint+"/"+strconv.Itoa(sess.Id), nil)
	if err != nil {
		log.Warn().Err(err).Msg("Error creating request for cleaning up workspace")
	}
	if resp, err := http.DefaultClient.Do(r); err != nil {
		log.Warn().Err(err).Msg("Error cleaning up workspace")
	} else {
		_ = resp.Body.Close()
	}
}

func (sess *Session) getCookieParams(uri *frontierV1.QueuedUri) []*network.CookieParam {
	log := sess.logger

	log.Debug().Msgf("Restoring %v browser cookies", len(uri.GetCookies()))
	cookies := make([]*network.CookieParam, len(uri.GetCookies()))
	for i, c := range uri.GetCookies() {
		expSec, expNsec := math.Modf(c.Expires)
		expires := cdp.TimeSinceEpoch(time.Unix(int64(expSec), int64(expNsec*(1e9))))

		cookies[i] = &network.CookieParam{
			Name:     c.Name,
			Value:    c.Value,
			URL:      uri.Uri,
			Domain:   c.Domain,
			Path:     c.Path,
			Secure:   c.Secure,
			HTTPOnly: c.HttpOnly,
			SameSite: network.CookieSameSite(c.SameSite),
			Expires:  &expires,
		}
	}
	return cookies
}

func (sess *Session) extractCookies() []*frontierV1.Cookie {
	log := sess.logger
	var result []*frontierV1.Cookie

	if err := chromedp.Run(sess.ctx,
		chromedp.ActionFunc(func(ctx context.Context) error {
			cookies, err := network.GetAllCookies().Do(ctx)
			if err != nil {
				return err
			}

			result = make([]*frontierV1.Cookie, len(cookies))
			for i, c := range cookies {
				result[i] = &frontierV1.Cookie{
					Name:     c.Name,
					Value:    c.Value,
					Domain:   c.Domain,
					Path:     c.Path,
					Expires:  c.Expires,
					Size:     int32(c.Size),
					HttpOnly: c.HTTPOnly,
					Secure:   c.Secure,
					Session:  c.Session,
					SameSite: c.SameSite.String(),
				}
			}
			return nil
		}),
	); err != nil {
		log.Error().Err(err).Msg("Could not extract cookies")
	}

	return result
}

func (sess *Session) saveScreenshot() {
	log := sess.logger

	span, ctx := opentracing.StartSpanFromContext(sess.ctx, "screenshot")
	defer span.Finish()
	// Skip screenshot of pages loaded from cache
	if sess.Requests.RootRequest().FromCache {
		log.Debug().Str("resourceType", sess.Requests.RootRequest().ResourceType).Msgf("Skipping screenshot: from cache")
		return
	}
	// Check if page is renderable
	if sess.Requests.RootRequest().ResourceType != "Document" && sess.Requests.RootRequest().ResourceType != "Image" {
		log.Debug().Str("resourceType", sess.Requests.RootRequest().ResourceType).Msgf("Skipping screenshot: not renderable")
		return
	}
	// Check if CrawlLog is present for root request
	if sess.Requests.RootRequest().CrawlLog == nil {
		log.Debug().Str("resourceType", sess.Requests.RootRequest().ResourceType).Msgf("Skipping screenshot: missing crawlLog")
		return
	}
	// Check if CrawlLog has WarcId
	if sess.Requests.RootRequest().CrawlLog.WarcId == "" {
		log.Debug().Str("resourceType", sess.Requests.RootRequest().ResourceType).Msgf("Skipping screenshot: crawlLog has empty warcId")
		return
	}
	var data []byte
	err := chromedp.Run(ctx,
		chromedp.ActionFunc(func(ctx context.Context) (err error) {
			data, err = page.CaptureScreenshot().WithFormat(page.CaptureScreenshotFormatPng).Do(ctx)
			return
		}),
	)
	if err != nil {
		log.Error().Err(err).Msg("Error capturing screenshot")
		return
	}
	metadata := screenshotwriter.Metadata{
		CrawlConfig:    sess.CrawlConfig,
		CrawlLog:       sess.Requests.RootRequest().CrawlLog,
		BrowserConfig:  sess.browserConfig,
		BrowserVersion: sess.browserVersion,
	}
	if err = sess.screenShotWriter.Write(ctx, data, metadata); err != nil {
		log.Error().Err(err).Msg("Error writing screenshot")
		return
	}
}

func (sess *Session) extractOutlinks() []string {
	var extractedUrls []string

	for _, s := range sess.scripts.Get(configV1.BrowserScript_EXTRACT_OUTLINKS) {
		log := sess.logger.With().
			Str("scriptType", configV1.BrowserScript_EXTRACT_OUTLINKS.String()).
			Str("scriptId", s.GetId()).
			Logger()

		var res *runtime.RemoteObject
		var exceptionDetails *runtime.ExceptionDetails
		err := chromedp.Run(sess.ctx,
			chromedp.ActionFunc(func(ctx context.Context) (err error) {
				res, exceptionDetails, err = runtime.Evaluate(s.GetBrowserScript().GetScript()).
					WithReturnByValue(true).Do(ctx)
				return err
			}),
		)
		if err != nil {
			log.Warn().Err(err).Msgf("Failed to evaluate script")
			continue
		}
		if exceptionDetails != nil {
			log.Warn().Err(exceptionDetails).Msgf("Exception during script evaluation")
			continue
		}
		if res.Value != nil {
			var links []string
			err := json.Unmarshal(res.Value, &links)
			if err != nil {
				log.Warn().Err(err).Msgf("Failed to unmarshal return value")
				continue
			}

			for _, link := range links {
				link = strings.TrimSpace(link)
				link = strings.Trim(link, "\"\\")
				if link != "" && link != sess.Requests.RootRequest().Url {
					extractedUrls = append(extractedUrls, link)
				}
			}
		}
	}

	return extractedUrls
}

func (sess *Session) AbortFetch() error {
	defer sess.loadCancel()
	defer sess.frameWg.Cancel()
	return chromedp.Run(sess.ctx, page.StopLoading())
}

repository: nlnwa/veidemann-browser-controller

repo_name: nlnwa/veidemann-browser-controller


text:
@Article{Dong2020,
  Title                    = {An interactive web-based dashboard to track COVID-19 in real time},
  Author                   = {{Dong E, Du H, Gardner L}},
  Year                     = {2020},

  Type                     = {Journal Article},
  Url                      = {https://github.com/CSSEGISandData/COVID-19}
}


text:
/*
The MIT License (MIT)

Copyright (c) 2016 ALT-F1, We believe in the projects we work on

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

// Package helloworld displays helloworld and the amount of time the invoke method as been called
package main

import (
	"errors"
	"fmt"
	"strconv"

	"github.com/hyperledger/fabric/core/chaincode/shim"
)

// var myLogger = logging.MustGetLogger("asset_mgm")
var myLogger = shim.NewLogger("chaincode_helloworld")

// HelloWorld example simple Chaincode implementation
type HelloWorld struct {
}

func main() {
	myLogger.Debug("HelloWorld Main\n")
	err := shim.Start(new(HelloWorld))
	//err := shim.Start(new(HelloWorld))
	if err != nil {
		fmt.Printf("Error starting HelloWorld chaincode: %s\n", err)
	}
}
// Init is called during Deploy transaction after the container has been
// func (t *HelloWorld) Init(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
func (t *HelloWorld) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
	myLogger.Debug("HelloWorld Init is called!")

	if len(args) != 0 {
		return nil, errors.New("Incorrect number of arguments. Expecting 0")
	}

	// Set the admin
	// The metadata will contain the certificate of the administrator

	err := stub.PutState("noHelloWorlds", []byte("0"))
	if err != nil {
		return nil, err
	}

	myLogger.Debug("Init HelloWorld...done")

	return nil, nil
}

// Invoke is called for every Invoke transactions. The chaincode may change
// its state variables
//func (t *HelloWorld) Invoke(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
func (t *HelloWorld) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
	fmt.Printf("HelloWorld in Invoke with function %s!\n", function)
	if function != "invoke" {
		return nil, errors.New("Invalid invoke function name. Expecting \"invoke\"")
	}

	b, err := stub.GetState("noHelloWorlds")
	if err != nil {
		return nil, errors.New("Failed to get state")
	}
	noevts, _ := strconv.Atoi(string(b))

	var theArgs string

	for _, s := range args {
		theArgs = theArgs + "," + s
	}
	fmt.Printf("theArgs: %s ", theArgs)

	err = stub.PutState("noHelloWorlds", []byte(strconv.Itoa(noevts+1)))
	if err != nil {
		return nil, err
	}

	return nil, nil
}

// Query is called for Query transactions. The chaincode may only read
// (but not modify) its state variables and return the result
//func (t *HelloWorld) Query(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
func (t *HelloWorld) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
	myLogger.Debug("HelloWorld Query is called!\n")
	if function != "query" {
		return nil, errors.New("Invalid query function name. Expecting \"query\"")
	}

	b, err := stub.GetState("noHelloWorlds")
	if err != nil {
		return nil, errors.New("Failed to get state")
	}
	jsonResp := "{\"NoHelloWorlds\":\"" + string(b) + "\"}"
	return []byte(jsonResp), nil
}

repository: tjclifford/learn-chaincode

repo_name: tjclifford/learn-chaincode


text:
package main

import (
	"debug/elf"
	"encoding/json"
	"fmt"
	"log"
	"os"
	"os/exec"
	"strings"

	"github.com/opencontainers/runtime-spec/specs-go"
)

func openElf(filename string) *elf.File {
	bin, err := os.OpenFile(filename, os.O_RDONLY, 0)
	if err != nil {
		log.Fatalln("can't open file", err)
	}

	f, err := elf.NewFile(bin)
	if err != nil {
		log.Fatalln("elf read error", err)
	}

	return f
}

// Verify if the binary is a go executable.
func isGoBinary(file *elf.File) bool {

	if sect := file.Section(".gosymtab"); sect != nil {
		return true
	}

	if sect := file.Section(".note.go.buildid"); sect != nil {
		return true
	}
	return false
}

// convert debug/elf based name to specs.Arch
func getArch(file *elf.File) specs.Arch {
	var arch specs.Arch

	switch file.Machine.String() {
	case "EM_X86_64":
		arch = specs.ArchX86_64
	case "EM_386":
		arch = specs.ArchX86
	case "EM_ARM":
		arch = specs.ArchARM
	default:
		log.Fatalf("Unsuported arch : %v\n", file.Machine.String())
	}

	fmt.Println("Arch : ", arch)
	return arch
}

// write the seccomp profile to the profilePath file given an architecture and a list of syscalls (name)
func writeProfile(syscallsList []string, arch specs.Arch, profilePath string) {

	profile := specs.LinuxSeccomp{
		DefaultAction: specs.ActErrno,
		Architectures: []specs.Arch{arch},
		Syscalls: []specs.LinuxSyscall{
			specs.LinuxSyscall{
				Names:  syscallsList,
				Action: specs.ActAllow,
			},
		},
	}

	profileFile, err := os.Create(profilePath)
	if err != nil {
		log.Fatalf("Failed to create seccomp profile: %v", err)
	}
	defer profileFile.Close()

	enc := json.NewEncoder(profileFile)
	enc.SetIndent("", "    ")
	enc.Encode(profile)
	fmt.Printf("Saved seccomp profile at %v\n", profilePath)
}

// run go tool objdump (objdump for go)
func disassamble(binaryPath string) *os.File {
	disassambled, err := os.Create("disassembled.asm")

	if err != nil {
		log.Fatalf("Failed to disassembling output file, reason: %v", err)
	}

	fmt.Printf("Using go tool objdump to disassemble %v\n", binaryPath)
	cmd := exec.Command("go", "tool", "objdump", binaryPath)
	cmd.Stdout = disassambled
	err = cmd.Run()

	if err != nil {
		log.Fatalf("Couldn't run go tool objdump: %v\n", err)
	}

	// Point to the beginning of the disassembled binary to start looking for syscalls
	disassambled.Seek(0, 0)
	return disassambled
}

func getCallOpByArch(arch specs.Arch) string {
	var j string

	switch arch {
	case specs.ArchX86_64, specs.ArchX86:
		j = "CALL "
	case specs.ArchARM:
		j = "BL "
	default:
		log.Fatalln("Arch not suppported")
	}

	return j
}

func parseFunctionName(instruction string) string {
	texts := strings.Split(instruction, " ")
	currentFunction := texts[1]
	if verbose {
		fmt.Printf("Entering function %v\n", currentFunction)
	}
	return currentFunction
}

func isSyscallPkgCall(arch specs.Arch, instruction string) bool {
	j := getCallOpByArch(arch)
	return strings.Contains(instruction, j+"syscall.Syscall(SB)") || strings.Contains(instruction, j+"syscall.Syscall6(SB)") ||
		strings.Contains(instruction, j+"syscall.RawSyscall(SB)") || strings.Contains(instruction, j+"syscall.RawSyscall6(SB)") ||
		strings.Contains(instruction, j+"syscall.rawVforkSyscall(SB)")
}

func isRuntimeSyscall(arch specs.Arch, instruction, currentFunction string) bool {
	// SYSCALL => x86_64, INT 0x80 => x86, SVC or SWI => ARM
	var isRuntimeSC bool
	switch arch {
	case specs.ArchX86:
		isRuntimeSC = (strings.Contains(instruction, "INT $0x80") || strings.Contains(instruction, "SYSENTER"))
	case specs.ArchX86_64:
		// there are SYSCALL instructions in each of the 5 functions on the syscall package, so we ignore those
		isRuntimeSC = strings.Contains(instruction, "SYSCALL") &&
			!strings.Contains(currentFunction, "syscall.Syscall") &&
			!strings.Contains(currentFunction, "syscall.RawSyscall") &&
			!strings.Contains(currentFunction, "syscall.rawVforkSyscall")
	case specs.ArchARM:
		isRuntimeSC = strings.Contains(instruction, "SVC $0") || strings.Contains(instruction, "SWI $0")
	}
	return isRuntimeSC
}

// Got these from https://github.com/moby/moby/issues/22252
// Even if they are not found in the binary, they are needed for starting the container
func getDefaultSyscalls(arch specs.Arch) map[int64]bool {
	syscalls := make(map[int64]bool)
	switch arch {

	case specs.ArchX86_64:
		// futex
		syscalls[202] = true
		// stat
		syscalls[4] = true
		// execve
		syscalls[59] = true
	case specs.ArchX86:
		// futex
		syscalls[240] = true
		// stat
		syscalls[106] = true
		// execve
		syscalls[11] = true
	case specs.ArchARM:
		// futex
		syscalls[240] = true
		// stat
		syscalls[106] = true
		// execve
		syscalls[11] = true
	default:
		log.Fatalln(arch, "not supported")
	}

	return syscalls
}


text:
package calendar

import "testing"

func TestRandomStringURLSafe(t *testing.T) {
	for i := 0; i < 10; i++ {
		res, err := randomStringURLSafe(i)
		if err != nil {
			t.Errorf("randomStringURLSafe(%d): returned an error %v", i, err)
		}

		actual := len(res)
		if actual != i {
			t.Errorf("randomStringURLSafe(%d): expected %d, actual %d", i, i, actual)
		}
	}
}

repository: davidepedranz/alfred-timetracker

repo_name: davidepedranz/alfred-timetracker


text:
SECTION = "devel/chicken"
DESCRIPTION = "A Scheme view server for Apache CouchDB"
LICENSE = "LGPLv2+"
LIC_FILES_CHKSUM = "file://couchdb-view-server.meta;md5=13906910cf6fd31442a523a5684ce398"
DEPENDS_append_class-cross = " chicken-egg-json-cross chicken-egg-environments-cross"
DEPENDS_append_class-crosssdk = " chicken-egg-json-crosssdk chicken-egg-environments-crosssdk"
DEPENDS_append_class-nativesdk = " nativesdk-chicken-egg-json nativesdk-chicken-egg-environments chicken-egg-json-crosssdk chicken-egg-environments-crosssdk"
DEPENDS = " chicken-egg-json chicken-egg-environments chicken-egg-json-cross chicken-egg-environments-cross"
RDEPENDS_${PN} = " chicken-egg-json chicken-egg-environments"

SRC_URI = "http://code.call-cc.org/egg-tarballs/4/couchdb-view-server/couchdb-view-server-${PV}.tar.gz"

SRC_URI[md5sum] = "375fc3d707faa6dbf3982c6556450792"
SRC_URI[sha256sum] = "e25903d4f2407653539fad58b9417bb8658cc74311843eb3a3f0966f4287a0cf"

S = "${WORKDIR}/couchdb-view-server-${PV}"

inherit chicken_install

BBCLASSEXTEND = "cross crosssdk nativesdk"

repository: OSSystems/meta-chicken

repo_name: OSSystems/meta-chicken


text:
SUMARY = "Corstone1000 platform Image"
DESCRIPTION = "This is the main image which is the container of all the binaries \
               generated for the Corstone1000 platform."
LICENSE = "MIT"

COMPATIBLE_MACHINE = "corstone1000"

inherit image
inherit wic_nopt tfm_sign_image

PACKAGE_INSTALL = ""

IMAGE_FSTYPES += "wic wic.nopt"

do_sign_images() {
    # Sign TF-A BL2
    sign_host_image ${RECIPE_SYSROOT}/firmware/${TFA_BL2_BINARY} \
        ${TFA_BL2_RE_IMAGE_LOAD_ADDRESS} ${TFA_BL2_RE_SIGN_BIN_SIZE}

    # Update BL2 in the FIP image
    cp ${RECIPE_SYSROOT}/firmware/${TFA_FIP_BINARY} .
    fiptool update --tb-fw ${TFM_IMAGE_SIGN_DIR}/signed_${TFA_BL2_BINARY} \
        ${TFM_IMAGE_SIGN_DIR}/${TFA_FIP_BINARY}

    # Sign the FIP image
    sign_host_image ${TFM_IMAGE_SIGN_DIR}/${TFA_FIP_BINARY} \
        ${TFA_FIP_RE_IMAGE_LOAD_ADDRESS} ${TFA_FIP_RE_SIGN_BIN_SIZE}
}
do_sign_images[depends] = "\
    trusted-firmware-a:do_populate_sysroot \
    fiptool-native:do_populate_sysroot \
    "

repository: dphadke-msft/openbmc

repo_name: dphadke-msft/openbmc

gha_license_id: NOASSERTION


text:
@article{Knight-Madden2006a,
 abstract = {BACKGROUND: The active ingredients of marijuana may have beneficial properties in the treatment of chronic pain and inflammation and is being used by sufferers of chronic pain and arthritis in some settings. Anecdotally, marijuana is believed by some sickle cell disease (SCD) patients to improve their health. This study aimed to determine the prevalence of marijuana smoking in the Jamaica Sickle Cell Cohort Study (JSCCS) in the years 2000 and 2004. The perception that marijuana use ameliorated the complications of SCD was also investigated. METHODS: All patients in the JSCCS were invited to attend an annual review, and during the 2000 and 2004 reviews, participants with homozygous sickle cell (SS) disease and sickle cell haemoglobin-C (SC) disease were asked whether they smoked marijuana, and if they smoked, whether it was used for medicinal purposes related to SCD. The authors compared smoking prevalence by gender, disease, and year of review. The association of smoking with a measure of pain frequency was also examined. RESULTS: The prevalence of marijuana smoking was higher among men and among SC participants. The proportion of either gender reporting smoking of marijuana increased in 2004 compared to 2000, and this use was not related to a simple measure of clinical severity of SCD. CONCLUSIONS: Marijuana smoking is common in adults with SCD but its usage is unrelated to clinical severity of the disease.},
 address = {Jamaica},
 author = {Knight-Madden, J. and Lewis, N. and Hambleton, I. R.},
 completed = {20070306},
 doi = {10.1590/s0043-31442006000400004},
 history = {2007/01/26 09:00 [entrez]},
 issue = {4},
 journal = {The West Indian medical journal},
 keywords = {Adolescent, Adult, Age Factors, Anemia, Sickle Cell/drug therapy/*physiopathology, Anti-Inflammatory Agents, Female, Humans, *Illicit Drugs, Inflammation/drug therapy/etiology, Jamaica/epidemiology, Male, Marijuana Smoking/*epidemiology, Pain/drug therapy/etiology, Prevalence, Prospective Studies},
 language = {eng},
 linking-issn = {0043-3144},
 month = {Sep},
 nlm-unique-id = {0417410},
 owner = {NLM},
 pages = {224-7},
 print-issn = {0043-3144},
 publication-status = {ppublish},
 registry-number = {0 (Illicit Drugs)},
 revised = {20191210},
 source = {West Indian Med J. 2006 Sep;55(4):224-7. doi: 10.1590/s0043-31442006000400004.},
 status = {MEDLINE},
 subset = {IM},
 title = {The prevalence of marijuana smoking in young adults with sickle cell disease: a longitudinal study.},
 title-abbreviation = {West Indian Med J},
 volume = {55},
 year = {2006}
}


text:
@book{rasmussenGaussianProcessesMachine2006,
  title = {Gaussian Processes for Machine Learning},
  author = {Rasmussen, Carl Edward and Williams, Christopher K. I.},
  date = {2006},
  publisher = {{MIT Press}},
  location = {{Cambridge, Mass}},
  file = {/Users/sergiusmath/Zotero/storage/JPDLE9TR/Rasmussen and Williams - 2006 - Gaussian processes for machine learning.pdf},
  isbn = {978-0-262-18253-9},
  keywords = {Data processing,Gaussian processes,Machine learning,Mathematical models},
  langid = {english},
  note = {OCLC: ocm61285753},
  pagetotal = {248},
  series = {Adaptive Computation and Machine Learning}
}

repository: SergiusMath/itn-windmill-reading-group

repo_name: SergiusMath/itn-windmill-reading-group

gha_language: TeX


text:
package licensing

import (
	"bytes"
	"crypto/hmac"
	"crypto/sha256"
	"encoding/base64"
	"encoding/json"
	"io/ioutil"
	"net/http"
	"testing"
	"time"

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

func TestPingerMF2(t *testing.T) {
	l := LicenseMF2{
		PublicKey:  "012345678901234567890123456789ab",
		PrivateKey: "ab012345678901234567890123456789",
	}

	doer := &DoerMock{
		DoFunc: func(r *http.Request) (*http.Response, error) {
			keyID := r.Header.Get(HTTPHeaderKeyID)
			sig := r.Header.Get(HTTPHeaderSignature)
			require.Len(t, keyID, 32)
			require.NotEqual(t, "", sig)

			body, err := ioutil.ReadAll(r.Body)
			if err != nil {
				return nil, err
			}

			// validate the signature
			mac := hmac.New(sha256.New, []byte(l.PrivateKey))
			mac.Write([]byte(body))
			require.Equal(t, base64.StdEncoding.EncodeToString(mac.Sum(nil)), sig)

			// validate the timestamp in the body
			var reqBody PingRequestMF2
			require.NoError(t, json.Unmarshal(body, &reqBody))
			require.False(t, reqBody.CurrentTime.IsZero())
			require.InDelta(t, time.Now().Unix(), reqBody.CurrentTime.Unix(), 1)

			signedResp, err := Sign(testLicenseKeyPrivate, &PingResponseMF2{Enabled: true})
			require.NoError(t, err)
			b, err := json.Marshal(&EnvelopePingResponse{Payload: signedResp})
			require.NoError(t, err)

			return &http.Response{
				Body:       ioutil.NopCloser(bytes.NewReader(b)),
				StatusCode: http.StatusOK,
			}, nil
		},
	}

	pinger := l.Pinger(doer, testLicenseKeyPublic)

	resp, err := pinger.Ping()
	require.NoError(t, err)
	require.True(t, resp.Enabled)
}

repository: graymeta/gmkit

repo_name: graymeta/gmkit


text:
DESCRIPTION = "A text-based bootmanager allowing a Zaurus to boot from SD or CF. \
Tested machines: Collie, Poodle, Akita, Spitz"
SECTION = "base"
PRIORITY = "optional"
MAINTAINER = "Matthias 'CoreDump' Hentges  <oe@hentges.net>"
LICENSE = "GPL"

PV = "0.0.1+cvs-${CVSDATE}"
PR = "r3"

SRC_URI = "file://altboot-menu \
	   file://altboot.rc \
	   file://altboot.func \
	   file://init.altboot \
	   file://altboot.cfg"

# S = "${WORKDIR}/files"

do_install() {
	install -d ${D}/sbin
	install -d ${D}/etc/altboot-menu
	install -d ${D}/etc/altboot-menu/Advanced
	install -d ${D}/etc/altboot.rc
	install -d ${D}/usr/share/doc/altboot

	install -m 0644 ${WORKDIR}/altboot.cfg ${D}/etc
	install -m 0644 ${WORKDIR}/altboot.func ${D}/etc
#	install -m 0644 ${WORKDIR}/docs/altboot/*.txt ${D}/usr/share/doc/altboot
	install -m 0755 ${WORKDIR}/init.altboot ${D}/sbin
	install -m 0755 ${WORKDIR}/altboot-menu/*-* ${D}/etc/altboot-menu
	install -m 0755 ${WORKDIR}/altboot-menu/Advanced/*-* ${D}/etc/altboot-menu/Advanced
}

pkg_postinst() {
	update-alternatives --install /sbin/init init /sbin/init.altboot 55
}

pkg_postinst_spitz() {

	# Note: Spitz support is a royal pain in the ass.
	#       Since Spitz pivot_roots by default, there is no real way
	#	a user can install an altboot.ipk into the flash FS.
	#	So we need to do that manually (*SIGH*)

	# /l/m only exists on the HDD on spitz
	if test -d /lib/modules
	then
		# FIXME: Do be written
		a=a # do nothing
	fi
}

pkg_postrm() {
	update-alternatives --remove init /sbin/init.altboot
}

pkg_postrm_spitz() {
	# FIXME: To be written
	a=a # do nothing
}

repository: BackupTheBerlios/openslug-svn

repo_name: BackupTheBerlios/openslug-svn


text:
require ninvaders.inc

# source URI and checksum for ninvaders source files
SRC_URI = "${SOURCEFORGE_MIRROR}/ninvaders/${BPN}-${PV}.tar.gz"
SRC_URI[sha256sum] = "bfbc5c378704d9cf5e7fed288dac88859149bee5ed0850175759d310b61fd30b"

# license file and checksum within the extracted source tarball
LIC_FILES_CHKSUM = "file://gpl.txt;md5=393a5ca445f6965873eca0259a17f833"

# ncurses is a build- and runtime dependency
DEPENDS = "ncurses"
RDEPENDS_${PV} = "ncurses"

# fix build issue to make make find the ncurses lib
EXTRA_OEMAKE = "-e"

# patch nInvaders.c to use joystick support
SRC_URI += "file://joystick-support.patch"

repository: tknerr/yocto-meta-zuehlkelabs

repo_name: tknerr/yocto-meta-zuehlkelabs


text:
DESCRIPTION = "A library that provides automatic proxy configuration management"
HOMEPAGE = "http://code.google.com/p/libproxy/"
BUGTRACKER = "http://code.google.com/p/libproxy/issues/list"
SECTION = "libs"
LICENSE = "LGPLv2.1+"
LIC_FILES_CHKSUM = "file://COPYING;md5=7d7044444a7b1b116e8783edcdb44ff4 \
                    file://utils/proxy.c;beginline=1;endline=18;md5=55152a1006d7dafbef32baf9c30a99c0"

DEPENDS = "gconf"

PR = "r4"

SRC_URI = "http://libproxy.googlecode.com/files/libproxy-${PV}.tar.gz \
           file://g++-namepace.patch \
           file://libproxy_fix_for_gcc4.7.patch \
           file://libproxy-0.4.7-CVE-2012-4504.patch \
          "

SRC_URI[md5sum] = "509e03a488a61cd62bfbaf3ab6a2a7a5"
SRC_URI[sha256sum] = "8fe0a58810139ba3c2e186deccf3e68adcd127aa0e972b0862b30b3dde493797"

inherit cmake pkgconfig

EXTRA_OECMAKE = "-DWITH_WEBKIT=no -DWITH_GNOME=yes -DWITH_KDE4=no \
	      -DWITH_PYTHON=no -DWITH_PERL=no -DWITH_MOZJS=no -DWITH_NM=no -DLIB_INSTALL_DIR=${libdir}"

FILES_${PN} += "${libdir}/${BPN}/${PV}/modules"
FILES_${PN}-dev += "${datadir}/cmake"
FILES_${PN}-dbg += "${libdir}/${BPN}/${PV}/plugins/.debug/ ${libdir}/${BPN}/${PV}/modules/.debug/"

do_configure_prepend() {
	export HOST_SYS=${HOST_SYS}
	export BUILD_SYS=${BUILD_SYS}
}

python() {
    if base_contains("INCOMPATIBLE_LICENSE", "GPLv3", "x", "", d) == "x" or base_contains("DISTRO_FEATURES", "x11", "x", "", d) == "":
        d.setVar("EXTRA_OECMAKE", d.getVar("EXTRA_OECMAKE").replace("-DWITH_GNOME=yes", "-DWITH_GNOME=no"))
        d.setVar("DEPENDS", " ".join(i for i in d.getVar("DEPENDS").split() if i != "gconf"))
}

repository: mmoselhy/temp

repo_name: mmoselhy/temp


text:
package githubcommit

import (
	"regexp"
	"strings"
)

// Commit is commit data
type Commit interface {
	GetRepo() string
	GetOwner() string
	GetRepoName() string
	GetHash() string
	IsPR() bool
	GetPRNumber() int
	GetPRID() string
	GetBaseRefName() string
	Error() error
}

type commit struct {
	repo         string
	hash         string
	err          error
	isPR         bool
	prNumbers    []int
	prID         []string
	baseRefNames []string
}

func (c *commit) GetRepo() string {
	return c.repo
}

func (c *commit) GetOwner() string {
	ownerAndRepo := strings.Split(c.repo, "/")
	return ownerAndRepo[0]
}

func (c *commit) GetRepoName() string {
	r := regexp.MustCompile(`([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)`)

	m := r.FindStringSubmatch(c.repo)
	if m == nil {
		return ""
	}

	return m[2]
}

func (c *commit) GetHash() string {
	return c.hash
}

func (c *commit) Error() error {
	return c.err
}

func (c *commit) IsPR() bool {
	return c.isPR
}

func (c *commit) GetPRNumber() int {
	if len(c.prNumbers) > 0 {
		return c.prNumbers[0]
	}

	return 0
}

func (c *commit) GetPRID() string {
	if len(c.prID) > 0 {
		return c.prID[0]
	}

	return ""
}

func (c *commit) GetBaseRefName() string {
	if len(c.baseRefNames) > 0 {
		return c.baseRefNames[0]
	}

	return ""
}