Skip to content

Instantly share code, notes, and snippets.

View harish86's full-sized avatar

Harish Premkumar harish86

View GitHub Profile
@harish86
harish86 / locations-lat-long-radius-and-distance.txt
Created May 8, 2013 03:20
To find distance between two locations and to find locations within the given radius in a Ruby on Rails application. Note: this code snippet is based on the ideas and examples found by googling.
Table schema for locations:
===========================
create_table "locations", :force => true do |t|
t.string "zipcode", :limit => 6
t.string "city", :limit => 25
t.string "state_code", :limit => 3
t.string "state_name", :limit => 25
t.float "latitude"
t.float "longitude"
@harish86
harish86 / items-sitemap.xml.builder
Last active December 17, 2015 07:39
Building xml sitemaps in rails.
# Below is a snippet to generate sitemap.xml file
# Reference: http://www.sitemaps.org, http://en.wikipedia.org/wiki/Site_map, http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668&topic=8476&ctx=topic
xml.instruct!
xml.urlset(:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9") {
@items.each do |item|
xml.url {
xml.loc(item_url(item))
@harish86
harish86 / Capfile
Created May 15, 2013 02:25
Capistrano deployment script. After installing capistrano gem, run the command 'capify .' from the root directory of a rails application
# Location: /Capfile
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks
@harish86
harish86 / app_config.rb
Created May 15, 2013 03:20
Initializing APP_CONFIG from /config/config.yml in a rails application
# Location: config/initializers/app_config.rb
APP_CONFIG = YAML.load_file(File.join(Rails.root, 'config', 'config.yml'))[Rails.env]
@harish86
harish86 / edit-commit-author.sh
Created May 18, 2013 18:49
Git: Changing author name or email for old commits in a git repo. Extracted from: http://stackoverflow.com/questions/750172/how-do-i-change-the-author-of-a-commit-in-git
git filter-branch --commit-filter '
if [ "$GIT_COMMITTER_NAME" = "<Old Name>" ];
then
GIT_COMMITTER_NAME="<New Name>";
GIT_AUTHOR_NAME="<New Name>";
GIT_COMMITTER_EMAIL="<New Email>";
GIT_AUTHOR_EMAIL="<New Email>";
git commit-tree "$@";
else
git commit-tree "$@";
#!/bin/bash
### Setup a wifi Access Point on Ubuntu 12.04 (or its derivatives).
### make sure that this script is executed from root
if [ $(whoami) != 'root' ]
then
echo "
This script should be executed as root or with sudo:
sudo $0
"
@harish86
harish86 / install.sh
Created October 9, 2017 11:05 — forked from ziadoz/install.sh
Install Chrome, ChromeDriver and Selenium on Ubuntu 16.04
#!/usr/bin/env bash
# https://developers.supportbee.com/blog/setting-up-cucumber-to-run-with-Chrome-on-Linux/
# https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c
# http://stackoverflow.com/questions/10792403/how-do-i-get-chrome-working-with-selenium-using-php-webdriver
# http://stackoverflow.com/questions/26133486/how-to-specify-binary-path-for-remote-chromedriver-in-codeception
# http://stackoverflow.com/questions/40262682/how-to-run-selenium-3-x-with-chrome-driver-through-terminal
# http://askubuntu.com/questions/760085/how-do-you-install-google-chrome-on-ubuntu-16-04
# Versions
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
@harish86
harish86 / base_controller.rb
Created May 16, 2013 05:06
Base controller for JSON APIs in a ruby on rails application. Inheriting Api::BaseController to any controller adds basic functionality to handle exceptions and denying unauthorized access to the API.
# Location: app/controllers/api/base_controller.rb
class Api::BaseController < ApplicationController
rescue_from ::Exception, :with => :rescue_exception
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
rescue_from ActionController::RoutingError, :with => :routing_error
def undefined_route
routing_error
end