Skip to content

Instantly share code, notes, and snippets.

View davidgarsan's full-sized avatar
💩
entropy

David davidgarsan

💩
entropy
View GitHub Profile
package com.emil.android.util;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
/**
* Check device's network connectivity and speed
* @author emil http://stackoverflow.com/users/220710/emil
@davidgarsan
davidgarsan / DoEachSecond
Created July 23, 2013 14:12
Do something each second using requestAnimationFrame instead of setTimeout or setInterval.
var time = new Date().getTime();
var interval = 1000;
(function update() {
requestAnimationFrame(update);
var now = new Date().getTime(),
delta = now - (time || now);
if(delta>=interval) {
// Update a "time ago"|"time left" or do something...
console.log((new Date(now)).getSeconds());