How to save the compressed audio file from Tone.Compressor object to plot the compressed waveform using wavesurfer.js in Javascript? Ask Question

I would like to Plot the compressed signal like the below figure. If this is not possible, then is there any way to implement the signal plot in Tone.js? I have implemented visualizer using Tone.Analyser Node. I am also looking for Signal plot which is different from visualizer and looks like the below image.
The reason I want to declare the audio in Tone and then compress and then plot it in wavesurfer is that there is no signal plot implementation in Tone.js. Kindly let me know. It would be great if some one can help.

    var comp = new Tone.Compressor({
    ratio  : 12 ,
    threshold  : -60,
    release  : 0.25 ,
    attack  : 0.001 ,
    knee  : 30}).fan(waveform).toMaster();
    sampler.connect(comp);
    sampler.start();

I am new to Web audio API and i used a Tone.Compressor library to compress a audio and draw a waveform of the same. But i would also like to plot the compressed audio signal like the wavesurfer.js library does. I have attached the example below. Can some one please help me out to connect this two libraries and draw a waveform with the wavesurfer.js using the Tone.Compressor compressed audio.?
Signal Plot using waversurfer.js

Thanks in advance!!!!

Highlight active line in CodeMirror Ask Question

Looking at the demo here, I downloaded the active-line.js file and included it in my HTML as shown in the demo but nothing happens. I included it like so:

<script src="/js/codemirror.js"></script>
<script src="/js/sql.js"></script>
<script src="/js/active-line.js"></script>
<link rel="stylesheet" type="text/css" href="/css/codemirror.css">

This is how I initialise CodeMirror:

<script>
    CodeMirror.fromTextArea(document.getElementById("maple_code"), {
        lineNumbers: true,
        mode: "text/x-mysql"
    });
</script>

Syntax highlighting and line numbers work as they should except the active line highlighting. Do I need to tweak anything in the options as well?

Json unexpected end of string buggy character Ask Question

Just scraped some json from a webpage and now when I try to parse it using vscode I get an ‘unexpected end of string’ error on the “content” line:
Here’s the json

    {
    "name": "Anna Vergnas",
    "date": "04/18/2018 4:30pm",
    "content": "L'appartement se situe au métro porte de Montreuil.Nous sommes au rez de chaussée d 'une belle et grande cour pavée, qui accueille volontier une baignade de soleil, des apéros au milieu des jardinières et . Cadre plutôt exceptionnel pour Paris, puisque vous avez un jardin et une terrasse dont vous profitez as you want (dans le respect de chacun).Pour plus d'
    info contactez moi en mp: )",
"number" : "null"}

Here’s part of the code using for scraping ( blocks is the div of the container):

let result = []

                let name = blocks[z].querySelector('.fwn.fcg') ? blocks[z].querySelector('.fwn.fcg').innerText : null
            let fb_url = blocks[z].querySelector('h5 a') ? blocks[z].querySelector('h5 a').href : null
            let date = blocks[z].querySelector('abbr') ? blocks[z].querySelector('abbr').title : null
            let content = blocks[z].querySelector('._5pbx.userContent._3576') ? blocks[z].querySelector('._5pbx.userContent._3576').innerText : null
            let number = blocks[z].querySelector('._5pbx.userContent._3576') ? blocks[z].querySelector('._5pbx.userContent._3576').innerText.replace(/s/g, '').match(/((+)33|0)[1-9](d{2}){4}/g) : null
            result.push({ name, fb_url, date, content, number, group_url})

html onclick event: how to update a value based on argument given to the onclick Ask Question

I’m reviewing some javascript interview questions, and came upon a codepen with the following line:

<form oninput="result2.value=add(parseInt(c.value))(parseInt(d.value))">

I’ve tried to do something similar with a button press, and know see that I don’t understand the proper syntax to update my output value upon the button-press. It works fine in the codepen example I was emulating. Does anyone know what I’m missing here?

I know I could create a js function that specifically updates my result.value by referencing it directly, but I’m trying to make my add function general so that don’t have to rewrite function for future input and output id’s.

HTML:

