Skip to content

Instantly share code, notes, and snippets.

@bhavyaw
bhavyaw / utils.service.ts
Created March 16, 2017 09:33
Minutes to HH:mm
formatMinutesToDuration(durationInMinutes){
let formattedDuration = ``;
if(durationInMinutes){
let derivedHours = round( (durationInMinutes / 60 ),3);
let hours = Math.trunc(derivedHours);
let derivedMinutes = Math.abs(derivedHours - Math.floor(derivedHours));
let minutes = Math.trunc(derivedMinutes * 60);
let hoursFormatted = hours ? ( (hours < 10) ? `0${hours}` : hours ) : "00";
let minuteFormatted = minutes ? ( (minutes < 10) ? `0${minutes}` : minutes ) : "00";
@bhavyaw
bhavyaw / Untitled-1
Created November 26, 2016 11:43
Promises Child Workflow Example
console.clear();
var myAwesomePromise = new Promise((resolve,reject) => {
setTimeout(() => {
resolve("Timeout - 2000 promise is resolved");
},2000);
});
var resolvedPromise = Promise.resolve("This is a resolved promise");
'use strict';
var $ = require('nodobjc');
// Load the AppKit framework.
$.framework('AppKit');
// Create delegate that gets notified
var Delegate = $.NSObject.extend('Delegate');
set windowTitle to ""
set currentTabTitle to ""
set appID to ""
set appName to ""
set comments to ""
set visWins to totalVisibleWindows()
tell application "System Events"
set frontApp to first application process whose frontmost is true
set appName to name of frontApp
set windowTitle to ""
set currentTabTitle to ""
set appID to ""
set appName to ""
set comments to ""
set wins to ""
set anyFinderWindowVisible to false
set anyVisibleWindow to anyVisibleWindow()
tell application "System Events"
set windowTitle to ""
set currentTabTitle to ""
set appID to ""
set appName to ""
set comments to ""
set wins to ""
set anyFinderWindowVisible to false
tell application "System Events"
set frontApp to first application process whose frontmost is true
@bhavyaw
bhavyaw / get_title_and_url.applescript
Created September 14, 2016 06:20 — forked from vitorgalvao/Get Title and URL.applescript
Applescript to get frontmost tab’s url and title of various browsers.
# Keep in mind that when asking for a `return` after another, only the first one will be output.
# This example is meant as a simple starting point, to show how to get the information in the simplest available way.
# Google Chrome
tell application "Google Chrome" to return URL of active tab of front window
tell application "Google Chrome" to return title of active tab of front window
# Google Chrome Canary
tell application "Google Chrome Canary" to return URL of active tab of front window
tell application "Google Chrome Canary" to return title of active tab of front window
# Chromium
var exec = require("child_process").exec;
var multiline = require("multiline");
var Q = require('q');
module.exports = {
start : runScript,
stop : stopScript
}
//Applescript to get active window title.
@bhavyaw
bhavyaw / waitFor.js
Created September 7, 2016 08:25
Waiting for condition to get true and then executing a certain function
//**********************************************************************
// function waitfor - Wait until a condition is met
//
// Needed parameters:
// test: function that returns a value
// expectedValue: the value of the test function we are waiting for
// msec: delay between the calls to test
// callback: function to execute when the condition is met
// Parameters for debugging:
// count: used to count the loops
var myWorker = new Worker("DetectWakeup.js");
myWorker.onmessage = function (ev) {
if (ev && ev.data === 'wakeup') {
// wakeup here
}
}
// DetectWakeup.js (put in a separate file)
var lastTime = (new Date()).getTime();
var checkInterval = 10000;