Skip to content

Instantly share code, notes, and snippets.

View karuppasamy's full-sized avatar
🎯
Focusing

Karuppasamy M karuppasamy

🎯
Focusing
  • Cognizant
  • Belfast, NI
View GitHub Profile
class DoNotDisturb
def initialize
@desk = InformationDesk.new
end
def method_missing(name, *args)
unless name.to_s == "emergency"
hour = Time.now.hour
raise "Out for lunch" if hour >= 12 && hour < 14
end
@karuppasamy
karuppasamy / calculate_duration.rb
Created March 8, 2016 03:06
ruby - number of months between dates
(end_date.year * 12 + end_date.month) - (start_date.year * 12 + start_date.month) + (end_date.day >= start_date.day ? 1 : 0)
@karuppasamy
karuppasamy / i18n_yaml_sort.rb
Created March 8, 2016 15:50
Sort I18n yaml files
# Recursive sorting algorithm for Hash
class Hash
def sort_by_key(recursive = false, &block)
self.keys.sort(&block).reduce({}) do |seed, key|
seed[key] = self[key]
if recursive && seed[key].is_a?(Hash)
seed[key] = seed[key].sort_by_key(true, &block)
end
seed
@karuppasamy
karuppasamy / sublime-linter-settings
Created May 4, 2016 16:00
Sublime - Linter Settings
{
"user": {
"debug": false,
"delay": 0.25,
"error_color": "D02000",
"gutter_theme": "Packages/SublimeLinter/gutter-themes/Default/Default.gutter-theme",
"gutter_theme_excludes": [],
"lint_mode": "background",
"linters": {
"eslint": {
@karuppasamy
karuppasamy / pre-commit
Created July 25, 2016 04:15
Git pre-commit hook
#!/usr/bin/env sh
# This hook has a focus on portability.
# This hook will attempt to setup your environment before running checks.
#
# If you would like `pre-commit` to get out of your way and you are comfortable
# setting up your own environment, you can install the manual hook using:
#
# pre-commit install --manual
#
@karuppasamy
karuppasamy / pre-push
Created July 25, 2016 04:17
Git Pre-push - Notify on Pivotal Tracker
#!/usr/bin/env ruby
# encoding: UTF-8
# Atlassian Stash and Pivotal Tracker Integration
# ===============================================
# - Post commit message details on Pivotal Tracker's user story
# Usage
# =====
# Create a branch with hash(#) + user story id. (#123467)
@karuppasamy
karuppasamy / git-activity
Created July 25, 2016 04:17
Git activity.
#!/bin/bash
set -e
GIT_OPTS=""
OUTPUT_FILTER="cat" # no-op
commit_id_format=$(tput setaf 1)
date_format=$(tput bold; tput setaf 4)
author_format=$(tput setaf 2)
@karuppasamy
karuppasamy / git-info
Created July 25, 2016 04:18
Git Info
#!/bin/bash
set -e
# actually parse the options and do stuff
while [[ $1 = -?* ]]; do
case $1 in
--gc)
echo "Repacking objects"
git gc --aggressive --auto
@karuppasamy
karuppasamy / git-delete-remote-branch
Created July 25, 2016 04:20
Git - Delete remote branches
# Delete remote branches except `master` and `development`
git branch -r --merged | grep origin | grep -v '>' | grep -v master | grep -v development | grep -v sprint | xargs -L1 | cut -d"/" -f2- | xargs git push origin --delete > ~/Documents/remote_branch
@karuppasamy
karuppasamy / module_private_public.rb
Created November 12, 2018 09:41
Ruby Module - Private, Public method
module Bar
def self.included(base)
class << base
def public_method # public method
puts "public method"
end
def call_private # public method
puts "Call Private from Public"
private_method