Thursday, April 21, 2011

Best way to figure out why didReceiveMemoryWarning is always getting called on a UIViewController

I have a UIViewController and I'm noticing that I've done something to where the didReceiveMemoryWarning method is getting called every time I run it on an actual device.

I've run the project with Run > Run With Performance Tool > Object Allocations (and Leaks also). There are no leaks but I have no idea how to read or understand the "Object Allocations" data that is displayed.

So ...

How do I read this information and what is/are the best ways to figure out (and resolve) why this is happening?

Thanks

EDIT: I should mention that I also have a number of 3rd party libraries/code that I've included in my project (e.g. Three20, MGTwitterEngine, FTUtils, extThree20JSON and Twitter+OAuth). Could this be causing this??? Or at least contributing to the problem?

EDIT #2: Don't know if this helps but I notice that this is happening either everytime that I present a UIImagePickerController modally -OR- after a take a picture using it.

* UPDATE *

Ran it again with the Object Alloc tool for several minutes and I don't see anymore than 4.75MB being allocated at any given moment. The app was running on a device and typically with 2.5 MB allocated on average.

Does this seem problematic to anyone??? Seems like its in an acceptable range insofar as I understand thing.

From stackoverflow

.net example of using client certificates in web service call?

I'd like to use client certificates to verify the identity of administrative callers to my web service. Then I can issue certificates only to the people I want to call my web service and be pretty sure noone else can call it. This is in a very controlled scenario where only one or two people will get the client certificate, so distribution isn't a hard problem.

This article provides a good example of how to call a web service using a client certificate.

But how can I check details of the client certificate from within my web service? This old article talks about configuring IIS to do it, but I'd like to do it programmatically within my app. I think?

thanks for any suggestions!

From stackoverflow
  • The incoming Request has a ClientCertificates collection that you can interrogate -- you can check the various fields in the cert or check the actual raw byte data (perhaps against a datastore or other source) if you want to completely validate it.

    Note, if you issue the certs from your own private CA, you will need to install the CA's cert on your webserver into a store that is visible to all users, otherwise IIS won't request those certs from the user (due to the nature of how the server/client interaction works.)

  • MSDN knowledge base article:

    http://support.microsoft.com/kb/901183

Move your Working Copy

I tried to find out how to move my working copy. I know SVN move can be used to move files and folders inside your working copy but what about the working copy itself? I want to move it because I created a branch in a folder location that's different from my branch and had updated therefore all my .NET project references. So when I go to merge back to the mainline trunk I get a bunch of tree conflicts.

From stackoverflow
  • The actual working copy directory may be moved at will using your client operating system commands (i.e. Windows Explorer if you're using tortoisSVN). The working copy contains all the meta-data needed to remain consistent with the original repository from which you checked out the local working copy.

Android xml pages

where to add the new GUI xml pages in android project, say I have a welcome screen in res>layout>main.xml layout and when user clicks "next" button, it has to load up a new page with username and password GUI. any help will be appreciated

From stackoverflow
  • in your same layout folder

    res>layout>login_screen.xml
    
    : okay , thank you very much...

JNDI - how it works

If I understand correctly the default JNDI service runs on my local AS, right? So if I create an EJB and in jboss.xml (running JBoss) I name it "sth" than it is registered in my AS. Correct?

In big projects EJBs might be distributed through many servers - on one server EJBs doing sth and on another sth else. When calling JNDI loopup() I search only one server, right? So it means that I need to know where the EJB is registered... Is it true?

From stackoverflow
  • When you cluster your app you will usually configure the cluster so that you have one shared JNDI. In JBoss you do this using HA-JNDI (High Availability - JNDI) or equivalent. This is a centralized service with fail-over. In principle you could imagine having a replicated service for better throughput, but to my knowledge that is not available in JBoss.

    In short, you will have only one namespace, so you don't need to know where it is registered.

SWT applet: swt-win32-3650.dll already loaded in another classloader

I have multiple pages with java applet written with SWT. The problem is, applet loads only on first page, to load it on another page i need restart browser, otherwise i get following error:

Exception in thread "Thread-27" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons: 
    no swt-win32-3650 in java.library.path
    no swt-win32 in java.library.path
    Native Library C:\Documents and Settings\xxx\Local Settings\Temp\swtlib-32\swt-win32-3650.dll already loaded in another classloader
    C:\Documents and Settings\xxx\Local Settings\Temp\swtlib-32\swt-win32.dll: %1 is not a valid Win32 application

at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)

