Showing posts with label timer. Show all posts
Showing posts with label timer. Show all posts

Monday, December 19, 2016

Time seconds increment on class of elements


function updateAge() {
 $('.age').each(function(){
  var age=$(this).text();
  age++;
  $(this).text(age);
 })
}

$(document).ready(function(){
  console.log('document ready'); 
  setInterval(updateAge, 1000); 
})

Thursday, September 4, 2014

Javascript counter and location.reload


 var interval = "";
 var incrementVar = 0;
 function increment(){
        incrementVar++;
        console.log(incrementVar);
        if(incrementVar>30) {
    location.reload(); 
    window.clearInterval(interval);
    incrementVar = 0;
         }
          
    }

   $(document).ready(function(){
    interval = setInterval( increment, 1000);
   }) 

Friday, December 30, 2011

Basic timer in Python

#!/usr/bin/env python


import time
import threading

class Timer(threading.Thread):
  def __init__(self, seconds):
   self.runTime = seconds
   threading.Thread.__init__(self)
  def run(self):
   time.sleep(self.runTime)
   print "Buzzzz!! Time's up!"

class CountDownTimer(Timer):
  def run(self):
   counter = self.runTime
   for sec in range(self.runTime):
    print counter
    time.sleep(1.0)
    counter -= 1
   print "Done."


class CountDownExec(CountDownTimer):   
  def __init__(self, seconds, action):  
   self.action = action    
   CountDownTimer.__init__(self, seconds) 
  def run(self):      
   CountDownTimer.run(self)   
   self.action()     
   
def myAction():      
  print "Performing my action..."   



c = CountDownExec(10, myAction)
c.start()
#>./timer.py 
10
9
8
7
6
5
4
3
2
1
Done.
Performing my action...