Categories
Mastering Development

How do I get keys that correspond to values in Python dictionary?

So let’s say I have a dictionary: my_dict = {‘A’ : 250, ‘B’ : 270, ‘C’ : 240} And I have a list that has values sorted in descending order: my_list = [270, 250, 240] Now, I want to create a list that looks like this: new_list = [‘B’, ‘A’, ‘C’] The elements are ordered […]

Categories
Mastering Development

How to use implicit conversion instead of structural typing when only one collection method is needed

I have a method in which I only need to access one method (appended, or :+) of a type. I want to be able to use both a custom case class and a normal List. Coming from a TypeScript background, I know how to do this using structural typing: case class CustomContainer[T](data: List[T]) { def […]

Categories
Mastering Development

How can i make this simple program work in C?

I want to print out all numbers between 100,000 and 100 with the same digits reversed as fraction. eg. 100.001 101.101 102.201 103.301 104.401 … … 243.342 … 12345.54321 I dont know how to do this, so first I tried to make a simpler program to print out with the same fraction: eg. 100.100 12345.12345 […]

Categories
Database Development

Relation in BCNF or not

Consider the relation R[A,B,C,D,E] with: the keys {A,E}, {A,B,C} and {A,B,D} the functional dependency {A,C} -> {D} no repeating attributes What is the normal form of R? My answer: It is in 1NF because the are no repeating attributes, it’s also in 2NF because there is no partial dependency since {A,C} and {D} are keys, […]

Categories
Mastering Development

Why is there an inconstancy between these two ways of plotting a function in Octave?

Context I have a function named ibm that I defined with a simple if condition: it should be 0 until a certain value (500), then is linear after that value: function f = ibm(x) if(nargin != 1) usage("ibm(x)"); endif if(x <= 500) f = 0; else f = (x-500) *0.02; endif endfunction Then in a […]

Categories
Mastering Development System & Network

Enabling MySQL authentication for proftpd

I am trying to use MySQL authentication for proftpd. I have configured everything and the authentication is working fine. The issue I am facing is that there is another database already being used for logs. So during the authentication time, the database user for the authentication is trying to write data to log database. proftpd[234014] […]

Categories
Mastering Development

How to store a generated, static set of bitsets in a minimized byte array

Optimization problem: I have an array of bitsets, A, all containing integers in the range [0; 2047], all with at least 2 elements, all sets unique. I want to store them in a byte array, BA, where each bitset, S, is stored in a compressed format, BS starting with 2 bytes: b0, which indicates the […]

Categories
Mastering Development System & Network

Enabling MySQL authentication for proftpd

I am trying to use MySQL authentication for proftpd. I have configured everything and the authentication is working fine. The issue I am facing is that there is another database already being used for logs. So during the authentication time, the database user for the authentication is trying to write data to log database. proftpd[234014] […]

Categories
Mastering Development

C switch returns default inside if/else

I have the following problem: i have two switch cases . They work perfectly when separated, but the minute I put them into an if/else the 2. switch always returns the default(error).I am sorry for the difficult wording,now ive copied in the whole program so you can check it, ive tried what you said, but […]

Categories
Mastering Development

Haskell. Sort by second element in the list of tuples

I have a code histogram, which shows the number of all characters in String. histogram :: String -> [(Char, Int)] histogram = foldr help [] where help x [] = [(x,1)] help x ((y,z):yzs) | x == y = (y,z+1) : yzs | otherwise = (y,z) : help x yzs But the result is shown […]