• Register
  • TOS
  • Privacy
  • @NeoGAF
  • Like

Phrynobatrachus
Junior Member
(10-17-2017, 08:24 PM)
Phrynobatrachus's Avatar
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!
Pokemaniac
Member
(10-17-2017, 10:40 PM)
Pokemaniac's Avatar

Originally Posted by Phrynobatrachus

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!

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.
cpp_is_king
Banned
(10-17-2017, 11:34 PM)
cpp_is_king's Avatar

Originally Posted by unknownstranger

Pretty much. I was expecting something a little more complicated but I think that works. I got a little thrown off that my teacher listed an example range as [3,6].

Your teacher was using mathematical notation. Just to convey the idea, but it had nothing to do with how to express that in code
Phrynobatrachus
Junior Member
(10-18-2017, 12:05 AM)
Phrynobatrachus's Avatar

Originally Posted by Pokemaniac

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.

looked them up, they seem nice but they're way out of my price range. I'll definitely check out the other potential issues though, thanks.
Kansoku
(10-18-2017, 02:02 AM)
Kansoku's Avatar
So, I haven't done tests that much and want to improve. However I literally have no idea how in my current situation. So my question for you guys is, how would you unit test what is essential a glorified CRUD?

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.
Kalnos
Banned
(10-18-2017, 04:35 AM)
Kalnos's Avatar
I find it hard to test code like that to be honest. You can mock HTTP requests with some test code that intercepts a properly formatted request and returns an example response from a file that mimics a real response. You could then also test that the fake data is properly transformed once it's run through your transformation functions.

I find those kinds of tests mostly tedious though. I would mostly focus on testing the transformations, if anything.
yellowjacket25
Member
(10-18-2017, 07:03 AM)
yellowjacket25's Avatar

Originally Posted by Kansoku

So, I haven't done tests that much and want to improve. However I literally have no idea how in my current situation. So my question for you guys is, how would you unit test what is essential a glorified CRUD?

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.

Mock all of the DB calls to return either valid responses or errors. Then make calls to the rest service for various scenarios. For instance, send a valid JSON but have the mock DB call return a connection error. If your rest endpoint is supposed to send a 500 error with some kind of payload then assert that it actually happens. Do the same for any other scenario you can think of. If the JSON is transformed and validated in other business classes then writing unit tests for that should be easy. If not then you will likely need more tests that send different types of payloads to your rest endpoint and asserts responses for valid and invalid inputs are correct. I would also ensure that a misformatted JSON payload returns a proper response.
gblues
Banned
(10-18-2017, 07:20 AM)
gblues's Avatar

Originally Posted by Kansoku

So, I haven't done tests that much and want to improve. However I literally have no idea how in my current situation. So my question for you guys is, how would you unit test what is essential a glorified CRUD?

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 like to think in terms of "what can go wrong."

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.
Somnid
Member
(10-18-2017, 07:38 AM)
Somnid's Avatar
Unit tests should not really go beyond atomic function calls. I put parameters in, I expect return value out. You can use dependency injection to mock implementations. If this is hard, you probably have code that is messy or has a lot of side effects.
Kansoku
(10-18-2017, 11:25 PM)
Kansoku's Avatar
A lot of these stuff is already dealt with by libraries we use. All the JSON stuff is basically dealt with Jackson with maps them to an class. At most we have to do null checks, which is something we have to do anyways. We also use JPA and Hibernate and a lot of things are dealt there as well, and we have some Helper classes to deal with those who aren't.

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.
CronoShot
Member
(10-19-2017, 06:14 AM)
CronoShot's Avatar
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:

a, b, c, d
{{1, 0, 0, 1}, {1, 1, 0, 0}, {1, 0, 1, 1}, {0, 0, 1, 0}}

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.
Jokab
Member
(10-19-2017, 07:17 AM)
Jokab's Avatar

Originally Posted by CronoShot

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.

Do the text files all look the same in terms of dimensions, just that the numbers vary?
CronoShot
Member
(10-19-2017, 07:55 AM)
CronoShot's Avatar

Originally Posted by Jokab

Do the text files all look the same in terms of dimensions, just that the numbers vary?

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.
Compsiox
Member
(10-19-2017, 09:07 AM)
Compsiox's Avatar
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.

