Is XCode's auto-complete code misleading programmers? [closed] - xcode

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
When I type "dispatch_after" in XCode, it auto-completes GCD code as below:
int64_t delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
<#code to be executed on the main queue after delay#>
});
let's look this statement :
int64_t delayInSeconds = 2.0;
int64_t is the synonyms of "long long",but here we assign a double value "2.0" to this kind of variable delayInSeconds.So the fractional part of the value will be discarded.If you assign it with value "0.3",the variable's value will be 0. I think this template of code will mislead programmers and the right code should be float delayInSeconds = 2.0;Am I right? thanks in advance.

Related

How to show more than 1 Stats panel in Three.js, side by side [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Only if it's possible; for example one panel for FPS and another one for MS
Thanks, best regards
Yes, you can have multiple:
var stats1 = new Stats();
stats1.showPanel(0); // Panel 0 = fps
stats1.domElement.style.cssText = 'position:absolute;top:0px;left:0px;';
document.body.appendChild(stats1.domElement);
var stats2 = new Stats();
stats2.showPanel(1); // Panel 1 = ms
stats2.domElement.style.cssText = 'position:absolute;top:0px;left:80px;';
document.body.appendChild(stats2.domElement);
And then in your main loop
stats1.update();
stats2.update();
stats.js r17

Transferring some parts of image [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to transfer some part of my image to another matrix with this code:
p1 = zeros(512,512,3);
p1(1:128, 1:128, 1:3) = image(1:128, 129:256, 1:3);
And when this code did not work I tried with 3 for loop
and after that I tried to transfer R G B layers separately:
p1(1:128, 1:128, 1) = image(1:128, 129:256, 1);
But none of these codes work. Could anyone tell me what to do?
In Matlab you can always assign one matrix to another with the same size. For example:
A = ones (4,2,3,4,5);
B = zeros(4,2,3,4,5);
A = B
will run with no errors.
It is possible that the type of the image you are using is uint8 (8-bit unsigned integer), while zeros creates a double matrix. This will result in improper behavior of operations or built-in functions, if you do not cast (change the type of) your matrices properly. Use whos to check the type of your image:
whos image
Try to cast the zeros to uint8:
p1 = uint8(zeros(512,512,3));
...
Here is an example:
image = imread('peppers.png');
partail_im = uint8(zeros(size(image)));
partail_im(1:128,1:128,:) = image(1:128,129:256,:);
imshow(partail_im);
Note: It's better not to use image as the name of any variable since it's name of a built-in function image.

Color of the cars [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Could you give me a hint on how to solve this problem?
How can I find out whether most cars have the same color if the only function I can use is to check whether two cars have the same color?
With equality, you can first build equivalence classes and then count the largest one.
You can create a "list" where the color of the car is the key value and it counts how many cars of that color you have and stores a car of that color.
It goes something like this:
you will have a struct of with this fields:
struct color
car *car_with_color = NULL
int count = 0
so you go to the first car store it's color and add 1:
color[1].car_with_color=&cars[1];
color[1].count=1;
then for the next car you do:
if (cars[2].color == color[1].car_with_color->color)
color[1].count++;
else
color[2].car_with_color=&cars[2];
color[2].count=1;
and so on:
for (i=1;i<=NUM_OF_CARS;i++){
j=1;
while (color[j].car_with_color != NULL){
if (cars[i].color == color[j].car_with_color->color){
color[i].count++;
break;
}else
j++;
}
if (color[j].car_with_color == NULL){
color[j].car_with_color=&cars[i];
color[j].count=1;
}
}
it's written in a C like pseudo-code.

Feature request for a text-editor with support for literate programming [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 12 years ago.
Improve this question
This is a feature request for the writers of Visual Studio and any other programmer's editor.
Consider a literate program as follows:
/* File Name: LiterateProgram.h */ // \begin{comment}
#pragma once
#include "myHeader.h"
/* \end{comment}
%\bigskip
\begin{lstlisting} %
*/
class CSomeClass : public CSomeBase {
public:
float someFunction(float some paramter);
};
// \end{lstlisting} \begin{comment}
/* \end{comment} %*/
I'd like an editor window with two small icons representing (COLLAPSE_CODE) and (COLLAPSE_COMMENTS) in the bottom right corner. If COLLAPSE_COMMENT, then the view of the file would look like:
+
#pragma once
#include "myHeader.h"
+
class CSomeClass : public CSomeBase {
public:
float someFunction(float some paramter);
};
+
If COLLAPSE_CODE, then the view of the file would look like:
/* File Name: LiterateProgram.h */ // \begin{comment}
+
/* \end{comment}
%\bigskip
\begin{lstlisting} %
*/
+
// \end{lstlisting} \begin{comment}
+
/* \end{comment} %*/
Bonus points for displaying a side-by-side splitscreen of both views simultaneously. (maybe that's the behaviour if both ICONS are chosen).
Try this
#region abc
//your code here
#endregion
http://msdn.microsoft.com/en-us/library/9a1ybwek%28v=VS.100%29.aspx

Combine Thumbnails to One Large Image with RMagick [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
What's the shortest way to combine say 20 256x256 thumbnails into a single large image of 4 rows by 5 columns using RMagick?
Assuming all the images are in the current directory and named from 1.jpg to n.jpg and row * col = n.
include Magick
row = NUM_ROWS
col = NUM_COLS
ilg = ImageList.new
1.upto(col) {|x| il = ImageList.new
1.upto(row) {|y| il.push(Image.read((y + (x-1)*col).to_s + ".jpg").first)}
ilg.push(il.append(false))}
ilg.append(true).write("out.jpg")

Resources