Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@adam12
adam12 / spike.rb
Created April 11, 2024 14:02 — forked from havenwood/spike.rb
A spike showing compiling IR binaries for all gems
# frozen_string_literal: true
require 'fileutils'
require 'find'
require 'zlib'
binaries_dir = File.join Gem.dir, 'binaries'
gems_dir = File.join Gem.dir, 'gems'
Dir['*/', base: gems_dir].each do |gem|
@adam12
adam12 / mdns.rb
Created January 21, 2024 03:44 — forked from tenderlove/mdns.rb
Sample mDNS client in Ruby
# mDNS client
#
# Usage: ruby script.rb "_http._tcp.local."
require "socket"
require "ipaddr"
require "fcntl"
require "resolv"
module DNSSD
@adam12
adam12 / PhlexMailerLayout.rb
Created January 6, 2024 18:28 — forked from georgekettle/PhlexMailerLayout.rb
Phlex Mailer layout
You'll need to update the following variables:
- ENV['APP_NAME']
- ENV['COMPANY_ADDRESS']
- ENV['HOST']
Make sure you have app/assets/images/logo.svg for this line:
helpers.image_url('logo.svg')
And also update the CSS variables to match your color scheme:
:root {
@adam12
adam12 / gist:acb2b08b7bc1a711fdf0afe503667c2e
Created November 30, 2023 15:31 — forked from rkumar/gist:445735
ruby's OptionParser to get subcommands
#!/usr/bin/env ruby -w
## Using ruby's standard OptionParser to get subcommand's in command line arguments
## Note you cannot do: opt.rb help command
## other options are commander, main, GLI, trollop...
# run it as
# ruby opt.rb --help
# ruby opt.rb foo --help
# ruby opt.rb foo -q
# etc
@adam12
adam12 / packer.rb
Created July 12, 2023 12:58 — forked from joeldrapper/packer.rb
Paquito Job Packer
# frozen_string_literal: true
module Packer
# A special packer class for globally identifiable objects. It takes a global ID and packs it as a String, then rehydrates it as a GlobalID lookup.
class GloballyIdentifiable
def self.from_pack(uri)
GlobalID::Locator.locate(uri)
end
def initialize(identifiable)
@adam12
adam12 / ring_buffer.rb
Created July 7, 2023 16:59 — forked from havenwood/ring_buffer.rb
A ring buffer implementation example for Ruby Discord.
# frozen_string_literal: true
class RingBuffer
Nothing = Data.define
EMPTY = Nothing.new
attr_reader :size
def initialize(capacity:)
@capacity = capacity
@adam12
adam12 / cache.rb
Created November 11, 2022 02:37 — forked from havenwood/cache.rb
Another example for xco on #ruby IRC
require_relative 'tuple_space'
class Cache
def initialize
@memory = TupleSpace.new(reaper_period_in_secs: 10, expires_in_secs: 60)
end
def get(request)
@memory[request]
end
@adam12
adam12 / database_cleaner.rb
Created January 9, 2020 02:23 — forked from jsteiner/database_cleaner.rb
Database Cleaner
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
@adam12
adam12 / 1 - I plan to turn these off
Created November 15, 2019 19:43 — forked from dlangille/1 - I plan to turn these off
Periodic things to turn off in FreeBSD jails
# after reviewing /etc/defaults/periodic.conf I have decided
# to disable these items in jails
daily_status_disks_enable="NO"
daily_status_network_enable="NO"
daily_status_uptime_enable="NO"
# not needed on jails
daily_ntpd_leapfile_enable="NO"
@adam12
adam12 / cron_helper.sh
Created August 23, 2019 02:08 — forked from liquidgecka/cron_helper.sh
Cron helper
#!/bin/bash
usage() {
cat << EOF
Usage: $0 [OPTION]... COMMAND
Execute the given command in a way that works safely with cron. This should
typically be used inside of a cron job definition like so:
* * * * * $(which "$0") [OPTION]... COMMAND
Arguments: