delay

How can I stop PHP sleep() affecting my whole PHP code?

强颜欢笑 提交于 2019-11-27 09:10:40
So, on my arcade, howlingdoggames.com. I have a points system that gives you a point every time you visit a page with a game on, now, to reduce abuse of this, I would like to make some sort of delay, so its only awarded after 45 seconds. Here's what i've tried. ... if ($_SESSION['lastgame'] != $gameid);{ sleep(45); $points = $points + $game_points; $_SESSION['lastgame'] = $gameid; } ... But, this just seems to halt my whole website for 45 seconds, because this is in the index.php file, as with alot of the other code to my site. Is there anyway I can isolate that bit of code, so it only makes

How to get millisecond and microsecond-resolution timestamps in Python [duplicate]

蓝咒 提交于 2019-11-27 09:08:12
This question already has an answer here: High-precision clock in Python 13 answers I finally figured this out and would like to share the knowledge and save someone a bunch of time, so see my answer below. However, I still need answers for Linux, so please answer if you know, as my code in my answer is for Windows only. UPDATE: I've figured it out for Linux too, including for pre-Python 3.3 (ex: for the Raspberry Pi), and I've posted my new module/code in my answer below. My original question: How do I get millisecond and microsecond-resolution timestamps in Python? I'd also like the Arduino

Add a delay after executing each iteration with forEach loop

旧巷老猫 提交于 2019-11-27 08:47:13
Is there an easy way to slow down the iteration in a forEach (with plain javascript)? For example: var items = document.querySelector('.item'); items.forEach(function(el) { // do stuff with el and pause before the next el; }); What you want to achieve is totally possible with Array#forEach — although in a different way you might think of it. You can not do a thing like this: var array = ['some', 'array', 'containing', 'words']; array.forEach(function (el) { console.log(el); wait(1000); // wait 1000 milliseconds }); console.log('Loop finished.'); ... and get the output: some array // one second

implement time delay in c

落花浮王杯 提交于 2019-11-27 08:15:08
I don't know exactly how to word a search for this.. so I haven't had any luck finding anything.. :S I need to implement a time delay in C. for example I want to do some stuff, then wait say 1 minute, then continue on doing stuff. Did that make sense? Can anyone help me out? In standard C (C99), you can use time() to do this, something like: #include <time.h> : void waitFor (unsigned int secs) { unsigned int retTime = time(0) + secs; // Get finishing time. while (time(0) < retTime); // Loop until it arrives. } By the way, this assumes time() returns a 1-second resolution value. I don't think

Ruby on Rails send_file doesn't work until i refresh the page?

北慕城南 提交于 2019-11-27 07:17:17
问题 I am working on a Rails server which I can download my locally stored movies and anime etc from. This is kind of working but when I click the download link I have to refresh the page in order for the download to actually start. This is the controller that handles the download: class DownloadController < ApplicationController def index @title = params[:title] @name = params[:name] @path = '/media/sf_Anime,_VN,_LN/Watching, not watched yet/'+@title+'/'+@name send_file( @path ) end end and this

How to create a delay in Swing

若如初见. 提交于 2019-11-27 05:34:57
I made a blackjack game, and I want the AI player to pause between taking cards. I tried simply using Thread.sleep(x), but that makes it freeze until the AI player is done taking all of his cards. I know that Swing is not thread safe, so I looked at Timers, but I could not understand how I could use one for this. Here is my current code: while (JB.total < 21) { try { Thread.sleep(1000); } catch (InterruptedException ex) { System.out.println("Oh noes!"); } switch (getJBTable(JB.total, JB.aces > 0)) { case 0: JB.hit(); break; case 1: break done; case 2: JB.hit(); JB.bet *= 2; break done; } } BTW

Idiomatic jQuery delayed event (only after a short pause in typing)? (aka timewatch/typewatch/keywatch)

家住魔仙堡 提交于 2019-11-27 05:05:56
问题 Here is some jQuery for a search box that I expect is actually an antipattern, and am sure there is a much better solution for that I would love to be pointed towards: I will describe it in comments then just give the code, since the comments may be more clear and simple than the code: // set up a function call on keypress. // function call has a delay before the main event occurs. // When keypress function is called, wipe any previously queued events and make a new one at the standard delay

RxJava delay for each item of list emitted

半腔热情 提交于 2019-11-27 03:32:55
I'm struggling to implement something I assumed would be fairly simple in Rx. I have a list of items, and I want to have each item emitted with a delay. It seems the Rx delay() operator just shifts the emission of all items by the specified delay, not each individual item. Here's some testing code. It groups items in a list. Each group should then have a delay applied before being emitted. Observable.range(1, 5) .groupBy(n -> n % 5) .flatMap(g -> g.toList()) .delay(50, TimeUnit.MILLISECONDS) .doOnNext(item -> { System.out.println(System.currentTimeMillis() - timeNow); System.out.println(item);

Java Delay/Wait

被刻印的时光 ゝ 提交于 2019-11-27 03:14:59
问题 How do I delay a while loop to 1 second intervals without slowing down the entire code / computer it's running on to the one second delay (just the one little loop). 回答1: Thread.sleep(1000); // do nothing for 1000 miliseconds (1 second) 回答2: It seems your loop runs on Main thread and if you do sleep on that thread it will pause the app (since there is only one thread which has been paused), to overcome this you can put this code in new Thread that runs parallely try{ Thread.sleep(1000);

How to put a delay on AngularJS instant search?

冷暖自知 提交于 2019-11-27 02:27:28
I have a performance issue that I can't seem to address. I have an instant search but it's somewhat laggy, since it starts searching on each keyup() . JS: var App = angular.module('App', []); App.controller('DisplayController', function($scope, $http) { $http.get('data.json').then(function(result){ $scope.entries = result.data; }); }); HTML: <input id="searchText" type="search" placeholder="live search..." ng-model="searchText" /> <div class="entry" ng-repeat="entry in entries | filter:searchText"> <span>{{entry.content}}</span> </div> The JSON data isn't even that large, 300KB only, I think