Please is it possible to publish a countdown in my gmail status?
Like "01:44:15:23" and its decrements continually.
Found a good article to share:
Google Talk uses XMPP then if you can connect using an XMPP client to your Google account you can use the client instead of Google talk.
The whole mechanism is too simple (Used the Smack XMPP Library because it is simple and serves me well):
Login.
Calculate difference between now and the targeted date.
Send the presence
Login
import org.jivesoftware.smack.XMPPConnection;
public void connect() {
XMPPConnection connection = new XMPPConnection(server); //Server is gmail.com for Google Talk.
connection.connect();
connection.login(username, password); //Username and password.
}
Calculate difference between now and the targeted date
This process is done using Java Calendar and Date objects:
import java.util.Calendar;
import java.util.Date;
{
Calendar calendar1 = Calendar.getInstance();
Date d = new Date();
calendar1.setTime(d);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(endLine); //End line is the date we're counting to.
long milliseconds1 = calendar1.getTimeInMillis();
long milliseconds2 = calendar2.getTimeInMillis();
long diff = milliseconds2 - milliseconds1;
long diffDays = diff / (24 * 60 * 60 * 1000);
diff = diff % (24 * 60 * 60 * 1000);
long diffHours = diff / (60 * 60 * 1000);
diff = diff % (60 * 60 * 1000);
long diffMinutes = diff / (60 * 1000);
diff = diff % (60 * 1000);
}
This code calculates the difference between the two dates in days, hours and minutes.
Send the presence
After calculating the difference all we have to do is to send the presence:
import org.jivesoftware.smack.packet.Presence;
{
String remaining = Long.toString(diffDays) + " day(s), " + Long.toString(diffHours) + " hour(s), " + Long.toString(diffMinutes) + " minute(s) " + message; //Message is usually: Until "something".
Presence presence = new Presence(Presence.Type.available);
presence.setStatus(remaining);
presence.setPriority(24); //Highest priority in Google Talk
presence.setMode(presenceMode); //This is one of XMPP modes (Available, Chat, DND, Away, XA).
connection.sendPacket(presence);
}
After this point people will see your new status instead of the one in Google Talk. (Notice that you won’t be able to see the change inside Google Talk but rest assured it is changed.f you wanna make sure it is changed ask one of your friends to tell you your status).
Its very simple just download status-counter.jar from here and write a script file
java -jar /root/status-counter.jar -status SF -username username#gmail.com -password XXXXXX -datetime 2013-03-21T16:00:00+02:00 -type hours -decimals 0
and write a cron to do the job
*/5 * * * * /path/script.sh > /dev/null
this updates your status every 5 minutes. More details can be found here.
Related
I wanna to create a timedown with mongoose and excited an function at the end of time.
I have a quiz and I wanna at the end of time logout from quiz page. code implemented with nodejs
You can try this:
// Set the date we're counting down to
var countDownDate = new Date("Jan 5, 2022 15:37:25").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
<p id="demo"></p>
This is an example of js timedown for js/dom.
and you can easily change the document.getElementById() by any var you want.
I would say to create a token (jwt) including the timestamp of the quiz starts on the server, user_id, and quiz_id and pass it to the client application. Then you might tick the timer in the ejs app itself using the native js function setInterval() and can automatically trigger an exit from the quiz page when ticker time reaches the quiz expiry time.
For each answer submission, you may pass that token created on quiz initiation to the server alongside submission details, so that server can validate whether that token is still valid to use (based on the quiz expiry time). So by the time expires, the server will no longer accept answers for that particular quiz since the token gets expired.
You may include the business logic based on your needs, this is a more generic answer for your generic question. (This might not be the best way of implementing a quiz, but this works with minimal server requests.)
I want to execute a piece code each Sunday 23:59 (11 pm) (basically at the end of each week). However, it should only be fired once per week.
A setInterval() function won't cut it here, as the app might be restarted meanwhile.
If this will help anyhow, I had this basic idea:
Set an interval (with setInterval) for every 5-10 seconds and check if it's Sunday and hour 23 (11 pm). However, this solution will be inconsistent and may fire more than once a week. I need a more bullet-proof solution to this.
You can use any cron module (like https://www.npmjs.com/package/cron) and set job for 59 23 * * 0 (ranges)
const { CronJob } = require('cron');
const job = new CronJob('59 23 * * 0', mySundayFunc);
job.start();
How about calculating the remaining time on start, like this code
const WEEK_IN_MS = 604800000;
const ONE_HOUR_IN_MS = 3600000;
const FOUR_DAYS_IN_MS = 4 * WEEK_IN_MS / 7;
function nextInterval() {
return WEEK_IN_MS - ((Date.now() + FOUR_DAYS_IN_MS) % WEEK_IN_MS) - ONE_HOUR_IN_MS;
}
const interval = nextInterval();
console.log(`run after ${interval} ms`);
setTimeout(
() => console.log('Do it!!!'),
interval
)
I am using the scheduled script which will create the custom records based on criteria. every time when the schedule script runs it should create approx. 100,000 records but the script is timing out after creating 5000 or 10000 records. I am using the below script to prevent the script execution usage limit but even with this also the script is not working. can any one please suggest some thing or provide any information. any suggestions are welcome and highly appreciated.
In my for loop iam using the below script. with this below script included the scheduled script is able to create up to 5000 or 10000 records only.
if (nlapiGetContext().getRemainingUsage() <= 0 && (i+1) < results.length )
{
var stateMain = nlapiYieldScript();
}
If you are going to reschedule using the nlapiYieldScript mechanism, then you also need to use nlapiSetRecoveryPoint at the point where you wish the script to resume. See the Help documentation for each of these methods, as well as the page titled Setting Recovery Points in Scheduled Scripts
Be aware that nlapiSetRecoveryPoint uses 100 governance units, so you will need to account for this in your getRemainingUsage check.
#rajesh, you are only checking the remaining usage. Also do check for execution time limit, which is 1 hour for any scheduled script. Something like below snippet-
var checkIfYieldOrContinue = function(startTime) {
var endTime = new Date().getTime();
var timeElapsed = (endTime * 0.001) - (startTime * 0.001);
if (nlapiGetContext().getRemainingUsage() < 3000 ||
timeElapsed > 3500) { //3500 secs
nlapiLogExecution('AUDIT', 'Remaining Usage: ' + nlapiGetContext().getRemainingUsage() + '. Time elapsed: ' + timeElapsed);
startTime = new Date().getTime();
var yieldStatus = nlapiYieldScript();
nlapiLogExecution('AUDIT', 'script yielded.' + yieldStatus.status);
nlapiLogExecution('AUDIT', 'script yielded reason.' + yieldStatus.reason);
nlapiLogExecution('AUDIT', 'script yielded information.' + yieldStatus.information);
}
};
Inside your for loop, you can call this method like-
var startTime = new Date();
if ((i+1) < results.length ) {
//do your operations here and then...
checkIfYieldOrContinue(startTime);
}
I have a script that lets you process an array like a forEach. The script checks each iteration and calculates the maximum usage and yields when there is not enough usage left to cover the max.
Head over to https://github.com/BKnights/KotN-Netsuite and download simpleBatch.js
def waktusekarang
SimpleDateFormat abc = new SimpleDateFormat("HHmm")
waktusekarang = abc.format(new Date())
if current time is 13:58, then it will be become 1358 because (SimpleDateFormat is HHmm). then how to +2 minutes to the current time then the result become 1400.
i try new Date()+2 but its not success and the result become 13581,and i also try to parseInteger but its not success too.
please help my problem , how can i +1 or +2 minutes to current time if current minute is 59.because if minute is 59 then +1 will be 60 ,it must be 00
Use can use Calendar to add minutes to your time, appropriately your time would be incremented:
SimpleDateFormat abc = new SimpleDateFormat("HHmm");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, 2);
String waktusekarang = abc.format(cal.getTime());
System.out.println(waktusekarang);
A Groovy solution would be:
Date in2mins = use( groovy.time.TimeCategory ) {
new Date() + 2.minutes
}
String waktusekarang = in2mins.format( 'HHmm' )
println waktusekarang
Dont use format(Date). Use format(int) and then call System.currentTimeMillis() and add 120000 ms = 2 mins. Thats a way to do it without calendar. But you should think of using calendar.
SimpleDateFormat abc = new SimpleDateFormat("HHmm");
waktusekarang = abc.format(System.currentTimeMillis()+120000);
I have the following code to retrieve the duration of a video uploaded:
HttpPostedFileBase postedFileCopy = postedFile;
postedFileCopy.InputStream.Position = 0;
Stream stream = postedFile.InputStream;
LocalResource tempDirectory = RoleEnvironment.GetLocalResource("TempZipDirectory");
postedFile.SaveAs(tempDirectory.RootPath + #"\" + postedFile.FileName);
ShellFile so = ShellFile.FromFilePath(tempDirectory.RootPath + #"\" + postedFile.FileName);
string durationString;
double nanoseconds;
double.TryParse(so.Properties.System.Media.Duration.Value.ToString(),out nanoseconds);
if (nanoseconds > 0)
{
int totalSeconds = (int)Math.Round((nanoseconds / 10000000), 0);
int seconds = totalSeconds % 60;
int minutes = totalSeconds / 60;
int hour = totalSeconds / (60 * 60);
durationString = "" + hour + ":" + minutes + ":" + seconds;
}
else
{
System.Diagnostics.EventLog.WriteEntry("Application", "BLANK DURATION STRING", System.Diagnostics.EventLogEntryType.Error);
durationString = "00:00:00";
}
This works as expected on localhost but when put up to Azure storage it does not seem to be able to retrieve the details of the file. The
postedFile.SaveAs(tempDirectory.RootPath + #"\" + postedFile.FileName);
saves the upload to the directory so i can grab these details but no matter what i try I cant seem to get the nanoseconds returned when the storage is on azure. This is a deployed MVC application and the tempdirectory is stored on the C:/ drive of the server.
The code you refer is using native (Shell) functions. As AzureWebSites is running as a high-density shared environment, your code runs into non-full-trust mode. Calls to native functions is restricted in Azure Web Sites, even if you scale to reserved mode instances.
UPDATE
The only way to get application executed under FULL TRUST is to use Web Role (for web projects) or Worker Role (for background tasks).
Read more about cloud services here.