Thursday, April 12, 2012

Keeping variable value while making async call to FB.api

I am trying to get albums of a user with the following JavaScript function, first call gets album list, and while iterating in albums I get their cover picture:



function GetAlbums() {
FB.api('/me/albums', function(resp) {
var ul = document.getElementById('albums');
for (var i=0, l=resp.data.length; i<l; i++) {
var album = resp.data[i];
FB.api('/'+album.cover_photo, function(resp1) {
li = document.createElement('li'),
a = document.createElement('a');
a.innerHTML = "<img src='"+resp1.picture+"'/>"+album.name;
a.href = album.link;
li.appendChild(a);
ul.appendChild(li);
});
}
});
};


I don't know why but cover pictures are fetched ok, but album name is always same. Probably the inner FB.api call is async. and before it finishes the album iteration goes to the last element. How can I correct the code?





Apache Unexpected subelement exception while generating a webservice client

I'm trying to generate a webservice client with wsdl2java from axis2 (version 1.6.1).



./wsdl2java.sh -uri http://www.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/efetch_snp.wsdl


When I call this service, I get an Exception.



org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://www.ncbi.nlm.nih.gov/soap/eutils/efetch_snp}Rs



    try {
EFetchSnpServiceStub fetchService = new EFetchSnpServiceStub();
EFetchSnpServiceStub.EFetchRequest reqIdSnp = new EFetchSnpServiceStub.EFetchRequest();
reqIdSnp.setId("193925233");
EFetchSnpServiceStub.EFetchResult resIdSnp = fetchService.run_eFetch(reqIdSnp);
} catch (Exception e) {
System.out.println(e.toString());
}


With soaptest however I can see the Rs Tag in the result.



<Rs rsId="193925233" snpClass="snp" snpType="notwithdrawn" molType="genomic" bitField="050000000005000000000100" taxId="3702">


How can I fix this exception? The WSDL is not under my control.





Project created in Visual Studio, open in Visual Studio Express for Windows Phone

I am new to Windows Phone 7 and Visual Studio and was just trying to look at a sample project and apparently the project was created in Visual Studio 2010 (as the .sln file of the project says)



On my machine, for WP7 development I have installed Visual Studio 2010 Express for Windows Phone which comes with WP7 SDK.



Now, when I try to open the sample project on VS Express it says:



The project type is not supported by this installation.


Is there a way that I can try the sample project on Visual Studio Express for WP7 or I must have Visual Studio installed?



Edit:



This is the project that I wanted to open in VSE for WP





Can I and is there a need to avoid singleton pattern?

I'm writing a program where among lots of other stuff I need three classes we can call here writer, storage and reader.



Writer needs to access the storage class very very often while reader instead somewhat seldom especially compared to writer. Storage class is there only to store the data writer writes. The only thing the writer is doing, is just to write some short bursts of data quite often. The reader reads the written data from storage and then flushes the storage to free some space for the writer to write new data. To give some numbers and idea of the frequency of the accesses let's say that the writer is accessing the storage numerous times in minute and the reader is accessing it approximately once in an hour.



So the question is that do I need to use the singleton pattern in the storage class or is it enough to declare it as static class?



Also how I can ensure that when the reader class is using the storage, it releases the storage resource immediately after it has read and flushed the data from the storage? Most of the time the storage class should be available for the writer to write the data in it.



The singleton approach looks nice especially that I'm not from OOP background. I've heard that it's bad though.





Creating our own crop rect in camera overlay

Before placing my question, I want to state my basic requirement which is to change the frame for crop rect in UIImagePickerController for a camera.

I just realized that it is not possible to change frame for crop rect. That leaves me with only one option i.e to create my own camera overlay wherein I can set frame for crop rect. I searched a lot but found nothing. I asked previously but didn't get anything. I don't even know is it possible and if yes then how to create it and move the crop box, scale it in accordance to default UIImagePickerController crop rect.

Can someone help me here?

Thanks,

Nitish





facebook api post to wall not working at server 400 bad request

I am trying to post request on the wall but facing a 400 Bad Request error.



I am using the following code:-



if (string.IsNullOrWhiteSpace(user.Facebook) || string.IsNullOrWhiteSpace(user.FacebookToken))
{
req.Status = (int)Notify.NotifyStatus.MissingAccount;
db.SaveChanges();
return false;
}

