Skip to content

Instantly share code, notes, and snippets.

View swombat's full-sized avatar

Daniel Tenner swombat

View GitHub Profile
require "faraday"
require "json"
class BrowserlessApi
def initialize(api_key: Rails.application.credentials.dig(:browserless, :api_key) || "<BROWSERLESS_API_KEY>", debug: false)
@api_key = api_key
@base_url = "https://production-sfo.browserless.io"
@debug = debug
end
@swombat
swombat / sumsub_api.rb
Created March 12, 2025 06:42
Sumsub API example
class SumsubApi < GenericApi
BASE_URL = "https://api.sumsub.com"
def initialize(api_token: Rails.application.credentials[:sumsub][:api_token], secret_key: Rails.application.credentials[:sumsub][:secret],
base_url: BASE_URL, debug: true)
@api_token = api_token
@secret_key = secret_key
@base_url = base_url
@debug = debug
@swombat
swombat / Dockerfile
Created February 23, 2025 15:59
Dockerfile (BT 1.18.0)
# syntax = docker/dockerfile:1
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.4.1
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
# Rails app lives here
WORKDIR /rails
# Set production environment
@swombat
swombat / corporation_tax.rb
Created December 10, 2024 10:00
UK Corporation Tax Calculator
class CorporationTax
def self.calculate_ct(profit, period_start_on, period_end_on)
if period_end_on < Date.new(2023, 4, 1)
calculate_ct_before_2023(profit)
elsif period_start_on >= Date.new(2023, 4, 1)
calculate_ct_after_2023(profit)
else
period_split = split_periods(period_start_on, period_end_on)
period_1_profit = profit * period_split[0] / (period_split[0] + period_split[1])
@swombat
swombat / active_children.rb
Created October 15, 2024 07:34
ActivePage workaround to get cable-like refreshes of complex pages without having a thousand `cable_ready_updates_for` blocks
module ActiveChildren
extend ActiveSupport::Concern
included do
class_attribute :active_children, default: []
after_save :notify_active_children
end
class_methods do
def has_active_child(name)
@swombat
swombat / transcribe-whisper-1.rb
Created August 11, 2024 07:42
Transcribe via whisper-1
#!/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
require 'rubygems'
require 'nokogiri'
require 'open-uri'
class Harvester
attr_accessor :output, :links_fetched
def initialize(args)
super()
@options = {
usage: /[... snip ...]/current/script/delayed_job.rb <command> [options]
Where <command> is one of start, stop, restart or status
[options] are additional options passed to the underlying process
create_table "audit_log_events", :force => true do |t|
t.integer "project_id"
t.integer "user_id"
t.integer "object_id"
t.string "object_type"
t.string "event_type"
t.string "display_string"
t.text "data_marshalled"
t.datetime "created_at"
t.datetime "updated_at"
<%= form_for @email_subscription do |f| -%>
<%= f.error_messages :header_message => "Can't subscribe", :message => "This went wrong:" %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label "Your time zone", :for => :time_zone_city %>
<%= f.time_zone_select :time_zone_city %>