Tuesday, September 28, 2021

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow


Decrypting a Caesar Cipher with ord() and chr()?

Posted: 28 Sep 2021 09:37 AM PDT

I have an assignment for a lab that asks me to decrypt an input file that has been encrypted with a ceasar cipher. As background, my instructor has already let everyone know that the cipher has a shift distance of three.

I was able to get my to write to an output file, but my output.txt is completely unreadable, and not close at all to what the expected output should be. I remember my instructor mentioning that we could use ord() and chr() combined with arithmetic to transform the encoded characters to plaintext.

decode = inpf.readlines()  for line in decode:      output = ""      c = str()      for c in line:          if c >= "a" and c <= "z":              x = ord(c)              x += 23              x %= 26              y = chr(x)              output = output + y          if c >= "A" and c <= "Z":               x = ord(c)              x += 23              x %= 26              y = chr(x)              output = output + y          else:              output = output + c        outf.write(output + "\n")  

I appreciate any help or advice you can offer! Thanks!!

Linting rule to ban specific method in Kotlin (not Android)

Posted: 28 Sep 2021 09:37 AM PDT

I am trying to add a linting rule to my Kotlin/Gradle project to ban a specific method from ever being called (specifically DateTimeTz.local from the Klock library - it has been causing some timezone issues due to devs calling it without fully understanding its purpose and I would like to add a barrier to make it harder to accidentally use). This is in the core code of a Kotlin Multiplatform app, so no access to Android libraries.

Ideally, I'd like it to be possible to override this rule.

This looks like the sort of thing I want to do, except it's not Android code: Custom lint rule which ensures a specific method is not called

Does anyone have any recommendations for a good library/approach for this problem? I'm quite new to linting rules in Kotlin.

Try to tidy an excel worksheet using R

Posted: 28 Sep 2021 09:36 AM PDT

I am using the following libraries in R:

library(tidyverse)  library(timetk)  library(readxl)  library(writexl)  

I have data like this:

