Wednesday, May 2, 2012

set explicit source update while using data context

I need to update the binding source object with the control values only during a button click event.



But as my top level has datacontext being set, it's updating the source object whenever the control values change... Is it possible to set explicitly to update it during that event only keeping the datacontext as it is?





Share session (cookies) between subdomains in Rails?

I have an app setup where each user belongs to a company, and that company has a subdomain (I am using basecamp style subdomains). The problem that I am facing is that rails is creating multiple cookies (one for lvh.me and another for subdomain.lvh.me) which is causing quite a few breaks in my application(such as flash messages being persistent though out all requests once signed in).



I have this in my /cofig/initilizers/session_store.rb file:



AppName::Application.config.session_store :cookie_store, key: '_application_devise_session', domain: :all


The domain: :all seems to be the standard answer I found on Google, but that doesn't seem to be working for me. Any help is appreciated!





Nested Async Javascript

I am using the technique specified http://friendlybit.com/js/lazy-loading-asyncronous-javascript/ to load external javascript when the window.onload() is triggered. But if the script itself contains some registration of load event handler then they might not get called as the event has been (somehow) passed. In order to confirm, I added the following code to the external javascript file that is loaded as mentioned above:





(function() {
if (window.attachEvent)
window.attachEvent('onload', alert("ok"));
else
window.addEventListener('load', alert("ok"), false);
})();



This alert actually appears which make me think, whether the onload is called twice or does loading javascript means loading the script, running its "global" part and then moving on to the next listener. In the latter case, if another listener is added to onload event while running its "global" part then this behavior is correct. But I am not sure of this and would appreciate if someone more experienced could clarify/confirm it.





Symfony2 Forms - Cannot add/remove entities from a collection

I have a form for a "Person" entity that has a collection of "Nicknames".



I have implemented this following the guide in the cookbook (http://symfony.com/doc/current/cookbook/form/form_collections.html)



When I create a new "Person" I can add "Nicknames" as expected successfully.



Using a similar form I have an edit page. On the edit page I have set up the front end in the same way as the new page.



On the edit page, I can edit the existing nicknames and the other simple fields successfully. However, when I submit a new "Nickname" (or try to remove one), it does not work.



I have var_dump()'ed the request object before it is binded to the "Person" and I have var_dump()ed the "Person" object after binding. The request does have the "Nicknames" collection passed correctly. However, they are not being binded to the Person at all, despite the fact that everything is the same as the new page. Further, I can still edit the existing Nicknames so it is working on that front.



I cannot for the life of me figure out why Symfony isn't creating these new Nicknames or adding them to the Person as it should. I have looked around and searched but everything just confirms that it should be working - but it isn't.



Heres the entry for the Nicknames on the Person form type:



->add('nicknames', 'collection', array(
'type' => new NicknameType(),
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'by_reference' => false,
'required' => false
))


Nickname type only has one field - "nickname" and its a text input.



Any help? Thanks for reading.



EDIT:



Here is the update action (changed Person to Player):



public function updateAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();

$player = $em->getRepository('SCDBAppBundle:Player')->find($id);

if (!$player) {
throw $this->createNotFoundException('Unable to find Player.');
}

$editForm = $this->createForm(new EditPlayerType(), $player);
$deleteForm = $this->createGenericIDForm($id);

$editForm->bindRequest($request);

if ($editForm->isValid()) {
$em->persist($player);
$em->flush();

return $this->redirect($this->generateUrl('admin_player_edit', array('id' => $id)));
}

return array(
'player' => $player,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}


I realize that to actually persist removing nicknames I need to change the code to persist. I'm not even worried about persistence right now, because the main issue is that after I bind the request to the Player form, the $player object does not contain the updated Nicknames collection.





Flex: implementing TextInput restrict in spark table gives error

I'm creating a Flex table in which one column is editable. I want to restrict the user's input to certain characters. The following code gives an Could not resolve <s:itemEditor> to a component implementation error. Anyone know how to resolve this?



....
<fx:Array>
<supportClasses:MyColumn ... />
<supportClasses:MyColumn editable="true" ...>
<s:itemEditor>
<fx:Component>
<s:TextInput restrict="0-9a-zA-Z"/>
</fx:Component>
</s:itemEditor>
</supportClasses:MyColumn>
<supportClasses:MyColumn ... />
...
</fx:Array>
....




Binding to DataGridTemplateColumn using style applied within DataTemplate?

I have a ComboBox that composes a DataTemplate, and I'm having trouble binding its IsEnabled property to the IsReadOnly property on the templated DataGridTemplateColumn.



I've been receiving the following error in my VS output window:




'IsReadOnly' property not found on 'object' ''ContentPresenter'




ComboBox style:



<Style TargetType="{x:Type ComboBox}" x:Key="ProficiencyColumnComboBoxStyle">
<Setter Property="IsEnabled"
Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
Path=IsReadOnly, Converter={StaticResource BooleanOppositeConverter}}" />
</Style>


