StackOverflow.com

VN:F [1.9.22_1171]
Rating: 9.4/10 (10 votes cast)

Random snippets of all sorts of code, mixed with a selection of help and advice.

Weird interaction with Python PIL image.save quality parameter

12 August 2022 @ 9:00 pm

This is just a part of the project I'm currently working on. I am trying to convert picture into text, then from text back to the picture without any loss or extra size. First, I open the picture, read the pixels, and write them down. Pictures are size NxN. from PIL import Image import sys import zlib def rgb_to_hex(rgb): return '%02x%02x%02x' % rgb N = im.width im = Image.open(r"path\\pic.png") px = im.load() read_pixels = "" for i in range(N): for j in range(N): read_pixels += rgb_to_hex(px[j, i,]) Then, transform the string into bytes. data = bytes.fromhex(read_pixels) img = Image.frombytes("RGB", (N,N), data) img.save("path\\new.png",quality = 92) According to the Pillow official documentation they are saying that quality goes from 0 -

Unit root test on lagged variables

12 August 2022 @ 9:00 pm

guys! I'm using this sintaxe but when I use the last part ("modelo = ...") it shows the following: "Error in merge.zoo(difetanol, detanol, mes2, mes3, mes4, mes5, mes6, mes7, : all(sapply(args, function(x) is.zoo(x) || !is.plain(x) || (is.plain(x) && .... is not TRUE" ethidra = (tsrelatorio[,"etanol"]) ethidra length(ethidra) acuavhp = (tsrelatorio[,"avhp"]) acuavhp length(acuavhp)``` matr <- matrix(0, nr = 12, nc = 12) matr[row(matr) == col(matr)] <- 1 matr Djt <- rbind(matr,matr,matr,matr); Djt dim(Djt) names(Djt) dimnames(Djt) = list(c(),c("M1", "M2", "M3", "M4","M5","M6","M7","M8","M9","M10","M11","M12")) Djt dim(Djt)``` teste=data.frame(Djt) attach(teste) mes2= teste[1:47,2] mes2 length(mes2) mes3= teste[1:47,3] mes3 length(mes3) mes4= teste[1:47,

Scheduling Multiple Cron Jobs for a REST API connector in Fivetran

12 August 2022 @ 9:00 pm

We use a Fivetran connector that pulls our data every five minutes. We do not need the data pulled that frequently during non working hours. The connector we have does not allow for customization, but a REST API was suggested if paired with a cron job. Is it possible to set up a schedule like this? Monday 4:00am to 11:55pm, run every five minutes. 12:00am to 4:00am, run on the hour Tuesday 4:00am to 11:55pm, run every five minutes. 12:00am to 4:00am, run on the hour Wednesday 4:00am to 11:55pm, run every five minutes. 12:00am to 4:00am, run on the hour Thursday 4:00am to 11:55pm, run every five minutes. 12:00am to 4:00am, run on the hour Friday 4:00am to 11:55pm, run every five minutes. 12:00am to 4:00am, run on the hour Saturday run every hour Sunday run every hour Thank you.

How do I maintain the state of my request data between GET and POST requests in one flask route?

12 August 2022 @ 8:59 pm

I have some user response data that is posted from the front end to my /post end route and then one piece of that data (user id) is posted to another flask route /stats. That is working properly, when I print to the console I am getting the correct user_id I want to get. The problem is that in this /stats end route I am performing a query of the database to gather some important stats and then I am grabbing those on the front end through a get request. The problem is that when I perform the get request, the state of my request_data is lost and throws the error: line 67, in stats user = request_data['user'] TypeError: 'NoneType' object is not subscriptable the app works perfectly until I perform the get request. here is my code for the flask route /stats: @app.route('/stats', methods=['GET', 'POST']) def stats(): request_data = request.get_json() user = request_data['user'] def get_total_percent_correct(user_id): correct =

Python globals() - how do variables get added/ updated to this global dictionary in the below example?

12 August 2022 @ 8:59 pm

In this line, how does name get populated to the globals dictionary? Method gets invoked here

Tailwind classes are not working after installed

12 August 2022 @ 8:59 pm

I'd like to begin with stating that this question's title is similar to this question but I tried the answers there but they won't work. I first tried Tailwind from their official CLI guide, but that wouldn't work so I followed this youtube tutorial for the set-up but Tailwind still won't work. In the previously mentioned question someone noted that you need to be very specific in the path from tailwind.cofig.js to your HTML, but I did this. My tailwind.config.js: module.exports = { content: ['./*.html'], theme: { extend: {}, }, plugins: [], } And here is a screenshot of my folder:

calling a function with a sublist inside another function

12 August 2022 @ 8:59 pm

I'm trying to run this code: list1 = [4,5,6,7,8] def func1(x,list1): return x*list1 def func2(x,list1): return func1(x,list[1:]) func2(3,list1) I got the following error message: TypeError Traceback (most recent call last) <ipython-input-25-5e4e46f738ca> in <module>() 7 return func1(x,list[1:]) 8 ----> 9 func2(3,list1) <ipython-input-25-5e4e46f738ca> in func2(x, list1) 5 6 def func2(x,list1): ----> 7 return func1(x,list[1:]) 8 9 func2(3,list1) TypeError: 'type' object is not subscriptable I want to know if it's possible to call a function inside another function but calling a sublist of the list called in the main function

system design vs system architecture

12 August 2022 @ 8:59 pm

I have seen many examples of system designs. For example, design a URL shortener or Twitter in Grokking the System Design Interview. But then, what is system architecture? Are those two the same things?

How can i backup mssql to microsoft azure sql?

12 August 2022 @ 8:58 pm

I have MSSQL sql backup and I want to use this backup of this file with .bak extension on microsoft azure server, how can I do it?

Stock Investment Experiment in OTree - no template

12 August 2022 @ 8:58 pm

I am working on an experiment in Otree/ Python and kindly ask for your help. I am a newbie in programming and Otree. In my experiment, participants either design their own portfolio (or get one assigned to them - whichever is easiest in the beginning) and observe changes to their portfolio in later rounds. After every round and change, they have the opportunity to buy/sell positions. On Otree's website, I found experiments titled "Stock game" or "Investment game" (links: https://www.otreehub.com/projects/otree-stock-trade/ and https://www.otreehub.com/projects/investment-game/), however, there was no template that I could adapt to my own experiment. I would be most grateful for guidance on a template with a stock investment game similar to mine. I am also very t