var address = "https://graph.facebook.com/" + user.Facebook + "/feed";
var form = new System.Collections.Specialized.NameValueCollection();
form.Add("access_token", user.FacebookToken);
form.Add("message", "Connect6");
form.Add("link", joburl);
form.Add("description", description);
form.Add("picture", picture);



WebClient wc = new WebClient();
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
var responseBytes = wc.UploadValues(address, "POST", form);
var page = Encoding.UTF8.GetString(responseBytes);

req.Status = (int)Notify.NotifyStatus.Sent;
db.SaveChanges();
return true;


At response bytes it is giving me error



Please suggest





NSArrayController + NSTableView : automatically save changes without Core Data

OK, so I'm implementing a classic scenario :




  • A NSPopupButton with some items in it

  • When the selected value changes, my itemsArray is updated

  • The itemsArray is linked to an NSArrayController

  • Each item in the itemsArray is an NSMutableDictionary (with keys : title,content)

  • An NSTableView displays the titles of the arrangedObjects (binding)

  • An NSTextView displays the content of the selected item.



Now, what I want is to automatically save any changes to the itemsArray (or itemsArray's item title/content), but without using Core Data (which I suspect might have been the best way to go about it).



I imagine it's quite a basic question this one, but honestly I've never really like Cocoa's auto-magical way of doing things... so, I need your help...



How should I go about that?





How to Identify the new iPad

I need to know current device is iPad2 or new iPad.
I use [[UIScreen mainScreen] Scale],but the result is 1.0





User analysis based on thier facebook profile?

I am pretty much sure that if you look carefully at any friend's timeline profile you can easily predict what going on in his/her life, Even you can write his/her entire life, you can also find out the hidden fact which he/she never told or updated directly but indirectly he/she shared n liked related thing which will help you to analyse his/her activity. Is it anyway possible to build an automated system which can read n analyse friends entire facebook profile, his/her shared stuff, likes, comments etc. and create a report which will expose his/her entire life fact including hidden one, using some AI or Machine learning concepts?





Call .Net assembly from a Biztalk Orchestration

I got a external .net assembly including app.config which I need to call from a Biztalk Orchestration.



I've put some logging into the .net assembly and can see that it doesn't read or can't find the app.config file as ConfigurationManager.AppSettings.Count is 0



I installed the .net assembly to the GAC using the gacutil /i path.to.dll and i'm not sure what happens to the app.config.



Any ideas on how I make sure the app.config is being read when I call it from a Biztalk Orchestration ?



Thanks.





C# streamwriter invoke

i want to reach and write a txt file in cross-threads but software gives an exception because multiple threads wants to reach the same file at the same time. How can i invoke streamwriter to avoid exceptions? Here is my code:



void WriteLog(string LogStr)
{
StreamWriter sw = new StreamWriter("Log.txt", true);
sw.WriteLine(LogStr);
sw.Close();
}


I call WriteLog method in threads.



Thank you.





Call an action using javascript and cause a post back

I need to call an action using a javascript method. That is I have a page with a link say like the one below,



      <a href="javascript:Sort();" >Click Me to Go</a>


and I need when a click is made to this I want to call an action which will return a view and I WANT A POST BACK to happen.



Below is what I have found to be working, but I am not sure if this is the right method, is there a way I could do this using $post, $ajax or $json ?



This is because I need to pass value to the action too.



 function Sort() {
location.href='@Url.Action("ActioName")';
}




Using fread to store data into a char buffer

I am working on a project where I need to read data from a binary file. I am trying to store the data into a char buffer. Suppose the binary file consisted of a character, an int and a double what size would the char buffer need to be ? And how would I convert back into int's and doubles ?



I am reading the data into a char buffer because it would improve the speed of my program.



Thanks!





Android ListView crashes while scrolling

i see a weird bug here.. i have a list view which is populated from the server in an async... it populates first and then displays the list view... but when i scroll down it crashes... from the logs i see it is not related to population of list view and all.. ... can you please help me?



04-12 12:39:54.676: E/AndroidRuntime(1984): FATAL EXCEPTION: main
04-12 12:39:54.676: E/AndroidRuntime(1984): java.lang.NullPointerException
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.widget.AbsListView.obtainView(AbsListView.java:1304)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.widget.ListView.makeAndAddView(ListView.java:1727)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.widget.ListView.fillUp(ListView.java:682)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.widget.ListView.correctTooHigh(ListView.java:1349)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.widget.ListView.fillGap(ListView.java:624)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:2944)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.widget.AbsListView.onTouchEvent(AbsListView.java:2065)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.widget.ListView.onTouchEvent(ListView.java:3315)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.view.View.dispatchTouchEvent(View.java:3766)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
04-12 12:39:54.676: E/AndroidRuntime(1984): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
04-12 12:39:54.676: E/AndroidRuntime(1984): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
04-12 12:39:54.676: E/AndroidRuntime(1984): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1655)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.os.Looper.loop(Looper.java:123)
04-12 12:39:54.676: E/AndroidRuntime(1984): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-12 12:39:54.676: E/AndroidRuntime(1984): at java.lang.reflect.Method.invokeNative(Native Method)
04-12 12:39:54.676: E/AndroidRuntime(1984): at java.lang.reflect.Method.invoke(Method.java:521)
04-12 12:39:54.676: E/AndroidRuntime(1984): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
04-12 12:39:54.676: E/AndroidRuntime(1984): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
04-12 12:39:54.676: E/AndroidRuntime(1984): at dalvik.system.NativeStart.main(Native Method)




