Ideas and Code

giovedì 24 marzo 2011

Best Android App

We opened up our catalog of Best Android Apps.

http://www.bestappsmarket.com/

Also available in the Android market as "Best Apps Market". Install from here

mercoledì 2 marzo 2011

Android Developer?

BuzzBox is launching a free SDK to add a scheduler to your Android App.
Check out the new website: BuzzBox Notification Platform

This is what I like to most:

- create a cron job in your App: cron scheduler for Android

- super simple notification API: Notification API

- add real time analytics: Real time analytics for Android

mercoledì 12 maggio 2010

venerdì 26 febbraio 2010

Tweet about a Story with buzzbox

The tweet button on buzzbox is pretty nice because with 1 click you get:

- the title of the story
- the source name
- the short url (using bzbx.us - buzzbox's shortening service)
- the most important topics (this is kind of unique, as far as I know)

Everything is formatted so it will fit in a tweet. For example:


Google Enhances Local Search With "Nearby" Filter [techcrunch] http://bzbx.us/S32 #Filter #Google


We could also include the buzzrank or other sources writing about the same story... we are experimenting about that.
What do you think? Do you find it useful?

martedì 23 febbraio 2010

Best Daily Video from Youtube

I like the way I was able to use BuzzBox to use the data provided by Fast Forward to show the feed of the best videos from youtube, constantly updated. A great channel to check out when you are bored and want to have some fun watching videos.

Popular YouTube Videos Feed

mercoledì 13 gennaio 2010

Spring Jdbc and no transaction

You don't need transaction? Are you using Spring Jdbc (SimpleJdbcTemplate)?
If you enable profileSQL in the jdbc connection url you will notice that all your queries are sorrounded by other 2 queries:

1. SET autocommit=1

2. YOUR QUERY

3. SET autocommit=1

You don't need 1 and 3 with you are not working with transaction. They are very fast to execute but they require network communication with your DB (and you don't want that!)

You can fix that adding to your connection URL:

elideSetAutoCommits=true
useLocalSessionState=true

in my case:

jdbc:mysql://localhost:3306/myDb?connectTimeout=4000&autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&profileSql=false&elideSetAutoCommits=true&useLocalSessionState=true

In my case I'm working on Mysql ISAM tables.


Similarly, I had an annoying SHOW WARNINGS query after every query. It went away when I upgraded Spring from 2.5.4 to 2.5.6
I'm using mysql connector for Java 5.1.10

lunedì 5 ottobre 2009

JTidy errors to Log4j

By default JTidy logs all the errors on the standard output, kind of an old fashion way of doing logging. So I spent some time to integrate it with log4j to clean up my standard output.

First, you need a PrintWriter as a bridge from JTidy to Log4j:

public class Log4jPrintWriter extends PrintWriter {
Priority level;
Category cat;
StringBuffer text = new StringBuffer("");

public Log4jPrintWriter(org.apache.log4j.Category cat, org.apache.log4j.Priority level) {
super(System.err); // PrintWriter doesn't have default constructor.
this.level =level;
this.cat = cat;
}

// overrides all the print and println methods for 'print' it to the constructor's Category
public void close(){
flush();
}
public void flush(){
if (!text.toString().equals("")){
cat.log(level,text.toString());
text.setLength(0);
}
}
public void print(boolean b){
text.append(b);
}

public void print(char c){
text.append(c);
}
public void print(char[] s){
text.append(s);
}
public void print(double d){
text.append(d);
}
public void print(float f){
text.append(f);
}
public void print(int i){
text.append(i);
}
public void print(long l){
text.append(l);
}
public void print(Object obj){
text.append(obj);
}
public void print(String s){
text.append(s);
}
public void println(){
if (!text.toString().equals("")){
cat.log(level,text.toString());
text.setLength(0);
}
}
public void println(boolean x){
text.append(x);
cat.log(level,text.toString());
text.setLength(0);
}
public void println(char x){
text.append(x);
cat.log(level,text.toString());
text.setLength(0);
}
public void println(char[] x){
text.append(x);
cat.log(level,text.toString());
text.setLength(0);
}
public void println(double x){
text.append(x);
cat.log(level,text.toString());
text.setLength(0);
}
public void println(float x){
text.append(x);
cat.log(level,text.toString());
text.setLength(0);
}
public void println(int x){
text.append(x);
cat.log(level,text.toString());
text.setLength(0);
}
public void println(long x){
text.append(x);
cat.log(level,text.toString());
text.setLength(0);
}
public void println(Object x){
text.append(x);
cat.log(level,text.toString());
text.setLength(0);
}
public void println(String x){
text.append(x);
cat.log(level,text.toString());
text.setLength(0);
}
}

Thanks to JD Evora for this.

Then, declare your Logger and your PrintWriter

private static Logger log = Logger.getLogger(HtmlProcessor.class);
private static Log4jPrintWriter log4j = new Log4jPrintWriter(log, Level.DEBUG);


And finally, make JTidy work with it:


InputStream pageStream =  new ByteArrayInputStream(html.getBytes("UTF-8"));
Tidy tidy = new Tidy();

tidy.setOnlyErrors(true); //<------------------

tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setQuiet(true);
tidy.setShowWarnings(false);
tidy.setErrout(log4j);
dom = tidy.parseDOM(pageStream, null);
dom.normalize();
...


Enjoy your clean catalina.out!