structure(list(hour = c("0000", "0100", "0200", "0300", "0400",   "0500", "0600", "0700", "0800", "0900", "1000", "1100", "1200",   "1300", "1400", "1500", "1600", "1700", "1800", "1900", "2000",   "2100", "2200", "2300", "0000", "0100", "0200", "0300", "0400",   "0500", "0600", "0700", "0800", "0900", "1000", "1100", "1200",   "1300", "1400", "1500", "1600", "1700", "1800", "1900", "2000",   "2100", "2200", "2300", "0000", "0100", "0200", "0300", "0400",   "0500", "0600", "0700", "0800", "0900", "1000", "1100", "1200",   "1300", "1400", "1500", "1600", "1700", "1800", "1900", "2000",   "2100", "2200", "2300", "0000", "0100", "0200", "0300", "0400",   "0500", "0600", "0700", "0800", "0900", "1000", "1100", "1200",   "1300", "1400", "1500", "1600", "1700", "1800", "1900", "2000",   "2100", "2200", "2300", "0000", "0100", "0200", "0300", "0400",   "0500", "0600", "0700", "0800", "0900", "1000", "1100", "1200",   "1300", "1400", "1500", "1600", "1700", "1800", "1900", "2000",   "2100", "2200", "2300", "0000", "0100", "0200", "0300", "0400",   "0500", "0600", "0700", "0800", "0900", "1000", "1100", "1200",   "1300", "1400", "1500", "1600", "1700", "1800", "1900", "2000",   "2100", "2200", "2300", "0000", "0100", "0200", "0300", "0400",   "0500", "0600", "0700", "0800", "0900", "1000", "1100", "1200",   "1300", "1400", "1500", "1600", "1700", "1800", "1900", "2000",   "2100", "2200", "2300"), Monday = c("6", "2", "4", "1", "3",   "1", "2", "4", "10", "10", "22", "16", "9", "10", "12", "8",   "8", "10", "14", "5", "5", "7", "12", "4", "5", "6", "3", "1",   "2", "2", "1", "5", "11", "7", "13", "9", "8", "14", "8", "13",   "11", "8", "11", "13", "7", "15", "8", "2", "2", "2", "1", "2",   "2", "1", "2", "5", "8", "19", "16", "10", "12", "9", "16", "10",   "13", "6", "10", "17", "12", "4", "6", "10", "2", "1", "4", "5",   "3", "2", "6", "5", "4", "9", "10", "12", "15", "11", "2", "14",   "15", "16", "15", "7", "19", "7", "7", "5", "1", "3", "2", "1",   "2", "4", "4", "5", "10", "11", "13", "8", "15", "19", "17",   "11", "13", "10", "6", "8", "7", "16", "8", "7", "3", "3", "3",   "3", "4", "4", "3", "6", "5", "8", "19", "13", "9", "8", "10",   "15", "10", "11", "9", "14", "12", "12", "4", "7", "6", "2",   "4", NA, "1", "2", "1", "7", "9", "7", "8", "11", "14", "13",   "16", "8", "19", "12", "10", "17", "13", "7", "3", "7"), Tuesday = c("7",   "5", "4", "1", "1", "5", "3", "3", "13", "9", "8", "11", "5",   "13", "7", "7", "6", "9", "9", "8", "9", "9", "7", "5", "1",   "2", NA, "3", "1", "2", "4", "8", "15", "7", "8", "9", "11",   "5", "6", "7", "13", "12", "12", "9", "8", "7", "13", "4", "1",   "4", "1", "3", "1", "1", "3", "4", "8", "6", "16", "9", "17",   "9", "6", "10", "13", "6", "13", "8", "7", "5", "5", "4", "4",   "2", "3", "0", "1", "2", "4", "7", "14", "13", "8", "9", "10",   "9", "14", "8", "6", "13", "17", "13", "13", "7", "6", "2", "3",   "2", "1", "1", "3", "1", "5", "9", "9", "12", "8", "14", "15",   "8", "9", "17", "6", "15", "4", "12", "17", "8", "7", "7", "4",   "1", "4", "2", "0", "4", "3", "2", "8", "12", "9", "7", "9",   "11", "9", "7", "10", "11", "10", "12", "2", "8", "8", "6", "1",   "2", "3", "5", "2", "3", "7", "8", "6", "11", "10", "12", "15",   "13", "10", "7", "12", "17", "8", "10", "9", "10", "5", "3"),       Wednesday = c("4", "5", "4", "3", "1", "4", "6", "6", "13",       "8", "13", "13", "13", "9", "5", "16", "9", "8", "18", "6",       "11", "4", "4", "10", "3", NA, "1", "2", "3", "3", "1", "2",       "4", "13", "8", "7", "12", "13", "8", "9", "10", "12", "12",       "6", "15", "11", "7", "6", "6", "2", "2", "4", "4", "2",       "4", "8", "7", "8", "14", "7", "8", "11", "10", "12", "11",       "10", "11", "11", "17", "5", "9", "4", "3", "1", "1", "3",       "2", "2", "0", "4", "12", "10", "11", "7", "11", "12", "12",       "7", "14", "12", "6", "12", "12", "8", "11", "5", "3", "2",       "0", "2", "2", "2", "4", "5", "5", "10", "9", "13", "14",       "14", "7", "9", "6", "5", "11", "13", "8", "11", "9", "8",       "8", "3", "4", "1", "2", "1", "3", "4", "4", "16", "14",       "13", "5", "9", "14", "15", "12", "9", "8", "11", "9", "6",       "9", "3", "4", "2", "3", "2", "2", "1", "3", "7", "7", "7",       "5", "16", "14", "8", "7", "9", "11", "15", "17", "16", "9",       "10", "6", "7"), Thursday = c("5", "3", "4", "1", "2", "1",       "1", "4", "5", "8", "13", "14", "10", "9", "9", "16", "10",       "6", "8", "10", "10", "11", "6", "12", "4", "3", "4", "6",       "2", "3", "2", "5", "7", "9", "13", "15", "14", "11", "9",       "6", "12", "11", "8", "10", "6", "8", "5", "3", "4", "5",       "0", "3", "3", "4", "1", "1", "7", "3", "16", "9", "11",       "16", "10", "15", "13", "11", "9", "12", "12", "7", "6",       "9", "4", "5", "2", "3", "1", NA, "2", "6", "4", "6", "9",       "7", "10", "9", "7", "7", "10", "11", "16", "7", "22", "12",       "6", "5", "3", "4", "3", "1", "1", "3", "3", "6", "7", "7",       "8", "10", "12", "9", "8", "10", "5", "12", "13", "13", "10",       "7", "5", "5", "8", "3", "2", "2", "2", "0", "6", "4", "3",       "11", "9", "11", "12", "13", "10", "9", "8", "7", "6", "9",       "6", "9", "8", "10", "3", "4", "6", "3", "3", "2", "4", "7",       "7", "7", "6", "11", "11", "11", "9", "5", "10", "7", "14",       "16", "7", "5", "6", "6"), Friday = c("6", "4", "1", "1",       "2", "0", "2", "4", "10", "4", "8", "9", "15", "9", "9",       "9", "9", "8", "8", "7", "10", "13", "5", "2", "3", "3",       "5", "3", "3", "8", "3", "4", "7", "9", "14", "9", "15",       "8", "7", "11", "14", "10", "4", "11", "8", "8", "7", "8",       "4", "2", "8", "2", "1", "1", "4", "1", "8", "7", "11", "16",       "11", "12", "9", "10", "4", "5", "4", "13", "8", "9", "5",       "7", "4", "3", "5", "1", "2", "3", "2", "6", "4", "7", "12",       "11", "7", "10", "8", "9", "12", "7", "5", "12", "7", "9",       "8", "9", "2", "2", "1", "3", "2", "2", "4", "3", "6", "7",       "14", "8", "13", "13", "10", "12", "11", "13", "8", "8",       "11", "8", "10", "6", "4", "3", "4", "3", "2", "3", "1",       "1", "3", "4", "10", "12", "9", "18", "5", "12", "9", "9",       "13", "10", "14", "4", "11", "6", "2", "5", "2", "3", "2",       "3", "4", "7", "8", "11", "7", "15", "12", "10", "8", "14",       "6", "10", "11", "9", "16", "13", "9", "6"), Saturday = c("4",       "6", "4", "4", "1", "4", "5", "4", "4", "5", "6", "7", "6",       "8", "7", "4", "11", "10", "10", "10", "9", "7", "6", "5",       "8", "5", "6", "2", "1", "1", "5", "5", "5", "10", "11",       "12", "8", "9", "8", "10", "9", "3", "9", "12", "11", "7",       "17", "5", "4", "4", "0", "4", "4", "3", "2", "4", "5", "13",       "7", "5", "9", "8", "10", "11", "9", "8", "12", "18", "8",       "11", "10", "4", "5", "8", "5", "3", "4", "5", "2", "6",       "5", "6", "9", "11", "7", "11", "8", "11", "2", "12", "9",       "10", "13", "9", "7", "8", "7", "3", "3", "2", "3", "3",       "5", "8", "5", "5", "13", "15", "8", "13", "10", "8", "10",       "6", "13", "6", "8", "9", "8", "6", "5", "6", "6", "4", "3",       "2", "4", "5", "4", "8", "10", "6", "13", "15", "11", "10",       "10", "4", "8", "7", "10", "9", "8", "8", "6", "3", "6",       "5", "3", "3", "2", "6", "9", "5", "11", "10", "8", "8",       "16", "9", "11", "6", "7", "11", "17", "10", "9", "8"), Sunday = c("6",       "6", "4", "2", "1", "1", "3", "4", "8", "7", "9", "10", "11",       "14", "7", "13", "8", "11", "9", "10", "12", "6", "8", "3",       "5", "3", "1", "2", "4", "3", "2", "8", "11", "9", "11",       "9", "7", "7", "8", "6", "5", "6", "10", "24", "15", "4",       "5", "2", "8", "2", "2", "5", "0", "2", "4", "6", "4", "8",       "6", "7", "9", "6", "8", "17", "10", "10", "8", "10", "13",       "6", "5", "4", "5", "6", "2", "4", "1", "2", "1", "3", "8",       "8", "12", "13", "10", "8", "8", "6", "7", "8", "9", "11",       "8", "8", "5", "5", "3", "4", "3", "3", "1", "1", "5", "3",       "6", "10", "3", "8", "4", "9", "7", "6", "7", "5", "10",       "8", "11", "10", "8", "13", "4", "6", "4", "2", "4", "1",       "6", "3", "5", "6", "7", "14", "8", "7", "6", "11", "9",       "8", "12", "6", "11", "10", "7", "5", "3", "4", "3", "4",       "2", "6", "7", "7", "6", "9", "15", "19", "5", "9", "10",       "9", "12", "10", "10", "12", "10", "7", "12", "7")), row.names = c(NA,   -168L), class = c("tbl_df", "tbl", "data.frame"))  