Sencha touch 2/ app workflow with navigation view

There is a problem with sencha touch 2.



I am trying to understand how can I implement the same functionality which provides navigation view in sencha touch 2, but ....
Each item of the 'Ext.NavigationView' component should have it's own unique set of 'navigationBar' elements. I mean set of buttons, for example.



I know that I can do something like this:



this.getMain().getNavigationBar().rightBox.removeAll();
this.getMain().getNavigationBar().rightBox.add(this.getSettingButton());
//where 'getSettingButton' predefined by me a button


And do this action each time when 'push' event happens (clear 'navigationBar' and add appropriate set of buttons)



Of course, I even can implement 'Ext.Panel' with 'layout: card' and set of 'Ext.panel' elements in the 'items' property, each of which will be have unique 'toolbar'.
To control the behavior I can use 'setActiveItem' method.



But, I think each of these approaches is a bit weird, isn't it?



I expected that would be much more natural approach to implement it.



Most likely I don't know what I need. Confirm my doubts. What is the best way to do it.





jQuery form error checking

I'm doing a simple jQuery form checker for a website. I have two forms on the website: a login form and a signup form. My code is as followed:



$('.btn').click(function(e) {
e.preventDefault();
// DOES SOME ERROR CHECKING HERE
if { hasError $('div.error').fadeIn() }

else { $(this).parents('form').submit() }
});


So my question is, both the login button and the signup button has a class called btn, how can I have the them check their own form instead of checking all the forms on the page since $(this).parents('form') will get both the signup and login form?



Thank you!





Best algorithm on checking a node in a tree path?

Suppose I have this tree :



           O-ROOT
/ \
O-A O-B
/ / \
O-A1 O-B1 O-B2


and I want to do this in C#:



1. Check every node starting from root (I think the best way is trought recursion?);
2. If I found a node with value = "Hello", return true and STOP the searching function;


Can you help me to make the best algorithm for doing it?





JavaScript - Can we set javascript objects in cookies?

I'm trying to put one javascript object in Cookies but somehow it is getting converted as String object. Is there any way we can set Objects in JavaScript cookies?





Android: Empty space between listview header and first item

I've created an android application with a ListView. I've added both a header and a footer to the list. But when adding a divider/seperator it also creates an empty space between the header and the first lisview item. It does the same for the last listview item and the footer.



The empty space is equivalent to the size of the divider between all the listview items, with the difference that it doesn't draw the divider and just leaves empty space. I thought I found the solution with the xml attributes 'Footer dividers enabled' and 'Header dividers enabled'. But when setting them to false, it doesn't change anything. I even tried to set them programmatically with



list.setFooterDividerEnabled(false);
list.setHeaderDividerEnabled(false);


But it just doesn't work. Any way to fix that problem? I just don't want the empty space to be there, I want the first item to fit exactly to the header (same for the footer).





MPMoviePlayerController not working in iOS 5 xcode (with storyboard), but works perfectly in iOS 4

I'm having problems playing a movie with the new xcode that comes with iOS 5 beta. I created a simple project (with storyboards and all), and added this code to a button:



MPMoviePlayerController *moviePlayer;
NSString *path = [[NSBundle mainBundle] pathForResource:@"position" ofType:@"m4v"];
NSURL *videoURL = [NSURL fileURLWithPath:path];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
//[moviePlayer setControlStyle:MPMovieControlStyleDefault];
[moviePlayer.view setFrame: self.view.bounds]; // player's frame must match parent's
[self.view addSubview: moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];


