Skip to content

Instantly share code, notes, and snippets.

View seandmccarthy's full-sized avatar

Sean McCarthy seandmccarthy

View GitHub Profile
class NullValue
def nil?
true
end
def coerce(other)
case other
when Numeric
[other, BigDecimal(0)]
end
@seandmccarthy
seandmccarthy / tuple.rb
Created October 8, 2018 09:43
Basic tuple types and subtypes
class Tuple
EPSILON = 5
attr_accessor :x, :y, :z, :w
def initialize(x, y, z, w)
@x = Float x
@y = Float y
@z = Float z
@w = Integer w
end
@seandmccarthy
seandmccarthy / stream_read_process.rb
Last active August 19, 2018 11:01
Read images from ffmpeg stream via pipes and instantiate as ImageMagick::Image objects for further processing.
#! /usr/bin/env ruby
require 'rmagick'
video_file = ARGV[0]
unless File.exist?(video_file.to_s)
$stderr.puts 'Usage: stream_read <video_filename>'
exit 1
end
@seandmccarthy
seandmccarthy / stream_read_to_images.rb
Last active August 19, 2018 11:04
Parse images out of a ffmpeg stream using pipes
#! /usr/bin/env ruby
video_file = ARGV[0]
unless File.exist?(video_file.to_s)
$stderr.puts 'Usage: stream_read <video_filename>'
exit 1
end
JPEG_START = [0xFF, 0xD8].freeze
JPEG_END = [0xFF, 0xD9].freeze