Using Twitter oauth on GAE/J

Twitter supports oauth and there are many libraries for it, for  Java(twitter4J)(oauth-signpost),  most of the time you see examples of a desktop version, so it can take time to implement it on a web application (it did take time for my case).

Step 1. Get a Twitter account and create a Twitter application from http://twitter.com/apps (don’t forget to check in browser and enter a  valid callback url. Callback URL can not be localhost :)

Step 2.  Download twitter4J add the library (in my case twitter4j-core-2.1.1-SNAPSHOT.jar) to project and update classpath

Step 3. Create a web application (I assume you have the Google plugin for Eclipse )

Step 4. Add the following servlets and update your web.xml. First servlet will handle login part. It will create a RequestToken which will create the magical aggrements between the consumer(your application) and provider(twitter). First servlet save the  token and secret token since we will need them later.

String token = requestToken.getToken();
String tokenSecret = requestToken.getTokenSecret();

Step 5. You forget to update web.xml didn’t you, update the web.xml

Step 6.  Enable session by adding

    <sessions-enabled>true</sessions-enabled>

to appengine-web.xml.

You can see my version from http://90.latest.denemekaya.appspot.com/login

ps. don’t forget to set the callback in Twittter to the url of the servlet for callback.

Links:

  • http://www.pakzilla.com/2009/10/03/tutorial-java-based-twitter-app-on-google-app-engine/
  • Explain the same procedure with Grails — http://blogs.bytecode.com.au/glen/2009/12/08/log-into-your-grails-app-using-your-twitter-credentials.html

Smashing Magazine’den 10 Kullanilabilirlik Ipucu

Smashing Magazine karsilastigim cok guzel bir yazinin, Turkce ozeti sayilabilecek bir post. Elbette cok cok kisaltilmis bir ozetidir. Yazinin orijinal hali burada.

1. Form yaratirken iki kolonlu tasarim yerine, dikey tasarim kullanin, cunku kullanicilar formu yukaridan asagiya tarayarak doldururlar. Bir diger noktada form’daki aciklama yazilari koyu renk (bold) olmamali.

2. Kullanicilar yuzlere odaklanir. Eger yuz bize degilde, ekranda baska bir yere bakiyorsa, yuzden sonra kullanicilarin bakacagi diger nokta, bakis dogrultusudur.

3. Tasarimin kalitesi, guvenirliliginizi arttirir. Okurlar kitabin kapagindan kesinlikle etkilenirler, bu web icinde gecerli. Eger  tasarimdaki yerlesim, tutarlilik, tipografi, renk, still uyumluluk gosteriyorsa, bu ziaretciler uzerinde olumlu etki yapacaktir.

4. Kullanicilar scroll kullanmazlar. Kullanicilarin %77 scroll arayuzunu kullanimiyor, bu yunden sayfanin yuklendiginde gorunen kismi cok onemli.

5. Linkler icin gecerli renk MAVi.

6.  Arama kutulari icin ideal genislik, 26 karakter.

7. Beyaz alanlar algiyi arttirir.

8. Sadece 5 kisiyle yapacaginiz kullanilabilirlik testi, sitenizdeki kullanilabilirlik sorunlarinin %85′ini cozecektir.

9. Urunleriniz icin bilgi acisindan aciklayici sayfalar hazirlayin, sadece kisa bir sure bakacak olan ziyaretciler icin bile daha gecerlidir.

10. Kulanicilarin cogu reklamlara (ya da reklama benzeyen ogelere) karsi kor gibidir.

Using Memcache with Google App Engine (GAE/J)

A simple beginning — Fragman iPhone Application

Memcache provides convenience to store a frequent query in memory, so that you don’t have to make the same execution over and over again. For the iPhone application I build (Fragman), I build a GAE/J backend for managing movie names, IMDB URLs, thumb images, video files, etc. It interacts with the Obj-c code via calls encoded in JSON.

Since the categories are updated so frequently (new trailer, top 250 , soap opera trailers), every time the user starts the application from her iPhone, the corresponding categories Id(key) lists are  created which includes all the aspects mentioned above,

what I see, after people start to use the application that, most of the time, the application got stuck with the time constraint of GAE and this causes inconvenience, so I decided to hold the category lists’s JSON in memory. Following is the code ,

this is the servlet for creating the JSON which is called after say upcoming movie list is changed. This servlet updates the memcached list

        List keyList = new ArrayList();
	static Cache cache;
	static
	{
		try
		{
			CacheFactory cacheFactory =
CacheManager.getInstance().getCacheFactory();
			cache = cacheFactory.createCache(
Collections.emptyMap());
		}
		catch (CacheException e)
		{
			// ...
		}
		//.....
                public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
	        {
                       //................
                       if(cache.containsKey(mode))
		       {
			     cache.remove(mode);
		       }
		       cache.put(mode, keyList);
	        }
                //........
          }

And this is the servlet that fetch the Fragman beans from the datastore with the given keys (key list is got from the memecached list)

          keyList = (List)cache.get(mode);
