Tuesday, May 22, 2012

Why doesn't VC++ 2010 Express require stdio.h in this program but gcc++ does?

I have the following code



#include <iostream>

using namespace std;

void WaitForEnter()
{
while(1)
{
if('\n' == getchar())
{
break;
}
}
}

int main()
{
cout<< "Press Enter to Exit... ";
WaitForEnter();
}


This compiles on Microsoft Visual C++ 2010 Express and does what I expected. On Ubuntu using code::blocks and gcc++ 4.7 the build fails with the following error: 'getchar' was not declared in this scope. If I add the line #include "stdio.h", the program compiles and runs with the expected behavior. Why does this program compile using MVC++ 2010 Express without stdio.h but not for code::blocks with gcc++ 4.7 on Ubuntu.





How can a web shared local html file be opened via Safari?

From system preferences/Internet & Wireless/Sharing I selected Web Sharing then clicked on Open Personal Website Folder, and there is an existing index.html file there with address



http://my ip address/~myusername/sites/index.html if online or if offline then
http://MacBook-Pro/~myusername/sites/index.html


But if I try to open these URLs from Safari it doesn't work, perhaps as expected if using the http scheme, so I tried with file:// instead but it says



"No file exists at "/~myusername/sites/index.html". But the file does exist there, I can see it.



Are there some tricks involved in getting Safari to see this file?





GetElementsByTagName alternative to DOMDocument

I am creating an HTML file with DOMDocument, but I have a problem at the time of the search by the getElementsByTagName method. What I found is that as I'm generating the hot, does not recognize the labels that I inserted.



I tried with DOMXPath, but to no avail :S



For now, I've got to do is go through all the children of a node and store in an array, but I need to convert that score DOMNodeList, and in doing



return (DOMNodeList) $ my_array;


generates a syntax error.



My specific question is, how I can do to make a search for tags with the getElementsByTagName method or other alternative I can offer to achieve the task?



Recalling that the DOMDocument I'm generating at the time.



If you need more information, I'll gladly place it in the question.



Sure Jonathan Sampson.



I apologize for the editing of the question the way. I did not quite understand this forum format.



For a better understanding of what I do, I put the inheritance chain.



I have this base class



abstract class ElementoBase {
...
}


And I have this class that inherits from the previous one, with an abstract function insert (insert)



abstract class Elemento extends ElementoBase {
...
public abstract function insertar ( $elemento );
}


Then I have a whole series of classes that represent the HTML tags that inherit from above, ie.



class A extends Elemento {
}
...


Now the code I use to insert the labels in the paper is as follows:



public function insertar ( $elemento ) {

$this->getElemento ()->appendChild ( $elemento->getElemento () );
}


where the function getElemento (), return a DOMElement



Moreover, before inserting the element do some validations that depend on the HTML tag that is to be inserted,
because they all have very specific specifications.



Since I'm generating HTML code at the same time, it is obvious that there is no HTML file.



To your question, the theory tells me to do this:



$myListTags = $this->getElemento ()->getElementsByTagName ( $tag );


but I always returns null, this so I researched it because I'm not loading the HTML file, because if I



$myHtmlFile = $this->getDocumento ()->loadHTMLFile ( $filename );
$myListTags = $myHtmlFile->getElementsByTagName ( $etiqueta );


I do return the list of HTML tags



If you need more information, I'll gladly place it in the question.





Understandable explanation to a simple file writer?

I have been looking around the internet for a long time and i STILL havent found a sensible answer as to making a program that creates a file in a directory (Such as C:). So if you could please explain to me how i would do this it would be greatly appreciated! Thanks!
EDIT-Im using java and i want to write a text document. Probably should have said that before :/





TestFlight build, network calls don't work

This is driving me batty. I've used TestFlight on a few occasions with great success, but this time around I'm having issues.



The archive works, uploads to TestFlight just fine, installs to the target device just fine, but my network calls NEVER execute. E.G. You never see any network activity from the device and watching the backend the calls never arrive.



Debug builds on the same device work as expected.





Java Script code not running well on ie9

