|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On March 09 2014 18:13 bo1b wrote:Show nested quote +On March 09 2014 16:38 obesechicken13 wrote:ruby on rails is so complicated... how do I even run a stupid script? Controllers and views and shit... There's such a huge learning curve and this tutorial just throws you into the water http://guides.rubyonrails.org/getting_started.html and tells you to flap your arms. I'm trying to convert a json to an xml using ruby. http://stackoverflow.com/questions/4272410/how-can-i-convert-json-to-xml-in-ruby require 'active_support' #for to_xml() 'gem install activesupport' use the 2.3 branch require 'json' #part of ruby 1.9 but otherwise 'gem install json'
my_json = "{\"test\":\"b\"}" my_xml = JSON.parse(my_json).to_xml(:root => :my_root)
Where do I define my json variable that's being received? What does :root => :my_root mean? What does \"test\":\"b\" mean? Can I run this code standalone without a rails server? I keep getting an error undefined method "to_xml" how do I resolve? Is there something I need to install? Is ":root" a symbol? Where do you define the :my_root symbol? What would an example be? There's just so many questions and no one to hold my hand and walk me through it D:< It could be an idea to learn a bit of ruby, if you can stand a text format then I found this guys tutorials to be pretty decent: http://ruby.learncodethehardway.org/book/ Thanks, I figured it out in the end.
I've gone through a few ruby tutorials, part of the codeacademy one. But it hasn't been too helpful.
Now I'm trying to figure out how to make a connection from the client to server side through ruby on rails.
+ Show Spoiler [fixed code] +#require 'active_support' #for to_xml() 'gem install activesupport' use the 2.3 branch require "active_support/core_ext/hash/conversions" {}.to_xml#activesupport no longer loads everything require 'json' #part of ruby 1.9 but otherwise 'gem install json'
#preparsing of json, you must escape single quotes with two backslashes content = '{"catalog":{"book":[{"author":"Gambardella, Matthew","title":"XML Developer\'s Guide","genre":"Computer","price":"44.95","publish_date":"2000-10-01","description":"An in-depth look at creating applications \n with XML.","id":"bk101"}]}}' json_content = content #json object my_json = json_content my_xml = JSON.parse(my_json).to_xml(:root => :my_root) print(my_xml)
edit: Stuck again now with making connections and 422 errors.
|
Starting to get a bit more hang on the 32-bit AVR now, but I'm not really impressed by the documentation of the ASF.
|
I have a design problem that I haven't been able to find a good solution to.
So far I have a thermometer (or a simulater of one) that sends its temperature every second over TCP to a server that calculates an average of the temperatures. Now I'm building an RMI-application where a client connects to the RMI-server and then reads the temperature. In the long run it's gonna be a control system for an "intelligent house", where you can check the temp in each room, change aircon, etc. from you mobile device.
How should I share the information between the different parts of the program? Save it in a file, Make some PublicStatic var or am I missing a clever solution?
This is probably pretty basic stuff, but after wrestling the rmi-stuff and finally getting it to work after hours I can't figure out an elegant solution.
|
+ Show Spoiler +Need another nudge in the right direction concerning PHP/HTML. I have a simple form which pretty much does: if (isset($_POST['submit'])) { } elseif (isset($_POST['confirm'])) { } else { }
It is pretty much a form with a submit, then confirmation screen (with a modify button which goes back to previous screen). To implement the modify button, I used a input type submit button. On form submits, the form would just go back to itself. Since it was not a name = "submit" or "confirm", it would go into the else and I used $_POST array to fill in the form with what data it had before by doing something like: if (isset($_POST['event_name'])) { $event_name = $_POST['event_name']; } else { $event_name = ""; }
And then the different form fields would use $event_name or its respective var to fill in the default value. But by doing this, I broke my form's reset button (input type = "reset") which would have cleared all the fields in the form, which it does not do so after Modify is pressed. Anyone know of a better way I can fix this? I currently just have my reset button refresh the page right now, which isn't so ideal. tldr: my fields use $vars as the value, initially they are set to nothing so that's why my reset works by clearing the fields, because it is just setting them to "". However after using the Modify button, the $vars are no longer "", so reset changes the values to them every time. Kinda just decided to live with it.
More concerned about these corrupted characters that appear after I click on Modify. Not sure where they came from.
![[image loading]](http://i.stack.imgur.com/GGXyD.png) Seems like it is an encoding thing..
BOM thing. Not fun. First time encountering it.
|
Hello peoples. Programming noob here taking his first class of C++ with no prior experience beforehand. Was hoping you guys could help me with some questions I have on a particular assignment. If asking about programming homework isn't allowed, please forgive me and ignore I guess.
So on one of the programs we were asked to write, we have to use functions. Instead of entering in the values of 2 variables I need (sales and advance) in main, the instructions are telling me to "write one function that reads the input using alias parameters."
I'm not sure if these instructions are ambiguous or not, but I interpreted it as "call a function, read in the values into that function, and return those values to main by way of alias parameters."
To attempt this, I made 2 variables in main, "sales" and "advance" with the value 0 in both of them, because I intended to change those values using the aliases in the function. So I call the function after that, but nothing shows up and I'm unable to enter in data into my function.
Here's the code I have right now. + Show Spoiler + #include <iostream> using namespace std;
void inputValues(float, float);
void inputValues (float & val1, float & val2) { float sales; float advance; cout << "amount of sales?"; cin >> sales; cout << " amount of advance taken?"; cin >> advance;
sales = val1; advance = val2; return; }
int main() { float sales = 0; float advance = 0; void inputValues(float & sales, float & advance); return 0; }
I've spent hours googling for an answer to my problem with no success. After trying a bunch of things, my thoughts are that you can't enter in data into a function. A function only takes in data and does stuff with that data. Am I correct in this? - that you can't enter information directly into a function, it has to be taken from main?
Thanks.
|
You are calling a function using a function definition
void inputValues(float & sales, float & advance);
Instead, you should be using:
inputValues(sales, advance);
As for the method using the ampersands, it's known as "call by reference". When you make a function prototype (e.g. void inputValues(float sales, float advance) , the variables within the parentheses are only created in memory when the function is called: inputValues(1.0, 2.0);
Then, within memory, two boxes are created called sales, and advance, only accessible within that function "instance", with the contents which were copied to the function. In this case, sales = 1.0, and advance = 2.0.
When you define a variable with an ampersand, you're actually not assigning new memory. Instead, you're creating a second variable name (basically) which points to some existing memory. E.g:
int main() { int x = 10; int & xReference = x; cout << x << endl; //Prints 10 xReference++; cout << x << endl; //Prints 11 }
So, when you call a function which defines reference variables, you don't set aside any memory. What is being modified, then? The original box of memory. In your case, the original variables of float sales; and float advance; are being modified, via the reference variables (which only exist inside that "instance" of the function inputValues).
|
On March 10 2014 13:17 Epishade wrote:Hello peoples. Programming noob here taking his first class of C++ with no prior experience beforehand. Was hoping you guys could help me with some questions I have on a particular assignment. If asking about programming homework isn't allowed, please forgive me and ignore I guess. So on one of the programs we were asked to write, we have to use functions. Instead of entering in the values of 2 variables I need (sales and advance) in main, the instructions are telling me to "write one function that reads the input using alias parameters." I'm not sure if these instructions are ambiguous or not, but I interpreted it as "call a function, read in the values into that function, and return those values to main by way of alias parameters." To attempt this, I made 2 variables in main, "sales" and "advance" with the value 0 in both of them, because I intended to change those values using the aliases in the function. So I call the function after that, but nothing shows up and I'm unable to enter in data into my function. Here's the code I have right now. + Show Spoiler + #include <iostream> using namespace std;
void inputValues(float, float);
void inputValues (float & val1, float & val2) { float sales; float advance; cout << "amount of sales?"; cin >> sales; cout << " amount of advance taken?"; cin >> advance;
sales = val1; advance = val2; return; }
int main() { float sales = 0; float advance = 0; void inputValues(float & sales, float & advance); return 0; }
I've spent hours googling for an answer to my problem with no success. After trying a bunch of things, my thoughts are that you can't enter in data into a function. A function only takes in data and does stuff with that data. Am I correct in this? - that you can't enter information directly into a function, it has to be taken from main? Thanks. One sure problem in your function is that you're overwriting what you've just inputted into the local variables rather than returning something new through the references. (see comments)
void inputValues (float & val1, float & val2) { float sales; float advance; cout << "amount of sales?"; cin >> sales; cout << " amount of advance taken?"; cin >> advance;
sales = val1; // perhaps this should be: val1 = sales ? advance = val2; // as above
return; }
|
Hell yeah, thanks for the help. I couldn't figure out for the life of me why it kept skipping the couts I had in my original function - then it turns out I just had something silly like calling the function wrong.
Fixed that, and changed the function code to look like this: + Show Spoiler +void inputValues (float & val1, float & val2) { float & sales = val1; float & advance = val2; cout << "amount of sales?"; cin >> sales; cout << " amount of advance taken?"; cin >> advance;
return; }
So I figured, based on your example, that I wouldn't need to reassign the variables to read sales = val1; advance = val2. So I got rid of those from before and added the ampersands to change the original values in main. It worked and I was able to print out those values in main to confirm. Yay. Thanks again!
On March 10 2014 14:12 Mstring wrote:Show nested quote +On March 10 2014 13:17 Epishade wrote:Hello peoples. Programming noob here taking his first class of C++ with no prior experience beforehand. Was hoping you guys could help me with some questions I have on a particular assignment. If asking about programming homework isn't allowed, please forgive me and ignore I guess. So on one of the programs we were asked to write, we have to use functions. Instead of entering in the values of 2 variables I need (sales and advance) in main, the instructions are telling me to "write one function that reads the input using alias parameters." I'm not sure if these instructions are ambiguous or not, but I interpreted it as "call a function, read in the values into that function, and return those values to main by way of alias parameters." To attempt this, I made 2 variables in main, "sales" and "advance" with the value 0 in both of them, because I intended to change those values using the aliases in the function. So I call the function after that, but nothing shows up and I'm unable to enter in data into my function. Here's the code I have right now. + Show Spoiler + #include <iostream> using namespace std;
void inputValues(float, float);
void inputValues (float & val1, float & val2) { float sales; float advance; cout << "amount of sales?"; cin >> sales; cout << " amount of advance taken?"; cin >> advance;
sales = val1; advance = val2; return; }
int main() { float sales = 0; float advance = 0; void inputValues(float & sales, float & advance); return 0; }
I've spent hours googling for an answer to my problem with no success. After trying a bunch of things, my thoughts are that you can't enter in data into a function. A function only takes in data and does stuff with that data. Am I correct in this? - that you can't enter information directly into a function, it has to be taken from main? Thanks. One sure problem in your function is that you're overwriting what you've just inputted into the local variables rather than returning something new through the references. (see comments) void inputValues (float & val1, float & val2) { float sales; float advance; cout << "amount of sales?"; cin >> sales; cout << " amount of advance taken?"; cin >> advance;
sales = val1; // perhaps this should be: val1 = sales ? advance = val2; // as above
return; }
Though I didn't see your post before I posted, thanks for trying to help too. I tested it and your solution works too. I couldn't debug it before because I kept calling the function wrong, so I wasn't quite sure what to fix without being able to access it. But you're right, that would have overwritten the variables I was trying to send back ^^.
|
On March 10 2014 14:19 Epishade wrote:Hell yeah, thanks for the help. I couldn't figure out for the life of me why it kept skipping the couts I had in my original function - then it turns out I just had something silly like calling the function wrong. Fixed that, and changed the function code to look like this: + Show Spoiler +void inputValues (float & val1, float & val2) { float & sales = val1; float & advance = val2; cout << "amount of sales?"; cin >> sales; cout << " amount of advance taken?"; cin >> advance;
return; }
So I figured, based on your example, that I wouldn't need to reassign the variables to read sales = val1; advance = val2. So I got rid of those from before and added the ampersands to change the original values in main. It worked and I was able to print out those values in main to confirm. Yay. Thanks again! You don't even need the local variables:
void inputValues (float & sales, float & advance) { cout << "amount of sales?"; cin >> sales; cout << " amount of advance taken?"; cin >> advance; }
Will do the exact same thing.
|
On March 10 2014 14:22 Mstring wrote:Show nested quote +On March 10 2014 14:19 Epishade wrote:Hell yeah, thanks for the help. I couldn't figure out for the life of me why it kept skipping the couts I had in my original function - then it turns out I just had something silly like calling the function wrong. Fixed that, and changed the function code to look like this: + Show Spoiler +void inputValues (float & val1, float & val2) { float & sales = val1; float & advance = val2; cout << "amount of sales?"; cin >> sales; cout << " amount of advance taken?"; cin >> advance;
return; }
So I figured, based on your example, that I wouldn't need to reassign the variables to read sales = val1; advance = val2. So I got rid of those from before and added the ampersands to change the original values in main. It worked and I was able to print out those values in main to confirm. Yay. Thanks again! You don't even need the local variables: void inputValues (float & sales, float & advance) { cout << "amount of sales?"; cin >> sales; cout << " amount of advance taken?"; cin >> advance; }
Will do the exact same thing.
Hmm, I tested this version but it wouldn't compile. I needed to keep the local variables for it to compile (though then there's a logic error if I don't add the val1=sales and val2=advance because it doesn't send back the variables I want it to). Your original solution worked though.
|
On March 10 2014 14:32 Epishade wrote:Show nested quote +On March 10 2014 14:22 Mstring wrote:On March 10 2014 14:19 Epishade wrote:Hell yeah, thanks for the help. I couldn't figure out for the life of me why it kept skipping the couts I had in my original function - then it turns out I just had something silly like calling the function wrong. Fixed that, and changed the function code to look like this: + Show Spoiler +void inputValues (float & val1, float & val2) { float & sales = val1; float & advance = val2; cout << "amount of sales?"; cin >> sales; cout << " amount of advance taken?"; cin >> advance;
return; }
So I figured, based on your example, that I wouldn't need to reassign the variables to read sales = val1; advance = val2. So I got rid of those from before and added the ampersands to change the original values in main. It worked and I was able to print out those values in main to confirm. Yay. Thanks again! You don't even need the local variables: void inputValues (float & sales, float & advance) { cout << "amount of sales?"; cin >> sales; cout << " amount of advance taken?"; cin >> advance; }
Will do the exact same thing. Hmm, I tested this version but it wouldn't compile. I needed to keep the local variables for it to compile (though then there's a logic error if I don't add the val1=sales and val2=advance because it doesn't send back the variables I want it to). Your original solution worked though. Notice in my version there is no such thing as val1 or val2: I changed the name of the parameters to sales and advance. Cin then acts directly rather than going through the middle man of the local variable.
|
Ohhh, that was dumb of me not to notice. I didn't copy the header, just the code beneath it.
I guess that kinda makes a difference haha. But yeah, that looks a lot cleaner than my code. It works too, but I'd feel morally wrong taking it from someone else for this assignment. I feel obligated to stick with my uglier unsightly code haha.
Thanks.
Edit: Actually, looking at it again, it is kinda useless to have those extra variables. I think I'll take your suggestion.
|
On March 10 2014 14:42 Epishade wrote: Edit: Actually, looking at it again, it is kinda useless to have those extra variables. I think I'll take your suggestion. I knew you'd come around XD
|
Escaping from code and software for a while:
What sites/blogs/magazines/other do you browse to keep up with latest trends in hardware and computer architecture?
Like most programmers (?) I am more interested in software than hardware but obviously it's important to understand what you are programming against. Especially if you work in a niche environment such as high performance computing.
So any tips on sources one might use to stay up to date?
|
never heard the term alias parameter before... what's it supposed to mean? reference?
|
Apparently so. My teacher told us the terms were interchangeable, but apparently not a lot of people call it alias so much as reference. I think my teacher was just giving it a different term to make it easier to memorize for us though, as not very many results have come up when I type in alias compared to reference.
|
Decided to write a set of hash table functions as a learning exercise. Took a few hours and it's working fine, except that I forgot that hash tables are supposed to map keys to distinct values. So now I have a bunch of hash functions that store the keys themselves as values, and I have to go rewrite them all.
I hate it when I make dumb mistakes like this while programming. FML
|
|
|
On March 11 2014 00:13 ParasitJonte wrote: Escaping from code and software for a while:
What sites/blogs/magazines/other do you browse to keep up with latest trends in hardware and computer architecture?
Like most programmers (?) I am more interested in software than hardware but obviously it's important to understand what you are programming against. Especially if you work in a niche environment such as high performance computing.
So any tips on sources one might use to stay up to date?
Hacker News is a pretty popular news aggregator. /r/programming would be another. I'd suggest glancing at them occasionally until you find specific blogs that interest you. Don't get too sucked into meta-programming discussions that thrive on aggregator sites.
|
|
|
|
|
|
|
|