Thursday, 18 May 2017

CKEditor for rails asset pipeline

1. Include ckeditor_rails in Gemefile
  gem 'ckeditor_rails'
2. Add to your app/assets/javascripts/application.js after //= require jquery_ujs to work with jQuery
//= require ckeditor-jquery
3. Add ckeditor class to text area tag
<%= f.text_area :content, :class => 'ckeditor' %>

4. Initialize CKEditor in Javascript file

<script type="text/javascript"> 
  $('.ckeditor').ckeditor({
     width: '735',
     height: '0',
     // optional config
  });
</script>

Add to ck-editor in HTML:

1. <textarea name="editor1" id="editor1" rows="10" cols="80"></textarea>
<script type="text/javascript">
  CKEDITOR.replace('editor1')
</script>

Monday, 15 May 2017

Image zoom Simple-jQuery-Image-Magnifier-Enlargement-Plugin-imagezoom.html

Basic Usage:

Js: 
2<script src="imagezoom.js"></script>
HTML:

<img src="<%= @product.image %>" data-imagezoom="true" data-magnification="3" data-zoomviewsize="[270,330]" class="simpleLens-big-image img-responsive" style="width: 270px; height: 330px">




Css:


.tgl {
  display: none;
}
.tgl, .tgl:after, .tgl:before, .tgl *, .tgl *:after, .tgl *:before, .tgl + .tgl-btn {
  box-sizing: border-box;
}
.tgl::-moz-selection, .tgl:after::-moz-selection, .tgl:before::-moz-selection, .tgl *::-moz-selection, .tgl *:after::-moz-selection, .tgl *:before::-moz-selection, .tgl + .tgl-btn::-moz-selection {
  background: none;
}
.tgl::selection, .tgl:after::selection, .tgl:before::selection, .tgl *::selection, .tgl *:after::selection, .tgl *:before::selection, .tgl + .tgl-btn::selection {
  background: none;
}
.tgl + .tgl-btn {
  outline: 0;
  display: block;
  width: 4em;
  height: 2em;
  position: relative;
  cursor: pointer;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}
.tgl + .tgl-btn:after, .tgl + .tgl-btn:before {
  position: relative;
  display: block;
  content: "";
  width: 50%;
  height: 100%;
}
.tgl + .tgl-btn:after {
  left: 0;
}
.tgl + .tgl-btn:before {
  display: none;
}
.tgl:checked + .tgl-btn:after {
  left: 50%;
}

.tgl-ios + .tgl-btn {
  background: #fbfbfb;
  border-radius: 2em;
  padding: 2px;
  -webkit-transition: all .4s ease;
  transition: all .4s ease;
  border: 1px solid #e8eae9;
}
.tgl-ios + .tgl-btn:after {
  border-radius: 2em;
  background: #fbfbfb;
  -webkit-transition: left 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), padding 0.3s ease, margin 0.3s ease;
  transition: left 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), padding 0.3s ease, margin 0.3s ease;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1), 0 4px 0 rgba(0, 0, 0, 0.08);
}
.tgl-ios + .tgl-btn:hover:after {
  will-change: padding;
}
.tgl-ios + .tgl-btn:active {
  box-shadow: inset 0 0 0 2em #e8eae9;
}
.tgl-ios + .tgl-btn:active:after {
  padding-right: .8em;
}
.tgl-ios:checked + .tgl-btn {
  background: #86d993;
}
.tgl-ios:checked + .tgl-btn:active {
  box-shadow: none;
}
.tgl-ios:checked + .tgl-btn:active:after {
  margin-left: -.8em;
}


URL: 

http://www.jqueryscript.net/zoom/Simple-jQuery-Image-Magnifier-Enlargement-Plugin-imagezoom.html

Wednesday, 19 April 2017

Ruby Arrays: Insert, Append, Length, Index, Remove

In this tutorial, we will cover:
  • How to create a Ruby array
  • How to access Elements
  • How to add elements to a list
  • How to delete elements from a list

Create a Ruby Array

Arrays can be created in various ways. All you need is a variable name.
The first two examples instantiate an array in the letters variable. Take note that they won’t have any values.
Arrays can be created by getting an instance of the Array class.
2.0.0-p0 :002 > letters = Array.new
 => [] 
A nice shortcut for this is to just give the value of [].
 2.0.0-p0 :003 > letters = []
 => [] 
Most of the time, we would like to have values in arrays we create. Here’s a very simple example on how to do it.
2.0.0-p0 :006 > letters = Array.new(['a', 'b'])
 => ["a", "b"] 
Again, there’s a shortcut.
2.0.0-p0 :001 > letters = ['a', 'b', 'c']
 => ["a", "b", "c"] 
Note that the long method is quite useful when you want to define how many elements your array would be.
2.0.0-p0 :007 > letters = Array.new(3)
 => [nil, nil, nil] 
We can also add default values to the elements
2.0.0-p0 :008 > letters = Array.new(3, 'me rocks')
 => ["me rocks", "me rocks", "me rocks"]

Accessing Elements

Accessing elements in Ruby is easy. Just like in most languages, arrays can be accessed via their indexes.
Now let’s create an array.
2.0.0-p0 :009 > letters = Array.new(['a', 'b', 'c'])
 => ["a", "b", "c"] 

Accessing the first element.

Usually done by using the index 0
2.0.0-p0 :010 > letters[0]
 => "a"

Accessing the last element.

2.0.0-p0 :011 > letters[-1]
 => "c"
Negative values go in reverse starting at -1, the last element. Naturally, the second to the last element would be accessed by [-2].
2.0.0-p0 :012 > letters[-2]
 => "b"

Inserting / Adding Elements

Inserting elements in a ruby array is very straight forward. We have 3 methods on how to insert elements on arrays.
Let’s try them on our example.
2.0.0-p0 :014 > letters = Array.new(['a', 'b', 'c'])
 => ["a", "b", "c"]

Using Ruby’s Array’s insert method

I love the insert method because it allows you to insert elements at various places in the array.
2.0.0-p0 :015 > letters.insert(0, 1)
 => [1, "a", "b", "c", "d"]
2.0.0-p0 :016 > letters.insert(-1, 'd')
 => [1, "a", "b", "c", "d"]

Using the “double less than” method

2.0.0-p0 :017 > letters << 'e'
 => [1, "a", "b", "c", "d", "e"] 

Using the Ruby’s array’s push method

2.0.0-p0 :018 > letters.push('f')
 => [1, "a", "b", "c", "d", "e", "f"] 

Removing Elements

If we can insert elements, why can’t we delete some?

Using the Ruby’s array’s pop method

The pop method let’s you remove the last element in the array.
2.0.0-p0 :021 > letters = Array.new(['a', 'b', 'c', 'd'])
 => ["a", "b", "c", "d"] 
2.0.0-p0 :022 > letters.pop
 => "d" 
2.0.0-p0 :023 > letters
 => ["a", "b", "c"]

Using the Ruby’s array’s delete_at method

When deleting an element at a particular index, delete_at is your method.
2.0.0-p0 :028 > letters = Array.new(['a', 'b', 'c', 'd'])
 => ["a", "b", "c", "d"] 
2.0.0-p0 :029 > letters.delete_at(2)
 => "c" 
2.0.0-p0 :030 > letters
 => ["a", "b", "d"]
The Ruby language is very a expressive language. There’s a bunch of methods you can use in every situation. This is perhaps why Ruby (and Rails) has seen a large growth of developers usage in the last few years.
I oblige you to learn Ruby and see what you think.