The confusing thing is that it works perfectly when I throw the code into a project built with a previous version of xcode (specifically the one that comes with iOS 4.3).



Any ideas?





Creating a view that display all records that belongs_to an association

I'm trying to create a view that display all records that belongs to an association and not sure on how to go about this.



I've created an erb file in view/members/showmembers.html.erb, added 'showmembers' method in members_controller.rb but when I go to http://localhost:3000/members/showmembers it says 'Couldn't find Member with id=showmembers' and its pointing to the show method in the controller *'app/controllers/members_controller.rb:29:in `show'*.



  def showmembers    
@organization = Organization.find(1)
@shmembers = @organization.members.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @members }
end
end


showmembers.html.erb



    <% @shmembers.each do |shmember| %>
<tr>
<td><%= shmember.id %></td>
<td><%= shmember.first_name %></td>
</tr>
<% end %>


Thanks.





Formatting a date in javascript

I noticed that javascriptnew Date() function is very smart in accepting dates in several formats.



Xmas95 = new Date("25 Dec, 1995 23:15:00")
Xmas95 = new Date("2009 06 12,12:52:39")
Xmas95 = new Date("20 09 2006,12:52:39")


But i could not find documentation anywhere showing what all string formats that are valid while calling new Date() function.



This is for converting string to date.
Now, if we look at the opposite side that is converting date object to string.



Till now, I was under impression that javascript doesn't have inbuilt API to format date object into a string.
Today, i played toString() method on date object and surprisingly it serves the purpose of formatting date to strings.



var d1=new Date();
d1.toString('yyyy-MM-dd'); //returns "2009-06-29"
d1.toString('dddd, MMMM ,yyyy') //returns "Monday, June 29,2009"


But here also i could find any documentation on what all ways we can format the date object into a string.



can someone please point me to a documentation which lists about the format specifiers supported for new Date() object.





Reloading UITableView without animation

What I'm trying to achive is UITableView reloading fast. Each cell has "checking" UIButton wchich tells user that item for this cell is selected. All selected cells should be on the end of the list (bottom cells).



I'm using NSFetchResultsController as a delegate and data source for UITableView. NSFetchResultsController is set to operate with "Item" entity with sectionKey selected for "checked" property (part od "Item" entity which )



- (id)initWithItemView:(ItemView*)iv{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Item" inManagedObjectContext:[CoreDataHandler context]];
[request setEntity:entity];
NSArray *predicates = [NSArray arrayWithObjects:[iv listDBUsingContext:[CoreDataHandler context]],nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"lista IN %@ AND deletedDB == NO", predicates];
[request setPredicate:predicate];
[request setFetchBatchSize:20];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"checked" ascending:YES selector:@selector(compare:)];
NSSortDescriptor *sortDescriptor2
= [[NSSortDescriptor alloc] initWithKey:@"position" ascending:YES selector:@selector(compare:)];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, sortDescriptor2, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[sortDescriptor release];
[sortDescriptor2 release];
if (self=[[FastTableDelegate alloc]
initWithFetchRequest:request
managedObjectContext:[CoreDataHandler context]
sectionNameKeyPath:@"checked"
cacheName:nil])
{
self.delegate = self;
self.itemView = iv;
self.heightsCache = [NSMutableDictionary dictionary];
}
[request release];
[self performFetch:nil];
return self;
}


Then when the user tap UIButton in cell I change the "checked" property in NSmanagedObject (Item entity) and save the context. Then my NSFetchReslutsController is notified that one item changed it state and it performs UITableView reload using functions



- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {

UITableView *tableView = self.itemView.tableView;
switch(type) {

case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationNone];
break;

case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationNone];
break;

case NSFetchedResultsChangeUpdate:
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationNone];
break;

case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationNone];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationNone];
break;
}
}


Because I changed "checked" property which is sectionKey for my NSFetchedResultsController UITableView should be reloaded with this scenario



case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationNone];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationNone];
break;


And here is a problem because when cells are inserted or delated UITableView performs animation which duration is about 0.5s. In this time UITableView stop reciving events for next cell so when the user "check" another cell it will not be notified about that tap. What I'm trying to achive is to enable user to quick checking some cells without waiting for animation to end.



