This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Session controller provides a token | |
#/controllers/api/sessions_controller.rb | |
class Api::SessionsController < Devise::SessionsController | |
before_filter :authenticate_user!, :except => [:create] | |
before_filter :ensure_params_exist, :except => [:destroy] | |
respond_to :json | |
def create | |
resource = User.find_for_database_authentication(:email => params[:user_login][:email]) | |
return invalid_login_attempt unless resource |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://www.amooma.de/screencasts/2015-01-22-nested_forms-rails-4.2/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
________________________________________________________________________________________________________________ | |
================================================================================================================ | |
Local setup for elastic search | |
sudo apt-get update | |
sudo apt-get install openjdk-7-jre-headless -y | |
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.6.deb | |
sudo dpkg -i elasticsearch-0.20.6.deb | |
sudo service elasticsearch start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="contacts-cnt"> | |
<%= form_tag admin_user_update_users_path(:id=>@list.user.id), :method => 'post',:id => "#{@list.id}" do%> | |
<div class="admin-edit-form-row"> | |
<div class="user-edit-form-left">Contact Name </div> | |
<div class="user-edit-form-right"> | |
<%=text_field_tag :first_name, "#{@list.user.first_name.blank? ? ' ' : @list.user.first_name}",:placeholder => "Name" %> | |
</div> | |
<div class="admin-edit-form-row"> | |
<div class="user-edit-form-left">Mobile : </div> | |
<div class="user-edit-form-right"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # if params[:my_action].present? && params[:listing_id].present? | |
# # SidebarAdd.where(:listing_id => [1,2,3,4]).each do |sidebar| | |
# # sidebar.update_attributes(:action => params[:my_action],:view_count =>sidebar.view_count+1 ) | |
# # end | |
# # end | |
# add_data=[] | |
# sidebar_add=SidebarAdd.paginate(:page => params[:page], :per_page => 4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> [1,2,3].map{ |i| i+1 } | |
=> [2, 3, 4] | |
_______________________________________________________________ | |
> { "x" => 1, "y" => 2, "z" => 3 }.map{ |k,v| k.to_sym => v } | |
SyntaxError: (irb):2: syntax error, unexpected tASSOC, expecting '}' | |
{ "x" => 1, "y" => 2, "z" => 3 }.map{ |k,v| k.to_sym => v } | |
from /home/smeagol/.rvm/rubies/ruby-1.9.3-p429/bin/irb:16:in `<main>' | |
____________________________________________________________________________________ | |
> { "x" => 1, "y" => 2, "z" => 3 }.map{ |k,v| { k.to_sym => v } } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Change the default message of jquery validation | |
jQuery.extend(jQuery.validator.messages, { | |
required: "This field is required.", | |
remote: "Please fix this field.", | |
email: "Please enter a valid email address.", | |
url: "Please enter a valid URL.", | |
date: "Please enter a valid date.", | |
dateISO: "Please enter a valid date (ISO).", | |
number: "Please enter a valid number.", | |
digits: "Please enter only digits.", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Delete the tables if they already exist */ | |
drop table if exists Movie; | |
drop table if exists Reviewer; | |
drop table if exists Rating; | |
/* Create the schema for our tables */ | |
create table Movie(mID int, title text, year int, director text); | |
create table Reviewer(rID int, name text); | |
create table Rating(rID int, mID int, stars int, ratingDate date); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Tested with ruby 1.8.7 on a Debian machine, with my own gmail account. | |
ruby -rubygems "from name" "from email" "to name" "to email" "subject" "body" | |
=end | |
require 'net/smtp' | |
require 'tlsmail' | |
Net::SMTP.enable_tls OpenSSL::SSL::VERIFY_NONE | |
$SERVER = 'smtp.gmail.com' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 2 - REVERSAL | |
# | |
# The quickest way to reverse an array is to swap elements at either end, and repeat | |
# while moving up from the left and down from the right. | |
# | |
# [ a b c d e f ] | |
# [ f a ] - Step 1 we switched A[0] with A[-1] | |
# [ e b ] - Step 2 we switched A[1] with A[-2] | |
# [ d c ] - Step 3 we switched A[2] with A[-3] |
OlderNewer