Skip to content

Instantly share code, notes, and snippets.

@fallwith
fallwith / reporter.rb
Last active March 28, 2023 00:00
New Relic Ruby agent demo: set an error group callback used for noticed errors
#!/usr/bin/env ruby
# frozen_string_literal: true
# INSTRUCTIONS:
# - Place this file somewhere. It can be called something like `reporter.rb`
#
# - Either place a newrelic.yml file in the same directory as this file OR
# export the NEW_RELIC_LICENSE_KEY and NEW_RELIC_HOST environment variables.
# If using a newrelic.yml file, it should look like this:
# # newrelic.yml
@fallwith
fallwith / demo.rb
Created November 17, 2022 23:47
Ruby threads and fibers testing
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'async', '~> 2.2'
end
@fallwith
fallwith / compression_test.rb
Created November 3, 2022 20:51
Ruby gzip compression testing of text
require 'zlib'
CHARACTERS = ['a'..'z', 'A'..'Z', 0..9].map(&:to_a).flatten.freeze
TRIES = 10_000
BYTE_RANGE = 50..1000
savings = TRIES.times.each_with_object([]) do |_, arr|
string = (0...rand(BYTE_RANGE)).map { CHARACTERS[rand(CHARACTERS.size)] }.join
gzipped = Zlib.gzip(string)
arr << (1 - gzipped.size.to_f / string.size) * 100
@fallwith
fallwith / grpc_ruby_gzip.rb
Last active January 26, 2023 20:16
Ruby grpc gem with gzip compression demonstration
#!/usr/bin/env ruby
# frozen_string_literal: true
# This standalone Ruby script is intended to demonstrate the use of the 'grpc'
# gem to establish a minimal unary rpc and spawn both a gRPC server and client
# and have them use gzip to compress content being sent to one another after
# the client requests the use of gzip at channel creation, stub creation, and
# call time.
#
# Instructions:
@fallwith
fallwith / emu2miyoo.rb
Last active September 21, 2022 00:49
Convert an emulationstation based dir to a miyoo mini v2 compatible one
#!/usr/bin/env ruby
# frozen_string_literal: true
# encoding: utf-8
require 'fileutils'
require 'nokogiri'
SOURCE_IMG_DIR = 'media/covers'
TARGET_IMG_DIR = 'Imgs'
UNUSED_ELEMENTS = %w[desc developer genre kidgame marquee players rating releasedate publisher video]
@fallwith
fallwith / instructions.md
Last active November 14, 2023 17:03
Using the New Relic Ruby agent with a standalone Ruby script

Instructions

  1. Download the standalone.rb file to your computer. Place it in an empty directory by itself. The file does not need to be made executable. The first "shebang" line of the file will be ignored, so the path is not important.
  2. Create a newrelic.yml file or copy an existing one from an existing project to the directory containing standalone.rb
  3. At a comand prompt in the directory, run ruby standalone.rb
  4. If the standalone test script is successful, its output will look like this:
Starting New Relic agent...
Waiting for New Relic agent to connect...
@fallwith
fallwith / notice_error.rb
Created August 22, 2022 20:07
Use newrelic_rpm to manually notice an error
#!/usr/bin/env ruby
# frozen_string_literal: true
# The New Relic Ruby agent can be instructed to manually notice an error by
# using the public NewRelic::Agent.notice_error method.
#
# NewRelic::Agent.notice_error does not require that a New Relic Ruby agent
# transaction exist. It simply requires that the New Relic Ruby agent be
# connected, which itself requires the use of a valid license key.
#
@fallwith
fallwith / README.md
Created July 22, 2022 00:51
Minimal example of configuring the New Relic Ruby agent to use method chaining for Redis instrumentation

Minimal example of configuring the New Relic Ruby agent to use method chaining for Redis instrumentation

The New Relic Ruby agent has instrumentation support for the redis Rubygem.

By default, the agent will instrument redis in "auto" mode and automatically decide whether to use method prepending or method chaining. The "auto" mode will opt for the use of method prepending unless it detects a condition known to cause a conflict. To explicitly use "chain" mode to force method chaining, the newrelic.yml configuration file can be given the following entry:

instrumentation.redis: chain
@fallwith
fallwith / phone_number.rb
Created April 22, 2022 21:43
Annotated submission for the 'phone-number' Exercism exercise
# Any variable starting with a capital letter (including a class name!) is a
# constant in Ruby. For static values like this one, Rubyists typically use all
# caps for the variable name.
#
# %w = word array, use spaces without commas to delimit values
#
# #freeze, available on any instance of an object, prevents a value from being
# modified after it has been frozen. There is no #thaw or #unfreeze, but the
# value itself can be overwritten later if need be.
INVALID_CODES = %w[0 1].freeze
@fallwith
fallwith / challenge.rs
Last active December 28, 2020 07:39
A Rust attempt at a Ruby challenge
use chrono::{DateTime, Local};
use std::collections::HashMap;
use std::env;
use std::process;
use std::time::SystemTime;
const VERSION: &str = "0.1.0";
// a Rust attempt at the following Ruby coding challenge:
// https://gist.github.com/fallwith/00aa5f7a0d5c192e91fa6468e7434048