This file contains hidden or 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 BaseClient | |
class APINotFound < StandardError; end | |
attr_reader :auth_strategy | |
def initialize(auth_strategy: :headers, headers: {}) | |
@auth_strategy = auth_strategy | |
@headers = headers | |
end |
This file contains hidden or 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
# mDNS client | |
# | |
# Usage: ruby script.rb "_http._tcp.local." | |
require "socket" | |
require "ipaddr" | |
require "fcntl" | |
require "resolv" | |
module DNSSD |
This file contains hidden or 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
# Example of using SQLite VSS with OpenAI's text embedding API | |
# from Ruby. | |
# Note: Install/bundle the sqlite3, sqlite_vss, and ruby-openai gems first | |
# OPENAI_API_KEY must also be set in the environment | |
# Other embeddings can be used, but this is the easiest for a quick demo | |
# More on the topic at | |
# https://observablehq.com/@asg017/introducing-sqlite-vss | |
# https://observablehq.com/@asg017/making-sqlite-extension-gem-installable |
This file contains hidden or 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 | |
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile do | |
source "https://rubygems.org" | |
gem "syntax_tree" | |
end |
This file contains hidden or 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 'thread' | |
require 'logger' | |
POOL_SIZE = 10 # limit for HTTP parallel connections | |
QUEUE_SIZE = 5 # limit to consume only fixed amount of memory | |
queue = SizedQueue.new(QUEUE_SIZE) | |
logger = Logger.new($stdout) | |
END_MESSAGE = :done | |
ERROR_MESSAGE = :error |
This file contains hidden or 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
# frozen_string_literal: true | |
source 'https://rubygems.org' | |
gem 'rack', github: 'rack/rack' | |
gem 'puma', github: 'puma/puma' |
This file contains hidden or 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
# Rails production setup via SQLite3 made durable by https://litestream.io/ | |
# Copy this to Dockerfile on a fresh rails app. Deploy to fly.io or any other container engine. | |
# | |
# try locally: docker build . -t rails && docker run -p3000:3000 -it rails | |
# | |
# in production you might want to map /data to somewhere on the host, | |
# but you don't have to! | |
# | |
FROM ruby:3.0.2 |
This file contains hidden or 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 'async' | |
class Enumerator | |
class Async | |
module Refinement | |
refine Enumerable do | |
def async | |
Enumerator::Async.new(self) | |
end | |
end |
This file contains hidden or 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 'async' | |
module Task | |
module_function | |
def async(*method_names) | |
Async do | |
method_names.map do |job| | |
Async do | |
job.to_proc.call(self) |
This file contains hidden or 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
# frozen_string_literal: true | |
# Example usage: | |
# | |
# tcpdump -i lo0 'port 3010' -v -X -l | ruby frame_display.rb | |
# | |
require 'bundler/inline' | |
gemfile(true, quiet: true) do | |
source 'https://rubygems.org' |
NewerOlder