This file contains 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 luke = { | |
name: "luke skywalker", | |
jedi: true, | |
parents: { | |
father: { | |
jedi: true | |
}, | |
mother: { | |
jedi: false | |
} |
This file contains 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
function increment(input) { return input + 1;} | |
function decrement(input) { return input - 1; } | |
function double(input) { return input * 2; } | |
function halve(input) { return input / 2; } | |
var initial_value = 1; | |
var pipeline = [ | |
increment, | |
increment, |
This file contains 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 data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; | |
var flattenedData = data.reduce(function(acc, value) { | |
return acc.concat(value); | |
}, []); | |
var input = [ | |
{ | |
title: "Batman Begins", | |
year: 2005, | |
cast: [ |
This file contains 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
function reducer(accumulator, value, index, array) { | |
var intermediaryValue = accumulator + value; | |
if (index === array.length - 1) { | |
return intermediaryValue / array.length; | |
} | |
return intermediaryValue; | |
} |
This file contains 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 data = [1, 2, 3]; | |
var doubled = data.reduce(function(acc, value) { | |
acc.push(value * 2); | |
return acc; | |
}, []); | |
var doubleMapped = data.map(function(item) { | |
return item * 2; | |
}); |
This file contains 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 TurboController < ApplicationController | |
class Responder < ActionController::Responder | |
def to_turbo_stream | |
controller.render(options.merge(formats: :html)) | |
rescue ActionView::MissingTemplate => error | |
if get? | |
raise error | |
elsif has_errors? && default_action | |
render rendering_options.merge(formats: :html, status: :unprocessable_entity) | |
else |
This file contains 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
module QrCodeHelper | |
def qr_code_as_svg(uri) | |
RQRCode::QRCode.new(uri).as_svg( | |
offset: 0, | |
color: '000', | |
shape_rendering: 'crispEdges', | |
module_size: 4, | |
standalone: true | |
).html_safe | |
end |
This file contains 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 SessionsController < Devise::SessionsController | |
include AuthenticateWithOtpTwoFactor | |
prepend_before_action :authenticate_with_otp_two_factor, | |
if: -> { action_name == 'create' && otp_two_factor_enabled? } | |
protect_from_forgery with: :exception, prepend: true, except: :destroy |
This file contains 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 SessionsController < Devise::SessionsController | |
protected | |
def configure_permitted_parameters | |
devise_parameter_sanitizer.permit(:sign_in, keys: [:otp_attempt]) | |
end | |
end |
This file contains 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="card"> | |
<div class="card-header">Two Factor Authentication</div> | |
<div class="card-body"> | |
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name), method: :post) do |f| %> | |
<%= f.input :otp_attempt, label: 'OTP' %> | |
<div class="actions"> | |
<%= f.submit 'Login', class: 'btn btn-primary mt-2' %> | |
</div> | |
<% end %> | |
</div> |
NewerOlder