Skip to content

Instantly share code, notes, and snippets.

View wajeeh-devsinc's full-sized avatar

wajeeh-devsinc

View GitHub Profile
require 'mechanize'
require 'csv'
# Load up the trending Ruby repos on GitHub from the last month.
url_to_scrape = "https://github.com/trending?l=ruby&since=monthly"
# Snag the website with Mechanize & parse it into an XML document we can query.
page = Mechanize.new.get(url_to_scrape)
# Set the name of the CSV we'll create & load from.
file = "repo_data.csv"
@wajeeh-devsinc
wajeeh-devsinc / sessions_controller.rb
Created January 30, 2020 10:55
Rails User Authentication with Devise and simple_token_authentication
class Api::V1::SessionsController < Devise::SessionsController
before_action :sign_in_params, only: :create
before_action :load_user, only: :create
# sign in
def create
if @user.valid_password?(sign_in_params[:password])
sign_in "user", @user
render json: {
messages: "Signed In Successfully",
is_success: true,
@wajeeh-devsinc
wajeeh-devsinc / registrations_controller.rb
Last active January 30, 2020 10:52
Rails User Authentication with Devise and simple_token_authentication
class Api::V1::RegistrationsController < Devise::RegistrationsController
before_action :ensure_params_exist, only: :create
skip_before_filter :verify_authenticity_token, :only => :create
# sign up
def create
user = User.new user_params
if user.save
render json: {
messages: "Sign Up Successfully",
is_success: true,