- Thread starter Kikarian
- Start date
- 19517

does anyone have recommendations for a laptop to program on? my budget is 400, and I don't care about screen size at all. 8 gigs of ram preferably. bonus points if it's a clean machine with no OS preloaded, as I'll be running a linux distro on it. thanks for any help!

Generally speaking, though you should check for Linux hardware gotchas before you buy. So many laptops make it difficult or near impossible to get a good Linux setup going, especially when it comes to graphics.

If you're looking for a Linux laptop, I've heard System 76 sell a bunch of those. No idea on the quality, however. I've never seen one in person.

Generally speaking, though you should check for Linux hardware gotchas before you buy. So many laptops make it difficult or near impossible to get a good Linux setup going, especially when it comes to graphics.

Generally speaking, though you should check for Linux hardware gotchas before you buy. So many laptops make it difficult or near impossible to get a good Linux setup going, especially when it comes to graphics.

In my case right now, what I have is basically a class with RESTful mappings (HTTP verb, params, path, etc.) that will receive a JSON from a front end. This JSON is then passed on to be transformed into an entity that will be persisted in a database. And then on GETs the reverse will happen, it will fetch stuff from the DB and transform then back into a JSON and return. 90% of the stuff in the business logic classes are creating the entities and validating that stuff exists and things like that.

I know a little about how (somewhat familiar with JUnit and Mockito), but I have no idea what to test.

I find those kinds of tests mostly tedious though. I would mostly focus on testing the transformations, if anything.

In my case right now, what I have is basically a class with RESTful mappings (HTTP verb, params, path, etc.) that will receive a JSON from a front end. This JSON is then passed on to be transformed into an entity that will be persisted in a database. And then on GETs the reverse will happen, it will fetch stuff from the DB and transform then back into a JSON and return. 90% of the stuff in the business logic classes are creating the entities and validating that stuff exists and things like that.

I know a little about how (somewhat familiar with JUnit and Mockito), but I have no idea what to test.

In my case right now, what I have is basically a class with RESTful mappings (HTTP verb, params, path, etc.) that will receive a JSON from a front end. This JSON is then passed on to be transformed into an entity that will be persisted in a database. And then on GETs the reverse will happen, it will fetch stuff from the DB and transform then back into a JSON and return. 90% of the stuff in the business logic classes are creating the entities and validating that stuff exists and things like that.

I know a little about how (somewhat familiar with JUnit and Mockito), but I have no idea what to test.

JSON is malformed -- what happens?

JSON is invalid (missing required keys in the hashmap or whatnot) -- what happens?

JSON is valid but DB object throws an exception (e.g. simulating corrupt/failed DB) -- what happens?

You'll not only want to mock up the bogus HTTP requests, but you'll also want to set up a mock DB object so that the test doesn't require a live database. Hopefully your CRUD class isn't doing raw SQL queries.

So I'm probably going with mocking the DB layer and testing the expected exceptions in all the processes or just giving up on unit test for most stuff and just doing integration tests...

Thanks for the answers guys, it was quite helpful.

I have an assignment in one of my classes. Basically, it's reading a text file, storing the information, and then acting with it. Text files look like this:

a, b, c, d

{{1, 0, 0, 1}, {1, 1, 0, 0}, {1, 0, 1, 1}, {0, 0, 1, 0}}

{{1, 0, 0, 1}, {1, 1, 0, 0}, {1, 0, 1, 1}, {0, 0, 1, 0}}

Hey guys, bit of a C++ noob here.

I have an assignment in one of my classes. Basically, it's reading a text file, storing the information, and then acting with it. Text files look like this:

Problem here is that I only want the numbers: I don't care about the letters in the first line, and I don't care about the brackets around the numbers. I need to get the numbers from this text file into a 2D array (doing matrix calculations with them, then printing results). The calculations should be no problem, but I have no fresh idea how to get the numbers into the array while ignoring everything else in the file.

I have an assignment in one of my classes. Basically, it's reading a text file, storing the information, and then acting with it. Text files look like this:

Problem here is that I only want the numbers: I don't care about the letters in the first line, and I don't care about the brackets around the numbers. I need to get the numbers from this text file into a 2D array (doing matrix calculations with them, then printing results). The calculations should be no problem, but I have no fresh idea how to get the numbers into the array while ignoring everything else in the file.

I tried running it on different drives and my computer works fine for games and everything else. Other programs also compile fine.

C FILES:

Main: https://pastebin.com/hTGn55df

Function(s) file: https://pastebin.com/ypH5EWrS

