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
class ApplicationController < ActionController::API | |
def metaprogram_controller_instance_variable | |
model_name = params['controller'].singularize | |
Model = Object.const_get(model_name.capitalize) | |
value_to_set = Model.find_by(id: params[:id]) | |
instance_variable_set('@' + model_name, value_to_set) | |
end | |
end |
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
class ApplicationController < ActionController::API | |
before_action :authenticate_user | |
def sorcery | |
controller_name = params['controller'] | |
controller_name.chop! | |
model_name = controller_name.capitalize | |
instance_variable_set('@' + controller_name, Object.const_get( model_name ).find_by(id: params[:id])) | |
end | |
end |
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
class ApplicationController < ActionController::Base | |
protect_from_forgery with: :exception | |
def after_sign_in_path_for(resource) | |
request.env['omniauth.origin'] || dashboard_path | |
end | |
def index | |
render "landing/index" | |
end |
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
class User | |
attr_accessor :name, :user_name, :age, :location, :bio | |
def initialize(attributes) | |
attributes.each {|key, value| self.send(("#{key}="), value)} | |
end | |
end |
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
def sorcery | |
controller_name = params['controller'] | |
controller_name.chop! | |
model_name = controller_name.capitalize | |
instance_variable_set('@' + controller_name, Object.const_get( model_name ).find_by(id: params[:id])) | |
end |
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
const myWorkSchedule = { | |
monday: '10-5', | |
tuesday: '10-5', | |
friday: '11-9' | |
} | |
const updatedSchedule = { thursday: '11-6', ...myWorkSchedule } | |
updatedSchedule | |
// {thursday: "11-6", monday: "10-5", tuesday: "10-5", friday: "11-9"} |
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
const myWorkSchedule = { | |
monday: '10-5', | |
tuesday: '10-5', | |
friday: '11-9' | |
} | |
const updatedSchedule = Object.assign({}, myWorkSchedule, { thursday: '8-5' }) | |
updatedSchedule | |
// {monday: "10-5", tuesday: "10-5", friday: "11-9", thursday: "8-5"} |
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
var twoSum = function(nums, target) { | |
let dictionary = {} | |
let complementValue = 0; | |
let indicesArray = []; | |
for (let i = 0; i < nums.length; i++) { | |
complementValue = target - nums[i]; | |
if (dictionary.hasOwnProperty( complementValue )) { | |
return indicesArray = [ dictionary[complementValue], i ] | |
} |
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
var twoSum = function(nums, target) { | |
let indicesArray = []; | |
for (let i = 0; i < nums.length; i++) { | |
for (let k = i + 1; k < nums.length; k++) { | |
if (nums[i] + nums[k] === target) { | |
indicesArray.push(i, k) | |
} | |
} | |
} | |
return indicesArray; |
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
// Input: [ 2, 7, 11, 15 ] | |
//* Use a nested for loop | |
//* compare the current num(i) to the next num(k++) and check if they match | |
//* if they match then return both indices in an array | |
// Output: [ 0, 1 ] | |
// edge cases: ?? |