Monday, May 21, 2012

More Tips

It's nice to be learning new stuff. I'm just going to write line by line of some more stuff that I learned ..

Always use UTF-8 as the default charset in Mysql. 

I added this in my.cnf (/etc/)
[mysqld
default-character-set=utf8 
default-collation=utf8_general_ci 
character-set-server=utf8 
collation-server=utf8_general_ci 
init-connect='SET NAMES utf8' 
[client
default-character-set=utf8

If you are trying to sync between DBs, then take chunks of data.

Say you are trying to sync between DBs. And you want to do some transformation before sync (May be rename some columns). Then you would want to do a select query to get a subset of data (limit n) and then insert it in bulk using values (n values).

If there is a possibility of updates instead of inserts, then use the 'ON DUPLICATE KEY UPDATE' clause.
It's a good idea to update based on timestamps. What I did was that I touched a file everytime I do an update, so that the next time I know where I need to start from.

If a transaction fails because of Lock Errors write a retry routine in Code.

Lock might occur. Especially on DBs where there are a lot of reads/writes. So I would say try writing for x times and then raise an exception.

Optimize Active Admin if using with a DB with many records.

I have had this problem where the data in the table was HUGE and there were associations with another table with HUGE number of records. This caused the application to load very slowly and also made the writes to fail.

The fix that I made was to take out thos associations and write getters and setters instead of the associations. Some extra code, but make a HUGE difference to performance.

Use S3 when you want to store data.

The application had to generate reports and store them for future viewing. The flow in implementation is as follows


  1. User Creates Report
  2. He sets the report to execute on a specific time (he could also execute this report manually)
  3. On triggering of the report, a GeneratedReport is created and the job is pushed to delayed_job
  4. When the delayed_job gets to it, the report is executed and the result is written to a tmp file
  5. This tmp file is uploaded to S3 as a private file and a url is made with an expiration of months.

More to Come.


Thursday, April 12, 2012

ARN Radio 96.7 Dubai in VLC

I have been listening to the malayalam radio station from Dubai (96.7) for some now. Its pretty good with news, greta anchors and good songs. To add it in VLC just add the stream.

http://4103.live.streamtheworld.com/HITAAC

is the url for the stream. Save the playlist too so that you could load it the next time.

Enjoy !

Friday, March 23, 2012

Learning Start

I flew from Bangalore to Berlin on the 1st of March, the day my Visa starts. The weather was cold and gloomy. But I met some Mallus on the way and had some socializing. I asked them about the eating habits, where I could save money and stuff.

It took me 17 hours to reach Tegel, Berlin. After that I took a cab and went to the work place. A great bunch of people greeted me and gave me the laptop and other stuff. I stayed with John for some days before he left for his vacation. John even got me a sim that I have on my phone now !

I managed to get some paper works done. I have got my insurance and Burgeramt as of now. I am waiting for the Work Visa approval, apartment for rent, bank account etc ..

Anna took me to a small bar where they played music and the people who came in sand and played instruments. A bunch of people did a lot of YoYo tricks as well ...

Something like this one


Im at Gregory's apartment for now and am looking out for a place to stay before Reshma comes.\


Rails Dev is going great too ... I learned a lot of stuff too ...

Some of them are

Rspec
Rvm
guard
simplecov
factorygirl
pow and powder
gem based coding and development
databasecleaner
forgery
airbrake
relic
scalarium
activeadmin
devise
vagrant
markdown

Most of them I knew before and understood more ....

Exciting times !!!!

Sunday, January 15, 2012

FB Likes

I have been trying to get the Facebook Like to appear on an application. It was getting somewhat stressful because the Like would just not take the whole URL, but would take the base URL.


I started using the XFBML first because the way to integrate it is so nice. 


Add 


<html xmlns:fb="http://ogp.me/ns/fb#"> 


as the namespace and then use 


<fb:like href="http://google.com/" send="false" layout="button_count" width="450" show_faces="false"></fb:like>


Easy enough. The application used a lot of Ajax and therefore the these likes need some refreshing. To do this I used the Javascript method available


fb.xfbml.parse()


Function and it started working. But the likes were happening only for the base URL and not the href in the fb:like. This is when I saw the statement in the documentation which said 'The XFBML version defaults to the current page.' if href is used. 


urghh


I went on to use the iframe way so that I could get likes for the particular URL. It seems its important that the url end with '/' and only then Facebook identifies the absolute URL.