
Name: Dogan Kaya
Posts by admin:
- System Sound API — very short – limited file type – no control
- AVAudioPlayer class — objC
- Audio Toolbox — recording – streaming – controls
- Audio Units — audio processing
- OpenAL — 3D positional sound (Yes, just like OpenGL)
Adding Short Sound Clips to iPhone/iPad Apps
August 24th, 2010There are lots of ways of playing/recording audio in your iPhone/iPad app, and probably this is why it took me a while to decide which one to chose,
Here are the alternatives (List of Audio APIs) –
Since what I need is just to play a short audio clip w/out any looping or any other control, I choose System Audio API.
As always, Google is the first address to ask howto use System Audio AP, How To Play Audio With The iPhone SDK is a step by step guide, but it takes the starting point from a sample code project from Apple, which is no longer available.
Another one is the sample code project SysSound which contains an iOS4 specific feature so that it will not work on iPad.
So how to play an audio clip w/out hassling that much?
Here is the code snippet : (don’t forget to add the AudioToolbox framework)
#include
….
-(void)playSound
{
SystemSoundID shortSound;
NSURL* audioFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:[NSString stringWithFormat:@"filename"] ofType:@"wav"]];
AudioServicesCreateSystemSoundID((CFURLRef)audioFile, &shortSound);
//playing it
AudioServicesPlaySystemSound(shortSound);
//cleanup
AudioServicesDisposeSystemSoundID(shortSound);
}
Implementing Paging on Google App Engine Java (gae/j) and GWT — the query cursor way
August 12th, 2010For the etohum admin application application, we used Goole App Engine Java (gae/j) two years ago, back then, the way to implement paging was not that easy. Because of that we came up with our custom way and implemented a combination of memcached+servlet+cron jobs update mechanism which introduced many bugs and took many hours to reach perfection.