<input id="inputA" type="number"/><br>
<input id="inputB" type="number"/><br>
<button onclick="result.value=add(inputA.value, inputB.value)">
Add A and B
</button>
<br>
<output id="result" value=""></output>

JS:

$(document).ready(function() {
    function add(a,b) {
    return a+b;
  }
});

Phonegap Build – Current Location prevent double alert Ask Question

I´m working on a webapp which is deployed with pohnegap build. I have a problem with the googlemaps api when i try to get my current Location i get two alerts one native from phonegap and one from the browser. i tried some solutions also from here but nothing worked for me.

Here is my config.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!-- config.xml reference: https://build.phonegap.com/docs/config-xml -->
<widget xmlns     = "http://www.w3.org/ns/widgets"
        xmlns:gap = "http://phonegap.com/ns/1.0"
        id        = "de.testproject.testproject"
        version   = "0.0.1"
>
<name>Testproject</name>

<description>
    Testproject
</description>

<author href="http://test.com" email="test@test.com">
    Testproject
</author>
<!--
    If you do not want any permissions to be added to your app, add the
    following tag to your config.xml; you will still have the INTERNET
    permission on your app, which PhoneGap requires.
-->
<content src="index.html" />
<preference name="permissions"                value="none"/>

<!-- Customize your app and platform with the preference element. -->
<preference name='phonegap-version'             value='cli-8.0.0' />
<preference name="orientation"                  value="default" />        <!-- all: default means both landscape and portrait are enabled -->
<preference name="target-device"                value="universal" />      <!-- all: possible values handset, tablet, or universal -->
<preference name="fullscreen"                   value="false" />           <!-- all: hides the status bar at the top of the screen -->
<preference name="webviewbounce"                value="true" />           <!-- ios: control whether the screen 'bounces' when scrolled beyond the top -->
<preference name="prerendered-icon"             value="true" />           <!-- ios: if icon is prerendered, iOS will not apply it's gloss to the app's icon on the user's home screen -->
<preference name="stay-in-webview"              value="false" />          <!-- ios: external links should open in the default browser, 'true' would use the webview the app lives in -->
<preference name="detect-data-types"            value="true" />           <!-- ios: controls whether data types (such as phone no. and dates) are automatically turned into links by the system -->
<preference name="exit-on-suspend"              value="false" />          <!-- ios: if set to true, app will terminate when home button is pressed -->
<preference name="show-splash-screen-spinner"   value="true" />           <!-- ios: if set to false, the spinner won't appear on the splash screen during app loading -->
<preference name="auto-hide-splash-screen"      value="true" />           <!-- ios: if set to false, the splash screen must be hidden using a JavaScript API -->
<preference name="disable-cursor"               value="false" />          <!-- blackberry: prevents a mouse-icon/cursor from being displayed on the app -->
<preference name="android-installLocation"      value="auto" />          <!-- android: app install location. 'auto' will choose. 'internalOnly' is device memory. 'preferExternal' is SDCard. -->
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="StatusBarBackgroundColor" value="#393938" /> <!--Your color value will go here-->
<preference name="StatusBarStyle" value="lightcontent" />
<!--
    Define a specific version of PhoneGap to build into your app.
    <preference name="phonegap-version"       value="3.5.0" />
-->

<!-- Plugins -->

