Skip to content

Instantly share code, notes, and snippets.

@fallwith
fallwith / rainbow_colors.rb
Created September 24, 2019 19:02
Preview all of the Rainbow gem's supported colors
#!/usr/bin/env ruby
# frozen_string_literal: true
require "rainbow"
ansi_colors = %w[black red green yellow blue magenta cyan white]
x11_colors = %w[aliceblue antiquewhite aqua aquamarine azure beige bisque
blanchedalmond blueviolet brown burlywood cadetblue
chartreuse chocolate coral cornflower cornsilk crimson
darkblue darkcyan darkgoldenrod darkgray darkgreen darkkhaki
@fallwith
fallwith / ruby_challenge.md
Last active December 20, 2020 02:59
Ruby Challenge

Ruby Challenge

Introduction

This is a simple test of basic Ruby programming concepts. To complete this challenge, you will need to install Ruby 1.8.6 or later on your system. Rails is not required for this test.

This test is open book, and you may use whatever resources you need to complete it.

Instructions

@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
@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 / 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 / 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 / instructions.md
Last active January 22, 2025 23:38
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 / 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 / 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 / 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