Visualizzazione post con etichetta Atom. Mostra tutti i post
Visualizzazione post con etichetta Atom. Mostra tutti i post

martedì 4 dicembre 2018

Atom Editor

Alcuni comandi per Atom Editor


CTRL + e - aumeta e diminuisce il carattere
CTRL N nuovo tab
CTRL O apre un file
ALT 1, ALT 2, ALT n sposta il focus tra i vari tab

CTRL SHIFT P apre l'help di Atom in cui ci sono gli shortcuts da tastiera

Per usare i Pane si usano combinazioni di tasto
CTRL K CTRL W chiude un pane
CTRL K CTRL N sposta il focus sul prossimo pane

per aprire l'albero a sinistra con i file "Toggle TreeView" oppure CTRL + \ (backslash)

per avere una finestra di shell si puo' installare il pacchetto Platformio-ide-terminal. Per aprire un terminale si usa ALT SHIFT T, per avere il focus sul terminale CTRL "apice inverso" la stessa combinazione di tasti esce dal terminale e ritorna nell'editor

venerdì 30 novembre 2018

Testare Lambda NodeJS in locale per Alexa Skills

Per testare una Lambda function per Alexa Skills non e' strettamente necessario utilizzare Amazon AWS con l'editor on line

per esempio si parte dallo scaricare il progetto Basic Starter da SkillTemplates (ask new --template --url https://skilltemplates.com/templates.json)

Si crea quindi nella root del progetto (dove e' contenuta la directory Lambda per capirsi) una directory test e si inseriscono i seguenti tre files

test.js
-------------------------------------------------------------------
var lambda = require('../lambda/custom/index.js');
var context = require('./context.js');
var mockEvent = require('./event.json');

var mockContext = new context();

function callback(error, data) {
  if(error) {
      console.log('error: ' + error);
  } else {
      console.log(data);
  }
}

lambda.handler(mockEvent, mockContext, callback);
-------------------------------------------------------------------


context.js
-------------------------------------------------------------------
module.exports = function() {
    return {
        succeed: function(result) {
            console.log(JSON.stringify(result, null,'\t') );
        },
        fail: function(err) {
            console.log(JSON.stringify(err, null,'\t') );
        },
        done: function(err, result) {
            //console.log("CONTEXT DONE:", err, result);
        },
        functionName: 'local_functionName',
        awsRequestId: 'local_awsRequestId',
        logGroupName: 'local_logGroupName',
        logStreamName: 'local_logStreamName',
        clientContext: 'local_clientContext',
        identity: {
            cognitoIdentityId: 'local_cognitoIdentityId'
        }
    };
};
-------------------------------------------------------------------

event.json
-------------------------------------------------------------------
{
  "session": {
    "new": false,
    "sessionId": "mock_sessionId",
    "application": {
      "applicationId": "mock_applicationId"
    },
    "attributes": {},
    "user": {
      "userId": "mock_userId"
    }
  },
  "request": {
    "type": "LaunchRequest",
    "requestId": "mock_requestId",
    "locale": "en-US",
    "timestamp": "2017-09-19T11:46:23Z"
  },
  "context": {
    "AudioPlayer": {
      "playerActivity": "IDLE"
    },
    "System": {
      "application": {
        "applicationId": "mock_applicationId"
      },
      "user": {
        "userId": "mock_userId"
      },
      "device": {
        "supportedInterfaces": {}
      }
    }
  },
  "version": "1.0"
}
-------------------------------------------------------------------

se si lancia il file test.js con

node.js

si ha come riposta
-------------------------------------------------------------------

{ version: '1.0',
  response:
   { outputSpeech:
      { type: 'SSML',
        ssml: '<speak>Hello there. What is your name?</speak>' },
     reprompt: { outputSpeech: [Object] },
     shouldEndSession: false,
     card:
      { type: 'Simple',
        title: 'Example Card Title',
        content: 'Example card body content.' } },
  userAgent: 'ask-node/2.0.5 Node/v10.4.1',
  sessionAttributes: {} }
-------------------------------------------------------------------

questo e' il file che normalmente Lambda passa a Alexa per poi essere trasformato in messaggio vocale ed spedito al dispositivo Alexa
In pratica viene generata l'intent LaunchRequest (event.json) della funzione Lambda che corrisponde a 

-------------------------------------------------------------------
const LaunchRequestHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
  },
  handle(handlerInput) {
    const speechText = 'Hello there. What is your name?';
    const repromptText = 'Can you tell me your name?';

    return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(repromptText)
      .withSimpleCard('Example Card Title', "Example card body content.")
      .getResponse();
  },
};
-------------------------------------------------------------------

