I use Amazon EC2 infrastructure to run my Ruby on Rails application and lately the load time for my application has gone in minutes, actually couple of minutes. After some googling I realized that it does not matter much if I have lots of models and controllers in my code. Most of the time consumed is while loading gems when the application starts. [Source]
So I realized that in my Gemfile I have couple of Gems which were used only during db:seed and are not at all used in production server. But when server is restarted, rails still load these gems as they are mentioned in Gemfile. To avoid this, we can mention ‘require => false’ for such gems and rails will do following:
- Install these gems whenever you run bundle install
- Do not load them when a server starts
- You can still load them by explicitly specifying “require <gemname>” where you need them
This brought down my server load time by 25% of original load time. Here is the log:
- Before using ‘require => true’ :
time r s -d
=> Booting WEBrick
=> Rails 3.0.3 application starting in development on http://0.0.0.0:3000
real 0m21.213s
user 0m17.353s
sys 0m1.852s - After using require => true (e.g. gem testgem, :require => true)
time r s -d
=> Booting WEBrick
=> Rails 3.0.3 application starting in development on http://0.0.0.0:3000
real 0m17.351s
user 0m13.865s
sys 0m1.648s
Source code and sample html available at: https://github.com/prabgupt/googleMap_virtual_tour
Usage: Mentioned in README present at git repo above
Purpose of Plugin: You can display virtual tours between places on map. Currently, above sample show animation of marker moving along actual direction path between places located on map in sequence specified.
Prequisite
- HTML, jQuery/JavaScript knowledge is required
- Basic knowledge about methods available in google Maps Javascript API v3 is recommended
Summary about method’s inside custom googleMaps js
You’ll need to mainly use two method just like used in sample html.
- showMapForDay- This method would render the map with places displayed as markers and routes connecting those places. It takes following arguments:
location 2D Array – It contains single locations in format [lat, lng] and routes in format [[lat1, lng2], [lat1, lng2]]. You can skip routes from this array if in your case, there will always be a route between two consecutive locations. Routes then, can be auto-generated inside this method after modifying its code a little bit.
zoom - zoom level which you want to set for your map
divId - This is div element Id inside which you want to show map. Google Maps libraries need this as an argument and hence passed here.
Description Array – This is array containing description about each location to be displayed in infoWindow when corresponding marker on map is clicked. This attribute allows HTML code inside it.
- animateTrip – This method displays virtual tour between places in sequence as specified. It also supports play/pause feature. If this function is called when tour is running, it resumes tour while if it is called when no tour is running, it starts tour. Few of the arguments in this method are same as above method:
divId - This is div element Id inside which you want to show map. Google Maps libraries need this as an argument and hence passed here.
location 2D Array – It contains single locations in format [lat, lng]
Description Array – This is array containing description about each location to be displayed in infoWindow when place is reached while virtual tour. This attribute allows HTML code inside it.
callBack Function – This function specifies what to do when tours end. In case not provided, map will halt at last location with its infoWindow opened.
Main function which is actually responsible for enabling virtual tour animation
- animate - We call this function periodically using ‘setTimeout’ Handler and each time this function is called, marker location is incremented by ‘step’(constant variable in js). In case current step is closer to the place we have located on map, marker is displayed for the location and corresponding infoWindow is opened by triggering ‘click’ action on the marker. Likewise, we keep proceeding until we reach ‘eol’(another variable in js) which signifies total path distance to be traveled on map and is calculated dynamically based on map’s locations.
Anurag Rawat joined as as our Sales and Marketing go-to-guy for 2 months from IIM Calcutta and today was his last day before he joins his new job in Boston Consulting Group. Team went out for a dinner and Anurag was more than willing to treat us ![]()
Had some nice get together and lot of gyaan flowed during ‘Happy Hours’. We were joined by Ananya, newest member to the team (6 months old), who loves eating desserts.
We wish good luck to Anurag for his future adventures.
Some pictures to remember the good time:
Source code and sample available at: https://github.com/prabgupt/youtube_video_upload_plugin
Usage: Please note that sample is available for RoR3 but it can be easily converted for any underlying platform. Refer README in git repo above to know how to run it in RoR3. To see how to tweak code to use it for any other platform, keep reading the post.
Purpose of this Utility: It will upload end user’s video directly to youtube and is easily integratable within your website.
Few Advantage:
- No need to have storage on server machine as you can now dump/use all videos directly to/from youtube.
- In case you have youtube channel, can directly organize video uploaded through your site to youtube channel.
- NO need for end user to login to youtube first to upload video through your site.
Flow to upload video on YouTube
- Website requests token and upload URL from youtube for every new video request. This is needed to avoid having end user logging into his/her YouTube account.
- Post your video to URL received in step#1 with parameter ‘nexturl’. ‘nexturl’ is callback url to be called by YouTube with status and video_id once upload operation is completed with failure or success. You need to send token received in step#1 too along with.
- Youtube invokes ‘nexturl’ with status and video_id, if upload is successful. Process/store this video_id as this will be key from now onwards based on which you can perform operations on this video directly in YouTube.
Source code contains of following things that you need to know:
youtubeUtilAPIs.py- Python script that uses Google Data Python client library. This script contains few methods performing certain operation on youtube.
Usage: py [-t <comma separated title and description>] [-u <video_id>] [-s <video_id>] [-d <video_id>]
-t => to get token and url. Input required is comma separated video title and video description
-u => to get youtube URL for that video. Input required is video_id
-s => to get upload status of the video. Input required is video_id
-d => to delete video from youtube. Input required is video_id
Prerequisite:
-
- Please refer Getting Started guide. In nutshell, you need to install Python and then google Data Library as specified in the link.
- Replace following senstive data inside python script; like developer key, password, etc. with that of yours. You will need to sign in for YouTube developer key. Once signed in, register you product and get values for below attributes. ‘source’ and ‘client_id’ will be the name of the product you registered before.
yt_service.developer_key = ‘xxxxxxx’
yt_service.client_id = ‘xxxxxxx’
yt_service.email = ‘xxxxxxx’
yt_service.password = ‘xxxxxxxx’
yt_service.source = ‘xxxxxxxxxx’
- Since above utility contains some sensitive data, hence for security reasons you would need to introduce a server side handler that will execute above script on client request and can send the required details back to client. In our case, we have introduced method ‘uploadToken’ inside multimedia controller which execute python script and returns back token and url needed to upload video on youtube.
- Below is the HTML code you’ll plug into your website to let end user select the video and upload it to youtube. Code just contains a form to have end use select the video and has action, token value blank at render time. If you have already noticed, there is async ajax request present at end of code which fetches upload URL and token from server at time page is loading and populate it inside form once ajax request gets completed.
Source code and README available at: https://github.com/prabgupt/geocode_autocompletion_js
Purpose of this Utility: It will auto suggest world places based on user input
Instructions as well as sample HTML to use the code are mentioned inside README mentioned above.
Making of geocode_autocomplete.js
I’m assuming here that you are already familiar with JavaScript/jQuery. You’ll need to understand following things so as to proceed further:
- autocomple jQuery UI: This jquery displays suggested list based on result passed to it
- Google Maps GeoCoding API usage: I’d recommend you to go through ‘Results‘ structure as it will help you to identify attributes you need to process based on your requirement. Once understood, rest would just be getting those attributes from result.
StepWise description of above code:
# First we bind ‘focus’ event to element so that on focus, we can attach autocomplete handler to it.
# source requires map list that will get displayed as suggestion list. We are calling geocode function of google maps here treating input value as some address. You can change the attribute as per what you expect end user to provide.
On receiving response, we are populating map which will be shown as suggested list. An entry in this suggested list is kinda map containing multiple keys/values. You can add/remove keys as per your requirement.
# minLength attr specifies minimum length of input after which it should try to find suggested list.
# select attr contains functions which gets executed once an entry is selected. In our case, once an entry is selected we process its location(lat/lng) and displays it on UI. You can add your logic that you need to execute once an entry is selected.