EDIT: VARIABLE FOUND WAS IN THE WRONG SCOPE

It's the first line (the letters) that determine the dimensions of the matrix. So my example of "a, b, c, d" would indicate that it's a 4x4 matrix, "a, b, c" would indicate a 3x3 matrix, and so on.

So my code is executing terribly. I compiled using gcc. When I execute the program it prints the first 400 values very quickly, still fast up to 900 and then starts slowing down but continues. It worked fine on the school computers.

I tried running it on different drives and my computer works fine for games and everything else. Other programs also compile fine.

I tried running it on different drives and my computer works fine for games and everything else. Other programs also compile fine.

Multiply it by 10 and the time needed is multiplied by 10000

That's normal... You have to write it completely differently, even a supercomputer will struggle quite fast (the limit depend on the power, but it will never be high)

The correct way to do this:

- compute ONCE all primes up to N using Eratosthene sieve

- keep BOTH a table containing primes and the table containing TRUE/FALSE values needed in the sieve

- to check whether x is the sum of two primes, take all primes p before x/2 (by using the first table) and check whether x-p is prime (by checking the TRUE/FALSE value in the second time at position x-p)

Eratosthene is O(n log(log(n))), so it will be bazing fast to compute all primes

Testing all values will still be slow, at O(n^2), but nowhere as slow... (for an upper bound of 1000, for example, the speed will be x1000000)

Edit: at the very least, you should be looking for divisors in isprime when i*i <= number and not i <= (number / 2), but that's a menial gain compared to other things...

Problem here is that I only want the numbers: I don't care about the letters in the first line, and I don't care about the brackets around the numbers. I need to get the numbers from this text file into a 2D array (doing matrix calculations with them, then printing results). The calculations should be no problem, but I have no fresh idea how to get the numbers into the array while ignoring everything else in the file.

As said, there's a bunch of different solution, depending on how well you want to be able to identify bad formatted files.

But if the file is properly formated, you can simply read digits, commas and ignore everything else...

Edit: Ahh you mean because first you iterate over all even numbers, and then for each even N, all primes less than N.

Well, for a fixed N theres O(N/log(N)) primes. With this observation i get O(n log n) for the nested loop

Well, for a fixed N there's O(N/log(N)) primes. With this observation i get O(n log n) for the nested loop

sum( pi(k/2) ) for even k over 1..n

where pi(k) is the prime counting function, and py(k) = Theta(k / log(k))

Problem is, I don't know what sum(pi(k)) gives. It''s obviously O(n^2), so I used that. I would like to know a more precise estimation.

But I really doubt it's O(n log(n)). k/log(k) is far too close to k, and log(k) grows infinitely slower than sqrt(n).

In another way :

sum(k / log(k)) dominates sum(k / sqrt(k)) which is equivalent to n sqrt(n) which dominates n log(k)

So, yes, it's less than O(n^2), but sufficiently close to it, I'd say, so that you'll never see a proper difference.

I suspect it's Omega(n^x) for basically any x<2... and it's not even O(n^1.9999999)

But I may be wrong, I'm bad at this kind of summing those special functions (and a couple of my own students are probably even better at it than me :/ )

Well, I agree that the number of operation is

sum( pi(k/2) ) for even k over 1..n

where pi(k) is the prime counting function, and py(k) = Theta(k / log(k))

Problem is, I don't know what sum(pi(k)) gives. It''s obviously O(n^2), so I used that. I would like to know a more precise estimation.

But I really doubt it's O(n log(n)). k/log(k) is far too close to k, and log(k) grows infinitely slower than sqrt(n).

In another way :

sum(k / log(k)) dominates sum(k / sqrt(k)) which is equivalent to n sqrt(n) which dominates n log(k)

So, yes, it's less than O(n^2), but sufficiently close to it, I'd say, so that you'll never see a proper difference.

I suspect it's Omega(n^x) for basically any x<2... and it's not even O(n^1.9999999)

But I may be wrong, I'm bad at this kind of summing those special functions (and a couple of my own students are probably even better at it than me :/ )

sum( pi(k/2) ) for even k over 1..n

where pi(k) is the prime counting function, and py(k) = Theta(k / log(k))

Problem is, I don't know what sum(pi(k)) gives. It''s obviously O(n^2), so I used that. I would like to know a more precise estimation.

But I really doubt it's O(n log(n)). k/log(k) is far too close to k, and log(k) grows infinitely slower than sqrt(n).

In another way :

sum(k / log(k)) dominates sum(k / sqrt(k)) which is equivalent to n sqrt(n) which dominates n log(k)

