Why does the C# compiler not even complain with a warning on this code? :
if (this == null)
{
// ...
}
Obviously the condition will never be satisfied..
I've been looking for a way to convert an mp3 to aac programmatically or via the command line with no luck. Ideally, I'd have a snippet of code that I could call from my rails app that converts an mp3 to an aac. I installed ffmpeg and libfaac and was able to create an aac file with the following command:
ffmpeg -i test.mp3 -acodec libfaac -ab 163840 dest.aac
When i change the output file's name to dest.m4a, it doesn't play in iTunes.
Thanks!
MS solution for source code control is visual source safe before. Now MS advocate its TFS. What the difference between MS Source Safe and Team Foundation Server from functional perspective? And what's the difference between TFS and open source for source control, like subversion?
Hello,
I am having trouble capturing Ctrl+PageUp keystroke in a ListView control in WinForms application.
I am using this code to capture keystrokes -
private void ListViewEx_KeyDown(object sender, KeyEventArgs e)
{
...
if(e.Control){
if((e.KeyCode ^ Keys.Left) == 0)
MessageBox.Show("Left"); //shows messagebox
else if((e.KeyCode ^ Keys.PageUp) == 0)
MessageBox.Show("PageUp"); //does not
...
}
Do I need to dive into WndProc to process this key? Thanks.
I'm tired of thinking how the hell my coodinates are working at each case.
I heard that I could flip the Y-axis by this code:
glScalef(1, -1, 1);
But should I? Doesnt this break some other external functions and lighting etc?
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);
}
}
Consider this Python code for printing a list of comma separated values
for element in list:
print element + ",",
What is the preferred method for printing such that a comma does not appear if element is the final element in the list.
ex
a = [1, 2, 3]
for element in a
print str(element) +",",
output
1,2,3,
desired
1,2,3
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?
I have a bunch of data in a database and I want to generate some tables in PowerPoint. I had started doing this manually but I thought there might be a way I can simply write some code to take my data from the database and output it onto a PowerPoint slide.
Any advice here?
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.
Hi
I am trying to convert an entry using a numeric stepper in flex into words to display in a textarea.
i.e a user uses the stepper to enter "89" as a value and in the text area the words "Eighty nine" are displayed.
After much searching i haven't found anything that helps - a few javascript functions but that is all.
any help sample code would be much appreciated.
thanks in advance.
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...
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
I am loading content into a page with ajax that will have live click events attached to them. It seems like the first time I load this content everything works as expected. If I load this again, the events fire twice (when put breakpoints in the code). What am I doing wrong? Is there a way I can clear the dom of these elements before they get loaded again?
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.)
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.
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!");})
}
);
Here's the code I'm running:
import re
FIND_TERM = r'C:\\Program Files\\Microsoft SQL Server\\90\\DTS\\Binn\\DTExec\.exe'
rfind_term = re.compile(FIND_TERM,re.I)
REPLACE_TERM = 'C:\\Program Files\\Microsoft SQL Server\\100\\DTS\\Binn\\DTExec.exe'
test = r'something C:\Program Files\Microsoft SQL Server\90\DTS\Binn\DTExec.exe something'
print rfind_term.sub(REPLACE_TERM,test)
And the result I get is:
something C:\Program Files\Microsoft SQL Server@\DTS\Binn\DTExec.exe something
Why is there an @ sign?
Hello everybody,
I just came across a problem, here's my code -
function unFilterPostData() {
$content = get_the_content();
return $content . 'Contact author on Twitter - @alilpirate';
}
add_filter('the_content','unFilterPostData');
I have also tried using
function unFilterPostData($content) {
return $content . 'Contact author on Twitter - @alilpirate';
}
add_filter('the_content','unFilterPostData');
But nothing works. Help!
Hi,
I would select multiple DOM elements using a typical code such as this:
$('#ele1, #ele2, #ele3').click(function () {});
If I have variables of each DOM element, e.g.
var domEle1 = $('#ele1');
var domEle2 = $('#ele2');
var domEle3 = $('#ele3');
How can I select them all at once? Instead of individually...
domEle1.click(function () {});
Thanks!