I wonder, how can I unload swt dlls when browser page with applet is closed?

From stackoverflow
  • Applet class:

        @Override
        public void stop() {
            // do this to unload swt dlls
            System.exit(0);
        }
    
    Gili : This won't help if you load the same applet twice or other applications that use SWT simultaneously.
    kilonet : it actually a bad solution - has many side effects (for example it shutdowns all other loaded applets). But still something

NIO Connector in Tomcat

Hi,

I'm trying to enable NIO Connector in Tomcat 6.0 by configuring server.xml file, but I'm getting Firefox can't establish a connection to the server at localhost:8081. in the browser whenever I type localhost:8081.

This is how I've configured NIO connector in Tomcat 6.0. May I know what's the problem?

<Connector connectionTimeout="20000" port="8081" protocol="org.apache.
coyote.http11.Http11NioProtocol" redirectPort="8443"/>
From stackoverflow
  • I've tried your tag on my server.

    Your Connector tag has one unnecessary space between apache. and coyote Remove it or try with the one below.

    <Connector connectionTimeout="20000" port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/>
    

    It should start up.

numeric updown control c#

I am using numeric updowncontrol. For min and max values changed listening for these events this.numDownMinLimit.ValueChanged += new System.EventHandler(this.numDownMinLimit_ValueChanged); this.numDownMaxLimit.ValueChanged += new System.EventHandler(this.numDownMaxLimit_ValueChanged);

step size set is 0.1

The eventhandler takes some time to complete.

If you keep the mouse pressed for a period of time and then release it, the eventhandler still executes with the previous values which were fired.

How do we prevent this scenario from occurring? I would like to discard the remaining events which are still in the queue, waiting to be handled, when the user releases the mouse button.

From stackoverflow
  • You need to have a look at the NumericUpDownAcceleration Class which handles this behaviour:

    From: http://msdn.microsoft.com/en-us/library/system.windows.forms.numericupdownacceleration.aspx

    The NumericUpDownAcceleration object is used by the NumericUpDown control to optionally provide acceleration when incrementing or decrementing the control through a large quantity of numbers.

    Let us know how you get on.

    Raghav : did not solved the problem once the updating the values are stopped. I will get the previous value also.

Logging iBatis (myBatis) events with GWT

How to turn on logging queries in GWT hosted mode?

From stackoverflow
  • The iBATIS framework records its interaction with the database through an internal logging mechanism patterned after Apache Log4J. The internal logging mechanism can use one of the three built-in loggers or external logging packages such as Apache Log4J. In order for iBATIS to generate log messages, the application's config file (log4j.properties or log4j.xml) must be put in default package and contains for example:

    
    log4j.appender.C=org.apache.log4j.ConsoleAppender
    log4j.appender.C.layout=org.apache.log4j.PatternLayout
    log4j.appender.C.layout.ConversionPattern=[%p] %c - %m - Date: %d %n
    log4j.rootLogger=TRACE, C
    

    That was the configuration. Apart of that you must download log4j library and put it into your classpath. At the moment the newest version is log4j-1.2.16.jar.

Adding namespace definition to xml using apache xmlbeans

I need to add namespace defintion to an element since its not getting added when when xml is generated using apache xmlbean. How do I acheieve this using xmlbeans API?

From stackoverflow
  • I have found answer to the problem. Here's how it is.

    XmlCursor cursor= targetObject.newCursor();
    cursor.toNextToken();
    cursor.insertNamespace("A", "namespace1");
    //For exmaple
    cursor.insertNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    cursor.dispose();
    

log2 in python math module

why doesn't it exist?

import math [x for x in dir(math) if 'log' in x] ['log', 'log10', 'log1p']

I know I can do log(x,2), but log2 is really common, so I'm kind of baffled.

Oh, it looks like it's only defined in C99, not C90, I guess that answers my question. Still seems kind of silly.

