set<int> s;
s.insert(1);
s.insert(2);
...
s.insert(n);
I wonder how much time it takes for s.find(k) where k is a number from 1..n?
I assume it is log(n). Is it correct?
So I've already written a function that works (based on underscores throttle) for functions that don't take in a parameter, but I'd like to make it generic enough to pass in a function with a variable number of parameters. Here's what I have:
(function () {
var lastTime = new Date().getTime();
function foo() {
var newTime = new Date().getTime();
var gap = newTime - lastTime; // Travels up scope chain to use parents lastTime. Function has access to variables declared in the same scope
console.log('foo called, gap:' + gap);
lastTime = newTime; // Updates lastTime
//console.log(x);
//x++;
}
var throttle = function(func, wait) {
var result;
var timeout = null; // flag updated through closure
var previous = 0; // time last run updated through closure
return function() { //func, wait, timeout, previous available through scope
var now = new Date().getTime();
var remaining = wait - (now - previous);
if (remaining <= 0) {
clearTimeout(timeout);
timeout = null;
previous = now;
result = func.apply(this, arguments); //func is available through closure
}
return result;
};
};
document.addEventListener("scroll", throttle(foo, 1000));
//document.addEventListener("scroll", throttle(foo(5), 2000));
}());
But I'd like to modify foo to foo(x) and get this to work
(function () {
var lastTime = new Date().getTime();
function foo(x) {
var newTime = new Date().getTime();
var gap = newTime - lastTime; // Travels up scope chain to use parents lastTime. Function has access to variables declared in the same scope
console.log('foo called, gap:' + gap);
lastTime = newTime; // Updates lastTime
console.log(x);
x++;
}
var throttle = function(func, wait) {
var result;
var timeout = null; // flag updated through closure
var previous = 0; // time last run updated through closure
return function() { //func, wait, timeout, previous available through scope
var now = new Date().getTime();
var remaining = wait - (now - previous);
if (remaining <= 0) {
clearTimeout(timeout);
timeout = null;
previous = now;
result = func.apply(this, arguments); //func is available through closure
}
return result;
};
};
document.addEventListener("scroll", throttle(foo(5), 2000));
}());
NHibernate_reference.pdf, page 26:
Note that ILifecycle.OnUpdate() is not called every time the object's persistent state is updated. It is called only when a
transient object is passed to ISession.Update().
Why it design link that?
I have been developing websites in n-tier structure and so far my requirements are fulfilled. But as powerful frameworks like Zend Framework, symphony are getting popular, I wonder how to know if it is time to shift to a framework?
I am in a kind of dilemma? Can anyone suggest me the right option !
Hi, we're in need to stop the user session in an ASP.NET site after some time(say 20 mins).
We know we can use a timer and code every page to expire on the timer tick, but we're searching a faster way, maybe through an IIS configuration?
Is there a built in way to do such things?
We're using ASP.NET 2.0, Framework 3.5, IIS 6, c#.
TY.
What can i do to fix this? Drop permission properties?
I have a large folder with 100k files. I moved it into my archive folder and its taking forever to move. Why is that? I know on XP it takes <1sec but not on windows 7. I am sure its a permission thing, is there a way i can disable it and make it faster?
-edit- I am moving the folder into another in the same drive/partition. In XP. AFAIK it just moves the folder file from one place to another. In windows 7, it seems like its touching something in every file when i move it.
Simplified table structure (the tables can't be merged at this time):
TableA:
dts_received (datetime)
dts_completed (datetime)
task_a (varchar)
TableB:
dts_started (datetime)
task_b (varchar)
What I would like to do is determine how long a task took to complete.
The join parameter would be something like
ON task_a = task_b AND dts_completed < dts_started
The issue is that there may be multiple date-times that occur after the dts_completed.
How do I create a join that only returns the first tableB-datetime that occurs after the tableA-datetime?
In MySQL you can insert multiple rows like this:
INSERT INTO 'tablename' ('column1', 'column2') VALUES
('data1', 'data2'),
('data1', 'data2'),
('data1', 'data2'),
('data1', 'data2');
However, I am getting an error when I try to do something like this. Is it possible to insert multiple rows at a time in an SQLite database? What is the syntax to do that?
hi,
I am creating one desktop application in which I want to track user activity on the system like opened Microsoft Excel with file name and worked for ... much of time on that..
I want to create on xml file to maintain that log.
Please provide me help on that.
Hello,
I have a problem with my vpn connections, my ISP requires me to connect to a private vpn server of it's own in order to connect to internet, im connected to main network via WiFi,
but i also want to connect to another VPN network of my choice (to bypass internet limitation in my country of course), i am able to do that in Windows, but its not working in Mac OS X Snow Leopard
second vpn connecion type is PPTP / CHAP
How can i do that?
as u see in the pic, both vpn's are connected, first one is for main internet which is working properly , second one is also connected but its not affecting anything. its just connected.
http://www.freezpic.com/pics/a5231c3e80501a3c25430f43c1ef5856.png
Hi. I'm having some difficulty with drawing a line on a map. I'm basically drawing it etc. but when I select other tab and then come back to the "map tab" the line disappears. How can I prevent that so the line stays there all the time?
Hi All,
I want to know if I can find/reach UI components of running application under Android OS.
it is possible to catch the Button/DDL/.. that was clicked by the user in real-time,
example from other subject(web):
In browser I can listen to the events and catch the DOM object that was clicked,
in this way I can save the DOM object data.
catching UI components that was changed by the user will give the option to save UI componentdata, and to perform the user actions automatic.
Thanks.
How much time, and what basic steps, are involved in integrating the "Facebook Like" feature into an existing e-commerce site?
Let's say we are only interested in the feature at the product details level and have approximately 5 different product details areas.
Any recommended tutorials perhaps?
Thanks
I need to display the FIFA world Cup 2010 schedule on my Drupal website. But what I want is that each visitor should be able to see the time for the upcoming matching as per his/her own geographic location . How can this be done ?Any suggestions would be welcomed. Thanks for reading this through.
So given a static type in your code you can do
var defaultMyTypeVal = default(MyType);
How would you do the same thing given a variable of Type so you can use it during runtime?
In other words how do I implement the following method without a bunch of if statements or using Generics (because I will not know the type I'm passing into the method at compile time)?
public object GetDefaultValueForType(Type type) {
....
}
I have been developing websites in n-tier structure and so far my requirements are fulfilled. But as powerful frameworks like Zend Framework, symphony are getting popular, I wonder how to know if it is time to shift to a framework?
I am in a kind of dilemma? Can anyone suggest me the right option !
I've been having problems with my internet connection over the past weeks (intermittent disconnections, slow transfers, etc), and my provider keeps telling me that the problem is not on their end.
I have cablemodem with a wifi router (this router was not provided by them).
The router is quite old (DIR-300), so I'm starting to wonder if it could be the issue and if I should replace it.
Is it possible that it is the cause? Can they become so outdated that they cause intermittent interruptions of service?
If I reset the modem and the router, they work fine for a few hours, but the problems starts again after a while.
We wrote a stored procedure for selecting a single record from DB at a time. Using the same stored procedure to read 2000 records it takes 4 seconds. Is there any way to optimize it? (like single stored procedure for 2000 records)
Thanks & Regards
Padma
This is a n00b question, sorry. I have a site running on a VPS, now I want to be able to receive mails at [email protected]. How do I need to set up the server? And how should I set up the mail client on my PC to receive those mails? The server is running CentOS/RHEL.
I'll really appreciate if someone shed some light on the steps that need to be taken. It will be really helpful. Thanks in advance!
Is there an API that works for pre OS 3.2 for getting the current time of a video being played back? There's this one
http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MPMediaPlayback_protocol/Reference/Reference.html
But it's 3.2 or later....
Is there any way to do this with the MPMoviePlayerController API?
How to record Audio and Video at the same time into flv in Adobe air 2.0 ? So that Video and Audio will be sinchronised?
Open Source libs and
Blog aricales are wellcomed!)
A lot of developers get an exciting idea and they create a project, but eventually life gets in the way and you have to stop working on the project. Some time passes and you know you should probably get back to work on the project, but you just can't make yourself do it.
What do you do to force yourself to get back to work on a project you have not touched in a while?
How to create a cron job in PHP for getting the update of modified date and time of files/folders?
I am a newbie to create a cron job how to get started?