Tuesday, April 5, 2016

Ubuntu - VM player: Ubuntu guest keeps going back to login screen on login


Scenario: Any ubuntu vm keeps going back to login screen even after entering valid credentials

Add line

mks.gl.allowBlacklistedDrivers = "TRUE"
to the VMX file.
http://askubuntu.com/questions/443474/how-can-i-enable-3d-acceleration-for-ubuntu-as-a-vmware-guest?lq=1

Friday, April 1, 2016

Image PDF to text PDF using OCR

Usecase: I have a PDF multi-page document that was compiled by scanning the physical document. I want to read that in my kindle and make notes.

The problem: Since the PDF is made up of images, kindle renders the pages as images. Hence, the text in the pages was not selectable.

Solution:
Use OCR.

Ref:
http://ubuntuforums.org/showthread.php?t=880471

Steps:

  1. pdftoppm generates a 100MB ppm per page. Should ideally iterate per page and delete
  2. convert ppm to tif: tesseract accepts tif
  3. Use tesseract for OCR: generates txt
  4. Append all txt to output file
  5. Create pdf out of the txt.


Script:
#!/bin/sh
mkdir tmp
cp $@ tmp
cd tmppdftoppm * -f 1 -l 10 -r 600 ocrbookfor i in *.ppm; do     convert "$i" "`basename "$i" .ppm`.tif";     tesseract "$i" "`basename "$i" .tif`" -l eng;    cat "`basename "$i" .txt`" >> pdf-ocr-output.txt;    echo "[pagebreak]" >> pdf-ocr-output.txt;done mv pdf-ocr-output.txt ..rm *cd ..rmdir tmp



Sunday, August 31, 2014

android studio The project is using an unsupported version of the Android Gradle plug-in 0.10

Using Android Studio
Projects generated using libGDX


vim build.gradle
locate line
buildscript {...
    classpath 'com.android.tools.build:gradle:0.10+'
}

Change it to

classpath 'com.android.tools.build:gradle:0.12+'


That's it.

Tuesday, August 12, 2014

Oracle JDK : how to create deb

http://www.santasoft.it/en/blog/20120910_flash-install-oracle-java-7-jdk-debian-way :

sudo apt-get install java-package

Download JDK tar.gz from Oracle's website:
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

fakeroot make-jpkg jdk-7u60-linux-x64.tar.gz

A deb file is created in the same directory. Install the created deb file using
sudo dpkg -i oracle-j2sdk1.7_1.7.0+update60_amd64.deb

 sudo update-alternatives --config java

Other references:
https://wiki.debian.org/JavaPackage

oracle-jdk-7 403 forbidden or The request or reply is too large


While trying to install cloudera manager I keep getting 403 Forbidden when it tries to install oracle-jdk -7.
When  I tried downloading the file manually I kept getting "The request or reply is too large."

1. One potential solution:
http://askubuntu.com/questions/453367/download-failed-oracle-jdk-7-is-not-installed

after getting error 403, use ls:
ls /var/cache/oracle-jdk7-installer/

download the JDK tar.gz from someplace else on web (google archive filename) and compare its md5 checksum against the one given on oracle's website.

sudo cp ~/Downloads/jdk-7u55-linux-x64.tar.gz /var/cache/oracle-jdk7-installer/

sudo apt-get install oracle-java7-installer

2. Found out why it was happening:
The local network went through squid proxy that had a 100MB limit. The JDK archive is 130+ MB
Moved to another network and it started installing :P

Friday, June 20, 2014

Mysql select filter by partition - partition by date

Mysql 5.6 supports PARTITION clause in the query itself.
Mysql 5.5 relies on something called as partition pruning.