I have this code it suppose to display an ad for 10 seconds then load a embed code.
the thing is that it's working fine on firefox but not ie 9 it's run the ad and the embed code in the same time in the background.
Is there is anyway to resolve this problem.
the code is attached.
thank you



<script type="text/javascript">
var nbsec=10;
var c=0;
var t;
var timer_is_on=0;
var sum=0;
function timedCount()
{
c=c+1;
t=setTimeout("timedCount()",1000);
sum=nbsec-c;
document.getElementById('chrono').innerHTML="<br>Loading .. Please wait "+sum+"secondes";
if(c == nbsec){
stopCount();
document.getElementById('mypub').style.visibility = 'hidden';
document.getElementById('mygame').style.visibility = 'visible';
document.getElementById('mygame').style.display ='block';
document.getElementById('mygame').style.height = 'auto';
document.getElementById('mypub').style.height = '0px';
document.getElementById('mypub').style.padding = '0px';
document.getElementById('mypub').innerHTML="";
}
}
function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}
</script>

<table border ="2" align="center" color="F2FC7E"><tr><td>
<div id="mypub" style="visibility: visible; text-align:center; padding:20px;">

<script>
..............
</script>

<div id="chrono" style="color:#FFF;"></div>
</div>
<div id="mygame" style="visibility: hidden;display:none; height:0px">
<param name="initial_focus" value="true">
<applet>
........................
</applet>
</div>
</td></tr></table>
</div>
<script type="text/javascript">
timedCount();
</script>




accessing vars inside a js function

So I have a psudo "Class" with functions and vars inside of it
for this question I'll just use an example:



function MyClass()
{
this.a = 0;
this.b = function(c)
{
this.a += c;
}
}


then when I go to use it later i'll do this:



var myObject = new MyClass();
myObject.b(3);
myObject.b(5);


but when I do this:



console.log("A: " + myObject.a);


I get:



A: 0


What am I doing wrong?





How to make CSS compatible with all browsers?

Basically what I mean is which CSS fields need "-moz-" and "-webkit" in front of them for them to work? I know "border-radius" and "box-shadow" do, but can anyone tell me all of them? Thanks a lot in advanced.





How to reuse JSON Object

Scenario:



The MVC web page gets JSON object with lots of data. Upon click of button (there are quiet a number of buttons) I would like to reuse this JSON object and select required JSON Properties (without making a request to server).



It's not HTML5 so can't use browser local storage. At the moment I'm storing the JSON object on GLOBAL variable and reusing it.



Are there any elegant options available to store and re-use returned JSON object on client side?





NSCache getting released randomly

so I had a category of NSCache:



@interface NSCache (SharedCache)
+(NSCache*)sharedCache;
@end

#import "NSCache+SharedCache.h"

@implementation NSCache (SharedCache)
+(NSCache*)sharedCache;
{
static NSCache* sharedCache = nil;
if (sharedCache == nil) {
sharedCache = [[self alloc] init];
[sharedCache setCountLimit:0];
}
return sharedCache;
}

@end


However ocasionnaly this gets deallocated and therefore my app crashes. If I retain sharedCache this problem is solved. What is the best way to have a shared NSCache to void crashes that it gets deallocated randomly?





Possible to initialize static variable by calling function

Is this possible?



static bool initialize()
{
TRC_SCOPE_INIT(...);
...
}

static bool initialized = initialize();


