Why does the C# compiler not even complain with a warning on this code? :
if (this == null)
{
// ...
}
Obviously the condition will never be satisfied..
Besides wrapping all your code in try except, is there any way of achieving the same thing as running your script like python -mpdb script? I'd like to be able to see what went wrong when an exception gets raised.
I need to deploy a new item/project template and I found out that the way to do it is to copy it to [Visual Studio folder]\Common7\IDE\ItemTemplates.
How can I find where VS was installed (in my case VS2010)?
WiX code will be welcomed...
Currently I'm having to include a significant chunk of XML in the app.config to get the CAB CacheManager going and I'd rather hide the configuration away in my code.
Is there any way to programmatically configure an Enterprise Library Caching Application Block's CacheManager?
the following code reads an input array, and constructs a BST from it. if the current arr[i] is a duplicate, of a node in the tree, then arr[i] is discarded. count in the struct node refers to the number of times a number appears in the array. fi refers to the first index of the element found in the array. after the insertion, i am doing a post-order traversal of the tree and printing the data, count and index (in this order). the output i am getting when i run this code is:
0 0 7
0 0 6
thank you for your help.
Jeev
struct node{
int data;
struct node *left;
struct node *right;
int fi;
int count;
};
struct node* binSearchTree(int arr[], int size);
int setdata(struct node**node, int data, int index);
void insert(int data, struct node **root, int index);
void sortOnCount(struct node* root);
void main(){
int arr[] = {2,5,2,8,5,6,8,8};
int size = sizeof(arr)/sizeof(arr[0]);
struct node* temp = binSearchTree(arr, size);
sortOnCount(temp);
}
struct node* binSearchTree(int arr[], int size){
struct node* root = (struct node*)malloc(sizeof(struct node));
if(!setdata(&root, arr[0], 0))
fprintf(stderr, "root couldn't be initialized");
int i = 1;
for(;i<size;i++){
insert(arr[i], &root, i);
}
return root;
}
int setdata(struct node** nod, int data, int index){
if(*nod!=NULL){
(*nod)->fi = index;
(*nod)->left = NULL;
(*nod)->right = NULL;
return 1;
}
return 0;
}
void insert(int data, struct node **root, int index){
struct node* new = (struct node*)malloc(sizeof(struct node));
setdata(&new, data, index);
struct node** temp = root;
while(1){
if(data<=(*temp)->data){
if((*temp)->left!=NULL)
*temp=(*temp)->left;
else{
(*temp)->left = new;
break;
}
}
else if(data>(*temp)->data){
if((*temp)->right!=NULL)
*temp=(*temp)->right;
else{
(*temp)->right = new;
break;
}
}
else{
(*temp)->count++;
free(new);
break;
}
}
}
void sortOnCount(struct node* root){
if(root!=NULL){
sortOnCount(root->left);
sortOnCount(root->right);
printf("%d %d %d\n", (root)->data, (root)->count, (root)->fi);
}
}
I have Google'd my butt off, and I can't find anything on this topic.
I am trying to create a download client using Java, and I have figured out how to download files with Java, but I want to accelerate the download speed. I know how this works (opening several connections to the download server), but how can I achieve this?
I am looking for either some detailed explanation of such an algorithm or some code examples.
I have a VS.NET 2008 project. Is it possible to check for classes that are not used anywere in the project? With FXcop I can find unused variables and unused code, but not unused classes.
i'm trying to get the c++ client for mongodb working in visual studio 2008. i can reference the includes, but whenever i tell the linker about the mongodb .lib file i get the following error: "fatal error LNK1257: code generation failed". if visual studio can't find the .lib, then i get a bunch of unresolved externals errors. i'm really pretty lost at this point.
I know this seems to be a very basic questions but I can't figure out how to give the textbox the focus on PageLoad.
Since this is a Login Control, I have no individual control over each textbox thru code the way I am used to it.
Does anyone happen to know how to give focus to the control please.
Steve
I tried to summarize the this as best as possible in the title. I am writing an initial value problem solver in the most general way possible. I start with an arbitrary number of initial values at arbitrary locations (inside a boundary.) The first part of my program creates a mesh/grid (I am not sure which is the correct nuance), with N points total, that contains all the initial values. My goal is to optimize the mesh such that the spacing is as uniform as possible. My solver seems to work half decently (it needs some more obscure debugging that is not relevant here.)
I am starting with one dimension. I intend to generalize the algorithm to an arbitrary number of dimensions once I get it working consistently. I am writing my code in fortran, but feel free to reply with pseudocode or the language of your choice.
Allow me to elaborate with an example:
Say I am working on a closed interval [1,10]
xmin=1
xmax=10
Say I have 3 initial points: xmin, 5 and xmax
num_ivc=3
known(num_ivc)=[xmin,5,xmax] //my arrays start at 1. Assume "known" starts sorted
I store my mesh/grid points in an array called coord. Say I want 10 points total in my mesh/grid.
N=10
coord(10)
Remember, all this is arbitrary--except the variable names of course.
The algorithm should set coord to {1,2,3,4,5,6,7,8,9,10}
Now for a less trivial example:
num_ivc=3
known(num_ivc)=[xmin,5.5,xmax
or just
num_ivc=1
known(num_ivc)=[5.5]
Now, would you have 5 evenly spaced points on the interval [1, 5.5] and 5 evenly spaced points on the interval (5.5, 10]? But there is more space between 1 and 5.5 than between 5.5 and 10. So would you have 6 points on [1, 5.5] followed by 4 on (5.5 to 10]. The key is to minimize the difference in spacing.
I have been working on this for 2 days straight and I can assure you it is a lot trickier than it sounds. I have written code that
only works if N is large
only works if N is small
only works if it the known points are close together
only works if it the known points are far apart
only works if at least one of the known points is near a boundary
only works if none of the known points are near a boundary
So as you can see, I have coded the gamut of almost-solutions. I cannot figure out a way to get it to perform equally well in all possible scenarios (that is, create the optimum spacing.)
For my side project kwiqi, I use ActionMailer's 'receive' method to process incoming email messages for tracking my expenses. Heroku doesn't have a local mail server running that same code will not work. One solution I've thought of is to periodically hit a controller action that will pull messages from Gmail. Are there other solutions that are reasonable? Is anyone processing incoming emails in Heroku?
In my other question You can see code of my arr structure and PriorityQueue collection. I normally add items to this collection like that:
arr.PriorityQueue.Add(new element((value(item, endPoint) + value(startPoint, item)),item));
I am curious that is other way to do this (add element(which is struct) object to List) ? In lambda way for example ? I just eager for knowledge :)
Hi,
We were given an assignment to develop a prototype for a customer community. It was suggested PHP as the programming language. (but we're not supposed to actually code it, just a prototype with documentation is required)
I'm wondering what are the best practices/ tools used in Unit testing, Integration Testing and System testing for such a php app
Thanks
So I got this code
Javascript:
<script type="text/javascript">
$(function(){
$('.ajax') .click(function(e){
e.preventDefault()
$('#content').load( 'file.htm' )
})
})
</script>
html:
<a href="file.htm" class="ajax">Link</a>
it works perfectly in firefox, but nothing happens when I click the link in chrome and IE simply opens a new window with the file. any advice?
Hi,
I did a Mod rewrite for my website so the URLs looks like this :
http://www.mydomain.com/health/54856
http://www.mydomain.com/economy/strategy/911025/
http://www.mydomain.com/tags/obama/new
So, the problem is that i make AJAX calls to a file here : http://www.mydomain.com/login.php
And i don't want to write the FULL url or even use ../ trick because there isn't a fixed number of folders.
So, what i want now, is something worked for my code to access the login.php from the root whatever the domain name is :
$.ajax({
type: "POST",
url: "http://www.mydomain.com/login.php"
});
I managed to get this code to compile with out error. But somehow it did not return the strings that I wrote inside file1.txt and file.txt that I pass its path through str1 and str2. My objective is to use this open source library to measure the similarity between strings contains inside 2 text files.
Inside the its Javadoc, its states that ...
public static java.lang.StringBuffer fileToString(java.io.File f)
private call to load a file and return its content as a string.
Parameters:
f - a file for which to load its content
Returns:
a string containing the files contents or "" if empty or not present
Here's is my modified code trying to use the FileLoader function, but fails to return the strings inside the file. The end result keeps on returning me the "" . I do not know where is my fault:
package uk.ac.shef.wit.simmetrics;
import java.io.File;
import uk.ac.shef.wit.simmetrics.similaritymetrics.*;
import uk.ac.shef.wit.simmetrics.utils.*;
public class SimpleExample {
public static void main(final String[] args) {
if(args.length != 2) {
usage();
} else {
String str1 = "arg[0]";
String str2 = "arg[1]";
File objFile1 = new File(str1);
File objFile2 = new File(str2);
FileLoader obj1 = new FileLoader();
FileLoader obj2 = new FileLoader();
str1 = obj1.fileToString(objFile1).toString();
str2 = obj2.fileToString(objFile2).toString();
System.out.println(str1);
System.out.println(str2);
AbstractStringMetric metric = new MongeElkan();
//this single line performs the similarity test
float result = metric.getSimilarity(str1, str2);
//outputs the results
outputResult(result, metric, str1, str2);
}
}
private static void outputResult(final float result, final AbstractStringMetric metric, final String str1, final String str2) {
System.out.println("Using Metric " + metric.getShortDescriptionString() + " on strings \"" + str1 + "\" & \"" + str2 + "\" gives a similarity score of " + result);
}
private static void usage() {
System.out.println("Performs a rudimentary string metric comparison from the arguments given.\n\tArgs:\n\t\t1) String1 to compare\n\t\t2)String2 to compare\n\n\tReturns:\n\t\tA standard output (command line of the similarity metric with the given test strings, for more details of this simple class please see the SimpleExample.java source file)");
}
}
How do i check if a textarea contains nothing?
I tryed with this code
if(document.getElementById("field").value ==null)
{
alert("debug");
document.getElementById("field").style.display ="none";
}
But it doesnt do what i expect.
I expect that it should appear a messagebox "debug" and that the textarea is not shown.
How can i fix that issue?
A little background: as a way to learn multinode trees in C++, I decided to generate all possible TicTacToe boards and store them in a tree such that the branch beginning at a node are all boards that can follow from that node, and the children of a node are boards that follow in one move. After that, I thought it would be fun to write an AI to play TicTacToe using that tree as a decision tree.
TTT is a solvable problem where a perfect player will never lose, so it seemed an easy AI to code for my first time trying an AI.
Now when I first implemented the AI, I went back and added two fields to each node upon generation: the # of times X will win & the # of times O will win in all children below that node. I figured the best solution was to simply have my AI on each move choose and go down the subtree where it wins the most times. Then I discovered that while it plays perfect most of the time, I found ways where I could beat it. It wasn't a problem with my code, simply a problem with the way I had the AI choose it's path.
Then I decided to have it choose the tree with either the maximum wins for the computer or the maximum losses for the human, whichever was more. This made it perform BETTER, but still not perfect. I could still beat it.
So I have two ideas and I'm hoping for input on which is better:
1) Instead of maximizing the wins or losses, instead I could assign values of 1 for a win, 0 for a draw, and -1 for a loss. Then choosing the tree with the highest value will be the best move because that next node can't be a move that results in a loss. It's an easy change in the board generation, but it retains the same search space and memory usage. Or...
2) During board generation, if there is a board such that either X or O will win in their next move, only the child that prevents that win will be generated. No other child nodes will be considered, and then generation will proceed as normal after that. It shrinks the size of the tree, but then I have to implement an algorithm to determine if there is a one move win and I think that can only be done in linear time (making board generation a lot slower I think?)
Which is better, or is there an even better solution?
Hi guys,
I've got this code
mysqli_query ( $userdatabase,
'CREATE TABLE `user_'.$emailreg.'` (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
IP varchar(10),
FLD1 varchar(20),
FLD2 varchar(40),
FLD3 varchar(25),
FLD4 varchar(25),
FLD5 varchar(25) )' );
echo ( mysqli_error ($userdatabase) );
that works fine on my localhost, but when I upload it to the server, it starts giving me a "Incorrect table name '[email protected]'" error. any idea?
Thanks!
I'm trying to logout of facebook from my app using the following code below, but i'm still logged in (and my alert does not execute)
any ideas?
FB_RequireFeatures(
["Api"],
function(){
FB.Facebook.init(api_key, channel_path);
var api = FB.Facebook.apiClient;
FB.Connect.logout(function(){alert("logged out!");})
}
);
I want to throw the last three character from file name and get the rest?
I have this code:
char* remove(char* mystr) {
char tmp[] = {0};
unsigned int x;
for (x = 0; x < (strlen(mystr) - 3); x++)
tmp[x] = mystr[x];
return tmp;
}
Here's what I got:
# D. Given a list of numbers, return a list where
# all adjacent == elements have been reduced to a single element,
# so [1, 2, 2, 3] returns [1, 2, 3]. You may create a new list or
# modify the passed in list.
def remove_adjacent(nums):
for number in nums:
numberHolder = number
# +++your code here+++
return
I'm kind of stuck here. What can I do?
How do I write a std::codecvt facet? I'd like to write ones that go from UTF-16 to UTF-8, which go from UTF-16 to the systems current code page (windows, so CP_ACP), and to the system's OEM codepage (windows, so CP_OEM).
Cross-platform is preferred, but MSVC on Windows is fine too. Are there any kinds of tutorials or anything of that nature on how to correctly use this class?
I am trying to make a web service request call to a third part web site who's server is a little unreliable. Is there a way I can set a timeout on a request to this site? Something like this pseudo code:
try for 1 minute
{
// Make web request here
using (WebClient client new WebClient())...etc.
}
catch
{
}