C FILES:
Main: https://pastebin.com/hTGn55df
Function(s) file: https://pastebin.com/ypH5EWrS

EDIT: VARIABLE FOUND WAS IN THE WRONG SCOPE
peakish
Member
(10-19-2017, 09:15 AM)

Originally Posted by CronoShot

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.

If you just want the numbers in the second line, go through it character by character, identify each number individually and parse it using eg. the atoi or stoi function. But C++ has like fifty other ways to do this with depending on how safe, concise or legible you want to be. How are you storing your data? As raw memory or eg. in a vector container?
Koren
Member
(10-19-2017, 10:29 AM)
Koren's Avatar

Originally Posted by Compsiox

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.

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...

Originally Posted by CronoShot

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.

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...
cpp_is_king
Banned
(10-19-2017, 02:44 PM)
cpp_is_king's Avatar
Where are you getting O(n^2) from in testing all values? Looks like O(n) to me, since checking a value whose primality has been precomputed is O(1)

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 there’s O(N/log(N)) primes. With this observation i get O(n log n) for the nested loop
Koren
Member
(10-19-2017, 08:14 PM)
Koren's Avatar

Originally Posted by cpp_is_king

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

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 :/ )
The Friendly Monster
Member
(10-19-2017, 08:34 PM)
The Friendly Monster's Avatar

Originally Posted by Koren

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 :/ )

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?

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
Koren
Member
(10-19-2017, 08:57 PM)
Koren's Avatar

Originally Posted by The Friendly Monster

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?

Well you can sum a large quantity of very small things and still get huge results...


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)
Koren
Member
(10-19-2017, 08:59 PM)
Koren's Avatar

Originally Posted by The Friendly Monster

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

It's not...

In fact, it tends towards infinity for any k<1
The Friendly Monster
Member
(10-19-2017, 09:06 PM)
The Friendly Monster's Avatar

Originally Posted by Koren

It's not...

In fact, it tends towards infinity for any k<1

I think you are correct :).
cpp_is_king
Banned
(10-19-2017, 09:28 PM)
cpp_is_king's Avatar

Originally Posted by Koren

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.

Sorry, i meant n^2 / log(n), which is a fairly direct result
Koren
Member
(10-19-2017, 09:42 PM)
Koren's Avatar

Originally Posted by cpp_is_king

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

I'm fine with O(n^2/log(n)), indeed.

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...
Compsiox
Member
(10-19-2017, 11:50 PM)
Compsiox's Avatar

Originally Posted by Koren

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...

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.
Tenck
Member
(10-20-2017, 01:17 AM)
Tenck's Avatar
Quick Python 3 question and I feel so dumb I can't figure it out.

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)
It prints the number 3 no problem. But when I try to print the number in a quick sentence like this

Code:

print("How many guest is it? Oh it's " + guest_number + ".")
it'll give me this error

Code:

TypeError: must be str, not int
Sorry for such a dumb question but I'm just getting the hang of Python and this is confusing me.
Kalnos
Banned
(10-20-2017, 01:26 AM)
Kalnos's Avatar

Originally Posted by Tenck

Quick Python 3 question and I feel so dumb I can't figure it out.

Code:

print("How many guest is it? Oh it's " + str(guest_number) + ".")
Use 'str(i)' to convert the integer to a string.
Tenck
Member
(10-20-2017, 01:34 AM)
Tenck's Avatar

Originally Posted by Kalnos

Code:

print("How many guest is it? Oh it's " + str(guest_number) + ".")
Use 'str(i)' to convert the integer to a string.

Thanks so much for the quick reply. You have no idea how much I appreciate it.
Ya no
Member
(10-20-2017, 01:44 AM)
Ya no's Avatar
Hi All,

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']
It's adding these u's... I learned that the u'string' means it's a unicode, but didn't find anything about the capital U's being added within the string itself.

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!!
Koren
Member
(10-20-2017, 08:48 AM)
Koren's Avatar

Originally Posted by Tenck

Quick Python 3 question and I feel so dumb I can't figure it out.

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)
It prints the number 3 no problem. But when I try to print the number in a quick sentence like this

Code:

print("How many guest is it? Oh it's " + guest_number + ".")
it'll give me this error