<!-- Core plugins -->
<plugin name="cordova-plugin-battery-status" />
<plugin name="cordova-plugin-camera" />
<config-file parent="NSPhotoLibraryUsageDescription" platform="ios" target="*-Info.plist">
<string>This app needs access to your Photo Library to upload pictures</string>
</config-file>
<config-file parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist">
<string>Allow to upload pictures</string>
</config-file>
<config-file parent="NSLocationWhenInUseUsageDescription" platform="ios" target="*-Info.plist" >
<string>need location access to find things nearby</string>
</config-file>
<plugin name="cordova-plugin-console" />
<plugin name="cordova-plugin-contacts" />
<plugin name="cordova-plugin-device" />
<plugin name="cordova-plugin-device-motion" />
<plugin name="cordova-plugin-device-orientation" />
<plugin name="cordova-plugin-dialogs" />
<plugin name="cordova-plugin-file" />
<!-- <plugin name="cordova-plugin-file-transfer" /> -->
<plugin name="cordova-plugin-geolocation" />
<plugin name="cordova-plugin-globalization" />
<plugin name="cordova-plugin-inappbrowser" />
<plugin name="cordova-plugin-media" />
<plugin name="cordova-plugin-network-information" />
<plugin name="cordova-plugin-splashscreen" />
<plugin name="cordova-plugin-vibration" />
<plugin name="cordova-plugin-statusbar" />
<plugin name="cordova-plugin-statusbar" />
<plugin name="cordova-plugin-insomnia" />
<!-- Third party plugins -->
<!-- A list of available plugins are available at https://build.phonegap.com/plugins -->
<!--
    <plugin name="com.phonegap.plugins.barcodescanner" />
-->
<!-- Define app splash screen for each platform. -->
<!-- <splash src="/res/screen/android/splash_xxxhdpi.png" platform="android" qualifier="port-xxxhdpi" />

   Define access to external domains.
    <access />            - a blank access tag denies access to all external resources.
    <access origin="*" /> - a wildcard access tag allows access to all external resource.
    Otherwise, you can specify specific domains:
    <access origin="http://phonegap.com" />                    - allow any secure requests to http://phonegap.com/
    <access origin="http://phonegap.com" subdomains="true" />  - same as above, but including subdomains, such as http://build.phonegap.com/
    <access origin="http://phonegap.com" browserOnly="true" /> - only allows http://phonegap.com to be opened by the child browser.
-->

<access origin="*"/>
<!-- Added the following intents to support the removal of whitelist code from base cordova to a plugin -->
<!-- Whitelist configuration. Refer to https://cordova.apache.org/docs/en/edge/guide_appdev_whitelist_index.md.html -->
<plugin name="cordova-plugin-whitelist" version="1" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
    <allow-intent href="market:*" />
</platform>
<platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
</platform>
<feature name="Geolocation">
<param name="ios-package" value="CDVLocation" />

And also my script in the index.html:

<script>
     function init(){
        document.addEventListener("deviceready",onDeviceReady,false);
     }
     function onDeviceReady(){
        navigator.geolocation.getCurrentPosition(success, fail);    
     }  
