just wondering if guys can code. it works serving images not pdf brochure. in advance func main(){ http.handlefunc("/", func(w http.responsewriter, r *http.request){ filename := "/var/www/filedipenser/brochure.pdf" streampdfbytes, err := ioutil.readfile( filename ) if err != nil { fmt.println(err) os.exit(1) } b := bytes.newbuffer(streampdfbytes) w.header().set("content-type", "application/pdf") if _, err := b.writeto(w); err != nil { fmt.fprintf(w, "%s", err) } w.write([]byte("pdf generated")) }) err := http.listenandserve(":4111", nil) if err != nil { log.fatal("listenandserve: ", err) fmt.println(err) } } the code bit inefficient appears working. however, pdf viewers might sensitive extraneous output adding end of http response stream...
i have following architecture: +-----------------+ | collection | | | | | | | | | +-----------------+ | ^ | | create() | | | | v | getitem(b) +------------+ | | item | | | | | | +------+ | | +------------+ a class managing collection of items, creates items. , these items may need other items collection. the actual code in python, , collection passes parameter created item . see it, bad practice. improvement can see pass few functions of collection needed item , instead of whole instance. for example: class collection: getitem(self, id): ... createitem(self, id): item = item(id, self) # <-- pass self ... class item: __init__(self, id, col): ... col.getite...
i having trouble using bbmle:mle2 function when trying regression. illustrate problem, have come toy example. we define minus log-likelihood poisson distribution (or custom distribution): ll <- function(beta, z, x){ -sum(stats::dpois(x, lambda = exp(z %*% beta), log = true)) } in code above, beta parameter vector estimate, z model/design matrix , x variable of interest. i generate random data work with: set.seed(2) age <- round(exp(rnorm(5000, mean = 2.37, sd = 0.78) - 1)) claim <- rpois(5000, lambda = 0.07 i can use optim regression. here intercept model: z1 <- model.matrix(claim ~ 1) optim(par = 0, fn = ll, z = z1, x = claim) here intercept + age model: z2 <- model.matrix(claim ~ age) optim(par = c(0, 0), fn = ll, z = z2, x = claim) the way large number of different models can assessed quite easy, 1 has specify model matrix. how can made work mle2 function bbmle package? i can it, if beta one-dimensional: mle2(minuslogl = functio...
Comments
Post a Comment