I believe the problem is with how I specify the RelativeSource intended to identify my DataGridColumn. I've tried:




  • RelativeSource={RelativeSource TemplatedParent}


  • RelativeSource AncestorType={x:Type DataGridColumn}


  • RelativeSource AncestorType={x:Type DataGridTemplateColumn}




I've tried adding other setters to this style, and they do take effect, so I know the style and DataTemplate are being applied to the controls.



P.S.



I've used this same technique to bind another ComboBox within a DataTemplate to a property on the parent DataGrid of its templated columns. The difference is that here I'm using a converter, and trying to bind to a property on a column (instead of the grid.) However, even if I remove the converter from the above style, no binding takes place.





Convert listBox.SelectedItem to PointF

I have an item in my listbox;
I want to take it and convert it to PointF so that I can compare it with a list of pointF.



Example)
var selection = listBox3.SelectedItem ; // like "{X=18,Y=48.10001}"



PointF p1 = (PointF) selection;



//now when that item has been selected and converted to float point, I want to search and find it in list called optFlowPoints to see if that points exists



PointF drawPointEst=optFlowPonits.Find(p=>p.Equals(selection));



So there are two problems:




  1. how to convert selectedItem to PointF

  2. how to write my lambda expression to find the match





HTML5 Canvas Mouse coordinates

I am in one .html create two first canvas have mouseDown, mouseUp, mouseMove event's and I am need for second set mouseClick event, but...
I am don't get real coordinates. something like my second canvas is 400x400 pixels and I set code:



http://pastebin.com/xxvvRFat



secondCanvas.addEventListener('click', function(e) {
console.log(e.pageX)
}, false);


if I click on top left point mouse I am get in console 500~ number, but not zero...



Sorry for my bad English language





What are the lowest locking primitives in Linux

What are the lowest locking primitives in linux. I know about futex_wait and futex_wake. But futexes can be used for signalling besides locking. What is the lowest locking primitive and where can I find it in the glibc library? Secondly, are the condition variables also based on futexes?





C# how many rectangles contains a complex figure [closed]

I draw a complex figure by Drawline() using an array of points. And I have several different rectangles (different size). The aim is to calculate how much of the rectangles contain my figure - see the picture:



enter image description here



I understand - there may be many variants - by I need to find the way - how to program it.





memory management in java strings?

Hi i am new to java programming,i created strings object as given below



Case 1:



  String s1="mystring";//Address location is 1000
String s1="yourstring";
String s2="mystring";


Case 2:



  String s1=new String("mystring");//Address location is 1000
String s1=new String("yourstring");
String s2=new String("mystring");


with ref



as per my knowledge these string are stored in string constant pool for Case1 with specific memory locations,similarly in case2 objects are created in Heap memory.how does these memory will mange and freed if we assign same or different strings to String objects.



Thanks
Mukthyar





How to make UIDatePicker to show only Sundays in objective c?

I have a question for which i didn't get any answer online…



I need to customize my uidatepicker to show only sundays or atleast can disable other days selection…Is it possible?
Thanks





create classes at runtime from database in c#

how can i create classes by using database entries in runtime



for example :



ID (int) :



1



Name (string) :



Product



Content (string) :



public class Product
{
public string Name { get; set; }



    public string Family { get; set; }

public int Age { get; set; }

}


or another pattern



its for dynamic page generator





Show application in foreground from a background agent

Is it possible to start an application in the foreground from the background agent?
Or is it only possible to show toasts ?



thx





PHP PDO class construction

Im pretty new to both PDO and OOP. Im trying to write a class that connects to a database and updates inserts and modifies it. I have several questions.



1) Is it good practices to connect to the database in the constructor?



2) Should the one class be updating, inserting, modifying and connecting or should it be split up into several classes?



3) Why is runQuery not working? I assume its because $pdo is defined in a different scope. How would I get this working?



4) If the class is include at the top of every page does that mean it will reconnect to the database every time a new page is loaded and will that cause security issues?



Apologies for the overload of questions. Thanks in advance for any answers.



<?php
class Login{

private $_username;
private $_password;
private $_host;
private $_database;
private $_driver;

//Connect to the database

function __construct($configFile){

$connectionDetails = parse_ini_file($configFile);

$this->_username = $connectionDetails['username'];
$this->_password = $connectionDetails['password'];
$this->_host = $connectionDetails['host'];
$this->_database = $connectionDetails['database'];
$this->_driver = $connectionDetails['driver'];

$pdo = new PDO("$this->_driver:host=$this->_host;dbname=$this->_database", $this->_username, $this->_password);

}

public function loginAllowed($user, $pw){

$sth = $pdo->setFetchMode(PDO::FETCH_ASSOC);
print_r($sth);
}

public function runQuery($query, $params){
$sth = $this->pdo->prepare($query);
$sth->execute($params);
}


}





Issue running express on Ubuntu 12.04

I had node installed on Ubuntu 11.10 and had express working. I then upgraded to 12.04 and suddenly I get the following stack trace:



node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: express is not defined
at Object.<anonymous> (/home/cyrus/server.js:2:11)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)