Possible solutions:




  1. Use reloadData istead of deleteRowsAtIndexPaths/insertRowsAtIndexPaths. It will be no animation but reloading all UITableView last longer that reloading one cell so in my case user will wait for UITableView to reload - again waiting. IS there a way to avoid animation without reloading all UITableView?


  2. Enable user to check cells, but save context only after 0.5s after last cell selection. User can select fast multiple cell and when he ends selecting all changes are propagated to UITableView - my boss want to send each selected cell to second section without grouping then, one reload for each cell selected - again bad idea


  3. Maybe some custom tableView (user created, not apple) ?




Primary goal:



Enable user to "check" cells quickly refreshing UITableView after each "checking"



I'm open for any ideals :)





How can I keep space, tab, CR and LF?

The string s include space, tab, CR and LF, alert(s) can render format correctly,
but $("#mydiv").text(s) lost CR and LF, I hope $("#mydiv").text(s) can render format correctly, how can I do ? Thanks!



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#Button1").bind("click", function () {
alert(s);
$("#mydiv").text(s);
});
});
</script>
</head>
<body>
<p>
<input id="Button1" type="button" value="button" /></p>
<div id="mydiv">
</div>
</body>
</html>




Apache Commons Email encode attach with base64

I'm trying to send a file base64-encoded via apache.commons.mail and I just can't seam to get the Content-Transfer-Encoding: base64 header where it's supposed to go.



// Create the email
MultiPartEmail email = new MultiPartEmail();
email.setSmtpPort(587);
email.setDebug(false);
email.setHostName("smtp.gmail.com");
email.setAuthentication("from@gmail.com", "password");
email.setTLS(true);

email.addTo("to@example.com");
email.setFrom("from@example.com");
email.setSubject("subject");

email.attach(new ByteArrayDataSource(
Base64.encodeBase64(attachFull.getBytes()), "text/plain"),
"samplefile.txt",
"sample file desc",
EmailAttachment.ATTACHMENT
);


And this is what gets to the recipient.



------=_Part_0_614021571.1334210788719
Content-Type: text/plain; charset=Cp1252; name=texto.txt
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename=samplefile.txt
Content-Description: sample file desc


How I can specify that the file is Base64 encoded?





Coffee script - preserve the class context and the event context

Looking for elegant solution to a common problem:
I got a class that subscribe to few events, I want the handler to be an instance method inside my class, but also want to get the event context(the element the event fired on for this case)
so I'm using the fat line syntax for the method definition but got no way to get the event context. To be concrete I'm using raphael js and when subscribing on element the event object does not contain the element, only the dom element so without the event context I'll have to search the element by it's raphael id inside the paper, and I don't like it.
What is the best practice in this case? I'm currently creating a new context object before each time I subscribe to the event, the context contains the instance reference and the element reference.





What does it mean when a Collection insert results in a 404?

I have a very simple test app in meteor, and I've created a collection like so:



var people = new Meteor.Collection("people");


When I try to do a simple insert, like this:



people.insert({name: "Benson"});


I get a 404 error with the text "Method not found". I admit there's a good chance I've fat-fingered something here, but I'd love to know both what's wrong, and why the error is so opaque (i.e. where it's coming from).





Configuring IIS Express to use default ports for http and https for debugging

I have followed scot's article on how to enable default ports (80 and 443) for http and https respectively. I have followed each step to the letter and in the end IIS express sytem tray shows me that site is running on following urls



enter image description here



Only thing i have done differently is to use netsh>advfirewall>firewall context because it was telling me that netsh firewall is deprecated. I used following command to allow port 80 through firewall



netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP localport=80 


Here is the relevant site section from applicationhost.config file of IIS Express



<site name="SSLTest" id="4">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="G:\Adeel\SSLTest\SSLTest" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:51518:localhost" />
<binding protocol="https" bindingInformation="*:44301:localhost" />
<binding protocol="http" bindingInformation="*:80:mhlabs" />
<binding protocol="https" bindingInformation="*:443:mhlabs" />
</bindings>
</site>




How to populate listview adapter from outside Activity in a TabActivity

I have the following problem.



I am in a tabActivity with 2 tabs. Every tab will launch the same activity, but there is a onTabChangeListener.
In this tabchange listener i need to set up the listview adapter that is different for each activity.
So i will have two different lists, and i want to change their adapter from TabActivity, from this onTabchangeListener, but i get the following error: system services not available to activities before oncreate()
The code for tabs is:



  host = getTabHost();

host.addTab(host.newTabSpec(TAG_AVAILABLE).setIndicator("First Tab")
.setContent(new Intent(this, MyActivity.class)));
host.addTab(host.newTabSpec(TAG_DOWNLOAD).setIndicator("Second Tab ")
.setContent(new Intent(this, MyActivity.class)));
host.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String s) {
MyActivity myActivity = new MyActivity();
int i = getTabHost().getCurrentTab();
if (i == FIRST_TAB) {
setAdapterForMyActivity(firstAdapter);
}
}
if (i == SECOND_TAB) {
setAdapterForMyActivity(secondAdapter);
}
}
}
});

}


