Skip to content

Instantly share code, notes, and snippets.

View buyaka's full-sized avatar
🎯
Focusing

buyaka buyaka

🎯
Focusing
  • UNIMEDIA
  • Mongolia
View GitHub Profile
@buyaka
buyaka / Gemfile
Created January 13, 2019 13:34 — forked from daqing/Gemfile
source "https://rubygems.org"
gem 'eventmachine'
#gem 'rubysl-stringio'
gem 'sinatra'
gem 'yajl-ruby', require: 'yajl'
gem 'thin'
gem 'em-websocket', :git=>'https://github.com/igrigorik/em-websocket.git'
@buyaka
buyaka / authentication_with_bcrypt_in_rails_4.md
Created August 28, 2016 23:43 — forked from thebucknerlife/authentication_with_bcrypt_in_rails_4.md
Simple Authentication in Rail 4 Using Bcrypt

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

@buyaka
buyaka / Ror lesson
Last active December 12, 2015 02:47
#--------------- search ----------------
#1 Add search route into route.rb (before resources :articles)
get '/articles/search' => "articles#search"
#2 Add search action into Post controller
def search
@articles = Article.where("title = ?",params[:q])
end
#rails new <APPNAME> -T -m app_template.rb -d mysql
source_paths << File.dirname(__FILE__)
gem 'devise'
gem 'cancan'
gem 'mysql2'
gem 'therubyracer', platforms: :ruby
gem 'materialize-sass'
#rails new <APPNAME> -T -m app_template.rb -d mysql
source_paths << File.dirname(__FILE__)
gem 'devise'
gem 'cancan'
gem 'mysql2'
gem 'therubyracer', platforms: :ruby
gem "twitter-bootstrap-rails"
gem 'bootstrap-material-design'
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
# Nginx+Unicorn best-practices congifuration guide. Heartbleed fixed.
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
#
# Deployment structure
#
# SERVER:
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#
# db/migrate/XXXXXXXXXXXXX_add_authentication_token_to_users.rb
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :authentication_token, :string
add_index :users, :authentication_token, :unique => true
end
end
//
// Macros.h
//
// Created by Buyaka on 2/4/13.
// Copyright (c) 2013 Buyaka. All rights reserved.
//
#ifndef Macros_h
#define Macros_h
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else