So, yes, it's less than O(n^2), but sufficiently close to it, I'd say, so that you'll never see a proper difference.

I suspect it's Omega(n^x) for basically any x<2... and it's not even O(n^1.9999999)

But I may be wrong, I'm bad at this kind of summing those special functions (and a couple of my own students are probably even better at it than me :/ )

edit: I think we need that not only does pi(x)/x -> 0, but pi(x)/(x^k) -> 0 for any k > 0, which is also true

Don't you have it backwards? Since pi(x) grows with log(x), pi(x)/x tends to 0 as x tends to infinity. So the number of primes you are looking through is actually very small once x is big enough. Thus it's less than O(n^k) for any k > 1?

for 0<p<1, and for sufficiently high k, k / log(k) dominates k / k^p = k^(1-p)

So, after summing this over 1..n, I can see sum( k / log(k) ) dominating n^(2-p)

Random check for lower n:

blue is sum(pi(k))

green is n^1.999

(well, in any case, it proves that it's sufficiently close to n^2 for any practical use of the above algorithm at the very least)

Well, I agree that the number of operation is

sum( pi(k/2) ) for even k over 1..n

where pi(k) is the prime counting function, and py(k) = Theta(k / log(k))

Problem is, I don't know what sum(pi(k)) gives. It''s obviously O(n^2), so I used that. I would like to know a more precise estimation.

sum( pi(k/2) ) for even k over 1..n

where pi(k) is the prime counting function, and py(k) = Theta(k / log(k))

Problem is, I don't know what sum(pi(k)) gives. It''s obviously O(n^2), so I used that. I would like to know a more precise estimation.

Sorry, i meant n^2 / log(n), which is a fairly direct result

Though, I don't think the log(n) here matters much*... you'll deal with 4 million numbers instead of 1 million in 1h on an average computer, which is welcome, but won't turn tables.

* like O(1) and O(log(n)), or O(n) and O(n log(n)) are usually nearly the same...

Complexity of the conjecture functions is O(n^4) and you're surprised it's quickly slow? If you want to multiply the upper limit by 2, you multiply the time needed by 8.

Multiply it by 10 and the time needed is multiplied by 10000

That's normal... You have to write it completely differently, even a supercomputer will struggle quite fast (the limit depend on the power, but it will never be high)

The correct way to do this:

- compute ONCE all primes up to N using Eratosthene sieve

- keep BOTH a table containing primes and the table containing TRUE/FALSE values needed in the sieve

- to check whether x is the sum of two primes, take all primes p before x/2 (by using the first table) and check whether x-p is prime (by checking the TRUE/FALSE value in the second time at position x-p)

Eratosthene is O(n log(log(n))), so it will be bazing fast to compute all primes

Testing all values will still be slow, at O(n^2), but nowhere as slow... (for an upper bound of 1000, for example, the speed will be x1000000)

Edit: at the very least, you should be looking for divisors in isprime when i*i <= number and not i <= (number / 2), but that's a menial gain compared to other things...

Are those integers or real numbers?

As said, there's a bunch of different solution, depending on how well you want to be able to identify bad formatted files.

But if the file is properly formated, you can simply read digits, commas and ignore everything else...

Multiply it by 10 and the time needed is multiplied by 10000

That's normal... You have to write it completely differently, even a supercomputer will struggle quite fast (the limit depend on the power, but it will never be high)

The correct way to do this:

- compute ONCE all primes up to N using Eratosthene sieve

- keep BOTH a table containing primes and the table containing TRUE/FALSE values needed in the sieve

- to check whether x is the sum of two primes, take all primes p before x/2 (by using the first table) and check whether x-p is prime (by checking the TRUE/FALSE value in the second time at position x-p)

Eratosthene is O(n log(log(n))), so it will be bazing fast to compute all primes

Testing all values will still be slow, at O(n^2), but nowhere as slow... (for an upper bound of 1000, for example, the speed will be x1000000)

Edit: at the very least, you should be looking for divisors in isprime when i*i <= number and not i <= (number / 2), but that's a menial gain compared to other things...

Are those integers or real numbers?

As said, there's a bunch of different solution, depending on how well you want to be able to identify bad formatted files.

But if the file is properly formated, you can simply read digits, commas and ignore everything else...

I'm trying to print the number of items on a list. If I do something as easy as:

Code:

```
guest = ['Jake', 'Fred', 'Joey']
guest_number = len(guest)
print(guest_number)
```

Code:

`print("How many guest is it? Oh it's " + guest_number + ".")`

Code:

`TypeError: must be str, not int`

I'm following the automate the boring stuff with python book and have a question regarding regular expressions. I'm writing the program scrape emails and phone numbers from a pdf and am getting different output than he does (watching the videos on udemy)

here's my regex followed by the output:

Code:

```
emailRegex = re.compile(r'''
# some.+_thing@something.com
# [a-zA-Z0-9_.+]+ --> custom char class
[a-zA-Z0-9_.+]+ ##name part - custom char class, search for one or more
@ #@
[a-zA-Z0-9_.+]+ #domain name part --> search for one or more
''', re.VERBOSE)
Output:
[u'Uricks@astate.eduU', u'Utmohajir@astate.eduU', u'Ughogue@astate.eduU', u'Urhannah@astate.eduU']
```

So I went to paste in an example e-mail from the document and even here it's adding the U...?

Urhannah@astate.eduU

Ughogue@astate.eduU

Any insight on why what this means is appreciated, thanks!!

I'm trying to print the number of items on a list. If I do something as easy as:

Code:

```
guest = ['Jake', 'Fred', 'Joey']
guest_number = len(guest)
print(guest_number)
```

Code:

`print("How many guest is it? Oh it's " + guest_number + ".")`

Code:

`TypeError: must be str, not int`

Code:

`print("How many guest is it? Oh it's ", guest_number, ".", sep="")`

Any insight on why what this means is appreciated, thanks!!

Thanks a lot for this indepth feedback but I made this from what we've learned so far in the class. I appreciate it though. Ill refer to this in the future.

Pretty sure it comes from the pdf, something related with underlining the mails... I'd say the regex is fine, it's an issue in the regex/data relation or the way you read the content/the pdf reader.

I'm trying to print the number of items on a list. If I do something as easy as:

Code:

```
guest = ['Jake', 'Fred', 'Joey']
guest_number = len(guest)
print(guest_number)
```

Code:

`print("How many guest is it? Oh it's " + guest_number + ".")`

Code:

`TypeError: must be str, not int`

print("How many guest is it? Oh it's " , guest_number, ".")

I want to learn orogramming so that aside from filling holes in the appworld where I need something like this money app I can build some sellable skills outside my main career path too. Don't want all my eggs in one basket.

I am starting with c# and want to learn java as well. Is that a good start? What are some good resources? Any tips?

I want to learn orogramming so that aside from filling holes in the appworld where I need something like this money app I can build some sellable skills outside my main career path too. Don't want all my eggs in one basket.

I am starting with c# and want to learn java as well. Is that a good start? What are some good resources? Any tips?

I want to learn orogramming so that aside from filling holes in the appworld where I need something like this money app I can build some sellable skills outside my main career path too. Don't want all my eggs in one basket.

I am starting with c# and want to learn java as well. Is that a good start? What are some good resources? Any tips?

So, I'd say start off with Java instead of C# to get a jumpstart on mobile development, specifically for Android, if that's where you want to go. After that, dive into C#, which will basically be a parallel move from Java, and get yourself acquainted with .NET. It seems like a lot of enterprise software is trending that route these days, ut I'm probably biased since I've been focusing on .NET these last couple years (started off learning C/C++ and then Java before transitioning to C# development).

Pretty sure it comes from the pdf, something related with underlining the mails... I'd say the regex is fine, it's an issue in the regex/data relation or the way you read the content/the pdf reader.

Sorry, I'll explain in depth a bit later... It's fine with what you now, I do it with students that have less than 4h of experience in coding, it's easy...

Sorry, I'll explain in depth a bit later... It's fine with what you now, I do it with students that have less than 4h of experience in coding, it's easy...

C#/.Net is great, but if you're wanting to go into mobile development, I'd try to learn Java asap. It's similar enough to C# these days and Android runs mainly off Java.

So, I'd say start off with Java instead of C# to get a jumpstart on mobile development, specifically for Android, if that's where you want to go.

So, I'd say start off with Java instead of C# to get a jumpstart on mobile development, specifically for Android, if that's where you want to go.

I wasn't being passive aggressive.

Also we were explicitly told to do it this way.

Still, even if you don't need right now, just for the future, the idea behind efficiently computing primes (it's quite a common task if you deal with algebra):

