Skip to content

Instantly share code, notes, and snippets.

View iamqasimali's full-sized avatar
🏠
Working from home

Qasim Ali Zahid iamqasimali

🏠
Working from home
View GitHub Profile
var luke = {
name: "luke skywalker",
jedi: true,
parents: {
father: {
jedi: true
},
mother: {
jedi: false
}
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,
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: [
function reducer(accumulator, value, index, array) {
var intermediaryValue = accumulator + value;
if (index === array.length - 1) {
return intermediaryValue / array.length;
}
return intermediaryValue;
}
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;
});
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
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
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
class SessionsController < Devise::SessionsController
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_in, keys: [:otp_attempt])
end
end
<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>