الثلاثاء، 31 ديسمبر 2013

Android: Searchview searches only whole words

Search is based on starting characters, but i would like that will search everything. Here is part of my code, method onTextChanged isn't right, I think.. Thanks for help!

@Overridepublic void onCreate(Bundle savedInstanceState) { final ArrayList seznamPojmov = (ArrayList) SeznamPojmovRazlag(0); final ArrayList array_sort= new ArrayList(); super.onCreate(savedInstanceState); setContentView(R.layout.activity_slovar); final ListView list = (ListView) findViewById(R.id.slovar); final EditText iskanje = (EditText) findViewById(R.id.iskanje); final ArrayAdapter a = new ArrayAdapter (Slovar.this, android.R.layout.simple_list_item_1, array_sort)); } });

View the original article here

Jquery datepicker format date not working

Thats the default, meaning it does not recognise your option.

try:

dateFormat: 'dd-mm-yy'

(small letters)


View the original article here

السبت، 28 ديسمبر 2013

How can I use CSS transitions to animate a responsive layout's vertical orientation?

I am trying to figure out a way to smoothly animate a responsive change to some elements' display property when the browser size reaches a certain breakpoint. I would like to use CSS transitions, but they do not apply to the display property so I may have to figure out a workaround. To be clear, I am only having trouble animating changes to the vertical orientation of elements that were previously arranged horizontally. Other, simple, responsive animations have been set up without issue.

Here is a simple example

In that example, I have set up effective transitions for the div dimensions that activate at given breakpoints. The final (smallest window) transition causes the divs to line up vertically. At first, this was achieved by simply changing the divs from display:inline-block; to display:block;. However, this could not be animated using CSS transitions, so I tried an alternative method. The alternative involved changing the divs from position:relative; to position:absolute; and adjusting their top properties. I thought CSS transitions would be able to effectively animate the change in top but that does not seem to happen.

Does anyone have any suggestions?


View the original article here

الجمعة، 27 ديسمبر 2013

AVAssetWriterInputPixelBufferAdaptor appendPixelBuffer:buffer withPresentationTime returning error NSURLErrorCannotCreateFile

I am creating a video file from an array of images. I am able to create video file on simulator, however when I try to run the same code on device it gives following error:

NSURLErrorDomain Code=-3000 "Cannot create file" UserInfo=0x200be260 {NSUnderlyingError=0x200bb030 "The operation couldn’t be completed. (OSStatus error -12149.)", NSLocalizedDescription=Cannot create file}

I have searched a lot but couldn't find anything.

Here is the code for creating path.

NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/movie.mp4"]];-(void)exportImages:(NSArray *)imageArray asVideoToPath:(NSString *)path withFrameSize:(CGSize)imageSize framesPerSecond:(NSUInteger)fps {NSLog(@"Start building video from defined frames.");NSError *error = nil;NSURL *url = [NSURL fileURLWithPath:path];AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL: url fileType:AVFileTypeMPEG4 error:&error];NSParameterAssert(videoWriter);NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: AVVideoCodecH264, AVVideoCodecKey, [NSNumber numberWithInt:imageSize.width], AVVideoWidthKey, [NSNumber numberWithInt:imageSize.height], AVVideoHeightKey, nil];AVAssetWriterInput* videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings];AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:videoWriterInput sourcePixelBufferAttributes:nil];NSParameterAssert(videoWriterInput);NSParameterAssert([videoWriter canAddInput:videoWriterInput]);videoWriterInput.expectsMediaDataInRealTime = YES;[videoWriter addInput:videoWriterInput];//Start a session:[videoWriter startWriting];[videoWriter startSessionAtSourceTime:kCMTimeZero];CVPixelBufferRef buffer = NULL;//convert uiimage to CGImage.int frameCount = 0;for(UIImage * img in imageArray) { buffer = [self pixelBufferFromCGImage:[img CGImage] andSize:imageSize]; while (1) { if (adaptor.assetWriterInput.readyForMoreMediaData) { break; } } BOOL append_ok = NO; int j = 0; while (!append_ok && j < 30) { NSString *border = @"**************************************************"; NSLog(@"\n%@\nProcessing video frame (%d,%d).\n%@",border,frameCount,[imageArray count],border); CMTime frameTime = CMTimeMake(frameCount,(int32_t) fps); append_ok = [adaptor appendPixelBuffer:buffer withPresentationTime:frameTime]; if(!append_ok){ NSError *error = videoWriter.error; if(error!=nil) { NSLog(@"Unresolved error %@,%@.", error, [error userInfo]); } } j++; } if (!append_ok) { printf("error appending image %d times %d\n, with error.", frameCount, j); } frameCount++;}//Finish the session:[videoWriterInput markAsFinished];[videoWriter finishWritingWithCompletionHandler:^{ NSLog(@"Write Ended");}];

}