- write 2 and all odd numbers >=3 in ascending order on a sheet of paper

- read numbers in order (they are primes), and remove multiples (they can't be primes)

done!

e.g. :

2 3 5 7 9 11 13 15 17 19 21 23 25...

2 is prime, remove multiples

2 3 5 7 9 11 13 15 17 19 21 23 25...

3 is prime, remove multiples

2 3 5 7 11 13 17 19 23 25...

5 is prime, remove multiples

2 3 5 7 11 13 17 19 23...

7 is prime, remove multiples

etc.

You actually only need to remove odd multiples of i starting with i**2

Here's a quick'n dirty solution (not memory efficient) that check if even numbers are sum of two primes

Code:

```
#include<stdio.h>
int main(int argc, char* argv[]) {
bool* isPrime = new bool[1000000]; // can't allocate large arrays the other way
int* primes = new int[1000000];
int nbPrimes = 0;
// Initialize isPrime:
// isPrime[i] will be true if i is prime
// at the end of the sieve
//
// At the beginning:
// - even numbers aren't -> false
// - odd numbers *can* be primes -> true
// - exceptions: 1 is not prime, 2 is prime
for(int i=0; i<1000000; ++i) {
isPrime[i] = (i%2 != 0);
}
isPrime[1] = false;
isPrime[2] = true;
// Compute primes with Erat. sieve
for(int i=0; i<1000000; ++i) {
// Take all numbers in order
// if there's true in isPrime[i],
// i is prime
if (isPrime[i]) {
primes[nbPrimes] = i; // Remember i
nbPrimes++; // One more prime
// Multiples of i are not primes
// Only odd multiples above i**2
// actually need to be removed,
// so only if i<sqrt(n)
if (i<1000) // 1000 is sqrt(1000000)
for(int m=i*i; m<1000000; m+=2*i)
isPrime[m] = false;
}
}
// Check conjecture
for(int i=4; i<1000000; i+=2) {
bool OK = false;
int k=0;
// Test all primes p <= i/2
// and check whether (i-p) is a prime
while (!OK) {
if (isPrime[i-primes[k]]) // We found a solution
OK = true;
else if (2*primes[k] >= i) { // We reached i/2
printf("The conjecture is false for %d\n", i);
OK = true;
}
k = k+1;
}
}
return 0;
}
```

The problem asks me to make a function called power that takes two parameters, a and b, and determines whether a is an integer power of b. If it is, the whole thing should return True. If not, False. I'm not allowed to use ** to calculate power, and I can't use loops. I have to just use recursion.

I keep falling into the pitfall of wanting to refer back to the initial a and b values but I can't, since each recursive call that I can come up with to try entails me changing a or b. I'm really stumped. Could I get a hint?

The problem asks me to make a function called power that takes two parameters, a and b, and determines whether a is an integer power of b. If it is, the whole thing should return True. If not, False. I'm not allowed to use ** to calculate power, and I can't use loops. I have to just use recursion.

I keep falling into the pitfall of wanting to refer back to the initial a and b values but I can't, since each recursive call that I can come up with to try entails me changing a or b. I'm really stumped. Could I get a hint?

* If you are having trouble thinking recursively, first write your function iteratively, i.e. using a loop. Then try to translate it into a recursive function.

* Think about your base case, i.e. your recursion function's terminating condition, and also think about how you ought to get arrive at that terminating condition (by changing one of the parameters that you pass to each function call).

* Bigger hint:

Failing finding a ready made solution, I'll have to implement my own. Essentially I'll just be taking the base image, adding noise to it and then adding it to the training set. That being the case, anyone have any advice for what kind of filters would be ideal/available? I'll be needing to apply as many as possible ideally to create the most iterations possible. Python3 friendly libraries is pretty much mandatory simply because I'll be having to live feed the data into the trainer instead of storing for later access. Feedback appreciated.

I have two QA servers, I remotely restart the second using the following C# method

Code:

```
private static void RestartSecondServer()
{
Console.WriteLine("Computer details retrieved using Windows Management Instrumentation (WMI)");
//Connect to the remote computer
ConnectionOptions co = new ConnectionOptions();
co.Username = @"***********";
co.Password = "*********";
ManagementScope ms = new ManagementScope("\\\\******\\root\\cimv2", co);
//Query remote computer across the connection
ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher query1 = new ManagementObjectSearcher(ms, oq);
ManagementObjectCollection queryCollection1 = query1.Get();
foreach (ManagementObject mo in queryCollection1)
{
string[] ss = {""};
mo.InvokeMethod("Reboot", ss);
Console.WriteLine(mo.ToString());
Console.WriteLine("Reboot complete");
//Process.Start("shutdown", "/r /t 0");
}
}
```

I want something that tells me in real time the server is being restarted. Mind you this is a remote server. Any ideas or suggestions? Thank you