Thursday, 8 November 2012

Ruby script to send windows toast notification

A simple ruby script to send MSDN toast notification for windows phones:

      require 'uri'
      require 'net/http'
      u = URI.parse('your-device-url')
      req =

      req_xml = '<?xml version="1.0" encoding="utf-8"?>'
      req_xml << '<wp:Notification xmlns:wp="WPNotification">'
      req_xml << '<wp:Toast>'
      req_xml << '<wp:Text1>Test title</wp:Text1>'
      req_xml << "<wp:Text2>My First notification</wp:Text2>"
      req_xml << "<wp:Param>/Page1.xaml?id=123</wp:Param>"
      req_xml << '</wp:Toast>'
      req_xml << '</wp:Notification>'

      req.content_type = 'text/xml'
      req['X-WindowsPhone-Target'] = 'toast'
      req['X-NotificationClass'] = '2'
      req.body = req_xml

      resp = Net::HTTP.start(, u.port) do |http|

Wednesday, 19 September 2012

Syncing Amazon S3 buckets

I would recommended two tools to sync data to s3 bucket or between two buckets.

First comes is s3cmd sync which is a command line.
For those who are not comfortable with the command line can checkout - DragonDisk

Wednesday, 6 June 2012

rsync - simple usage

rsync -Avrzh --ignore-existing src/ dest/

This command syncs the new files or dirs from /src to /dest recursively.

Wednesday, 30 May 2012

Linux: Delete old log files

Here's a simple shell command to delete old log(or any) files.


ls -t <list of files> | tail -n <count> | xargs rm -f


 ls -t /data/www/myapp/shared/log/*.log.gz | tail -n +6 | xargs rm -f

This will remove all compressed log files leaving recent 5 backups.

Friday, 9 March 2012

Thursday, 23 February 2012

ffmpeg: transpose and watermark together

Command to transpose and watermark a video at the same time using ffmpeg:

ffmpeg -i test.mp4 -vf 'movie=watermark.png [watermark]; [in] transpose=1 [trans]; [trans][watermark] overlay=2:2 [out]' -y output.mp4

Good luck!

Tuesday, 21 February 2012

Google Apps: Mail server settings

To configure Google apps as the mail server for your domain (provided you have created the MX records on your domain), use these settings:

    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
      :address              => '',
      :port                 => 587,
      :domain               => '',
      :user_name            => '',
      :password             => 'password',
      :authentication       => 'plain',
      :enable_starttls_auto => true

Thursday, 16 February 2012

ffmpeg: video conversion parameters

Sample ffmpeg conversion command - iOS and Android compatible.

ffmpeg -i -s 432x320 -vcodec libx264 -coder 0 -trellis 0 -bf 0 -subq 6 -refs 5 -me_range 16 -g 250 -sc_threshold 40 -keyint_min 25 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -acodec libfaac -ac 2 -b:v 384k -ar 16000 -ab 32000 -r 25 -partitions +parti4x4+parti8x8+partp4x4+partp8x8 -cmp 256 -flags +loop+mv4 -aspect 3:2 -y output.mp4

Tuesday, 7 February 2012

Unix: Search and replace script

Simple Unix command to replace text within a directory.

find app/views/ -type f -print0 | xargs -0 sed -i 's/SearchText/ReplaceText/g'

Tuesday, 31 January 2012

Install latest ffmpeg in Centos

Install ffmpeg from git source on CentOS:


yum install SDL-devel a52dec a52dec-devel alsa-lib-devel faac faac-devel faad2 faad2-devel
yum install freetype-devel giflib gsm gsm-devel imlib2 imlib2-devel lame lame-devel libICE-devel libSM-devel libX11-devel
yum install libXau-devel libXdmcp-devel libXext-devel libXrandr-devel libXrender-devel libXt-devel
yum install libid3tag libogg-devel libvorbis-devel mesa-libGL-devel mesa-libGLU-devel xorg-x11-proto-devel xvidcore xvidcore-devel zlib-devel
yum install amrnb-devel amrwb-devel libtheora libtheora-devel glibc gcc gcc-c++ autoconf automake libtool ncurses-devel libdc1394 libdc1394-devel yasm nasm


cd /usr/local/src
git clone --depth 1 git://
cd ffmpeg
./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvorbis --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
make install
hash x264 ffmpeg ffplay ffprobe


ffmpeg -filters

And you are done.


2). - Installs through automated script.

Monday, 30 January 2012

Paperclip: Unzip/decompress uploaded file

Very often(in a client-server API architecture) we might want to transfer compressed file data over HTTP, so gain speed over file uploads.

So, this is how the decompression code looks like in Rails 3: For a Video model, with 'data' as the paperclip attachment and opts[:data] being the uploaded file.

    tmp_fle =[:data].original_filename.to_s)
    zi =[:data]), "wb+") do |ucf|
      ucf <<
    tmp_fle.binmode = tmp_fle

Hope it works.

Thursday, 5 January 2012

Rails/Mysql - Selecting Random records

The straight forward and the most reliable solution to select random record from a table would be to use rand() in Mysql or random() in Postgres.

However the glitch is with the performance of rand() when using against large tables (even as 1000 rows). With my test results of 750 rows.

Photo.order('rand()').limit(30)  - took 9ms

Photo.where(:id => Photo.order('rand()').limit(30).select(:id).collect(&:id))  - took 2.5ms

So using rand() with selecting just the id, is atleast 3 times faster.