</script>



   <script>

      var map;
      var infowindow;
      var latitude, longitude;
      var offzeit;
     /* var onSuccess = function(position) {
        /*alert('Latitude: '          + position.coords.latitude          + 'n' +
              'Longitude: '         + position.coords.longitude         + 'n' +
              'Altitude: '          + position.coords.altitude          + 'n' +
              'Accuracy: '          + position.coords.accuracy          + 'n' +
              'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + 'n' +
              'Heading: '           + position.coords.heading           + 'n' +
              'Speed: '             + position.coords.speed             + 'n' +
              'Timestamp: '         + position.timestamp                + 'n');*/
         //latitude = (position.coords.latitude);
         //longitude = (position.coords.longitude);
         // console.log(longitude)
        //};
        function onError(error) {
        alert('code: '    + error.code    + 'n' +
              'message: ' + error.message + 'n');
    }

     function initMap() {
    // onError Callback receives a PositionError object
    //
        navigator.geolocation.getCurrentPosition(onSuccess, onError);
        function onSuccess(position) {
        var lat=position.coords.latitude;
        var lang=position.coords.longitude;
        var pyrmont = {lat: lat, lng: lang};
        map = new google.maps.Map(document.getElementById('map'), {
          center: pyrmont,
          zoom: 13
        });
            var input = /** @type {!HTMLInputElement} */(
            document.getElementById('locate_input'));   

            var autocomplete = new google.maps.places.Autocomplete(input);
            autocomplete.bindTo('bounds', map)

          $("#map").css("position","fixed !important");
            infowindow = new google.maps.InfoWindow();
            var service = new google.maps.places.PlacesService(map);
        service.nearbySearch({
          location: pyrmont,
          radius: 1500,
          keyword: 'einkaufen',
        }, processResults);

         autocomplete.addListener('place_changed', function() {
          infowindow.close();
          //marker.setVisible(false);
          var place = autocomplete.getPlace();
          if (!place.geometry) {
            // User entered the name of a Place that was not suggested and
            // pressed the Enter key, or the Place Details request failed.
            window.alert("No details available for input: '" + place.name + "'");
            return;
          }

          // If the place has a geometry, then present it on a map.
          if (place.geometry.viewport) {
            map.fitBounds(place.geometry.viewport);
          } else {
            map.setCenter(place.geometry.location);
            map.setZoom(13);  // Why 17? Because it looks good.
          }
          var service = new google.maps.places.PlacesService(map);
            service.nearbySearch({
            location: place.geometry.location,
            radius: 1500,
            keyword: 'einkaufen',
        }, processResults);
          marker.setIcon(/** @type {google.maps.Icon} */({
            url: "img/chili_login.png",
            size: new google.maps.Size(75, 75),
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(17, 34),
            scaledSize: new google.maps.Size(35, 35)
          }));
          marker.setPosition(place.geometry.location);
          marker.setVisible(true);

          var address = '';
          if (place.address_components) {
            address = [
              (place.address_components[0] && place.address_components[0].short_name || ''),
              (place.address_components[1] && place.address_components[1].short_name || ''),
              (place.address_components[2] && place.address_components[2].short_name || '')
            ].join(' ');
          }
          infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
          infowindow.open(map, marker);
        }); 



      }
     }

  function processResults(results, status, pagination) {
        if (status !== google.maps.places.PlacesServiceStatus.OK) {
          return;
        } else {
            for (var b= 0;b < results.length; b++)
            {
                createMarkers(results[b]);
            }
          if (pagination.hasNextPage) {
            var moreButton = document.getElementById('more');

            moreButton.disabled = false;

            moreButton.addEventListener('click', function() {
              moreButton.disabled = true;
              pagination.nextPage();
            });
          }
        }
      }

      function createMarkers(places) {
        var bounds = new google.maps.LatLngBounds();
        var placesList = document.getElementById('places');
          var image = {
            url: "img/chili_login.png",
            size: new google.maps.Size(74, 74),
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(17, 34),
            scaledSize: new google.maps.Size(25, 25)
          };
          marker = new google.maps.Marker({
            map: map,
            icon: image,
            title: places.name,
            position: places.geometry.location
          });
            google.maps.event.addListener(marker, 'click', function() {
            if(places.opening_hours.open_now == true)
              {
                  offzeit = "Geöffnet"
              }
          else
              {
                  offzeit = "Geschlossen"
              }
                infowindow.setContent('<div><strong>' + places.name + '</strong><br>' + places.vicinity + '<br>' + offzeit + '</div>');
                infowindow.setOptions({pixelOffset:new google.maps.Size(-22, 0)});
                infowindow.open(map, this); 
            });

          //placesList.innerHTML += '<li>' + place.name + '</li>';
         // bounds.extend(places.geometry.location);
        //}
        //map.fitBounds(bounds);
      }
    </script>

How i can prevent the second alert wich is something like this: /var/Containers…index.html Would you like to use your current location

Can someone help me understand how to use the result from nativescript-barcodescanner Ask Question

The barcode scanner reads the barcode and displays on console log but how to make it look up for the book on Google Book API. The book details such as Title, Author, and Published year should be displayed on a different page. This is the plugin that I followed: https://github.com/EddyVerbruggen/nativescript-barcodescanner

This is my hardcopy-view-model.js file

var observable_1 = require("data/observable");
var dialogs_1 = require("ui/dialogs");
var view = require("ui/core/view");
var nativescript_barcodescanner = require("nativescript-barcodescanner");
const httpModule = require("http");