From stackoverflow
  • I think you've answered your own question. :-) There's no log2(x) because you can do log(x, 2). As The Zen of Python (PEP 20) says, "There should be one-- and preferably only one --obvious way to do it."

    That said, log2 was considered in Issue3366 (scroll down to the last 3 messages) which added several other C99 math functions to the math module for Python 2.7 and 3.2.

    Mark Ransom : That begs the question, why does `log10` exist?
    Mark Dickinson : log10 is C89, so it exists on all common platforms, including Windows. So it's trivial for Python to add a wrapper round it.
    nmaxwell : Well, fair enough. I guess people like log10 enough to include it specially but not log2. It looks like it's actually in numpy, so that solves that.

Super user powers in development environment?

Is it too much to ask for when I ask the IT department to give my development team an environment where we can use whatever software that we can download without having to have security check those tools?

Of course, the software can be checked by security before deploying to Test, and the development environment can be on a VLAN that is not accessible from outside. This would greatly aid us by allowing us to use whatever open-source testing tools that we want.

I'm asking because we have such tight restrictions on the software approval process, and I hear of other teams that have an environment where they can configure their local server however they want and they can use whatever tools they want. What's the norm out there?

Thank you for any comments!

From stackoverflow
  • It really depends on who you work for, and what their policies are. If you work for an open-source shop, you probably have broad powers over your machine. If you work for the military, you probably have squat.

    So there is no normative standard that you can point to and say, "See, this is how everyone else is doing it."

  • I would say that providing the development environment is isolated, then you shouldn't be restricted as to what you can install (within reason). Creativity can be severely hampered by policies!

    If you are being restricted, what's to stop you from setting up a VM on your own machine, and putting whatever you want on that? Switch off the networking on the guest machine, and you should be free to download through your host machine and copy into the guest.

    Sparky : This assumes you have the permissions or are allowed to install VM software. I'm not joking.
    red tiger : That's a good option, except it would be nice to have a network that's connected to my co-workers' machines, so we can all share a source control server, etc.
  • At one previous employer, there was a meeting for the company (around 17,000 employers) to approve software takes place every six months. If you're lucky, you get your request in the next meeting, and legal reports the meeting after that. Then IT has to approve it, which takes a few more weeks. All software must be tied to a specific business need for a project. Most projects last three months.

    David Thornley : Does this process have any relationship to why you said "previous employer"?
    Pete Kirkham : Not entirely unrelated.
    red tiger : I assume that the company wasn't in the business of providing software as one of their products...

NSFetchedResultsController not processing certain section driven moves

I utilize a NSFetchedResultsController (frc) with a Core Data store. I implement all the frc delegate methods. The table is sporadically updated by background threads. All the inserts, deletes and updates work fine, with the exception that updates to the frc's index key for rows toward to the bottom of the table (50 rows), do not result in a section move. e.g. if "name" is the index key and the name "Victor" is changed to "Alex", the victor row now shows the name Alex, but is not moved to the top of the table alongside all other names starting with A. As I noted, this is only for rows towards the bottom of the table. If a row like "Andy" is changed to "Ben", the move is indeed processed correctly by the frc. Any suggestions to fix this would be appreciated. I do not use a frc cache. Thanks

From stackoverflow
  • There are a few twitchy issues with the FRC and table view sections in pre-4.0 Core Data. I would suggest retesting in 4.0; if it works and you need to be 3.x compliant then do table reloads instead for 3.x to avoid some of the refresh issues.

    update

    If the issue is persisting in 4.0, then I highly recommend building a test case to duplicate the issue. This will accomplish several things:

    • it will give me a clearer picture of the issue.
    • it may show you the solution.
    • if we are both stumped you can submit it to Apple so they can fix the API

    I cannot suggest this strongly enough.

    Run Loop : Thanks for your reply. Unfortunately, these issues persist in 4.0. My workaround is in fact a reload as you suggested. I hope all the frc issues will be resolved eventually.

Is there any Tag for generating a datagrid in Struts 2?

Hi..,

I need to generate a datagrid using a Struts 2, i have found out Struts-Layout can do that, but its not supporting Struts 2. Can any one suggest me a way to generate a datagrid using Struts 2?

