package com.pkm.sound.record; import java.io.File; public class AudioRecorder { private static final int RECORD_TIME = 6 * 1000; // 6 seconds public static void main(String[] args) { File wavFile = new File("Record.wav"); final SoundRecordingUtil recorder = new SoundRecordingUtil(); Thread recordThread = new Thread(new Runnable() { @Override public void run() { try { System.out.println("Start recording..."); recorder.start(); } catch (Exception ex) { ex.printStackTrace(); System.exit(-1); } } }); recordThread.start(); try { Thread.sleep(RECORD_TIME); } catch (InterruptedException ex) { ex.printStackTrace(); } try { recorder.stop(); recorder.save(wavFile); System.out.println("STOPPED"); } catch (Exception ex) { ex.printStackTrace(); } System.out.println("DONE"); } }
Sunday, July 13, 2014
Audio Record Using Java
Monday, July 7, 2014
Php, convert time between two timezones
<?php
$src_tz = new DateTimeZone('Australia/Melbourne');
$dest_tz = new DateTimeZone('GMT');
$dt = new DateTime("2014-07-06 00:00:00", $src_tz);
echo 'Australia/Melbourne: ' . $dt->format('Y-m-d H:i:s');
$dt->setTimeZone($dest_tz);
echo '<br/>GMT: ' . $dt->format('Y-m-d H:i:s');
$dt = new DateTime("2014-10-06 00:00:00", $src_tz);
echo '<br/><br/>Australia/Melbourne: ' . $dt->format('Y-m-d H:i:s');
$dt->setTimeZone($dest_tz);
echo '<br/>GMT (DST Enabled): ' . $dt->format('Y-m-d H:i:s');
?>
Output
Australia/Melbourne: 2014-07-06 00:00:00 GMT: 2014-07-05 14:00:00 Australia/Melbourne: 2014-10-06 00:00:00 GMT (DST Enabled): 2014-10-05 13:00:00
Saturday, July 5, 2014
Grails default version=false to all domain classes
Need to write the following line of code Config.groovy:
grails.gorm.default.mapping = { version false }
Request Mocking In Grails For Back-end/Background Threads
import javax.servlet.http.HttpServletRequest import org.springframework.web.context.request.RequestContextHolder import org.codehaus.groovy.grails.web.context.ServletContextHolder import org.springframework.web.context.support.WebApplicationContextUtils def getRequest() { def webRequest = RequestContextHolder.getRequestAttributes(); if(!webRequest) { def servletContext = ServletContextHolder.getServletContext(); def applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); webRequest = grails.util.GrailsWebUtil.bindMockWebRequest(applicationContext); } return webRequest.request; }
This code can broke while working on a WAR environment. The problem was that the MockWebRequest class was part of the “org.springframework:org.springframework.test:3.0.3.RELEASE” jar and had to be included in the BuildConfig.groovy as dependencies { runtime 'org.springframework:org.springframework.test:3.0.3.RELEASE' } Ensure that the line: mavenCentral() is not commented in BuildConfig.groovy
https://drive.google.com/file/d/0B5nZNPW48dpFd3U2UG9DMmVsX28/edit?usp=sharing
Tuesday, July 1, 2014
Strict Standards: Non-static method Configure::getInstance() should not be called
I Got this error as follows:
Strict Standards: Redefining already defined constructor for class Object in C:\Xampp\htdocs\webapp\cake\libs\object.php on line 54 Strict Standards: Non-static method Configure::getInstance() should not be called statically in C:\Xampp\htdocs\webapp\cake\bootstrap.php on line 38
I solved this problem by changing in /cake/bootstrap.php.
FIND: error_reporting(E_ALL & ~E_DEPRECATED); REPLACE: error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
Monday, June 30, 2014
Grails get bean/service from service or other class
import org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib import grails.util.Holders import org.codehaus.groovy.grails.commons.GrailsApplication public static GrailsApplication grailsApplication = Holders.grailsApplication; public static ServletContext servletContext = Holders.servletContext; public static ApplicationTagLib g = Holders.applicationContext.getBean("org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib") def bean = Holders.applicationContext.getBean(beanIdentifier); // beanIdentifier = userService, groupService etc...
Saturday, June 28, 2014
Encrypt & Decrypt String Using AES Algorithm & jQuery
<!doctype html> <html> <head> <meta charset="utf-8"/> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="crypto-js/core-min.js"></script> <script src="crypto-js/enc-utf16-min.js"></script> <script src="crypto-js/enc-base64-min.js"></script> <script src="crypto-js/aes.js"></script> <script> $(function() { $('#test').on('submit', function() { var plaintext = $('#text').val(); var secret = $('#secret').val(); var encrypted = '' + CryptoJS.AES.encrypt(plaintext, secret); $("#output").prepend("<br/>Encrypted: " + encrypted); var decrypted = CryptoJS.AES.decrypt(encrypted, secret); $("#output").prepend("<br/><br/> Original From Encrypted: " + decrypted.toString(CryptoJS.enc.Utf8)); return false; }); }); </script> </head> <body lang="en"> <form id="test"> <p> <label>Secret</label><br> <input id="secret" value="Secret Passphrase"> </p> <p> <label>Text</label><br> <textarea id="text">This is the secret message</textarea> </p> <input type="submit" id="submit"> </form> <div id="output"></div> </body> </html>
Subscribe to:
Posts (Atom)