View the original article here

How can I get a single random number from multiple possible ranges?

Would you choose a random Range and then use Random.Next() on that?

No, because that would give numbers in shorter ranges more weight. For example, if one range contains a single number 42 and the other range contains 10,000 numbers, then 42 would be generated roughly 50% of the time.

Or would you keep choosing random numbers until you got one that was within each of the ranges?

No, because that would not be the too efficient. For example, if the first range is [1..3] and the second range is [200,000..200,001], getting a number in one of these ranges would take a while.

I would implement a Size property on the range, compute the total size, generate an int in the range index = [0..TotalSize-1], and then picked the item at the index as if all numbers in your ranges were numbered sequentially.

For example, in your ranges TotalSize would be 6+7+12=25. First, I would generate a random number in the range [0..24], say, 15. I would then see that 15 falls in the third range, so I'd return 21.

This would give each range a weight proportional to its size. If you would like to assign specific weights to your ranges, the algorithm would be different: you would compute an equivalent of TotalRange by multiplying the actual size by the weight of the range, and totaling up the products. You would then generate a number in the range of that weighted sum, pick the range by working backward from that random number, and then dividing out the weight of the specific range to obtain the position of the random item in the range.


View the original article here

Most efficient and standard-compliant way of reinterpreting int as float

Assume I have guarantees that float is IEEE 754 binary32. Given a bit pattern that corresponds to a valid float, stored in std::uint32_t, how does one reinterpret it as a float in a most efficient standard compliant way?

float reinterpret_as_float(std::uint32_t ui) { return /* apply sorcery to ui */;}

I've got a few ways that I know/suspect/assume have some issues:

Via reinterpret_cast,

float reinterpret_as_float(std::uint32_t ui) { return reinterpret_cast(ui);}

or equvalently

float reinterpret_as_float(std::uint32_t ui) { return *reinterpret_cast(&ui);}

which suffers from aliasing issues.

Via union,

float reinterpret_as_float(std::uint32_t ui) { union { std::uint32_t ui; float f; } u = {ui}; return u.f;}

which is not actually legal, as it is only allowed to read from most recently written to member. Yet, it seems some compilers (gcc) allow this.

Via std::memcpy,

float reinterpret_as_float(std::uint32_t ui) { float f; std::memcpy(&f, &ui, 4); return f;}

which AFAIK is legal, but a function call to copy single word seems wasteful, though it might get optimized away.

Via reinterpret_casting to char* and copying,

float reinterpret_as_float(std::uint32_t ui) { char* uip = reinterpret_cast(&ui); float f; char* fp = reinterpret_cast(&f); for (int i = 0; i < 4; ++i) { fp[i] = uip[i]; } return f;}

which AFAIK is also legal, as char pointers are exempt from aliasing issues and manual byte copying loop saves a possible function call. The loop will most definitely be unrolled, yet 4 possibly separate one-byte loads/stores are worrisome, I have no idea whether this is optimizable to single four byte load/store.

The 4 is the best I've been able to come up with.

Am I correct so far? Is there a better way to do this, particulary one that will guarantee single load/store?


View the original article here

Grid view row command showing error

I am getting this error:

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

This is my code:

protected void GridViewCommandEventHandler(object sender, GridViewCommandEventArgs e){ if (e.CommandName == "view") { int row_id = Convert.ToInt32(e.CommandArgument); var result = (from test in je.jobposting where test.id==row_id select test).FirstOrDefault(); Session["id"] = result; } else { int row_id = Convert.ToInt32(e.CommandArgument); var result = (from test in je.jobposting where test.id==row_id select test).FirstOrDefault(); je.DeleteObject(result); je.SaveChanges(); Response.Redirect (""); }}

View the original article here