• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

JS gaf. What's the best tool for real time plotting of pretty large data sets? D3 seems to be the go but I know next to nothing about frontend/javascript.

D3 for sure. There might be some libraries that are based on D3 that a specialised on _your_ kind of data sets though too.
 
Hey Programming GAF. Two questions.

1) I'm trying to transition from mostly manual QA to either mostly automation testing or outright development. I teach web dev to high school kids, and occasionally make games on the side (game jams and hackathons), so I want to make it my job.

But I need more proof I can code. I want to make examples on my github using:

Python
Java
C# or C++ either one
Maybe Vbscript
And maybe javascript, but I may have to make examples with this anyway for my web dev classes.

But I don't know what will be considered an acceptable example. Help?

2) The web dev classes. I have no idea how to teach high school kids, nevermind teaching them how to make websites. Thankfully they already have some experience, so I'm really just trying to help them improve.

But I don't have a curriculum to work with this time. The person who normally makes them is gone. Any links or tips on how to make one and implement it would be fantastic!
 

Hylian7

Member
I'm really frustrated. I have been trying for hours to solve this. I'm using the Dropwizard framework (similar to Spring, and others), and I have my server set up. I try to access any URLs and all of them 404. Why is this? I have my resource (basically a Controller) set up, is there some XML file I'm missing? All I want is to see JSON in the browser.
 
I'm really frustrated. I have been trying for hours to solve this. I'm using the Dropwizard framework (similar to Spring, and others), and I have my server set up. I try to access any URLs and all of them 404. Why is this? I have my resource (basically a Controller) set up, is there some XML file I'm missing? All I want is to see JSON in the browser.

Did you make sure to register your resources to jersey with environment.jersey().register?
What port is the jetty server running on? Are you making sure to put the port after the ip address/url?
 
Anyone here familiar with Visual Studio 2015 and Code Blocks? As well as linux?

My C code compiles on Visual Studio 2015 and my school's linux server (Flip). But won't compile on code blocks. It seems like there's some syntax error. But I can't find any.

I can't post the code here directly. Would anyone be willing to PM me?
Throw a message my way. I'll take a look. I regularly deal with this stuff (as does cppisking though it looks like he got mod renamed...) so I might be able to help. Please include the error message.
 

Hylian7

Member
Did you make sure to register your resources to jersey with environment.jersey().register?
What port is the jetty server running on? Are you making sure to put the port after the ip address/url?

I registered the resources.

It should be running on 8080, but is there a way to check for sure?

Either way, I am putting in localhost:8080/whatever

Anything pulls up the Apache 404 page.
 
I registered the resources.

It should be running on 8080, but is there a way to check for sure?

Either way, I am putting in localhost:8080/whatever

Anything pulls up the Apache 404 page.

When it boots up it should show the port.

Like here's some output from one of my programs I built for my job.

Code:
INFO  [2016-03-08 10:04:38,549] 
org.eclipse.jetty.setuid.SetUIDListener: Opened application@53a9dd25{HTTP/1.1}{0.0.0.0:[B]9080[/B]}
INFO  [2016-03-08 10:04:38,550] org.eclipse.jetty.setuid.SetUIDListener: Opened admin@34f5d30c{HTTP/1.1}{0.0.0.0:[B]9081[/B]}
INFO  [2016-03-08 10:04:38,583] org.eclipse.jetty.server.Server: jetty-9.0.z-SNAPSHOT
INFO  [2016-03-08 10:04:40,366] com.sun.jersey.server.impl.application.WebApplicationImpl: Initiating Jersey application, version 'Jersey: 1.18.1 02/
19/2014 03:28 AM'

It listens on every inbound ip on port 9080 for the application and 9081 for admin functions.
 

Hylian7

Member
When it boots up it should show the port.

Like here's some output from one of my programs I built for my job.

Code:
INFO  [2016-03-08 10:04:38,549] 
org.eclipse.jetty.setuid.SetUIDListener: Opened application@53a9dd25{HTTP/1.1}{0.0.0.0:[B]9080[/B]}
INFO  [2016-03-08 10:04:38,550] org.eclipse.jetty.setuid.SetUIDListener: Opened admin@34f5d30c{HTTP/1.1}{0.0.0.0:[B]9081[/B]}
INFO  [2016-03-08 10:04:38,583] org.eclipse.jetty.server.Server: jetty-9.0.z-SNAPSHOT
INFO  [2016-03-08 10:04:40,366] com.sun.jersey.server.impl.application.WebApplicationImpl: Initiating Jersey application, version 'Jersey: 1.18.1 02/
19/2014 03:28 AM'

