1,080,642 Members — Technology Publication meets Social Media

# Posts by Duki

## Re: Help on C++ code please?! in C++

Can you be more specific about what you're having troubles with?

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Having trouble understanding radix sorts in C++

Hey guys,

I'm trying to understand how radix sort works in C++ : I've looked over the C++ implementation from wikipedia:

``````void radixsort(int *a, int n)
{
int i, b[MAX], m = a[0], exp = 1;
for (i = 0; i < n; i++)
{
if (a[i] > m)
m = a[i];
}

while (m / exp > 0)
{
int bucket[10] =
{  0 };
for (i = 0; i < n; i++)
bucket[a[i] / exp % 10]++;

//accumulate
for (i = 1; i < 10; i++)
bucket[i] += bucket[i - 1];

//transfer
for (i = n - 1; i >= 0; i--)
b[--bucket[a[i] / exp % 10]] = a[i];

for (i = 0; i < n; i++)
a[i] = b[i];
exp *= 10;

#ifdef SHOWPASS
printf("\nPASS   : ");
print(a, n);
#endif
}
}
``````

The portion I'm having trouble with is the accumulation and transfer parts (commented above). What's the point in the accumulation step, and how does the transfer portion work? Can someone shed some light?

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Accessing HTML Form data in MVC controller in ASP.NET

Hey everyone,

I have this problem. I need to access data that the user inputs via the <input /> statement during the controller method.

Here's my code, maybe this will make it more clear:

``````// client side
@using (Html.BeginForm())
{
if (competitorList.Count > 0 && eventList.Count > 0)
{
foreach (Event evt in eventList)
{
<table>
<tr><th>@evt.activity.Name</th></tr>
<tr>
<th>Name</th>
<th>Email</th>
<th>Score</th>
<th>New Score</th>
<th>Update</th>
</tr>
@foreach (Results res in resultList)
{
if (res.EventID == evt.id)
{
string competitorName = Person.getUserByEmail(res.CompetitorEmail).FirstName + Person.getUserByEmail(res.CompetitorEmail).LastName;

<tr>
<td>@competitorName</td>
<td>@res.CompetitorEmail</td>
<td>@res.Score</td>
<td><form action="EventResults"><input type="text" name="score" id="score" /></form></td>
<td>@Html.ActionLink("Update", "UpdateResults", "Competition", new { compId = evt.competitionId, evtId = res.EventID, email = res.CompetitorEmail }, null)</td>
</tr>
}
}
</table>
<hr />
}
}
else
{
<p>There are currently no competitors invited to participate</p>
}
}

// controller
public ActionResult UpdateResults(FormCollection form, int compId, int evtId, string email)
{
//////     this returns 0.0     /////
double score = Convert.ToDouble(form["score"]);

BINC.Models.Results.UpdateResults(evtId, email, score);

List<Event> CompetitionEvents = Event.getEventsByCompetitionId(compId);
ViewBag.CompetitionEvents = CompetitionEvents;

List<Competitor> Competitors = Competitor.getCompetitors(compId);
ViewBag.Competitors = Competitors;

List<Results> Results = Competition.getCompetitorResultsPairings(CompetitionEvents, Competitors);
ViewBag.Results = Results;

ViewBag.Competition = Competition.getCompetitionById(compId);

return View("EventResults");
}
``````

Can someone give me a hand?

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## jtables - how to call httpPost methods? in JavaScript / DHTML / AJAX

hey everyone - I'm trying to figure out how to call the appropriate httpPost methods for a particular jtable instance? I thought it was specified by the actions in the javascript, but I can't figure it out. Can anyone give me a hand? Here's my script and the httpPost method - it's located in the CompetitionController.cs file

`````` <div id="CompetitionTable""></div>

<script type="text/javascript">

//Prepare jtable plugin
\$('#CompetitionTable').jtable({
title: 'The Events List',
paging: true, //Enable paging
pageSize: 10, //Set page size (default: 10)
sorting: true, //Enable sorting
defaultSorting: 'Name ASC', //Set default sorting
actions: {
listAction: '@Url.Action("EventList", "CompetitionController")'
},
fields: {
EventID: {
key: true,
create: false,
edit: false,
list: false
},
EventName: {
title: 'Name',
width: '15%'
},
CompetitorEmail: {
list: false
},
CompetitorName: {
title: 'Competitor',
width: '15%',
},
Score: {
title: 'Score',
width: '10%',
}
}
});

});

</script>

[HttpPost]
public JsonResult EventList(int compId)
{
try
{
//Get data from database
List<Event> events = Event.getEventsByCompetitionId(compId);

//Return result to jTable
return Json(new { Result = "OK", Records = events});
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message });
}
}
``````
Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Passing values from popup box to httppost in ASP.NET

Hey everyone,