Since Burak hoca asks for an enhancements recently, we go through the app engine documentation and see this new feature query cursors which is excellent for paging.
The idea behind query cursors is pretty simple, make a query for the first page, pass the cursor data to the client. When you need the second page, instead of making a query from scracth, use the cursor data to get the next page’s data.
In our case the RPC call getApplications(String cursor) is called. For the first page, cursor data is passed as null, so we make the query as follows:
if (cursorString == null)
{
//
Query query = pm.newQuery(Application.class);
query.setOrdering("basvuruTarihi desc");
query.setRange(0, 15);
results = (List) query.execute();
Cursor cursor = JDOCursorHelper.getCursor(results);
resultWrapper.setCursorData(cursor.toWebSafeString());
for (Iterator iterator = results.iterator(); iterator.hasNext();)
{
Application applicationFromDatabase = (Application) iterator.next();
app = DunyaTurkOlsunUtil.createApplicationDTO(applicationFromDatabase);
resultAppList.add(app);
}
resultWrapper.setResultAppList(resultAppList);
}
So this code above fetch the first page and cursor string. On the client side, inside GWT, we hold the cursor string for each page in an arraylist, so that we can handle going back and forth between the pages.
When the user asks for the second pages, the following code block executes
else
{
Cursor cursor = Cursor.fromWebSafeString(cursorString);
Map extensionMap = new HashMap();
extensionMap.put(JDOCursorHelper.CURSOR_EXTENSION, cursor);
Query query = pm.newQuery(Application.class);
query.setOrdering("basvuruTarihi desc");
query.setExtensions(extensionMap);
query.setRange(0, 15);
results = (List) query.execute();
resultWrapper.setCursorData(JDOCursorHelper.getCursor(results).toWebSafeString());
for (Iterator iterator = results.iterator(); iterator.hasNext();)
{
Application applicationFromDatabase = (Application) iterator.next();
app = DunyaTurkOlsunUtil.createApplicationDTO(applicationFromDatabase);
//
resultAppList.add(app);
}
resultWrapper.setResultAppList(resultAppList);
}
//
This works even faster than memcached version of ours.
ps. By the way, there is still no way of passing JDO objects through RPC calls which is sad for GWT apps on GAE/J/
Weird Grails Deployment Problem — MissingMethodException yada yada
August 11th, 2010We host Remotespots on a Tomcat 6 server on eapps. As we changed the UI design, we deployed a new version of it yesterday, but the scaffold views seems broken with the following error:
Error 500: Executing action [list] of controller [app.InvitationCodeController] caused exception: groovy.lang.MissingMethodException: No signature of method: static app.InvitationCode.list() is applicable for argument types: (org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap) values: [[action:list, controller:invitationCode, max:10]] Servlet: grails URI: /app/grails/invitationCode/list.dispatch Exception Message: No signature of method: static app.InvitationCode.list() is applicable for argument types: (org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap) values: [[action:list, controller:invitationCode, max:10]] Caused by: No signature of method: static app.InvitationCode.list() is applicable for argument types: (org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap) values: [[action:list, controller:invitationCode, max:10]] Class: script12814638559751136092009 At Line: [13]
With the Stack Trace:
groovy.lang.MissingMethodException: No signature of method: static app.InvitationCode.list() is applicable for argument types: (org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap) values: [[action:list, controller:invitationCode, max:10]] at app.InvitationCodeController$_closure2.doCall(script12814638559751136092009.groovy:13) at app.InvitationCodeController$_closure2.doCall(script12814638559751136092009.groovy) at org.apache.shiro.web.servlet.ShiroFilter.executeChain(ShiroFilter.java:687) at org.apache.shiro.web.servlet.ShiroFilter.doFilterInternal(ShiroFilter.java:616) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:81) at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190) at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291) at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769) at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698) at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891) at java.lang.Thread.run(Thread.java:619)
Although it runs on the local server grails run-app, the same problem occurs with grails run-war, and also on the Tomcat 6 on eapps. So after a little Googling, here is the magical solution:
grails clean
This solves the problem
These are the links that can help:
- http://jira.codehaus.org/browse/GRAILS-4951?focusedCommentId=231632#action_231632
- http://www.pubbs.net/201002/grails/62508-grails-user-no-signature-of-method-issue-with-list.html
- Yada yada
Using Different AWS S3 Buckets on Different Rails Environments
August 10th, 2010Below is the process for using different buckets on Amazon S3 with your production and development environments (Paperclip)
1. Add config vars to your Heroku environment http://blog.heroku.com/archives/2009/4/7/config-vars/
heroku config:add S3_BUCKET=production-bucket-name S3_KEY=8N029N81 S3_SECRET=9s83109d3+583493190
2. Add the same constants to your .profile file
export S3_BUCKET=development-bucket-name
export S3_KEY=888888888
export S3_SECRET=999999999
ps . Blog Post on Heroku about AWS S3 — http://blog.heroku.com/archives/2009/4/7/config-vars/
ps2. and yes this post is also about heatmap.me which is my pet project for online heatmap generation.
Weird Grails+Adobe+Mac OS X Error
August 3rd, 20102010-08-03 19:00:21.793 java[3891:60f] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper java: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
Yes this seems to be a Mac issue, the solution is as follows:
Solution 1: Update the Adobe Unit Types.osax to version 2.1.0.
- Click this link to download the Adobe Unit Types.osax version 2.1.0 file.
- Choose /Library/ScriptingAdditions.
- Move the existing Adobe Unit Types.osax file to a backup location.
- Copy the downloaded version of the Adobe Unit Types.osax file to the /Library/ScriptingAdditions folder. Select Yes to authenticate this operation.
- Restart your computer.
This is from the link http://kb2.adobe.com/cps/516/cpsid_51615.html
Sending E-mail with Rails via Gmail (Spoiler Alert! this is for dummies)
July 30th, 2010Yes, Rails is super cool, everything is super easy, and so far I really fall in love with it. But why is it that hard to send an e-mail via Gmail !?!
So after messing up a couple of git branches, I finally get it work, yey!
Here are the steps:
- Watch the railscast about sending email
- Install the gem with TLS
sudo gem install ambethia-smtp-tls -v '1.1.2' --source http://gems.github.com
#to the top of file
require 'smtp-tls'
...
#to the very end of the file
ActionMailer::Base.smtp_settings =
{
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "dkberktas",#not with @gmail.com
:password => "xxxyyyzzz",
:authentication => :plain,
:enable_starttls_auto => true
}
script/generate mailer user_mailer
def registration_confirmation()
recipients "xxx@gmail.com"
from "xxx@gmail.com"
subject "Thank you for being that awesome"
body "no I am just kidding" #if you want to pass parameter do it like this -- > ":user => user"
end
#in application controller
def mailDeneme
UserMailer.deliver_registration_confirmation()
render :text => "OK"
end
#in routes.rb
map.mail '/mail', :controller => 'application', :action => 'mailDeneme'
If you see an error like this:
Net::SMTPAuthenticationError (530 5.7.0 Must issue a STARTTLS command first.
You miss the item above about installing smtp-tls gem. Read it again again, or check this forum post.
ps. This is the official rails guide.
ps2. this is another link.
Background Jobs in Rails — Delayed_job
July 22nd, 2010Rails has lots of options for background jobs, the list below is a collection of link that help my choose Delayed Jobs which is a simple and capable enough one.
- Blog post which is a good summary of alternatives — (kind of a survey)
- A related question on StackOverflow
- Blog post about Delayed Job link
- Heroku suggests Delayed Job, so this is the one I am looking for
- and finally this is the Heroku guide for using Delayed Job
- Railcast about Delyaed_job
- Tip&Tricks
If you are interested, we are using Delayed Job for creating our heatmaps for remotespots usability testing site. Heatmap project will probably work as a separate project so that others can also use it for creating heatmaps on top of their images. Stay tuned for the heatmap side project!
Steps for Delayed_job
- Install the plugin from github (from collectiveideas) with
script/plugin install git://github.com/collectiveidea/delayed_job.git
script/generate delayed_job
rake db:migrate
send_later(:your_method_name, -3, 3.days.from_now)
Summary of Web Application Libraries for iPhone
July 17th, 2010PastryKit — it is from Apple, but it is not public, you can see it from the iPhone User Guide, it will be released to public hopefully.
- http://stackoverflow.com/questions/1143589/what-is-the-pastrykit-framework
- http://daringfireball.net/2009/12/pastrykit
- http://ajaxian.com/archives/pastrykit-an-iphone-webdev-library-from-apple
Sencha Touch — you should definitely see their kitchen sink, it is pretty cool.but there is no commercial license yet.
- http://ajaxian.com/archives/sencha-touch
- http://mobile.tutsplus.com/articles/news/sencha-touch-html5-mobile-framework/
- http://www.endofnative.com/

iUi — not that many people using it I guess. I build a site with it, if it is sth fast and easy to learn, iUi can do the job.
- Sites build with iUi — http://code.google.com/p/iui/wiki/PoweredBy
jqtouch — demos seem very nice, probably better than iUi in terms of current release capabilities and size of community.
iWebkit — demo seems promising, but not ready for prime time.
SproutCore — not for iPhone specificly, but its demo seems nice.
So my choice for the next task is jqtouch. not iui this time.
Using AWS S3 Service with RoR Paperclip
July 15th, 2010Continuing from the last post, you might want to use AWS S3 for hosting the uploaded files. Actually the steps are pretty easy as described in the following links:
ps. If you are having an error like this
ArgumentError: wrong number of arguments (5 for 4)
this is probably because you have both the aws-s3 gem and right_aws, just change the environment.rb
as in the following link
http://stackoverflow.com/questions/1550708/rails-paperclip-conflict-between-aws-s3-gem-and-right-aws-gem-how-to-solve
ps2. If you are planning to deploy to heroku add the gem to .gems file, or you will get an error like this “App failed to start” — your application is missing the following gems:…”

Paperclip and ImageMagick and a Weird Problem — in RoR
July 13th, 2010As promised in the last post, here is the Paperclip and ImageMagick as an extension to railstutorial.
For image upload and manipulation, Paperclip seems to be the solutions. The following links does a great job of describing the installation process and basic usage, so I have nothing to add here.
- Paperclip: Attaching Files in Rails (don’t use SVN, use git repo instead as in the second link below)
- Goodbye attachment_fu, hello Paperclip
- http://railscasts.com/episodes/134-paperclip
- The Ruby On Rails Paperclip Plugin Tutorial – Easy Image Attachments
- Ruby On Rails Polymorphic Paperclip Plug-in Tutorial
So far so good, but if you are following railstutorial, you will probably doing this stuff to micropost, and you will probably get an error like this,
- “missing” image replacement in microspots
- In the log/development.log file,
Rendering rescues/layout (not_found)
Solution:
If you carefully inspect the log file you can catch the line
[4;36;1mMicropost Create (0.4ms)[0m [0;1mINSERT INTO “microposts” (“created_at”, “photo_file_size”, “updated_at”, “photo_file_name”, “photo_content_type”, “user_id”, “photo_updated_at”, “content”)
Just with just one line, open your model and fix the accessibility:
class Micropost & ActiveRecord::Base attr_accessible :content, :photo ...
ps. In case you are a noob like me in RoR, this link shows howto uninstall the paperclip plug in.
ps2. Another possible problem might be your ImageMagick installation, make sure you have the correct path by trying convert and identify command. In case add the path to development.rb as described this Stackoverflow entry.
Summary of Steps to add Paperclip
- script/plugin install git://github.com/thoughtbot/paperclip.git
- script/generate paperclip product photo
- In the model
has_attached_file :photo
- In the form
header part
<% form_for @micropost do |f| %>
<% form_for @micropost, :html => { :multipart => true} do |f| %>
body part
<p> <%= f.file_field :photo %> </p>
- To show the uploaded file
<%= image_tag @product.photo.url %>