The main question is how to set adapter of an listView which is in an Activity from TabActivity.
Thank you very much.





free() invalid pointer - freeing array of pointers fails

I have been debugging a piece of legacy code, running on an XScale (arm v5te) System with linux, that crashes reproducible.



I have debugged using gdb and set MALLOC_CHECK_ to 1. It's a lot of code, so just some snippets:



We have this structure:



typedef struct {
...clipped..
char **data_column_list;
/** data column count */
int data_column_cnt;
...clipped
} csv_t;


We initialize the columns in a function, putting them in a variable "columns"



/* Allocating memory for pointer to every register id */
columns = (char **) malloc(column_cnt * sizeof(char *));

column_cnt = 0;
/* loop over all sensors */
for(i=0; i<cfg.sen_cnt; i++) {
/* loop over all registers */
for(j=0; j<cfg.sen_list[i]->data_cnt; j++) {
/* Storing all the pointers to id */
columns[column_cnt++] = cfg.sen_list[i]->data_list[j]->id;
}
}


In another function, what happens is this:



/* free the previous list */
csv_free(lc_csv);

lc_csv->data_column_list = columns;
lc_csv->data_column_cnt = column_cnt;


csv_free being:



void csv_free(csv_t *csv) {
if(csv->data_column_cnt > 0)
free(csv->data_column_list);

csv->data_column_cnt = 0;
}


Now, there is another function, building the whole "cfg"/config structure, that contains these ids.
Code frome above: cfg.sen_list[i]->data_list[j]->id; where cfg is a struct, sen_list is an array of pointers to structs, data_list is an array of pointers to other structs, that contain a string "id".



Whe the program gets a signal SIGUSR1, the config is being updated. All of these data_list and sen_list structs are being freed, then new ones are generated.
Then with the first function, new collumns of ids are generated and put into the csv structure, but the old list is being freed before.



Thats where it crashes. In csv_free.



*** glibc detected *** /root/elv: free(): invalid pointer: 0x0001ae88 ***


I thought it should be like this. You have an array of pointers. When you free the pointers, you have to free the pointer, pointing to a set of pointers (the array).
Or put in code terms, the above situation should be analog to:



char **ar = malloc(n * sizeof(char *));
char *xn = malloc(10 * sizeof(char)); // Do for 0 to n strings
...
ar[n] = xn; // Do for 0 to n strings
...do stuff...
free(xn); // Do for 0 to n strings
free(ar);


When the structs, containing the id strings, are freed, I still have my pointer arrays with (invalid) pointers, not null pointers:



(gdb) p csv
$40 = {sysid = 222, ip = '' <repeats 49 times>,
module = "elv_v2", '' <repeats 14 times>, format_type = 1, msg_id = 0,
data_column_list = 0x1ae88, data_column_cnt = 10, pub_int = 30,
line_cnt = 0, pub_seq = -1, format = 0x18260}
(gdb) p csv.data_column_list[0]
$41 = 0x1b378 "0"


But I get the above error message (or SIGABRT without the MALLOC_CHECK_).
I don't understand this at all. I have to free this array of pointers, or it will become a memory leak. There is no other call of free before that, that I could find. I don't know why csv.data_column_list is considered an invalid pointer.
Valgrind is unfortunately not availiable on arm v5te :(



Have been debugging this for hours and hours and would be happy for any help.
Thank you very much,
Cheers,
Ben



UPDATE:



I'm wondering if it could be connected to some "scope" issue. There is almost identical code in another application, which works. The function which crashes, "csv_free" is used by both programs (statically linked). The only difference is, that the struct containing the pointer to be freed is declared and defined normally in the working program and declared as external and defined in another file than main.c
Calling "free" manually in main.c works, while calling "csv_free" crashes. Riddle me this...