By doing this, I reduce the time that the servlet that creates the JSON takes.

Fragman iPhone Application

Film fragmalarini ve trailerlarini iceren yeni iPhone uygulamasi Fragman app store’da yerini aldi.  Vizyon, gelecek, dizi ve Top 250 (imdb top 250) kategorilerini iceriyor, su an icin oldukca guncel :) devamini da getirmeyi dusunuyoruz, yardim etmek isteyenler olursa cok seviniriz. Uygulamanin web sayfasi http://ifragman.com.

app store

Yeni Tohumlar — etohum 2010

2009 bizim (ben ve yekmer) için çok heyecanli bir yil oldu. Bunda etohum’un ve Burak hoca‘nin payi çok büyük.

Bu sene etohum 20 Ocak’ta yeni tohumlari duyuracak, inaniyorumki etohum bu sene daha da etkili ve basarili olacak. bu sene geçen seneki gibi girisimcilere 4 günlük bir kurs verilecek. 2009 yilinda bogaz manzarasi esliginde yapilan kurs, bu sene akdeniz sahilllerine tasinmis :) bir de incubator acilldi, bu sene etohumcular için harika geçecek sanirim. ilgili etohum linki‘de budur.

A Simple Chart for a GWT Application on GAE/J

I am trying charting solutions for a GWT project and gchart seems a nice one. After some digging I create a sample project which is hosted on Google App Engine (GAE) demo. Source code is at Google project

