Posts

ffmpeg for Google Speech API

ffmpeg -i call.mp3 -acodec pcm_s16le -ar 16000 call.wav  The following command will convert an audio file into a mono wav at a specified sample rate of 8000: ffmpeg -i /home/absin/Downloads/RT7345201f37e6ae014fcbbc353400bce8.mka -ar 8000 -ac 1 /home/absin/Downloads/audio.wav The following command will take a frame from a video ffmpeg -i input.flv -ss 00:00:14.435 -vframes 1 out.png

Learning in 2018

So, this is a follow-up post from my earlier post on learning which you can read here . What has changed since January, well I started dissecting text and speech (or nlp and asr for the 3 letter proponents). What I realised in the process was that a lot of information seems quite foreign when you try to chew on something which doesn't fit your jaws. Learning how to understand language and speech was like that and I got bombarded by the sheer volume of ideas and concepts I had to absorb. As I reflected in the previous post, learning by doing is one of the best ways of learning new things is to just pull up your sleeves and dive into practising them. While this is very satisfying and indeed takes you forward in the journey of understanding things. It is equally important to have a depth-full understanding of the concepts you are practising. Why you may ask is it necessary to not just practice things but also understand them? Well couple of reasons, practising things gives you ...

API Sandbox

Read More: https://smartbear.com/learn/api-testing/what-is-an-api-sandbox/ Today’s software architecture relies on APIs as core to the application in much the same way as a database or user interface are considered core components to the architecture. That reliance on APIs means that application testers have to test the application’s reaction to a variety of API responses. But, if those APIs are still in development or are developed by a third party, how can you fully test against them? This is where an API sandbox comes in. Fundamentally, an API sandbox is an environment that testers can use to mimic the characteristics of the production environment and create simulated responses from all APIs the application relies on. The API sandbox makes it possible to: reduce the cost and risk associated with calling 3rd party APIs during testing. allow for concurrent testing and development to fast-track app development cycles and reduce time-to-market. simulate error scenario...

SPARQL

Sparql can be used to query structured data sets like DBPedia. These queries can be run on SPAQL enpoints like http://lod.openlinksw.com/sparql or http://dbpedia.org/sparql/. The queries can be slightly different, but for an experienced SPARQLer (which I hope to be one day) this won't be a problem. Here are a few of my first queries, the structure will be purpose followed by the query: The urban and metro population of Patna PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX dbr: <http://dbpedia.org/resource/> select ?populationUrban  ?populationMetro where {   dbpedia:Patna  dbo:populationUrban ?populationUrban;                  dbo:populationMetro ?populationMetro  . } Details of Hemmingway: prefix dbpedia: <http://dbpedia.org/resource/> prefix dbpedia-owl: <http://dbpedia.org/ontology/> select ?abstract ?thumbnail where {    dbpedia:Ernest_Hemingway ...

Redis Supported Data Types and Commands

Redis support 5 types of data types. You need to know what type of value that key maps to, as for each data type, the command to retrieve it is different. Here are the commands to retrieve key value: if value is of type string -> GET  <key> if value is of type hash -> HGETALL  <key> if value is of type lists -> lrange  <key> <start> <end> if value is of type sets -> smembers  <key> if value is of type sorted sets -> ZRANGEBYSCORE  <key> <min> <max> command to check the type of value a key mapping to: type  <key>

Wikipedia API

A collection of a number of wikipedia API links to perform a plethora of tasks: Searching : Search can be done using Opensearch or query on the api Open search method: Use url:  https://en.wikipedia.org/w/api.php?action=opensearch&search=concurrency+java&limit=10&namespace=0&format=json https : //en.wikipedia.org/w/api.php ? action = opensearch & search = zyz # search query & limit = 1 # return only the first result & namespace = 0 # search only articles, ignoring Talk, Mediawiki, etc. & format = json # jsonfm prints the JSON in HTML for debugging. Query method: Use url: https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=what+is+concurrency+java&utf8=&format=json   Titles : Once the search yields url (in case of opensearch) or titles in case of query search, each can be individually opened. In case of query search, plain text or w-test can be obtained using...

log4j experiments

2 loggers into 2 different files : log = C:/Apache24/htdocs/logs log4j.rootLogger=TRACE, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out   log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n log4j.appender.debugLog=org.apache.log4j.FileAppender log4j.appender.debugLog.File=${log}/debug.html log4j.appender.debugLog.layout=org.apache.log4j.HTMLLayout log4j.appender.debugLog.layout.Title=HTML Debug log4j.appender.debugLog.layout.LocationInfo=true log4j.appender.reportsLog=org.apache.log4j.FileAppender log4j.appender.reportsLog.File=${log}/reports.html log4j.appender.reportsLog.layout=org.apache.log4j.HTMLLayout log4j.appender.debugLog.layout.Title=HTML Reports log4j.appender.debugLog.layout.LocationInfo=true log4j.category.debugLogger=TRACE, debugLog log4j.additivity.debugLogger=false log4j.categ...

