Skip to content

Instantly share code, notes, and snippets.

View Mothirajha's full-sized avatar

Mothirajha Mothirajha

View GitHub Profile
@Mothirajha
Mothirajha / gist:1742012630bb0559842a
Created January 1, 2016 18:12 — forked from jugyo/gist:3882497
nginx + ngx_lua on Mac
@Mothirajha
Mothirajha / .vimrc
Last active August 29, 2015 14:22
New Vimrc config
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
set tabstop=2
set shiftwidth=2
set softtabstop=2
set smarttab
set expandtab
set number
@Mothirajha
Mothirajha / print_missing_element.rb
Last active August 29, 2015 14:19
Print missing elements that lie in range 0-99 without using array
a = [88, 105, 3, 2, 200, 0, 10]
a.delete_if {|num| num > 99} # [88, 3, 2, 0, 10]
#a.sort #[0, 2, 3, 10, 88]
c = []
range = 0..99
range.each do |x|
c << x unless a.include?(x)
end
c.each_with_index do |v, i|
@Mothirajha
Mothirajha / interchange_array_element.rb
Last active August 29, 2015 14:18
[[1,2,3], [4,5,6],[7,8,9]] to [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
#INPUT:
[[1,2,3], [4,5,6],[7,8,9]]
l = [[1,2,3], [4,5,6],[7,8,9]]
l.length
l[0].zip(l[1], l[2])
#OUTPUT:
@Mothirajha
Mothirajha / gist:6907f904e43d60bcf6c8
Created March 30, 2015 04:17
Subtraction without arithmetic Operators
http://www.geeksforgeeks.org/subtract-two-numbers-without-using-arithmetic-operators/
http://zetcode.com/lang/rubytutorial/expressions/
@Mothirajha
Mothirajha / angle_btw_hands_in_clock.rb
Created March 27, 2015 10:23
Find the angel between hour hand and the minute hand of the clock
# Let me do it later
@Mothirajha
Mothirajha / SquareOfNumber
Created March 27, 2015 10:10
Find square of the given number without using * or pow() or any methods
p "Please provide a number to find the square root"
number = gets.chomp
end_number = number.to_i
start_number = 1
result = 0
(start_number..end_number).each do |sq_num|
result += end_number
end
@Mothirajha
Mothirajha / word_count
Last active August 29, 2015 14:17
Count words present in text
# Get the highly repeated word in the given text with count
# Get the count of given word (text) in the text
text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
words = text.split
frequencies = Hash.new(0)
words.each {|w| frequencies[w] += 1 }
result = frequencies.sort_by{|k,v| v}.reverse
@Mothirajha
Mothirajha / rails-4
Last active August 29, 2015 14:13
Rails 4 Upgradation
Gem file:
Gem rails -v
Remove assests and add the following default rails
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
Error 1:
Check whether all gems in Gemfile are compatible with all their dependencies.
@Mothirajha
Mothirajha / migration
Last active August 29, 2015 14:12
mysql
-- -- -- Data Migration For Organizor -- -- --
-- What is it?
-- List of SQL queries to migrate data from old database to the newly designed database.
-- It has been classified into two levels
-- 1. Level 1 (which will be in top of database hierarchy)
-- 2. Level 2 (which will be depend on the Level 1 tables)
-- Prerequisites for data migration
-- Login into MySQL prompt