From stackoverflow
  • There are two out of the box solution available.

    The first is Display Tag and the other is [Struts2 jQuery Plugin with the Grid Tag][2].

    http://displaytag.sourceforge.net/1.2/ http://code.google.com/p/struts2-jquery/

Unable to migrate mails to "Trash"

Hi,

I am migrating some mails to 'TRASH' in Google Apps.

Using Google API Ver 2:

Code Sample :

MailItemEntry[] entries = new MailItemEntry[1];
entries[0]              = new MailItemEntry();
entries[0].Rfc822Msg    = new Rfc822MsgElement(msg);
entries[0].MailItemProperties.Add(MailItemPropertyElement.TRASH);                                  

I tried with :

entries[0].Labels.Add(new LabelElement("Trash"));

How can i migrate mails to "TRASH" in Google Apps ?

Thanx

From stackoverflow
  • Sorry...but u r going in a wrong way... :)

    Preeti Singh : then what is right way?
  • Google Apps or Gmail keeps only Last 30 Days mails in Trash.

Can the get of a property be abstract and the set be virtual?

I have a base class like this:

public class Trajectory{
    public int Count { get; set; }
    public double Initial { get; set { Count = 1; } }
    public double Current { get; set { Count ++ ; } }
}

So, I have code in the base class, which makes the set-s virtual, but the get-s must stay abstract. So I need something like this:

...
public double Initial { abstract get; virtual set { Count = 1; } }
...

But this code gives an error. The whole point is to implement the counter functionality in the base class instead in all the derived classes. So, how can I make the get and set of a property with different modifiers?

From stackoverflow
  • split it into 2 functions:

    public double Initial
    {
        get { return GetInitial(); }
        set { SetInitial(value); }
    }
    
    protected virtual void SetInitial(double value)
    {
        Count = 1;
    }
    
    protected abstract double GetInitial();
    
  • Make it neither abstract nor virtual. And make the backing field private. That way, a derived class cannot override it nor can it mess with it.

  • No, you can't. At least I haven't found a solution.

    If property is marked as abstract then neither it's getter and setter can have bodies.

coverting existing flash with cakephp website into mobile version

How to convert the existing flash site into mobile version existing site in form of the cakephp frame work. We thought that html ,css,php,javascript may work all mobiles.We dont know exactly. Please tell us how many possible way to develop existing site into mobile version and also need to detect the from which browser the request is coming whether mobile browser or pc browser.

The existing site link is :This site convert into mobile version

From stackoverflow
  • Take a look at this post. PHP is handled on the server. No browser needs to support it. CSS and XHTML are supported pretty well by mobile browsers. Javascript support is limited.

Android: How to create custom shape keys on keyboard?

I wonder how could is possible to make custom shape key on android keyboard. To create custom keyboard is relatively easy, but what needs to be done to create new buttons. They also need to respond with all events as normal keyboard.

Any ideas where to start?

From stackoverflow
  • You need to create an image for each key you want on your custom keyboard, and then, create the xml supporting the design of your keyboard and load it in your application with they Keyboard class. Do you need more details? If so, I will prepare one if you want, I've been wanting to have a go at this class for a while.

    Solata : Isn't enough just overriding the createKeyFromXml() function of Keyboard class?
    Sephy : oh yeah, I suppose it is possible, though I never tried it. Didn't understand you properly, I thought you wanted to change the whole keyboard
    Solata : You understood right, I just thought this would be easier way. I guess not. Perhaps you should go a little more in details :)
  • Yes, that would be great if you can post more explanation !

simple jquery dropdown - clearTimeout, setTimeout issues

HTML:

<ul class="topnav">
    <li><a href="#"><span>One</span></a></li>
    <li><a href="#"><span>Two</span></a></li>
    <li>
        <li><a href="#"><span>Three</span></a></li>
        <ul class="subnav">
            <li><a href="#">A</a></li>
            <li><a href="#">B</a></li>
            <li><a href="#">C</a></li>
        </ul>
    </li>
</ul>

jquery:

var timeout = null;