>show create table mytable
`id` int(11) NOT NULL AUTO_INCREMENT,
`created_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
...

PARTITION BY LIST (DAYOFMONTH(created_at))
(PARTITION day1 VALUES IN (1) ENGINE = InnoDB,
 PARTITION day2 VALUES IN (2) ENGINE = InnoDB,
...
PARTITION day31 VALUES IN (31) ENGINE = InnoDB)


explain partitions select count(*) from mytable where created_at = '2014-06-19'
explain partitions select count(*) from mytable where creation_date between '2014-06-19' and '2014-06-19'
Uses partition day19
Returns only those rows that have created_at  exactly equal to 2014-06-19 00:00:00'

explain partitions select count(*) from mytable where date(created_at) = '2014-06-19'
Correctly returns all rows of 19th June
But uses all partitions day1 to day31. Apparently this happens if you use any function on the LHS the where clause.


explain partitions  select count(*) from mytable where timestamp >= '2014-05-13' and time
stamp <= '2014-05-14';
Uses all partitions. Fails to prune partitions. All rows of 13th May.

Obviously I am screwed. Relying on indices for any performance improvement.
Apparently designing partitions on date has this drawback where your actual cell value is more granular than your partition definition. Here my actual value are timestamps accurate to seconds while my partition is defined on day of month(1-31).

This was used to leverage faster purging of data by truncating day-wise partitions. However leveraging any form of performance improvement on select queries seems impossible.

Thursday, June 13, 2013

linux screen set session title and window after creating a session

http://stackoverflow.com/questions/3202111/set-a-name-for-screens-with-the-screen-command

Session title:
"Ctrl+A" -> ":"
type in "sessionname ABCD"
Visible when you do screen -ls

Window title:
"Ctrl+A" -> "Shift+A"
type in a title
Visible when you do CtlrA->Shift[double quote]


Thursday, May 30, 2013

Setup Local Radio using VLC

Following are steps to setup a radio-like streaming on a LAN:
Works for sure on Ubuntu 12.10

I] Start VLC from command  line as follows:
vlc -vvv --sout-keep --sout '#standard{access=http,mux=ts,dst={YOUR OWN_LOCAL_IP_ADDRESS}:8080}'

II] Enqueue songs and hit play. You should see the seek bar moving.

III] Create a file "myliveradio.m3u" and put the following contents into it:

#EXTM3U
#EXTINF:-1,Radio Local - AACPlus - 32kbps Stream
http://{YOUR OWN_LOCAL_IP_ADDRESS}:8080


 IV]
Send this file to listeners. Anyone who opens this file in VLC woul start listening to the songs playing in your VLC. Please note that you won't be able to listen to the songs being streamed from the VLC process/window that's streaming them.
You yourself should open the file in a new VLC window and you can listen.

Source: http://forum.videolan.org/viewtopic.php?f=4&t=84303


Friday, March 29, 2013

Android device screencast on my computer

I have an android app that communicates with a server.
Wanted to present a demo of integration of the app with my servers.

For
Used the following tool to cast the device's screen on my PC. Was farely easy.

https://code.google.com/p/androidscreencast/

Needed to enable developer options on the device(Jelly Bean) for the same.
Developer options are not visible by default. To expose them tap SEVEN times on
Settings->About Phone ->Build Number
as suggested by: http://forum.xda-developers.com/showthread.php?t=1989777

However couldn't control the device by KB/MOUSE. Didn't have time to look into it further.

Wednesday, January 2, 2013

Ubuntu - install an older package from some repository ( puppet 0.25.4 on Ubuntu 12.10)

Case: Needed to install puppet version 0.25.4. on a latest version 1.10 of Ubuntu. Latest version of puppet- 3.X gets installed by default.

Found the deb for the version I need in following repository:
http://security.ubuntu.com/ubuntu/pool/main/p/puppet/puppet_0.25.4-2ubuntu6_all.deb

Following worked(as root):
echo "deb http://security.ubuntu.com/ubuntu lucid-security main\ndeb-src http://security.ubuntu.com/ubuntu lucid-security main"\
 >> /etc/apt/sources.list
apt-get update
apt-get install puppet-common=0.25.4-2ubuntu6.8 || exit
apt-get install puppet=0.25.4-2ubuntu6.8 || exit

Wednesday, December 19, 2012

Aspectj - trace method exection caller context details

http://mathewjhall.wordpress.com/2011/03/31/tracing-java-method-execution-with-aspectj/
:
Signature sig = thisJoinPointStaticPart.getSignature();
  String line =""+ thisJoinPointStaticPart.getSourceLocation().getLine();
  String sourceName = thisJoinPointStaticPart.getSourceLocation().getWithinType().getCanonicalName();
  Logger.getLogger("Tracing").log(
                Level.INFO, 
                "Call from "
                 +  sourceName
                    +" line " +
                    line
                    +" to " +sig.getDeclaringTypeName() + "." + sig.getName()
  );

jvisualvm remote tomcat

http://www.codefactorycr.com/java-visualvm-to-profile-a-remote-server.html
:
Start jstatd:
Given JAVA_HOME=/usr/lib/jvm/java-6-sun/bin
 Write following config to /usr/lib/jvm/java-6-sun/bin/jstatd.all.policy
grant codebase "file:<JAVA_HOME>/lib/tools.jar" {
permission java.security.AllPermission;};

 > /usr/lib/jvm/java-6-sun/bin/jstatd.all.policy

Then execute jstatd as
./jstatd -J-Djava.security.policy=jstatd.all.policy &


Identify jstatd ports as given in above link and make necessary firewall modifications.

Result: We can see the remote jstatd process in local jvisualvm as a remote process under the host.(plz add the host)

http://stackoverflow.com/questions/3892084/can-visualvm-connect-automatically-via-jmx-to-a-remote-process
:
Open tomcat's startup.sh and add following lines before the call
exec "$PRGDIR"/"$EXECUTABLE" start "$@"

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=60000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

 Now you can even see your server along with jstatd under the remote host.

For JConsole:
http://docs.oracle.com/javase/1.5.0/docs/guide/management/jconsole.html:
Just connect to <host>:60000 (port no. set in the jmx settings specified in JAVA_OPTS above) and it works.

Thanks,
Tapomay.

Wednesday, September 12, 2012

Fedora 17: ant-optional - custom ant libs - ClassNotFoundException

http://fastcloud.wordpress.com/2009/05/14/how-to-install-apache-ant-on-fedora-8/ :
Basically you have to maually create the /usr/share/ant hierarchy and set ANT_HOME. Thats it.
You may want to include junit.jar also into the ANT_HOME/lib. Then you need not manuallly declare it in each of your project's classpath.

The default installation of ant from yum is bare-minimum and won't work for custom ant libs.

Tuesday, July 31, 2012

Fighting make error: not protecting function: no buffer at least 8 bytes long

Attempting to build monetdb from source. The mercurial checkout date is not today but somewhere around start of July.

Getting the following error saying something like:
cc1: warnings being treated as errors - this is due to -Werror flag to gcc


inet.c: In function ‘INET_comp_CW’:
inet.c:323: error: not protecting function: no buffer at least 8 bytes long
inet.c: In function ‘INETbroadcast’:
inet.c:423: error: not protecting function: no buffer at least 8 bytes long
inet.c: In function ‘INETnetmask’:
inet.c:523: error: not protecting function: no buffer at least 8 bytes long
inet.c: In function ‘INETnetwork’:
inet.c:593: error: not protecting function: no buffer at least 8 bytes long
inet.c: In function ‘INETabbrev’:
inet.c:660: error: not protecting function: no buffer at least 8 bytes long
make[7]: *** [libatoms_la-inet.lo] Error 1
 - due to -fstack-protector-all -Wstack-protector flags to gcc. For more info on stack protector feature refer http://stackoverflow.com/questions/1629685/when-and-how-to-use-gccs-stack-protection-feature


The explanation at http://ubuntuforums.org/showthread.php?t=1612849 was sufficient for fixing.

Went to those line numbers.  They were the entry point of the reported functions.
Found unsigned char[4] local variables. Changed them to char[8].

Owned it.

Regards,
Tapomay.

Design patterns in Ruby


http://rubylearning.com/blog/2010/11/02/how-does-one-use-design-patterns-in-ruby/ :


I believe that the essence of design patterns is to make a system resilient to changes in requirements which in itself could be attributed with the parameters associated with the problem definition. The above article helped me with a lucid set of ruby examples demonstrating following patterns:
(The comments are for my personal notes. Plz ignore them)
1. Inheritance  : Car < Vehicle
2. Composition over inheritance : Car<Vehicle, Car->Engine
3. Delegation ; Car<Vehicle, Car->Engine
4. Template Method pattern : HTMLReport<Report, TextReport<Report
5. Singleton pattern : require 'singleton', attr_accessor :data
6. Adapter pattern : Renderer, TextObject, DifferentTextObject, TextObjectAdapter, class << diff_text_obj

Thanks and Regards,
Tapomay




Tuesday, May 8, 2012

Java books


Concurrency in java -doug lee
gang of 4
Effective Java -Joshua
Java performance tuning 

Friday, April 20, 2012

Bash script - execute all sql files in a directory


#!/bin/bash

for i in $(ls *.sql)
do

echo "Executing" $i;
mysql  -u root < $i

done

Wednesday, March 21, 2012

Try hd(0,0): NTFS5: No wubildr

http://ubuntuforums.org/showthread.php?t=1585120&page=2

Just wait for sometime on the screen saying "Try hd(0,0): NTFS5: No wubildr". Grub comes up later without doing anything.

I was getting windows boot loader earlier. Selected Ubuntu and I was stuck with above message.

Monday, March 19, 2012

Hibernate HQL view join: java.lang.NullPointerException at org.hibernate.util.ReflectHelper.getConstructor(ReflectHelper.java:234)

https://hibernate.onjira.com/browse/HHH-5621

What worked for me:
"This is a minor issue since an easy workaround is available: you just have to use an alias to qualified the properties....
Query query3 = session.createQuery("select new Something(sthg.id, sthg.event, sthg.dummyField) " +
"from Something sthg" );"