I removed express using npm and then cleared my cache and ran the following:



npm install express;


Still I get the same stack trace indicated express is not defined, although npm ls shows that I have express 2.5.9 installed with connect version 1.8.7.



My node script is as follows:



var app = require('express').createServer();
app.get('/', function(req,res){

});


It worked I upgraded to Ubuntu 12.04.





Out of Memory Error in android due to Heap Size Increasing

I am having out of Memory error. I am working on live chat application. It is working fine but when I run the app 1 to 2 hours continuously the heap size is increasing and when I do chatting then again close chat generate chat it is being crashed. In my app I am using web services.



When the heap size is increasing and reach to 16 MB application begin to hang and after some time being crashed. Showing out of memory due to heap size because the resultant heap size is greater than allocated.



I am testing my application on HTC Explorer. In my application most of the activities are using background thread and for that i am using Asnyc Task.



I am getting error like the following.



04-30 16:53:14.658: E/AndroidRuntime(5707): FATAL EXCEPTION: MagentoBackground
04-30 16:53:14.658: E/AndroidRuntime(5707): java.lang.OutOfMemoryError: (Heap Size=20167KB, Allocated=16063KB, Bitmap Size=355KB)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.util.ByteArrayBuffer.<init>(ByteArrayBuffer.java:53)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.impl.io.AbstractSessionInputBuffer.init(AbstractSessionInputBuffer.java:82)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.impl.io.SocketInputBuffer.<init>(SocketInputBuffer.java:98)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:83)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:170)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:106)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:129)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:173)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
04-30 16:53:14.658: E/AndroidRuntime(5707): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
04-30 16:53:14.658: E/AndroidRuntime(5707): at com.live2support.CustomHttpClient.executeHttpPost1(CustomHttpClient.java:163)


Is there limit of heap size?



how can i solve my issue?





Implementing method error message

I'm working on a web service to send an email. When i run my application I get the following error:



The method or operation is not implemented.



My Code in my website looks like:



WebTestServiceApp.localhost.Service1 Send = new WebTestServiceApp.localhost.Service1();
Send.Sendemail(txtTo.Text, txtSubject.Text, txtbody.Text);


My code in my webService looks like:



[WebMethod]
public string Sendemail( String inValueTo, String inValueSub, String inValueBody)
{try
{
String valueTo = inValueTo;
String valueSub = inValueSub;
String valueBody = inValueBody;
// String valueAttachmentPostedfile = inValueAttachmentPostedfile; //FileUpload1.PostedFile.FileName
// String valueAttachmentFileContent = inValueAttachemtnFileContent; //FileUpload1.FileContent.fileName

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); // Creating new message.

message.To.Add(valueTo);
message.Subject = valueSub;
message.From = new System.Net.Mail.MailAddress("shaunmossop@mweb.co.za");
message.Body = valueBody;
message.IsBodyHtml = true;

// string fileName = Path.GetFileName(valueAttachmentPostedfile); // Get attachment file
// Attachment myAttachment =
// new Attachment(valueAttachmentFileContent, fileName);
// if (fileName != "")
// {
// message.Attachments.Add(myAttachment); // Send attachment
// }

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com"); //Properties.Settings.Default.MailSMTPServer

smtp.Port = 587;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;

NetworkCredential netC = new NetworkCredential(Properties.Settings.Default.username, Properties.Settings.Default.password); // Useing Projects defult settings.
smtp.Credentials = netC;
smtp.Send(message);

return "Message has been sent";
}
catch (Exception)
{
return "Message faild to send" ;

}}


The rest of the code in the webService works, i know this because i used it in a working website, my problem is just passing the values though or a step i'm missing in the webService.



Can anyone see a obvious problem and what am i doing wrong, iv used webservices in VB but not C# so is there a difference?





How can I convert from LONGLONG to class _variant_t?

In this example m_Amount is CString. stringToNumber function converts it to a LONGLONG number successfully. But when I want to assign it to a variant I get this error:



error C2440: 'type cast' : cannot convert from '__int64' to 'class _variant_t'


mycode



_variant_t  myVar = _variant_t( (LONGLONG)stringToNumber(m_Amount) );




compilation error in java "stray '@' in program"

i am trying to submit a java program in codechef. I successfully compiled it and ran it using netbeans. But when i submit the code by uploading the corresponding .java file... it comes up like this...




prog.cpp:41: error: stray '@' in program prog.cpp:4: error: 'import' does not name a type prog.cpp:7: error: expected unqualified-id before 'public'



my java program starts like this....



import java.util.Scanner;


public class jewels{
static int CNT=0;
static String q,qq;



and so on....



Should i write any package name... or still i should rather change some thing....???



Please help... :)



@Jon Skeet... u were ... I got the error... Sorry for that.. I was submitting it as a C++ file.
but now i am getting the new one...



Main.java:7: class jewels is public, should be declared in a file named jewels.java public class jewels{ ^ 1 error



although i uploaded the jewels.java file...
please help...