{"QuestionId": 27385501, "AnswerCount": 1, "Tags": "", "CreationDate": "2014-12-09T17:51:33.053", "AcceptedAnswerId": null, "Title": "Display form fields if radio button is selected on page load or on click", "Body": "

I am trying to get specific form fields to show if a particular radio button is selected on page load OR if it is clicked on. I've been messing with this for a few hours and this is the closest that I have gotten. Right now it's running the entire showForm function no matter what. I switched out input[type='radio'] with $(this) but $(this) means nothing so that obviously didn't work (here's the JS fiddle for that. The form works with it on click but not the displaying of the form on page load). I also took all of this out of the showForm function and tried to trigger.click()like this

\n\n
if ($(\"input[type='radio']\").is(':checked')){\n    $(this).trigger('click');       \n}\n
\n\n

but that didn't work either.

\n\n

Here's the JS:

\n\n
$(document).ready(function() {\n$(\".currentForm, .address, .trust, .individual\").hide();\n\nif ($(\"input[type='radio']\").is(':checked')){\n    showForm();     \n}\n\n $(\"input[type='radio']\").click(showForm);    \n\nfunction showForm(){    \n    if($(\"input[type='radio']\").attr('name') == 'enterAddress' && $(this).attr('value') == 'true') {\n        $('.address').slideDown( \"slow\", function() {});                   \n    }       \n    else{\n        $('.address').slideUp( \"slow\", function() {});  \n    }\n\n    //Individual\n    if($(\"input[type='radio']\").attr('id') == 'nameType1') {\n        $('.currentForm, .address, .trust, .business').hide();  \n        $('.individual, .currentForm').slideDown( \"slow\", function() {});  \n        $('#enterAddress1').attr('checked', false);\n        $('#enterAddress2').attr('checked', true);                \n    } \n    //Trust\n    else if($(\"input[type='radio']\").attr('id') == 'nameType2'){\n        $('.currentForm, .address, .individual, .business').hide();\n        $('.trust, .currentForm').slideDown( \"slow\", function() {});\n        $('#enterAddress1').attr('checked', false);\n        $('#enterAddress2').attr('checked', true);\n    }\n    //Business\n    else if($(\"input[type='radio']\").attr('id') == 'nameType3'){\n        $('.currentForm, .address, .individual, .trust').hide();\n        $('.business, .currentForm').slideDown( \"slow\", function() {});\n        $('#enterAddress1').attr('checked', false);\n        $('#enterAddress2').attr('checked', true);\n    }\n}// end showForm                \n});\n
\n\n

Here is the current jsFiddle

\n", "Lable": "No"} {"QuestionId": 27393472, "AnswerCount": 1, "Tags": "", "CreationDate": "2014-12-10T04:41:22.753", "AcceptedAnswerId": null, "Title": "UIAlertView ios8 only showing a line for keyboard", "Body": "

Problem:

\n\n

UIAlertView in iOS8 only showing a line for keyboard

\n\n

Here is my Code:

\n\n
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{\n\n    UITextField *txtName = nil;\n\n    if(buttonIndex == 1){ // save project name\n        txtName = (UITextField *)[alertView textFieldAtIndex:0];\n\n        if(txtName && txtName.text && [txtName.text length] > 0 && ![txtName.text isEqualToString:@\" \"]) {\n\n            //SPAppDelegate *appdelegate = (SPAppDelegate*)[[UIApplication sharedApplication] delegate];\n            NSString *filePath = nil;\n\n            //if(![appdelegate isProjectNameAlreadyExist:txtName.text]){\n            if(![SPUtility isProjectNameAlreadyExist:txtName.text]){\n                //filePath = [appdelegate getProjectPathWthName:txtName.text];\n                filePath = [SPUtility getProjectPathWthName:txtName.text];\n                [self loadProjectList];\n            }\n            else{\n                [[[UIAlertView alloc] initWithTitle:@\"Error\" message:@\"Project name already exists.\" delegate:nil cancelButtonTitle:@\"OK\" otherButtonTitles:nil] show];\n            }\n        }\n        else{\n            [[[UIAlertView alloc] initWithTitle:@\"Error\" message:@\"Project name is empty.\" delegate:nil cancelButtonTitle:@\"OK\" otherButtonTitles:nil] show];\n        }\n    }\n}\n
\n\n

The problem must be happening somewhere here***

\n\n
-(void) launchProjectNameInputAlert{\n\n    /*_alertView = nil;\n\n    _alertView = [[UIAlertView alloc] initWithTitle:@\"test\" message:@\"test1\" delegate:nil cancelButtonTitle:@\"OK\" otherButtonTitles:nil];\n\n    [_alertView show];*/\n\n    _isShowAlert = YES; //boolean variable\n\n    //_alertView =[[UIAlertView alloc] initWithTitle:@\"ADD item\" message:@\"Put it blank textfield will cover this\" delegate:self cancelButtonTitle:@\"Cancel\" otherButtonTitles:@\"OK\", nil];\n    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@\" \" message:@\" \" delegate:self cancelButtonTitle:@\"Cancel\" otherButtonTitles:@\"OK\", nil];\n\n    alertView.alertViewStyle = UIAlertViewStylePlainTextInput;\n\n    UITextField *txtName = [alertView textFieldAtIndex:0];\n    txtName.text=@\"\";\n    //txtName.tag = 1000;\n    //[txtName setBackgroundColor:[UIColor blackColor]];\n    [txtName setKeyboardAppearance:UIKeyboardAppearanceAlert];\n    [txtName setAutocorrectionType:UITextAutocorrectionTypeNo];\n    [txtName setTextAlignment:NSTextAlignmentLeft];\n    txtName.placeholder = @\"Project Name\";\n    [alertView addSubview:txtName];\n    [alertView show];\n\n}\n
\n\n

Can someone please check it out?

\n\n

Here is a link of the Image for reference.

\n", "Lable": "No"} {"QuestionId": 27622732, "AnswerCount": 1, "Tags": "", "CreationDate": "2014-12-23T14:52:44.033", "AcceptedAnswerId": null, "Title": "malloc.c:3096: sYSMALLOc: Assertion Error using pointers", "Body": "

I'm getting

\n\n
     malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1)                        * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (   old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.\n     Aborted\n
\n\n

Error, I ran valgrind and received

\n\n
    ==8595==\n    ==8595== HEAP SUMMARY:\n    ==8595==     in use at exit: 0 bytes in 0 blocks\n    ==8595==   total heap usage: 49 allocs, 49 frees, 7,204 bytes allocated\n    ==8595==\n    ==8595== All heap blocks were freed -- no leaks are possible\n    ==8595==\n    ==8595== For counts of detected and suppressed errors, rerun with: -v\n    ==8595== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 25 from 6)\n
\n\n

which left me confused. The code I believe is causing the problem is:

\n\n
    int asn1_encoder(char *bufff[]){\n\n    char av[20];\n\n\n    char boibuff[] = {0x01, 0x00, 0x00, 0x01};\n\n    char propbuff[] = {0x01};\n     \\\\BACnetConfirmedServiceChoice and BACnetConfirmedServiceRequest types have been ommitted\n    long int arb = 0;\n    long int arb1 = 0;\n    BACnet_Confirmed_Request_PDU_t *bacnetConfirmedPDU;\n    int i = 0;\n    BACnet_Confirmed_Service_Request_t *service_request;\n    BACnetConfirmedServiceChoice_t *service_choice;\n    WriteProperty_Request_t *writeProperty;\n    BACnetObjectIdentifier_t *objectIdentifier;\n    BACnetPropertyIdentifier_t *propertyIdentifier;\n    asn_enc_rval_t ec;\n\n    sprintf(av,\"test.bin\");\n\n\n\n\n\n      bacnetConfirmedPDU = calloc(1, sizeof(BACnet_Confirmed_Request_PDU_t)); //PDU-TYPE deff\n\n      bacnetConfirmedPDU -> service_request  = calloc(1,             sizeof(BACnet_Confirmed_Service_Request_t));\n\n            objectIdentifier = calloc(1, sizeof(BACnetObjectIdentifier_t));\n      service_choice = calloc(1, sizeof(BACnetConfirmedServiceChoice_t)); //Select Service deff\n\n      writeProperty = calloc(1, sizeof(WriteProperty_Request_t)); //Encoded service deff\n\n       bacnetConfirmedPDU -> service_request -> choice.writeProperty.objectIdentifier.buf = calloc(1, sizeof(BACnetObjectIdentifier_t));\n\n      propertyIdentifier = calloc(1, sizeof(BACnetPropertyIdentifier_t));\n\n\n            if(!bacnetConfirmedPDU){\n                    perror(\"calloc() failed\");\n                    exit(1);\n            }\n\n            bacnetConfirmedPDU -> pdu_type = 1;\n\n            bacnetConfirmedPDU -> service_choice  = BACnetConfirmedServiceChoice_writeProperty;\n            printf(\"the value in service_choice struct is %d\\n\", bacnetConfirmedPDU->service_choice);\n\n\n            bacnetConfirmedPDU -> service_request -> present = BACnet_Confirmed_Service_Request_PR_writeProperty;\n            bacnetConfirmedPDU -> service_request -> choice.writeProperty.objectIdentifier.buf = boibuff; // BACnetObjectType_binary_output;  //boibuff;\n\n\n            bacnetConfirmedPDU -> service_request -> choice.writeProperty.objectIdentifier.size = 4;\n            printf(\"boi is %02x\\n\",bacnetConfirmedPDU -> service_request ->choice.writeProperty.objectIdentifier.buf[1]);\n\n            bacnetConfirmedPDU -> service_request -> choice.writeProperty.propertyIdentifier = BACnetPropertyIdentifier_present_value;\n\n            printf(\"property ident = %d\\n\", bacnetConfirmedPDU -> service_request -> choice.writeProperty.propertyIdentifier);\n            //bacnetConfirmedPDU -> service_request -> choice.writeProperty.propertyArrayIndex = arb1;\n            //printf(\"the value in proper array is %lu\\n\",bacnetConfirmedPDU -> service_request -> choice.writeProperty.propertyArrayIndex);\n            printf(\"sef fault before propbuff\\n\");\n            bacnetConfirmedPDU -> service_request -> choice.writeProperty.propertyValue.buf =  propbuff;\n\n            bacnetConfirmedPDU -> service_request -> choice.writeProperty.propertyValue.size = sizeof(propbuff);\n\n\n\n            //define port\n\n\n            FILE *fp = fopen(av, \"wb+\");\n            if(fp == NULL){\n            printf(\"fp is null\\n\");\n            }\n\n            if(!fp){\n            perror(av);\n            exit(1);\n            }\n\n            ec = der_encode(&asn_DEF_BACnet_Confirmed_Request_PDU, bacnetConfirmedPDU, write_out, fp);\n\n            if(fp == NULL)\n            {\n            printf(\"fp null\\n\");\n            }\n\n             if(!fp){\n            perror(av);\n            exit(1);\n            }\n\n            ec = der_encode(&asn_DEF_BACnet_Confirmed_Request_PDU, bacnetConfirmedPDU, write_out, fp);\n\n            if(fp == NULL)\n            {\n            printf(\"fp null\\n\");\n\n            }\n\n            printf(\"the file is closed\\n\");\n            int end = fseek(fp, 0, SEEK_END);\n            end = ftell(fp);\n            fseek(fp, 0, SEEK_SET);\n            printf(\"fseek is happening\\n\");\n            //int end = ftell(fp);\n             if(fp == NULL)\n            {\n            printf(\"*******************bufff is null***************************\\n\");\n            }\n\n            printf(\"end equals %d\\n\", end);\n            //printf(\"just before fgetc\\n\");\n            //for(i = 0; i<= 35 ; i++)\n         for(i = 0; i <  end; i++)\n         {\n\n            if(feof(fp)){\n            printf(\"we're a broken family\\n\");\n            break;\n            }\n            if(i> maxlen){\n            printf(\" buff is full\\n\");\n            break;\n            }\n             }\n\n            }\n\n            fclose(fp);\n            if(ec.encoded == -1){\n                    fprintf(stderr, \"could not encode ConfirmedRequest_PDU at (%s)\\n\",\n                    ec.failed_type ? ec.failed_type -> name : \"unknown\");\n                            exit(1);\n            }else{\n                    fprintf(stderr, \"Created %s with BER encoded ConfirmedRequestPDU\\n\", av);\n                    }\n\n            xer_fprint(stdout, &asn_DEF_BACnet_Confirmed_Request_PDU, bacnetConfirmedPDU);\n\n            free(bacnetConfirmedPDU);\n            free(bacnetConfirmedPDU -> service_request);\n            return i;\n            }\n
\n\n

I cant identify where the issue is caused, I have tried freeing all the variables that I calloc-ed. however, all those sturctures are members of bacnetConfirmedPDU, so, by this, shouldn't freeing just bacnetConfirmedPDU be enough? also, the line:

\n\n
               free((bacnetConfirmedPDU -> service_request);\n
\n\n

is a little worry-sum as it could be a double free? My question is, what other options are there for checking for memory leaks and bound violations other than valgrind? also, is there anything glaringly obvious that could cause an assertion error? Any suggestions are greatly appreciated, also, if anyone does have error detection suggestions, an example would also be greatly appreciated. Thanks

\n", "Lable": "No"} {"QuestionId": 27639522, "AnswerCount": 2, "Tags": "<.net>", "CreationDate": "2014-12-24T16:08:48.297", "AcceptedAnswerId": null, "Title": "DotNetOpenAuth OAuth2 Accessing Extra Data", "Body": "

I'm using DotNetOpenAuth's OAuth2 library to handle authorization with another third party system. It all works great, except that the third party system is returning the UserId=\"testname\" in the Response with the AccessToken.

\n\n

I need that UserId because this third party API requires it as part of their API calls (ex: users/{userId}/account).

\n\n

Using DotNetOpenAuth, I don't have access to the AccessToken response so I can't get the UserId out.

\n\n

I'm calling: (_client is a WebServerClient)\nvar state = _client.ProcessUserAuthorization(request);

\n\n

state has my AccessToken, but not the extra data sent down. Based on the DotNetOpenAuth source code the UserId came in inside the library and I don't have any access.

\n\n

Is there anyway to get that UserId out using DotNetOpenAuth? Or do I need to abandon DotNetOpenAuth and try something else?

\n", "Lable": "No"} {"QuestionId": 27643654, "AnswerCount": 2, "Tags": "", "CreationDate": "2014-12-25T01:55:29.890", "AcceptedAnswerId": "27643666", "Title": "best way to make an ajax call to a PHP script, and have the reponse data opened in a new window.", "Body": "

I am trying to implement a feature in my webapp to let user click a button and see a \"status report\" of something. The status report is quite large hence I want to have it on a separate page. I am trying to think of a way to make an Ajax call to a PHP script and have the response data displayed nicely on another window. Is there a way to do that? I am new to web dev and any help would be appreciated. Thanks

\n", "Lable": "No"} {"QuestionId": 27881802, "AnswerCount": 1, "Tags": "", "CreationDate": "2015-01-10T22:16:49.323", "AcceptedAnswerId": null, "Title": "generate html in axure. adaptive views without js", "Body": "

I created a simple page with Axure in 2 versions (basically 2 adaptive views: base and 768 and below). When I generate the html, it works fine and follows the adaptive views. But this seems to work only with javascript, is there a way to deal with/generate the adaptive views in css? This could help me later on integrating the Axure generated html and css into my responsive design based on bootstrap. Thank you.

\n", "Lable": "No"} {"QuestionId": 27890274, "AnswerCount": 1, "Tags": "", "CreationDate": "2015-01-11T18:00:00.217", "AcceptedAnswerId": "27890384", "Title": "Js: create html element that inherits from some js class", "Body": "

I have js class (if js supports classes is offtopic for this question):

\n\n
var MyClass=function(){\n....\n}\n\nMyClass.prototype.someMethod=function(){\n...\n}\n
\n\n

I want to create html element (for example div) that will inherit MyClass. For example for custom elements I could use the following:

\n\n
  var SimpleTableClass = document.registerElement('simple-table',{prototype: new MyClass()});\n  simpleTable=new SimpleTableClass();\n
\n\n

The only idea I have is:

\n\n
var newDiv = document.createElement(\"div\");\nnewDiv.prototype=new MyClass();\n
\n\n

But I don't know if it's safe method, because I will override all html element prototype.

\n\n

If it's possible I'd like to get not only html element but and its constructor (class) as in example with SimpleTableClass.

\n", "Lable": "No"} {"QuestionId": 27905269, "AnswerCount": 4, "Tags": "", "CreationDate": "2015-01-12T15:21:25.367", "AcceptedAnswerId": "27919680", "Title": "Pandas rolling sum, variating length", "Body": "

I will try and explain the problem I am currently having concerning cumulative sums on DataFrames in Python, and hopefully you'll grasp it!

\n\n

Given a pandas DataFrame df with a column returns as such:

\n\n
              returns\nDate                                                          \n2014-12-10    0.0000\n2014-12-11    0.0200\n2014-12-12    0.0500\n2014-12-15    -0.0200\n2014-12-16    0.0000\n
\n\n

Applying a cumulative sum on this DataFrame is easy, just using e.g. df.cumsum(). But is it possible to apply a cumulative sum every X days (or data points) say, yielding only the cumulative sum of the last Y days (data points).

\n\n

Clarification: Given daily data as above, how do I get the accumulated sum of the last Y days, re-evaluated (from zero) every X days?

\n\n

Hope its clear enough,

\n\n

Thanks,\nN

\n", "Lable": "No"} {"QuestionId": 28009257, "AnswerCount": 0, "Tags": "", "CreationDate": "2015-01-18T11:38:02.113", "AcceptedAnswerId": null, "Title": "Ninject dependency injection in SignalR custom authorize attribute", "Body": "

I have an ASP.NET MVC5 application with SignalR and Ninject for dependency injection.\nI have a custom authorize attribute for both the web request and the signalr hub request.

\n\n

I made the following class for the web:

\n\n
public class MyWebAuthorizeAttribute : AuthorizeAttribute // (System.Web.Mvc.AuthorizeAttribute)\n{\n    [Inject]\n    public IMyService MyService { get; set; } \n\n    protected override bool AuthorizeCore(HttpContextBase httpContext)\n    {\n        var id = int.Parse((httpContext.Handler as MvcHandler).RequestContext.RouteData.Values[\"id\"].ToString());\n        if (!MyService.Exists(id)) \n            return false;\n        return base.AuthorizeCore(httpContext);\n    }\n}\n
\n\n

And the following for SignalR:

\n\n
public class MySignalRAuthorizeAttribute : AuthorizeAttribute // (Microsoft.AspNet.SignalR.AuthorizeAttribute)\n{\n    [Inject]\n    public IMyService MyService { get; set; } \n\n    public override bool AuthorizeHubConnection(HubDescriptor hubDescriptor, IRequest request)\n    {\n        var id = int.Parse(request.QueryString[\"id\"]);\n        if (!MyService.Exists(id))\n            return false;\n        return base.AuthorizeHubConnection(hubDescriptor, request);\n    }\n}\n
\n\n

Ninject bindings in the Startup class:

\n\n
var kernel = new StandardKernel();\nvar resolver = new NinjectSignalRDependencyResolver(kernel);\nkernel.Bind<IMyService>().To<MyService>().InSingletonScope();\nvar config = new HubConfiguration();\nconfig.Resolver = resolver;\napp.MapSignalR(config);\n
\n\n

The problem is that the service is not being injected in MySignalRAuthorizeAttribute, though in MyWebAuthorizeAttribute the service is properly being injected.

\n\n

Any idea what I am missing to get this working?

\n\n

Edit:\nFound a way to get it more or less working.

\n\n

In the startup class I had to add this:

\n\n
GlobalHost.DependencyResolver = resolver;\n
\n\n

And then in MySignalRAuthorizeAttribute I could get the service like this:

\n\n
MyService = GlobalHost.DependencyResolver.Resolve<IMyService>();\n
\n\n

This works but I'd still prefer to simply get the service injected with the [Inject] attribute.

\n", "Lable": "No"} {"QuestionId": 28056273, "AnswerCount": 2, "Tags": "", "CreationDate": "2015-01-20T22:26:16.593", "AcceptedAnswerId": "28056642", "Title": "shell programming - counting words from multiple files", "Body": "

Need some help in shell programming.

\n\n

I need to write a shell script which accepts multiple text file as arguments and count the word occurrences from all of them.

\n\n

For Eg file1.txt contains text

\n\n
mary had a little lamb. His fleece was white as a snow. And everywhere that mary went.\n
\n\n

and file2.txt contains

\n\n
Mary had a little lamb. Hello How are you\n
\n\n

So the script should give the output like

\n\n
Mary 2\nHad 2\na  2\nwhite 1\n.\n.\n.\n
\n\n

Thanks in advance

\n", "Lable": "No"} {"QuestionId": 28121290, "AnswerCount": 1, "Tags": "", "CreationDate": "2015-01-24T01:21:14.627", "AcceptedAnswerId": null, "Title": "Is this behavior (apparently an out of thin air store) forbidden by C11?", "Body": "

Is the behavior mentioned the LWN article \u201cBetrayed by a bitfield\u201d forbidden by C11? Assume that spinlock_t is a type referring to a struct which is accessed only through means of C11 atomic primitives on its members (Actually it uses Linux (the kernel) memory barriers, but assume it doesn't so that it isn't undefined because of using an implementation-specific interface). In addition to the question in the title, is it an example of an \u201cout of thin air store\u201d?.

\n\n

Thanks in advance.

\n", "Lable": "No"}