Friday, 18 May 2018

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV




In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man 2, Spider-Man 3. He also provided the voice of Spider-Man for the videogame adaptations of the films, but he wasn't in the recent release of Spider-Man series The Amazing Spider-Man.



Since his outstanding performance in the Spider-Man series, I was surprised. Why didn't Tobey Maguire get a chance to act in The Amazing Spider-Man?


Answer



The new Amazing Spider-Man is a reboot of the series. In other words, it has nothing to do with the earlier three movies. A few core elements remain, but the rest have been changed. So it only makes sense since they're giving the franchise a fresh start to give the role of Peter Parker to someone else.


Thursday, 17 May 2018

identify this movie - Character Eaten by Monster from a Trap Door on the Floor - Movies & TV






The movie is in color and probably from the 1960s. I don't think it is Mysterious Island or Captain Nemo and the Underwater City.



The only scene I remember involves characters in a room, with wooden planks on the floor and the walls. The center is bare and prisoners face a group questioning them.



They are wearing what looks like pirate or sailor costumes from an earlier century.



At the center of the room is a trap door. After questioning one of the prisoners, one of the men opens the trap door, revealing the mouth of a monster. The prisoner is thrown into the trap door and is eaten by the monster, feet first.



Answer



The only other film that this remotely reminds me of is The Lost Continent from 1968.




This film starts out like the Love Boat on acid, as a cast of varied characters, with various issues, take Captain Eric Portman's leaky cargo ship to escape their troubles. When a violent storm strikes, the ship is swept into the Sargasso Sea and our heroes find themselves trapped on an island of man-eating seaweed, populated by giant monster crabs and some Spanish conquistadors who think the Inquisition is still on.



alphanumeric - How to generate unique six digit alpha-numeric code in Ruby



I need to generate a unique six digit alpha-numeric code. To save in my database as voucher no: for every transaction.


Answer



I used this



  require 'sha1'

srand
seed = "--#{rand(10000)}--#{Time.now}--"
Digest::SHA1.hexdigest(seed)[0,6]


How to generate a random string in Ruby This link was useful


ag-grid API Undefined in Angular 2



I am using the ag-grid API in an Angular 2 app, inside the ngOnInit method.



In the onGridReady event like mentioned in this post, the API is accessible and things work fine.




However, I need to call the API in one of the following methods as well:




  • onRowDataChanged

  • onNewColumnsLoaded

  • onModelUpdated



This is not working because the API is undefined. In addition, for some reason I can also call the API in the onCellDoubleClicked and onCellClicked events.




This seem to be a bug. Does anyone know what is going on?



Please see the code bellow:



ngOnInit() {

this.gridOptions = {

onGridReady: function (param) {

param.api.sizeColumnsToFit(); // works fine
},

onCellDoubleClicked: function (param) {
param.api.sizeColumnsToFit(); // works fine
},

onRowDataChanged: function (param) {
param.api.sizeColumnsToFit(); // API is undefined
},

};
}

Answer



Alright, here is how I got it working.




  • First, capture the this reference for your angular component just to make sure that you will not have JavaScript scoping issues.


  • Then, capture the API reference when it is available inside the onGridReady event


  • Lastly, only call the API after the stack is empty, deferring all the API calls with the setTimeout function





So now the code looks more or less like this:



...
let self = this;
...
onGridReady: function (param) {
self.api = param.api;
},


onRowDataChanged: function (param) {
setTimeout(() => {
self.api.sizeColumnsToFit()
...more API calls...
}, 0);
},
...

oracle - Icinga (nagios) trend of query result



I am setting up Icinga monitoring and after reading tons of documentation i still cant find out how to resolve the last aspect i need.




I need to execute a custom query on a Oracle datatabase on a extern network. The result of this query which will be a number (COUNT rows) I will have to save somehow in the Icinga database.



Then every 4 hours i want to execute a query that calculates the average of the results of query on the oracle database and have checks on these. Lets say if more then 50 then its critical if more then 40 then warning and so forth.




  1. How can I set up an event that calls the Oracle database every 5 minutes and saves the result in the Icinga database?


  2. How can I set up an event to read the information put in the database of Icinga? Suppose a query will suffice, i can calculate average with a query.




Thanks in advance! I love Icinga, but when things get complicated, it sometimes feels it comes short of solutions.




(Running on Ubuntu server, Icinga2 and Icinga web)


Answer



For icinga to query and store in the database use idoutils. COnfigure the required plugins for idodb which are modules of mysql. livestatus I think doesn't read or write in any database but is more prone to get live data and display it thats all.


matlab - Trying to optimize some code and make it faster

I have the following code in matlab, which is extremely slow.this code is related to my previous post in I as wondering is there any way to make matlab faster, also when I run the code it should show me figure, with updated images, but it doesnt show any thing




%% Loading Data
cd('D:\MatlabTest\15-07SpeedSensitivity\0.3');
clear all
row=101;
column=311;

%%
%Coefficients Creation
N=5;
W = [0.005 0.10;0.10 0.20;0.20 0.30;0.30 0.40;0.40 0.50;0.50 0.60 ;0.60 0.70;0.70 0.80 ;0.80 0.90;0.90 1.0];

for ind=1:9
wn = W(ind,:);
[b,a] = butter(N,wn);
bCoeff{ind}=b;
aCoeff{ind}=a;
end
[bCoeff{10},aCoeff{10}]=butter(N,0.9,'high');

%%
%filter initialization

ZState = cell(1,10);
for i=1:10
ZState{i} = zeros(max(length(aCoeff{i}), length(aCoeff{i})) - 1, 1); %# This is the initial filter state
end
%%
bands=10;
for b=1:bands
Yout{b}{row, column}=[];
end


%%
j=1;
K = 1000:4000;
window = zeros(1,10);
figure;
y = 0; %# Preallocate memory for output
j=0;
buffSize=10;
tempMean{row,column}=[];
Gibbs=(length(K)*3)/100;

fImg{1}(row,column)=0;
%load one image
for i = 1000:length(K)
disp(i)
str = int2str(i);
str1 = strcat(str,'.mat');
load(str1);
D(:,:) = A(100:200 ,200:510);
%go throught the columns and rows
for p = 1:row