$(document).ready(function() {

    $("ul.topnav li").mouseover(function() {

        if (timeout) clearTimeout(timeout);

        $(this).find("ul.subnav").slideDown('fast').show();

    }).mouseout(function() {
        timeout = setTimeout(closemenu, 500);
    });

    // sub menu mouseovers keep dropdown open
    $("ul.subnav li").mouseover(function() {
        if (timeout) clearTimeout(timeout);
    }
    ).mouseout(function() {
        timeout = setTimeout(closemenu, 500);
        // alert(timeout);

    });

    // any click closes
    $(document).click(closemenu);
});

// Closes all open menus 
function closemenu() {
    $('ul.subnav:visible').hide();
    if (timeout) clearTimeout(timeout);
} 

I'm having issues with timeout. In use, if i mouseover "Three", the dropdown stays out forever. if i mouseover "A", dropdown will stay out forever, but if I mouseover "B" or anything lower, the menu will close on me. if you uncomment "// alert(timeout);" it gets there for B, (and A) but timeout will have a value. why is this? i thought clearTimeout would null the timeout variable?

From stackoverflow
  • youre trying to build a drop down menu? why not use existing jquery plugins for that or better yet, css-only drop down menu like http://purecssmenu.com/?

    : i'm trying to work it into an existing website menu, so i was trying to go the simplest route possible
  • You can simplify your code overall by using .hover() and .data() like this:

    $(function() {
      $("ul.topnav li").hover(function() {
        var timeout = $(this).data("timeout");
        if(timeout) clearTimeout(timeout);
        $(this).find("ul.subnav").slideDown('fast');
      }, function() {
          $(this).data("timeout", setTimeout($.proxy(function() {
              $(this).find("ul.subnav").slideUp();
          }, this), 500));
      });
      $(document).click(function() {
          $('ul.subnav:visible').hide();
      });
    });​
    

    You can see a working demo here

    Instead of sharing a global timeout variable, this sets a timeout per top level <li>, each one has an independent timer, and when you hover back over that element, only its timer is cleared. Also .hover() uses mouseenter and mouseleave, rather than mouseover and mouseout, the difference is when you go into a child or between children, mouseenter doesn't fire again, and mouseleave doesn't fire on the parent <li> we care about.

    You can test this with the demo link above, I added sub-items to the first menu as well, to demonstrate they're independent. If you happen to have question about the $.proxy in there, it's just making this inside that timeout anonymous function refer to what I want it to (the current this)...the element that needs closing after the timeout.

Urgent Please in asp.net

Can u say how to set readonly property in property method(get and set)

if anybodies knows please share with me...............

From stackoverflow
  • You can either only give your property a getter:

    private string _name;
    
    public string Name { get { return _name; } }
    

    Or you can give the accessors different visibilities:

    public string Name { get; private set; }
    
  • You simply omit the setter:

     private string myField;
     public string MyReadOnlyProperty {get { return myField;}}
    

ORM on android SQLite and database scheme

I'm looking for a very simple ORM framework working on Android for sqlite. I've been testing activeAndroid but none of the example could ever build on Eclipse. By the way, how do guys implements a "many to many" relationship in sqlite for android ? How do you reflect the cascade regarding deletion of rows and guarantee the database integrity ?

From stackoverflow
  • Try SQLiteGen. It's not as feature-rich as hibernate, but you can generate some simple ORM classes with it in Eclipse.

    Hope that helps!

  • ORMLite has recently released the 3.2 version which makes calls to the native Android OS database APIs to support its ORM functionality. Love to get some feedback from more Android developers.

if insert error in oracle trigger creation?

  CREATE TRIGGER Background_Process_Report_trit
AFTER INSERT
ON Background_Process_Report
FOR EACH ROW
IF INSERT(PROCESS_NAME)
BEGIN
    SET EXECUTION_TIMESTAMP := NEW.TIMESTAMP; 
END;
/

process_name -- column in my Background_Process_Report table.but i want to update the each time the process_name is created(by java application), trigger update the time in the EXECUTION_TIMESTAMP table. but it is throwing the compliation error..

error:

IF INSERT(PROCESS_NAME)
*
ERROR at line 5:
ORA-04079: invalid trigger specification

