Skip to content

Instantly share code, notes, and snippets.

View coreyjs's full-sized avatar

Corey Schaf coreyjs

View GitHub Profile
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'application#index', format: 'json'
end
class ApplicationController < ActionController::API
def index
render json: { status: 200, message: 'Hello World'}
end
end
http role route
GET Get an app /v1/apps/{int:id}
GET Get all apps /v1/apps/
POST Create an app /v1/apps/
PATCH Update an app /v1/apps/{int:id}
DELETE Delete an app /v1/apps/
class V1::AppsController < ApplicationController
before_action :set_app, only: [:show, :update, :destroy]
# GET /v1/apps
def index
@apps = App.all
render json: @apps
end
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'application#index', format: 'json'
namespace :v1 do
resource :apps
end
end
class App < ApplicationRecord
validates :name, uniqueness: true
validates :token, uniqueness: true
end
require 'test_helper'
class AppTest < ActiveSupport::TestCase
# 1
test "app should save with unqiue name and token" do
app1 = App.new(name: 'Hello World', token: '13456')
app2 = App.new(name: 'Goodbye World', token: 'abcdef')
assert app1.save
assert app2.save
@coreyjs
coreyjs / gist:3197326b6016acb444a18a8251b15c88
Created November 1, 2018 12:44
flake8 cli for serverless python
flake8 --exit-zero --count --max-line-length 120 --exclude=node_modules,.cache,.serverless_plugins,.circleci,.pytest_cache,postman,sls,.serverless
@coreyjs
coreyjs / dcp2.rb
Created February 25, 2019 18:52
Daily Coding Email Problem 2
#Given an array of integers, return a new array such that
# each element at index i of the new array is the product of all the
# numbers in the original array except the one at i.
input = [1, 2, 3, 4, 5]
input2 = [3, 2, 1]
def sum_array(input)
total = input.reduce(1, :*)
out = []