The chart will show the remaining number of months in the current year.

  • First download the jar from the project home page http://code.google.com/p/gchart/
  • Put it under war/WEB-INF/lib and add the gchart.jar to your classpath
  • Create a  Web Application project called it GChart-samples (I assume you have Google Eclipse Plugin and follow the basic steps from here)
  • This step is for make-up, find GChart_samples.html under war/WEB-INF and clear the part between <body> tags.
  • Open GChart_samples.gwt.xml and add the following line
    <inherits name='com.googlecode.gchart.GChart'/>
  • Create a class in client folder called FirstChart and change it as the following
    package com.dogan.kaya.client;
    
    import com.googlecode.gchart.client.GChart;
    
    public class FirstChart extends GChart
    {
    	public FirstChart()
    	{
    		setChartSize(350, 350);
    
    		addCurve();
    
    		int[] data = { 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
    		for (int i = 0; i < data.length; i++)
    		{
    			getCurve().addPoint(i + 1, data[i]);
    		}
    		//curve customization
    		getCurve().getSymbol().setHeight(10);
    		getCurve().getSymbol().setWidth(10);
    		getCurve().getSymbol().setBorderColor("black");
    		getCurve().getSymbol().setBorderWidth(3);
    		getCurve().getSymbol().setSymbolType(SymbolType.LINE);
    		getCurve().getSymbol().setFillThickness(2);
    		getCurve().getSymbol().setFillSpacing(0);
    		//chart customization
    		getXAxis().setAxisMin(1);
    		getXAxis().setAxisMax(12);
    		getXAxis().setTickCount(12);
    		getXAxis().setHasGridlines(false);
    		getXAxis().setTickLocation(TickLocation.CENTERED);
    		getXAxis().setTickLabelFontSize(10);
    		getYAxis().setAxisMin(0);
    		getYAxis().setAxisMax(12);
    		//to get inteter values on y axis, be careful
    		//about the number of intervals it can be tricky
    		getYAxis().setTickCount(13);
    		getYAxis().setTicksPerLabel(2);
    		getYAxis().setHasGridlines(false);
    		getYAxis().setTickLabelFontSize(10);
    		//
    		update();
    	}
    }
  • Open GChart_samples class and change it like the following
    package com.dogan.kaya.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.RootPanel;
    
    public class GChart_samples implements EntryPoint
    {
    	public void onModuleLoad()
    	{
    		RootPanel.get().add(new FirstChart());
    	}
    }
  • My output is sth like that

ps:

some nice links about gchart are as follows:

  1. gchart homepage
  2. A simple tutorial at http://whatwouldnickdo.com/wordpress/264/simple-charts-in-gwt-with-gchart/

Back to basics — A simple beginning to Grails

I guess I can finally finish my search for a good server side companion (at least for now).  A couple years ago RIFE was my only choice but unfortunately, it didn’t work out well as I expected (RIFE is an open source project but partly because of developers like me  who uses the framework but doesn’t pay his gratitude by adding sth to it, RIFE for the time being a dead project (at least for me!))

Anyway, for some time I consider turn back to good old J2EE, then wander on the land of some other Java enterprise frameworks (Spring MVC, Wicket, Struts 2, Hibernate etc ) then Google App engine Java with its in progress full stack framework like environment. Then I decide that all the ones mentioned above has steep learning curves and without feeling complely comfortable with them, It is imposible to develop sth quickly.

Then the obvious direction was rails. First give a try to Django, then read some about  RoR but both of them somehow scare me out. I need to learn a new language (which Django tutorial specificly warns about looking a good python tutorial before devlde into Django), on the other hand, Grails (my love!) just start the sentence with “don’t worry about the groovy, you can learn it along the way”.

Obviously, Grails is relatively new compared to two other alternative and it has (or used to have) to many bugs for a relaible product.

But trust me, it is easy to just start and kick the first alfa version of sth out is a joy.

Ok this post is suppose to be a yet another introduction to Grails tutorial, so…

Steps to Get Started

1.  install Grails (there is nothing I can add here — http://www.grails.org/Installation)

2. open command line and create a project with grails create-app Yeap

3. Go to the created directory cd Yeap

4. Type grails run-app

That’s it!

I’m currently using Apache Shiro plugin (previously JSecurity), Gwt plugin, Postgresql, Eclipse for the development, More posts related to these will be here soon (I hope)

Rama II

Rama III’ve recently finished the novel Rama II (goodreads)(wikiepedia)by Arthur C. Clarke (ACC) and Getry Lee. Two authors form a perfect combination. Below are some of the passages I underline. There are in fact some very good passages.

Mankind was not unique, maybe not even special. It was just a question of time before prevailing homo centric notion of universe was to be irrevocably shattered by clearer awareness of the Others.(pg23)

The memories of the terrible traumas of their youth during the Chaos haunted the adult generation and made them extremely rigid in their application of parental discipline. To them life was not a joyride at am amusement park. It was a deadly serious affair…(pg33)

Our conversation reminds me of that old Hindu proverb about the blind men who felt the elephant, They all described it differently, for of them touched only a small part of the animal. None of them was correct.(pg 216)

there came from inside her a different voice, an assertive, optimistic voice that refuse to let her give up. It told her that any time of being alive was precious and wonderful, that simply being conscious at all, ever, was an overwhelming miracle of nature.(pg292)

Father of Nicole des Jardin to the audience on a ceremony for his successful scientific career:

For when your life is over, if you can say “I have learned” and “I have loved”, you will also be able to say “I have been happy(pg297)”

All bureausicracies are the same. They drain the life out of the truly creative people and develop mindless paper-pushers as their critical mass(pg339)

There may be or not may be a god;I may or may not believe in him. The only way I can lose is if there is a go and I do not believe him. Therefore I shall believe in him to minimize my risk(pg479)

It was a real excitement to image myself (just for a minute ) in Rama and try to look around and at the same the check my back to see whether there is a biot trying to rip me apart!

Paul Graham at Startup School 08

Recently I started to reread and re watch all the pg resources (including the ones I haven’t encountered before).

This is a nice video from the Start-up school of 2008 which has suggestions for start-ups and suggestions about being good (not evil) towards people.

<div><a href='http://www.omnisio.com'>Share and annotate your videos</a> with Omnisio!</div> <p>

Cydia and XCode Local App Testing

1. Go to /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/SDKSettings.plist and change CODE_SIGNING_REQUIRED to NO and save it. (if it complains about file permission right click the file and select Get Info and after unlocking the file, change the permission to read&write)

Plist File

Picture 12

2. In XCode open the info page and change Code Signing Identy to Don’t Code Sign.

Picture 13
3. In the terminal, set the environment variable  CODESIGN_ALLOCATE  as follows: (or you will get an error like this util/ldid.cpp(567): _assert(0:arch != NULL))
export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
Picture 14
4. Open Fugu and connect to your iphone (you can download FUGU from here)(you can find the IP address your iphone from Settings->Wi-fi->ConnectedWirelessName) (Username should be root and password should be alpine OR dottie) (open your iphone and don’t let it pass to stand-by mode during these phases)

Picture 15Picture 16
5. Go to root directory and from here go to Applications directory

Picture 17Picture 18Picture 19
6. In XCode, build your application, from Products folder, select Reveal in Finder

7. Upload the .app file to the Applications folder in your iPhone

8. Open a Terminal and connect to your iphone with ssh like (be  careful that iphone is not in stand-by mode)

root@192.168.1.5 and enter your password

Picture 20

9. First change the binary file permission of your application

chmod 755 /Applications/Appname.app/Appname

10. Then sign the app file with ldid

ldid -S /Applications/Appname.app/Appname

11. Restart the iphone, you are good to go

Note:
1. If ldid command can not be found, type apt-get install ldid OR aptitude install ldid
2. If apt-get can not be found install aptitude from Cydia

3.There are very useful pages on the net, so just google xcode and cydia, here is one of them http://thebigboss.org/hosting-repository/submit-your-app/compile-for-cydia-submission/

4. If you get an error like util/ldid.cpp(567): _assert(0:arch != NULL), there can be two possible reason for this, you either forget to export CODESIGN_ALLOCATE. The other possibility is that you build the application for the simulator. To fix this,  from XCOde change it to Device – 3.0  or sth similar :) . You should see it on the combo box top left top corner of XCode.