how to reslove this error

From stackoverflow
  • If EXECUTION_TIMESTAMP is a table as you say, then it must have a column you want to update, let's call it TIMESTAMP_COL. The the trigger would be something like:

    CREATE TRIGGER Background_Process_Report_trit
    AFTER INSERT
    ON Background_Process_Report
    FOR EACH ROW
    WHEN (NEW.PROCESS_NAME IS NOT NULL)
    BEGIN
        UPDATE EXECUTION_TIMESTAMP
        SET TIMESTAMP_COL = NEW.TIMESTAMP
        WHERE ???;  -- Change ??? to the appropriate condition
    END;
    /
    

    I have assumed that by "IF INSERT(PROCESS_NAME)" you mean "if a non-null value is inserted into PROCESS_NAME" and created a WHEN clause to match.

    murali : Thanks...it is working fine
    Peter Lang : @murali: If this answer is working for you, please consider [accepting it](http://meta.stackoverflow.com/questions/5234/accepting-answers-what-is-it-all-about).

Channel Factory in WCF

Hi all i am new to WCF i wanted to know if i use channel factory and if i make any changes in service contract whether the changes will be updated automatically in the client system or not???If the changes are updated automatically how????

From stackoverflow
  • No, the channel factory is not updated automatically - you have to update your service reference (if you added it using Visual Studio's Add Service Reference) or you need to re-create the client side proxy from the WSDL/XSD or service URL.

    UPDATE: of course, if you're sharing the service and data contracts in an assembly between both the service and the client, then of course you have the client up to date as soon as you have the new service contract DLL in place...

    If you want to enable this sharing of service and data contracts, use the following setup:

    • in your Contracts assembly, have all the service contracts (interfaces) and data contracts (data types)

    • in your implementation of the service, reference that Contracts assembly and implement the service contract(s)

    • in your client-side proxy, also reference that shared Contracts assembly, and use ChannelFactory<T> to create a channel factory for the service contract interface T.

    With this setup, whenever you make a change to the shared contract assembly, both service implementation and client side proxy will "get" those changes, e.g. they're always up to date and using the same service and data contracts

    : Thnaks..If i add service DLL in client side then if i make any changes in the service then what should be done in order to update the client side????
    marc_s : If you share the DLL with the service and data contracts, then you don't have to do anything - you're sharing the same code base, after all, so any changes in your service contracts are in the client side proxy automatically (you didn't mention this very important fact in your question....)
    : sorry marc its my mistake...can u give me an example how to use the channel factory and make changes in the service without changing anything in the client side????
    : Thanks marc...it really helped me

postback validation causes an alert dialog to be displayed

Hi, For some strange reason an alert dialog with the text title "Message From Web page" and message "-" displays when posting back a for with validation. There are no custom validation scripts that display an alert window. I am debgging javascript using IE development toolbar? Is it possible to break into the code that displays the alert box? so far I have been unable to do so.

Thanks

From stackoverflow
  • CTRL-SHIFT-J (also under the Page > Developer > Debug JavaScript menu item) in chrome to debug javascript. Debuggin in chrome is easier than IE

  • the validation error was displayed by validation summary control with no display. Thanks for taking the time.

Push notifications for iPhone

I need to implement push notifications in my iPhone app. This is the first time I am working on this. I created certificates and a basic program. I need to link up with the server (the server is implemented in Java). I don't know how to link up. Can anyone help me?

From stackoverflow
  • There's no simple answer that'd fit in here. Read all the docs that apple provides.

    This should help you out as well: http://www.easyapns.com/

Eclipse CDT Debugger Issue, v. .metadata does not exist

I am attempting to use the gdb/mi debugger in the Eclipse CDT version 6.02. While I am debugging I can step through the program with ease up until I reach the following snippet of a block of code.

ENUM_START_TYPE My_Class::some_function( const char * c, const char * e)
{
    ENUM_START_TYPE result = GENERIC_ENUM_VALUE;

    if ( c[0] == '<' )
    {
        result = do_something()
    }

    ...
    MORE CODE
    ...

    return result;
}

When the debugger reaches this line.

if ( c[0] == '<' )

It starts exploring sections of code that it can not find until it opens a tab containing the /projectname/.metadata and simply declares:

"Resource '/project_name/.metadata' does not exist.

At which point the debugger terminates the program with no reason as to why.

All I wish to do is step over this line of code because it really is as trivial as comparing characters.

My question is: Why is this happening? Is it something to do with the debugger, or does it have something to do with my code, or what. Additionally, what is the .metadata and why can't the file be located and opened when it clearly exists (I can locate and open the .metafile without a problem).

Other info that may be pertinent: The files are located on a clearcase snapshot view, but are not checked into source control. I don't think that would cause an error like this, but clear case has caused so many random errors for me that I thought it would be worth mentioning.

Thanks in advance

From stackoverflow
  • As I am not aware of any side-effect a snapshot view might have in the process.
    A dynamic view could consider part of the directories as "non-selected" (and then non-readable).
    You have also the issue of symlink to dynamic view set on drive.

    But a snapshot view is nothing more than a working tree on the hard drive.

    To rule out any "ClearCase interference", you could try and debug your project entirely copied outside of any view of any sort (based on the content of your current snapshot view), and see if the problem persists.

    dp : Thanks for the advice on clearcase, I tested the program outside of the snapshot view and the error still occurs, so we can pretty much rule that out as a possible problem.

Missing site templates when creating a publising (template) site in SP2010

All I am having issues trying to add some of the additional site templates when a user selects New Site form the site settings menu. I have a publishing site template as recomended by Microsoft as a default Intranet site. How can I add some of the templates such as a team site, or something else?

From stackoverflow
  • I was using a publishing template from the start, so i rebuilt the server anyway, and created a blank site with activitating the publishing features.

Rails — Formtastic, how to set text for options in select?

f.input :some_model_values, :as => :select

Using Formtastic, I need to set a text for options on my select input, but not populated from :some_model_values.

The second: how could be collection of :some_model_values pre-modefied? Because i don want to show some options according to user role.

Thanks!

From stackoverflow
  • What do You mean with "set a text for option on my select input" ?

    Please have a look at the :collection parameter, for example:

    f.input :some_model_values, :as => :select, :collection => [1,2,3,4]
    

    or

    f.input :some_model_values, :as => :select, :collection => [["male",1], ["female",2], ["other",3]]
    

    When you want to set the label, the best option is to localise it by the /config/locales/#locale#.rb file

    Hope this helps

Not able to access dynamic controls (inside ascx) using javascript (on aspx page)

Hello all,

I have a user control (ascx) which contains a control (hidden field). In the page_load event of ascx, i have the below code:

HyperLink.Attributes.Add("onclick", "JavaScript:return AccessControl('" + hdnField.UniqueID + "');"); Note: The hidden field resides in .ascx file.

I want to access this hidden field at runtime and i have the below javascript function in aspx page that loads the usercontrol.

function AccessControl(hdnFieldId) { var ctrl = document.getElementById(hdnFieldId); alert(ctrl);

I am getting 'null' value in the alert. I tried using 'ClientID' and 'this' instead of 'UniqueId'. I am wondering why this is not working. I am using .net 2.0.

From stackoverflow
  • Does the hidden field exist when the page renders? Try moving the code for adding the control into the page init, this is the safest place to dynamically add controls to the page.

List.ForEach method and collection interfaces

In .NET 3.5 List<> gains a ForEach method. I notice this does not exist on IList<> or IEnumerable<> what was the thinking here? Is there another way to do this? Nice and simple short way to do this?

I ask because I was at a talk where the speaker said always use the more general interfaces. But why would I use IList<> as a return type if I want to be able to turn around and use ForEach? Then I would just end up casting it back to a List<>.

From stackoverflow
  • what was the thinking here?

    You can read Eric Lippert's blog for the reasons why this feature wasn't added.

    Is there another way to do this? Nice and simple short way to do this?

    Why not just use the foreach keyword? I find it more readable.

    foreach (var foo in ilist)
    {
        // etc...
    }
    

    Though you can add a ForEach extension method to IEnumerable<T> if you want to:

    public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action)
    {
        foreach (T item in enumeration)
        {
            action(item);
        }
    }
    

    Taken from here.

  • It's not in the framework (yet) but Rx adds the .Run(this IEnumerable enumerable) extension method that does the same as List's custom ForEach. Until this is part of the standard framework you'll have to write your own or use the extra dependency.

    tyndall : Good to know this is coming.
  • Why is ForEach not in IEnumerable<T>? Eric Lippert explains this nicely in his blog. Basically, LINQ is meant to be functional (no side effects), and ForEach is decidedly non-functional.

    But, why is it not in IList<T>? Well... it should be!

libvlc_media_player_get_time returning zero

Hi! hey people I was writing a simple application to run a video stream using libvlc.But it seem that libvlc_media_player_get_time() function is not working properly.It is returning zero every time it is being called no matter how much video has been played.So can you please find out the possible remedies for it. Also is there any signal handler or function in libvlc which can raise an event when we reach the end of stream so that I can pause for a moment till more data get stacked up? All the replies in this regard will be appreciated. With Regards, Thanks

From stackoverflow
  • if you're streaming incoming data it might always return 0

C# Microsoft Chart Control/Dundas Charts Clear Contents!?

Hello! I am using the Dundas Chart Controls/Microsoft Chart Control for .Net. Currently I have a method which populates the chart control with date from a generic List.

Lets say for example that I populate the chart with data from one list. Then I want to populate the chart with data from another list.

The problem I have is that when populating the chart with the data from the second list, I end up with a chart that displays the combined data from list 1 and list 2, whereas I want it to display only the data from the first list, and then clear the chart before displaying the data from the second list.

I have tried various method calls to clear the chart control before populating it with the data from the second list but to no avail.

Does anyone know of a way of doing this? Help appreciated greatly,

Regards,

From stackoverflow
  • You should probably post some example code.

    However, I would guess it is simply a matter of resetting the data source. Assuming you have a list of points (or some other structure), you should probably create a new instance of that data container (i.e. the list), populate that, and then assign it to the chart.

    Instead, it seems like you are probably trying to set the elements of an existing data container and not clearing it out correctly.

  • Found it!

    chart1.Series[0].Points.Clear();

  • A comment for others who may come across this:

    To clear out the chart series, titles, and legends:

    //clear chart
    Chart1.Series.Clear();
    Chart1.Titles.Clear();
    Chart1.Legends.Clear();           
    //create chart
    

Struct with pointer to a function

Hello,

In a C struct I have defined a function pointer as follows:

typedef struct _sequence_t
{
  const int seq[3];
  typedef void (* callbackPtr)();
} sequence_t;

I want to initialize a var of that type globally with:

sequence_t sequences[] = {
  { { 0, 1, 2 }, toggleArmament },
};

And I keep getting error telling me that there are too many initializers. How to work it out?

From stackoverflow
  • typedef is used to declare an alias to a type. Since you have an actual member here, remove the inner typedef.

    typedef struct _sequence_t
    {
      const int seq[3];
      void (* callbackPtr)();
    } sequence_t;
    

How to retrieve Google Appengine Objects by id (Long value) ?

Hi,

i have declared an entity the following way:

public class MyEntity {
 @PrimaryKey
 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 private Long id;
 @Persistent
 private String text;
        //getters and setters
}

Now I want to retrieve the objects using the id. I tried to manage it from the Google Appengine Data Viewer with "SELECT * FROM MyEntity Where id = 382005" or via a query in a servlet. I get no results returned. But i know for sure that the object with the id exists (i made a jsp which queries all objects in the db and displays them in the db).

So what is wrong in my query? Am I querying the wrong field? The Google Appengine Data Viewer names the field "ID/name" and it has the value "id=382005". Do I have to query with this names? I've tried but it didn't work out :(

From stackoverflow
  • You can use below since you are querying using the primary key:

    MyEntity yourEntity = entityManager.find(MyEntity.class, yourId);
    

    Note, this should work as well, but it's easier to use find() if you are searching based on the primary key:

    Query query = entityManager.createQuery(
        "SELECT m FROM MyEntity m WHERE id = :id");
    query.setParameter("id", yourId);
    
    MyEntity yourEntity = (MyEntity) query.getSingleResult();