I know the start date and the end date, so I have them set:

start_date <- "2018-04-09 00:00:00"  end_date   <- "2021-09-26 23:00:00"  date_seq   <- tk_make_timeseries(    start_date = start_date,    end_date   = end_date,    by         = "hour"  ) %>%    as_tibble() %>%    mutate(rn = rep(1:24, nrow(date_seq)/24))  

What I am trying to do is get my data out of the weird wide format and make it long. Monday 00:00:00 Value, Monday 01:00:00 Value etc.

Possible?

Python selenium webdriver

Posted: 28 Sep 2021 09:36 AM PDT

I m new in selenium automation with python. I was designing this hybrid frame work for login . This error i get i don't know what is the problem but if you guys can help that would be great

Error : " def test_login(self): self.driver=webdriver.Chrome("C:\Users\91808\Documents\Chrome selenium package\chromedriver.exe") self.driver.get(self.baseurl) #import login action methods from page object file self.Lp=Logintest(self.driver)

  self.Lp.setUserName(self.username)  

E AttributeError: 'Logintest' object has no attribute 'setUserName'

Code

Properly setting up LuaBinaries files on Windows?

Posted: 28 Sep 2021 09:36 AM PDT

I'm trying to setup the files from LuaBinaries (specifically Lua 5.2.4 64-bit), and there are a few things I'm confused about.

There are two zip files provided, the binaries: lua-*_Win*_bin.zip and the libraries: lua-*_Win*_*_lib.zip

So, these are my questions:

  1. For the libraries, two versions are provided, static and dynamic. What's the difference?
  2. The zip file for the dynamic libraries contains a lua*.dll, but a file with the same name is provided in the zip file for the binaries. Which one should I use?
  3. Some of the library zip files (the older ones?) contains a liblua*.a file, is this supposed to be a misnamed lua*.lib file?

Monitor 3 different processes with particular pid with a child process executing execvp("ps", argv)

Posted: 28 Sep 2021 09:36 AM PDT

I'm trying to make a program where parent process creates 3 child processes creates another process to monitor the processes. The monitoring child process executes

char *argv[6] = {"ps", "-p", "p1,p2,p3", "r", "-o", "pid,%cpu,%mem,stat"};  execvp(argv[0], argv);  

and sends them to parent with pipe lining and redirecting stdout to stdin.

But I am having problem as the process STAT never changes in consecutive iteration even after the processes are dead it still shows that the p1,p2,p3 are running Here is my code:

#include <iostream>  #include <sys/ipc.h>  #include <unistd.h>  #include <signal.h>  #include <fstream>  #include <math.h>  #include <string.h>  #define BUFFSIZE 40000    using namespace std;      int main()  {      pid_t c[3];      c[0] = fork();      if(c[0] == 0) {          // 1st process code      }      else {          c[1] = fork();          if(c[1] == 0) {              // 2nd process code          }          else {              c[2] = fork();              if(c[2] == 0) {                  // 3rd process code              }              else {                  for (; ;)                  {                      int fd[2];                      if(pipe(fd) == -1){                          cout<<"on creation pipe error";                      }                      if(fork()) {                            close(fd[1]);                          dup2(fd[0], 0);                            char s[30000];                          read(fd[0], s, BUFFSIZE);                          cout<<s;                            int j = 0;                          for (int i = 0; i < strlen(s); ++i)                          {                              if(s[i] == '\n')                                  j++;                          }                            if(j <= 1) {                              cout<<"All children have terminated\n";                              return 0;                          }                        }                      else {                          close(fd[0]);                          dup2(fd[1], 1);                                                string listpid = to_string(c[0]) + "," + to_string(c[1]) + "," + to_string(c[2]);                          char *argv[6] = {"ps", "-p", (char*)listpid.c_str(), "r", "-o", "pid,%cpu,%mem,stat"};                          close(fd[1]);                          execvp(argv[0], argv);                          break;                      }                      close(fd[0]);                      sleep(2);                  }              }          }      }        return 0;  }  

If anybody have any advice or any solution for this that would be great. Thank you in advance.

How to find rows with duplicate values that exist across JSON arrays

Posted: 28 Sep 2021 09:36 AM PDT

I'm working with a table defined as follows:

CREATE TABLE objects(    id uuid DEFAULT uuid_generate_v4() PRIMARY KEY,    identifiers     JSONB  );  

The identifiers column contains a JSONB document in the following form:

{    "primary_id":   "7b5d5137-12cb-430c-9181-094900c2b512",    "secondary_id": "u7wKxfGAAFHwTj20"    "tertiary_ids": [      "75",      "15",      "0E"    ]  }  

Where the length of the tertiary_ids array can vary from row to row, and any or all of the ids may not exist in some rows. For example:

{    "primary_id":   "7b5d5137-12cb-430c-9181-094900c2b512",    "tertiary_ids": [      "75",      "15",      "0E"    ]  }  