Experiential learning

I have always challenged myself to learn. In fact that's an ingredient that keeps my own sanity in place. There are days when there is no learning and just doing. Those are the kind of days I really dislike. For last nine months I have learnt to become a full stack web-developer from having an absolute zero background in software development. In this post, I want to shed some light on the way I learned and how I feel right now. I am especially going to focus on the ways you can learn anything new, maybe this is contextually more related to technology skills, but nonetheless its an interesting insight into how some of us manage to learn new things with 'ease' and some keep going through perennial struggle and mostly just give up. Just Do It Yeah, that's right. The best way to teach yourself something completely new and complicated is to just observe how it translates into reality. When we are talking about technology there is no better way to learn systems and fram...

WIKIPEDIA API and ChatBots

I have been trying to use ontological bases in my chatbot to introduce interactivity which can take the conversation forward. What I have till now : Any user query is parsed by an NLP engine to classify if the intent is any one of the preset intents. Some of these preset intents are greetings, compliments, tasks assigned in the Talentify for Business app amongst a few. If none of the intents are matched then the user query is passed in sequence to various search engines and their web results are scraped to get a metadata response generated by the search engine, which usually is a representation of the internal knowledge graph of the search engine implementation. If none of the search engines can identify that query, then the query is passed to a knowledge engine called wolfram alpha which in most of the cases can give response to even very complex queries like "what is the distance between Chennai and Bangalore in kilometres" If even that fails then a default random...

Getting same MD5 from java and javascript

