Techno

things which came out my laptop

Batch Convert PNG Into SVG Using Python

| Comments

Recently I am working on product where I have been assigned to some interesting charting related tasks. As part of an assignment, I needed to convert bunch of PNGs to SVGs with embedded base64 png image as charting API I was working on written to accept SVG only so I wrote following python script which does this bulk conversion.

(png2svg.py) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import os
startSvgTag = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="240px" height="240px" viewBox="0 0 240 240">"""

endSvgTag = """</svg>"""
for files in os.listdir("."):
    if files.endswith(".png"):
      pngFile = open(files, 'rb')
      base64data = pngFile.read().encode("base64").replace('\n','')
      base64String = '<image xlink:href="data:image/png;base64,{0}" width="240" height="240" x="0" y="0" />'.format(base64data)

      f = open(os.path.splitext(files)[0]+".svg",'w')
      f.write( startSvgTag + base64String + endSvgTag)
      print 'Converted '+ files + ' to ' + os.path.splitext(files)[0]+".svg"

Basically we will be converting PNG image to base64 format string and we will be using it an SVG using the template String by string concatenation. A Just run this script in directory where you have your pngs.

1
sachin@sachin-VPCF226FM:~/download/icons$ python png2svg.py

Life is short - you need Python!

Introducing Garagesaledroid

| Comments

After I moved to United States, I found interesting concept here to sell unused items in your home, called as Garage Sale or Yard sale. The garage sale sell the used thing but it’s still good quality. You can buy something with the cheap price over there. You can save much money from buying yard sale.

But its bit hard to find garage sale which will interesting and near to you, so I decided to use my android development skills to write app to do this which will use current GPS or user entered location to find garage sales and allow search using item names like chairs, books etc. Initial work of android application is complete and its google play now, named as “Garagesaledroid”,

Garagesaledroid which lets you to find garage sales near you. It talks to appengine service which actually aggregates the sale data from various site together as result you get large database of sales in this app. Following is the list of features,

Current features:

  • Find garage sale near you using GPS or preferred location.
  • Filter sale by distance (aerial), sale day, item or location.
  • View sale details and get driving direction or navigation instructions.
  • View sales on google maps with detailed map balloon.
  • Aggregated large sale database.

Upcoming features:

  • Save and organize Favourite sale
  • Get Real time notifications for newly added sales.
  • Set reminders for sale dates.
  • and You can also suggest new feature!

Following are some screenshots from application:

Happy Shopping.

Thanks,

Sachin.

Criscoredroid- Live Cricket Is Back

| Comments

During last cricket world cup, I developed cricket score android application named as cricscoredroid. I had taken this application off from android market for 6 months now as there was not free score provider was available after world cup.

Cricscoredroid was very popular during cricket world cup, it had 4.5 rating in android market and was installed by more than 25k users within 2 months of its release. Reason of its popularity was its very simple and fastest in android market. Also it has some unique notification features.

Cricscoredroid is back in Google Play now with lots UI improvements. Cricscoredroid now features Android HOLO dark theme and Honeycomb styled Action Bar using HoloEverywhere and ActionBarSherlock . What this library does is that if you’re using your app in a device with Android 2.x, it gives you an ActionBar that is a copy of the real Honeycomb ActionBar, thanks to Jake Wharton , a guy who created this library.

It is available on Google Play . Use and rate it on google play!. Screenshots of cricscoredroid with new Holo Dark theme,


Have fun!

Eclipse Juno : Rememberer Previously Open File Tabs Under Visible Tabs

| Comments

If you tried Eclipse Juno, you may see strange behaviour with open tabs in editors. Juno has stopped retaining open file tabs tabs. If you open new file using Ctrl Shift R, it closes last active file . This behaviour is started in Juno.

If you take a look in the preferences, in the appearance section, you won’t find anything related to this.

The good news is that I found fix, rather work around :). Go to Preferences -> General -> Appearance and switch to the Classic theme. Yes, switching theme solved this issue.

I am still looking for correct fix, let me know if you find one.

Failed to Load JavaHL Library

| Comments

Today after upgrading eclipse to juno(4.2) and installing subclipse 1.6, I got following error on Ubuntu 12.04 installtion,

1
2
3
4
5
6
Failed to load JavaHL Library.
    These are the errors that were encountered:
    no libsvnjavahl-1 in java.library.path
    no svnjavahl-1 in java.library.path
    no svnjavahl in java.library.path
    java.library.path = /usr/lib/jni:/lib

I run into this error every time I upgrade eclipse as subclipse needs javahl library. Usually a fix is to install javahl from ubuntu repo,

1
sudo apt-get install libsvn-java

But this time it did not fix the issue, I got same error after restarting eclipse.

I found that javahl library location has been changed to /usr/lib/x86_64-linux-gnu/jni on ubuntu 64 (12.04) using find command

So updated java.library.path location in $ECLIPSE_HOME/eclipse.ini file from

1
-Djava.library.path=/usr/lib/jni

to

1
-Djava.library.path=/usr/lib/x86_64-linux-gnu/jni

and that did the trick!

Expected BEGIN_ARRAY but Was BEGIN_OBJECT

| Comments

I had a problem with Google GSON deserialization. JSON data which I was trying to parse using GSON library looks like this {"matches":{"matchId":"bla" "score" : "bla"}} and when there is more roles available it looks like this {"matches":[{"matchId":"bla" "score" : "bla"}{"matchId":"hihi" "score" : "hihi"}]}. So sometimes “matches” data comes as “Object” or “ARRAY” format depending upon number of matches available.

GSON fails as expected to parse this in to Java class which has field of type List class, When JSON data comes with matches as “Object” format, it throws exception “Expected BEGIN_ARRAY but was BEGIN_OBJECT”.

Source JSON data it self is bogus here, correct fix should be at JSON generator which should always return ARRAY format for array objects irrespective of number of objects being sent.

Unfortunately I don’t have access to JSON response generator, so I decided to write own GSON’s TypeAdapter implementation for List type which handles this single instance case, deserializes it and then transform into an List and set it on the field, making it uniform.

Following is implementation of ArrayAdapterFactory,

(ArrayAdapter.java) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.blog.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;


public class ArrayAdapter<T> extends TypeAdapter<List<T>> {
  private Class<T> adapterclass;

  public ArrayAdapter(Class<T> adapterclass) {
      this.adapterclass = adapterclass;
  }

  public List<T> read(JsonReader reader) throws IOException {

      List<T> list = new ArrayList<T>();

      Gson gson = new GsonBuilder()
              .registerTypeAdapterFactory(new ArrayAdapterFactory())
              .create();

      if (reader.peek() == JsonToken.BEGIN_OBJECT) {
          T inning = gson.fromJson(reader, adapterclass);
          list.add(inning);

      } else if (reader.peek() == JsonToken.BEGIN_ARRAY) {

          reader.beginArray();
          while (reader.hasNext()) {
              T inning = gson.fromJson(reader, adapterclass);
              list.add(inning);
          }
          reader.endArray();

      }

      return list;
  }

  public void write(JsonWriter writer, List<T> value) throws IOException {

  }

}
(ArrayAdapterFactory.java) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.blog.util;;

import java.lang.reflect.ParameterizedType;
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;

public class ArrayAdapterFactory implements TypeAdapterFactory {

  @SuppressWarnings({ "unchecked", "rawtypes" })
  @Override
  public <T> TypeAdapter<T> create(final Gson gson, final TypeToken<T> type) {

      TypeAdapter<T> typeAdapter = null;

      try {
          if (type.getRawType() == List.class)
              typeAdapter = new ArrayAdapter(
                      (Class) ((ParameterizedType) type.getType())
                              .getActualTypeArguments()[0]);
      } catch (Exception e) {
          e.printStackTrace();
      }

      return typeAdapter;
      

  }

}

While constructing GSON instance, I assigned TypeAdapterFactory with ArrayAdapterFactory to GsonBuilder,

1
Gson gson = new GsonBuilder().registerTypeAdapterFactory(new ArrayAdapterFactory()).create();

Happy New Year

Its been more than half year since I blogged last time. I was busy trying to settle up in my personal life. During this period, I purchased new home and also I got married on 23rd nov. So its been eventful period for me. Now I am enjoying my married life.
As 2011 is beginning, I decided to restart my technical blogging. Apart from my personal life, I have tried to continue my technical evolution. Meanwhile I owned a android device, HTC Wildfire and now I am quite busy with experimenting android apps and custom roms. I will try to post android experiment in coming days.

Happy New Year 2011.

Comments

India Gets Everything Free
Happy New Year :)

Ubuntu 10.04 Change Is Here!!!

After six months of development, Tomorrow, the Ubuntu team will be releasing Final New Version of Ubuntu (10.04) for public. This is Ubuntu Lucid Lynx, a name that combines reflection and vigilance (lucid) the desire to conquer a predator (lynx).

This release is LTS(Long Term Support), it means technical support and security updates are provided for a period of at least three years to release “Desktop” and at least five years for version “Server”.

To download Ubuntu 10.04 Lucid Lynx, you can go directly to the official page: ubuntu.com (Available from Thursday, April 29 at 13:00).
Upgrade from an earlier Ubuntu version can be done through a terminal make sure you back up your data.



After upgrade to RC, I experinced something new. Firstly, there is the integration of Plymouth, the system boot graphic that is used in Fedora for quite some time now. Specifically, we are left with only one screen at startup (two cons for version 9.10) and also a boot time much faster.
Canonical wished to develop a whole new identity(Change!!). A new logo (see icon at the top of the article)

Music Store:
Canonical seems to always find a profitable business model. With this in mind we now propose to purchase music tracks online, directly from the media player Rhythmbox.

Other changes includes,

* Use Linux kernel 2.6.32
* OpenOffice.org goes to version 3.2
* Firefox 3.6
* Gnome 2.30
* KDE 4.4

Ubuntu, Change is here!!!

GNUnify 2010, My Experience Day 1

Last week I attended my first GNUnify Conference in Pune, it is annual event organised by SICSR an PLUG (Pune Linux User group). It was very good experience, I got chance to listen few open source Geeks around the globe. As it is 2 days event, multiple activities were running in parallel. So missed few “interesting” talks although it was organised carefully based on tracks like Software Development, System Administration, Embedded Systems, Embedded Systems.

Being software developer, I decided to attain all possible Software Development related sessions.

So on day first, I started with “Playing with python” session by Kushal Das. Though I have coded few applications in python already, I decided to attain this, as I have never learnt python in any classroom. It was worth, as I learnt few new things about Python which I was not aware of.

After this workshop, I went for Collaborative Software Development talk by Senthil Kumaran from CollabNet. It was really useful session for me as I had to deal with various SCM related tasks at my work. Senthil introduced RedMine,a project management web application. It is very flexible and written using Ruby on Rails framework, it is cross-platform and cross-database as well.

After this session is over, I walked into another room for “MySQL Shell Scripting”, (Good thing of Gnunify is you can just walk in any room at any time). In that session I got idea how I can leverage shell scripting to automate database related daily tasks.

After Lunch break, I went for Embracing the Web Platform talks from Arun Ranganathan. a member of the World Wide Web Consortium (W3C) Advisory Board, and is Chair of the Khronos WebGL Working Group. Arun did more of demonstrated than talk for emerging implementations of HTML5 and other web technologies with tag line “Pictures speak more than words” for which audience applauded. After this session, Web.Next talk from Ragavan Srinivasan gave introuction to “Weave - a framework for building personalized web experiences” and Project Jetpack - reimagining Firefox extensions.

I ended my day 1 of GNUnify with “Next generation Wireless” which gave how me idea about Wireless networking works, I have very less knowledge about networking itself. So it was worth!!


I will write about my day 2 session soon. I gotta go now.

I love freedom (saw this one-liner on Few TEEs at GNUnify)

Why MS Badly Needs Open Source

Recently MS admitted flaws in IE which allows Remote code execution, it allowed recent attacks on Google’s systems that originated in China. Look at How MS struggling to update its aged Internet Explorer web browser which is very unfortunate.
Lets try to understand what’s Open Source,

Open Source means that the source code of the software may be copied and distributed freely according to the license it is released under.


Open Source software guarantees quality and continuity for the user, because:

* users are no longer dependent on the survival of the software supplier,
* users can continue to develop and change the core of the acquired software,
* users can benefit from successful developments by others who have (previously) used this software,
* rapid bug fixing and feature development with large community base across globe.

The best-known open source software products are the Linux operating system, Mozilla Firefox, the Apache web server and OpenOffice.
Open-sourcing products is the only way that Microsoft can move forward. Look at how many years it took for Microsoft to develop Vista, and how bad it was (Win7 is basically a repaired version of Vista). Look at it struggling to update its Windows Mobile phone OS, which now seems to be an impossible task.
Microsoft will eventually have to start using open-source licenses, to which Steve Ballmer once said “a cancer”!!!

Be community driven rather than commercial driven!!!