or:

{    "primary_id":   "7b5d5137-12cb-430c-9181-094900c2b512",    "secondary_id": "u7wKxfGAAFHwTj20"  }  

I want to find all the rows where any or all of the ids are duplicated across rows. For example:

{    "primary_id":   "7b5d5137-12cb-430c-9181-094900c2b512",    "secondary_id": "u7wKxfGAAFHwTj20"    "tertiary_ids": [      "75",      "15",      "0E"    ]  }  

would match

{    "primary_id": "669c91a3-3693-465e-a8f9-39a3350350f5",    "secondary_id": "CyXu5rDJCh6H1h0o",    "tertiary_ids": [      "4A",      "0E"    ]  }  

and

{    "secondary_id": "u7wKxfGAAFHwTj20"  }  

The part that has me stumped is the array. Without the array, I've been able to find duplicates via the following:

SELECT    identifiers->>'primary_id'   AS insights_id,    identifiers->>'secondary_id' AS satellite_id,    id  FROM objects  WHERE    identifiers->>'primary_id' IN (      SELECT identifiers->>'primary_id' FROM hosts        GROUP BY identifiers->>'primary_id'          HAVING COUNT(identifiers->>'primary_id') > 1    )    OR    identifiers->>'secondary_id' IN (      SELECT identifiers->>'secondary_id' FROM hosts        GROUP BY identifiers->>'secondary_id'          HAVING COUNT(identifiers->>'secondary_id') > 1    )  ORDER BY    identifiers->>'primary_id',    identifiers->>'secondary_id',  DESC;  

In my efforts to include the array, I've tried different variations of the following, to no avail:

SELECT    identifiers->>'primary_id'   AS insights_id,    identifiers->>'secondary_id' AS satellite_id,    jsonb_array_elements_text(identifiers->'tertiary_ids') AS tertiary_ids,    id  FROM objects  WHERE    identifiers->>'primary_id' IN (      SELECT identifiers->>'primary_id' FROM hosts        GROUP BY identifiers->>'primary_id'          HAVING COUNT(identifiers->>'primary_id') > 1    )    OR    identifiers->>'secondary_id' IN (      SELECT identifiers->>'secondary_id' FROM hosts        GROUP BY identifiers->>'secondary_id'          HAVING COUNT(identifiers->>'secondary_id') > 1    )    OR    EXISTS (      SELECT *        FROM jsonb_array_elements(identifiers->'tertiary_ids') AS t(tertiary_ids)      GROUP BY t.tertiary_ids HAVING COUNT(t.tertiary_ids) > 1    )  ORDER BY    identifiers->>'primary_id',    identifiers->>'secondary_id',  DESC;  

While this does indeed find duplicates in primary_id and secondary_id, rows that only have duplicates in one or more tertiary_ids are not detected.

To focus on the issue, I've simplified the query to:

SELECT    jsonb_array_elements_text(identifiers->'tertiary_ids') AS tertiary_ids,    id  FROM objects  WHERE    EXISTS (      SELECT *        FROM jsonb_array_elements(identifiers->'tertiary_ids') AS t(tertiary_ids)      GROUP BY t.tertiary_ids HAVING COUNT(t.tertiary_ids) > 1    );  

Which doesn't return any rows, even though duplicates across the arrays do exist.

This function only runs outside of the event listener

Posted: 28 Sep 2021 09:36 AM PDT

I was fetching a promise with an asynchronous function and using a compose function to handle the data, but i need to add an event listener to make the site dynamic, but the function doesn't run inside the eventlistener, if i run it outside of the event in the global scope it works just fine

