What is the total number of comparisons necessary to locate all the n sorted distinct integers in an array using binary search, I think it is nlogn, but I am not sure. What do u guys think?
So I have two cell arrays:
A = {2 2 2 2}
B = {[1 2] [3 2] [5 5] [7 7]}
and a function of two arguments:
F = @(a, b) [a * b(1), (b(2) / 3), (b(1) + a) * 22]
And I want to apply the function to the two cell arrays like so:
idealfun(F, A, B)
and have it do the right thing (return a cell array with four cells of 1x3 vectors). Any ideas how to find/write idealfun?
use heap sort to sort this in descending order and show the steps or explanation please
below is the tree
79
33 57
8 25 48
below is the array
79 - 33 - 57 - 8 - 25 - 48
MSDN states the following SortedSet(T).Add Method :
If Count is less than the capacity of the internal array, this method is an O(1) operation.
Could someone please explain "how so"? I mean when adding new value we need to find a correct place to add a value (comparing it with another values) and internal implementation looks like a "Red-Black tree" with O (log N) insertion complexity.
B=l.append((l[i]+A+B))
l is a list here and i am trying to append into it more value for it to act as an array . But its still giving me error like list index out of range . How to get rid of it ?
Hi!
In my iPhone App In table view cell I want to dispaly one main title and 5 subtitlessubtitles
suppose item1 as main title and item2 , item3 , item4 , item5 and item6 as subtitles,
for that i have saperate two arrays for passing the values in table view cell
one for cell.textLabel.text=
second for cell.detailTextLabel.text
now I want the flexibility to make item2 as maintitle and want to add item1 to subtitle
How can I set title and subtitle programmatically from single array? and any of them as
Please Help and Suggest,
Thank You.
All examples I find on shuffling arrays are for NSMutableArrays. Copying an NSArray to an NSMutable array, shuffling, then copying back always crashes the application. Is it even possible to shuffle an NSArray?
Anything in objective-c similar to Collections.shuffle() (Java)?
i want to submit a form via ajax javascript to cakephp function.
cakephp function accepts $this-data, so i want to convert html form datas to cakephp function acceptable format i.e $this-data(array)...
how to do this in javascript(jquery)
I created image from byte array
System.Drawing.Image newImage;
using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
{
ms.Write(imageBytes, 0, imageBytes.Length);
newImage = System.Drawing.Image.FromStream(ms, true);
}
and now I need to have this image as a source for asp:Image (System.Web.UI.WebControls.Image). Is this possible as I know that conversion is impossible?
After toying with the jquery slideshow extension, I created my own that better suited my purposes ( I didn't like that all the images needed to load at the beginning for instance). Now, upon upgrading to jQuery 1.4.2 (I know I'm late), the slideshow loads the first image fine ( from the line$('div#slideshow img#ssone').fadeIn(1500); towards the bottom), but doesn't do anything beyond that. Does anyone have any idea which jquery construct is killing my script? The live page is at lplonline.org which is using 1.3.2 for the time being. Thanks in advance.
Array.prototype.random = function( r ) {
var i = 0, l = this.length;
if( !r ) { r = this.length; }
else if( r > 0 ) { r = r % l; }
else { i = r; r = l + r % l; }
return this[ Math.floor( r * Math.random() - i ) ];
};
jQuery(function($){
var imgArr = new Array();
imgArr[1] = "wp-content/uploads/rotator/Brbrshop4-hrmnywkshp72006.jpg";
imgArr[2] = "wp-content/uploads/rotator/IMGA0125.JPG";
//etc, etc, about 30 of these are created dynamically from a db
function randImgs () {
var randImg = imgArr.random();
var img1 = $('div#slideshow img#ssone');
var img2 = $('div#slideshow img#sstwo');
if(img1.is(':visible') ) {
img2.fadeIn(1500);
img1.fadeOut(1500,function() {
img1.attr({src : randImg});
});
} else {
img1.fadeIn(1500);
img2.fadeOut(1500,function() {
img2.attr({src : randImg});
});
}
}
setInterval(randImgs,9000); // 9 SECONDS
$('div#slideshow img#ssone').fadeIn(1500);
});
</script>
<div id="slideshow">
<img id="ssone" style="display:none;" src="wp-content/uploads/rotator/quote-investments.png" alt="" />
<img id="sstwo" style="display:none;" src="wp-content/uploads/rotator/quote-drugs.png" alt="" />
</div>
I am using an ajax call which is as follows
var ID=$(this).attr('id');
var input=$("#input_"+ID).val();
var dataString = {id: ID, value: input};
$("#span_"+ID).html(input);
if(input.length>0)
{
$.ajax({
type: "POST",
url: "/apps/worker_app.php",
data: dataString,
cache: false,
success: function(html)
{
$("#span_"+ID).html(span);
}
});
}
How can I get the data in my php function edit_ajax() which is inside worker_app
I use post but the array come to be empty
Thanks
I've found plenty of tutorials / questions on Stackoverflow that deal with copying char arrays from C/JNI side into something like a byte[] in Java, but not the other way around.
I am using a native C library which expects a byte array. I simply want to get data from a byte[] in java, into preferably an unsigned char[] in C.
Long story short: What is the best way of copying data from a jBytearray in JNI? Is there any way to detect it's size?
Hi, I have an NSArray of NSDictionary objects which I would like to be able to return a new array of NSDictionaries from, where every NSDictionary has "Area == North" (for example).
The closest example I have found so far is http://stackoverflow.com/questions/958622/using-nspredicate-to-filter-an-nsarray-based-on-nsdictionary-keys but this just returns the unique values for a given key, not the dictionary that has that key. Is there any way to perform a similar operation, and to return the entire dictionary?
I am getting dynamic image in form of byte array. and i want to show that in webpage, preferably ImageControl
I am aware of method of creating http handler and getting image stream. but I cant do that here as logic for same is performed somewhere else.
Could not get any suitable way to do this.
Thank you in advance.
I'm setting something up to SSH out to several servers in 'batches'. I basically want to maintain 5 connections at a time, and when one finishes open up another (following an array of server IPs).
I'm wondering for something like this should I be using fork()? If so, what logic can I use to ensure that the I maintain 5 children at a time?
I am learning how to write test cases using Rspec. I have a simple Post Comments Scaffold where a Post can have many Comments. I am testing this using Rspec. How should i go about checking for Post :has_many :comments. Should I stub Post.comments method and then check this with by returning a mock object of array of comment objects? Is testing for AR associations really required ?
In Java, is there a way (at runtime) to obtain the bytecode which defined a particular class?
Put another way, is there a way to obtain the byte[] array passed to ClassLoader.defineClass(String name, byte[] b, int off, int len) when a particular class was loaded? I see that this method is declared final, so creating a custom ClassLoader to intercept class definitions seems out of the question.
In the past, I have used the class's ClassLoader to obtain the bytecode via the getResourceAsStream(String) method, but I would prefer a more canonical solution.
I have a string:
[\n['-','some text what\rcontains\nnewlines'],\n\n
trying to parse:
Regex.Split(@"[\n['-','some text what contains newlines'],\n\n", @"\[\n\['(.*)','(.*)'],.*");
but the split return array seems to be null
i need to get part of text: "some text what contains newlines"
Hi guys,
I've been searching for tutorials to better understand this, but I'm having no luck. Please forgive the lengthy explination, but I want make sure I explain myself well.
First, I'm quite new to the MVC structure, though I have been doing tutorials and learning as best I can.
I have been moving over a live site into the Zend Framework model. So far, I have all the views within views/scripts/index/example.phtml.
So therefore I'm using one IndexController and I have the code in each Action method for each page: IE public function exampleAction()
Because I didn't know how to interact with a model, I put all the methods at the bottom of the controller (a fat controller).
So basically, I had a working site by using a View and Controller and no model.
...
Now I'm trying to learn how to incorporate the Model.
So I created a View at:
view/scripts/calendar/index.phtml
I created a new Controller at:
controller/CalendarControllers.php
and a new model at:
model/Calendar.php
The problem is I think I'm not correctly communication with the model (I'm still new to OOP).
Can you look over my controller and model and tell me if you see a problem.
I'm needing to return an array from runCalendarScript(), but I'm not sure if I can return an array into the object like I'm trying to? I don't really understand how to "run" the runCalendarScript() from the controller?
Thanks for any help! I'm stripping out most of the guts of the methods for the sake of brevity:
controller:
<?php
class CalendarController extends Zend_Controller_Action
{
public function indexAction()
{
$finishedFeedArray = new Application_Model_Calendar();
$this->view->googleArray = $finishedFeedArray;
}
}
model:
<?php
class Application_Model_Calendar
{
public function _runCalendarScript(){
$gcal = $this->_validateCalendarConnection();
$uncleanedFeedArray = $this->_getCalendarFeed($gcal);
$finishedFeedArray = $this->_cleanFeed($uncleanedFeedArray);
return $finishedFeedArray;
}
//Validate Google Calendar connection
public function _validateCalendarConnection()
{
...
return $gcal;
}
//extracts googles calendar object into the $feed object
public function _getCalendarFeed($gcal)
{
...
return $feed;
}
//cleans the feed to just text, etc
protected function _cleanFeed($uncleanedFeedArray)
{
$contentText = $this->_cleanupText($event);
$eventData = $this->_filterEventDetails($contentText);
return $cleanedArray;
}
//Cleans up all formatting of text from Calendar feed
public function _cleanupText($event)
{
...
return $contentText;
}
//filterEventDetails
protected function _filterEventDetails($contentText)
{
...
return $data;
}
}
I've googled for creation of namespaces and found some very useful examples, what these examples didn't have is how do I compile and implement my created namespace on my system so I can include it from my various applications.
So for example, if I create a namespace to load a config file from my application path and insert it to an array, Do i need to include the namespace on any project I use or is there a way to make it part of my environment?