To make a very long story short, I need to call a series of macros (to initialize debugging messages) as early as possible (before thread X is started, and I don't have the ability to know when thread X is started).





Parsing html with Jsoup and removing spans with certain style

I'm writing an app for a friend but I ran into a problem, the website has these



<span style="display:none">&amp;0000000000000217000000</span>


And we have no idea even what they are, but I need them removed because my app is outputting their value.



Is there any way I can check to see if this is in the Elements and remove it? I have a for-each loop parsing however I cant figure out how to effectively remove this element.



thanks





Default value for height and width of components in UIPickerView

What is the default value of the height and width of the components in UIPickerView? ie., what is the value that iOS uses as height and width for the below, if the application has not implemented these methods?



pickerView:widthForComponent:
pickerView:rowHeightForComponent:


I tried the suggestion from the thread :
What is the default width of a UIPickerView component?
But that would give an array out of bound exception:



Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'


Any help appreciated.





Make persistent changes to init.rc

I want to change the init.rc file of an android pad. But after I change it and reboot the system, the original init.rc comes back.



How can I make the change to the init.rc persistently without rebuild the system (since I don't have the source code of the system)? Or is there any way to work around?





Difficulty parsing a double - String

Thanks for taking the time to answer my question.



I have a double value (let's say 22.35). I need to parse it into a String and get 2235. The following code is not working properly.



double totalPrice = 22.35;
DecimalFormat df = new DecimalFormat("#.##");
String[] temp = df.format(totalPrice).split(".");
String amount = temp[0] + temp[1];


I keep getting an exception ArrayIndexOutOfBounds. What is another way to do this? Thanks in advance!





Viewing database records realtime in WPF application

disclaimer: I must use a microsoft access database and I cannot connect my app to a server to subscribe to any service.



I am using VB.net to create a WPF application. I am populating a listview based on records from an access database which I query one time when the application loads and I fill a dataset. I then use LINQ to dataset to display data to the user depending on filters and whatnot.



However.. the access table is modified many times throughout the day which means the user will have "old data" as the day progresses if they do not reload the application. Is there a way to connect the access database to the VB.net application such that it can raise an event when a record is added, removed, or modified in the database? I am fine with any code required IN the event handler.. I just need to figure out a way to trigger a vb.net application event from the access table.



Think of what I am trying to do as viewing real-time edits to a database table, but within the application.. any help is MUCH appreciated and let me know if you require any clarification - I just need a general direction and I am happy to research more.



My solution idea:




  • Create audit table for ms access change

  • Create separate worker thread within the users application to query
    the audit table for changes every 60 seconds

  • if changes are found it will modify the affected dataset records

  • Raise event on dataset record update to refresh any affected
    objects/properties





GetAsyncKeyState() very CPU heavy? Am I using it correctly?

I am using GetAsyncKeyState() in a simple pong game of mine to check if the user has pressed the arrow keys. I read online that you need to use this function a certain way however I found out that it is very CPU heavy (using 50% of my CPU!). This was rather disconcerting, however, after some playing around I found out that if I added a sleep(1); then the CPU usage went down to 0% and everything still worked fine. There must be a better way of using this function or at least a better way of lowering CPU usage.



Any help here would be much appreciated!



My Code:



while(true)
{
for(i = 8; i < 191; ++i)
{
if(GetAsyncKeyState(i) == -32767)
{
if(i == VK_LEFT)
// do stuff
else if(i == VK_RIGHT)
// do stuff
else if(i == VK_UP)
// do stuff
else if(i == VK_DOWN)
// do stuff
}
}
Sleep(1);
}




jquery + hotkeys - supress open file dialog

i just discovered the jquery hotkeys plugin for adding global hotkeys.
i would like to use the ctrl-o hotkey for own purposes, unfortunately firefox keeps displaying the open file dialog. i've tried return false and stopPropagation within my bind function but unfortunately didn't help.
any ideas how to supress the browser's open file dialog?
thanks





Two Foreign Keys in one Column. How to split?

I have the following situation.



Combinations Table:

Combination ID | Option ID's


Options Table:

Option ID | Option Name | Option Value



The "Option ID's" column in the combinations table reads like "2345,3421" (in the one column) when refering to the two options associated to the combination.



Is it possible to generate a list that lists all possible combinations and values for each combination?



ie. combination1 | option1 | name:size | value:Small | option2 | name:color | value:Blue





Add mailto link to static email with JQuery

I'm trying to add a mailto link to static email addresses found within a list of results from a database, using JQuery. I was able to find the following excerpt online which works for the first result, but it does not work for any email addresses after the first one.



I'm curious why this is.. and how I can get it to apply the mailto: attribute to every email address found in the results. :-)



Current code:



<script type="text/javascript">
$(document).ready(function(){
var regEx = /(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)/;
$("table td").filter(function() {
return $(this).html().match(regEx);
}).each(function() {
$(this).html($(this).html().replace(regEx, "<a href=\"mailto:$1\">$1</a>"));
});
});




Thanks!





HTML5 and a Decibel meter

Is there anyway using HTML5 and Javascript to capture audio and get the live Decibel value of it? Can this be done on mobile devices using PhoneGap?





Debugging Rails with Passanger and Apache

Some of the threads I was following seem old, so maybe what I am trying to do has been superseded by something else--if that is the case, please let me know!



I just reinstalled a Rails app on a new server, but this time am using Apache and Passenger. Rails version 1.8.7, Apache2, and Passenger on a Ubuntu 12.04 server. I would like to still have a debugger, so I tried following this thread:



http://chrisadams.me.uk/2009/04/28/how-to-set-up-a-debugger-with-mod_railspassenger/
http://duckpunching.com/passenger-mod_rails-for-development-now-with-debugger
(the original article)



I'm pretty sure I followed this exactly, and my files are correct. But I am getting two discrepencies. First, when I refresh my webpage, my site does not hang (as stated on the duckpunching page)...second, when I put in:



rdebug -c


I get the following error:



/usr/lib/ruby/gems/1.8/gems/ruby-debug-0.10.4/cli/ruby-debug.rb:109:in initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
from /usr/lib/ruby/gems/1.8/gems/ruby-debug-0.10.4/cli/ruby-debug.rb:109:in
new'
from /usr/lib/ruby/gems/1.8/gems/ruby-debug-0.10.4/cli/ruby-debug.rb:109:in start_client'
from /usr/lib/ruby/gems/1.8/gems/ruby-debug-0.10.4/bin/rdebug:336
from /usr/bin/rdebug:23:in
load'
from /usr/bin/rdebug:23



So I feel like my terminal is not automatically connecting somehow? As I stated, I can't really find updated information online about this problem, so any help is appreciated in either making this work (console-type debugging for Apache / Passenger, like what I had with WEBrick) or current best-practices. Thanks!





Free XML formatter (indent) tool on Mac?

Need a tool that can format the xml in human readable format on Mac!





Debug a Java project which is invoked through a perl script

I am working on a big Java project which is on eclipse. To use the program we need to invoke a perl script in the terminal with the parameters then that script will call the program. In this case how can I debug the program in eclipse?



Thank you,
Regards,
Robo





Reading SMS from inbox in j2me

I am using j2me technology. My application is for sending and receiving sms. Sender can not send sms on specific port and sms always goes to inbox. Is it possible to read sms from inbox in j2me?





jquery shows wrong page

This is the jquery



$(document).on('change', '.ui-slider-switch', function () {

if ($(this).val() == 'on') {
$("#content1").hide();
$("#content2").show();

} else {
$("#content1").show();
$("#content2").hide();
}

});


My HTML



<div id="switch" data-role="fieldcontain">      
<select name="slider" id="flip-a" data-role="slider">
<option value="off"></option>
<option value="on"></option>
</select>
</div>


In my site I sometimes use a custom URL (And get data out of it with $ _GET).
When the page reload I'm always getting $("#content2").show(); instead of $("#content1").show();





Upload external file to AWS S3 bucket using PHP SDK

I want to upload a file from an external URL directly to an Amazon S3 bucket using the PHP SDK. I managed to do this with the following code:



$s3 = new AmazonS3();
$response = $s3->create_object($bucket, $destination, array(
'fileUpload' => $source,
'length' => remote_filesize($source),
'contentType' => 'image/jpeg'
));


Where the function remote_filesize is the following:



function remote_filesize($url) {
ob_start();
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
$ok = curl_exec($ch);
curl_close($ch);
$head = ob_get_contents();
ob_end_clean();
$regex = '/Content-Length:\s([0-9].+?)\s/';
$count = preg_match($regex, $head, $matches);
return isset($matches[1]) ? $matches[1] : "unknown";
}


However, it would be nice if I could skip setting the filesize when uploading to Amazon since this would save me a trip to my own server. But if I remove setting the 'length' property in the $s3->create_object function, I get an error saying that the 'The stream size for the streaming upload cannot be determined.' Any ideas how to solve this problem?





Grab euro dollar conversion rate in Java

I have an application that has to convert dollar to euro and vice versa. Is there an interface or API I can use to grab the current conversion rate?