yoshi blog

IT infra engineer working at Tokyo, Japan. coding on weekends just for fun.

Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Wednesday, January 3, 2018

csv update app with spyre python

now I created csv update app with spyre. full code is here.

Preparation

set python vision and install dataspyre.
% python -V
Python 3.5.0
 
% pip install dataspyre

set directory tree as below. "test_data.csv" is the csv file to edit. number of columns have to be 5.

% tree
.
├── csv_update.py
├── data
│   ├── test_data.csv


% cat data/test_data.csv
data1,data2,data3,data4,data5
haha,hihi,huhu,hehe,hoho
gaga,gigi,gugu,gege,gogo
rara,riri,ruru,rere,roro

Execution


% python csv_update.py

Then, access to "http://127.0.0.1:9093"
input file name and push "get data" button.



input data and push "add data" button.




push "get data" button again to check added data.
backup data added under "data" directory in case.




% tree
.
├── csv_update.py
├── data
│   ├── test_data.csv
│   ├── test_data.csv_20180103173523
│   └── test_data.csv_20180103174330

% cat data/test_data.csv
data1,data2,data3,data4,data5
haha,hihi,huhu,hehe,hoho
gaga,gigi,gugu,gege,gogo
rara,riri,ruru,rere,roro
data1,data2,data3,data4,data5
Posted by yoshi at 7:22 PM
Labels: html, mac, python

Sunday, May 28, 2017

make sound with javascript

javascript can make sound. I tried as a first javascript coding. the sound is from the famous Japanese movie :)

push the button to play music. *check the system volume!!
Audio API test

sample code is below.
<!DOCTYPE html>
<html lang="ja">
     <head>
          <meta charset="utf-8">
          <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

          <title>Audio API test</title>

          <!-- Bootstrap core CSS -->
          <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" id="themesid">

          <!-- Custom styles -->
          <link href="https://getbootstrap.com/examples/theme/theme.css" rel="stylesheet">
          <link href="https://getbootstrap.com/dist/css/bootstrap-theme.min.css" rel="stylesheet">
          <link href="https://getbootstrap.com/examples/offcanvas/offcanvas.css" rel="stylesheet">

     </head>

     <body>
          <div class="container">
               <div class="row row-offcanvas row-offcanvas-right">
                    <div class="col-xs-12 col-sm-9">
                         <div class="row">

                              <!-- button -->
                              <div class="container theme-showcase" role="main">
                                   <p>
                                        <button type="button" class="btn btn-lg btn-primary" id="PlayButton">Play</button>
                                   </p>
                              </div>

                         </div>
                    </div>
               </div>
          </div>

          <script>
               function play() {

                    window.AudioContext = window.AudioContext || window.webkitAudioContext; // cross browser
                    var audioCtx = new AudioContext();

          for (key = 0; key < music.length; key++) {

                         // define sound key
                         if(music[key] == "Do"){var hz = 262;}
                         if(music[key] == "re"){var hz = 294;}
                         if(music[key] == "mi"){var hz = 330;}
                         if(music[key] == "fa"){var hz = 349;}
                         if(music[key] == "so"){var hz = 392;}
                         if(music[key] == "la"){var hz = 440;}
                         if(music[key] == "si"){var hz = 494;}
                         if(music[key] == "Doo"){var hz = 523;}
                         if(music[key] == "ree"){var hz = 587;}
                         if(music[key] == "mii"){var hz = 659;}
                         if(music[key] == "faa"){var hz = 699;}
                         if(music[key] == "soo"){var hz = 784;}
                         if(music[key] == "laa"){var hz = 880;}
                         if(music[key] == "sii"){var hz = 988;}

                         // sound play
                         if(hz != "none"){
                              var osciillator = audioCtx.createOscillator();   // sound generate
                              osciillator.frequency.value = hz;   // defined hertz 
                         var audioDestination = audioCtx.destination;   //defined sound output
                         osciillator.connect(audioDestination);   // connect speaker
                         osciillator.start = osciillator.start || osciillator.noteOn; // cross browser
                         osciillator.start();  // start playing
                              osciillator.stop(audioCtx.currentTime + time[key]);   // stop sound after time[key] sec
                         }

                         // sleep between each sound
                         Sleep(time[key]+0.1);

                    }
               }

               // sleep function
               function Sleep(T){
                  var d1 = new Date().getTime();
                  var d2 = new Date().getTime();
                  while( d2 < d1+1000*T ){     // wait T sec
                       d2=new Date().getTime();
                  }
                  return;
               }

               // defined tone
               var music = [];
               music.push("soo");
               music.push("mii");
               music.push("Doo");
               music.push("so");
               music.push("so");
               music.push("so");
               music.push("la");
               music.push("Doo");
               music.push("faa");
               music.push("laa");
               music.push("soo");

               // defined length of sound
               var time = [];
               time.push(0.7);
               time.push(0.2);
               time.push(0.7);
               time.push(0.2);
               time.push(0.2);
               time.push(0.2);
               time.push(0.2);
               time.push(0.2);
               time.push(0.2);
               time.push(0.2);
               time.push(0.7);

               // execution
               var Button1 = document.getElementsByClassName("btn btn-lg btn-primary");
               Button1[0].addEventListener("click", play, false);

          </script>
     </body>
</html>
Posted by yoshi at 2:15 AM
Labels: html, javascript
Older Posts Home
Subscribe to: Posts (Atom)

About Me

IT infra engineer working at Tokyo. want to improve english skill.

Labels

python mac ansible aws blogger html javascript shellscript apache bitnami go linux nginx ssl ubuntu vagrant virtualbox vmware

Line stamp

Line stamp
Line stamp I made is here. I hope you like them!

tip me for more fun!

15zgMbiE1aSwGvWxTzTjtoiLN5FrRwqpKv Donate with IndieSquare

links

  • github
  • line
  • blog(Japanese)

twitter

Tweets by yoshiisland_dev

Search This Blog

Labels

  • ansible (2)
  • apache (1)
  • aws (2)
  • bitnami (1)
  • blogger (2)
  • go (1)
  • html (2)
  • javascript (2)
  • linux (1)
  • mac (3)
  • nginx (1)
  • python (5)
  • shellscript (2)
  • ssl (1)
  • ubuntu (1)
  • vagrant (1)
  • virtualbox (1)
  • vmware (1)

Blog Archive

  • ▼  2019 (1)
    • ▼  December (1)
      • How to restart apache with Bitnami EC2?
  • ►  2018 (2)
    • ►  April (1)
    • ►  January (1)
  • ►  2017 (14)
    • ►  December (1)
    • ►  July (1)
    • ►  June (1)
    • ►  May (11)

Pages

  • Home
Simple theme. Powered by Blogger.