I'm trying to code a webform to allow people to input data on several objects in a database. I'd like to have them be able to click an update button for each item they want to update, popup a box for the value, and pass that value to [Httppost] along with some other data.

Does anyone have an idea of where I can get started with this?

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Re: Using httppost in ASP.NET

I tried using the following, but it didn't seem to work either:

`````` @Html.LabelFor(model => model.Score, "New Score   ");
@Html.TextBoxFor(model => model.Score, new { maxlength = 10, style = "width:125px" })
@Html.HiddenFor(model => model.EventID);
@Html.HiddenFor(model => model.CompetitorEmail);
<input type="submit" name="submitButton" value="Update" />
``````
Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Using httppost in ASP.NET

Hey everyone,

I'm having some problems with my code and was hoping someone could give me a hand. Here's the snippet I'm working with:

``````[Authorize]
public ActionResult EventResults(int id)
{
List<Event> CompetitionEvents = Event.getEventsByCompetitionId(id);
ViewBag.CompetitionEvents = CompetitionEvents;

List<Person> Competitors = Competition.getCompetitorsByCompetitionID(id);
ViewBag.Competitors = Competitors;

List<Results> Results = Competition.getCompetitorResultsPairings(CompetitionEvents, Competitors);
ViewBag.Results = Results;

ViewBag.OrganizerEmail = Competition.getCompetitionById(id).OrganizerEmail;

return View();
}

@model BINC.Models.Results
@using BINC.Models;

@{
var eventList = ViewBag.CompetitionEvents as List<Event>;
var competitorList = ViewBag.Competitors as List<Person>;
var resultList = ViewBag.Results as List<Results>;
}

<h2></h2>

<p>Results:</p>
@using (Html.BeginForm())
{
foreach (var evt in eventList)
{
<fieldset>
<legend>@evt.activity.Name</legend>

<p>Event Description:  @evt.activity.Description</p>
@foreach (var competitor in competitorList)
{
foreach (var result in resultList)
{
if (result.EventID == evt.id && result.CompetitorEmail == competitor.Email)
{
<p>Competitor:  @competitor.FirstName @competitor.LastName</p>
<p>Score:  @result.Score</p>

if (ViewBag.OrganizerEmail.Equals(@User.Identity.Name))
{
@Html.LabelFor(model => model.Score, "New Score   ");
@Html.TextBoxFor(model => model.Score, new { maxlength = 10, style = "width:125px" })
<input type="submit" name="submitButton" value="Update" />
}
}
}
}
</fieldset>
}
}

[HttpPost]
public ActionResult EventResults(Results res)
{
//stuff
}
``````

My problem is I want to pass in the value of the current result-set, not the Result model object.
For example, when I put the value '15' into the text box and click 'Update', I'm passing the Result model object to the httppost method, which has everything set to null other than the 'score' field that I just entered.

Am I over complicating this? Is there an easier way?

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## How to interact with wordpress user accounts in PHP

Hey everyone,

I'm pretty new to web design in general, so I'm not really sure how to get started with this. I have a wordpress site that I would like to be able to manage user profiles on. The built in account management stuff works great for regular logon/off sessions, but there are some features I would like to make available for our users.

I maintain a wellness site and I would like to allow users who are logged on to be able to click a button that says "Claim Points" or something similar for events they participate in - when they click the button, it would automatically update their total wellness points on their profile. Can anyone suggest where I should start on this? I'm assuming PHP might be an easy way to interact with users, but I'm really not sure where to begin.

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Web server - port forwarding in RSS, Web Services and SOAP

Hey everyone,

Trying to configure an apache web server on my home network and had a question about port forwarding. I have my router set to forward everything on port 80 to the webserver, but I wanted to see if there were any ramifications of this that I may not be aware of? I can still browse the net fine from my other computers, and can access the website externally. But does this create a security risk of any kind? Is there a better (safer) way to do this?

We checked with the dns company, and they said they couldn't do port matching (i.e., could only point our url to xxx.xxx.xxx.xxx and not xxx.xxx.xxx.xxx:<port>) - does this sound normal? Are there hosting companies that do allow this type of thing?

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Solaris build: -qlanglvl:newexcp turned on by default? in C++

Hey everyone,

Anyone know if Solaris, by default, throws an out of memory exception when 'new' is called but the system has run out of memory? I know Windows systems has this turned on by default, and AIX doesn't. But I can't find anything related to Solaris.

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Re: Polymorphism - what am I not getting? in Java

Whoops - forgot the level of access had to match also (private vs. public). Marking as solved. :)

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Solved:Polymorphism - what am I not getting? in Java

When I debug this method, I can clearly see that currentNode = Workstation, so I am puzzled as to why I'm still entering into the "Node" buffer print, rather than the "Workstation" buffer print. Shouldn't polymorphism handle this for me?:

part of Node Class

``````public void printToBufferAsHTML(Network network, StringBuffer buf) {

Node currentNode = this;
buf.append("\n\n<UL>");
do {
buf.append("\n\t<LI> ");

if (isValidNode(currentNode))
currentNode.printNodeToBufferAsHTML(buf, currentNode);
else
buf.append("(Unexpected)");

buf.append(" </LI>");

currentNode = currentNode.nextNode;
} while (network.notCompleteCycle(currentNode));
buf.append("\n\t<LI>...</LI>\n</UL>\n\n</BODY>\n</HTML>\n");
}

private void printNodeToBufferAsHTML(StringBuffer buf, Node currentNode) {
buf.append("Node ");
buf.append(currentNode.name);
buf.append(" [Node]");
}``````
``````public class Workstation extends Node{

public Workstation(String _name) {
super(_name);
}

public Workstation(String _name, Node _nextNode) {
super(_name, _nextNode);
}

public void printNodeToBufferAsHTML(StringBuffer buf, Node currentNode) {
buf.append("Workstation ");
buf.append(currentNode.name);
buf.append(" [Workstation]");
}
}``````
Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Re: Clear console screen? in Java

Through Java code.

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Clear console screen? in Java

Hey everyone,

I've searched around Google a bit but most places suggest just using "\n" over and over. This gets messy though, for the code and the interface. Is there a built in method for Java that can clear the console?

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Re: Eclipse XML Encoding in Java

Ok, here's my updated code ... I can't get the ArrayLists to print to file though :(

``````package main;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

Notebook book = new Notebook();

Note note1 = new Note();
Tag tag1 = new Tag();

book.saveAs();

System.out.println("Finished.");

}

}``````
``````package main;

import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;

public class Notebook implements java.io.Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;

/* constructors */
public Notebook (){
id = nextId;
nextId++;
myTitle = "Title" + id;
};

public Notebook (String newTitle){
id = nextId;
nextId++;
myTitle = newTitle;
};

/*	members	 */

//persistent objects
public int id;
public static int nextId = 0;
public String myTitle;

public ArrayList<Tag> myTags = new ArrayList<Tag>();
public ArrayList<Note> myNotes = new ArrayList<Note>();

/*	methods	*/

//getters & setters
public int getID() { return id; }
public void setID(int newID) { id = newID; }

public String getMyTitle() { return myTitle; }
public void setMyTitle(String newTitle) { myTitle = newTitle; }

public ArrayList<Tag> getMyTags() { return myTags; }
public void setMyTags(ArrayList<Tag> newTag) { myTags = newTag; }

public ArrayList<Note> getMyNotes() { return myNotes; }
public void setMyNotes(ArrayList<Note> newNotes) { myNotes = newNotes; }

public void saveAs() {

try {
XMLEncoder n = new XMLEncoder(new BufferedOutputStream(
new FileOutputStream(getMyTitle() + ".xml")));
n.writeObject(this);
n.close();
} catch (Exception e) {
System.out.println(e);
}
}

}``````
``````package main;

import java.util.ArrayList;

public class Note implements java.io.Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;

/* constructors */
public Note(){
id = nextId;
nextId++;

myTitle = "Note" + id;
myText = null;
myParent = null;
};

public Note(String newTitle, Notebook newParent){

id = nextId;
nextId++;

myTitle = newTitle;
myText = null;
myParent = newParent;
};

/* members */

//Persistent objects
public int id;
public static int nextId = 0;

public String myTitle;
public String myText;

public Notebook myParent;

public ArrayList<Tag> myTags = new ArrayList<Tag>();
public ArrayList<Note> myLinksFrom = new ArrayList<Note>();
public ArrayList<Note> myLinksTo = new ArrayList<Note>();

/* methods */

//getters and setters
public int getId(){return id;}
public void setId(int newID) {id = newID;}

public String getMyTitle(){return myTitle;}
public void setMyTitle(String newTitle){myTitle = newTitle;}

public String getMyText() {return myText;}
public void setMyText(String newText) {myText = newText;}

public Notebook getMyParent() {return myParent;}
public void setMyParent(Notebook newParent){myParent = newParent;}

public ArrayList<Tag> getMyTags() {return myTags;}
public void setMyTags(ArrayList<Tag> newTags) {myTags = newTags;}

}``````
``````package main;

public class Tag implements java.io.Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;

/* constructors */
public Tag(){
id = nextId;
nextId++;
myTitle = null;
};

public Tag(String newTitle){
id = nextId;
nextId++;
myTitle = newTitle;
};

/* members */

//Persistent Objects
public int id;
public static int nextId = 0;
public String myTitle;

/* methods */

//getters and setters
public int getId(){return id;}
public void setId(int newId){id = newId;}

