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 / react_rails_webpack_application.js
Created March 18, 2018 07:28
Contents of pack/application js
// Path: app/javascript/packs/application.js
/* eslint no-console:0 */
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
//
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb
<div class="container">
<%= form_tag comparisons_compare_sections_path, remote: true do %>
<div class="row">
<div class="col-6 pad-a10">
<%= text_area_tag 'left_section', @sample_text, class: 'form-control', size: '50x25' %>
</div>
<div class="col-6 pad-a10">
<%= text_area_tag 'right_section', @sample_text, class: 'form-control', size: '50x25' %>
</div>
<div class="col-12 text-center pad-t10">
<% if @diff_percentage != 0.0 %>
$('.result')
.removeClass('text-success')
.addClass('text-danger')
.html("Percentage Difference: <%= '%.2f' % @diff_percentage %>");
<% else %>
$('.result')
.removeClass('text-danger')
.addClass('text-success')
.html("Both contents are same!");
@AnkurVyas-BTC
AnkurVyas-BTC / blog_comparisons_controller.rb
Created January 28, 2018 09:58
Code for the comparisons controller
class ComparisonsController < ApplicationController
SAMPLE_TEXT =
"<header>
<title> Sample Title </title>
</header>
<navbar>
<ul>
<li>Sample Title 1</li>
<li>Sample Title 2</li>
@AnkurVyas-BTC
AnkurVyas-BTC / SQL Query to retrieve product properties.sql
Last active January 11, 2018 11:36
SQL Query to retrieve product properties
SELECT spree_products.id AS product_id,
MAX(CASE WHEN r.property_id = (select "spree_properties"."id" from "spree_properties" where "spree_properties"."name"='THC' ) THEN r.value ELSE NULL END) AS "THC",
MAX(CASE WHEN r.property_id = (select "spree_properties"."id" from "spree_properties" where "spree_properties"."name"='CBD' ) THEN r.value ELSE NULL END) AS "CBD",
MAX(CASE WHEN r.property_id = (select "spree_properties"."id" from "spree_properties" where "spree_properties"."name"='Material' ) THEN r.value ELSE NULL END) AS "Material",
MAX(CASE WHEN r.property_id = (select "spree_properties"."id" from "spree_properties" where "spree_properties"."name"='Ingredients' ) THEN r.value ELSE NULL END) AS "Ingredients",
MAX(CASE WHEN r.property_id = (select "spree_properties"."id" from "spree_properties" where "spree_properties"."name"='Serving Per Container' ) THEN r.value ELSE NULL END) AS "Serving Per Container",
MAX(CASE WHEN r.property_id = (select "spree_properties"."i
@AnkurVyas-BTC
AnkurVyas-BTC / git_release_tag.txt
Last active September 18, 2017 09:18
How can we add tags to github project.
How to add tags in github project.
git tag -a v2.8.0 -m "v2.8.0 Release"
git push origin master --follow-tags
heroku run rake db:migrate --remote=production # Run migrations if needed
//= require jquery
//= require spec_helper
describe("Static Page Test", function () {
it("test static page", function () {
// replace body contents with static HTML
$('body').html(JST['templates/static_template']());
expect($('#sample-form').is(':visible')).to.be.true;
<div id="sample-form">
<h1>I am sample title</h1>
<input type="textbox" name="" value="type here" id="input-1">
</div>
@AnkurVyas-BTC
AnkurVyas-BTC / mocha_test_blog_konacha.rb
Created June 28, 2017 16:01
Konacha initializer file
Konacha.configure do |config|
config.spec_dir = 'spec/javascripts'
config.spec_matcher = /_spec\.|_test\./
config.stylesheets = %w(application)
config.driver = :webkit
end if defined?(Konacha)
//= require calculator
describe("Calculator", function () {
it("test add function", function () {
expect(add(1, 2)).to.equal(3);
});
it("test subtract function", function () {
expect(subtract(10, 4)).to.equal(6);