Skip to content

Instantly share code, notes, and snippets.

View mrhead's full-sized avatar
👋
nil

Patrik Bóna mrhead

👋
nil
View GitHub Profile
# Very simple Ruby diff for strings.
# It works only on strings with the same number of lines, but it was perfect
# for my usecase where I was modifying templates saved in the database and I
# wanted to be sure that I am changing only what needs to be changed.
def differ(str_a, str_b)
str_a.lines.zip(str_b.lines) do |line_a, line_b|
if line_a != line_b
puts "< #{line_a}"
puts "> #{line_b}"
@mrhead
mrhead / polyglot
Last active October 25, 2015 21:20
#define a /*
#! \
sub 'echo {print @_; print "\n"}
#' 2>/dev/null
# \
echo "my polyglot"; exit;
# \
sub puts{};
puts "my polyglot";
exit;
#!/usr/bin/env ruby
class Splitter
SEPARATOR = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00DICM\x02\x00"
attr_reader :file_in_string
def initialize(file)
@file_in_string = File.binread(file)
end