Code:

TypeError: must be str, not int
Sorry for such a dumb question but I'm just getting the hang of Python and this is confusing me.

I'm late, and there was a perfect answer, but just a comment... + require strings on both sides, so str is a solution, but slightly better: don't use +, use commas

Code:

print("How many guest is it? Oh it's ", guest_number, ".", sep="")
it's more efficient (sep="" is to remove spaces betweens elements)
Koren
Member
(10-20-2017, 08:55 AM)
Koren's Avatar

Originally Posted by Ya no

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

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.

Originally Posted by Compsiox

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.

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...
Ya no
Member
(10-21-2017, 01:30 AM)
Ya no's Avatar

Originally Posted by Koren

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.

Thanks! That's the conclusion I came too as well. The e-mails were clickable links in the pdf and if I copied text from a file that did not have clickable links it worked as expected.
fixuis
Member
(10-21-2017, 04:01 AM)

Originally Posted by Tenck

Quick Python 3 question and I feel so dumb I can't figure it out.

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)
It prints the number 3 no problem. But when I try to print the number in a quick sentence like this

Code:

print("How many guest is it? Oh it's " + guest_number + ".")
it'll give me this error

Code:

TypeError: must be str, not int
Sorry for such a dumb question but I'm just getting the hang of Python and this is confusing me.

if you use ",' instead of "+" you can not only get it to work without the traceback but also you don't need to convert it to string then..like this..

print("How many guest is it? Oh it's " , guest_number, ".")
Skar
Member
(10-21-2017, 04:35 AM)
I am intending to learn to program. I am primarly interested in app development for mobile platforms like android and big data interests me too.my first program is to be a personal finance app tracking income and expenses, budgeting, and saving for the average Joe. I haven't found a really simple and intuitive app for that that really fits what I want in that type of app. It will most likely be canadian based so I can create programs for estimating pay cheques and tax returns and stuff too and have it focused. It will be a simple, intuitive soon for the average canadian Joe who wants to start managing his money.

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?
Somnid
Member
(10-21-2017, 05:18 AM)
Somnid's Avatar

Originally Posted by Skar

I am intending to learn to program. I am primarly interested in app development for mobile platforms like android and big data interests me too.my first program is to be a personal finance app tracking income and expenses, budgeting, and saving for the average Joe. I haven't found a really simple and intuitive app for that that really fits what I want in that type of app. It will most likely be canadian based so I can create programs for estimating pay cheques and tax returns and stuff too and have it focused. It will be a simple, intuitive soon for the average canadian Joe who wants to start managing his money.

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?

C# is a pretty decent way to start. It's pretty flexible. A budgeting app is not a bad place to start either as the core functionality is simple. Just don't get too bogged down in the interface design at the start.
dabig2
Member
(10-21-2017, 06:40 AM)
dabig2's Avatar

Originally Posted by Skar

I am intending to learn to program. I am primarly interested in app development for mobile platforms like android and big data interests me too.my first program is to be a personal finance app tracking income and expenses, budgeting, and saving for the average Joe. I haven't found a really simple and intuitive app for that that really fits what I want in that type of app. It will most likely be canadian based so I can create programs for estimating pay cheques and tax returns and stuff too and have it focused. It will be a simple, intuitive soon for the average canadian Joe who wants to start managing his money.

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?

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. 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).
Compsiox
Member
(10-21-2017, 09:30 AM)
Compsiox's Avatar

Originally Posted by Koren

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...

I wasn't being passive aggressive. Also we were explicitly told to do it this way.
Koren
Member
(10-21-2017, 12:28 PM)
Koren's Avatar

Originally Posted by dabig2

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.

It's the sensible way to do things if you want to take the quick road (though I wouldn't suggest leaning coding with Java) but my heart would say learn C# and hope Android developpers come to their senses and get rid of Java ;)

Originally Posted by Compsiox

I wasn't being passive aggressive.

I don't doubt that... It's just... it's hard to guess what's the background of people, and I'm really sorry when I misjudge it.

Originally Posted by Compsiox

Also we were explicitly told to do it this way.

