Skip to content

Instantly share code, notes, and snippets.

@irokhes
irokhes / miliseconds-2-human-readable-time
Created January 23, 2017 22:47
Javascript => convert time in milliseconds to hours, minutes ands seconds
function msToTime(duration) {
var milliseconds = parseInt((duration%1000)/100)
, seconds = parseInt((duration/1000)%60)
, minutes = parseInt((duration/(1000*60))%60)
, hours = parseInt((duration/(1000*60*60))%24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
app.config(function($routeProvider){
$routeProvider
.when('/secretpage' ,{
templateUrl: "templates/secretpage.html",
resolve:{
"check":function(authService,$location){ //function to be resolved, accessFac and $location Injected
if(authService.isAuthenticated()){ //This happens before the page loads
//it's ok to see the content
}else{
$location.path('/'); //redirect user to home if it does not have permission.
@irokhes
irokhes / web-api-self-hosted-Program.cs
Created June 15, 2016 14:28
Web api service self hosted using OWIN
using Microsoft.Owin.Hosting;
using System;
using System.Net.Http;
//Install-Package Microsoft.AspNet.WebApi.OwinSelfHost
namespace WebApi.SelfHosting.POC
{
static class Program
{
static void Main()
{
@irokhes
irokhes / fake-date-sinon-node-js
Created June 4, 2016 13:22
Fake a date in node.js for testing with sinon
clock = sinon.useFakeTimers(new Date(2016,11,1).getTime());
new Date(); //=> return the fake Date 'Sat Nov 01 2016 00:00:00'
clock.restore();
new Date(); //=> will return the real time again (now)