It listens on every inbound ip on port 9080 for the application and 9081 for admin functions.

Okay it's definitely on 8080

Code:
Starting preview server on port 8080

I feel like I'm missing something so stupid, but hours of google have gotten me absolutely nowhere.
 
Okay it's definitely on 8080

Code:
Starting preview server on port 8080

I feel like I'm missing something so stupid, but hours of google have gotten me absolutely nowhere.

Can you post the full startup log?

I'm specifically interested in the things immediately after

Code:
The following paths were found for the configured resources:
 

Hylian7

Member
Can you post the full startup log?

I'm specifically interested in the things immediately after

Code:
The following paths were found for the configured resources:

This is using the Apache Tomcat 8.0 server. I redacted a few personally identifiable things in directories, but it's nothing major.

Code:
usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ]  { -help | start | stop }
Apr 07, 2016 5:42:55 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:server-test' did not find a matching property.
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/8.0.33
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Mar 18 2016 20:31:49 UTC
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         8.0.33.0
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 10
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            10.0
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             C:\Program Files\Java\jre1.8.0_77
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_77-b03
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         C:\Users\[redacted]\Desktop\[redacted]\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         C:\Program Files\Apache Software Foundation\Tomcat 8.0
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\[redacted]\Desktop\[redacted]\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 8.0
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\[redacted]\Desktop\[redacted]\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 8.0\endorsed
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Apr 07, 2016 5:42:55 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_77\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_77/bin/server;C:/Program Files/Java/jre1.8.0_77/bin;C:/Program Files/Java/jre1.8.0_77/lib/amd64;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Python27;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\Java\jdk1.8.0_51\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Skype\Phone\;C:\Users[redacted]\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Users\[redacted]\Desktop\gradle-212-all\gradle-212\bin;C:\Program Files\Java\jdk1.8.0_51\bin;C:\Program Files (x86)\CMake\bin;C:\Program Files\Java\jdk1.8.0_51\bin;C:\Users\[redacted]\Desktop\gradle-212-all\gradle-212\bin;C:\Program Files\eclipse-jee-mars-R-win32-x86_64\eclipse;;.
Apr 07, 2016 5:42:55 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Apr 07, 2016 5:42:55 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Apr 07, 2016 5:42:55 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Apr 07, 2016 5:42:55 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 518 ms
Apr 07, 2016 5:42:55 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 07, 2016 5:42:55 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.33
Apr 07, 2016 5:42:55 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Apr 07, 2016 5:42:55 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Apr 07, 2016 5:42:55 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 360 ms
 

Hylian7

Member
This doesn't contain the line you originally said you saw "Starting preview on port 8080". Is this actually the full log?

I was using a J2EE preview server for that other one. For what it's worth I can post taht one too. I verified this one is also on 8080.

Code:
Starting preview server on port 8080

Modules:
  server-test (/server-test)

2016-04-07 17:51:28.783:INFO::main: Logging initialized @267ms
2016-04-07 17:51:28.866:INFO:oejs.Server:main: jetty-9.2.9.v20150224
2016-04-07 17:51:28.969:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /server-test, did not find org.eclipse.jetty.jsp.JettyJspServlet
2016-04-07 17:51:28.998:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@6442b0a6{/server-test,file:/C:/Users/[redacted]/Desktop/[redacted]/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/server-test/,AVAILABLE}{C:/Users/[redacted]/Desktop/[redacted]/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/server-test}
2016-04-07 17:51:29.045:INFO:oejs.ServerConnector:main: Started ServerConnector@7f71d5ee{HTTP/1.1}{0.0.0.0:8080}
2016-04-07 17:51:29.046:INFO:oejs.Server:main: Started @530ms
 
This is using the Apache Tomcat 8.0 server. I redacted a few personally identifiable things in directories, but it's nothing major.

Code:
usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ]  { -help | start | stop }

I'm wondering what this is.

I don't see any of the resources being bound.

Like you should see things such as

