Skip to content

Instantly share code, notes, and snippets.

View sferik's full-sized avatar

Erik Berlin sferik

View GitHub Profile
@sferik
sferik / mutant.out
Created October 24, 2023 02:27
Erroring mutant output for x-ruby MediaUploader class
This file has been truncated, but you can view the full file.
warning: parser/current is loading parser/ruby33, which recognizes 3.3.0-dev-compliant syntax, but you are running 3.3.0.
Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Mutant environment:
Matcher: #<Mutant::Matcher::Config subjects: [X::MediaUploader]>
Integration: minitest
Jobs: 10
Includes: ["lib"]
Requires: ["x", "x/media_uploader"]
Operators: full
MutationTimeout: 10
@sferik
sferik / digits_cli.cr
Last active July 28, 2023 19:05
NYTimes Digits Game (aka Countdown) Solver written in Crystal by Erik Berlin
require "option_parser"
class CountdownGame
OPERATORS = [:+, :-, :*, :/]
def initialize(@numbers : Array(Int32), @target : Int32)
end
def solve
result = solve_recursively(@numbers.map { |n| {n, n.to_s} }).find { |result, _| result == @target }
@sferik
sferik / twimg.cr
Last active September 4, 2021 14:43
require "http/client"
require "json"
require "oauth"
HOST = "api.twitter.com"
# Generate API keys at https://developer.twitter.com/en/portal/projects-and-apps
API_KEY = "Replace this with your Twitter API Key"
API_SECRET = "Replace this with your Twitter API Key Secret"
ACCESS_TOKEN = "Replace this with your Twitter Access Token"
ACCESS_TOKEN_SECRET = "Replace this with your Twitter Access Token Secret"
class SizeAwareCache
@@cache = {} of String => Hash(Int32, String)
def read(key : String, size : Int32)
if value = @@cache.dig?(key, size)
# Hit! (both key and size)
return value
elsif results = @@cache[key]?
# Key hit, size miss
sorted_results = results.to_a.sort_by(&.first)
require 'benchmark/ips'
def class_integer
0.class == Integer
end
def version_gte
RUBY_VERSION >= '2.4'
end
digraph G {
label="Caddy Architecture"
labelloc="top"
fontsize=20
fontname="Helvetica Neue"
node [shape="ellipse", style="filled", fontname="Helvetica Neue"]
edge [fontname="Helvetica Neue"]
peripheries=0
rankdir="LR"
subgraph clusterClient {
module Enumerable
def first_to_finish
threads = collect { |args| Thread.new { yield(args) } }
loop until done = threads.detect { |t| !t.alive? }
threads.each(&:kill)
done.value
end
end
puts [5, 3, 1, 2, 4].first_to_finish { |x| sleep x }

What is the system Ruby?

What version of Ruby shipped by default on Mac OS X?

Default Ruby version * Refers to the fully patched version (e.g. 10.5.8, not 10.5.0). Earlier versions may have shipped with different Ruby patchlevels but the RUBY_VERSION has never changed within major Mac OS X releases.
Mac OS X version* Mac OS X release date
require 'benchmark/ips'
require 'ostruct'
N = 100
ATTRS = (:aa..:zz).take(N)
HASH = Hash[ATTRS.map { |x| [x, x] }]
CStruct = Struct.new(*ATTRS)
def struct
@sferik
sferik / 1_class_refactored_solution.rb
Last active September 7, 2015 20:47 — forked from JoshCheek/1_class_refactored_solution.rb
Checking the Credits, y'all!
def valid?(card_number)
digits = card_number
.split("")
.map { |number| number.to_i }
numbers = []
digits.each_with_index do |digit, index|
if index.even?
numbers << digit * 2
else