Skip to content

Instantly share code, notes, and snippets.

View AnkurVyas-BTC's full-sized avatar
🎯
Karma rules world... You get whatever you give!

Ankur Vyas AnkurVyas-BTC

🎯
Karma rules world... You get whatever you give!
View GitHub Profile
@AnkurVyas-BTC
AnkurVyas-BTC / solidus_my_extension.gemspec
Last active July 23, 2016 19:50
Solidus Extension gemspec file
# encoding: UTF-8
$:.push File.expand_path('../lib', __FILE__)
require 'solidus_my_extension/version'
Gem::Specification.new do |s|
s.name = 'solidus_my_extension'
s.version = SolidusMyExtension::VERSION
s.summary = 'This is for test summary'
s.description = 'This is for test description'
s.license = 'BSD-3-Clause'
@AnkurVyas-BTC
AnkurVyas-BTC / database.yml
Created July 23, 2016 20:18
Database yml file for solidus example
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: postgres
password: root
host: localhost
development:
<<: *default
@AnkurVyas-BTC
AnkurVyas-BTC / message_controller_index_method.rb
Created July 24, 2016 07:40
Index method of the message controller.
class MessagesController < ApplicationController
def index
@message = Message.all
#Retrives all messages and divides into two groups todays messages and other messages
@grouped_messages = @message.group_by{ |t| t.created_at.to_date == DateTime.now.to_date }
if @grouped_messages[false].present?
#Create month wise groups of messages
@AnkurVyas-BTC
AnkurVyas-BTC / messages_view_part.html.erb
Created July 24, 2016 07:47
The view part to display the messages.
<h1>Messages</h1>
<!-- Todays messages -->
<% if @grouped_messages.present? && @grouped_messages[true].present? %>
<h3> Today </h3>
<% @grouped_messages[true].each do |msg| %>
<%= msg.content %>
<%= msg.created_at.strftime('%I:%M %p') %>
<br />
@AnkurVyas-BTC
AnkurVyas-BTC / simple_case_statement.rb
Created July 24, 2016 08:05
How to write simple case statement ruby
case
when input = '+'
puts 'The operation is addition'
when '-'
puts 'The operation is subtraction'
when '*'
puts 'The operation is multiplication'
else
puts 'The operation is division'
end
@AnkurVyas-BTC
AnkurVyas-BTC / formatted_code_for_more_parameters.rb
Created July 24, 2016 08:07
How to write formatted code when there are more parameters
def send_mail(source)
Mailer.deliver( to: '[email protected]',
from: '[email protected]',
subject: 'Message subject',
body: source.text)
end
@AnkurVyas-BTC
AnkurVyas-BTC / setting_variables_with_if_else.rb
Created July 24, 2016 08:08
How to set variables with if else.
variable_result = if condition_1
a
else_if condition_2
b
else
c
end
@AnkurVyas-BTC
AnkurVyas-BTC / word_counted_gem_controller.rb
Last active August 3, 2016 05:53
Controller for Word counted gem
class WordCountController < ApplicationController
CHARGE_PER_WORDS_BUNCH = 50
WORDS_PER_BUNCH = 100
def index
@sentence = 'Keyword density is the percentage of times a keyword or phrase appears on a web page compared to the total number of words on the page. In the context of search engine optimization keyword density can be used as a factor in determining whether a web page is relevant to a specified keyword or keyword phrase.
In the late 1990s, which was the early days of search engines, keyword density was an important factor in how a page was ranked. However, as webmasters discovered this and the implementation of optimum keyword density became widespread, it became a minor factor in the rankings. Search engines began giving priority to other factors that are beyond the direct control of webmasters. Today, the overuse of keywords, a practice called keyword stuffing, will cause a web page to be penalized.
Many SEO experts consider the optimum keyword density t
module ApplicationHelper
STOP_WORDS = ["a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also","although","always","am","among", "amongst", "amoungst", "amount", "an", "and", "another", "any","anyhow","anyone","anything","anyway", "anywhere", "are", "around", "as", "at", "back","be","became", "because","become","becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom","but", "by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry", "de", "describe", "detail", "do", "done", "down", "due", "during", "each", "eg", "eight", "either", "eleven","else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further",
@AnkurVyas-BTC
AnkurVyas-BTC / word_counted_gem_index.html.erb
Last active August 2, 2016 15:15
Wordcounted gem index page view
<h1>Content</h1>
<p> <%= @sentence%></p>
<h1>Content Stats</h1>
<p><b>Total Words</b> = <%= @counter_with_stop_words.token_count %></p>
<p><b>Total Price</b> = $<%= @price %></p>