Code:
GET     /product (com.example.product.resources.ProductResource)

It could be a difference in how tomcat does thing. Is there any particular reason why you are going with Tomcat as opposed to using Jetty for the embedded servlet container?
 

Hylian7

Member
I'm wondering what this is.

I don't see any of the resources being bound.

Like you should see things such as

Code:
GET     /product (com.example.product.resources.ProductResource)

It could be a difference in how tomcat does thing. Is there any particular reason why you are going with Tomcat as opposed to using Jetty for the embedded servlet container?

I don't completely understand what Jetty is, is that a type of server I should be using?

Edit: This is from the documentation for Dropwizard, but I still don't completely understand. If it's automatically starting a server, how do I know it actually is? I don't get it.
Jetty for HTTP

Because you can’t be a web application without HTTP, Dropwizard uses the Jetty HTTP library to embed an incredibly tuned HTTP server directly into your project. Instead of handing your application off to a complicated application server, Dropwizard projects have a main method which spins up an HTTP server. Running your application as a simple process eliminates a number of unsavory aspects of Java in production (no PermGen issues, no application server configuration and maintenance, no arcane deployment tools, no class loader troubles, no hidden application logs, no trying to tune a single garbage collector to work with multiple application workloads) and allows you to use all of the existing Unix process management tools instead.
 
I don't completely understand what Jetty is, is that a type of server I should be using?

Edit: This is from the documentation for Dropwizard, but I still don't completely understand. If it's automatically starting a server, how do I know it actually is? I don't get it.

If it's using Catalina, it's using an embedded tomcat servlet container. Jetty is another type of embedded servlet container. You can configure it through the yaml file passed after the server parameter when launching a dropwizard application.
 

Hylian7

Member
If it's using Catalina, it's using an embedded tomcat servlet container. Jetty is another type of embedded servlet container. You can configure it through the yaml file passed after the server parameter when launching a dropwizard application.

So then I guess what I don't understand is, how exactly am I supposed to launch the application?
 
Hey Programming GAF. Two questions.

1) I'm trying to transition from mostly manual QA to either mostly automation testing or outright development. I teach web dev to high school kids, and occasionally make games on the side (game jams and hackathons), so I want to make it my job.

But I need more proof I can code. I want to make examples on my github using:

Python
Java
C# or C++ either one
Maybe Vbscript
And maybe javascript, but I may have to make examples with this anyway for my web dev classes.

But I don't know what will be considered an acceptable example. Help?

2) The web dev classes. I have no idea how to teach high school kids, nevermind teaching them how to make websites. Thankfully they already have some experience, so I'm really just trying to help them improve.

But I don't have a curriculum to work with this time. The person who normally makes them is gone. Any links or tips on how to make one and implement it would be fantastic!

Answering your first question: I think any of those are acceptable, save for VBScript, which isn't really used much anymore. Javascript is great to show off your web development skills, Python for scripting, and the rest to show off data structure knowledge as well as grasping things like OO.
 
1) I'm trying to transition from mostly manual QA to either mostly automation testing or outright development. I teach web dev to high school kids, and occasionally make games on the side (game jams and hackathons), so I want to make it my job.

But I need more proof I can code. I want to make examples on my github using:

Python
Java
C# or C++ either one
Maybe Vbscript
And maybe javascript, but I may have to make examples with this anyway for my web dev classes.

But I don't know what will be considered an acceptable example. Help?

You should play to your strengths and work with the technology stack that the code you currently do manual tests on runs if you interact with that code in any way other than perform manual tests. If you don't have code exposure to the app you are testing you should learn JavaScript, because good mastery of it will let you code both the front end and the back end of applications. Whatever you choose, learning one thing well is generally more marketable as a junior dev than knowing a lot of thing less well.

If you want to get into automated testing you should look at your current test cases, identify what could be automated, build a demo of some tests being automated and then pitch it to your management.


2) The web dev classes. I have no idea how to teach high school kids, nevermind teaching them how to make websites. Thankfully they already have some experience, so I'm really just trying to help them improve.

But I don't have a curriculum to work with this time. The person who normally makes them is gone. Any links or tips on how to make one and implement it would be fantastic!

I would have a strong emphasis towards making the class project-oriented depending on how much classroom time you have.
 

Marcus

