Skip to content

Instantly share code, notes, and snippets.

View leopolicastro's full-sized avatar

Leo Policastro leopolicastro

View GitHub Profile
import { Controller } from "stimulus";
export default class extends Controller {
static targets = ["field"];
fetchOpportunities(query) {
const url = `/admin/salesforce.json?query=${query}`;
let csrf = document
.querySelector("meta[name='csrf-token']")
.getAttribute("content");
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
static values = {
maxallowed: Number,
};
currencyFormatter(e) {
let value = e.target.value;
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
static values = {
maxallowed: Number,
};
currencyFormatter(e) {
let value = e.target.value;
<%# _inline_edit.html.erb %>
<% frame_id = dom_id(model, "#{attribute}_turbo_frame") %>
<%= form_with model: model, class: "contents", data: { turbo_frame: frame_id } do %>
<turbo-frame id="<%= frame_id %>" class="group inline-edit flex items-center">
<%= link_to edit_polymorphic_path(model), class: "text-main mr-3" do %>
<i class="fa-solid fa-pen-to-square text-main text-xl"></i>
<% end %>
<%= yield %>
</turbo-frame>
<% end %>
# frozen_string_literal: true
# Plain Old Ruby Object
# Not backed by ActiveRecord
class RequestsClient
# client class
attr_reader :options, :adapter, :base_url
def initialize(base_url, options: {}, adapter: Faraday.default_adapter)
# frozen_string_literal: true
# Plain Old Ruby Object
# Not backed by ActiveRecord
class RequestsClient
# client class
attr_reader :options, :adapter, :base_url
def initialize(base_url, options: {}, adapter: Faraday.default_adapter)
# frozen_string_literal: true
# Monkey Patch string class
class String
def black
"\033[30m#{self}\033[0m"
end
def red
"\033[31m#{self}\033[0m"
AllCops:
TargetRubyVersion: 3.1.1
require: standard
inherit_gem:
standard: config/base.yml
def binary_search(ordered_array, search_value)
lower_bound = 0
upper_bound = ordered_array.length - 1
while lower_bound <= upper_bound do
midpoint = (lower_bound + upper_bound) / 2
value_at_midpoint = ordered_array[midpoint]
def linear_search(sorted_array, search_value)
sorted_array.each_with_index do |element, index|
if element == search_value
return index
elsif element > search_value
break
end
end
nil
end