for q = 1:column
%calculte the temporal mean value based on previous ones
if(size(tempMean{p,q}) tempMean{p,q}=[D(p,q) tempMean{p,q}];
else
tempMean{p,q}=[D(p,q) tempMean{p,q}(1:end-1)];
end
if(mean2(tempMean{p,q})==0)
x=0;
else

x = double(D(p,q)/mean2(tempMean{p,q}));
end
%filtering for 10 bands, based on the previous state
for f = 1:10
[y, ZState{f}] = filter(bCoeff{f},aCoeff{f},x,ZState{f});
if(j continue;
end
if(size(Yout{f}{p,q})<10)%init the first 10 after Gibbs phenomenon
Yout{f}{p,q} = [y.^2 Yout{f}{p,q}];

else
Yout{f}{p,q} = [y.^2 Yout{f}{p,q}(1:end-1)];
fImg{f}(p,q)=mean2(Yout{f}{p,q});
end
end
end
end
if(size(fImg{1}(1,1))>1)
for k = 1:10
subplot(5,2,1);

subimage(fImg{k}*5000, [0 0.5]);
colormap jet
end
pause(0.01);
end
j=j+1;
end
disp('Done Loading...')`

Javascript load Image into Offscreen Canvas, perform webp conversion



I recently used canvas to conert images to webp, using :




const dataUrl = canvas.toDataURL('image/webp');



But this takes a lots of time for certain images, like 400ms.



I got a warning from Chrome, since it is blocking UI.



I would like to use an Offscreen Canvas to perform that conversion in background.



But :




1) I don't know which Offscreen Canvas I should use :
a] new OffscreenCanvas()
b] canvas.transferControlToOffscreen()



2) I load a local image url in an Image object (img.src = url) to get width and height of the local image. But I don't understand how to transfert the Image object to the offscreen Canvas, to be able to do in the worker :



ctx.drawImage(img, 0, 0)



Because If I don't transfert the image, worker doesn't know img.



Answer



You are facing an XY and even -Z problem here, but each may have an useful answer, so let's dig in.






X. Do not use the canvas API to perform image format conversion.
The canvas API is lossy, whatever you do, you will loose information from your original image, even if you do pass it lossless images, the image drawn on the canvas will not be the same as this original image.
If you pass an already lossy format like JPEG, it will even add information that were not in the original image: the compression artifacts are now part of the raw bitmap, and export algo will treat these as information it should keep, making your file probably bigger than the JPEG file you fed it with.



Not knowing your use case, it's a bit hard to give you the perfect advice, but generally, make the different formats from the version the closest to the raw image, and once it's painted in a browser, you are already at least three steps too late.







Now, if you do some processing on this image, you may indeed want to export the results.
But you probably don't need this Web Worker here.
Y. What takes the biggest blocking time in your description should be the synchronous toDataURL() call.
Instead of this historical error in the API, you should always be using the asynchronous and nonetheless more performant toBlob() method. In 99% of the cases, you don't need a data URL anyway, almost all you want to do with a data URL should be done with a Blob directly.



Using this method, the only heavy synchronous operation remaining would be the painting on canvas, and unless you are downsizing some huge images, this should not take the 400ms.



But you can anyway make it even better on newest canvas thanks to createImageBitmap method, which allows you to prepare asynchronously your image so that the image's decoding be complete and all that needs to be done is really just a put pixels operation:






large.onclick = e => process('https://upload.wikimedia.org/wikipedia/commons/c/cf/Black_hole_-_Messier_87.jpg');
medium.onclick = e => process('https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Black_hole_-_Messier_87.jpg/1280px-Black_hole_-_Messier_87.jpg');

function process(url) {
convertToWebp(url)
.then(prepareDownload)
.catch(console.error);
}

async function convertToWebp(url) {

if(!supportWebpExport())
console.warn("your browser doesn't support webp export, will default to png");

let img = await loadImage(url);
if(typeof window.createImageBitmap === 'function') {
img = await createImageBitmap(img);
}
const ctx = get2DContext(img.width, img.height);

console.time('only sync part');

ctx.drawImage(img, 0,0);
console.timeEnd('only sync part');

return new Promise((res, rej) => {
ctx.canvas.toBlob( blob => {
if(!blob) rej(ctx.canvas);
res(blob);
}, 'image/webp');
});
}


// some helpers

function loadImage(url) {
return new Promise((res, rej) => {
const img = new Image();
img.crossOrigin = 'anonymous';
img.src = url;
img.onload = e => res(img);
img.onerror = rej;

});
}

function get2DContext(width = 300, height=150) {
return Object.assign(
document.createElement('canvas'),
{width, height}
).getContext('2d');
}


function prepareDownload(blob) {
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'image.' + blob.type.replace('image/', '');
a.textContent = 'download';
document.body.append(a);
}

function supportWebpExport() {
return get2DContext(1,1).canvas

.toDataURL('image/webp')
.indexOf('image/webp') > -1;
}











Z. To draw an image on an OffscreenCanvas from a Web Worker, you will need the createImageBitmap mentioned above. Indeed, the ImageBitmap object produced by this method is the only image source value that drawImage() and texImage2D()(*) can accept which is available in Workers (all other being DOM Elements).



This ImageBitmap is transferable, so you could generate it from the main thread and then send it to you Worker with no memory cost:



main.js



const img = new Image();
img.onload = e => {
createImageBitmap(img).then(bmp => {

// transfer it to your worker
worker.postMessage({
image: bmp // the key to retrieve it in `event.data`
},
[bmp] // transfer it
);
};
img.src = url;



An other solution is to fetch your image's data from the Worker directly, and to generate the ImageBitmap object from the fetched Blob:



worker.js



const blob = await fetch(url).then(r => r.blob());
const img = await createImageBitmap(blob);
ctx.drawImage(img,0,0);






And note if you got the original image in your main's page as a Blob (e.g from an ), then don't even go the way of the HTMLImageElement, nor of the fetching, directly send this Blob and generate the ImageBitmap from it.



*texImage2D actually accepts more source image formats, such as TypedArrays, and ImageData objects, but these TypedArrays should represent the pixel data, just like an ImageData does, and in order to have this pixel data, you probably need to already have drawn the image somewhere using one of the other image source formats.


methods - Is Java "pass-by-reference" or "pass-by-value"?

I always thought Java was pass-by-reference.



However, I've seen a couple of blog posts (for example, this blog) that claim that it isn't.



I don't think I understand the distinction they're making.



What is the explanation?

java - How do I generate all possible numbers from this regular expression?





I want to get a list of all possible values for a regular expression.



Input :



2W
9WW

7W0W3


where W can be any digit from 0 to 9. i.e. W = [0-9]



Output:



20,21,22,....29
900,901,...910,911,...999
70003,70013,70023,...71003,72003,...79093



What I did :



I'm using Java and decided to create an ArrayList of Integers.



I created a method ArrayList getNumbers(String regex).



ArrayList getNumbers(String regex){


ArrayList fullList = new ArrayList();

char[] cArray = regex.toCharArray(); //converted the string into a character array.

for(int i=1;i
if(cArray[i] == 'W') {

for(int j=0;j<10;j++) {
//I'm not sure what goes here

fullList.add(the number with 'w' at this index replaced by 'j');
}
}

}
return fullList;
}


Is there any better way or library functions available to generate all such numbers?




How can I achieve this?



Any help please.


Answer



This is not quite a regex-based problem, but from an algorithmic perspective you can do the followings:




  • Count the number of W's in your string.

  • Based on the number of W's, create the product of range(0,9), for example if you have 2 W you need to create the products of two [0...9] lists that will be something like 0,0-0,1-0,2-...-9,9.


  • Loop over the combinations and replace them with a simple string formatting. For instance when you are iterating over a triple combination suppose with 3 variables i,j,k you want want to replace them in a string like 7W0W3W, you can do "7%d0%dW%d"%(i,j,k).



And if you are looking for a general regex to wrap all the cases you can use a regex like (w) (w in a capture group) then you need to first access to position of the match groups and replace them with combination items (i,j,k,..).


python - Negative list index?





Possible Duplicate:
Explain slice notation







I'm trying to understand the following piece of code:



# node list
n = []
for i in xrange(1, numnodes + 1):
tmp = session.newobject();
n.append(tmp)
link(n[0], n[-1])



Specifically, I don't understand what the index -1 refers to. If the index 0 refers to the first element, then what does -1 refer to?


Answer



Negative numbers mean that you count from the right instead of the left. So, list[-1] refers to the last element, list[-2] is the second-last, and so on.


c++ 2d array access speed changes based on [a][b] order?











I have been tinkering around with a program that I'm using to simply sum the elements of a 2d array. A typo led to what seem to me at least, some very strange results.



When dealing with array, matrix[SIZE][SIZE]:



for(int row = 0; row < SIZE; ++row)
for(int col = 0; col < SIZE; ++col)
sum1 += matrix[row][col];



Runs very quickly, however is the above line sum1... is modified:



sum2 += matrix[col][row]


As I did once on accident without realizing it, I notice that my runtime increases SIGNIFICANTLY. Why is this?


Answer



This is due to caching behaviour of your program.




Arrays are just consecutive blocks of memory, so when you access [row][column] you are accessing the memory sequentially. This means the data page you are accessing is on the same page, so the access is much faster.



When you do [column][row], you aren't accessing that memory sequentially anymore, so you will end up with more cache misses, so your program runs much slower.


Wednesday, 16 May 2018

r - How to change point size in lattice?



How can I modify "point" sizes proportionally to a given variable?



For example with ggplot I can do it with



ggplot(mydata,aes(x=x, y=y))+geom_point(aes(size=mysize))+geom_line(aes(group=id, color=id))


where mysize is the size of every point I want.
but it's very slow when the dataset is big.



I've tried with lattice:



xyplot(y~x , type="b", col="black", col.line="blue", data=mydata, pch=16, lwd=1 )


But I can't find a working way to use a size= option with lattice.



I've tried the cex option but it produces strange results.



This is a simplified version of my data: (it's a data.table but you can use a data.frame if you want)



structure(list(id = c(3059L, 1161L, 3996L, 6330L, 6675L, 1511L, 
3678L, 294L, 596L, 2440L, 446L, 2635L, 6073L, 3709L, 744L, 4997L,
3495L, 6447L, 6693L, 1040L, 1031L, 690L, 352L, 6311L, 2599L,
6425L, 3758L, 690L, 6742L, 3025L, 6348L, 214L, 222L, 8192L, 615L,
2939L, 5351L, 255L, 1531L, 6426L, 1686L, 2677L, 1919L, 3665L,
6514L, 630L, 820L, 2138L, 6695L, 1323L, 6246L, 2102L, 2600L,
3663L, 3851L, 970L, 1124L, 4071L, 1806L, 4579L, 3395L, 4371L,
1466L, 201L, 2112L, 8653L, 4407L, 1959L, 6341L, 2214L, 6515L,
1390L, 6346L, 5373L, 662L, 2198L, 1971L, 6177L, 4652L, 4420L,
6527L, 2704L, 6366L, 1111L, 6156L, 151L, 734L, 4286L, 5085L,
2359L, 2818L, 339L, 8486L, 5303L, 5076L, 8490L, 1230L, 1884L,
5204L, 2880L, 8463L, 215L, 6778L, 6329L, 5797L, 584L, 4831L,
4806L, 2581L, 3972L, 2298L, 3136L, 335L, 5538L, 1528L, 518L,
3552L, 3874L, 1967L, 4333L, 3035L, 4112L, 215L, 1768L, 866L,
3545L, 8085L, 8622L, 2844L, 2663L, 1356L, 4902L, 880L, 8219L,
1486L, 3086L, 685L, 417L, 5966L, 221L, 8401L, 8378L, 1542L, 1815L,
515L, 6262L, 3522L, 2440L, 182L, 946L, 3924L, 6219L, 2282L, 4165L,
4969L, 5829L, 6707L, 4467L, 8645L, 8267L, 3960L, 1432L, 8203L,
1691L, 5515L, 2005L, 5578L, 6732L, 103L, 740L, 8239L, 2037L,
630L, 8286L, 4005L, 3874L, 1691L, 201L, 4191L, 1259L, 4476L,
5210L, 798L, 5829L, 6499L, 120L, 1725L, 2185L, 3795L, 5918L,
3474L, 936L, 4625L, 4449L, 5579L, 5906L, 2050L, 3376L, 6140L,
8021L, 5009L, 3545L, 346L, 8513L, 1529L, 4155L, 3029L, 5785L,
397L, 1448L, 1804L, 6209L, 3043L, 2448L, 8371L, 5729L, 1602L,
5600L, 1488L, 280L, 1986L, 2858L, 1742L, 1939L, 4869L, 751L,
2967L, 6350L, 612L, 3935L, 3972L, 8321L, 8225L, 8117L, 5181L,
2214L, 1461L, 8150L, 3218L, 3699L, 4906L, 4488L, 1317L, 866L,
6832L, 8394L, 527L, 1384L, 3356L, 3320L, 1951L, 2979L, 3884L,
1664L, 8446L, 1851L, 1105L, 816L, 6323L, 4490L, 1020L, 3888L,
1086L, 4804L, 1203L, 3464L, 836L, 1591L, 755L, 6332L, 221L, 3519L,
1565L, 1169L, 2841L, 3992L, 5296L, 6187L, 3001L, 3711L, 1394L,
3333L, 1728L, 4320L, 6670L, 4653L, 6409L, 2369L, 8428L, 3714L,
8383L, 2142L, 1803L, 589L, 1986L, 866L, 866L, 4558L, 8139L, 3996L,
3667L, 2939L, 4626L, 3950L, 4371L, 6036L, 3212L, 8534L, 1599L,
1801L, 5015L, 121L, 8258L, 3811L, 1277L, 1161L, 4854L, 4581L,
8150L, 3223L, 2939L, 8548L, 1691L, 2969L, 1705L, 3477L, 5351L,
1120L, 3921L, 3915L, 2599L, 3457L, 630L, 2296L, 1569L, 6378L,
3447L, 6438L, 2697L, 2236L, 675L, 6147L, 4842L, 6205L, 4453L,
4478L, 2394L, 2115L, 5799L, 4683L, 1699L, 4757L, 8566L, 2125L,
3365L, 5194L, 1448L, 2043L, 2549L, 8647L, 1542L, 6179L, 1706L,
4099L, 5996L, 5289L, 6383L, 5102L, 488L, 889L, 3323L, 8461L,
1673L, 919L, 661L, 6505L, 1624L, 8261L, 6118L, 3935L, 2288L,
1230L, 1221L, 8359L, 8611L, 5710L, 6064L, 5238L, 2251L, 72L,
678L, 1649L, 8304L, 6056L, 8294L, 1967L, 5914L, 536L, 6330L,
8548L, 1111L, 3773L, 1381L, 3522L, 8461L, 1163L, 3111L, 3035L,
8101L, 1705L, 1690L, 2988L, 2243L, 3921L, 6348L, 4683L, 8424L,
3117L, 2015L, 559L, 8596L, 4235L, 280L, 8197L, 6096L, 3130L,
2880L, 1224L, 3636L, 8291L, 108L, 3213L, 2386L, 3350L, 3526L,
8116L, 2213L, 3519L, 1387L, 3672L, 4096L, 4288L, 905L, 3348L,
380L, 876L, 1685L, 8636L, 5559L, 1630L, 4696L, 5068L, 2351L,
757L, 3842L, 3517L, 8270L, 2880L, 8572L, 3384L, 6056L, 3884L,
1259L, 1053L, 6262L, 3965L, 4401L, 5295L, 4467L, 8216L, 8197L,
3500L, 5475L, 6662L, 2117L, 1092L, 5500L, 1447L, 6283L, 5930L,
2486L, 3258L, 4272L, 1616L, 3024L, 4104L, 3760L, 4431L, 5830L,
6366L, 5202L, 2868L, 5097L, 8647L, 6701L, 1167L, 5521L, 1209L,
5979L, 6178L), cars = structure(c(11L, 12L, 12L, 11L, 12L, 11L,
12L, 9L, 1L, 9L, 8L, 13L, 12L, 12L, 12L, 9L, 12L, 10L, 8L, 10L,
9L, 12L, 13L, 8L, 10L, 9L, 7L, 9L, 11L, 13L, 9L, 3L, 12L, 13L,
13L, 12L, 11L, 13L, 13L, 8L, 7L, 13L, 13L, 13L, 13L, 12L, 7L,
9L, 11L, 10L, 11L, 9L, 12L, 12L, 12L, 13L, 13L, 11L, 6L, 12L,
13L, 9L, 9L, 2L, 11L, 11L, 13L, 12L, 13L, 8L, 11L, 9L, 11L, 11L,
7L, 12L, 10L, 7L, 13L, 5L, 12L, 10L, 7L, 13L, 13L, 12L, 7L, 9L,
10L, 12L, 13L, 13L, 7L, 13L, 12L, 13L, 13L, 9L, 13L, 9L, 10L,
10L, 13L, 11L, 13L, 13L, 13L, 13L, 13L, 11L, 11L, 7L, 6L, 13L,
11L, 7L, 12L, 10L, 4L, 11L, 13L, 12L, 6L, 8L, 12L, 7L, 12L, 12L,
12L, 10L, 8L, 9L, 11L, 13L, 12L, 9L, 13L, 10L, 12L, 8L, 7L, 12L,
13L, 13L, 13L, 13L, 13L, 10L, 12L, 3L, 13L, 13L, 12L, 13L, 13L,
9L, 6L, 11L, 11L, 12L, 13L, 12L, 13L, 6L, 8L, 13L, 10L, 13L,
11L, 13L, 11L, 7L, 12L, 13L, 13L, 11L, 4L, 11L, 11L, 5L, 11L,
12L, 13L, 11L, 8L, 9L, 10L, 11L, 12L, 3L, 10L, 8L, 10L, 13L,
8L, 13L, 6L, 12L, 13L, 12L, 13L, 6L, 12L, 12L, 11L, 13L, 10L,
12L, 10L, 12L, 8L, 10L, 10L, 13L, 13L, 13L, 8L, 13L, 8L, 12L,
7L, 8L, 11L, 1L, 11L, 12L, 7L, 12L, 13L, 11L, 7L, 13L, 12L, 9L,
13L, 13L, 2L, 4L, 13L, 12L, 9L, 10L, 11L, 12L, 9L, 13L, 10L,
12L, 9L, 7L, 12L, 13L, 11L, 13L, 7L, 4L, 7L, 13L, 13L, 13L, 13L,
12L, 8L, 5L, 8L, 13L, 6L, 13L, 12L, 8L, 12L, 6L, 8L, 6L, 13L,
12L, 8L, 6L, 11L, 8L, 4L, 12L, 10L, 12L, 12L, 11L, 8L, 12L, 10L,
9L, 13L, 12L, 10L, 11L, 13L, 12L, 12L, 12L, 11L, 7L, 13L, 12L,
11L, 7L, 8L, 13L, 12L, 13L, 12L, 13L, 13L, 13L, 13L, 11L, 13L,
13L, 6L, 5L, 9L, 13L, 10L, 8L, 13L, 8L, 10L, 12L, 10L, 11L, 11L,
13L, 13L, 8L, 13L, 13L, 12L, 2L, 12L, 1L, 5L, 13L, 4L, 12L, 3L,
3L, 13L, 8L, 13L, 13L, 10L, 10L, 5L, 11L, 11L, 12L, 10L, 8L,
13L, 5L, 13L, 11L, 7L, 12L, 9L, 13L, 12L, 5L, 12L, 12L, 7L, 10L,
3L, 12L, 11L, 6L, 11L, 12L, 12L, 12L, 11L, 7L, 8L, 11L, 10L,
11L, 13L, 13L, 13L, 12L, 6L, 12L, 11L, 13L, 9L, 8L, 13L, 7L,
4L, 13L, 9L, 9L, 10L, 12L, 1L, 12L, 12L, 13L, 9L, 12L, 7L, 6L,
13L, 9L, 13L, 10L, 12L, 12L, 13L, 13L, 12L, 13L, 12L, 7L, 13L,
3L, 12L, 12L, 13L, 2L, 5L, 9L, 12L, 10L, 7L, 12L, 12L, 11L, 10L,
13L, 13L, 13L, 11L, 13L, 13L, 12L, 10L, 7L, 13L, 12L, 6L, 13L,
8L, 11L, 8L, 13L, 10L, 13L, 13L, 11L, 8L, 11L, 8L, 7L, 11L, 5L,
11L, 13L, 11L, 13L, 13L, 12L, 6L, 13L, 9L, 13L, 8L, 6L, 8L, 6L,
13L, 9L, 13L, 12L, 6L, 8L, 12L, 10L, 13L, 12L, 12L, 11L, 8L,
11L, 11L, 2L, 11L, 12L, 11L, 11L, 6L, 12L), .Label = c("FORD",
"VW", "PEUGEOT", "RENAULT", "TOYOTA", "BMW", "NISSAN", "MB",
"AUDI", "HONDA", "FIAT", "LR", "SKODA", "MAZDA", "MINI", "KIA",
"VOLVO", "SEAT", "SUZUKI", "MITSU", "JAGUAR", "ROVER", "SAAB",
"LEXUS", "CHEVRO", "MG", "PORSCHE"), class = "factor"), numb = c(1L,
1L, 1L, 1L, 1L, 2L, 1L, 3L, 2L, 2L, 2L, 1L, 1L, 1L, 5L, 2L, 2L,
1L, 2L, 3L, 1L, 4L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 1L, 5L, 1L, 1L,
4L, 6L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 4L, 12L, 9L, 1L,
1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 3L, 2L, 1L, 6L,
1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 4L, 2L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 7L, 1L, 2L, 6L, 1L, 1L, 1L, 3L, 2L, 2L, 6L, 1L, 1L,
2L, 2L, 3L, 2L, 2L, 1L, 2L, 2L, 3L, 3L, 4L, 1L, 2L, 2L, 1L, 5L,
3L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 3L, 1L, 2L, 1L, 10L, 4L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 1L, 1L, 2L, 8L, 1L, 1L, 4L, 2L, 1L, 5L,
1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 1L, 2L, 1L, 3L, 1L,
1L, 2L, 1L, 2L, 3L, 4L, 2L, 1L, 2L, 1L, 3L, 1L, 2L, 8L, 1L, 1L,
3L, 6L, 4L, 1L, 2L, 1L, 1L, 3L, 1L, 2L, 1L, 1L, 1L, 1L, 4L, 1L,
1L, 2L, 2L, 2L, 1L, 3L, 1L, 2L, 2L, 1L, 5L, 1L, 1L, 1L, 2L, 6L,
2L, 1L, 4L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 2L, 2L, 2L, 1L,
3L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 3L, 1L, 2L, 2L, 3L, 3L, 3L, 1L,
4L, 1L, 2L, 2L, 7L, 2L, 1L, 1L, 3L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
3L, 6L, 3L, 2L, 8L, 3L, 2L, 1L, 3L, 1L, 1L, 1L, 2L, 1L, 2L, 2L,
1L, 4L, 2L, 2L, 3L, 3L, 2L, 1L, 2L, 2L, 1L, 3L, 1L, 1L, 1L, 3L,
2L, 3L, 1L, 2L, 1L, 1L, 1L, 3L, 1L, 4L, 1L, 2L, 2L, 2L, 2L, 1L,
2L, 3L, 4L, 2L, 1L, 1L, 1L, 2L, 1L, 4L, 1L, 3L, 2L, 1L, 4L, 5L,
5L, 3L, 2L, 8L, 1L, 3L, 4L, 1L, 2L, 1L, 2L, 2L, 4L, 13L, 1L,
4L, 2L, 1L, 1L, 1L, 4L, 1L, 1L, 1L, 2L, 1L, 2L, 3L, 1L, 1L, 5L,
5L, 1L, 2L, 1L, 1L, 1L, 6L, 3L, 3L, 1L, 4L, 1L, 3L, 2L, 1L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 5L, 2L, 1L, 3L, 2L, 2L, 3L, 2L, 4L, 4L, 2L, 1L, 2L, 2L,
2L, 1L, 2L, 1L, 7L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 4L, 2L,
16L, 4L, 2L, 6L, 1L, 2L, 3L, 4L, 3L, 5L, 1L, 1L, 6L, 3L, 5L,
3L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 3L, 3L, 1L, 1L,
2L, 1L, 1L, 2L, 3L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L,
2L, 1L, 6L, 1L, 1L, 2L, 1L, 5L, 1L, 6L, 4L, 1L, 1L, 2L, 3L, 1L,
2L, 1L, 1L, 2L, 1L, 6L, 1L, 3L, 4L, 1L, 2L, 3L, 1L, 5L, 2L, 1L,
2L, 2L, 2L, 1L, 1L, 1L, 1L), mysize = c(0.196195449459157, 0.259604625139873,
0.259604625139873, 0.196195449459157, 0.259604625139873, 0.0982578397212544,
0.259604625139873, 0.0761772853185596, 0.00627177700348432, 0.0759581881533101,
0.0655052264808362, 0.198433420365535, 0.259604625139873, 0.259604625139873,
0.167701863354037, 0.0759581881533101, 0.212543554006969, 0.120477433793361,
0.0655052264808362, 0.0664819944598338, 0.061917195076464, 0.183673469387755,
0.307479224376731, 0.0512465373961219, 0.120477433793361, 0.061917195076464,
0.0484893696381947, 0.0759581881533101, 0.0982578397212544, 0.198433420365535,
0.142857142857143, 0.0115628496829541, 0.259604625139873, 0.34402332361516,
0.375, 0.259604625139873, 0.0982578397212544, 0.198433420365535,
0.198433420365535, 0.0481163744871317, 0.0522648083623693, 0.282229965156794,
0.282229965156794, 0.198433420365535, 0.34402332361516, 0.5,
0.1, 0.061917195076464, 0.196195449459157, 0.120477433793361,
0.196195449459157, 0.0759581881533101, 0.212543554006969, 0.259604625139873,
0.212543554006969, 0.198433420365535, 0.198433420365535, 0.196195449459157,
0.0662020905923345, 0.259604625139873, 0.307479224376731, 0.0759581881533101,
0.061917195076464, 0.0625, 0.196195449459157, 0.0982578397212544,
0.282229965156794, 0.259604625139873, 0.282229965156794, 0.0481163744871317,
0.0982578397212544, 0.061917195076464, 0.0982578397212544, 0.196195449459157,
0.0699708454810496, 0.212543554006969, 0.120477433793361, 0.0484893696381947,
0.198433420365535, 0.00857888847444983, 0.212543554006969, 0.0682926829268293,
0.0522648083623693, 0.444444444444444, 0.198433420365535, 0.212543554006969,
0.0875, 0.061917195076464, 0.120477433793361, 0.259604625139873,
0.307479224376731, 0.282229965156794, 0.0522648083623693, 0.375,
0.259604625139873, 0.198433420365535, 0.282229965156794, 0.0759581881533101,
0.307479224376731, 0.0759581881533101, 0.0682926829268293, 0.120477433793361,
0.282229965156794, 0.0982578397212544, 0.307479224376731, 0.307479224376731,
0.34402332361516, 0.198433420365535, 0.282229965156794, 0.0982578397212544,
0.196195449459157, 0.0496894409937888, 0.054016620498615, 0.198433420365535,
0.196195449459157, 0.0484893696381947, 0.259604625139873, 0.0682926829268293,
0.0229965156794425, 0.196195449459157, 0.307479224376731, 0.259604625139873,
0.0662020905923345, 0.0481163744871317, 0.4, 0.0699708454810496,
0.259604625139873, 0.212543554006969, 0.21606648199446, 0.120477433793361,
0.0655052264808362, 0.0761772853185596, 0.196195449459157, 0.198433420365535,
0.259604625139873, 0.0759581881533101, 0.5, 0.120477433793361,
0.259604625139873, 0.0728862973760933, 0.0522648083623693, 0.259604625139873,
0.322981366459627, 0.198433420365535, 0.282229965156794, 0.282229965156794,
0.282229965156794, 0.120477433793361, 0.259604625139873, 0.0115628496829541,
0.198433420365535, 0.307479224376731, 0.21606648199446, 0.307479224376731,
0.198433420365535, 0.0759581881533101, 0.0354345393509884, 0.0775623268698061,
0.196195449459157, 0.259604625139873, 0.282229965156794, 0.259604625139873,
0.282229965156794, 0.054016620498615, 0.0728862973760933, 0.282229965156794,
0.120477433793361, 0.282229965156794, 0.196195449459157, 0.307479224376731,
0.196195449459157, 0.0522648083623693, 0.1, 0.198433420365535,
0.198433420365535, 0.0775623268698061, 0.0125, 0.032069970845481,
0.196195449459157, 0.0229965156794425, 0.196195449459157, 0.259604625139873,
0.307479224376731, 0.196195449459157, 0.0655052264808362, 0.061917195076464,
0.120477433793361, 0.196195449459157, 0.259604625139873, 0.0204081632653061,
0.120477433793361, 0.0481163744871317, 0.0682926829268293, 0.282229965156794,
0.0655052264808362, 0.198433420365535, 0.054016620498615, 0.259604625139873,
0.282229965156794, 0.212543554006969, 0.198433420365535, 0.0683229813664596,
0.259604625139873, 0.259604625139873, 0.196195449459157, 0.282229965156794,
0.0375, 0.212543554006969, 0.120477433793361, 0.183673469387755,
0.0481163744871317, 0.0664819944598338, 0.0682926829268293, 0.198433420365535,
0.307479224376731, 0.282229965156794, 0.0481163744871317, 0.307479224376731,
0.0655052264808362, 0.212543554006969, 0.0522648083623693, 0.0655052264808362,
0.196195449459157, 0.0138504155124654, 0.196195449459157, 0.259604625139873,
0.0522648083623693, 0.212543554006969, 0.198433420365535, 0.0982578397212544,
0.0484893696381947, 0.307479224376731, 0.259604625139873, 0.0759581881533101,
0.282229965156794, 0.307479224376731, 0.0152354570637119, 0.0193905817174515,
0.198433420365535, 0.183673469387755, 0.061917195076464, 0.0682926829268293,
0.0982578397212544, 0.2, 0.0759581881533101, 0.198433420365535,
0.120477433793361, 0.21606648199446, 0.061917195076464, 0.0522648083623693,
0.259604625139873, 0.198433420365535, 0.196195449459157, 0.198433420365535,
0.0484893696381947, 0.0193905817174515, 0.0875, 0.307479224376731,
0.282229965156794, 0.5, 0.307479224376731, 0.212543554006969,
0.0481163744871317, 0.0318559556786704, 0.0481163744871317, 0.198433420365535,
0.0354345393509884, 0.282229965156794, 0.259604625139873, 0.0655052264808362,
0.212543554006969, 0.0354345393509884, 0.0728862973760933, 0.0662020905923345,
0.282229965156794, 0.21606648199446, 0.0512465373961219, 0.0662020905923345,
0.196195449459157, 0.0655052264808362, 0.0229965156794425, 0.259604625139873,
0.0664819944598338, 0.259604625139873, 0.259604625139873, 0.196195449459157,
0.0512465373961219, 0.212543554006969, 0.0664819944598338, 0.061917195076464,
0.282229965156794, 0.259604625139873, 0.120477433793361, 0.196195449459157,
0.307479224376731, 0.259604625139873, 0.183673469387755, 0.259604625139873,
0.0982578397212544, 0.0522648083623693, 0.282229965156794, 0.212543554006969,
0.196195449459157, 0.0522648083623693, 0.0512465373961219, 0.34402332361516,
0.212543554006969, 0.198433420365535, 0.259604625139873, 0.198433420365535,
0.282229965156794, 0.198433420365535, 0.34402332361516, 0.196195449459157,
0.307479224376731, 0.282229965156794, 0.0354345393509884, 0.0291545189504373,
0.142857142857143, 0.322981366459627, 0.0664819944598338, 0.0655052264808362,
0.5, 0.0481163744871317, 0.0664819944598338, 0.183673469387755,
0.120477433793361, 0.0982578397212544, 0.196195449459157, 0.282229965156794,
0.282229965156794, 0.0728862973760933, 0.5, 0.198433420365535,
0.183673469387755, 0.0132404181184669, 0.259604625139873, 0.00484893696381947,
0.00857888847444983, 0.34402332361516, 0.00484893696381947, 0.259604625139873,
0.0115628496829541, 0.0132404181184669, 0.198433420365535, 0.0655052264808362,
0.307479224376731, 0.198433420365535, 0.120477433793361, 0.031055900621118,
0.0248447204968944, 0.196195449459157, 0.0982578397212544, 0.259604625139873,
0.120477433793361, 0.0481163744871317, 0.375, 0.0318559556786704,
0.307479224376731, 0.196195449459157, 0.0699708454810496, 0.259604625139873,
0.0761772853185596, 0.282229965156794, 0.259604625139873, 0.0229965156794425,
0.259604625139873, 0.259604625139873, 0.0484893696381947, 0.120477433793361,
0.0115628496829541, 0.259604625139873, 0.196195449459157, 0.0354345393509884,
0.196195449459157, 0.212543554006969, 0.259604625139873, 0.259604625139873,
0.196195449459157, 0.0484893696381947, 0.0481163744871317, 0.196195449459157,
0.120477433793361, 0.196195449459157, 0.322981366459627, 0.282229965156794,
0.198433420365535, 0.21606648199446, 0.0662020905923345, 0.212543554006969,
0.0775623268698061, 0.282229965156794, 0.0787172011661808, 0.0728862973760933,
0.282229965156794, 0.0484893696381947, 0.0229965156794425, 0.282229965156794,
0.0759581881533101, 0.061917195076464, 0.0682926829268293, 0.259604625139873,
0.0222222222222222, 0.259604625139873, 0.212543554006969, 0.282229965156794,
0.061917195076464, 0.212543554006969, 0.0484893696381947, 0.0662020905923345,
0.198433420365535, 0.061917195076464, 0.34402332361516, 0.0682926829268293,
1, 0.183673469387755, 0.282229965156794, 0.375, 0.259604625139873,
0.282229965156794, 0.21606648199446, 0.0699708454810496, 0.307479224376731,
0.0124223602484472, 0.259604625139873, 0.259604625139873, 0.375,
0.0152354570637119, 0.0248447204968944, 0.0761772853185596, 0.259604625139873,
0.120477433793361, 0.0595567867036011, 0.259604625139873, 0.259604625139873,
0.196195449459157, 0.120477433793361, 0.282229965156794, 0.198433420365535,
0.198433420365535, 0.0982578397212544, 0.307479224376731, 0.307479224376731,
0.259604625139873, 0.120477433793361, 0.0522648083623693, 0.198433420365535,
0.259604625139873, 0.0662020905923345, 0.307479224376731, 0.0655052264808362,
0.196195449459157, 0.0481163744871317, 0.282229965156794, 0.120477433793361,
0.282229965156794, 0.282229965156794, 0.196195449459157, 0.0481163744871317,
0.0982578397212544, 0.0481163744871317, 0.0522648083623693, 0.196195449459157,
0.05, 0.196195449459157, 0.198433420365535, 0.0982578397212544,
0.198433420365535, 0.322981366459627, 0.259604625139873, 0.05,
0.34402332361516, 0.061917195076464, 0.198433420365535, 0.0655052264808362,
0.054016620498615, 0.0481163744871317, 0.0662020905923345, 0.198433420365535,
0.061917195076464, 0.282229965156794, 0.259604625139873, 0.05,
0.0481163744871317, 0.21606648199446, 0.043731778425656, 0.198433420365535,
0.212543554006969, 0.21606648199446, 0.196195449459157, 0.062111801242236,
0.0982578397212544, 0.196195449459157, 0.0132404181184669, 0.0982578397212544,
0.212543554006969, 0.196195449459157, 0.196195449459157, 0.0354345393509884,
0.259604625139873)), .Names = c("id", "cars", "numb", "mysize"
), class = c("data.table", "data.frame"), row.names = c(NA, -500L
), .internal.selfref = )


and this is the resulting plot with ggplot



ggplot(mydata,aes(x=numb, y=cars))+geom_point(aes(size=mysize))+geom_line(aes(group=id, color="blue"),  show.legend = FALSE)+theme_bw()


enter image description here



and the plot with Lattice



xyplot(cars~numb , type="b", col="black", col.line="blue",  data=mydata, pch=16, cex= mydata$mysize*3,  lwd=1 , groups= mydata$id)


enter image description here



As you can see the circles aren't equivalent.
I don't know which one is wrong.



PD2:
I've summarized the data keeping only unique pairs.



poi <- unique(mydata, by=c("cars","numb"))



structure(list(id = c(3059L, 1161L, 1511L, 294L, 596L, 2440L, 
446L, 2635L, 744L, 3495L, 6447L, 1040L, 1031L, 690L, 352L, 6311L,
3758L, 6348L, 214L, 8192L, 615L, 6426L, 1686L, 2677L, 630L, 820L,
1806L, 201L, 662L, 4420L, 2704L, 1111L, 734L, 3136L, 335L, 1967L,
866L, 2844L, 685L, 221L, 1542L, 6707L, 4467L, 630L, 1691L, 201L,
1259L, 5918L, 3545L, 3029L, 1939L, 1461L, 8150L, 866L, 4804L,
4581L, 630L, 6378L, 6438L, 675L, 6205L, 4683L, 1699L, 8304L,
1381L, 6348L, 8197L, 2386L, 1053L, 8197L, 4104L, 5202L), cars = structure(c(11L,
12L, 11L, 9L, 1L, 9L, 8L, 13L, 12L, 12L, 10L, 10L, 9L, 12L, 13L,
8L, 7L, 9L, 3L, 13L, 13L, 8L, 7L, 13L, 12L, 7L, 6L, 2L, 7L, 5L,
10L, 13L, 7L, 7L, 6L, 4L, 12L, 12L, 13L, 8L, 13L, 6L, 11L, 12L,
4L, 11L, 5L, 3L, 6L, 10L, 1L, 2L, 4L, 12L, 5L, 5L, 13L, 2L, 1L,
4L, 3L, 10L, 5L, 9L, 1L, 12L, 3L, 7L, 5L, 6L, 10L, 8L), .Label = c("FORD",
"VW", "PEUGEOT", "RENAULT", "TOYOTA", "BMW", "NISSAN", "MB",
"AUDI", "HONDA", "FIAT", "LR", "SKODA", "MAZDA", "MINI", "KIA",
"VOLVO", "SEAT", "SUZUKI", "MITSU", "JAGUAR", "ROVER", "SAAB",
"LEXUS", "CHEVRO", "MG", "PORSCHE"), class = "factor"), numb = c(1L,
1L, 2L, 3L, 2L, 2L, 2L, 1L, 5L, 2L, 1L, 3L, 1L, 4L, 3L, 3L, 1L,
5L, 1L, 4L, 6L, 1L, 2L, 2L, 12L, 9L, 2L, 6L, 4L, 1L, 2L, 7L,
6L, 5L, 3L, 2L, 10L, 3L, 8L, 4L, 5L, 1L, 3L, 8L, 6L, 4L, 2L,
4L, 5L, 6L, 3L, 3L, 3L, 7L, 3L, 4L, 13L, 2L, 1L, 1L, 2L, 5L,
5L, 4L, 7L, 16L, 5L, 3L, 6L, 6L, 4L, 5L), mysize = c(0.196195449459157,
0.259604625139873, 0.0982578397212544, 0.0761772853185596, 0.00627177700348432,
0.0759581881533101, 0.0655052264808362, 0.198433420365535, 0.167701863354037,
0.212543554006969, 0.120477433793361, 0.0664819944598338, 0.061917195076464,
0.183673469387755, 0.307479224376731, 0.0512465373961219, 0.0484893696381947,
0.142857142857143, 0.0115628496829541, 0.34402332361516, 0.375,
0.0481163744871317, 0.0522648083623693, 0.282229965156794, 0.5,
0.1, 0.0662020905923345, 0.0625, 0.0699708454810496, 0.00857888847444983,
0.0682926829268293, 0.444444444444444, 0.0875, 0.0496894409937888,
0.054016620498615, 0.0229965156794425, 0.4, 0.21606648199446,
0.5, 0.0728862973760933, 0.322981366459627, 0.0354345393509884,
0.0775623268698061, 0.1, 0.0125, 0.032069970845481, 0.0229965156794425,
0.0204081632653061, 0.0683229813664596, 0.0375, 0.0138504155124654,
0.0152354570637119, 0.0193905817174515, 0.2, 0.0318559556786704,
0.0291545189504373, 0.5, 0.0132404181184669, 0.00484893696381947,
0.00484893696381947, 0.0132404181184669, 0.031055900621118, 0.0248447204968944,
0.0787172011661808, 0.0222222222222222, 1, 0.0124223602484472,
0.0595567867036011, 0.05, 0.05, 0.043731778425656, 0.062111801242236
)), class = c("data.table", "data.frame"), row.names = c(NA,
-72L), .Names = c("id", "cars", "numb", "mysize"))


Lattice doesn't produce the same result with this uniquefied dataset but at least is near what we want.



p1 <- xyplot(cars~numb , type="p", col="black",  data=poi, pch=16, cex= poi$mysize*3)
p2 <- xyplot(cars ~ numb , type = "l", col.line = "blue", data = mydata, lwd = 1 , groups = mydata$id)
p1+as.layer(p2)


enter image description here


Answer



You can use the cex parameter to set the size of the points in lattice.



The code may look like this, with some invented data:



library(lattice)

## some data invented on the spot
mydata <- data.frame(x = 1:5,
y = 6:10,
mysize = 1:5,
id = c(1,1,1,2,2))

xyplot(y ~ x , type = c("b"), col = c("black"), col.line = c("blue"),
data = mydata, pch = 21, cex = mydata$mysize, lwd = 1 )


This yields the following plot:



enter image description here



if you also want to use the grouping (as in your ggplot example), add a groups parameter:



xyplot(y~x , type=c("b"), col=c("black"), col.line=c("blue"), 
data=mydata, pch=21, cex= mydata$mysize, lwd=1 , groups= mydata$id)


Please let me know whether this is what you want.



UPDATE



We can see that one dot is the result of overplotting of several data points: e.g. the car "LR" with numb "1" occurs 61 times.



library(dplyr) ; nrow(mydata %>% filter(cars=="LR" & numb<2))
# 61


Let us remove these LR--1 combinations (after saving on for later) and make sure there is just one of them present. Store in mydata2



OneRow <- head(mydata %>% filter(cars=="LR" & numb<2), 1)
mydata2 <- mydata %>% filter( !(cars=="LR" & numb<2))
mydata2 <- rbind(mydata2, OneRow)


Now plot with ggplot



ggplot(mydata2, aes(x = numb, y = cars)) + 
geom_point(aes(size = mysize)) +
geom_line(aes(group=id, color="blue"), show.legend = FALSE) +
theme_bw()


enter image description here



and with lattice xyplot()



xyplot(cars ~ numb , type = "b", col = "black", col.line = "blue",  
data = mydata2, pch = 16,
cex = mydata$mysize*3, lwd = 1 , groups = mydata$id)


enter image description here



Comparing the two lattice plots makes it clear that, the multiplicity of the LR--1 combination plays a role in the size of the dot. If we want to - **and we need to know whether we want this ** - get the same result as with ggplot we need to have unique rows.


javascript - Promises - How to make asynchronous code execute synchronous without async / await?



  var p1 = new Promise(function(resolve, reject) {  
setTimeout(() => resolve("first"), 5000);

});
var p2 = new Promise(function(resolve, reject) {
setTimeout(() => resolve("second"), 2000);
});
var p3 = new Promise(function(resolve, reject) {
setTimeout(() => resolve("third"), 1000);
});

console.log("last to print");


p1.then(()=>p2).then(()=>p3).then(()=> console.log("last to be printed"))


As I was reading about promises, I know that I can print promises synchronous (in this case print: first, second, third, last to print) when I use async /await. Now I have also been reading that the same thing can be achieved using .then chaining and async/await is nothing 'special'. When I try to chain my promises, however, nothing happens except for the console.log of "last to be printed". Any insight would be great! Thanks!!



Edit to question:



  var p1 = new Promise(function (resolve, reject) {
setTimeout(() => console.log("first"), 5000);
resolve("first resolved")

});
var p2 = new Promise(function (resolve, reject) {
setTimeout(() => console.log("second"), 2000);
resolve("second resolved")
});
var p3 = new Promise(function (resolve, reject) {
setTimeout(() => console.log("third"), 0);
resolve("third resolved")
});


console.log("starting");
p1.then((val) => {
console.log("(1)", val)
return p2
}).then((val) => {
console.log("(2)", val)
return p3
}).then((val) => {
console.log("(3)", val)
})



Loggs:



starting
(1) first resolved
(2) second resolved
(3) third resolved
third
second

first


1: if executor function passed to new Promise is executed immediately, before the new promise is returned, then why are here promises resolved ()synchronously) first and after the setTimeouts (asynchronously) gets executed?




  1. Return value vs. resolve promise:



    var sync = function () {
    return new Promise(function(resolve, reject){

    setTimeout(()=> {
    console.log("start")
    resolve("hello") //--works
    // return "hello" //--> doesnt do anything
    }, 3000);
    })
    }
    sync().then((val)=> console.log("val", val))



Answer




The executor function you pass to new Promise is executed immediately, before the new promise is returned. So when you do:



var p1 = new Promise(function(resolve, reject) {  
setTimeout(() => resolve("first"), 5000);
});


...by the time the promise is assigned to p1, the setTimeout has already been called and scheduled the callback for five seconds later. That callback happens whether you listen for the resolution of the promise or not, and it happens whether you listen for resolution via the await keyword or the then method.



So your code starts three setTimeouts immediately, and then starts waiting for the first promise's resolution, and only then waiting for the second promise's resolution (it'll already be resolved, so that's almost immediate), and then waiting for the third (same again).




To have your code execute those setTimeout calls only sequentially when the previous timeout has completed, you have to not create the new promise until the previous promise resolves (using shorter timeouts to avoid lots of waiting):





console.log("starting");
new Promise(function(resolve, reject) {
setTimeout(() => resolve("first"), 1000);
})
.then(result => {

console.log("(1) got " + result);
return new Promise(function(resolve, reject) {
setTimeout(() => resolve("second"), 500);
});
})
.then(result => {
console.log("(2) got " + result);
return new Promise(function(resolve, reject) {
setTimeout(() => resolve("third"), 100);
});

})
.then(result => {
console.log("(3) got " + result);
console.log("last to print");
});





Remember that a promise doesn't do anything, and doesn't change the nature of the code in the promise executor. All a promise does is provide a means of observing the result of something (with really handy combinable semantics).




Let's factor out the common parts of those three promises into a function:



function delay(ms, ...args) {
return new Promise(resolve => {
setTimeout(resolve, ms, ...args);
});
}



Then the code becomes a bit clearer:





function delay(ms, ...args) {
return new Promise(resolve => {
setTimeout(resolve, ms, ...args);
});
}


console.log("starting");
delay(1000, "first")
.then(result => {
console.log("(1) got " + result);
return delay(500, "second");
})
.then(result => {
console.log("(2) got " + result);
return delay(100, "third");
})

.then(result => {
console.log("(3) got " + result);
console.log("last to print");
});





Now, let's put that in an async function and use await:






function delay(ms, ...args) {
return new Promise(resolve => {
setTimeout(resolve, ms, ...args);
});
}

(async() => {
console.log("starting");

console.log("(1) got " + await delay(1000, "first"));
console.log("(2) got " + await delay(500, "second"));
console.log("(3) got " + await delay(100, "third"));
console.log("last to print");
})();





Promises make that syntax possible, by standardizing how we observe asynchronous processes.







Re your edit:




1: if executor function passed to new Promise is executed immediately, before the new promise is returned, then why are here promises resolved ()synchronously) first and after the setTimeouts (asynchronously) gets executed?




There are two parts to that question:




A) "...why are here promises resolved ()synchronously) first..."



B) "...why are here promises resolved...after the setTimeouts (asynchronously) gets executed"



The answer to (A) is: Although you resolve them synchronously, then always calls its callback asynchronously. It's one of the guarantees promises provide. You're resolving p1 (in that edit) before the executor function returns. But the way you're observing the resolutions ensures that you observe the resolutions in order, because you don't start observing p2 until p1 has resolved, and then you don't start observing p3 until p2 is resolved.



The answer to (B) is: They don't, you're resolving them synchronously, and then observing those resolutions asynchronously, and since they're already resolved that happens very quickly; later, the timer callbacks run. Let's look at how you create p1 in that edit:



var p1 = new Promise(function (resolve, reject) {

setTimeout(() => console.log("first"), 5000);
resolve("first resolved")
});


What happens there is:




  1. new Promise gets called

  2. It calls the executor function


  3. The executor function calls setTimeout to schedule a callback

  4. You immediately resolve the promise with "first resolved"

  5. new Promise returns and the resolved promise is assigned to p1

  6. Later, the timeout occurs and you output "first" to the console



Then later you do:



p1.then((val) => {
console.log("(1)", val)

return p2
})
// ...


Since then always calls its callback asynchronously, that happens asynchronously — but very soon, because the promise is already resolved.



So when you run that code, you see all three promises resolve before the first setTimeout callback occurs — because the promises aren't waiting for the setTimeout callback to occur.



You may be wondering why you see your final then callback run before you see "third" in the console, since both the promise resolutions and the console.log("third") are happening asynchronously but very soon (since it's a setTimeout(..., 0) and the promises are all pre-resolved): The answer is that promise resolutions are microtasks and setTimeout calls are macrotasks (or just "tasks"). All of the microtasks a task schedules are run as soon as that task finishes (and any microtasks that they schedule are then executed as well), before the next task is taken from the task queue. So the task running your script does this:





  1. Schedules a task for the setTimeout callback

  2. Schedules a microtask to call p1's then callback

  3. When the task ends, its microtasks are processed:


    1. The first then handler is run, scheduling a microtask to run the second then handler

    2. The second then handler runs and schedules a micro task to call the third then handler

    3. Etc. until all the then handlers have run



  4. The next task is picked up from the task queue. It's probably the setTimeout callback for p3, so it gets run and "third" appears in the console





  1. Return value vs. resolve promise:





The part you've put in the question doesn't make sense to me, but your comment on this does:




I read that returning a value or resolving a promise is same...




What you've probably read is that returning a value from then or catch is the same as returning a resolved promise from then or catch. That's because then and catch create and return new promises when they're called, and if their callbacks return a simple (non-promise) value, they resolve the promise they create with that value; if the callback returns a promise, they resolve or reject the promise they created based on whether that promise resolves or rejects.



So for instance:




.then(() => {
return 42;
})


and



.then(() => {
return new Promise(resolve => resolve(42));
})



have the same end result (but the second one is less efficient).



Within a then or catch callback:




  1. Returning a non-promise resolves the promise then/catch created with that value

  2. Throwing an error (throw ...) rejects that promise with the value you throw

  3. Returning a promise makes then/catch's promise resolve or reject based on the promise the callback returns



json - Convert java.util.Date to java.sql.Date with 'yyyy-mm-dd hh mm ss'

I need to pass json string to one of the rest web service. There is a property called 'amortizationdate' which will have format 'yyyy-mm-dd hh mm ss'.




for e.g. {amortizationdate:2015-07-31 00:00:00}



we are having AmortizationVO.java with a property amortizationdate.



for e.g



private java.sql.Date amortizationDate.

public void setAmortizationDate(java.sql.Date date){


}


We need to set the date by calling setAmortizationDate(..date) method and using Jackson to convert AmortizationVO.java to Json.



but in JSON I m getting {amortizationdate:2015-07-31}. But expected result should be with timestamp.(amortizationdate:2015-07-31 00:00:00)



note: I don't want to use util date in my Value Object.



Pls help.




What I've tried:



java.util.Date utilDate = new java.util.Date();
java.sql.Timestamp sq = new java.sql.Timestamp(utilDate.getTime());


ExcelEntityAddressVO entityAddressVO = new ExcelEntityAddressVO();
entityAddressVO.setAmortizationDate(new java.sql.Date(sq.getTime()));



This is my JSON:



{
"amortizationdate" : "2015-07-31",
}

javascript - which is the best method used for checking isarray

I want to check a variable is it array?




which is the best method used for this to get better performance.



isArray



or



instanceof

php - redirect() is giving header() error even though nothing is being output to the browser




So basically, I'm getting an error message which reads:





Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\star\application\controllers\process_login.php:1)




I know what is the meaning of that error but I can't figure out where the output was started. I've no whitespaces in the process_login.php file nor anything echo-ed out as well.



I access the login form via the http://localhost/star/index.php/star URL



star Controller



class Star extends CI_Controller {


public function index()
{
$this->load->view('login');
}
}


On form submit, I'm posting to the process_login Controller.




process_login Controller (it doesn't even have a closing tag to avoid whitespace)




class Process_login extends CI_Controller {
public function index()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('userid', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password',

'required|callback_check_valid['.trim($this->input->post('userid')).']');

if ($this->form_validation->run() == FALSE)
{
$this->load->view('login');
}
else
{
redirect('dashboard'); // this is the problem area
}

}

public function check_valid($pw, $un)
{
if($un)
{
$this->load->model('user');
if($this->user->is_authenticated($un, $pw))
{
return true;

}
else
{
$this->form_validation->set_message('check_valid',
'Invalid login. Please try again!');
return false;
}
}
}
}


/* End of file process_login.php */


dashboard Controller



class Dashboard extends CI_Controller {

public function index()
{

$this->load->view('admin_area', array('page_title'=>'Dashboard');
}
}


I'm assuming the process_login.php:1 means the output started from Line 1 of that file? If so, I don't have any output or whitespace in that file. Then why is it that I'm getting the error?



Debugging



After removing everything from the process_login.php file, I'm still getting the same error. This is what the stripped down version of the file looks like:





class Process_login extends CI_Controller {
public function index()
{
redirect('dashboard');
}
}



I'm starting to think the problem might be in some other file which are being loaded before this controller file. Hence, it's saying that the output started from Line 1.


Answer



I managed to solve it.



I referred to this SO Answer and it worked. Not sure how can the main index.php be the trouble maker. Anyone care to explain it please?


What techniques are used by directors to make an actor cry?

I have always wondered what techniques directors use to get amateur actors, especially young ones, to cry. How can someone surrounded with so many film crew and cameras can concentrate enough and feel so sad that s/he can possibly burst into tears?

In general, is crying in a movie scene (with real tears) something that can be learned by practice or is it something that only talented people can perform?


Answer


It's the same for professional as well as amateur actors - I've known some pros that have a hard time reaching the crying point.


One technique includes allowing the actor to focus on the saddest memory they have, in solitude, then pull them out for the take. I recall seeing a documentary that showed Gary Oldman looking through a book of photos of his family (he had just split from Uma Thurman) on the set of Dracula that got him to the point of sorrow that Coppola wanted.


I have worked with some amazing amateur actors that would work themselves up into a state before filming. One actress imagined something terrible happening to her sister, and she delivered a very powerful performance (that got the crew all choked up).


If all else fails, the vapors from an onion can induce tears (but also cause redness), or a few drops of glycerin in the corners of the eyes can be released - but nothing beats real tears.


I have also heard of directors bullying/belittling actors to the point of melt-down, just to get the shot they want. But that's a pretty extreme way to go about it.


r - Another Follow up to “add values to a reactive table in Shiny” when we already have a dataframe



I would like to extend this application when data frame exists at the beginning. To be honest, my question is bigger than this where you can find the problem in following link: How to add a new row to uploaded datatable in shiny



Via this question, I am gonna chase the big picture with minors.

I have a currently data frame, 2 columns and 3 rows. First column indicates the current date, other one is to be calculated. new row should be appeared like (Current Date - Like in Excel eg. 11.02.2015-, [Input$1 + "perivious value of column2's row"])



However, I have problem about showing the system date. Additionaly, I cannot produce a new line which gives a warning in newLine!



second version: data can be uploaded. with error: Error in read.table(file = file, header = header, sep = sep, quote = quote, :
'file' must be a character string or connection
Warning: Unhandled error in observer: object of type 'closure' is not subsettable
observeEvent(input$update)



library(shiny)

library(gtools)
runApp(
list(
ui = fluidPage(

pageWithSidebar(
headerPanel("Adding entries to table"),
sidebarPanel(
wellPanel(fileInput('file1', 'Choose Planning File:', accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv'), multiple = FALSE),



selectInput(inputId = "location",label = "Choose Location",
choices = c('All','Lobau'='LOB', 'Graz'='GRA', 'St. Valentin'='VAL'), selected = "GRA"),
selectInput(inputId = "product",label = "Choose Product",
choices = c('All','Gasoline'='OK', 'Diesel'='DK'), selected = "DK")),

numericInput("spotQuantity", "Enter the Spot Quantity",value=0),

actionButton("action","Confirm Spot Sales"),



numericInput("num2", "Column 2", value = 0),

actionButton("update", "Update Table")),
mainPanel(tableOutput("table1")))
),
server = function(input, output, session) {

values <- reactive({ #
#file.choose()

dm <- as.data.frame(read.csv(input$file1$datapath, sep=";",check.names = FALSE))


})

addData <- observeEvent(input$update, {
values$dm <- isolate({
newLine <- data.frame('Month'=1,'Day ID'=2,'Day'="28-11-2012",'starting inventory'=2,'planned (in kTO)'=2,'lifted (in kTO)'="2",'replenishment (in kTO)'="2", 'Product'="OK",'Location'="GRA", check.names=F)
rbind.data.frame(values$dm,newLine)
})

})

output$table1 <- renderTable({
values()
})
}


)
)



Answer



There are multiple issues with your code. You start reactiveValues but you never assign anything to it so no data could hope to be reactive. Also, you likely want to use observeEvent so that each time you hit the Update button you get a response. You can also isolate blocks of code. Furthermore, you should use a data.frame for your new data as the 'type' of the data matters (i.e. numeric, character, etc.). The following works well for me.



library(shiny)

runApp(
list(
ui = fluidPage(

pageWithSidebar(

headerPanel("Adding entries to table"),
sidebarPanel(
numericInput("num2", "Column 2", value = 0),

actionButton("update", "Update Table")),
mainPanel(tableOutput("table1")))
),
server = function(input, output, session) {

values <- reactiveValues(

dm = data.frame(Date = as.Date(c("2015-05-10", "2015-10-07", "2015-03-26","2015-07-18")),
Col2 = c(160, 150, 121, 93))
)

addData <- observeEvent(input$update, {
values$dm <- isolate({
newLine <- data.frame(Date = format(Sys.time(), "%Y-%m-%d"),
Col2 = tail(values$dm$Col2, n=1) - 4)
rbind(values$dm,newLine)
})

})


output$table1 <- renderTable({
values$dm
})
}
)
)


php - Warning: Cannot modify header information - headers already sent by ERROR






Possible Duplicate:
Headers already sent by PHP







I've been struggling with this error for a while now.



To start with, I just thought it was white space, but after further research I think it might be a problem similar to this:




Look for any statements that could send output to the user before this header statement. If you find one or more, change your code to move the header statement before them. Complex conditional statements may complicate the issue, but they may also help solve the problem. Consider a conditional expression at the top of the PHP script that determines the header value as early as possible and sets it there.




I'm guessing the include header is causing the problem along with the header(), but I'm not sure how to rearrange the code to get rid of this error.




How do I remove the error?



    $username = $password = $token = $fName = "";

include_once 'header.php';

if (isset($_POST['username']) && isset($_POST['password']))
$username = sanitizeString($_POST['username']);


$password = sanitizeString($_POST['password']); //Set temporary username and password variables
$token = md5("$password"); //Encrypt temporary password

if ($username != 'admin')
{
header("Location:summary.php");
}
elseif($username == 'admin')
{
header("Location:admin.php");

}
elseif($username == '')
{
header("Location:index.php");
}
else
die ("

Invalid username or password.

");

if ($username == "" || $token == "")
{

echo "

Please enter your username and password

";
}
else
{
$query = "SELECT * FROM members WHERE username='$username'AND password = '$token'"; //Look in table for username entered
$result = mysql_query($query);
if (!$result)
die ("Database access failed: " . mysql_error());
elseif (mysql_num_rows($result) > 0)
{

$row = mysql_fetch_row($result);
$_SESSION['username'] = $username; //Set session variables
$_SESSION['password'] = $token;

$fName = $row[0];
}
}
?>

Answer




The long-term answer is that all output from your PHP scripts should be buffered in variables. This includes headers and body output. Then at the end of your scripts do any output you need.



The very quick fix for your problem will be to add



ob_start();


as the very first thing in your script, if you only need it in this one script. If you need it in all your scripts add it as the very first thing in your header.php file.



This turns on PHP's output buffering feature. In PHP when you output something (do an echo or print) it has to send the HTTP headers at that time. If you turn on output buffering you can output in the script but PHP doesn't have to send the headers until the buffer is flushed. If you turn it on and don't turn it off PHP will automatically flush everything in the buffer after the script finishes running. There really is no harm in just turning it on in almost all cases and could give you a small performance increase under some configurations.




If you have access to change your php.ini configuration file you can find and change or add the following



output_buffering = On


This will turn output buffering out without the need to call ob_start().



To find out more about output buffering check out http://php.net/manual/en/book.outcontrol.php


c++ - ctags does not parse stdio.h properly



I am trying to use ctags with VIM, and I am a newbie to both. In order to test the extent to which ctags could be useful I decided to put it through a very simple test, namely to parse the headers in /usr/include so that I could autocomplete some very basic functions.



When I run the command



 ctags  --c++-kinds=+p --fields=+iaS -f ~/.tags/tags /usr/include/*.h



then the output prints




BUFSIZ /usr/include/stdio.h 108;" d
EOF /usr/include/stdio.h 115;" d
FILE /usr/include/stdio.h /^typedef struct _IO_FILE FILE;$/;" t typeref:struct:_IO_FILE
FSETLOCKING_BYCALLER /usr/include/stdio_ext.h /^ FSETLOCKING_BYCALLER$/;" e enum:__anon122
FSETLOCKING_BYCALLER /usr/include/stdio_ext.h 39;" d
FSETLOCKING_INTERNAL /usr/include/stdio_ext.h /^ FSETLOCKING_INTERNAL,$/;" e enum:__anon122

FSETLOCKING_INTERNAL /usr/include/stdio_ext.h 36;" d
FSETLOCKING_QUERY /usr/include/stdio_ext.h /^ FSETLOCKING_QUERY = 0,$/;" e enum:__anon122
FSETLOCKING_QUERY /usr/include/stdio_ext.h 32;" d
P_tmpdir /usr/include/stdio.h 128;" d
SEEK_CUR /usr/include/stdio.h 122;" d
SEEK_END /usr/include/stdio.h 123;" d
SEEK_SET /usr/include/stdio.h 121;" d
_IOFBF /usr/include/stdio.h 101;" d
_IOLBF /usr/include/stdio.h 102;" d
_IONBF /usr/include/stdio.h 103;" d

_IO_STDIO /usr/include/libio.h 165;" d
_IO_STDIO_H /usr/include/libio.h 30;" d
_OLD_STDIO_MAGIC /usr/include/libio.h 121;" d
_STDIO_EXT_H /usr/include/stdio_ext.h 24;" d
_STDIO_H /usr/include/stdio.h 27;" d
_STDIO_USES_IOSTREAM /usr/include/stdio.h 73;" d
_VA_LIST_DEFINED /usr/include/stdio.h 81;" d
__FILE /usr/include/stdio.h /^typedef struct _IO_FILE __FILE;$/;" t typeref:struct:_IO_FILE
__FILE_defined /usr/include/stdio.h 57;" d
____FILE_defined /usr/include/stdio.h 67;" d

__need_FILE /usr/include/stdio.h 37;" d
__need_FILE /usr/include/stdio.h 59;" d
__need_NULL /usr/include/stdio.h 33;" d
__need___FILE /usr/include/stdio.h 38;" d
__need___FILE /usr/include/stdio.h 69;" d
__need_getopt /usr/include/stdio.h 902;" d
__need_size_t /usr/include/stdio.h 32;" d
__wur /usr/include/stdio.h /^ _IO_cookie_io_functions_t __io_funcs) __THROW __wur;$/;" v
__wur /usr/include/stdio.h /^ __THROW __attribute__ ((__format__ (__printf__, 2, 0))) __wur;$/;" v
__wur /usr/include/stdio.h /^ __THROW __attribute__ ((__format__ (__printf__, 2, 3))) __wur;$/;" v

__wur /usr/include/stdio.h /^ __THROW __attribute_malloc__ __wur;$/;" v
__wur /usr/include/stdio.h /^ __THROW __wur;$/;" v
__wur /usr/include/stdio.h /^extern FILE *fdopen (int __fd, __const char *__modes) __THROW __wur;$/;" v
__wur /usr/include/stdio.h /^extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW __wur;$/;" v
__wur /usr/include/stdio.h /^extern char *tmpnam (char *__s) __THROW __wur;$/;" v
__wur /usr/include/stdio.h /^extern char *tmpnam_r (char *__s) __THROW __wur;$/;" v
__wur /usr/include/stdio.h /^extern int feof (FILE *__stream) __THROW __wur;$/;" v
__wur /usr/include/stdio.h /^extern int feof_unlocked (FILE *__stream) __THROW __wur;$/;" v
__wur /usr/include/stdio.h /^extern int ferror (FILE *__stream) __THROW __wur;$/;" v
__wur /usr/include/stdio.h /^extern int ferror_unlocked (FILE *__stream) __THROW __wur;$/;" v

__wur /usr/include/stdio.h /^extern int fileno (FILE *__stream) __THROW __wur;$/;" v
__wur /usr/include/stdio.h /^extern int fileno_unlocked (FILE *__stream) __THROW __wur;$/;" v
__wur /usr/include/stdio.h /^extern int ftrylockfile (FILE *__stream) __THROW __wur;$/;" v
_flushlbf /usr/include/stdio_ext.h /^extern void _flushlbf (void);$/;" p signature:(void)
cuserid /usr/include/stdio.h /^extern char *cuserid (char *__s);$/;" p signature:(char *__s)
dprintf /usr/include/stdio.h /^extern int dprintf (int __fd, __const char *__restrict __fmt, ...)$/;" p signature:(int __fd, __const char *__restrict __fmt, ...)
fclose /usr/include/stdio.h /^extern int fclose (FILE *__stream);$/;" p signature:(FILE *__stream)
fcloseall /usr/include/stdio.h /^extern int fcloseall (void);$/;" p signature:(void)
fflush /usr/include/stdio.h /^extern int fflush (FILE *__stream);$/;" p signature:(FILE *__stream)
fflush_unlocked /usr/include/stdio.h /^extern int fflush_unlocked (FILE *__stream);$/;" p signature:(FILE *__stream)

fgetc /usr/include/stdio.h /^extern int fgetc (FILE *__stream);$/;" p signature:(FILE *__stream)
fgetc_unlocked /usr/include/stdio.h /^extern int fgetc_unlocked (FILE *__stream);$/;" p signature:(FILE *__stream)
fgetpos /usr/include/stdio.h /^extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);$/;" p signature:(FILE *__restrict __stream, fpos_t *__restrict __pos)
fgetpos64 /usr/include/stdio.h /^extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos);$/;" p signature:(FILE *__restrict __stream, fpos64_t *__restrict __pos)
fpos64_t /usr/include/stdio.h /^typedef _G_fpos64_t fpos64_t;$/;" t
fpos_t /usr/include/stdio.h /^typedef _G_fpos_t fpos_t;$/;" t
fprintf /usr/include/stdio.h /^extern int fprintf (FILE *__restrict __stream,$/;" p signature:(FILE *__restrict __stream, __const char *__restrict __format, ...)
fputc /usr/include/stdio.h /^extern int fputc (int __c, FILE *__stream);$/;" p signature:(int __c, FILE *__stream)
fputc_unlocked /usr/include/stdio.h /^extern int fputc_unlocked (int __c, FILE *__stream);$/;" p signature:(int __c, FILE *__stream)
fputs /usr/include/stdio.h /^extern int fputs (__const char *__restrict __s, FILE *__restrict __stream);$/;" p signature:(__const char *__restrict __s, FILE *__restrict __stream)

fputs_unlocked /usr/include/stdio.h /^extern int fputs_unlocked (__const char *__restrict __s,$/;" p signature:(__const char *__restrict __s, FILE *__restrict __stream)
fscanf /usr/include/stdio.h 441;" d
fseek /usr/include/stdio.h /^extern int fseek (FILE *__stream, long int __off, int __whence);$/;" p signature:(FILE *__stream, long int __off, int __whence)
fseeko /usr/include/stdio.h /^extern int fseeko (FILE *__stream, __off_t __off, int __whence);$/;" p signature:(FILE *__stream, __off_t __off, int __whence)
fseeko64 /usr/include/stdio.h /^extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence);$/;" p signature:(FILE *__stream, __off64_t __off, int __whence)
fsetpos /usr/include/stdio.h /^extern int fsetpos (FILE *__stream, __const fpos_t *__pos);$/;" p signature:(FILE *__stream, __const fpos_t *__pos)
fsetpos64 /usr/include/stdio.h /^extern int fsetpos64 (FILE *__stream, __const fpos64_t *__pos);$/;" p signature:(FILE *__stream, __const fpos64_t *__pos)
getc /usr/include/stdio.h /^extern int getc (FILE *__stream);$/;" p signature:(FILE *__stream)
getc /usr/include/stdio.h 527;" d
getc_unlocked /usr/include/stdio.h /^extern int getc_unlocked (FILE *__stream);$/;" p signature:(FILE *__stream)

getchar /usr/include/stdio.h /^extern int getchar (void);$/;" p signature:(void)
getchar_unlocked /usr/include/stdio.h /^extern int getchar_unlocked (void);$/;" p signature:(void)
getw /usr/include/stdio.h /^extern int getw (FILE *__stream);$/;" p signature:(FILE *__stream)
jpeg_stdio_dest /usr/include/jpeglib.h /^EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));$/;" p signature:(j_compress_ptr cinfo, FILE * outfile)
jpeg_stdio_dest /usr/include/jpeglib.h 841;" d
jpeg_stdio_src /usr/include/jpeglib.h /^EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));$/;" p signature:(j_decompress_ptr cinfo, FILE * infile)
jpeg_stdio_src /usr/include/jpeglib.h 842;" d
pclose /usr/include/stdio.h /^extern int pclose (FILE *__stream);$/;" p signature:(FILE *__stream)
perror /usr/include/stdio.h /^extern void perror (__const char *__s);$/;" p signature:(__const char *__s)
printf /usr/include/stdio.h /^extern int printf (__const char *__restrict __format, ...);$/;" p signature:(__const char *__restrict __format, ...)

putc /usr/include/stdio.h /^extern int putc (int __c, FILE *__stream);$/;" p signature:(int __c, FILE *__stream)
putc /usr/include/stdio.h 569;" d
putc_unlocked /usr/include/stdio.h /^extern int putc_unlocked (int __c, FILE *__stream);$/;" p signature:(int __c, FILE *__stream)
putchar /usr/include/stdio.h /^extern int putchar (int __c);$/;" p signature:(int __c)
putchar_unlocked /usr/include/stdio.h /^extern int putchar_unlocked (int __c);$/;" p signature:(int __c)
puts /usr/include/stdio.h /^extern int puts (__const char *__s);$/;" p signature:(__const char *__s)
putw /usr/include/stdio.h /^extern int putw (int __w, FILE *__stream);$/;" p signature:(int __w, FILE *__stream)
rewind /usr/include/stdio.h /^extern void rewind (FILE *__stream);$/;" p signature:(FILE *__stream)
scanf /usr/include/stdio.h 442;" d
sscanf /usr/include/stdio.h 443;" d

stderr /usr/include/stdio.h 152;" d
stdin /usr/include/stdio.h 150;" d
stdout /usr/include/stdio.h 151;" d
ungetc /usr/include/stdio.h /^extern int ungetc (int __c, FILE *__stream);$/;" p signature:(int __c, FILE *__stream)
va_list /usr/include/stdio.h /^typedef _G_va_list va_list;$/;" t
vdprintf /usr/include/stdio.h /^extern int vdprintf (int __fd, __const char *__restrict __fmt,$/;" p signature:(int __fd, __const char *__restrict __fmt, _G_va_list __arg)
vfprintf /usr/include/stdio.h /^extern int vfprintf (FILE *__restrict __s, __const char *__restrict __format,$/;" p signature:(FILE *__restrict __s, __const char *__restrict __format, _G_va_list __arg)
vfscanf /usr/include/stdio.h 500;" d
vprintf /usr/include/stdio.h /^extern int vprintf (__const char *__restrict __format, _G_va_list __arg);$/;" p signature:(__const char *__restrict __format, _G_va_list __arg)
vscanf /usr/include/stdio.h 501;" d

vsscanf /usr/include/stdio.h 502;" d


so clearly ctags missed some very obvious functions like fopen, yet it included functions like fclose. Is there some option I am missing when I am parsing with ctags?


Answer



Add a -I__wur to your ctags command and you'll get the result you're after.
__wur is a macro for __attribute__ ((__warn_unused_result__))



For a more thurough explanation, see:




http://sourceforge.net/mailarchive/message.php?msg_name=48A7FF60.9080609%40sina.com


film techniques - Walking around someone who is moving in Slow Motion?

In the "Buffy the Vampire Slayer" series musical episode, "Once More With Feeling", during the Giles and Buffy fight montage (Song: 'Standing in the Way') there is a scene where Buffy is hitting a punching bag in slow motion. Giles in regular speed is singing, he walks in front of her and then behind her.


I can understand how one layer is through a green screen. I'm not entirely sure how it worked for two layers in real time.


Can anyone give a quick synopses how this worked?


Answer


Can't recall the particular shot, but the effect is commonly created using multiple composite layers


Typically there will be three layers



  • the person walking in real time,

  • the person in slow time,

  • the background


Each is filmed separately as individual layers.


For the "people" layers only the people (and I guess the punchbag in this case) are used - the rest of the layer is transparent.


Now in editing a composite is done with the background layer, then the Buffy layer, then the Giles layer. When Giles moves behind Buffy the editor simply swaps over the order of those two layers at that point. So



  • Background > Buffy > Giles


Becomes:



  • Background > Giles > Buffy


The result is that they then appear behind.


Filming wise this probably means that both actors were acting in front of a Chroma key (green) screen. Also if the camera was moving in the shot then a motion controlled camera is likely to ensure that each element of the composite was filmed from the same angle throughout the shot.


How does 'this' works in javascript?

hi i am a little confusion on how exactly this works in javascript.Based on this example:



var myFunction = function(){
function testMe(){
console.log(this) --------> DOMwindow
}
console.log(this) ---------> myFunction
}


var myvariable = new myFunction();


What is happening here?

python - Return or yield from a function that calls a generator?

I have a generator generator and also a convenience method to it - generate_all.



def generator(some_list):

for i in some_list:
yield do_something(i)

def generate_all():
some_list = get_the_list()
return generator(some_list) # <-- Is this supposed to be return or yield?


Should generate_all return or yield? I want the users of both methods to use it the same, i.e.




for x in generate_all()


should be equal to



some_list = get_the_list()
for x in generate(some_list)

setTimeout with Loop in JavaScript




I have a very trivial question. For a simple loop with setTimeout, like this:



for (var count = 0; count < 3; count++) {
setTimeout(function() {
alert("Count = " + count);
}, 1000 * count);
}


console gives an output like this:




Count = 3
Count = 3
Count = 3


Not sure why the output like this. Anyone could explain, please?


Answer



This has to do with how scoping and hoisting is being treated in JavaScript.




What happens in your code is that the JS engine modifies your code to this:



var count;

for (count = 0; count < 3; count++) {
setTimeout(function() {
alert("Count = " + count);
}, 1000 * count);
}



And when setTimeout() is being run it will first look in it's own scope after count but it won't find it so then it'll start looking in the functions that closes (this is called closures) over the setTimeout function until it finds the var count statement, which will have the value 3 since loop will have finished before the first timeout function has been executed.



More code-ily explained your code actually looks like this:



//first iteration
var count = 0; //this is 1 because of count++ in your for loop.

for (count = 0; count < 3; count++) {
setTimeout(function() {

alert("Count = " + 1);
}, 1000 * 1);
}
count = count + 1; //count = 1

//second iteration
var count = 1;

for (count = 0; count < 3; count++) {
setTimeout(function() {

alert("Count = " + 2);
}, 1000 * 2);
}
count = count + 1; //count = 2

//third iteration
var count = 2;

for (count = 0; count < 3; count++) {
setTimeout(function() {

alert("Count = " + 3);
}, 1000 * 3);
}
count = count + 1; //count = 3

//after 1000 ms
window.setTimeout(alert(count));
//after 2000 ms
window.setTimeout(alert(count));
//after 3000 ms

window.setTimeout(alert(count));

Tuesday, 15 May 2018

php - __callStatic(): instantiating objects from static context?




I am confused about how "static" and "dynamic" functions and objects in PHP work together especially with regards to __callStatic().




How __callStatic() works:



You can have a normal class MyClass, where within the class you can
put a static function called __callStatic(), which gets called only
when MyClass doesn't have a static function by the name you want.




i.e. I call MyClass::newFunction();



newFunction() is called statically but MyClass does not
have it declared. So, then __callStatic() gets called and
inside you can say



$myObject=new SomeOtherClass();
$myObject->newFunction();



which calls the function you wanted but on some other object.




Short Version:



In other words, __callStatic() does this:



MyClass::newFunction();



which is hiding this:



(new SomeOtherClass())->newFunction();


Say what now? What looks like code calling a static function from a class, turns out to be calling that function from some other class and calling it via instantiation, and not statically.



Explain this, please!



Why was it done? Can you do anything like this elsewhere, like C++ or Java? I am looking for short & concise, but informative explanation on static and dynamic functions in languages, and in this case whether __callStatic() violates or conforms to the big picture of Language constructs. Or is it a new language construct entirely.



Answer



__callStatic() provides developers with possibility to react on static method calls even if that methods don't exist or aren't accessible from outside of the class ( being protected). This is useful for dynamic, generic code generation.






Example: You have this class:



class Test {

protected static function myProtected($test) {

var_dump(__METHOD__, $test);
}

public static function __callStatic($method, $args) {
switch($method) {
case 'foo' :
echo 'You have called foo()';
var_dump($args);
break;


case 'helloWorld':
echo 'Hello ' . $args[0];
break;

case 'myProtected':
return call_user_func_array(
array(get_called_class(), 'myProtected'),
$args
);
break;

}

}

}


Try to call:



// these ones does not *really* exist

Test::foo('bar');
Test::helloWorld('hek2mgl');

// this one wouldn't be accessible
Test::myProtected('foo');

casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...