Member
hey, so I coded up the card game Dominion in Python. it's playable by up to 4 people in a console window right now, but i wanted to make it available online so only my friends and i could play using it. what would i need to learn to make this playable through a web browser for me and my friends? ive heard of Django and Flask, is that what i should look into?

Either of those work but you will probably have to look into WebSocket options if you want it to be real-time. Flask is probably the easiest one to start with because it doesn't include as much as Django does by default.

i almost forgot to give an update. i finished this a few weeks ago and ended up using Tornado instead of Flask. if anyone is interested, you can play it here. it supports only 1 game at a time and up to 4 players.

it was very fun diving into the world of HTML/CSS/JavaScript :]
 

Kalnos

Banned
i almost forgot to give an update. i finished this a few weeks ago and ended up using Tornado instead of Flask. if anyone is interested, you can play it here. it supports only 1 game at a time and up to 4 players.

it was very fun diving into the world of HTML/CSS/JavaScript :]

That is really cool, nice job! I just so happened to check this thread before going to bed so that was an interesting surprise.
 

Zeus7

Member
There is one global reference to a touchData and you just add that reference to the recordingData. So you keep changing it and it changes every place it's referenced. You need to create a "new" one each time you start a recording.

It is working correctly now, thank you very much.
 
So then I guess what I don't understand is, how exactly am I supposed to launch the application?

In general, there's two common ways to deploy a Java server application. One is to build a WAR file (web archive) and give that file to a servlet container like Tomcat which will then host your application. The other way, which I believe Dropwizard uses, is to embed Tomcat or Jetty in the application and then build a single JAR file that you can just launch via java -jar project.jar. The building should be done by your build/dependecy tool (Maven, Gradle or whatever) which should then produce a nice big .jar file in the build folder with all the project's dependencies.

I suspect your problem is related to the code, not so much the deployment. What does the Resource look like you're having trouble with? Also, you need to register resources with the Jersey context for them to be usable.
 

Hylian7

Member
In general, there's two common ways to deploy a Java server application. One is to build a WAR file (web archive) and give that file to a servlet container like Tomcat which will then host your application. The other way, which I believe Dropwizard uses, is to embed Tomcat or Jetty in the application and then build a single JAR file that you can just launch via java -jar project.jar. The building should be done by your build/dependecy tool (Maven, Gradle or whatever) which should then produce a nice big .jar file in the build folder with all the project's dependencies.

I suspect your problem is related to the code, not so much the deployment. What does the Resource look like you're having trouble with? Also, you need to register resources with the Jersey context for them to be usable.

I already had to submit what I had (when I asked a question about it, they compared this test to a "kobayashi maru" from Star Trek: Basically, there is no right answer, we just want to see how you got here).

Regardless, I was building with Gradle, and I installed it on a server and nothing was happening. I thought that was the wrong thing with Dropwizard, but then reading the documentation more made it sound like it prepares a server built in. It didn't seem to be working though, and I felt like it wasn't launching any server at all, but I have no idea why and could not figure it out. I kept going back to the original skeleton source code they gave me from their github, as well as other Dropwizard examples, but I didn't figure it out.

They're going to have me back in the office sometime next week to discuss my solution, part of what the email said "Just do your best, and if it's a good build, great". These kinds of tests are the most frustrating to me, because I feel like I have to do it perfectly or I fail. I have all the JSON annotations in the Resource, I wanted to use an H2 Database, but had trouble getting that to work, so I had to use an in-memory list, but I did set up DAOs for that as if I were doing it from a DB.
 

Vuze

Member
Somebody around who managed to simulate input in a DirectX application? I'm using C# and tried several ways described on the internet, but none of them work (SendKeys, keybd_event and SendInput). It works fine when I use the physical keys on my KB :/

Just a hobbyist, so I'm not exactly sure what's the matter. Maybe I messed up some where with SendInput though, felt a little overwhelming. I'll check again later but in the meanwhile I'm open to suggestions :)
 

Aikidoka

Member

To install things like OpenMPI, CUDA, Fortran, etc... do you simply use the same commands as you would in Ubuntu - i.e., sudo apt-get install ??

On another note, what's the best resource to learn CUDA? For a project, I decided to try and take my existing code, written in FORTRAN (uses MPI, and openMP), and get it to use GPUs. I've found some of the online documentation to be completely false in some case though. For instance, in using some CUBLAS, an official Nvidia documentation gives the wrong function arguments for whatever reason.
 