public String getMyTitle(){return myTitle;}
public void setMyTitle(String newTitle){myTitle = newTitle;}

}``````
``````<?xml version="1.0" encoding="UTF-8"?>
<java version="1.7.0" class="java.beans.XMLDecoder">
<object class="main.Notebook" id="Notebook0">
<void class="main.Notebook" method="getField">
<string>id</string>
<void method="set">
<object idref="Notebook0">
<void class="main.Notebook" method="getField">
<string>myTitle</string>
<void method="set">
<object idref="Notebook0"/>
<string>Title0</string>
</void>
</void>
</object>
<int>0</int>
</void>
</void>
</object>
</java>``````

Edit:
I changed my main method to use the get/set methods for my classes, and I now have more xml output - does it look correct, though?

``````//new main

package main;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

Notebook book = new Notebook();

Note note1 = new Note();
Tag tag1 = new Tag();

book.saveAs();

System.out.println("Finished.");

}

}``````
``````<?xml version="1.0" encoding="UTF-8"?>
<java version="1.7.0" class="java.beans.XMLDecoder">
<object class="main.Notebook">
<void property="ID">
<int>0</int>
</void>
<void property="myNotes">
<object class="main.Note">
<void property="id">
<int>0</int>
</void>
<void property="myTitle">
<string>Note0</string>
</void>
</object>
</void>
</void>
<void property="myTags">
<object class="main.Tag">
<void property="id">
<int>0</int>
</void>
</object>
</void>
</void>
<void property="myTitle">
<string>Title0</string>
</void>
</object>
</java>``````
Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Re: Eclipse XML Encoding in Java

So if everything is stored in a single Notebook object, and I write that object to XML ... it will recursively go through and write all it's objects, and it's object's-objects, it's arrays, it's member object's arrays etc.?

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Re: Eclipse XML Encoding in Java

The code is quite big at this point - however, I will post if absolutely necessary. As a general idea of what I'm trying to do, I have the following setup:

``````Notebook (class)
--- contains Array of Notes (class)
--- contains Array of Tags (class)

Note (class)
--- contains Array of Tags (class)
--- contains members (e.g., String for the note text)

Tag (class)
--- contains members (e.g., String for tag text)``````

So, I'd like to be able to save the Notebook to XML and also restore these objects if requested. As for naming and methods, is there anything other than getMember, setMember methods I need?

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Re: Eclipse XML Encoding in Java

>Don't mix the definition of bean and list classes. Try to define a new list class.

That's not really an option at this point - is there any other way around this?

Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Strings don't match? in Java

Can someone explain why, when I input 'mytag' it does find it? When I debug, it shows the text matches, but the IDs are different. Not sure why that would matter?

``````public void RemoveTag() throws IOException, NoSuchTagException{

System.out.printf("Tag to delete:  ");

for (int i = 0 ; i < tags.size() ; i++)
{
if (tempTagText == tags.get(i).getTagName().toString())
{
tags.remove(i);
System.out.println("Tag " + tempTagText + " removed.");
return;
}
}
throw
new NoSuchTagException("The entered text does not match any tag");
}
}``````
``````package main;

public class Tag {

public Tag(String name) {
tagName = name;
tagID = nextTagID;
nextTagID++;
};

private static int nextTagID = 0;

public void setTagName(String name)
{
tagName = name;
}

public String getTagName()
{
return tagName;
}

public String tagName;
public int tagID;

}``````
Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817
Skill Endorsements: 7

## Re: Eclipse XML Encoding in Java

Hm, still not writing out anything. Here's my Shelf class again, with the methods you suggested:

``````package main;

import java.util.ArrayList;

public class Shelf implements java.io.Serializable {

public Shelf() {
shelfName = "New Shelf" + nextShelfID;
shelfID = nextShelfID;
nextShelfID++;
};

public Shelf(String name) {
shelfName = name;
shelfID = nextShelfID;
nextShelfID++;
};

private String shelfName;
static private int nextShelfID = 0;
private int shelfID;

public ArrayList<Notebook> notebooks = new ArrayList<Notebook>();

public void setShelfName(String name) {
shelfName = name;
}

public ArrayList<Notebook> getNotebooks() {
return this.notebooks;
}

public void setNotebooks(ArrayList<Notebook> notebooks) {
this.notebooks = notebooks;
}

public String getShelfName() {
return shelfName;
}

public int getShelfID() {
return shelfID;
}

public void setShelfID(int id) {
shelfID = id;
}

public int getNextShelfID() {
return nextShelfID;
}

public void PrintProperties() {
System.out.println("Shelf Name: " + shelfName);
System.out.println("Shelf ID: " + shelfID);
}
}``````
Duki
Nearly a Posting Virtuoso
1,483 posts since Jun 2006
Reputation Points: 817