Is there a way to set a default position for a UIPicker? I mean, if the user has the option of selecting any number from 1 to 100 in the UIPicker, can I set it to automatically start at 50?
When I compile scanf("%s", &var);, gcc sends back a warning:
warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[20]’
however when I compile scanf("%s", var);, no warning is applied. Both pieces of code work and the book I am reading specifically says to use the ampersand, but even it doesn't in some of the examples.
My question is, should I continue to use the ampersand, even when the book doesn't specify?
I am using three buttons along with the list view.These three buttons are added to the layout using the TableRow.The first button takes more space on content, so the other two becomes smaller in size than first one. When the application runs, it doesn't even show the two other buttons.
How can I make the size of three buttons equal and display all of them when application runs?
This might be a bit of a code smell, but I have seen it is some production code, namely the use of StringBuilder as opposed to XmlDocument when creating XML documents. In some cases these are write once operations (e.g. create the document and save it to disk) where as others are passing the built string to an XmlDocument to preform an XslTransform to a document that is returned to the client.
So obvious question: is there merit to doing things this way, is it something that should be done on a case-by-case basis, or is this the wrong way of doing things?
I am creating a custom Qt widget that mimics an A4 printed page and am having problems getting fonts to render at the correct size. My widget uses QPainter::setViewport and QPainter::setWindow to mimic the A4 page, using units of 10ths of a millimetre which enables me to draw easily. However, attempting to create a font at a specific point size doesn't seem to work and using QFont:setPixelSize isn't accurate. Here is some code:
View::View(QWidget *parent) :
QWidget(parent),
printer(new QPrinter)
{
printer->setPaperSize(QPrinter::A4);
printer->setFullPage(true);
}
void View::paintEvent(QPaintEvent*)
{
QPainter painter(this);
painter.setWindow(0, 0, 2100, 2970);
painter.setViewport(0, 0, printer->width(), printer->height());
// Draw a rect at x = 1cm, y = 1cm, 6cm wide and 1 inch high
painter.drawRect(100, 100, 600, 254);
// Create a 72pt (1 inch) high font
QFont font("Arial");
font.setPixelSize(254);
painter.setFont(font);
// Draw in the same box
// The font is too large
painter.drawText(QRect(100, 100, 600, 254), tr("Wg\u0102"));
// Ack - the actual font size reported by the metrics is 283 pixels!
const QFontMetrics fontMetrics = painter.fontMetrics();
qDebug() << "Font height = " << fontMetrics.height();
}
So I'm asking for a 254 high font (1 inch, 72 pts) and it's too big and sure enough when I query for the font height via QFontMetrics it is 283 high.
Does anyone else know how to use font sizes in points when using custom mapping modes like this? It must be possible. Note that I cannot see how to convert between logical/device points either (i.e. the Win32 DPtoLP/LPtoDP equivalents.)
I'm just starting a new project and I am getting some really weird stuff happening.
ASP.NET 3.5, VS2008.
I've tried rebuild, close VS, delete everything and get from svn again but I cannot understand why the repeater in the following is null on page_load.
I know this is going to be a headslapping moment. Help me out?
Markup:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GalleryControl.ascx.cs" Inherits="Site.UserControls.GalleryControl" %>
<asp:Repeater ID="rptGalleries" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<ItemTemplate>
<li>wqe</li>
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
Code behind
public partial class GalleryControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
rptGalleries.DataSource = new[] {1, 2, 3, 4, 5};
rptGalleries.DataBind();
}
}
Why is my repeater null? What the F is going on?
I've been given data from a previous version of a website (it was a custom CMS) and am looking to get it into a state that I can import it into my Wordpress site.
This is what I'm working on - http://www.teamworksdesign.com/clients/ciw/datatest/index.php. If you scroll down to row 187 the data starts to fail (there should be a red message) with the following error message:
Fatal error: Uncaught exception 'Exception' with message 'String could
not be parsed as XML' in
/home/teamwork/public_html/clients/ciw/datatest/index.php:132 Stack
trace: #0
/home/teamwork/public_html/clients/ciw/datatest/index.php(132):
SimpleXMLElement-__construct('
Can anyone see what the problem is and how to fix it?
This is how I'm outputting the date:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php
ini_set('memory_limit','1024M');
ini_set('max_execution_time', 500); //300 seconds = 5 minutes
echo "<br />memory_limit: " . ini_get('memory_limit') . "<br /><br />";
echo "<br />max_execution_time: " . ini_get('max_execution_time') . "<br /><br />";
libxml_use_internal_errors(true);
$z = new XMLReader;
$z->open('dbo_Content.xml');
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
// move to the first <product /> node
while ($z->read() && $z->name !== 'dbo_Content');
$c = 0;
// now that we're at the right depth, hop to the next <product/> until the end of the tree
while ($z->name === 'dbo_Content')
{
if($c < 201) {
// either one should work
$node = simplexml_import_dom($doc->importNode($z->expand(), true));
if($node->ClassId == 'policydocument') {
$c++;
echo "<h1>Row: $c</h1>";
echo "<pre>";
echo htmlentities($node->XML) . "<br /><br /><br /><b>*******</b><br /><br /><br />";
echo "</pre>";
try{
$xmlObject = new SimpleXMLElement($node->XML);
foreach ($xmlObject->fields[0]->field as $field) {
switch((string) $field['name']) {
case 'parentId':
echo "<b>PARENT ID: </b> " . $field->value . "<br />";
break;
case 'title':
echo "<b>TITLE: </b> " . $field->value . "<br />";
break;
case 'summary':
echo "<b>SUMMARY: </b> " . $field->value . "<br />";
break;
case 'body':
echo "<b>BODY:</b> " . $field->value . "<br />";
break;
case 'published':
echo "<b>PUBLISHED:</b> " . $field->value . "<br />";
break;
}
}
echo '<br /><h2 style="color:green;">Success on node: '.$node->ContentId.'</h2><hr /><br />';
} catch (Exception $e){
echo '<h2 style="color:red;">Failed on node: '.$node->ContentId.'</h2>';
}
}
// go to next <product />
$z->next('dbo_Content');
}
} ?>
</body>
</html>
C# socket server, which has roughly 200 - 500 active connections, each one constantly sending messages to our server.
About 70% of the time the messages are handled fine (in the correct order etc), however in the other 30% of cases we have jumbled up messages and things get screwed up. We should note that some clients send data in unicode and others in ASCII, so that's handled as well.
Messages sent to the server are a variable length string which end in a char3, it's the char3 that we break on, other than that we keep receiving data.
Could anyone shed any light on our ProcessReceive code and see what could possibly be causing us issues and how we can solve this small issue (here's hoping it's a small issue!)
Code below:
I've installed ruby-1.8.6-p383 with RVM. System ruby is 1.9.1_p378-1
I'm getting the wrong date from Date.today and DateTime.now when using ruby 1.8.. Whereas Time.now is correct:
irb(main):002:0> DateTime.now.to_s
=> "2126--1-10618T11:23:43+00:00"
irb(main):004:0> Date.today.to_s
=> "2126--1-10618"
irb(main):005:0> Time.now
=> Thu Jan 28 11:55:27 +0000 2010
All is well if I switch to ruby 1.9:
irb(main):003:0> DateTime.now.to_s
=> "2010-01-28T11:58:51+00:00"
irb(main):004:0> Date.today.to_s
=> "2010-01-28"
irb(main):005:0> Time.now
=> 2010-01-28 11:59:05 +0000
Any advice on how to get DateTime to work properly in ruby 1.8 would be most appreciated!
I have a ListView element with a DataTemplate for each ListViewItem defined as follows. When run, the ListView's height is not collapsed onto the items in the view, which is undesirable behavior:
<DataTemplate x:Key="LicenseItemTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding company}"></TextBlock>
<Grid Grid.Row="1" Style="{StaticResource HiddenWhenNotSelectedStyle}">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Button Grid.Row="0">ClickIt</Button>
</Grid>
</Grid>
</DataTemplate>
The second row of the outer grid has a style applied which looks like this. The purpose of the style is to :
<Style TargetType="{x:Type Grid}" x:Key="HiddenWhenNotSelectedStyle" >
<Style.Triggers>
<DataTrigger
Binding="{Binding Path=IsSelected,
RelativeSource={
RelativeSource
Mode=FindAncestor,
AncestorType={x:Type ListViewItem}
}
}"
Value="False">
<Setter Property="Grid.Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger
Binding="{Binding Path=IsSelected,
RelativeSource={
RelativeSource
Mode=FindAncestor,
AncestorType={x:Type ListViewItem}
}
}"
Value="True">
<Setter
Property="Grid.Visibility"
Value="Visible"
/>
</DataTrigger>
</Style.Triggers>
</Style>
The ListView renders like this:
The desired appearance is this, when none of the elements are selected:
...with, of course, the ListView's height adjusting to accommodate the additional content when the second grid is made visible by selection. What can I do to get the desired behavior?
I'm using selenium_client with cucumber, webrat + IE
As you'd expect, Firefox works fine. I've tried the following:
selenium.is_visible("css=#flash .flash_notice")
selenium.is_visible("xpath=//*[@id='flash']/*[@class='flash_notice]")
selenium.is_visible("xpath=//*[@id='flash']/*[contains(@class,'flash_notice]')")
both cannot find the element.
I think it must be something to do with IE, looking closer at the html selenium returns from IE...
It looks like this:
<UL id=flash>
<LI className=flash_notice>Deleted</LI>
</UL>
Notice IE returns the class attribute as className, is this confusing selenium? How can I get round this so that I can use the same statement for selenium using IE and Firefox
Just to confuse us even more, this example works, confirming its something to do with checking the class attribute
selenium.is_visible("xpath=//*[@id='flash']/*[. =\'Deleted\']")
I would like to request opinions about my career/situation at work with a software development project.
I would like to ask anonymously or created a new stackoverflow.com account because I think I may be identified by co-workers at my employer since I have referred them to (non-sensititive) technical questions I have asked here. So they might know my account and be able to follow my activity.
If I create a new account it will have no reputation and some readers may ignore it, for example, because they might think that the user only wishes to take ideas from here and not contribute, i.e. not a committed stackoverflow poster.
What are your thoughts?
(I do feel that it is appropriate to ask such pogramming career/situational questions here as many others have and there are some good questions -and answers and it seems that the stackoverflow community accepts such questions even thought the site's strict guidelines are for specific answers and not discussion, and non-subjective questions. And thank goodness that is the case - not all problems faced by programmers are about the craft but also the human factors around it - where else would folks go?)
I'm trying to bind to a WinForms control's DataSource property in my WPF application but I'm not having much luck...
Falafel.com gives it a shot, but although it claimes that a DependencyObject is not required to perform the binding, that seems to be the only way of doing it.
Has anyone done this before?
<?php
include_once('booter/login/includes/db.php');
$query="SELECT * FROM shells";
$result=mysql_query($query);
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
$hash = @md5_file($row['url']);
echo $hash . "<br>";
}
?>
The above is my code. Usually it works flawlessly on most urls, but every now and then it will just skip the md5 on a line, as if it doesn't retrieve it, even though the file is there.
I can't figure out why. Any ideas?
Hi,
This function is called when an up/down arrow is clicked to slide hidden div. If the div is hidden, the arrow points down and changes to up when the div is shown. If the div is shown, the arrow points up to hide div and changes to down when the div is closed. I just wanted to know if there was a more efficient way of doing this or if this is the correct way. Thanks.
function showInfo(info_id) {
var img_id = '#arrow_'+info_id;
var div = '#info_'+appointment_id;
$(div).slideToggle('normal',function() {
if ($(this).is(':visible')) {
$(img_id).attr('src',$(img_id).attr('src').replace('_down','_up'));
}
else {
$(img_id).attr('src',$(img_id).attr('src').replace('_up','_down'));
}
});}
The MSDN documentation on WebBrowser Customization explains how to prevent new windows from being opened and how to cancel navigation. In my case, my application is hosting an IWebBrowser2 but I don't want the user to navigate to new pages within my app. Instead, I'd like to open all links in a new IE window. The desired behavior is: user clicks a link, and a new window opens with that URL.
A similar question was asked and answered here and rather than pollute that answered post, it was suggested I open a new discussion.
The members on the related post suggested I should be able to do this by trapping DISPID_BEFORENAVIGATE2, setting the cancel flag, and writing code to open a new window, but I've found out that the browser control gets lots of BeforeNavigate2 events that seem to be initiated by scripts on the main page. For example, amazon.com fires BeforeNavigate2 events like crazy, and they are not a result of link invocation.
Replies appreciated!
I want to show the user a flattened pick list of all their contacts phone numbers and it must work from versions 1.6 up. I have read the related questions on SO and the Android documentation for Eclair (http://developer.android.com/resources/articles/contacts.html#legacy).
The problem is, even splitting my code into a factory class and specific implementations does not work for me because using Contacts.CONTENT_URI only shows contacts not individual numbers. What I need is this for version 1.6
Intent intent = new Intent(Intent.ACTION_PICK, Phones.CONTENT_URI);
startActivityForResult(intent, REQUEST_PICK_CONTACT);
And the equivalent for 2.0 and above.
Even if I get their example to work, by building against the 2.1 API am I not stopping my app being visible on the Market to users with earlier versions of the OS? I can't launch it against a 1.6 emulator, for example.
Currently I'm using file_get_contents() to submit GET data to an array of sites, but upon execution of the page I get this error:
Fatal error: Maximum execution time of 30 seconds exceeded
All I really want the script to do is start loading the webpage, and then leave. Each webpage may take up to 5 minutes to load fully, and I don't need it to load fully.
Here is what I currently have:
foreach($sites as $s) //Create one line to read from a wide array
{
file_get_contents($s['url']); // Send to the shells
}
After doing some reading about the Module Pattern, I've seen a few ways of returning the properties which you want to be public.
One of the most common ways is to declare your public properties and methods right inside of the "return" statement, apart from your private properties and methods. A similar way (the "Revealing" pattern) is to provide simply references to the properties and methods which you want to be public. Lastly, a third technique I saw was to create a new object inside your module function, to which you assign your new properties before returning said object. This was an interesting idea, but requires the creation of a new object.
So I was thinking, why not just use "this.propertyName" to assign your public properties and methods, and finally use "return this" at the end? This way seems much simpler to me, as you can create private properties and methods with the usual "var" or "function" syntax, or use the "this.propertyName" syntax to declare your public methods.
Here's the method I'm suggesting:
(function() {
var privateMethod = function () {
alert('This is a private method.');
}
this.publicMethod = function () {
alert('This is a public method.');
}
return this;
})();
Are there any pros/cons to using the method above? What about the others?
Hello all,
I have a UIPickerView implemented in one of my pages that depends on the didSelectRow delegate method.
An odd behavior I have noticed is when the user moves a wheel and leaves it between selections, then the wheel will move very slowly to the closest selection. The didSelectRow event will not fire until this is complete, sometimes 3 seconds later.
Is there a way to speed this up, or detect when the wheel is being moved, so I can freeze my interface during this time?
Is there a reason that a C# System.Decimal remembers the number of trailing zeros it was entered with?
See the following example:
public void DoSomething()
{
decimal dec1 = 0.5M;
decimal dec2 = 0.50M;
Console.WriteLine(dec1); //Output: 0.5
Console.WriteLine(dec2); //Output: 0.50
Console.WriteLine(dec1 == dec2); //Output: True
}
The decimals are classed as equal, yet dec2 remembers that it was entered with an additional zero. What is the reason/purpose for this?
I am working on a project (that i will not be releasing to the app store - just for fun) that will upload an image via an HTTP Post request from my iPhone to a server that I have running the Python script SimpleHTTPServer. I have successfully used the ASIHTTP APIs in the past for text strings, but can't for the life of me figure out how to upload an image. I have tried all of the following:
NSString *path = [[NSBundle mainBundle] pathForResource:@"Image" ofType:@".png"];
[request setFile:@"Image.png" forKey:@"file"];
[request setFile:path forKey:@"file"];
[request setFile:path withFileName:@"Image.png" andContentType:@"image/jpeg"
forKey:@"file"];
[request setData:[UIImage imageNamed:@"Image.png"] withFileName:@"Image.png" andContentType:@"Image" forKey:@"file"];
Any thoughts on where i could be going wrong?
I have a string in my db I want to pull into my page and convert to a json object.
[
{id: 1,title: "Long Event",
start: new Date(2009, 5, 6, 14, 0),end: new Date(2009, 5, 11)},
{id: 2,title: "Repeating Event",
start: new Date(2009, 5, 2)},
{id: 3,title: "Meeting",
start: new Date(2009, 5, 20, 9, 0)},
{id: 4,title: "Click for Facebook",
start: new Date(2009, 5, 27, 16),end: new Date(2009, 5, 29),
url: "http://facebook.com/"}
]
How can I do this using JQuery?