If that's the case, it's perfectly normal it's slow, and there's little you can do about it, except some tweaks.

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;
}
Basically, it takes less than 1 second to check half a million even numbers with this.
1upsuper
Member
(10-22-2017, 02:09 AM)
Hello again. I'm a programming scrub taking an intro CS class using Python. We're currently learning about recursion. It's really tough for me but I've been able to do most of the exercises, though one is really causing me trouble. I'd really appreciate a nudge in the right direction.

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?
Tristam
Member
(10-25-2017, 03:36 AM)
Tristam's Avatar

Originally Posted by 1upsuper

Hello again. I'm a programming scrub taking an intro CS class using Python. We're currently learning about recursion. It's really tough for me but I've been able to do most of the exercises, though one is really causing me trouble. I'd really appreciate a nudge in the right direction.

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?

Hint: there's no problem with changing one of the parameters - in fact that's a necessity in recursive functions. So there are a few hints:

* 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: You would mutate *a* as you call your recursive function, and your base case should could check: if a == b, then return True, but if a < b, return False
* Biggest hint: You mutate a by dividing it by b, so for example given a = 125 and b = 5, the first call to power() a == 125 and b == 5, the second call to power() a == 25 and b == 5, and the third and final call to power a == 5 and b == 5. Since a == b, you know that a is an integer power of b.
oxrock
Gravity is a myth, the Earth SUCKS!
(10-25-2017, 04:22 AM)
oxrock's Avatar
Hey all, for fun I've been trying my hand at machine learning. I'm currently trying a competition that gives us a MASSIVE picture dataset from an online retailer which we have to label by category. For each product we're given 1-4 preview pictures of it. For machine learning (especially neural networks, which is what I had in mind) this isn't an awful lot of data per item. I'm looking for a way to take those few pictures and increase the data available by altering the image slightly. Similar to what one might do for a Haar Cascade detecting a particular item. Ideally I'm looking for a ready made solution that would work, but I think that's unlikely. Something similar to opencv create samples utility but something I could actually use within my python script. There's no way I'm going to get this working at all unless I can automate the process. There's just too much data.

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.
mugurumakensei
Member
(10-26-2017, 03:08 AM)
mugurumakensei's Avatar
Hope to see some of you guys in ProgrammingGAF in a new place. This will be my last post in the ProgrammingGAF threads.
vypek
Member
(10-26-2017, 05:10 AM)
Thats funny. This didn't show up in my subscriptions as being updated. Just randomly ran into it on the first page. And maybe I'll see you guys around elsewhere. I started posting less in here anyways though
Somnid
Member
(10-28-2017, 04:06 AM)
Somnid's Avatar
Cpp King sends his regards to everyone at programming GAF. Says it's been fun and that C++ is the best language. You can find him on Slaent.
dabig2
Member
(10-28-2017, 05:08 PM)
dabig2's Avatar

Originally Posted by Somnid

Cpp King sends his regards to everyone at programming GAF. Says it's been fun and that C++ is the best language. You can find him on Slaent.

See some familiar faces there. Neat. I'll give it a look, but I'm resistant to change so I'm hoping some programmingGaf members stay here.
BuddyTheBestPuppy
Member
(11-01-2017, 01:58 AM)
Hey guys, I need some help

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");
    }
}
Now I want to find out if the server is running or if it's being restarted. I created a method that looks at the WMI LastBootUpTime and compares it with the DateTimeNow, but that wasn't such a good idea. Since the the LastBootUpTime isn't accessible while the server is being restarted. Also tried pinging the server while it was being restarted and the ping was a success :/

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
Baldassare Castiglione
Junior Member
(11-25-2017, 09:28 PM)
Baldassare Castiglione's Avatar
this thread is great!
Koren
Member
(11-26-2017, 01:15 PM)
Koren's Avatar
It's also unfortunately quite dead :/

I miss the discussions here T_T
oxrock
Gravity is a myth, the Earth SUCKS!
(11-26-2017, 03:55 PM)
oxrock's Avatar
I wasn't exactly a regular but I posted from time to time and lurked quite a long while. Anyhow, I'm still subbed! Will respond if something in my wheelhouse comes up.
llien
Member
(11-27-2017, 09:32 AM)
llien's Avatar

Originally Posted by Koren

I miss the discussions here T_T

Well, if you have things to ask, ask.

Thread Tools