var BarCodeModel = (function (_super) {
__extends(BarCodeModel, _super);
function BarCodeModel() {
    _super.call(this);
    this.barcodeScanner = new nativescript_barcodescanner.BarcodeScanner();
}
BarCodeModel.prototype.doCheckHasCameraPermission = function () {
    this.barcodeScanner.hasCameraPermission().then(function (permitted) {
        dialogs_1.alert({
            title: "Has Camera permission?",
            message: permitted ? "YES" : "NO",
            okButtonText: "OK"
        });
    }, function (err) {
        dialogs_1.alert(err);
    });
};
BarCodeModel.prototype.doScanWithTorch = function () {
    this.scan(false, true, true, "landscape");
};
;
BarCodeModel.prototype.doScanLandscape = function () {
    this.scan(false, true, true, "landscape");
};
;

BarCodeModel.prototype.scan = function () {
 this.barcodeScanner.scan({
 cancelLabel: "EXIT. Also, try the volume buttons!", 
 cancelLabelBackgroundColor: "#333333", 
 message: "Tap the bulb button or Use the volume button for turning on 
 light", 
 showFlipCameraButton: false,   
 preferFrontCamera: false,     
 showTorchButton: true,        
 beepOnScan: true,             
 torchOn: false,               
 closeCallback: function () { console.log("Scanner closed"); }, 
 resultDisplayDuration: 500,  
 orientation: "landscape",     
 openSettingsIfPermissionWasPreviouslyDenied: true 
 }).then(

 function(result) {
        console.log("---- scanned " +result.text);
        httpModule.request({
            url: "https://www.googleapis.com/books/v1/volumes? 
 q=isbn:"+result,
            method: "GET"
        }).then((response) => {
            var obj = response.content.toJSON();
            console.log("Book: " +obj);
            console.log(JSON.parse(response)); 
            alert({
                title:"Scan Result",
                message: "Barcode Format: " + result.format + "nCode: " + 
 result.text + "nBook Title: " + result.response,
                okButtonText:"OK"
            });
        });  
     },          
  function(error) {
    console.log("No scan: " + error);
 });
};
;
return BarCodeModel;
}(observable_1.Observable));
exports.BarCodeModel = BarCodeModel;

Selecting Input Element by Name in IE, in iFrame, using AHK? Ask Question

There is a daily report that is used at work that records the starting, ending, and total run time of a particular process. There is an excel spreadsheet that is used for recording this time. It’s a simple process to do, but I’d like to automate it using AutoHotKey. However, I am running into issues because everything on the page is contained within iFrames.

Below is the DOM structure
HTML>frameset>frameset>frame>html>body>form>table>tbody>tr>td>table>tbody>tr>td>font>input

The input element is what I want to select. It is a Report Filter that I would like to send the name of the particular report to, and select ‘search’ so that this one particular report is called successfully.

I can return the text of the ‘font’ element above the ‘input’ element with the below line

a:= pwb.document.parentWindow.frames("FrameB").document.all.tags("font")[46].innertext

however, when I attempt to select the “input” element by name or by tag index, it doesn’t return anything.

a:= pwb.document.parentWindow.frames("FrameB").document.getElementsByName("ReportCodeFilter")[0].value

The above line returns nothing for AHK, and it only returns two double quotes in the JS console in IE. I can see within the HTML DOM that the value is set to the name of the report I want to search after I put it in. This is the only place the ‘name’ is used.

How can I create a randomizer in javascript which will redirect to a random webpage? Ask Question

My question is about how to create a travel destination generator for a school project (similar to this https://travelsp.in/) but my HTML keeps on having issues redirecting to the other webpages. Here’s my js:

var place = ['sydney', 'calgary', 'london'];
function differentPlace() {
var randomNumber= Math.floor(Math.random()*(place.length));
document.getElementById('placeDisplay').innerHTML=place[randomNumber];
}
if (placeDisplay=="calgary") {
 return window.location.href = "http://ide50-w.cs50.io:8080/calgary";
  }
else if (placeDisplay=="london") {
  return window.location.href = "http://ide50-w.cs50.io:8080/london";
}
  else if (placeDisplay=="sydney") {
  return window.location.href = "http://ide50-w.cs50.io:8080/sydney";
 }

and my html is:

 <body>
     <h2>Discover a new destination:</h2>
<div id="placeDisplay">
    </div>
    <button onclick="differentPlace()">Find your next journey!</button>
    <script src="javascript.js"></script>
 </body>