luoapp

Member
To install things like OpenMPI, CUDA, Fortran, etc... do you simply use the same commands as you would in Ubuntu - i.e., sudo apt-get install ??

On another note, what's the best resource to learn CUDA? For a project, I decided to try and take my existing code, written in FORTRAN (uses MPI, and openMP), and get it to use GPUs. I've found some of the online documentation to be completely false in some case though. For instance, in using some CUBLAS, an official Nvidia documentation gives the wrong function arguments for whatever reason.

PG Fortran (bought by Nvidia) is the only option for Fortran as far as I know. You should be able to get an edu license.
 

Aikidoka

Member
PG Fortran (bought by Nvidia) is the only option for Fortran as far as I know. You should be able to get an edu license.

Oh yeah, I remember hearing about Portland's Fortran compiler. Also, about the API OpenACC which works similar to OpenMP.

I did find a tutorial (http://www.computationalmathematics.org/topics/files/calling_cuda_from_fortran.html) about being able to inferface/link fortran code with CUDA kernal similar to how one would do with C code - though honestly I'm not too sure on the details or what the advantages any each of the mehtods would have.
 

luoapp

Member
Oh yeah, I remember hearing about Portland's Fortran compiler. Also, about the API OpenACC which works similar to OpenMP.

I did find a tutorial (http://www.computationalmathematics.org/topics/files/calling_cuda_from_fortran.html) about being able to inferface/link fortran code with CUDA kernal similar to how one would do with C code - though honestly I'm not too sure on the details or what the advantages any each of the mehtods would have.

That's standard Fortran calling C function. Everything CUDA is wrapped inside C. IMHO, if you still need to write/port the kernel code to C, you might as well consider rewriting the whole program in C. It will be great if there are existing mature C libraries to link to though.
 

Timedog

good credit (by proxy)
I feel real dumb, but is there a better way to do this? I have a loop and I want to enter an if statement inside the loop every 2 loops, then not enter the next 2 loops, then enter the next 2, and so on. That is, the if statement will be entered on loops 1,2, and 5,6. It will not be entered on loops 3,4, and 7,8.

This is the code I came up with and it works, but it seems like a big fat mess and I'm sure there's a better way to do it that I'm brainfarting:

Code:
for (int i = 1; i <= 8; i++)
{
	if ( (i % 2 == 0 || (i + 1) % 2 == 0) && (i % 4 != 0) && ((i+1)% 4 != 0))
	{
		// make computer read a bit with value 2
	}
	else
		// rocket science
}

I'm sure it needn't be that unreadable to do such a simple task, but my brain is real dumb guys.
 
I feel real dumb, but is there a better way to do this? I have a loop and I want to enter an if statement inside the loop every 2 loops, then not enter the next 2 loops, then enter the next 2, and so on. That is, the if statement will be entered on loops 1,2, and 5,6. It will not be entered on loops 3,4, and 7,8.

This is the code I came up with and it works, but it seems like a big fat mess and I'm sure there's a better way to do it that I'm brainfarting:

Code:
for (int i = 1; i <= 8; i++)
{
	if ( (i % 2 == 0 || (i + 1) % 2 == 0) && (i % 4 != 0) && ((i+1)% 4 != 0))
	{
		// make computer read a bit with value 2
	}
	else
		// rocket science
}

I'm sure it needn't be that unreadable to do such a simple task, but my brain is real dumb guys.

just use a counter, when it reaches 3 (or whatever you need) reset it to zero and return.

edit: actually, I gues you don't need to reset it to zero.

Code:
 ;
for (int i = 1; i <= 8; i++)
{
   
	if ((i==3) || (i==4) || (i==7) || (i==8))
	{
		return;
	}
	else
		// do your stuff here
}
 

Koren

Member
I feel real dumb, but is there a better way to do this? I have a loop and I want to enter an if statement inside the loop every 2 loops, then not enter the next 2 loops, then enter the next 2, and so on. That is, the if statement will be entered on loops 1,2, and 5,6. It will not be entered on loops 3,4, and 7,8.
In this specific case, there's a really simple solution...

If you want to do something when i=0, 1, 4, 5, 8, 9, 12, 13, ... and something else (or nothing) on 2, 3, 6, 7, 10, 11, ... , there's an easy test:

Code:
    if (i & 2) {
        // will be executed when i = 2, 3, 6, 7, 10, 11, ...
    } else {
        // will be executed when i = 0, 1, 4, 5, 8, 9, ...
    }

That's because the second least-significant bit of a counter will switch each two iterations...

You'd better add a comment to explain the behavior of the test, though, because it can be non-obvious.


Edit: obviously, it also works with series like 4/4, 2/2/2/2, 4/2/2, 8/8, 16/2/4/8/2... as long as the sum is a power of 2 and each part is a power of two.

A more "universal" solution would be
Code:
    if ((i % 4)<2) {
        // will be executed when i = 0, 1, 4, 5, 8, 9, ...
    } else {
        // will be executed when i = 2, 3, 6, 7, 10, 11, ...
    }

or
Code:
    switch (i % 4) {
        case 0:
        case 1:
            // will be executed when i = 0, 1, 4, 5, 8, 9, ...
            break
        default :
            // will be executed when i = 2, 3, 6, 7, 10, 11, ...
    }

You can also write (the possibilities are countless ;) )
Code:
    if ((i/2) & 1) {
        // will be executed when i = 2, 3, 6, 7, 10, 11, ...
    } else {
        // will be executed when i = 0, 1, 4, 5, 8, 9, ...
    }
 

Aikidoka

Member
That's standard Fortran calling C function. Everything CUDA is wrapped inside C. IMHO, if you still need to write/port the kernel code to C, you might as well consider rewriting the whole program in C. It will be great if there are existing mature C libraries to link to though.

This code is pretty big and used by a group, so I don't think rewriting it in C is going to be practical. For whatever reasons, when the project was started 3 or so years ago, they wanted to use FORTRAN like lots of scientists in HPC seem to still do. Not even modern Fortran but good old F90 (mostly) with a bit of F77.


Anyways, what's the best/safest way to use the Windows Insider Builds for Bash on Windows? Should I create a new windows account or what?
 
Hi all!

I have a problem with a PHP code I'm writing. First of all: I have zero skills in PHP, I'm a Programmer Analyst but all I've done is related to Cobol, DDBB and the like. So I am less than a newbie here, and I'm just writing code after searching things in Google. I just have no time to make the program work, so I can't study as much as I want!

What do I need? Very simple: I need two arrays, one with Hours and the other one with Prices, so I can make a graph (with JpGraph) just by telling "this array is the X axis, and this other array is the Y axis".

So I have this variable, $array_indicators, as a JSON decoded. And I'm able to get the Hours and Prices stored in $array_indicators. And now I want to declare a new array ($array_hprice), with a sequential numeric index, with two values for each entry: Hour and Price.

This is my code:


$i = 0;

if($array_indicators)
{
foreach ($array_indicators as $valor)
{
// Getting HOUR in the format I need.
$hour = date ('H:i:s', strtotime ( $valor['datetime']) );
// Getting PRICE.
$price = $valor['value'];
// Building array.
$array_hprice[$i] = [$hour, $price];
// Testing result.
echo "Hour: ".$array_hprice[$i][0].", Price: ".$array_hprice[$i][1]."<br>\n";

$i++;
}
}


I tried this code in my house, with a local Apache server and PHP 5.4, and worked perfectly. After this, I was able to create the graph using this two arrays:

array_column($array_hprice, 0);
array_column($array_hprice, 1);

The first one for Hours, the second one for Prices.



Now, return to real world. I put my code in my real server, here in my working place, with PHP 7.0 installed... and it didn't work!! Specifically, this is the part don't working:

$array_hprice[$i] = [$hour, $price];

Apparently, now I can´t declare my array that way. And I don't know why, and I don't know how to do it.

So, please, could anyone help me?? I know my PHP code sure is atrocious... But I don't know what's the best way to get what I need now! Obviously, I could build two separate arrays: one for Hours, and the other for Prices; but that's something I'd like to avoid, if possible...

Real question, then: What's best way to do what I need to do?

Thank you very much!!
 

V_Arnold

Member
You did not initialize the containing array anywhere? I do not remember you being able to explicitily reference an uninitialized array's specific (yet non-existing) elements like the way you are doing....

But my PHP is rusty, to say the least.
 
PHP question

I'd just build up 2 separate arrays, something like

Code:
<?php

date_default_timezone_set('America/Los_Angeles');

$array_indicators = [
    ['datetime' => 1, 'value' => 501],
    ['datetime' => 100, 'value' => 400],
    ['datetime' => 1000, 'value' => 300],
    ['datetime' => 10000, 'value' => 200]
];

$dates = [];
$prices = [];

if ($array_indicators) {
    foreach ($array_indicators as $valor) {
        $dates[] = date('H:i:s', strtotime($valor['datetime']));
        $prices[] = $valor['value'];
    }
}

I'm not familiar with PHP7 yet, but this works on 5.4
 
I'd just build up 2 separate arrays, something like

Code:
<?php

date_default_timezone_set('America/Los_Angeles');

$array_indicators = [
    ['datetime' => 1, 'value' => 501],
    ['datetime' => 100, 'value' => 400],
    ['datetime' => 1000, 'value' => 300],
    ['datetime' => 10000, 'value' => 200]
];

$dates = [];
$prices = [];

if ($array_indicators) {
    foreach ($array_indicators as $valor) {
        $dates[] = date('H:i:s', strtotime($valor['datetime']));
        $prices[] = $valor['value'];
    }
}

I'm not familiar with PHP7 yet, but this works on 5.4

I will prob go with that. I really wanted to do the other way, having just one array with all the needed information. But usualy the simplest is the best.

Thanks for the answer!
 

Koren

Member
For whatever reasons, when the project was started 3 or so years ago, they wanted to use FORTRAN like lots of scientists in HPC seem to still do. Not even modern Fortran but good old F90 (mostly) with a bit of F77.
Habits may be the (bad) reason, but there's still arguments in favor of Fortran. With its support of 2D tables, it's often faster than C/C++ for raw computations (had to use blitz to get an edge with C++), and LAPACK and the like originated from there and used extensively, so it can be trusted.

Is "modern" Fortran really different from F90? I mean, F77 is quite bad, but F90 was nice enough for a low-level language to do mass computations. The compiler I used was especially great at guessing mistakes you had done.
 

Aikidoka

Member
Habits may be the (bad) reason, but there's still arguments in favor of Fortran. With its support of 2D tables, it's often faster than C/C++ for raw computations (had to use blitz to get an edge with C++), and LAPACK and the like originated from there and used extensively, so it can be trusted.

Is "modern" Fortran really different from F90? I mean, F77 is quite bad, but F90 was nice enough for a low-level language to do mass computations. The compiler I used was especially great at guessing mistakes you had done.

When I say modern Fortran, I mean Fortran that allows object-oriented programming like Fortran 2008 (maybe 2003?). And yeah, F90 makes it difficult to write a really slow program - especially if you are only doing array manipulations. I think that's one of its appeals as, from what I've heard, it requires a more advanced programmer to get similar speeds in language like C++. That and the huge legacy code that's available, as you say.

Just recently though, my main advisor became sold on the idea of object-oriented programming and is definitely going that route for the next project.
 

Koren

Member
When I say modern Fortran, I mean Fortran that allows object-oriented programming like Fortran 2008 (maybe 2003?).
I admit I haven't used OO in Fortran... I've mostly done number-crunching with it (astrophysics computations, for example), and there's not much use of OO when you mostly do massive convolution computations...

it requires a more advanced programmer to get similar speeds in language like C++.
The main problem with C/C++ is that there's no n-dimensional table type, so the compiler don't know exactly what you're doing, and is slightly less good at optimizing it.

So you have to do some of the compiler job... and usually, it's either a lot of work, or you'll have a slightly slower code. I would suspect the difference isn't so big now, but I haven't done benchmarks for some time (and some will always argue that 20% increase in speed is significant)

Some people wanted to demonstrate that C++ coud be really quick, though, and developped thinks like Blitz++.

http://blitz.sourceforge.net/

It *is* impressive, often faster than Fortran, and with a syntax I find interesting and expressive.

But to achieve this, they went the extra mile (when you do a convolution on a table, for example, they don't work line-by-line, but use a Hilbert fractal to lower cache-miss... seems a bit crazy, but really effective!)

Always seemed to me rather a proof-of-concept, and an argument that C++ (and OO) can compete with Fortran, than a real tool, but it works, and well.
 
I'd just build up 2 separate arrays, something like

Code:
<?php

date_default_timezone_set('America/Los_Angeles');

$array_indicators = [
    ['datetime' => 1, 'value' => 501],
    ['datetime' => 100, 'value' => 400],
    ['datetime' => 1000, 'value' => 300],
    ['datetime' => 10000, 'value' => 200]
];

$dates = [];
$prices = [];

if ($array_indicators) {
    foreach ($array_indicators as $valor) {
        $dates[] = date('H:i:s', strtotime($valor['datetime']));
        $prices[] = $valor['value'];
    }
}

I'm not familiar with PHP7 yet, but this works on 5.4

Funnily, this code does not work for me - I don't know if the reason is PHP 7.0 or the configuration on my server. Specifically this two lines:

$dates = [];
$prices = [];

Apparently, something in the array declaration is going wrong with my PHP/server. And I don't know what is it!!

Anyway, deleting those two lines works, so I'll go that way. Thanks for all!
 
Funnily, this code does not work for me - I don't know if the reason is PHP 7.0 or the configuration on my server. Specifically this two lines:

$dates = [];
$prices = [];

Apparently, something in the array declaration is going wrong with my PHP/server. And I don't know what is it!!

Anyway, deleting those two lines works, so I'll go that way. Thanks for all!

Weird. Well on PHP >5.5 I guess you could do

Code:
function format_date($timestamp) {
    return date('H:i:s', strtotime($timestamp));
}

$prices = array_column($array_indicators, 'value');
$dates = array_map('format_date', array_column($array_indicators, 'datetime'));
 

TheSeks

Blinded by the luminous glory that is David Bowie's physical manifestation.
Someone explain the .split/.reverse/.join actions in javascript to me.

Why aren't they functions?

Essentially they are going to do what they say they're going to do.

Like:

Code:
var string = "this is a string";
var array = [];

array = string.reverse();
return array;

Should work from my understanding and the quick tutorial I did, but apparently that's "not a function" and it's making me tear my hair out because I have no clue why it wouldn't run like a function?
 

TheSeks

Blinded by the luminous glory that is David Bowie's physical manifestation.
Reverse is a function for arrays and not strings.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse


Try converting your string into an array (.split('')) and then using reverse.

Code:
var array = [];
array = rvrStr;

return array.split(' ');

"SyntaxError: Illegal return statement?"

Ok, that is fine. Let's see if console.log(array.split(' ')); will work:

"TypeError: array.split is not a function."

Wut. I thought I assigned rvrStr into the array?

This is the same shit that stopped me in the CS50 course: Arrays and putting things into them from strings. :/
 

TheSeks

Blinded by the luminous glory that is David Bowie's physical manifestation.
... All this time I've been going about it in the wrong order?

Why is arrays and strings being put into them a pain in the ass no matter what language you use?

"I want to assign this string in the array."

"OKAY!"

"But before that I want to reverse the order of the string/words then put it into the array as a whole word."

"NOT OKAY! :D!"

"..."
 

TheSeks

Blinded by the luminous glory that is David Bowie's physical manifestation.
with ES6 you could use the spread operator

That's thousands of steps ahead of where I am right now. I keep failing to understand arrays, strings and why you can't just shove strings in arrays.

Like

array = [];
jam_into_array = 5, 6, true;

array = jam_into_array;

Would work, AFAIK. But sentences that state they're strings? Oh hell no, you have to bend over backwards to jam those into the array. :/
 

Somnid

Member
Interesting. I tried Array.prototype.reverse.call("hello"). Doesn't work because string aren't mutable. Never realized this but it makes sense.

Code:
  var x = "hello";
  x[0] = "j";
  console.log(x) // hello

Now if only the stupid reverse method didn't mutate.

That's thousands of steps ahead of where I am right now. I keep failing to understand arrays, strings and why you can't just shove strings in arrays.

Like

array = [];
jam_into_array = 5, 6, true;

array = jam_into_array;

Would work, AFAIK. But sentences that state they're strings? Oh hell no, you have to bend over backwards to jam those into the array. :/

That's what spread does. It takes iterable things and let's you jam them into arrays (and vise-versa).
 
Top Bottom