martedì 20 dicembre 2016

Atom Editor e proxy su Windows

Non e' proprio intuitivo installare pacchetti su Atom in presenza di un proxy server


la soluzione e' digitare a riga di comando

apm config set proxy "http://ip:port/"
 apm config set https_proxy "http://ip:port/"

mercoledì 3 ottobre 2012

Hyperthreading e Open MP su Atom N450

Stavo pensando di iniziare a studiare la programmazione parallela quando mi sono accorto che tutte le mie macchine sono vecchiotte (ad esclusione del portatile di mia moglie che pero' e' intoccabile) e non sono provviste di un processore dual core. Avevo quasi abbandonato l'idea quando leggendo ho scoperto che il processore N450, pur essendo Single Core, possiede l'HyperThreading ovvero la capacita' di gestire piu' thread sul un solo core

Atom N450
Digitando il comando lscpu infatti si legge che

Architecture:  i686
CPU op-mode(s): 32-bit, 64-bit
CPU(s): 2
Thread(s) per core: 2
Core(s) per socket: 1
CPU socket(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 28
Stepping: 10
CPU MHz: 1662.438
L1d cache: 24K
L1i cache: 32K
L2 cache:  512K

Si vede chiaramente la presenza di un solo core ma i thread risultano due per cui e' possibile fare calcolo parallelo su N450
P4 640 3.2 GHz


Incuriosito mi sono chiesto se anche l'HP DC5100 SFF dotato di Pentium 4 Processor 640 with HT Technology  2.8 GHz poteva fare calcolo parallelo
Digitando lscpu e' apparso uno sconfortante

Architecture: i686
CPU op-mode(s):  32-bit, 64-bit
Byte Order:  Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
Vendor ID:  GenuineIntel
CPU family:  15
Model:  4
Stepping:  9
CPU MHz:  2793.347
BogoMIPS:  5586.69
L1d cache: 16K
L2 cache: 1024K

In un solo core con un solo thread?? Il problema e' stato risolto entrando nel BIOS ed abilitando lo switch dell'Hyperthreading. Una volta riavviata la macchina il risultato e' stato

Architecture:          i686
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2
On-line CPU(s) list:   0,1
Thread(s) per core:    2
Core(s) per socket:    1
Socket(s):             1

Per testare l'effettivo utilizzo di HyperThreading ho usato il programma sotto riportato utilizzando OpenMP, una libreria per distribuire il calcolo

Il programma inizializza con il valore del seno un array molto grande, prima senza l'utilizzo di Hyperthreading e poi con

La prima prova, in modalita' standard, deve essere compilato con  g++ -Wall -O3 test_no.cpp -o test_no
---------------------------------------
#include <cmath>
#include <iostream>

using namespace std;

int main()
{
const int size = 100000;
double tabella[size];


for (int n=0; n<size;++n)
{
tabella[n] = sin(2*M_PI*n/size);
}
return 0;
}
---------------------------------------
La seconda, che utilizza invece OpenMP si compila con g++ -Wall -O3 test.cpp -o test -fopenmp
---------------------------------------
#include <cmath>
#include <omp.h>
#include <iostream>

using namespace std;

int main()
{
const int size = 100000;
double tabella[size];
int id;
int proc0,proc1;

#pragma omp parallel for
for (int n=0; n<size;++n)
{
id = omp_get_thread_num();
tabella[n] = sin(2*M_PI*n/size);
if (id == 1) proc1++;
else
proc0++;
}
cout << "0: "<< proc0 << "   |  1: "<<proc1;
return 0;
}
---------------------------------------
come si vede dall'output il carico di lavoro e' stato equamente diviso tra il thread 0 ed il thread 1 che hanno ciascuno effettutao 50000 cicli dei 100000 previsti
0: 50000   |  1: 50000

I tempi di caloolo sono pero' a favore della versione standard
Tempo con utilizzo dei thread
real 0m0.021s
user 0m0.020s
sys 0m0.012s

Tempo senza utilizzo dei thread
real 0m0.003s
user 0m0.000s
sys 0m0.004s

L'altra cosa divertente che ho scoperto e' che il mio Samsung N150 Plus esegue correttamente anche Debian a 64 Bit anche se,l leggendo qua e la', non ci sono particolari motivi di utilizzare 64 bit su una macchina con un solo Gb di Ram
Debian Live 64 Bit su N450 




Geologi

  E so anche espatriare senza praticamente toccare strada asfaltata