let btn = document.querySelector("#shorten-btn"),  menu = document.querySelector(".shorted--links");    const compose = (f, g) => (data) => g(f(data));    const shortLink = async function (data) {    try {      const response = await fetch(        `https://api.shrtco.de/v2/shorten?url=${data}`      );      let link = await response.json();      //console.log(link.result.full_short_link)      return link;    } catch (err) {      console.log(err);    }  };      const createLi = (x) => {    x.then((a) => {        let newLi = document.createElement("li");      newLi.classList.add("shorted--link");      newLi.innerHTML = `          <span>${a.result.original_link}</span>          <span><a href="#">${a.result.full_short_link}</a>          <a href="${a.result.full_short_link}" class="btn">copy</a></span>          `;      menu.appendChild(newLi);    });      };    const shortAndAdd = compose(shortLink, createLi);    btn.addEventListener("click", function(){    shortAndAdd(document.querySelector("#shorten").value)  });  

Length mismatch: Expected axis has 0 elements, new values have 6 elements

Posted: 28 Sep 2021 09:36 AM PDT

Hi I am trying to run an exercise from Howard B. Brandy's book "Quantitive Technical Analysis" I know he used python 2.x but I am using Python 3.9 therefor updating the code. The Code is listed below and the error I get I think when Calling the function to retrieve historical intra-day data looks like a mismatch with the index but not sure how to resolve is. Could you please guide me what needs to be modify to have it runing in Python 3.9 This is the code I am using:

  import datetime  import pandas as pd  import requests    def getGoogleIntradayData(ticker,numSeconds,numDays):        #  Define some variables           parsedData = []      syncChar = 'a'      numSkipLines = 7        # Form the url      urlStr = 'http://www.google.com/finance/getprices?q='      urlStr += ticker      urlStr += '&i=' + str(numSeconds)      urlStr += '&p=' + str(numDays) + 'd'      urlStr += '&f=d,o,h,l,c,v'      # Open the url      resp = requests.get(urlStr)      rawData = resp.text      lines = rawData.split('\n')      nrows = len(lines)            for i in range(numSkipLines,nrows):          #  check for empty line at end of data          if (lines[i]==""): continue          dtField, o, h, l, c, v = lines[i].split(',')          if dtField[0]==syncChar:              #  Full datetime              dtBase = dtField[1:]              dtIncr = 0          else:              #  Datetime increment              dtIncr = int(dtField)          dtValue = datetime.datetime.fromtimestamp\                      (float(dtBase) + (dtIncr*numSeconds))          o, h, l, c = [float(x) for x in [o, h, l, c]]          parsedData.append((dtValue, o, h, l, c, v))                qt = pd.DataFrame(parsedData)      qt.columns = ['datetime', 'open', 'high', 'low', 'close', 'volume']      qt.index = qt.datetime      del qt['datetime']      return qt      qtIntra = getGoogleIntradayData('AAPL',300,5)    print(type(qtIntra))  print(qtIntra.head())  print(qtIntra.tail())    

I am getting the following error :

ValueError: Length mismatch: Expected axis has 0 elements, new values have 6 elements  

Could you please guide me what needs to be modify to have it runing in Python 3.9

How to fill in an from excel imported dataframe with an other from excel imported dataframe row by row?

Posted: 28 Sep 2021 09:36 AM PDT

I have two dataframes imported from different sheets from excel and i need to fill in the row of the one dataframe with a row of the other dataframe but i dont want to create new rows, it has to replace the values of the existing row . Thankyou in advance

C++ is completely ignoring a while loop, why?

Posted: 28 Sep 2021 09:35 AM PDT

I understand that while loops are ignored if the condition is false, however in this instance the variable "helper" is never entered yet the program returns 0, so I don't understand why C++ skips the while(cin >> helper) loop. In this exercise we have to write a program that can convert from decimal to binary, binary to decimal, binary to hexadecimal, and so on. That's easy, I can do that, although I probably don't use the most optimal, nor the smartest method, but that's not a problem. The problem is that (unless I comment out the entirety of int main() until the point where I would prompt the user to enter a hexadecimal number), the program simply stops and returns 0 without ever allowing the user to enter a hexadecimal number. (PS: sorry if I used some weird variable names, and sorry if this is a dumb question, I'm still learning) Thanks for your answers in advance!

#include <iostream>  #include <vector>  #include <math.h>  //#include <iterator>  //#include <algorithm>  using namespace std;    void dectobin(int num)  {      vector<int> a;      int maradek;      while(num > 0)      {          maradek = num % 2;          a.push_back(maradek);          num = num / 2;        }      for(int i = a.size()-1;i >= 0;i--)      {          cout << a[i] << "";      }  }  void bintodec(const vector<int>& binarynum)  {      int len = binarynum.size()-1;      int sum = 0;      int twopow;      for(int i=len;i>=0;i--)      {          if(binarynum[i] == 1)          {              twopow = pow(2,1.0*len-i);              sum += twopow;          }        }      cout << sum;    }  void hextobin(const vector<char>& input)  {      int len = input.size()-1;      vector<string> results;      results.push_back("0000");      results.push_back("0001");      results.push_back("0010");      results.push_back("0011");      results.push_back("0100");      results.push_back("0101");      results.push_back("0110");      results.push_back("0111");      results.push_back("1000");      results.push_back("1001");      results.push_back("1010");      results.push_back("1011");      results.push_back("1100");      results.push_back("1101");      results.push_back("1110");      results.push_back("1111");          for(int i=0;i<=len;i++)      {          switch(input[i])          {              case '0': cout << results[0];break;              case '1': cout << results[1];break;              case '2': cout << results[2];break;              case '3': cout << results[3];break;              case '4': cout << results[4];break;              case '5': cout << results[5];break;              case '6': cout << results[6];break;              case '7': cout << results[7];break;              case '8': cout << results[8];break;              case '9': cout << results[9];break;              case 'A': cout << results[10];break;              case 'B': cout << results[11];break;              case 'C': cout << results[12];break;              case 'D': cout << results[13];break;              case 'E': cout << results[14];break;              case 'F': cout << results[15];break;          }      }    }  int main()  {      int num;        vector<int> binnum;      cout << "Enter a decimal number you want to convert into binary: " << endl; // 10 to 2      cin >> num ;      cout << "The binary version is: " << endl << endl;;      dectobin(num);      cout << endl << endl;        cout << "Enter a binary number you want to convert into a decimal: " << endl << endl; //2 to 10      int input;      while(cin >> input)      {          binnum.push_back(input);      }        bintodec(binnum);        cout << "\nEnter a hexadecimal number you want to convert into binary: " << endl << endl; //16 to 2        vector<char> hexnum;      char helper;        while(cin >> helper)      {          hexnum.push_back(helper);      }      hextobin(hexnum);            return 0;  }  

Function on created jquery droppable element

Posted: 28 Sep 2021 09:36 AM PDT

Please tell me why the droppable function does not work on the added drop elements and how to solve this problem?

$(function() {    $(".drag").draggable({      start: function(event, ui) {        $(".to_drop").append('<div class="drop">New</div>');      },      stop: function(event, ui) {        },    });    $(".drop").droppable({      revert: "valid",      drop: function(event, ui) {        alert(1);      }    });  });
.drag {    width: 50px;    height: 50px;    background: blue;  }    .drop {    width: 100px;    height: 100px;    border: 1px solid;  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>  <div class="drag"></div>  <div class="to_drop">    <div class="drop">Old</div>  </div>

SDK and android studio issue in flutter doctor

Posted: 28 Sep 2021 09:36 AM PDT

How do i resolve these 2 errors in flutter

  1. Unable to locate SDK and
  2. Android studio directory flutterError

Convert integer to string, split at the decimal and then include the decimal in the 2nd part of the array?

Posted: 28 Sep 2021 09:36 AM PDT

I would like to split a number at the decimal in order to convert the number after the decimal into a fraction.

var num = 2.2287,      numString = num.toString(),      numSplit = numString.split('.'),      decimal = parseInt(numSplit[1]);    $('.number').text(decimal);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  <div class="number"></div>

This gets me 2287, how would I go about adding the decimal back into the 2nd part of the array so that I would get .2287

How to make body divided into 3 equal part using container?

Posted: 28 Sep 2021 09:35 AM PDT

I want to make my screen into 3 equal part using container class in flutter. How to do that?

How to change 'this' keyword color in vscode custom theme

Posted: 28 Sep 2021 09:35 AM PDT

I'm working on a custom theme over the Atom One Dark Theme, but I just can't figure out how to change the 'this' keyword color. When opening Developer: Inspect Editor Tokens and Scopes it shows as a variable. with dark one theme on

But with vscode regular dark theme it does appear in a different color. with vscode dark theme

Any ideas on how to do it?

Thanks!

Combining two 8-bit integers to a 16-bit integer

Posted: 28 Sep 2021 09:35 AM PDT

IN C Programming, how do I combine (note: not add) two integers into one big integer? So if i have

int a = 8 int b = 6

in binary it would be int a = 1000 int b = 0110

so combined it would be = 01101000

IntelliJ Maven error: Repository is non-nexus repo, or is not indexed

Posted: 28 Sep 2021 09:36 AM PDT

enter image description here

Hello,

I'm getting this error for the sonatype repository. I'm pretty sure I set it up correctly in the pom.xml:

<repository>      <id>OSS Sonatype</id>      <url>https://oss.sonatype.org/content/repositories/snapshots/</url>  </repository>  

I have already tried invalidating caches, reinstalling my entire IDE, deleting the .m2 folder or clicking every reload button I found. Nothing was successful. What is the issue here?

Note: The https://s01.oss.sonatype.org/content/repositories/snapshots/ repository did not work either.

How can I change the color of one portion of a font icon?

Posted: 28 Sep 2021 09:35 AM PDT

I am implementing upvote button using fa fa signs and I was trying to color background of up vote button but the color is showing outside of sign (which is i think padding of icon), And i am trying to hide the outer padding. so the color will only inside the up vote sign

<link href="https://cdn.jsdelivr.net/gh/hung1001/font-awesome-pro@4cac1a6/css/all.css" rel="stylesheet" type="text/css" />  <i  class="fal voteup fa-sort-up fa-4x"></i>

.voteup {    background-color : red;  }
<link href="https://cdn.jsdelivr.net/gh/hung1001/font-awesome-pro@4cac1a6/css/all.css" rel="stylesheet" type="text/css" />  <i  class="fal voteup fa-sort-up fa-4x"></i>

I have also tried by adding padding : none; but it is still showing.

Any help would be much Appreciated.

when I Installed Python on Windows and it doesn’t configure the path

Posted: 28 Sep 2021 09:36 AM PDT

When i entered the code its showing this error as I attached on picture. [Environment]::SetEnvironment Variable("Path", "$env:Path;C:\Python27", "User")

Blockquote

HTML required form validation is not giving any warning

Posted: 28 Sep 2021 09:37 AM PDT

I have a register form and I have 3 inputs. They are working well when I post the values to the controller but when I don't fill them in and click the submit button, it's not allowing me to submit this form. When it's not allowing me to submit it, it should give me warning about those input like 'This field is required' or etc. but its not giving me that error.

The form:

<div class="form-container">      <div class="form-form">          <div class="form-form-wrap">              <div class="form-container">                  <div class="form-content">                      <h1 class="">Get started with a <br /> free account</h1>                      <p class="signup-link">Already have an account? <a href="auth_login.html">Log in</a></p>                      <form class="text-left" asp-action="Register" method="post">                          <div class="form">                              <div id="username-field" class="field-wrapper input">                                  <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>                                  <input asp-for="User.UserName" type="text" class="form-control" placeholder="Username" required>                                  <span asp-validation-for="User.UserName" class="text-danger"></span>                              </div>                              <div id="email-field" class="field-wrapper input">                                  <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-at-sign"><circle cx="12" cy="12" r="4"></circle><path d="M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-3.92 7.94"></path></svg>                                  <input asp-for="User.UserEMail" type="text" value="" placeholder="Email" required>                                  <span asp-validation-for="User.UserEMail" class="text-danger"></span>                              </div>                              <div id="password-field" class="field-wrapper input mb-2">                                  <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-lock"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>                                  <input asp-for="User.UserPassword" type="password" value="" placeholder="Password" required>                                  <span asp-validation-for="User.UserPassword" class="text-danger"></span>                              </div>                              <div class="field-wrapper terms_condition">                                  <div class="n-chk new-checkbox checkbox-outline-primary">                                      <label class="new-control new-checkbox checkbox-outline-primary">                                          <input type="checkbox" class="new-control-input">                                          <span class="new-control-indicator"></span><span>I agree to the <a href="javascript:void(0);">  terms and conditions </a></span>                                      </label>                                  </div>                              </div>                              <div class="d-sm-flex justify-content-between">                                  <div class="field-wrapper toggle-pass">                                      <p class="d-inline-block">Show Password</p>                                      <label class="switch s-primary">                                          <input type="checkbox" id="toggle-password" class="d-none">                                          <span class="slider round"></span>                                      </label>                                  </div>                                  <div class="field-wrapper">                                      <button type="submit" name="Register" class="btn btn-primary">Get Started!</button>                                  </div>                              </div>                            </div>                      </form>                      <p class="terms-conditions">© 2020 All Rights Reserved. <a href="index.html">CORK</a> is a product of Designreset. <a href="javascript:void(0);">Cookie Preferences</a>, <a href="javascript:void(0);">Privacy</a>, and <a href="javascript:void(0);">Terms</a>.</p>                  </div>              </div>          </div>      </div>      <div class="form-image">          <div class="l-image">          </div>      </div>  </div>  

I think there is something which overrides those warnings and not letting them to become visible but I just could not find it. When I remove the <span asp-validation-for="****" class="text-danger"></span> it's still the same. I don't know which place I'm wrong and I hope someone can help me.

I'm creating nav_graph to link one fragment to another but it's showing error

Posted: 28 Sep 2021 09:36 AM PDT

09/28 20:43:56: Launching 'app' on Pixel 3a XL1 API 26. Install successfully finished in 4 s 64 ms. $ adb shell am start -n "com.example.fragment_communication_we1/com.example.fragment_communication_we1.StudentDetailsActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Connected to process 24447 on device 'Pixel_3a_XL1_API_26 [emulator-5554]'. Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page. I/zygote: Not late-enabling -Xcheck:jni (already on) W/zygote: Unexpected CPU variant for X86 using defaults: x86 D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.fragment_communication_we1, PID: 24447 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragment_communication_we1/com.example.fragment_communication_we1.StudentDetailsActivity}: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class androidx.fragment.app.FragmentContainerView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class androidx.fragment.app.FragmentContainerView Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class androidx.fragment.app.FragmentContainerView Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment android.navigation.fragment.NavHostFragment: make sure class name exists at androidx.fragment.app.FragmentFactory.loadFragmentClass(FragmentFactory.java:97) at androidx.fragment.app.Fragment.instantiate(Fragment.java:611) at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57) at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:483) at androidx.fragment.app.FragmentContainerView.(FragmentContainerView.java:175) at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:52) at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135) at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:319) at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:298) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195) at com.masai.fragment_communication_we1.StudentDetailsActivity.onCreate(StudentDetailsActivity.java:17) at android.app.Activity.performCreate(Activity.java:6975) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.ClassNotFoundException: android.navigation.fragment.NavHostFragment at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:453) E/AndroidRuntime: at androidx.fragment.app.FragmentFactory.loadClass(FragmentFactory.java:53) at androidx.fragment.app.FragmentFactory.loadFragmentClass(FragmentFactory.java:94) ... 30 more Caused by: java.lang.ClassNotFoundException: Didn't find class "android.navigation.fragment.NavHostFragment" on path: DexPathList[[zip file "/data/app/com.example.fragment_communication_we1-EmNvUY7d7SPFTv3-S2408g==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.fragment_communication_we1-EmNvUY7d7SPFTv3-S2408g==/lib/x86, /system/lib, /vendor/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 34 more

Recup input value through screen manager kivy

Posted: 28 Sep 2021 09:36 AM PDT

I want to catch a value from my first screen into my thirdscreen.

In the first, I write my name in an input field. I go to the next window.

And I try to show my name in this last window.

So I share the code with you and I hope I will find an issue.

Python code :

import kivy  from kivy.app import App  from kivy.uix.widget import Widget  from kivy.lang import Builder  from kivy.core.window import Window  from kivy.properties import ObjectProperty  from kivy.uix.screenmanager import ScreenManager, Screen        #define ou different screens  class FirstWindow(Screen):      def envoyer(self):          name = self.ids.nom_input.text            self.ids.my_name.text = name      class SecondWindow(Screen):      pass    class ThirdWindow(Screen):      #PROBLEM HERE      def on_press(self):          self.ids.recup_infos.text = self.root.get_screen('FirstWindow').ids.my_name.text      class WindowManager(ScreenManager):      pass    class MonWidget(Widget):      pass      kv = Builder.load_file('new_window.kv')    class AwesomeApp(App):        def build(self):          Window.clearcolor = (0,0,0,0)          return kv          if __name__ == '__main__':      AwesomeApp().run()  

My KV CODE :

WindowManager:      FirstWindow:      SecondWindow:      ThirdWindow:          <FirstWindow>:      name: "romain"        BoxLayout:          orientation: "vertical"          size: root.width, root.height            Label:              id: my_name              text: "Entrez votre nom"              font_size: 32            TextInput:              id: nom_input              multiline: False              size_hint: (1, .5)            Button:              text: "Next screen"              font_size: 32              on_press: root.envoyer()              on_release:                  app.root.current = "Mickael"                  root.manager.transition.direction = "left"                    <SecondWindow>:      name: "Mickael"        BoxLayout:          orientation: "vertical"          size: root.width, root.height            Label:              text: "Entre votre ville"              font_size: 32            TextInput:              id: ville_input              multiline: False              size_hint: (1, .5)              Button:              text: "Vérifier les infos"              font_size: 32              on_release:                  app.root.current = "foncier"                  root.manager.transition.direction = "left"            Button:              text: "go back first screen"              font_size: 32              on_release:                  app.root.current = "romain"                  root.manager.transition.direction = "right"              <ThirdWindow>:      name: "foncier"        BoxLayout:          orientation: "vertical"          size: root.width, root.height            Label:              text: "Verifier : "              font_size: 32              Label:              id: recup_infos              text: ""              font_size: 32              color: 'white'              Button:              text: "On press"              font_size: 32              #Problem HERE              on_press: root.on_press()            Button:              text: "Précedent"              font_size: 32              on_release:                  app.root.current = "Mickael"                  root.manager.transition.direction = "right"  

Could you help me ? Thank you Romain

How to pass array in C# program that will record the number of hours a student studies in a week

Posted: 28 Sep 2021 09:36 AM PDT

I'm creating a C# program that will record the number of hours a student studies in a week. I'm having a problem linking my hours array created within the Student Class into the StudentUI class. Is it correct to pass the Student object inside the methods

The proper output of the Console is shown in the two images I've linked below.

*****Main Class    namespace StudentStudyApp  {      public class Program      {          static void Main(string[] args)          {          Info myInfo = new Info();          myInfo.DisplayInfo("Assignment 5");            StudentUI main = new StudentUI();          main.MainMethod();          main.DisplayData();          main.FillHours();          main.DisplayAverage();          }      }  }    *****Student Class    namespace StudentStudyApp  {      public class Student      {          double[] hours = new double[7];          string id;          string name;            public string ID          {              get              {return id;              }              set              {               id = value;              }          }            public string Name          {              get              {              return name;              }              set              {              name = value;              }          }            public void CalculateAvg()          {              double avg = Queryable.Average(hours.AsQueryable());          }            public void EnterHours(string days[])          {              for (double i = 0; i < hours.Length; i++)              {                  Console.WriteLine("Enter the number of hours that you                   studied ITDEV-115 on" + days + ":", i + 1);                  hours[] = Console.ReadLine();              }          }            public void GetNumberHours()          {              return hours[];          }            public void Students()          {                Console.WriteLine("Please enter your name: ");              string name = Console.ReadLine();              name = Name;                Console.Write("Please enter your student id: ");              string id = Console.ReadLine();              id = ID;               return Name;             return ID;         }      }  }    *****Student UI Class    namespace StudentStudyApp  {      public class StudentUI      {          string [] days = new string[] {"Sunday",           "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };            public void DisplayAverage(Student)          {              Console.WriteLine("The average number of hours studied per day               was: " + avg);          }            public void DisplayData(Student)          {              Console.WriteLine("Name: " + Name);              Console.WriteLine("ID: " + ID);              Console.WriteLine("The number of hours of study that you did               during the week are as follows");                for (int hrs = 0; hrs < hours.GetLength(0); hrs++)                  for (int da = 0; da < days.GetLength(1); da++)                  Console.WriteLine(" {0}\t{1}\t", hrs + 1,                  dayName[days], studying[hours]);          }            public void FillHours(Student)          {          }            public void MainMethod()          {              Student call = new Student();              call.Students();              call.EnterHours(string days[]);              call.GetNumberHours();              call.CalculateAvg();          }      }  }    *****Info Class    namespace StudentStudyApp  {      public class Info      {          public void DisplayInfo          {              ***Course Info here***          }      }  }    

console screen 1

console screen 2

Create an array with all the links of the years' archive (of a custom post type)

Posted: 28 Sep 2021 09:37 AM PDT

I have a custom post type called "papers" and I need to create an array with all the archive links per year that exists. Something like:

array (  [0]=> 'http://www.example.com/2021/?post_type=papers'  [1]=> 'http://www.example.com/2019/?post_type=papers'// cause there's no post in 2020  [2]=> 'http://www.example.com/2017/?post_type=papers'  )  

I've been told to use get_archives() but that just gives me a formated list, not an array I can use to feed another function. Or am I doing something wrong?

.Net5 Core API: In Post action, Dictionary object is not received in [FromForm] but received in [FromBody]

Posted: 28 Sep 2021 09:36 AM PDT

I have two actions

        [HttpPost("MyFromForm")]          public async Task<IActionResult> MyFromForm([FromForm] RequestExample request)          {              return new OkObjectResult(request);          }            [HttpPost("MyFromBody")]          public async Task<IActionResult> MyFromBody([FromBody] RequestExample request)          {              return new OkObjectResult(request);          }  

The class contains only one property of Dictionary type

    public class RequestExample      {          public Dictionary<string, string> DeviceDetails { get; set; }      }  

Request enter image description here

{    "deviceDetails": {      "additionalProp1": "string",      "additionalProp2": "string",      "additionalProp3": "string"    }  }  

In case I send the data using swagger to these methods, The method having FromBody is working but the method having FromForm is not working.

Using: FromBody, I am able to receive the dictionary in the request enter image description here

Using: FromForm, I am not able to receive the dictionary in the request enter image description here

Question: Why I am not able to receive the object in FromForm type of request?

databricks code to send filename and size to another table

Posted: 28 Sep 2021 09:35 AM PDT

I have a code to check whether the incoming files had data or not.it checks for each of the files and performs the actions as mentioned in the code. wanted to know how to send the file name, file size, and time at which that file was read to another table created using data bricks?

How to use ExceptT to replace lots of IO (Either a b)

Posted: 28 Sep 2021 09:36 AM PDT

I have a function which connects to a database, then runs a query. Each of these steps results in IO (Either SomeErrorType SomeResultType).

One of the things I have really liked about using Either and similar monads in learning Haskell has been the ability to use the monad functions like >>= and combinators like mapLeft to streamline a lot of the handling of expected error states.

My expectation here from reading blog posts, the Control.Monad.Trans documentation, and other answers on SO is that I have to somehow use transformers / lift to move from the IO context to the Either context.

This answer in particular is really good, but I'm struggling to apply it to my own case.

A simpler example of my code:

simpleVersion :: Integer -> Config -> IO ()  simpleVersion id c =     connect c >>= \case         (Left e)     -> printErrorAndExit e        (Right conn) -> (run . query id $ conn)                >>= \case                       (Left e)  -> printErrorAndExit e                      (Right r) -> print r                                     >> release conn  

My problem is that (a) I'm not really understanding the mechanics of how ExceptT gets me to a similar place to the mapLeft handleErrors $ eitherErrorOrResult >>= someOtherErrorOrResult >>= print world; (b) I'm not sure how to ensure that the connection is always released in the nicest way (even in my simple example above), although I suppose I would use the bracket pattern.

I'm sure every (relatively) new Haskeller says this but I still really don't understand monad transformers and everything I read (except aforelinked SO answer) is too opaque for me (yet).

How can I transform the code above into something which removes all this nesting and error handling?

How to "rebuild" the CDK entrypoint

Posted: 28 Sep 2021 09:36 AM PDT

A bit of background, started a CDK in typescript project and didn't know the conventions as I'm new to AWS so the code was written on the "entrypoint" in the /bin directory. Upon further reading I found out that I was doing it incorrectly

bin/cdk-workshop.ts is the entrypoint of the CDK application. It will load the stack defined in lib/cdk-workshop-stack.ts.

So my question is, after I move my code from the /bin file to the /lib, how do I then generate the bin/cdk-workshop.ts file again?

Entitlements file "Entitlements.plist" not found. error

Posted: 28 Sep 2021 09:35 AM PDT

I am trying to run a simple app on an iPod touch. The code complies and runs on the emulator just fine, but as soon as I try to run it on the device I get the error above. I have run other applications this way and have tried different provisioning profiles. The Entitlements file is in the root of the project. I have also tried a wildcard id and a specific id as well. I am not sure what is happening.

Any help is appreciated.

No comments:

Post a Comment