Java: try { String plaintext = "test123"; MessageDigest m; m = MessageDigest.getInstance("MD5"); m.reset(); m.update(plaintext.getBytes()); byte[] digest = m.digest(); BigInteger bigInt = new BigInteger(1, digest); String hashtext = bigInt.toString(16); // Now we need to zero pad it if you actually want the full 32 chars. while (hashtext.length() < 32) { hashtext = "0" + hashtext; } System.out.println(hashtext); javascript: var MD5 = function(s){function L(k,d){return(k<<d)|(k>>>(32- d))}function K(G,k){var I,d,F,H,x;F=(G&2147483648);H=( k&2147483648);I=(G&1073741824) ;d=(k&1073741824);x=(G& 1073741823)+(k&1073741823);if( I&d){return(x^2147483648^F^H)} if(I|d){if(x&1073741824){ return(x^3221225472^F^H)}else{ return(x^1073741824^F^H)}} else{return(x^F^H)}}function r(d,F,k){return(d&F)|((~d)&k)} function q(d,F,k){return(d&k)|(F&(~k))} function p(d,F,k){return(d^F^k)} function n(d,F,...

Using cookies with HttpURLConnection

Before the advent of REST, we services were stateful. There were cookies sent with every HTTP request to maintain the state of the client using the services. When we use HttpURLConnection (Java) we need to discretely mention the cookies in the header and store it somewhere for maintaining the session. Below is an attempt using a singleton class for maintaining the session details and some sample HTTP methods: First our Singleton to maintain the cookies in memory between successive transactions: package singletonCookieManager; import java.net.CookieManager; /**  * @author absin  *  */ public class EaqerInitializedCookieHelper { private static final CookieManager instance = new CookieManager(); // private constructor to avoid client applications to use constructor private EaqerInitializedCookieHelper() { } public static CookieManager getInstance() { return instance; } } Next, wherever you want to use this class initialize it as such ...

ehCache getting Started

First create a singleton class (CacheHelper) to return an instance of cache: package cache; import org.ehcache.Cache; import org.ehcache.CacheManager; import org.ehcache.config.builders.CacheConfigurationBuilder; import org.ehcache.config.builders.CacheManagerBuilder; import org.ehcache.config.builders.ResourcePoolsBuilder; import com.istarindia.android.pojo.ComplexObject; public class CacheHelper { private CacheManager cacheManager; private Cache<Integer, ComplexObject> squareNumberCache; public CacheHelper() { cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(); cacheManager.init(); squareNumberCache = cacheManager.createCache("squaredNumber", CacheConfigurationBuilder .newCacheConfigurationBuilder(Integer.class, ComplexObject.class, ResourcePoolsBuilder.heap(10))); } public Cache<Integer, ComplexObject> getSquareNumberCacheFromCacheManager() { return cacheManager.getCache("squaredNumber", Int...

Steinhaus–Johnson–Trotter algorithm

package permutation; import java.util.HashSet; import java.util.Scanner; public class JohnsonTrotter { static HashSet<String> permutations = new HashSet<>(); public static void main(String args []) { // Incorrect(); System. out .println( "Enter the count of integers whose all " + "possible orders will be permuted using Johnson and Trotter" ); Scanner scanner = new Scanner(System. in ); int N = scanner .nextInt(); scanner .close(); int arr [] = new int [ N ]; for ( int i = 1; i <= N ; i ++) { arr [ i - 1] = i ; } boolean [] direction = new boolean [ N ]; // I am using a boolean array of the same size as the number of // integers. A true indicates right, and false indicates left. Don't // judge me for choosing right as true, I am right handed :P. There is // another reason why I chose right as true, by default a new boolean // array in Java...

SOAP REST SERVLET What is the difference?

This is more of a psychological question I think. What is psychological about this? These 3 things together represent something very broad, so broad it may not even share a name. Phew.. differences between boys and girls. Between cat and dog. Pencil and pen. At least those things are close. Asking SOAP vs REST vs SERVLET is like asking 'bat' vs 'bat shit crazy'. So let's take them one by one, then we shall find out the underlying relationship. SOAP: Soap is a construct. The construct demands you to use the Internet in a particular way to achieve your job at hand. It suggests that you send human readable data like XMLs through the Internet using mainly HTTP and SMTP protocols. So if you want to make a blog application. You will send the blog posts as XMLs to your browser which shall be equipped with a JavaScript file to understand and make sense of this fury of information. Coming in on the HTTP and SMTP protocol in extensive human readable formats like XML. Is it...
I was wondering, why can't I read .class files generated by the compiler on my notepad. I saw some strange figures between infrequent english alphabets. There were even some paragraph changes. What is this? What is a .class file? Why are there random alphabets in it? What is happening? Can I read this file somehow?? Well basically how a java program gets executed is divided into some steps. Starting of these is the conversion of java code written in the Java Programming language which is quite human readable. Human readable... Hmmm. Does that mean the machine cannot understand it? Isn't the machine showing me all this, isn't it supposed to know? Yes the machine is showing you all this. But you have to understand a machine just understands instructions. And your machine has a lot of them. Actually its just being fed with shit load of instructions, a couple of billions every second approximately. Speak of a hardworking individual. So when you tried to read it on your ...

Self musings

Light burns diffidence into me   Darkness is my accomplice   Together we prowl, looking for victims   Not to villainize >   For we are the heroes who revel in secret   Touched we get by these small gestures   Incomplete we are without the other   Sail high our emotions do   For we understand what nothingness feels   Black is our color, we roll into it happily   Hate we the happiness that flows through our veins   Dislike our nature we do   But it is our nature which defines us   So constantly we struggle to become brighter   Without understanding that brightness will eventually kill us   Because we do not believe in destinations   Which is absolution   But love the journey we do

Rails Musings

The order of mentioning stuff in the model.rb files should be: =begin 1. reference to libraries 2. has many association 3. has many through association 4. belongs_to association 5. validations 6. call backs 7. custom validations 8. custom instance methods 9. custom class methods 10. all our private methods =end Oh and btw, =begin and =end mark the start and end of the comment :)

Linux-Postgres Musings

To take a dump from linux server and compress it psql -U username -F filename psql -U postgres -d postgres -f chameli.sql pg_dump -U postgres postgres -f  /tmp/chameli.sql tar -cvzf abc.tar.gz chameli.sql tar -zcvf archive-name.tar.gz directory-name To use a dump file to setup db in win machine  Use pg_restore.exe --host "localhost" --port "5432" -U "postgres" --dbname "postgres" --verbose --schema "public" "C:\Users\abhinav\Downloads\new03march.backup"

SQL Musings

SELECT distinct "public".task."id", "public".task_log.created_at FROM "public".task , "public".task_log WHERE "public".task.actor_id = 777 and task."id"= task_log.task_id order by "public".task_log.created_at desc limit 10 TO Set up data for the whole column UPDATE schema.table_name SET column_name='value' Deleting a lesson SELECT id FROM cmsession WHERE cmsession.title like '%elete%' DELETE FROM cmsession WHERE cmsession.title like '%elete%' SELECT * FROM lesson WHERE  session_id in (SELECT id FROM cmsession WHERE cmsession.title like '%elete%' ) DELETE FROM lesson WHERE  session_id in (SELECT id FROM cmsession WHERE cmsession.title like '%elete%' ) SELECT * from assessment where lesson_id in (SELECT "id" FROM lesson WHERE  session_id in (SELECT id FROM cmsession WHERE cmsession.title like '%elete%' )) DELETE fro...