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
#!/usr/bin/env ruby | |
require 'open3' | |
require 'signal' | |
require 'openai' | |
# Define the silence threshold and duration for detection | |
@silence_threshold = '-30dB' | |
@silence_duration = 0.5 |
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 TailwindClassBuilder | |
include ActionView::Helpers::TagHelper | |
def button_classes(options) | |
button_type = options.delete(:button_type) { :button } | |
class_names( | |
# general classes | |
"mt-4 px-1 sm:px-3 py-sm sm:py-1 font-semibold bg-transparent border rounded", | |
case button_type |
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
def css(selector) | |
html.css(selector).text | |
end | |
def html | |
Nokogiri::HTML(response.body) | |
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 OAuth::GoogleAuthorizationsController < ApplicationController | |
CLIENT_ID = Rails.application.credentials.google.client_id | |
CLIENT_SECRET = Rails.application.credentials.google.client_secret | |
SCOPE = "openid email profile" | |
AUTHORIZATION_URL = URI("https://accounts.google.com/o/oauth2/v2/auth") | |
TOKEN_URL = URI("https://www.googleapis.com/oauth2/v4/token") | |
USER_INFO_URL = URI("https://www.googleapis.com/oauth2/v3/userinfo") | |
before_action :validate_state_token, only: :show |
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
# ActiveJob natively captures constructor arguments in an `@arguments` instance variable | |
# which is also exposed as an `arguments` property on each job instance. | |
# | |
# Calls to `perform_now` and `perform_later` both forward arguments to the constructor. | |
# | |
# For example, all of these invocation styles work. | |
# | |
# result = DoStuffJob.new("foobar").perform # sync | |
# result = DoStuffJob.new.perform("foobar") # sync | |
# result = DoStuffJob.perform_now("foobar") # sync |
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
require "json" | |
struct = { "a" => 1, "b" => 2, "c" => [1, 2, 3], "d" => [{ "e" => 3 }, nil, false, true, [], {}] } | |
source = JSON.dump(struct) | |
tokens = [] | |
index = 0 | |
until source.empty? | |
tokens << |
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
# BAD each iteration loads invoice model | |
class Company < ApplicationRecord | |
has_many :invoices | |
end | |
class Invoice < ApplicationRecord | |
belongs_to :company | |
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
# spec/system/support/login_helpers.rb | |
# See this blog post for setup guide: https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing | |
module LoginHelpers | |
def login_as(user) | |
# Craft session cookie to make request authenticated (to pass even routing constraints) | |
# Compilation of these: | |
# - https://dev.to/nejremeslnici/migrating-selenium-system-tests-to-cuprite-42ah#faster-signin-in-tests | |
# - https://turriate.com/articles/2011/feb/how-to-generate-signed-rails-session-cookie | |
# - https://github.com/rails/rails/blob/43e29f0f5d54294ed61c31ddecdf76c2e1a474f7/actionpack/test/dispatch/cookies_test.rb#L350 |
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
gem "webpacker", "~> 5.4.0" |
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
# refer to https://ozow.com/integrations/ for more information | |
# Ordering with the params matters, see the link above for more information | |
ozow_params = { | |
'SiteCode': 'SOME_SITE_CODE', # find this here https://dash.ozow.com/MerchantAdmin/Site | |
'CountryCode': 'ZA', # only supports ZA currently | |
'CurrencyCode': 'ZAR', # only supports ZAR currently | |
'Amount': 1000, # this is R1000, not working well for floats though | |
'TransactionReference': 'SOME_TEST', # your internal reference to match against | |
'BankReference': "Nice Reference", # the reference that the customer will see on their bank statement |
NewerOlder